Kaynağa Gözat

Merge remote-tracking branch 'origin/master'

lwhhszx 1 yıl önce
ebeveyn
işleme
f6560da468

+ 41 - 0
src/main/java/cn/cslg/pas/factorys/PatentExportFactory/GetPatentTypeValue.java

@@ -0,0 +1,41 @@
+package cn.cslg.pas.factorys.PatentExportFactory;
+
+import org.springframework.stereotype.Component;
+
+/**
+ * @Author xiexiang
+ * @Date 2024/6/6
+ */
+@Component
+public class GetPatentTypeValue implements GetValueImp {
+    @Override
+    public String getValue(Object value) {
+        String patentTypeStr = "";
+        if (value != null) {
+            try {
+                int patentType = Integer.parseInt(value.toString());
+
+                switch (patentType) {
+                    case 1:
+                    case 8:
+                        patentTypeStr = "发明";
+                        break;
+                    case 2:
+                    case 9:
+                        patentTypeStr = "实用新型";
+                        break;
+                    case 3:
+                        patentTypeStr = "外观";
+                        break;
+                    default:
+                        patentTypeStr = "";
+                        break;
+                }
+            } catch (NumberFormatException e) {
+                // 处理无法解析为整数的情况
+                patentTypeStr = "";
+            }
+        }
+        return patentTypeStr;
+    }
+}

+ 39 - 0
src/main/java/cn/cslg/pas/factorys/PatentExportFactory/GetSimpleStatusValue.java

@@ -0,0 +1,39 @@
+package cn.cslg.pas.factorys.PatentExportFactory;
+
+import org.springframework.stereotype.Component;
+
+/**
+ * @Author xiexiang
+ * @Date 2024/6/6
+ */
+@Component
+public class GetSimpleStatusValue implements GetValueImp {
+    @Override
+    public String getValue(Object value) {
+        String statusStr = "";
+        if (value != null) {
+            try {
+                int simpleStatus = Integer.parseInt(value.toString());
+
+                switch (simpleStatus) {
+                    case 1:
+                        statusStr = "有效";
+                        break;
+                    case 2:
+                        statusStr = "无效";
+                        break;
+                    case 3:
+                        statusStr = "审中";
+                        break;
+                    default:
+                        statusStr = "";
+                        break;
+                }
+            } catch (NumberFormatException e) {
+                // 处理无法解析为整数的情况
+                statusStr = "";
+            }
+        }
+        return statusStr;
+    }
+}

+ 40 - 1
src/main/java/cn/cslg/pas/service/business/PDFExportFirstPageService.java

@@ -22,6 +22,10 @@ import org.apache.pdfbox.multipdf.PDFMergerUtility;
 import org.apache.pdfbox.io.MemoryUsageSetting;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDPage;
+import org.apache.pdfbox.pdmodel.PDPageContentStream;
+import org.apache.pdfbox.pdmodel.common.PDRectangle;
+import org.apache.pdfbox.pdmodel.font.PDFont;
+import org.apache.pdfbox.pdmodel.font.PDType1Font;
 import org.apache.pdfbox.rendering.PDFRenderer;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
