浏览代码

5/22 导入导出报告修改

lwhhszx 1 年之前
父节点
当前提交
c8dca14f5a

+ 58 - 0
src/main/java/cn/cslg/pas/common/utils/FileUtils.java

@@ -2,6 +2,7 @@ package cn.cslg.pas.common.utils;
 
 
 
 
 import cn.cslg.pas.Application;
 import cn.cslg.pas.Application;
+import cn.cslg.pas.common.vo.business.PatentProjectVO;
 import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.IdUtil;
 import org.apache.commons.fileupload.FileItem;
 import org.apache.commons.fileupload.FileItem;
 import org.apache.commons.fileupload.disk.DiskFileItemFactory;
 import org.apache.commons.fileupload.disk.DiskFileItemFactory;
@@ -210,4 +211,61 @@ public class FileUtils {
     public String getSystemPath(String url) {
     public String getSystemPath(String url) {
         return getStaticPath(COMMON_FILE) + FILE_SEPARATOR + url;
         return getStaticPath(COMMON_FILE) + FILE_SEPARATOR + url;
     }
     }
+
+    public static void  writeObjectToFile(Object object, String url) {
+        //根据projectId查询对象
+        try {
+            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(url));
+            oos.writeObject(object);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+    }
+
+
+
+
+    public String readJson(String jsonPath) {
+        File jsonFile = new File(jsonPath);
+        try {
+            FileReader fileReader = new FileReader(jsonFile);
+            BufferedReader reader = new BufferedReader(fileReader);
+            StringBuilder sb = new StringBuilder();
+            while (true) {
+                int ch = reader.read();
+                if (ch != -1) {
+                    sb.append((char) ch);
+                } else {
+                    break;
+                }
+            }
+            fileReader.close();
+            reader.close();
+            return sb.toString();
+        } catch (IOException e) {
+            return "";
+        }
+    }
+
+
+    public static String writeJson(String jsonPath, Object object) {
+        // Map数据转化为Json,再转换为String
+        String data =JsonUtils.objectToJson(object);
+        File jsonFile = new File(jsonPath);
+        try {
+            // 文件不存在就创建文件
+            if (!jsonFile.exists()) {
+                jsonFile.createNewFile();
+            }
+            FileWriter fileWriter = new FileWriter(jsonFile.getAbsoluteFile(),false);
+            BufferedWriter bw = new BufferedWriter(fileWriter);
+            bw.write(data);
+            bw.close();
+            return "success";
+        } catch (IOException e) {
+            return "error";
+        }
+    }
 }
 }

+ 4 - 3
src/main/java/cn/cslg/pas/controller/ExportProjectController.java

@@ -7,6 +7,7 @@ import cn.cslg.pas.service.exportProject.ImportProjectService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Operation;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.bind.annotation.RestController;
@@ -25,9 +26,9 @@ public class ExportProjectController {
     @Autowired
     @Autowired
     private ImportProjectService importProjectService;
     private ImportProjectService importProjectService;
     @Operation(summary = "查询无效理由")
     @Operation(summary = "查询无效理由")
-    @PostMapping("/writeProjectToFile")
-    public Response writeProjectToFile() {
-        exportProjectService.exportProject(281);
+    @GetMapping("/writeProjectToFile")
+    public Response writeProjectToFile(Integer projectId) {
+        exportProjectService.exportProject(projectId);
         return Response.success("");
         return Response.success("");
     }
     }
 
 

+ 15 - 13
src/main/java/cn/cslg/pas/service/exportProject/ExportProjectService.java

@@ -28,10 +28,7 @@ import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
+import java.io.*;
 import java.util.ArrayList;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
@@ -68,8 +65,6 @@ public class ExportProjectService {
 
 
         this.writeProjectToFile(projectId, url);
         this.writeProjectToFile(projectId, url);
         this.getPatentsFromEs(projectId,url);
         this.getPatentsFromEs(projectId,url);
-        List<CustomField> customFields = this.getCustomFiled(projectId, url);
-        this.getCustomFiledLabel(customFields, url);
         String outUrl = FileUtils.getStaticPath("");
         String outUrl = FileUtils.getStaticPath("");
         String trueOutUrl = outUrl + "\\" + directoryName + ".zip";
         String trueOutUrl = outUrl + "\\" + directoryName + ".zip";
         ZipUtil.zip(url, trueOutUrl);
         ZipUtil.zip(url, trueOutUrl);
@@ -82,8 +77,7 @@ public class ExportProjectService {
         try {
         try {
             PatentProjectVO patentProjectVO=patentProjectService.getPatentProjectVOById(projectId);
             PatentProjectVO patentProjectVO=patentProjectService.getPatentProjectVOById(projectId);
             String projectUrl = url + "\\project.json";
             String projectUrl = url + "\\project.json";
-            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(projectUrl));
-            oos.writeObject(patentProjectVO);
+           FileUtils.writeJson(projectUrl,patentProjectVO);
 
 
         } catch (Exception e) {
         } catch (Exception e) {
             e.printStackTrace();
             e.printStackTrace();
@@ -136,12 +130,20 @@ public class ExportProjectService {
                     queryRequests.add(queryRequest1);
                     queryRequests.add(queryRequest1);
 
 
                 }
                 }
-                String customFiledUrl = url + "\\patent" + index + ".json";
-                try {
-                    ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(customFiledUrl));
-                    oos.writeObject(patents);
-                } catch (Exception e) {
+                for(PatentColumnDTO patent:patents){
+                    String appNo =patent.getAppNo();
+                    String patentDirectoryName =url+"\\"+appNo;
+                    File patentDirectory =new File(patentDirectoryName);
+                    if(!patentDirectory.exists())
+                    {
+                        patentDirectory.mkdir();
+                    }
+                    String patentName ="patentCategory.json";
+                    String patentCategoryUrl =patentDirectoryName+"\\"+patentName;
+
+                    FileUtils.writeJson(patentCategoryUrl,patent);
                 }
                 }
+
             }
             }
         } catch (Exception e) {
         } catch (Exception e) {
             e.printStackTrace();
             e.printStackTrace();

+ 3 - 3
src/main/resources/application-dev.yml

@@ -61,12 +61,12 @@ spring:
     #初始化表结构
     #初始化表结构
     jdbc:
     jdbc:
       initialize-schema: always
       initialize-schema: always
-authorUrl: http://localhost:8871
-PCSUrl: http://localhost:8871
+authorUrl: http://localhost:8880
+PCSUrl: http://localhost:8880
 #OPSUrl: http://192.168.2.24:5001
 #OPSUrl: http://192.168.2.24:5001
 OPSUrl: http://139.224.24.90:5001
 OPSUrl: http://139.224.24.90:5001
 PASUrl: http://localhost:8879
 PASUrl: http://localhost:8879
-FMSUrl: http://localhost:8802
+FMSUrl: http://localhost:8885
 FileSource: 1
 FileSource: 1
 ES:
 ES:
   patentVector: patent_vector
   patentVector: patent_vector

+ 1 - 1
src/main/resources/application-testNetIn.yml

@@ -66,7 +66,7 @@ PCSUrl: http://localhost:8880
 #OPSUrl: http://192.168.1.24:5001
 #OPSUrl: http://192.168.1.24:5001
 OPSUrl: http://139.224.24.90:5001
 OPSUrl: http://139.224.24.90:5001
 PASUrl: http://localhost:8880
 PASUrl: http://localhost:8880
-FMSUrl: http://localhost:8885
+FMSUrl: http://localhost:8801
 FileSource: 3
 FileSource: 3
 ES:
 ES:
   patentVector: patent_vector
   patentVector: patent_vector