瀏覽代碼

4/13 patentExport

xiexiang 1 年之前
父節點
當前提交
a339a868a0

+ 59 - 0
src/main/java/com/example/xiaoshiweixinback/business/utils/ExcuteConfigUtils.java

@@ -0,0 +1,59 @@
+package com.example.xiaoshiweixinback.business.utils;
+
+import com.alibaba.fastjson.JSONArray;
+import com.example.xiaoshiweixinback.XiaoshiWeixinbackApplication;
+import com.example.xiaoshiweixinback.entity.vo.PatentExportVO;
+import org.springframework.boot.system.ApplicationHome;
+import org.springframework.stereotype.Service;
+
+import java.io.*;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+
+/**
+ * 解析配置utils
+ *
+ * @Author xiexiang
+ * @Date 2023/6/2
+ */
+@Service
+public class ExcuteConfigUtils {
+    public static final String FILE_SEPARATOR = System.getProperty("file.separator");
+    //解析配置utils
+    public static String excuteConfigJson() {
+        ApplicationHome ah = new ApplicationHome(XiaoshiWeixinbackApplication.class);
+        File file = ah.getSource();
+        String rootPath = file.getParentFile().toString() + FILE_SEPARATOR + "patentExport.json";
+        BufferedReader reader = null;
+        StringBuilder last = new StringBuilder();
+        InputStreamReader inputStreamReader;
+        try (FileInputStream fileInputStream = new FileInputStream(rootPath)) {
+            inputStreamReader = new InputStreamReader(fileInputStream, StandardCharsets.UTF_8);
+
+            reader = new BufferedReader(inputStreamReader);
+            String tempString;
+            while ((tempString = reader.readLine()) != null) {
+                last.append(tempString);
+            }
+            reader.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            if (reader != null) {
+                try {
+                    reader.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return last.toString();
+    }
+
+    //解析配置utils
+    public static List<PatentExportVO> excuteConfigVO() {
+        String config = ExcuteConfigUtils.excuteConfigJson();
+        List<PatentExportVO> patentExportVOS = JSONArray.parseArray(config,PatentExportVO.class);
+        return patentExportVOS;
+    }
+}

+ 18 - 3
src/main/java/com/example/xiaoshiweixinback/controller/PatentController.java

@@ -18,11 +18,18 @@ import com.example.xiaoshiweixinback.service.importPatent.ImportFromWebToEsServi
 import io.swagger.v3.oas.annotations.Operation;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.InputStreamResource;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.IOException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
 import java.util.List;
 
 
@@ -137,8 +144,16 @@ public class PatentController {
     //--------------------------导出专利-------------------------------
     @PostMapping(value = "/exportPatent")
     @Operation(summary = "导出专利数据")
-    public Response exportPatent(@RequestBody ExportPatentDTO exportPatentDTO) throws IOException {
-        String fileGuid = patentExportService.exportPatent(exportPatentDTO.getPatentNos());
-        return Response.success(fileGuid);
+    public ResponseEntity<InputStreamResource> exportPatent(@RequestBody ExportPatentDTO exportPatentDTO) throws IOException {
+        byte[] fileData = patentExportService.exportPatent(exportPatentDTO.getPatentNos());
+        //保存生成excel的地址
+        String fileName = "导出专利.xlsx";
+        //文件原始名中的中文字符可能会乱码,对文件名进行URL编码
+        String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.toString());
+        return ResponseEntity.ok().contentLength(fileData.length)
+                .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + encodedFileName + "\"")
+                .contentType(MediaType.parseMediaType("application/octet-stream"))
+                .body(new InputStreamResource(new ByteArrayInputStream(fileData)));
     }
+
 }

+ 35 - 37
src/main/java/com/example/xiaoshiweixinback/service/exportPatent/PatentExportService.java

@@ -51,41 +51,30 @@ public class PatentExportService {
      * @throws IOException
      */
     @Async
-    public String exportPatent(List<String> patentNos) throws IOException {
+    public byte[] exportPatent(List<String> patentNos) throws IOException {
         try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
-            String patentExportJson = CommonService.readJsonFile("patentExport.json");
-//            List<EsConfigVO> esConfigVOS = JSON.parseArray(json, EsConfigVO.class);
-//
-//            String esSelected = JsonUtils.objectToJson(EsVO.getSelected());
+            String patentExportJson = ExcuteConfigUtils.excuteConfigJson();
             //selected字符串转PatentExportVO集合
-            List<PatentExportVO> selected = Optional.ofNullable(JsonUtils.jsonToList(patentExportJson, PatentExportVO.class))
+            List<PatentExportVO> patentExportVOS = Optional.ofNullable(JsonUtils.jsonToList(patentExportJson, PatentExportVO.class))
                     .orElse(new ArrayList<>());
-            //导出文件名
-            if (selected.isEmpty()) {
-                throw new IllegalArgumentException("没有选择要导出的字段数据");
+            if (patentExportVOS.isEmpty()) {
+                throw new IllegalArgumentException("未解析出字段");
             }
-
-            //key的集合(标头:例如patentNo)
-            List<String> columns = selected.stream().filter(PatentExportVO::getSelected).map(PatentExportVO::getValue).distinct().collect(Collectors.toList());
-            //name的集合
-            List<String> headers = selected.stream().filter(PatentExportVO::getSelected).map(PatentExportVO::getName).distinct().collect(Collectors.toList());
+            //字段名 key的集合(标头:例如patentNo)
+            List<String> columns = patentExportVOS.stream().map(PatentExportVO::getValue).distinct().collect(Collectors.toList());
+            //中文 name的集合
+            List<String> headers = patentExportVOS.stream().map(PatentExportVO::getName).collect(Collectors.toList());
             if (columns.size() != headers.size()) {
-                throw new XiaoShiException("数不匹配");
+                throw new XiaoShiException("字段数不匹配");
             }
-            //新建工作簿
-            HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
-            //新建sheet页
-            HSSFSheet sheet = hssfWorkbook.createSheet();
+            HSSFWorkbook hssfWorkbook = new HSSFWorkbook();//新建工作簿
+            HSSFSheet sheet = hssfWorkbook.createSheet();//新建sheet页
             sheet.setDefaultColumnWidth(30);
-            //新建标头行
-            HSSFRow headerRow = sheet.createRow(0);
+            HSSFRow headerRow = sheet.createRow(0);//新建标头行
             headerRow.setHeight((short) 500);
-            //新建标头行格式
-            HSSFCellStyle headerCellStyle = hssfWorkbook.createCellStyle();
-            //新建普通行格式
-            HSSFCellStyle commonCellStyle = hssfWorkbook.createCellStyle();
-            //遍历设置标头
-            for (int i = 0; i < headers.size(); i++) {
+            HSSFCellStyle headerCellStyle = hssfWorkbook.createCellStyle();//新建标头行格式
+            HSSFCellStyle commonCellStyle = hssfWorkbook.createCellStyle();//新建普通行格式
+            for (int i = 0; i < headers.size(); i++) {//遍历设置标头
                 HSSFCell cell = headerRow.createCell(i);
                 ExcelUtils.setExcelCellStyle(headerCellStyle);
                 headerCellStyle.setAlignment(HorizontalAlignment.CENTER);
@@ -96,21 +85,31 @@ public class PatentExportService {
                 cell.setCellStyle(headerCellStyle);
                 cell.setCellValue(headers.get(i));
             }
+
+
             Integer total = patentNos.size();
             Integer defaultNum = 0;
+
+            //遍历专利号数量
             for (int i = 0; i < patentNos.size(); i++) {
                 Map<String, Object> map = new LinkedHashMap<>();
+
+                //获取专利信息
                 PatentColumnDTO patent = esPatentService.selectPatentByAppNo(patentNos.get(i));
                 if (patent == null) {
                     defaultNum++;
                     continue;
                 }
+
+                //遍历字段 配置map集合
                 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());
-                    // 使用反射获取属性值
+                    //解析出的patentExportVOS根据value匹配column字段,拿出对应字段的配置
+                    PatentExportVO patentExportVO = patentExportVOS.stream().filter(item -> item.getValue().equals(column)).findFirst().orElse(new PatentExportVO());
+                    //使用反射获取属性值  (例如:title->patent.getTitile())
                     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);
@@ -122,15 +121,18 @@ public class PatentExportService {
                         }
                     }
                 }
-                //新建一普通行
-                HSSFRow row = sheet.createRow(i + 1);
+
+                HSSFRow row = sheet.createRow(i + 1);//新建一普通行
                 row.setHeight((short) 800);
+
+
+                //填入数据
                 for (String key : map.keySet()) {
                     int index = headers.indexOf(key);
                     if (index != -1) {
                         HSSFCell cell = row.createCell(index);
                         ExcelUtils.setExcelCellStyle(commonCellStyle);
-                        commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                        commonCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
                         commonCellStyle.setWrapText(true);
                         cell.setCellStyle(commonCellStyle);
                         if (StringUtils.isNotNull(map.get(key))) {
@@ -140,11 +142,7 @@ public class PatentExportService {
                 }
             }
             hssfWorkbook.write(out);
-            String fileGuid = "";
-            if (out.toByteArray() != null && out.toByteArray().length != 0) {
-                fileGuid = parseByteToFileUtils.uploadFile(out.toByteArray(), 1);
-            }
-            return fileGuid;
+            return out.toByteArray();
         } catch (FileNotFoundException e) {
             throw new FileNotFoundException();
         }

File diff suppressed because it is too large
+ 1347 - 0
src/main/resources/jsons/patent.json


+ 348 - 5
src/main/resources/jsons/patentExport.json

@@ -1,14 +1,357 @@
 [
   {
-    "name": "申请号",
+    "name": "专利号",
     "type": "String",
-    "value": "appNo",
-    "exportClass": "getCommonValue"
+    "value": "patentNo"
+  },
+  {
+    "name": "标题",
+    "type": "Array",
+    "value": "title"
+  },
+  {
+    "name": "公开说明书文本",
+    "type": "Array",
+    "value": "publicFullText"
+  },
+  {
+    "name": "授权说明书文本",
+    "type": "Array",
+    "value": "grantFullText"
+  },
+  {
+    "name": "摘要",
+    "type": "Array",
+    "value": "abstractStr"
+  },
+  {
+    "name": "申请人地址 ",
+    "type": "Object",
+    "value": "applicantAddr"
+  },
+  {
+    "name": "申请人地址",
+    "type": "String",
+    "value": "appAddress"
   },
   {
     "name": "申请人国家",
     "type": "String",
-    "value": "applicantCountry",
-    "exportClass": "getCommonValue"
+    "value": "applicantCountry"
+  },
+  {
+    "name": "申请人省份",
+    "type": "String",
+    "value": "appProvince"
+  },
+  {
+    "name": "申请人市",
+    "type": "String",
+    "value": "appCity"
+  },
+  {
+    "name": "申请人县",
+    "type": "String",
+    "value": "appDistrict"
+  },
+  {
+    "name": "权利人地址",
+    "type": "String",
+    "value": "rightAddress"
+  },
+  {
+    "name": "权利人国家",
+    "type": "String",
+    "value": "rightCountry"
+  },
+  {
+    "name": "权利人省份",
+    "type": "String",
+    "value": "rightProvince"
+  },
+  {
+    "name": "权利人市",
+    "type": "String",
+    "value": "rightCity"
+  },
+  {
+    "name": "权利人县",
+    "type": "String",
+    "value": "rightDistrict"
+  },
+  {
+    "name": "权利人地址 ",
+    "type": "Object",
+    "value": "rightHolderAddr"
+  },
+  {
+    "name": "审查员",
+    "type": "String",
+    "value": "examiner"
+  },
+  {
+    "name": "助理审查员",
+    "type": "String",
+    "value": "aidExaminer"
+  },
+  {
+    "name": "实审日",
+    "type": "DateTime",
+    "value": "examinationDate"
+  },
+  {
+    "name": "公开号",
+    "type": "String",
+    "value": "publicNo"
+  },
+  {
+    "name": "公开日",
+    "type": "DateTime",
+    "value": "publicDate"
+  },
+  {
+    "name": "申请号",
+    "type": "String",
+    "value": "appNo"
+  },
+  {
+    "name": "申请日",
+    "type": "DateTime",
+    "value": "appDate"
+  },
+  {
+    "name": "授权号",
+    "type": "DateTime",
+    "value": "grantNo"
+  },
+  {
+    "name": "授权日",
+    "type": "DateTime",
+    "value": "grantDate"
+  },
+  {
+    "name": "优先权",
+    "type": "Array",
+    "value": "priorities"
+  },
+  {
+    "name": "申请国家",
+    "type": "DateTime",
+    "value": "appCountry"
+  },
+  {
+    "name": "IPC分类号(主)",
+    "type": "Object",
+    "value": "mipc"
+  },
+  {
+    "name": "ipc集合",
+    "type": "Array",
+    "value": "ipc"
+  },
+  {
+    "name": "CPC分类号(主)",
+    "type": "Object",
+    "value": "mcpc"
+  },
+  {
+    "name": "cpc集合",
+    "type": "Array",
+    "value": "cpc"
+  },
+  {
+    "name": "UPC分类号(主)",
+    "type": "Object",
+    "value": "mupc"
+  },
+  {
+    "name": "UPC集合",
+    "type": "Array",
+    "value": "upc"
+  },
+  {
+    "name": "UPC集合",
+    "type": "Array",
+    "value": "loc"
+  },
+  {
+    "name": "专利状态",
+    "type": "String",
+    "value": "simpleStatus"
+  },
+  {
+    "name": "类型",
+    "type": "String",
+    "value": "patentType"
+  },
+  {
+    "name": "权利要求",
+    "type": "Array",
+    "value": "claim"
+  },
+  {
+    "name": "pct申请号",
+    "type": "Integer",
+    "value": "pctAppDate"
+  },
+  {
+    "name": "pct申请日",
+    "type": "String",
+    "value": "pctAppNo"
+  },
+  {
+    "name": "pct进入日期",
+    "type": "Integer",
+    "value": "pctEnterDate"
+  },
+  {
+    "name": "pct公开日",
+    "type": "Integer",
+    "value": "pctPubDate"
+  },
+  {
+    "name": "pct公开号",
+    "type": "String",
+    "value": "pctPubNo"
+  },
+  {
+    "name": "wo指定国",
+    "type": "String",
+    "value": "wo"
+  },
+  {
+    "name": "ep申请号",
+    "type": "String",
+    "value": "epNo"
+  },
+  {
+    "name": "ep申请日",
+    "type": "String",
+    "value": "epDate"
+  },
+  {
+    "name": "EP指定国状态",
+    "type": "String",
+    "value": "epCountry"
+  },
+  {
+    "name": "申请人",
+    "type": "Array",
+    "value": "applicant"
+  },
+  {
+    "name": "标准申请人",
+    "type": "Array",
+    "value": "standerApplicant"
+  },
+  {
+    "name": "合并申请人",
+    "type": "Array",
+    "value": "mergeApplicant"
+  },
+  {
+    "name": "申请人数量",
+    "type": "Integer",
+    "value": "applicantsNum"
+  },
+  {
+    "name": "权利人",
+    "type": "Array",
+    "value": "rightHolder"
+  },
+  {
+    "name": "标准权利人",
+    "type": "Array",
+    "value": "standerRightHolder"
+  },
+  {
+    "name": "合并权利人",
+    "type": "Array",
+    "value": "mergeRightHolder"
+  },
+  {
+    "name": "权利人数量",
+    "type": "Integer",
+    "value": "rightHolderNum"
+  },
+  {
+    "name": "发明人",
+    "type": "Array",
+    "value": "inventor"
+  },
+  {
+    "name": "合并发明人",
+    "type": "Array",
+    "value": "mergeInventor"
+  },
+  {
+    "name": "发明人数量",
+    "type": "Integer",
+    "value": "inventor_num"
+  },
+  {
+    "name": "代理机构",
+    "type": "String",
+    "value": "agency"
+  },
+  {
+    "name": "代理机构编号",
+    "type": "String",
+    "value": "agencyNo"
+  },
+  {
+    "name": "代理人",
+    "type": "Array",
+    "value": "agent"
+  },
+  {
+    "name": "引用专利数量",
+    "type": "Integer",
+    "value": "quotePatentNoNum"
+  },
+  {
+    "name": "被引用专利数量",
+    "type": "Integer",
+    "value": "quotedPatentNoNum"
+  },
+  {
+    "name": "自定义栏位",
+    "type": "Array",
+    "value": "ESCustomField"
+  },
+  {
+    "name": "扩展同族数量",
+    "type": "Integer",
+    "value": "patsnapFamilyNum"
+  },
+  {
+    "name": "扩展同族id",
+    "type": "String",
+    "value": "patsnapFamilyId"
+  },
+  {
+    "name": "INPADOC同族数量",
+    "type": "Integer",
+    "value": "inpadocFamilyNum"
+  },
+  {
+    "name": "INPADOC同族id",
+    "type": "String",
+    "value": "inpadocFamilyId"
+  },
+  {
+    "name": "简单同族数量",
+    "type": "Integer",
+    "value": "simpleFamilyNum"
+  },
+  {
+    "name": "简单同族id",
+    "type": "String",
+    "value": "simpleFamilyId"
+  },
+  {
+    "name": "外部专利的原始申请号",
+    "type": "String",
+    "value": "rowApplicationNo"
   }
 ]