@@ -65,12 +69,12 @@ public class PDFExportFirstPageService {
         List<String> patentNos = this.getPatentNo(EsVO);
         Integer total = patentNos.size();
         Integer defaultNum = 0;
-
         PDFMergerUtility merger = new PDFMergerUtility();
         PDDocument resultDocument = new PDDocument();
         for (int i = 0; i < patentNos.size(); i++) {
             PatentNoVO patentNoVO = new PatentNoVO();
             patentNoVO.setPatentNo(patentNos.get(i));
+            patentNoVO.setProjectId(exportTask.getProjectId());
             PatentColumnDTO patentColumnDTO = new PatentColumnDTO();
             try {
                 patentColumnDTO = patentService.selectPatentDetail(patentNoVO);
@@ -94,6 +98,11 @@ public class PDFExportFirstPageService {
                             String pdfGuid2 = FormatUtil.getPDFFormat(appNo, type2);
                             pdfData = fileManagerService.downloadSystemFileFromFMS(pdfGuid2);
                             if (pdfData == null || pdfData.length == 0) {
+                                // 创建一个空白页文档 内容为暂无文档
+                                PDDocument blankPageDocument = createBlankPageDocument();
+                                merger.appendDocument(resultDocument, blankPageDocument);
+                                // 不需要关闭 blankPageDocument,因为在保存 resultDocument 时会处理它
+                                // 同样,根据这个修改更新任何相关的 WebSocketMessageVO 或代码其他部分。
                                 defaultNum++;
                                 continue;
                             } else {
@@ -183,6 +192,36 @@ public class PDFExportFirstPageService {
     }
 
     /**
+     * 创建一个空白pdf文档 内容为”暂无文档“
+     * @return
+     * @throws IOException
+     */
+    private PDDocument createBlankPageDocument() throws IOException {
+        PDDocument document = new PDDocument();
+        PDPage blankPage = new PDPage();
+        document.addPage(blankPage);
+
+        try (PDPageContentStream contentStream = new PDPageContentStream(document, blankPage)) {
+            // 加载适当的字体
+            PDFont font = PDType1Font.HELVETICA_BOLD;
+            contentStream.setFont(font, 30);
+
+            String text = "NO DOCUMENTS";
+            float textWidth = font.getStringWidth(text) / 1000 * 30;
+            PDRectangle pageSize = blankPage.getMediaBox();
+            float startX = (pageSize.getWidth() - textWidth) / 2;
+            float startY = pageSize.getHeight() / 2;
+
+            //居中
+            contentStream.beginText();
+//            contentStream.setLeading(14.5f);
+            contentStream.newLineAtOffset(startX, startY);
+            contentStream.showText(text);
+            contentStream.endText();
+        }
+        return document;
+    }
+    /**
      * 获取专利号
      * @param EsVO
      * @return

+ 79 - 19
src/main/java/cn/cslg/pas/service/business/PatentExportService.java

@@ -3,15 +3,21 @@ package cn.cslg.pas.service.business;
 import cn.cslg.pas.common.dto.ExportTaskDTO;
 import cn.cslg.pas.common.dto.PatentColumnDTO;
 import cn.cslg.pas.common.dto.PatentExport.PatentExportVO;
+import cn.cslg.pas.common.dto.es.EsQueryPatentFieldsDTO;
+import cn.cslg.pas.common.dto.es.InnerFields;
 import cn.cslg.pas.common.utils.*;
 import cn.cslg.pas.common.vo.ConfigVOS.PatentConfigVO;
+import cn.cslg.pas.common.vo.FieldValueVO;
 import cn.cslg.pas.common.vo.WebSocketMessageVO;
 import cn.cslg.pas.common.vo.business.PatentNoVO;
 import cn.cslg.pas.common.vo.es.EsCustomFieldBatchVO;
+import cn.cslg.pas.common.vo.es.EsPatentFieldsVO;
+import cn.cslg.pas.common.vo.es.InnerPatentFieldsVO;
 import cn.cslg.pas.domain.business.ImportTask;
 import cn.cslg.pas.exception.XiaoShiException;
 import cn.cslg.pas.factorys.PatentExportFactory.GetValueImp;
 import cn.cslg.pas.factorys.PatentExportFactory.PatentExportFactory;
+import cn.cslg.pas.service.business.es.EsCustomFieldService;
 import cn.cslg.pas.service.business.es.EsPatentService;
 import cn.cslg.pas.service.common.MessageService;
 import com.alibaba.fastjson.JSON;
@@ -58,6 +64,9 @@ public class PatentExportService {
     @Autowired
     private ImportTaskService importTaskService;
 
+    @Autowired
+    private EsCustomFieldService esCustomFieldService;
+
     /**
      * 导出专利
      *
@@ -79,12 +88,21 @@ public class PatentExportService {
             }
 
             //key的集合(标头:例如patentNo)
-            List<String> columns = selected.stream().filter(PatentExportVO::getSelected).map(PatentExportVO::getValue).distinct().collect(Collectors.toList());
+            List<PatentExportVO> patentExportVOS = selected.stream()
+                    .filter(PatentExportVO::getSelected)
+                    .collect(Collectors.toList());
+            List<String> types = Arrays.asList("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10");
+            List<InnerFields> innerFieldsList = new ArrayList<>();
+            for (PatentExportVO patentExportVO : patentExportVOS) {
+                if (types.contains(patentExportVO.getType())) {
+                    InnerFields innerFields = new InnerFields();
+                    innerFields.setFieldId(patentExportVO.getValue());
+                    innerFields.setFieldType(Integer.parseInt(patentExportVO.getType()));
+                    innerFieldsList.add(innerFields);
+                }
+            }
             //name的集合
             List<String> headers = selected.stream().filter(PatentExportVO::getSelected).map(PatentExportVO::getName).distinct().collect(Collectors.toList());
-            if (columns.size() != headers.size()) {
-                throw new XiaoShiException("数量不匹配");
-            }
             //新建工作簿
             HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
             //新建sheet页
@@ -117,29 +135,68 @@ public class PatentExportService {
             Integer total = patentNos.size();
             Integer defaultNum = 0;
             for (int i = 0; i < patentNos.size(); i++) {
+                String patentNo = patentNos.get(i);
                 Map<String, Object> map = new LinkedHashMap<>();
                 PatentNoVO patentNoVO = new PatentNoVO();
-                patentNoVO.setPatentNo(patentNos.get(i));
+                patentNoVO.setPatentNo(patentNo);
                 patentNoVO.setProjectId(exportTask.getProjectId());
                 PatentColumnDTO patent = patentService.selectPatentDetail(patentNoVO);
                 if (patent == null) {
                     defaultNum++;
                     continue;
                 }
-                for (int j = 0; j < columns.size(); j++) {
-                    String column = columns.get(j);
-                    PatentExportVO patentExportVO = selected.stream().filter(item -> item.getValue().equals(column)).findFirst().orElse(new PatentExportVO());
-                    // 使用反射获取属性值
-                    Object value = GenerateObjectUtil.getPropertyValue(patent, patentExportVO.getValue());
-                    if (value != null) {
-                        String json = CommonService.readJsonFile("patent.json");
-                        List<PatentConfigVO> patentConfigVOS = JSON.parseArray(json, PatentConfigVO.class);
-                        PatentConfigVO patentConfigVO = patentConfigVOS.stream().filter(item -> item.getValue().equals(column)).findFirst().orElse(null);
-                        String exportClass = patentConfigVO.getExportClass();
-                        GetValueImp getValueImp = patentExportFactory.getClass(exportClass);
-                        if (getValueImp != null) {
-                            String reValue = getValueImp.getValue(value);
-                            map.put(patentExportVO.getName(), reValue);
+
+                EsQueryPatentFieldsDTO esQueryPatentFieldsDTO = new EsQueryPatentFieldsDTO();
+                esQueryPatentFieldsDTO.setProjectId(exportTask.getProjectId());
+                esQueryPatentFieldsDTO.setTaskId(EsVO.getTaskId());
+                esQueryPatentFieldsDTO.setPatentNos(patentNos);
+                esQueryPatentFieldsDTO.setInnerFields(innerFieldsList);
+                List<EsPatentFieldsVO> list = esCustomFieldService.getPatentFields(esQueryPatentFieldsDTO);
+
+
+                for (int j = 0; j < patentExportVOS.size(); j++) {
+                    String column = patentExportVOS.get(j).getValue();
+                    String name = patentExportVOS.get(j).getName();
+                    String type = patentExportVOS.get(j).getType();
+
+                    if (types.contains(type)) {
+                        EsPatentFieldsVO esPatentFieldsVO = list.stream()
+                                .filter(item -> item.getPatentNo().equals(patentNo))
+                                .findFirst()
+                                .orElse(null);
+                        if (esPatentFieldsVO != null) {
+                            List<InnerPatentFieldsVO> innerClassFields = esPatentFieldsVO.getInnerClassFields();
+                            if (!innerClassFields.isEmpty()) {
+                                InnerPatentFieldsVO innerPatentFieldsVO = innerClassFields.stream()
+                                        .filter(item -> item.getField().equals(column) && item.getFieldType().equals(Integer.parseInt(type)))
+                                        .findFirst()
+                                        .orElse(null);
+                                if (innerPatentFieldsVO != null) {
+                                    List<FieldValueVO> fieldValueVOS = innerPatentFieldsVO.getFieldValueVOS();
+                                    if (!fieldValueVOS.isEmpty()) {
+                                        StringBuffer sb = new StringBuffer();
+                                        for (FieldValueVO fieldValueVO : fieldValueVOS) {
+                                            String valueStr = fieldValueVO.getValue();
+                                            sb.append(valueStr);
+                                        }
+                                        map.put(name, sb.toString());
+                                    }
+                                }
+                            }
+                        }
+                    } else {
+                        // 使用反射获取属性值
+                        Object value = GenerateObjectUtil.getPropertyValue(patent, column);
+                        if (value != null) {
+                            String json = CommonService.readJsonFile("patent.json");
+                            List<PatentConfigVO> patentConfigVOS = JSON.parseArray(json, PatentConfigVO.class);
+                            PatentConfigVO patentConfigVO = patentConfigVOS.stream().filter(item -> item.getValue().equals(column)).findFirst().orElse(null);
+                            String exportClass = patentConfigVO.getExportClass();
+                            GetValueImp getValueImp = patentExportFactory.getClass(exportClass);
+                            if (getValueImp != null) {
+                                String reValue = getValueImp.getValue(value);
+                                map.put(name, reValue);
+                            }
                         }
                     }
                 }
@@ -192,8 +249,11 @@ public class PatentExportService {
             if (taskId == null) {
                 throw new XiaoShiException("导出记录失败");
             }
+
         } catch (FileNotFoundException e) {
             throw new FileNotFoundException();
+        } catch (Exception e) {
+
         }
     }
 

+ 2 - 2
src/main/resources/jsons/patent.json

@@ -1039,7 +1039,7 @@
     "fieldOptionQueryParam": "PATENT_SIMPLE_STATUS",
     "groupBy": "typeStatus",
     "ifSort": "true",
-    "exportClass": "getCommonValue",
+    "exportClass": "getSimpleStatusValue",
     "optionValue": [
       {
         "label": "有效",
@@ -1070,7 +1070,7 @@
     "fieldOptionQueryParam": "PATENT_TYPE",
     "groupBy": "typeStatus",
     "ifSort": "true",
-    "exportClass": "getCommonValue",
+    "exportClass": "getPatentTypeValue",
     "optionValue": [
       {
         "label": "发明",