|
@@ -0,0 +1,84 @@
|
|
|
+package cn.cslg.pas.service.business;
|
|
|
+
|
|
|
+import cn.cslg.pas.common.dto.PatentDTO;
|
|
|
+import cn.cslg.pas.common.dto.business.PatentProjectDTO;
|
|
|
+import cn.cslg.pas.common.model.request.QueryRequest;
|
|
|
+import cn.cslg.pas.common.model.request.StringRequest;
|
|
|
+import cn.cslg.pas.common.utils.FileUtils;
|
|
|
+import cn.cslg.pas.common.utils.JsonUtils;
|
|
|
+import cn.cslg.pas.domain.es.Patent;
|
|
|
+import cn.cslg.pas.service.business.es.EsService;
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
+import cn.hutool.core.util.ZipUtil;
|
|
|
+import io.swagger.v3.oas.annotations.media.Schema;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class ProjectExportService {
|
|
|
+ @Autowired
|
|
|
+ private FileUtils fileUtils;
|
|
|
+ @Autowired
|
|
|
+ private EsService esService;
|
|
|
+ @Autowired
|
|
|
+ private PatentProjectService patentProjectService;
|
|
|
+ @Autowired
|
|
|
+ private ProjectService projectService;
|
|
|
+ public void exportProject() throws Exception {
|
|
|
+ String directoryName = IdUtil.simpleUUID();
|
|
|
+ String fileName = directoryName + ".zip";
|
|
|
+ String tempPath = fileUtils.getTempPath(directoryName);
|
|
|
+ String url = fileUtils.getDirectory(fileName);
|
|
|
+ String savePath = fileUtils.getSystemPath(url);
|
|
|
+ File directory = new File(tempPath);
|
|
|
+ if (!directory.exists()) {
|
|
|
+ boolean success = directory.mkdir();
|
|
|
+ if (!success) {
|
|
|
+ throw new Exception("数据导出时创建文件夹失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Patent patent = new Patent();
|
|
|
+ patent.setAppNo("123");
|
|
|
+ this.saveDataToJsonFile(tempPath, "专利.json", getProjectPatent(185));
|
|
|
+ File file = ZipUtil.zip(tempPath, savePath);
|
|
|
+ FileUtil.del(tempPath);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void saveDataToJsonFile(String tempPath, String fileName, String data) throws IOException {
|
|
|
+ String path = tempPath + FileUtils.FILE_SEPARATOR + fileName;
|
|
|
+ FileOutputStream fileOutputStream = new FileOutputStream(path);
|
|
|
+ fileOutputStream.write(data.getBytes(StandardCharsets.UTF_8));
|
|
|
+ fileOutputStream.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getProjectPatent(Integer projectId) throws Exception{
|
|
|
+ StringRequest stringRequest =new StringRequest();
|
|
|
+ stringRequest.setProjectId(185);
|
|
|
+ PatentDTO patentDTO =esService.esSearch(stringRequest);
|
|
|
+ if(patentDTO ==null){
|
|
|
+ patentDTO=new PatentDTO();
|
|
|
+ }
|
|
|
+ return Objects.requireNonNull(JsonUtils.objectToJson(patentDTO.getPatents()));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param projectId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getProject(Integer projectId){
|
|
|
+
|
|
|
+ PatentProjectDTO patentProjectDTO =new PatentProjectDTO();
|
|
|
+ //根据
|
|
|
+
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+}
|