|
@@ -0,0 +1,100 @@
|
|
|
+package com.fdkankan.fusion.controller;
|
|
|
+
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.deepoove.poi.XWPFTemplate;
|
|
|
+import com.deepoove.poi.config.Configure;
|
|
|
+import com.deepoove.poi.data.TextRenderData;
|
|
|
+import com.deepoove.poi.data.style.Style;
|
|
|
+import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
|
|
|
+import com.deepoove.poi.util.PoitlIOUtils;
|
|
|
+import com.fdkankan.fusion.common.ResultCode;
|
|
|
+import com.fdkankan.fusion.common.ResultData;
|
|
|
+import com.fdkankan.fusion.entity.CaseExtractDetail;
|
|
|
+import com.fdkankan.fusion.entity.CaseInquest;
|
|
|
+import com.fdkankan.fusion.exception.BusinessException;
|
|
|
+import com.fdkankan.fusion.response.CaseInquestVo;
|
|
|
+import com.fdkankan.fusion.response.WitnessVo;
|
|
|
+import com.fdkankan.fusion.service.ICaseExtractDetailService;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.BufferedOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.io.OutputStream;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 前端控制器
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author
|
|
|
+ * @since 2024-07-05
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/caseExtractDetail")
|
|
|
+public class CaseExtractDetailController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ICaseExtractDetailService caseExtractDetailService;
|
|
|
+
|
|
|
+
|
|
|
+ @GetMapping("/info")
|
|
|
+ public ResultData info(@RequestParam(required = false) Integer caseId){
|
|
|
+ return ResultData.ok(caseExtractDetailService.getByCaseId(caseId));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/saveOrUpdate")
|
|
|
+ public ResultData saveOrUpdate(@RequestBody CaseExtractDetail caseExtractDetail){
|
|
|
+ caseExtractDetailService.saveByParam(caseExtractDetail);
|
|
|
+ return ResultData.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/downDocx")
|
|
|
+ public void downDocx(@RequestParam(required = false) Integer caseId,
|
|
|
+ HttpServletResponse res, HttpServletRequest req) throws IOException {
|
|
|
+
|
|
|
+ if(caseId == null){
|
|
|
+ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
+ }
|
|
|
+ CaseExtractDetail caseExtractDetail = caseExtractDetailService.getByCaseId(caseId);
|
|
|
+ if(caseExtractDetail == null){
|
|
|
+ throw new BusinessException(ResultCode.INQUEST_ERROR2);
|
|
|
+ }
|
|
|
+
|
|
|
+ InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("template/extract-template.docx");
|
|
|
+ // 渲染模板
|
|
|
+
|
|
|
+ // 定义行循环插件
|
|
|
+ LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
|
|
|
+
|
|
|
+ Configure config = Configure.builder()
|
|
|
+ .bind("detail", policy).bind("extractUser", policy).bind("witnessInfo", policy).build();
|
|
|
+
|
|
|
+ XWPFTemplate template = XWPFTemplate.compile(inputStream,config).render(caseExtractDetail);
|
|
|
+
|
|
|
+ // 设置响应头,指定文件类型和内容长度
|
|
|
+ res.setContentType("application/octet-stream");
|
|
|
+ res.setHeader("Content-Disposition", "attachment; filename=output.docx");
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 返回网络流
|
|
|
+ OutputStream out = res.getOutputStream();
|
|
|
+ BufferedOutputStream bos = new BufferedOutputStream(out);
|
|
|
+ template.write(bos);
|
|
|
+ bos.flush();
|
|
|
+ out.flush();
|
|
|
+ // 关闭流
|
|
|
+ PoitlIOUtils.closeQuietlyMulti(template, bos, out);
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|