zero 9 meses atrás
pai
commit
eba762a587

+ 47 - 0
src/main/java/cn/cslg/pas/common/core/GlobalException.java

@@ -0,0 +1,47 @@
+package cn.cslg.pas.common.core;
+
+import cn.cslg.pas.common.core.exception.PermissionException;
+import cn.cslg.pas.common.utils.Response;
+import cn.cslg.pas.common.utils.ResponseEnum;
+import cn.cslg.pas.exception.XiaoShiException;
+import cn.dev33.satoken.exception.NotLoginException;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+
+
+/**
+ * 全局异常处理
+ */
+@Slf4j
+@RestControllerAdvice // 可指定包前缀,比如:(basePackages = "com.pj.admin")
+public class GlobalException {
+
+    // 全局异常拦截(拦截项目中的所有异常)
+    @ExceptionHandler
+    public String handlerException(Exception e, HttpServletRequest request, HttpServletResponse response) throws Exception {
+        // 打印堆栈,以供调试
+        e.printStackTrace();
+        if (e instanceof NotLoginException) {
+            return Response.error(ResponseEnum.UNAUTHORIZED);
+        } else if (e instanceof PermissionException) {
+            return Response.error(ResponseEnum.NOT_PERMISSION);
+        } else {
+            return Response.error(ResponseEnum.SYSTEM_ERROR);
+        }
+    }
+
+    //小世异常
+    @ExceptionHandler
+    public Response handlerXiaoShiException(XiaoShiException e) {
+        log.info("全局异常处理机制捕获到XiaoShiException,异常信息提示为:{}", e.getErrorCode() + "--" + e.getMessage());
+        if (StringUtils.isNotEmpty(e.getErrorCode())) {
+            return Response.error(e.getErrorCode(), e.getErrorMessage());
+        } else {
+            return Response.error(e.getMessage());
+        }
+    }
+}

+ 1 - 1
src/main/java/cn/cslg/pas/common/utils/CacheUtils.java

