Bläddra i källkod

word 模板开启el表达式

lyhzzz 9 månader sedan
förälder
incheckning
5bcd7ac6c4

+ 13 - 0
src/main/java/com/fdkankan/fusion/common/util/XwpTemplateUtils.java

@@ -0,0 +1,13 @@
+package com.fdkankan.fusion.common.util;
+
+public class XwpTemplateUtils {
+
+    public static String getSexStr(Integer type){
+        switch (type){
+            case 0 :return "男";
+            case 1 :return "女";
+            default:return "未知";
+        }
+    }
+
+}

+ 1 - 1
src/main/java/com/fdkankan/fusion/config/SaTokenConfigure.java

@@ -44,7 +44,7 @@ public class SaTokenConfigure {
     public SaServletFilter getSaServletFilter() {
         return new SaServletFilter()
                 // 指定 拦截路由 与 放行路由
-                .addInclude("/**").addExclude("/**/test/**","/**/inner/**","/**/notAuth/**","/**ws/**")
+                .addInclude("/**").addExclude("/**/test/**","/**/inner/**","/**/notAuth/**","/**ws/**","/**/downDocx/**")
                 // 认证函数: 每次请求执行
                 .setAuth(obj -> {
                     String share = SaHolder.getRequest().getHeader("share");

+ 3 - 0
src/main/java/com/fdkankan/fusion/entity/CaseInquestCriminal.java

@@ -141,6 +141,7 @@ public class CaseInquestCriminal implements Serializable {
 
     /**
      * 现场保护人
+     * {"unit":"天地","name":"李","job":"天才"}
      */
     @TableField(typeHandler = JsonObjTypeHandler.class)
     private JSONObject protector;
@@ -167,6 +168,7 @@ public class CaseInquestCriminal implements Serializable {
     private String changeReasonOtherValue;
     /**
      * 天气情况
+     * {"temperature":"10","humidity":"20","windDirection":"南","type":[0,1,2,3]}
      */
     @TableField(typeHandler = JsonObjTypeHandler.class)
     private JSONObject weatherInfo;
@@ -179,6 +181,7 @@ public class CaseInquestCriminal implements Serializable {
 
     /**
      * 勘验指挥人
+     * {"unit":"第三方","name":"张","job":"植物"}
      */
     @TableField(typeHandler = JsonObjTypeHandler.class)
     private JSONObject inquestCommander;

+ 43 - 173
src/main/java/com/fdkankan/fusion/response/CaseInquestCriminalVo.java

@@ -8,193 +8,63 @@ import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableLogic;
 import com.deepoove.poi.data.TextRenderData;
 import com.fdkankan.fusion.common.util.DateUtils;
+import com.fdkankan.fusion.entity.CaseInquestCriminal;
 import lombok.Data;
 
 import java.util.Date;
 
 @Data
-public class CaseInquestCriminalVo {
-    /**
-     * 案件id
-     */
-    private Integer caseId;
+public class CaseInquestCriminalVo extends CaseInquestCriminal {
 
-    /**
-     * 现场勘验号
-     */
-    private String inquestNum;
+    private String makeTimeStr;
+    private String startTime;
+    private String endTime;
 
-    /**
-     * 单位名称
-     */
-    private String deptName;
-
-    /**
-     * 标题
-     */
-    private String title;
-
-    /**
-     * 发送单位
-     */
-    private String sendDept;
-
-    /**
-     * 笔录人
-     */
-    private String recorder;
-
-    /**
-     * 绘图人
-     */
-    private String painter;
-
-    /**
-     * 照相人
-     */
-    private String photographer;
-
-    /**
-     * 份数
-     */
-    private Integer issuanceCount;
-
-    /**
-     * 制作时间
-     */
-    private Date makeTime;
-
-    /**
-     * 签发意见
-     */
-    private String issuanceOpinion;
-
-    /**
-     * 签名
-     */
-    private String signature;
-
-    /**
-     * 签名时间
-     */
-    private Date signatureTime;
-
-    /**
-     * 报告单位
-     */
-    private String reportDept;
-
-    /**
-     * 时间
-     */
-    private Date inquestTime;
-
-    /**
-     * 勘验开始时间
-     */
-    private Date startTime;
-
-    /**
-     * 勘验结束时间
-     */
-    private Date endTime;
-
-    /**
-     * 勘验地址
-     */
-    private String address;
-
-    /**
-     * 现场保护情况
-     */
-    private String protectionSituation;
-
-    /**
-     * 现场保护人
-     */
-    private String protector;
-
-    /**
-     * 现场保护措施
-     */
-    private String protectionMeasures;
-
-    /**
-     * 现场情况
-     */
-    private String situation;
-
-    /**
-     * 变动原因
-     */
-    private String changeReason;
-
-    /**
-     * 天气情况
-     */
-    private JSONObject weatherInfo;
-
-    /**
-     * 光线
-     */
-    private String light;
-
-    /**
-     * 勘验指挥人
-     */
-    private String inquestCommander;
-
-    /**
-     * 勘验情况
-     */
-    private String inquestSituation;
-
-    /**
-     * 现场勘验制图数量
-     */
-    private Integer imageNum;
-
-    /**
-     * 照相数量
-     */
-    private Integer photographNum;
-
-    /**
-     * 摄影数量
-     */
-    private Integer photographyNum;
-
-    /**
-     * 现场勘验纪录人员数组
-     */
-    private JSONArray recorderInfo;
-
-    /**
-     * 现场勘验人员签名数组
-     */
-    private JSONArray signatureInfo;
-
-    /**
-     * 现场勘验见证人数组
-     */
-    private JSONArray witnessInfo;
+    private String inquestTimeStr1;
+    private String inquestTimeStr;
 
-    /**
-     * 备注
-     */
-    private String remark;
+    //数组
+    private TextRenderData recorderInfoText;
+    private TextRenderData signatureInfoText;
+    private TextRenderData witnessInfoText;
 
-    private Integer tbStatus;
 
-    private Date createTime;
+    public String getInquestTimeStr1() {
+        if(super.getInquestTime() == null){
+            return "";
+        }
+        return DateUtil.format(super.getInquestTime(),DatePattern.CHINESE_DATE_TIME_FORMAT);
+    }
 
-    private Date updateTime;
+    public String getMakeTimeStr() {
+        if(super.getMakeTime() == null){
+            return "";
+        }
+        return DateUtil.format(super.getMakeTime(),DatePattern.CHINESE_DATE_TIME_FORMAT);
+    }
 
-    private String inquestTimeStr;
+    //
+    public String getStartTime() {
+        if(super.getTimes().isEmpty()){
+            return "";
+        }
+        Date date = super.getTimes().getDate(0);
+        return DateUtil.format(date,DatePattern.CHINESE_DATE_TIME_FORMAT);
+    }
 
-    private TextRenderData text;
+    public String getEndTime() {
+        if(super.getTimes().isEmpty()){
+            return "";
+        }
+        Date date = super.getTimes().getDate(1);
+        return DateUtil.format(date,DatePattern.CHINESE_DATE_TIME_FORMAT);
+    }
 
     public String getInquestTimeStr() {
-        return DateUtils.getCnDateStr(DateUtil.format(inquestTime, DatePattern.CHINESE_DATE_FORMAT));
+        if(super.getInquestTime() == null){
+            return "";
+        }
+        return DateUtils.getCnDateStr(DateUtil.format(super.getInquestTime(), DatePattern.CHINESE_DATE_FORMAT));
     }
+
 }

+ 58 - 15
src/main/java/com/fdkankan/fusion/service/impl/CaseInquestCriminalServiceImpl.java

@@ -1,13 +1,21 @@
 package com.fdkankan.fusion.service.impl;
 
 import cn.dev33.satoken.stp.StpUtil;
+import cn.hutool.core.date.DatePattern;
+import cn.hutool.core.date.DateUtil;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.deepoove.poi.XWPFTemplate;
+import com.deepoove.poi.config.Configure;
+import com.deepoove.poi.config.ConfigureBuilder;
 import com.deepoove.poi.data.TextRenderData;
 import com.deepoove.poi.data.style.Style;
+import com.deepoove.poi.xwpf.NiceXWPFDocument;
 import com.fdkankan.fusion.common.ResultCode;
+import com.fdkankan.fusion.common.util.DateUtils;
+import com.fdkankan.fusion.common.util.XwpTemplateUtils;
 import com.fdkankan.fusion.entity.*;
 import com.fdkankan.fusion.exception.BusinessException;
 import com.fdkankan.fusion.mapper.ICaseInquestCriminalMapper;
@@ -16,6 +24,7 @@ import com.fdkankan.fusion.response.CaseInquestVo;
 import com.fdkankan.fusion.response.WitnessVo;
 import com.fdkankan.fusion.service.*;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.xwpf.usermodel.UnderlinePatterns;
 import org.springframework.beans.BeanUtils;
@@ -35,6 +44,7 @@ import java.util.List;
  * @since 2024-10-18
  */
 @Service
+@Slf4j
 public class CaseInquestCriminalServiceImpl extends ServiceImpl<ICaseInquestCriminalMapper, CaseInquestCriminal> implements ICaseInquestCriminalService {
 
     @Autowired
@@ -100,11 +110,12 @@ public class CaseInquestCriminalServiceImpl extends ServiceImpl<ICaseInquestCrim
             if(!byCaseId.isEmpty()){
                 CaseNumEntity caseNumEntity = byCaseId.get(0);
                 String num = caseNumEntity.getNum();
+                ScenePlus scenePlus = scenePlusService.getByNum(num);
+                if(scenePlus == null){
+                    log.info("设置案件勘验笔录失败-场景不存在:案件id:{},场景码:{}",caseInquestCriminal.getCaseId(),num);
+                    return;
+                }
                 if(caseInquestCriminal.getInquestTime() == null){
-                    ScenePlus scenePlus = scenePlusService.getByNum(num);
-                    if(scenePlus == null){
-                        return;
-                    }
                     wrapper.set(CaseInquestCriminal::getInquestTime,scenePlus.getCreateTime());
                     caseInquestCriminal.setInquestTime(scenePlus.getCreateTime());
                 }
@@ -156,21 +167,53 @@ public class CaseInquestCriminalServiceImpl extends ServiceImpl<ICaseInquestCrim
 
         CaseInquestCriminalVo vo = new CaseInquestCriminalVo();
         BeanUtils.copyProperties(caseInquest,vo);
-        String info = "证人或当事人(签名):%s  %s年 %s月 %s日 身份证件号码:%s\n"
-                +"   单位或住址:%s\n";
-        StringBuilder msg = new StringBuilder();
-        for (Object object : vo.getWitnessInfo()) {
+
+        //[{"unit":"四维","name":"张三","typeLabel":"笔录人","type":0,"job":"植物一"}]
+        String recorderInfo = "%s:姓名 %s 单位 %s 职务 %s\n";
+        StringBuilder recorderInfoMsg = new StringBuilder();
+        for (Object object : vo.getRecorderInfo()) {
             JSONObject obj = (JSONObject) object;
-            WitnessVo witnessVo = JSONObject.toJavaObject(obj,WitnessVo.class);
-            String format = String.format(info, witnessVo.getName(), witnessVo.getYear(), witnessVo.getMonth(), witnessVo.getDay(), witnessVo.getId(), witnessVo.getAddress());
-            msg.append(format);
+            String format = String.format(recorderInfo,obj.getString("typeLabel"), obj.getString("name"), obj.getString("unit"), obj.getString("job"));
+            recorderInfoMsg.append(format);
         }
-        TextRenderData text = new TextRenderData("000000",msg.toString());
+        TextRenderData text = new TextRenderData("000000",recorderInfoMsg.toString());
         Style style = text.getStyle();
         style.setUnderlinePatterns(UnderlinePatterns.SINGLE);
-        vo.setText(text);
+        vo.setRecorderInfoText(text);
 
-        XWPFTemplate template = XWPFTemplate.compile(inputStream).render(vo);
-        return template;
+        //[{"unit":"四维","job":"植物一"}]
+        String signatureInfo = "本人签名:        单位 %s 职务 %s\n";
+        StringBuilder signatureInfoMsg = new StringBuilder();
+        for (Object object : vo.getSignatureInfo()) {
+            JSONObject obj = (JSONObject) object;
+            String format = String.format(signatureInfo, obj.getString("unit"), obj.getString("job"));
+            signatureInfoMsg.append(format);
+        }
+        TextRenderData text2 = new TextRenderData("000000",signatureInfoMsg.toString());
+        Style style2 = text2.getStyle();
+        style2.setUnderlinePatterns(UnderlinePatterns.SINGLE);
+        vo.setSignatureInfoText(text2);
+
+        //[{"birthday":"2024-10-15T16:00:00.000Z","address":"dfsdfdsdsdsdsds","sex":0}]
+        String witnessInfo = "本人签名        性别 %s 出生日期 %s 住址 %s\n";
+        StringBuilder witnessInfoMsg = new StringBuilder();
+        for (Object object : vo.getWitnessInfo()) {
+            JSONObject obj = (JSONObject) object;
+            String format = String.format(witnessInfo, XwpTemplateUtils.getSexStr(obj.getInteger("sex")), DateUtil.format(obj.getDate("birthday"), DatePattern.CHINESE_DATE_FORMAT),obj.getString("address"));
+            witnessInfoMsg.append(format);
+        }
+        TextRenderData text3 = new TextRenderData("000000",witnessInfoMsg.toString());
+        Style style3 = text3.getStyle();
+        style3.setUnderlinePatterns(UnderlinePatterns.SINGLE);
+        vo.setWitnessInfoText(text3);
+
+        ConfigureBuilder builder = Configure.builder();
+        builder.useSpringEL(false);
+        //builder.setValidErrorHandler(new Configure.DiscardHandler());
+        XWPFTemplate compile = XWPFTemplate.compile(inputStream, builder.build());
+        compile.render(vo);
+        return compile;
     }
+
+
 }

BIN
src/main/resources/template/inquest_criminal-template.docx