@@ -29,7 +29,7 @@ public class CacheUtils {
 
     public PersonnelVO getLoginUser(Object userId) {
         String json = redisUtil.get(RedisConf.LOGIN_USER + RedisConf.SYMBOL_COLON + userId);
-        if (StringUtils.isEmpty(json)) {
+        if (Boolean.TRUE.equals(StringUtils.isEmpty(json))) {
             throw new XiaoShiException(ExceptionEnum.LOGIN_NO_LOGIN,"未登录");
         } else {
             return com.alibaba.fastjson2.JSONObject.parseObject(json, PersonnelVO.class);

+ 44 - 7
src/main/java/cn/cslg/pas/service/ReportExportService.java

@@ -18,8 +18,10 @@ import cn.cslg.pas.domain.es.Patent;
 import cn.cslg.pas.domain.es.PatentPerson;
 import cn.cslg.pas.domain.es.Priorities;
 import cn.cslg.pas.domain.es.Text;
+import cn.cslg.pas.exception.ExceptionEnum;
 import cn.cslg.pas.exception.XiaoShiException;
 import cn.cslg.pas.mapper.AvoidDesignMapper;
+import cn.cslg.pas.mapper.ProjectMapper;
 import cn.cslg.pas.service.business.*;
 import cn.cslg.pas.service.business.es.*;
 import cn.cslg.pas.service.business.invalidReport.AssoReasonLiteratureService;
@@ -38,6 +40,7 @@ import com.deepoove.poi.data.Pictures;
 import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.ddr.poi.html.HtmlRenderPolicy;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -104,6 +107,8 @@ public class ReportExportService {
     private EvidenceReasonService evidenceReasonService;
     @Autowired
     private TortCompareRecordService tortCompareRecordService;
+    @Autowired
+    private ProjectMapper projectMapper;
 
     /**
      * @param projectId
@@ -117,9 +122,16 @@ public class ReportExportService {
         ReportTemple reportTemplate = templeService.getById(templeId);
         //获得模板路径
         String templateFilePath = fileUtils.getPath(reportTemplate.getTemplatePath());
-
+        //获取项目名称
+        String name = "";
+        Project project = projectMapper.selectById(projectId);
+        if (ObjectUtils.isNotEmpty(project) && StringUtils.isNotEmpty(project.getName())) {
+            name = project.getName();
+        } else {
+            name = IdUtil.simpleUUID();
+        }
         //读取模板后保存生成word的地址
-        String fileName = IdUtil.simpleUUID() + ".docx";
+        String fileName = name + ".docx";
         String directoryName = fileUtils.createDirectory();
         String outPath = fileUtils.getSavePath(directoryName) + fileName;
 
@@ -317,7 +329,12 @@ public class ReportExportService {
         HtmlRenderPolicy htmlRenderPolicy = new HtmlRenderPolicy();
         // 将bz设置为行循环绑定的数据源的key,即key是bz的value会在模板中的{{bz}}处进行解析
         Configure configure = Configure.builder().bind("cM", policy).bind("targetDescription", htmlRenderPolicy).bind("compareDescription",htmlRenderPolicy).build();
-        XWPFTemplate template = XWPFTemplate.compile(filePath, configure).render(map1);
+        XWPFTemplate template = null;
+        try {
+            template = XWPFTemplate.compile(filePath, configure).render(map1);
+        } catch (Exception e) {
+            throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR,"未匹配到模版文件");
+        }
         return template;
     }
 
@@ -355,7 +372,12 @@ public class ReportExportService {
                 .bind("littleDirection", htmlRenderPolicy)
                 .bind("wholeDirection", htmlRenderPolicy)
                 .build();
-        XWPFTemplate template = XWPFTemplate.compile(path, configure).render(new HashMap<>());
+        XWPFTemplate template = null;
+        try {
+            template = XWPFTemplate.compile(path, configure).render(new HashMap<>());
+        } catch (Exception e) {
+            throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR,"未匹配到模版文件");
+        }
         return template;
     }
 
@@ -591,7 +613,12 @@ public class ReportExportService {
         HtmlRenderPolicy htmlRenderPolicy = new HtmlRenderPolicy();
         // 将bz设置为行循环绑定的数据源的key,即key是bz的value会在模板中的{{bz}}处进行解析
         Configure configure = Configure.builder().bind("cM", policy).bind("targetDescription", htmlRenderPolicy).build();
-        XWPFTemplate template = XWPFTemplate.compile(filePath, configure).render(map);
+        XWPFTemplate template = null;
+        try {
+            template = XWPFTemplate.compile(filePath, configure).render(map);
+        } catch (Exception e) {
+            throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR,"未匹配到模版文件");
+        }
         return template;
 
     }
@@ -988,7 +1015,12 @@ public class ReportExportService {
                 .bind("remark", htmlRenderPolicy)
                 .build();
         // 读取模板、数据并渲染
-        XWPFTemplate template = XWPFTemplate.compile(filePath, configure).render(map);
+        XWPFTemplate template = null;
+        try {
+            template = XWPFTemplate.compile(filePath, configure).render(map);
+        } catch (Exception e) {
+            throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR,"未匹配到模版文件");
+        }
         return template;
     }
 
@@ -1378,7 +1410,12 @@ public class ReportExportService {
                 .bind("remark", htmlRenderPolicy)
                 .build();
         // 读取模板、数据并渲染
-        XWPFTemplate template = XWPFTemplate.compile(filePath, configure).render(map);
+        XWPFTemplate template = null;
+        try {
+            template = XWPFTemplate.compile(filePath, configure).render(map);
+        } catch (Exception e) {
+            throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR,"未匹配到模版文件");
+        }
         return template;
     }
 }

BIN
src/main/resources/file/reportTemple/FTOTemplate1-chinese.docx


+ 7 - 0
src/main/resources/jsons/patent.json

@@ -1349,6 +1349,7 @@
     "ifSearch": "false",
     "ifGroup": "false",
     "ifShow": "false",
+    "ifSort": "false",
     "ifAsCondition": "true"
   },
   {
@@ -1361,6 +1362,7 @@
     "ifSearch": "false",
     "ifGroup": "false",
     "ifShow": "false",
+    "ifSort": "false",
     "ifAsCondition": "true"
   },
   {
@@ -1373,6 +1375,7 @@
     "ifSearch": "false",
     "ifGroup": "false",
     "ifShow": "false",
+    "ifSort": "false",
     "ifAsCondition": "true"
   },
   {
@@ -1385,6 +1388,7 @@
     "ifSearch": "false",
     "ifGroup": "false",
     "ifShow": "false",
+    "ifSort": "false",
     "ifAsCondition": "true"
   },
   {
@@ -1397,6 +1401,7 @@
     "ifSearch": "false",
     "ifGroup": "false",
     "ifShow": "false",
+    "ifSort": "false",
     "ifAsCondition": "true"
   },
   {
@@ -1409,6 +1414,7 @@
     "ifSearch": "false",
     "ifGroup": "false",
     "ifShow": "false",
+    "ifSort": "false",
     "ifAsCondition": "false"
   },
   {
@@ -1421,6 +1427,7 @@
     "ifSearch": "false",
     "ifGroup": "false",
     "ifShow": "false",
+    "ifSort": "false",
     "ifAsCondition": "true"
   }
 ]