Przeglądaj źródła

Merge remote-tracking branch 'origin/master'

lwhhszx 1 rok temu
rodzic
commit
b72e15d4c0

+ 18 - 0
src/main/java/cn/cslg/pas/common/dto/ExportDTO.java

@@ -0,0 +1,18 @@
+package cn.cslg.pas.common.dto;
+
+import lombok.Data;
+
+@Data
+public class ExportDTO {
+    private String condition;
+    private String estimatedTree;
+    private String actualTree;
+    private String treeFlag;
+    private String estimatedQuery;
+    private String actualQuery;
+    private String queryFlag;
+    private String outCondition;
+    private String estimatedOutQuery;
+    private String actualOutQuery;
+    private String outQueryFlag;
+}

+ 52 - 19
src/main/java/cn/cslg/pas/common/utils/FileUtils.java

@@ -4,14 +4,11 @@ package cn.cslg.pas.common.utils;
 import cn.cslg.pas.Application;
 import cn.hutool.core.util.IdUtil;
 import com.alibaba.fastjson.JSON;
-import org.apache.commons.fileupload.FileItem;
-import org.apache.commons.fileupload.disk.DiskFileItemFactory;
 import org.springframework.boot.system.ApplicationHome;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.*;
-import java.net.MalformedURLException;
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
 
@@ -28,13 +25,11 @@ public class FileUtils {
         //获取 applicationHome 内的路径 ...\target\classes 到这一层级下
         File file = ah.getSource();
         //获取 file的parentFile 即最后一级之前的所有层级路径(包括盘符) 这里能获得到的最终层级为  ...\target 后续用FILE_SEPARATOR(系统路径分割通配符 即 "\") 以及fileName拼接生成存放文件的目录层级 即为根目录 root
-        String rootPath =null;
+        String rootPath = null;
 
-        if (fileName!=null&&!fileName.equals(""))
-        {
-            rootPath= file.getParentFile().toString() + FILE_SEPARATOR + fileName;
-        }
-        else {
+        if (fileName != null && !fileName.equals("")) {
+            rootPath = file.getParentFile().toString() + FILE_SEPARATOR + fileName;
+        } else {
             rootPath = file.getParentFile().toString();
         }
         //根据上方生成的根目录路径 生成对应文件夹 没有就新建
@@ -77,7 +72,7 @@ public class FileUtils {
         return last.toString();
     }
 
-    public static   File  getFileByBytes(byte[] bytes, String prefix, String suffix) {
+    public static File getFileByBytes(byte[] bytes, String prefix, String suffix) {
         BufferedOutputStream bos = null;
         FileOutputStream fos = null;
         File file = null;
@@ -111,12 +106,12 @@ public class FileUtils {
                     e.printStackTrace();
                 }
             }
-            return  file;
+            return file;
         }
     }
 
 
-    public static  File getFileByUrl(String dataUrl) throws IOException {
+    public static File getFileByUrl(String dataUrl) throws IOException {
 
         URL url = new URL(dataUrl);  //想要读取的url地址
         InputStream in = url.openStream();
@@ -133,7 +128,8 @@ public class FileUtils {
         in.close();
         return file;
     }
-    public static  File getPictureFileByUrl(String dataUrl) throws IOException {
+
+    public static File getPictureFileByUrl(String dataUrl) throws IOException {
 
         URL url = new URL(dataUrl);  //想要读取的url地址
         InputStream in = url.openStream();
@@ -150,9 +146,11 @@ public class FileUtils {
         in.close();
         return file;
     }
+
     public String getPath(String url) {
         return getStaticPath(COMMON_FILE) + url;
     }
+
     public String getDirectoryName() {
         return DateUtils.getNowTimeFormat("yyyyMMdd");
     }
@@ -160,6 +158,7 @@ public class FileUtils {
     public String getSavePath(String directoryName) {
         return getStaticPath(COMMON_FILE) + FILE_SEPARATOR + directoryName + FILE_SEPARATOR;
     }
+
     public String createDirectory() {
         String directoryName = this.getDirectoryName();
         String savePath = this.getSavePath(directoryName);
@@ -169,8 +168,9 @@ public class FileUtils {
         }
         return directoryName;
     }
+
     public String createRandomDirectory() {
-        String directoryName =  IdUtil.simpleUUID();
+        String directoryName = IdUtil.simpleUUID();
         String savePath = this.getSavePath(directoryName);
         File directory = new File(savePath);
         if (!directory.exists()) {
@@ -178,6 +178,7 @@ public class FileUtils {
         }
         return directoryName;
     }
+
     public static FileInputStream byteToFile(byte[] bytes) {
         String fileName = IdUtil.simpleUUID() + ".png";
         File file = new File(fileName);
@@ -209,13 +210,16 @@ public class FileUtils {
     public String getDirectory(String fileName) {
         return FILE_SEPARATOR + this.createDirectory() + FILE_SEPARATOR + fileName;
     }
+
     public String getSystemPath(String url) {
         return getStaticPath(COMMON_FILE) + FILE_SEPARATOR + url;
     }
+
     public static String getSystemPath2(String url) {
         return getStaticPath(COMMON_FILE) + FILE_SEPARATOR + url;
     }
-    public  static void  writeFile(String json, String FilePath) {
+
+    public static void writeFile(String json, String FilePath) {
 
         try {
             File file = new File(FilePath);
@@ -238,6 +242,7 @@ public class FileUtils {
             e.printStackTrace();
         }
     }
+
     public static File getFileByName(File file, String name) {
         for (File file1 : file.listFiles()) {
             if (file1.getName().equals(name)) {
@@ -248,10 +253,9 @@ public class FileUtils {
     }
 
 
-    public  static void  writeFile(Object object,File file) {
-       String json = JSON.toJSONString(object);
+    public static void writeFile(Object object, File file) {
+        String json = JSON.toJSONString(object);
         try {
-
             // if file doesnt exists, then create it
             if (!file.exists()) {
                 file.createNewFile();
@@ -259,7 +263,6 @@ public class FileUtils {
                 file.delete();
                 file.createNewFile();
             }
-
             // true = append file
             FileWriter fileWritter = new FileWriter(file, false);
             BufferedWriter bufferWritter = new BufferedWriter(fileWritter);
@@ -270,4 +273,34 @@ public class FileUtils {
             e.printStackTrace();
         }
     }
+
+    public static File multipartFileToFile(MultipartFile file) throws Exception {
+        File toFile = null;
+        if (file == null || file.equals("") || file.getSize() <= 0) {
+            file = null;
+        } else {
+            InputStream ins = null;
+            ins = file.getInputStream();
+            toFile = new File(file.getOriginalFilename());
+            inputStreamToFile(ins, toFile);
+            ins.close();
+        }
+        return toFile;
+    }
+
+    //获取流文件
+    private static void inputStreamToFile(InputStream ins, File file) {
+        try {
+            OutputStream os = new FileOutputStream(file);
+            int bytesRead = 0;
+            byte[] buffer = new byte[8192];
+            while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
+                os.write(buffer, 0, bytesRead);
+            }
+            os.close();
+            ins.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
 }

+ 2 - 0
src/main/java/cn/cslg/pas/common/vo/business/HandleResultFileVO.java

@@ -28,6 +28,8 @@ public class HandleResultFileVO {
 
     private String createId;
 
+    private Integer source;
+
     /**
      * 上传人
      */

+ 8 - 0
src/main/java/cn/cslg/pas/common/vo/business/PatentDigProjectFilesVO.java

@@ -82,4 +82,12 @@ public class PatentDigProjectFilesVO {
     private Date createTime;
 
     private ProjectTask projectTask;
+
+    /**
+     * 来源:1 PatentDigProjectFiles
+     *      2 AssoHandleResultFile
+     *      3 AssoProjectFile
+     *      4 AssoTaskFile
+     */
+    private Integer source;
 }

+ 39 - 0
src/main/java/cn/cslg/pas/controller/ExportController.java

@@ -0,0 +1,39 @@
+package cn.cslg.pas.controller;
+
+import cn.cslg.pas.common.core.base.Constants;
+import cn.cslg.pas.common.model.cronModel.Records;
+import cn.cslg.pas.common.utils.FileUtils;
+import cn.cslg.pas.common.utils.Response;
+import cn.cslg.pas.service.business.es.EsExportService;
+import io.swagger.v3.oas.annotations.Operation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.File;
+
+@RequestMapping(Constants.API_XiaoSHI + "/export")
+@RestController
+public class ExportController {
+
+    @Autowired
+    private EsExportService esExportService;
+
+    @Operation(summary = "导出二叉树")
+    @PostMapping("/export")
+    public Response exportTree(@RequestParam(value = "multipartFile", required = false) MultipartFile multipartFile) throws Exception {
+        Records records = new Records();
+        File file = FileUtils.multipartFileToFile(multipartFile);
+        try {
+            esExportService.exportTree(file);
+            records.setData("导出成功");
+        } catch (Exception e) {
+            records.setData("导出失败");
+
+        }
+        return Response.success(records);
+    }
+}

+ 9 - 0
src/main/java/cn/cslg/pas/controller/PatentDigProjectFilesController.java

@@ -95,4 +95,13 @@ public class PatentDigProjectFilesController {
         return Response.success(records);
     }
 
+    @Operation(summary = "删除专利挖掘项目文件")
+    @GetMapping("/delete")
+    public Response delete(Integer source, String fileGuid) throws Exception {
+        patentDigProjectFilesService.delete(source, fileGuid);
+        Records records = new Records();
+        records.setData("success");
+        return Response.success(records);
+    }
+
 }

+ 3 - 7
src/main/java/cn/cslg/pas/factorys/EsBuilderFactory/DateQueryBuilder.java

@@ -150,11 +150,9 @@ public class DateQueryBuilder implements IQueryBuilder {
             String[] dates = value.split("~");
             String date1 = dates[0];
             String date2 = dates[1];
-          String  findate1=this.formatDateString(date1);
-         String    findate2 =this.formatDateString(date2);
-           query = QueryBuilders
-                    .range(range -> range.field(field).gte(JsonData.of(findate1)).lte(JsonData.of(findate2)));
-
+            String findDate1 = this.formatDateString(date1);
+            String findDate2 = this.formatDateString(date2);
+            query = QueryBuilders.range(range -> range.field(field).gte(JsonData.of(findDate1)).lte(JsonData.of(findDate2)));
         } else {
             query = this.getSingle();
         }
@@ -257,7 +255,6 @@ public class DateQueryBuilder implements IQueryBuilder {
 
     private Query getSingle() throws ParseException {
         Query query = null;
-
         if (value != null && !"".equals(value)) {
             Calendar calendar = Calendar.getInstance();
             if (value.length() == YEAR) {
@@ -371,6 +368,5 @@ public class DateQueryBuilder implements IQueryBuilder {
             }
         }
         return query;
-
     }
 }

+ 114 - 56
src/main/java/cn/cslg/pas/factorys/EsBuilderFactory/PrioritiesNestedQueryBuilder.java

@@ -27,6 +27,116 @@ public class PrioritiesNestedQueryBuilder implements IQueryBuilder{
     @Override
     public Query creteQuery() throws ParseException {
         Query query = null;
+        if (value.contains("~")) {
+            String[] dates = value.split("~");
+            String date1 = dates[0];
+            String date2 = dates[1];
+            String findDate1 = this.formatDateString(date1);
+            String findDate2 = this.formatDateString(date2);
+            query = QueryBuilders.range(range -> range.field(field).gte(JsonData.of(findDate1)).lte(JsonData.of(findDate2)));
+        } else {
+            query = this.getSingle();
+        }
+        Query finalQuery = query;
+        Query nestedQuery = QueryBuilders.nested(z -> z.path(path).query(finalQuery));
+        return nestedQuery;
+    }
+
+    @Override
+    public String getField() {
+        return field;
+    }
+
+    @Override
+    public void setField(String field) {
+        this.field = field;
+    }
+
+    @Override
+    public String getValue() {
+        return value;
+    }
+
+    @Override
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+    @Override
+    public String getOperator() {
+        return operator;
+    }
+
+    @Override
+    public void setOperator(String operator) {
+        this.operator = operator;
+    }
+
+    @Override
+    public String getPath() {
+        return path;
+    }
+
+    @Override
+    public void setPath(String path) {
+        this.path = path;
+    }
+
+    @Override
+    public Integer getProjectId() {
+        return projectId;
+    }
+
+    @Override
+    public void setProjectId(Integer projectId) {
+        this.projectId = projectId;
+    }
+
+    private String formatDateString(String dateStr) throws ParseException {
+        Calendar calendar = Calendar.getInstance();
+        String formatedTime = "";
+        if (dateStr.length() == YEAR) {
+            SimpleDateFormat format = new SimpleDateFormat("yyyy");
+            Date year = format.parse(dateStr);
+            calendar.setTime(year);
+            String yearTime = String.valueOf(calendar.getTime().getTime());
+            formatedTime = yearTime;
+        } else if (dateStr.length() == MONTH || dateStr.length() == MONTHONE) {
+            Date month = new Date();
+            if (dateStr.contains("-")) {
+                SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM");
+                month = format2.parse(dateStr);
+            } else if (dateStr.contains("/")) {
+                SimpleDateFormat format3 = new SimpleDateFormat("yyyy/MM");
+                month = format3.parse(dateStr);
+            } else {
+                SimpleDateFormat format1 = new SimpleDateFormat("yyyyMM");
+                month = format1.parse(dateStr);
+            }
+            calendar.setTime(month);
+            String monthTime = String.valueOf(calendar.getTime().getTime());
+            formatedTime = monthTime;
+        } else if (dateStr.length() == DAY || dateStr.length() == DAYONE) {
+            Date day = new Date();
+            if (dateStr.contains("-")) {
+                SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd");
+                day = format2.parse(dateStr);
+            } else if (dateStr.contains("/")) {
+                SimpleDateFormat format3 = new SimpleDateFormat("yyyy/MM/dd");
+                day = format3.parse(dateStr);
+            } else {
+                SimpleDateFormat format1 = new SimpleDateFormat("yyyyMMdd");
+                day = format1.parse(dateStr);
+            }
+            calendar.setTime(day);
+            String dayTime = String.valueOf(day.getTime());
+            formatedTime = dayTime;
+        }
+        return formatedTime;
+    }
+
+    private Query getSingle() throws ParseException {
+        Query query = null;
         if (value != null && !"".equals(value)) {
             Calendar calendar = Calendar.getInstance();
             if (value.length() == YEAR) {
@@ -55,7 +165,7 @@ public class PrioritiesNestedQueryBuilder implements IQueryBuilder{
                         break;
                     default:
                         query = QueryBuilders
-                                .range(range -> range.field(field).gte(JsonData.of(yearTime)).lte(JsonData.of(yearNextTime)));
+                                .range(range -> range.field(field).gte(JsonData.of(yearTime)).lt(JsonData.of(yearNextTime)));
                         break;
                 }
             } else if (value.length() == MONTH || value.length() == MONTHONE) {
@@ -93,7 +203,7 @@ public class PrioritiesNestedQueryBuilder implements IQueryBuilder{
                         break;
                     default:
                         query = QueryBuilders
-                                .range(range -> range.field(field).gte(JsonData.of(monthTime)).lte(JsonData.of(monthNextTime)));
+                                .range(range -> range.field(field).gte(JsonData.of(monthTime)).lt(JsonData.of(monthNextTime)));
                         break;
                 }
             } else if (value.length() == DAY || value.length() == DAYONE) {
@@ -131,7 +241,7 @@ public class PrioritiesNestedQueryBuilder implements IQueryBuilder{
                         break;
                     default:
                         query = QueryBuilders
-                                .range(range -> range.field(field).gte(JsonData.of(dayTime)).lte(JsonData.of(nextDayTime)));
+                                .range(range -> range.field(field).gte(JsonData.of(dayTime)).lt(JsonData.of(nextDayTime)));
                         break;
                 }
             } else {
@@ -139,58 +249,6 @@ public class PrioritiesNestedQueryBuilder implements IQueryBuilder{
                         .range(range -> range.field(field).gte(JsonData.of(1)).lte(JsonData.of(2)));
             }
         }
-        Query finalQuery = query;
-        Query nestedQuery = QueryBuilders.nested(z -> z.path(path).query(finalQuery));
-        return nestedQuery;
-    }
-
-    @Override
-    public String getField() {
-        return field;
-    }
-
-    @Override
-    public void setField(String field) {
-        this.field = field;
-    }
-
-    @Override
-    public String getValue() {
-        return value;
-    }
-
-    @Override
-    public void setValue(String value) {
-        this.value = value;
-    }
-
-    @Override
-    public String getOperator() {
-        return operator;
-    }
-
-    @Override
-    public void setOperator(String operator) {
-        this.operator = operator;
-    }
-
-    @Override
-    public String getPath() {
-        return path;
-    }
-
-    @Override
-    public void setPath(String path) {
-        this.path = path;
-    }
-
-    @Override
-    public Integer getProjectId() {
-        return projectId;
-    }
-
-    @Override
-    public void setProjectId(Integer projectId) {
-        this.projectId = projectId;
+        return query;
     }
 }

+ 41 - 1
src/main/java/cn/cslg/pas/service/business/PatentDigProjectFilesService.java

@@ -313,6 +313,10 @@ public class PatentDigProjectFilesService extends ServiceImpl<PatentDigProjectFi
 
     /**
      * 查询专利挖掘项目所有文件
+     * 来源:1 PatentDigProjectFiles
+     *      2 AssoHandleResultFile
+     *      3 AssoProjectFile
+     *      4 AssoTaskFile
      *
      * @param queryPatentDigProjectFilesDTO
      */
@@ -343,6 +347,7 @@ public class PatentDigProjectFilesService extends ServiceImpl<PatentDigProjectFi
             patentDigProjectFilesList.forEach(item -> {
                 PatentDigProjectFilesVO patentDigProjectFilesVO = new PatentDigProjectFilesVO();
                 BeanUtils.copyProperties(item, patentDigProjectFilesVO);
+                patentDigProjectFilesVO.setSource(1);
                 patentDigProjectFilesVOS.add(patentDigProjectFilesVO);
             });
         }
@@ -374,6 +379,7 @@ public class PatentDigProjectFilesService extends ServiceImpl<PatentDigProjectFi
                     if (projectTask != null) {
                         patentDigProjectFilesVO.setProcessId(projectTask.getProcessId());
                     }
+                    patentDigProjectFilesVO.setSource(4);
                     patentDigProjectFilesVOS.add(patentDigProjectFilesVO);
                 });
             }
@@ -394,9 +400,9 @@ public class PatentDigProjectFilesService extends ServiceImpl<PatentDigProjectFi
                     patentDigProjectFilesVO.setCreateId(item.getCreateId());
                     patentDigProjectFilesVO.setProcessId(processId);
                     patentDigProjectFilesVO.setCreateTime(item.getCreateTime());
+                    patentDigProjectFilesVO.setSource(2);
                     patentDigProjectFilesVOS.add(patentDigProjectFilesVO);
                 });
-
             }
         }
         //查询项目下的文件
@@ -411,6 +417,7 @@ public class PatentDigProjectFilesService extends ServiceImpl<PatentDigProjectFi
                     patentDigProjectFilesVO.setFileGuid(item.getFileGuid());
                     patentDigProjectFilesVO.setCreateId(item.getCreateId());
                     patentDigProjectFilesVO.setCreateTime(item.getCreateTime());
+                    patentDigProjectFilesVO.setSource(3);
                     patentDigProjectFilesVOS.add(patentDigProjectFilesVO);
                 });
             }
@@ -422,4 +429,37 @@ public class PatentDigProjectFilesService extends ServiceImpl<PatentDigProjectFi
         }
         return patentDigProjectFilesVOS;
     }
+
+    /**
+     * 删除
+     * 来源:1 PatentDigProjectFiles
+     *      2 AssoHandleResultFile
+     *      3 AssoProjectFile
+     *      4 AssoTaskFile
+     * @param source
+     * @param fileGuid
+     */
+    public void delete(Integer source, String fileGuid) {
+        if (fileGuid != null && !fileGuid.trim().isEmpty()) {
+            if (source != null) {
+                if (source.equals(1)) {
+                    LambdaQueryWrapper<PatentDigProjectFiles> queryWrapper = new LambdaQueryWrapper<>();
+                    queryWrapper.eq(PatentDigProjectFiles::getFileGuid, fileGuid);
+                    this.remove(queryWrapper);
+                } else if (source.equals(2)) {
+                    LambdaQueryWrapper<AssoHandleResultFile> queryWrapper = new LambdaQueryWrapper<>();
+                    queryWrapper.eq(AssoHandleResultFile::getFileGuid, fileGuid);
+                    assoHandleResultFileService.remove(queryWrapper);
+                } else if (source.equals(3)) {
+                    LambdaQueryWrapper<AssoProjectFile> queryWrapper = new LambdaQueryWrapper<>();
+                    queryWrapper.eq(AssoProjectFile::getFileGuid, fileGuid);
+                    assoProjectFileService.remove(queryWrapper);
+                } else if (source.equals(4)) {
+                    LambdaQueryWrapper<AssoTaskFile> queryWrapper = new LambdaQueryWrapper<>();
+                    queryWrapper.eq(AssoTaskFile::getFileGuid, fileGuid);
+                    assoTaskFileService.remove(queryWrapper);
+                }
+            }
+        }
+    }
 }

+ 199 - 2
src/main/java/cn/cslg/pas/service/business/PatentExportService.java

@@ -67,6 +67,199 @@ public class PatentExportService {
     @Autowired
     private EsCustomFieldService esCustomFieldService;
 
+//    /**
+//     * 导出专利
+//     *
+//     * @param exportTask
+//     * @return
+//     * @throws IOException
+//     */
+//    @Async
+//    public void exportPatent(ExportTaskDTO exportTask) throws IOException {
+//        EsCustomFieldBatchVO EsVO = exportTask.getEsVO();
+//        try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+//            //字段是否被选择
+//            String esSelected = JsonUtils.objectToJson(EsVO.getSelected());
+//            //专利字段的集合
+//            List<PatentExportVO> selected = Optional.ofNullable(JsonUtils.jsonToList(esSelected, PatentExportVO.class))
+//                    .orElse(new ArrayList<>());
+//
+//            if (selected.isEmpty()) {
+//                throw new IllegalArgumentException("没有选择要导出的字段数据");
+//            }
+//
+//            //key的集合(标头:例如patentNo)
+//            //过滤出被选择的字段
+//            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());
+//            //新建工作簿
+//            HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
+//            //新建sheet页
+//            HSSFSheet sheet = hssfWorkbook.createSheet();
+//            sheet.setDefaultColumnWidth(30);
+//            //新建标头行
+//            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++) {
+//                HSSFCell cell = headerRow.createCell(i);
+//                ExcelUtils.setExcelCellStyle(headerCellStyle);
+//                headerCellStyle.setAlignment(HorizontalAlignment.CENTER);
+//                headerCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
+//                headerCellStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.SKY_BLUE.getIndex());
+//                headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+//                headerCellStyle.setWrapText(true);
+//                cell.setCellStyle(headerCellStyle);
+//                cell.setCellValue(headers.get(i));
+//            }
+//            //根据projectId查询专利信息
+//            List<String> patentNos = pdfExportFirstPageService.getPatentNo(EsVO);
+//            if (patentNos.isEmpty()) {
+//                throw new XiaoShiException("未获取到专利信息");
+//            }
+//            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(patentNo);
+//                patentNoVO.setProjectId(exportTask.getProjectId());
+//                PatentColumnDTO patent = patentService.selectPatentDetail(patentNoVO);
+//                if (patent == null) {
+//                    defaultNum++;
+//                    continue;
+//                }
+//
+//                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);
+//                            }
+//                        }
+//                    }
+//                }
+//                //新建一普通行
+//                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.setWrapText(true);
+//                        cell.setCellStyle(commonCellStyle);
+//                        if (StringUtils.isNotNull(map.get(key))) {
+//                            cell.setCellValue(String.valueOf(map.get(key)));
+//                        }
+//                    }
+//                }
+//                WebSocketMessageVO webSocketMessageVO = new WebSocketMessageVO();
+//                webSocketMessageVO.setProjectId(EsVO.getProjectId());
+//                webSocketMessageVO.setCreateId(exportTask.getCreateId());
+//                webSocketMessageVO.setCode(602);
+//                webSocketMessageVO.setAllNum(total);
+//                webSocketMessageVO.setCurrentNum(i+1);
+//                webSocketMessageVO.setTaskId(exportTask.getTaskId());
+//                webSocketMessageVO.setState(1);
+//                messageService.sendPatentExportMessage(webSocketMessageVO);
+//            }
+//            hssfWorkbook.write(out);
+//            WebSocketMessageVO webSocketMessageVO = new WebSocketMessageVO();
+//            webSocketMessageVO.setProjectId(EsVO.getProjectId());
+//            webSocketMessageVO.setCreateId(exportTask.getCreateId());
+//            webSocketMessageVO.setCode(603);
+//            webSocketMessageVO.setAllNum(total);
+//            webSocketMessageVO.setCurrentNum(total);
+//            webSocketMessageVO.setTaskId(exportTask.getTaskId());
+//            webSocketMessageVO.setState(2);
+//            messageService.sendPatentExportMessage(webSocketMessageVO);
+//            String fileGuid = "";
+//            if (out.toByteArray() != null && out.toByteArray().length != 0) {
+//                fileGuid = parseByteToFileUtils.uploadFile(out.toByteArray(), 1);
+//            }
+//            exportTask.setFileGuid(fileGuid);
+//            exportTask.setAllNum(total);
+//            exportTask.setDefaultNum(defaultNum);
+//            exportTask.setDoneNum(total - defaultNum);
+//            exportTask.setState(2);
+//            Integer taskId = importTaskService.updateExportTask(exportTask);
+//            if (taskId == null) {
+//                throw new XiaoShiException("导出记录失败");
+//            }
+//
+//        } catch (FileNotFoundException e) {
+//            throw new FileNotFoundException();
+//        } catch (Exception e) {
+//
+//        }
+//    }
+
+
     /**
      * 导出专利
      *
@@ -78,16 +271,18 @@ public class PatentExportService {
     public void exportPatent(ExportTaskDTO exportTask) throws IOException {
         EsCustomFieldBatchVO EsVO = exportTask.getEsVO();
         try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+            //字段是否被选择
             String esSelected = JsonUtils.objectToJson(EsVO.getSelected());
-            //selected字符串转PatentExportVO集合
+            //专利字段的集合
             List<PatentExportVO> selected = Optional.ofNullable(JsonUtils.jsonToList(esSelected, PatentExportVO.class))
                     .orElse(new ArrayList<>());
-            //导出文件名
+
             if (selected.isEmpty()) {
                 throw new IllegalArgumentException("没有选择要导出的字段数据");
             }
 
             //key的集合(标头:例如patentNo)
+            //过滤出被选择的字段
             List<PatentExportVO> patentExportVOS = selected.stream()
                     .filter(PatentExportVO::getSelected)
                     .collect(Collectors.toList());
@@ -103,6 +298,7 @@ public class PatentExportService {
             }
             //name的集合
             List<String> headers = selected.stream().filter(PatentExportVO::getSelected).map(PatentExportVO::getName).distinct().collect(Collectors.toList());
+            long startTime = System.currentTimeMillis();
             //新建工作簿
             HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
             //新建sheet页
@@ -227,6 +423,7 @@ public class PatentExportService {
                 messageService.sendPatentExportMessage(webSocketMessageVO);
             }
             hssfWorkbook.write(out);
+            log.info("导出excel结束,总数据量={},耗时={}ms", total, System.currentTimeMillis() - startTime);
             WebSocketMessageVO webSocketMessageVO = new WebSocketMessageVO();
             webSocketMessageVO.setProjectId(EsVO.getProjectId());
             webSocketMessageVO.setCreateId(exportTask.getCreateId());

+ 2 - 0
src/main/java/cn/cslg/pas/service/business/ProjectTaskService.java

@@ -401,6 +401,7 @@ import java.util.stream.Collectors;
                                 BeanUtils.copyProperties(patentDigProjectFiles1, handleResultFileVO);
                                 handleResultFileVO.setGuid(patentDigProjectFiles1.getFileGuid());
                                 handleResultFileVO.setType(systemFile.getType());
+                                handleResultFileVO.setSource(1);
                                 handleResultFileVO.setOriginalName(systemFile.getOriginalName());
                             }
                             handleResultFileVOS.add(handleResultFileVO);
@@ -490,6 +491,7 @@ import java.util.stream.Collectors;
                     if (systemFile != null) {
                         BeanUtils.copyProperties(assoHandleResultFile, handleResultFileVO);
                         handleResultFileVO.setGuid(assoHandleResultFile.getFileGuid());
+                        handleResultFileVO.setSource(2);
                         handleResultFileVO.setType(systemFile.getType());
                         handleResultFileVO.setOriginalName(systemFile.getOriginalName());
                     }

+ 1 - 0
src/main/java/cn/cslg/pas/service/business/TaskHandleResultService.java

@@ -236,6 +236,7 @@ public class TaskHandleResultService extends ServiceImpl<TaskHandleResultMapper,
                         handleResultFileVO.setGuid(assoHandleResultFile.getFileGuid());
                         handleResultFileVO.setType(systemFile.getType());
                         handleResultFileVO.setOriginalName(systemFile.getOriginalName());
+                        handleResultFileVO.setSource(2);
                         handleResultFileVOS.add(handleResultFileVO);
                     }
                 }

+ 222 - 0
src/main/java/cn/cslg/pas/service/business/es/EsExportService.java

@@ -0,0 +1,222 @@
+package cn.cslg.pas.service.business.es;
+
+import cn.cslg.pas.common.dto.ExportDTO;
+import cn.cslg.pas.common.utils.ExcelUtils;
+import cn.cslg.pas.common.utils.FileUtils;
+import cn.cslg.pas.common.utils.ReadExcelUtils;
+import cn.cslg.pas.common.utils.parseQueryToTree.expressManager;
+import cn.cslg.pas.common.utils.parseQueryToTree.operateNode;
+import cn.cslg.pas.common.utils.parseQueryToTree.treeNode;
+import cn.cslg.pas.common.vo.PatentData;
+import cn.cslg.pas.service.query.FormatQueryService;
+import co.elastic.clients.elasticsearch._types.query_dsl.Query;
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.serializer.SerializerFeature;
+import lombok.RequiredArgsConstructor;
+import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.hssf.usermodel.*;
+import org.apache.poi.hssf.util.HSSFColor;
+import org.apache.poi.ss.usermodel.FillPatternType;
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.VerticalAlignment;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+@Service
+@RequiredArgsConstructor(onConstructor_ = {@Lazy})
+public class EsExportService {
+
+    @Autowired
+    private FormatQueryService formatQueryService;
+
+    public void exportTree(File file) throws Exception {
+        Sheet sheet = ReadExcelUtils.readExcel(file);
+        int total = sheet.getPhysicalNumberOfRows() - 1;
+        List<ExportDTO> list = new ArrayList<>();
+        for (int i = 0; i < total; i++) {
+            PatentData patentData = ReadExcelUtils.readExcelOneRow(file, sheet, i + 1);
+            Map<Object, Object> patentDataMap = patentData.getMap();
+            String condition = patentDataMap.get("检索条件").toString();
+            String estimatedTree = patentDataMap.get("预期二叉树").toString();
+            String estimatedQuery = patentDataMap.get("预期Query").toString();
+            String outCondition = patentDataMap.get("外部检索条件").toString();
+            String estimatedOutQuery = patentDataMap.get("预期外部检索式").toString();
+            ExportDTO exportDTO = new ExportDTO();
+            exportDTO.setCondition(condition);
+            exportDTO.setOutCondition(outCondition);
+            if (StringUtils.isNotEmpty(estimatedTree)) {
+                exportDTO.setEstimatedTree(estimatedTree);
+            }
+            if (StringUtils.isNotEmpty(estimatedQuery)) {
+                exportDTO.setEstimatedQuery(estimatedQuery);
+            }
+            if (StringUtils.isNotEmpty(estimatedOutQuery)) {
+                exportDTO.setEstimatedOutQuery(estimatedOutQuery);
+            }
+            list.add(exportDTO);
+        }
+        for (ExportDTO exportDTO : list) {
+            if (StringUtils.isNotEmpty(exportDTO.getEstimatedTree())) {
+                treeNode tree = null;
+                try {
+                    tree = expressManager.getInstance().Parse(exportDTO.getCondition(), false);
+                } catch (Exception e) {
+                    System.out.println(exportDTO.getCondition() + "转换二叉树表达式错误");
+                }
+                String treeJson = JSONObject.toJSONString(tree, SerializerFeature.DisableCircularReferenceDetect);
+                exportDTO.setActualTree(treeJson);
+                if (treeJson == null || exportDTO.getEstimatedTree() == null || !treeJson.equalsIgnoreCase(exportDTO.getEstimatedTree().trim())) {
+                    exportDTO.setTreeFlag("F");
+                } else {
+                    exportDTO.setTreeFlag("T");
+                }
+                Query query = null;
+                try {
+                    query = formatQueryService.EsQueryToQuery((operateNode) tree, "patent", 331);
+                } catch (ParseException e) {
+                    System.out.println(exportDTO.getCondition() + "转换es表达式错误");
+                }
+                String queryStr = query.toString();
+                exportDTO.setActualQuery(queryStr);
+                if (queryStr == null || exportDTO.getEstimatedQuery() == null || !queryStr.equalsIgnoreCase(exportDTO.getEstimatedQuery().trim())) {
+                    exportDTO.setQueryFlag("F");
+                } else {
+                    exportDTO.setQueryFlag("T");
+                }
+            }
+            if (StringUtils.isNotEmpty(exportDTO.getOutCondition()) && !exportDTO.getOutCondition().contains("+")) {
+                String outQueryStr = null;
+                try {
+                    outQueryStr = formatQueryService.reQuery(exportDTO.getOutCondition(), "webSearchConfig");
+                } catch (Exception e) {
+                    System.out.println(exportDTO.getOutCondition() + "转换外部接口检索表达式错误");
+                }
+                exportDTO.setActualOutQuery(outQueryStr);
+                if (outQueryStr == null || exportDTO.getEstimatedOutQuery() == null || !outQueryStr.equalsIgnoreCase(exportDTO.getEstimatedOutQuery().trim())) {
+                    exportDTO.setOutQueryFlag("F");
+                } else {
+                    exportDTO.setOutQueryFlag("T");
+                }
+            }
+        }
+        if (!CollectionUtils.isEmpty(list)) {
+            this.loadExportTree(list);
+        }
+    }
+
+    public void loadExportTree(List<ExportDTO> list) throws FileNotFoundException {
+        try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+            List<String> headers = Arrays.asList("检索条件", "预期二叉树", "实际二叉树", "二叉树是否一致", "预期Query", "实际Query","Query是否一致",
+                    "外部检索条件","预期外部检索式", "实际外部检索式","外部检索式是否一致");
+            HSSFWorkbook hssfWorkbook = new HSSFWorkbook();//新建工作簿
+            HSSFSheet sheet = hssfWorkbook.createSheet();//新建sheet页
+            sheet.setDefaultColumnWidth(30);
+            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++) {//遍历设置标头
+                HSSFCell cell = headerRow.createCell(i);
+                ExcelUtils.setExcelCellStyle(headerCellStyle);
+                headerCellStyle.setAlignment(HorizontalAlignment.CENTER);
+                headerCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
+                headerCellStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.SKY_BLUE.getIndex());
+                headerCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+                headerCellStyle.setWrapText(true);
+                cell.setCellStyle(headerCellStyle);
+                cell.setCellValue(headers.get(i));
+            }
+            for (int i = 0; i < list.size(); i++) {
+                ExportDTO exportDTO = list.get(i);
+                HSSFRow row = sheet.createRow(i + 1);//新建一普通行
+                row.setHeight((short) 800);
+                HSSFCell cell = row.createCell(0);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell.setCellStyle(commonCellStyle);
+                cell.setCellValue(exportDTO.getCondition());
+                HSSFCell cell1 = row.createCell(1);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell1.setCellStyle(commonCellStyle);
+                cell1.setCellValue(exportDTO.getEstimatedTree());
+                HSSFCell cell2 = row.createCell(2);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell2.setCellStyle(commonCellStyle);
+                cell2.setCellValue(exportDTO.getActualTree());
+                HSSFCell cell3 = row.createCell(3);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell3.setCellStyle(commonCellStyle);
+                cell3.setCellValue(exportDTO.getTreeFlag());
+                HSSFCell cell4 = row.createCell(4);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell4.setCellStyle(commonCellStyle);
+                cell4.setCellValue(exportDTO.getEstimatedQuery());
+                HSSFCell cell5 = row.createCell(5);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell5.setCellStyle(commonCellStyle);
+                cell5.setCellValue(exportDTO.getActualQuery());
+                HSSFCell cell6 = row.createCell(6);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell6.setCellStyle(commonCellStyle);
+                cell6.setCellValue(exportDTO.getQueryFlag());
+                HSSFCell cell7 = row.createCell(7);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell7.setCellStyle(commonCellStyle);
+                cell7.setCellValue(exportDTO.getOutCondition());
+                HSSFCell cell8 = row.createCell(8);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell8.setCellStyle(commonCellStyle);
+                cell8.setCellValue(exportDTO.getEstimatedOutQuery());
+                HSSFCell cell9 = row.createCell(9);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell9.setCellStyle(commonCellStyle);
+                cell9.setCellValue(exportDTO.getActualOutQuery());
+                HSSFCell cell10 = row.createCell(10);
+                ExcelUtils.setExcelCellStyle(commonCellStyle);
+                commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
+                commonCellStyle.setWrapText(true);
+                cell10.setCellStyle(commonCellStyle);
+                cell10.setCellValue(exportDTO.getOutQueryFlag());
+            }
+            hssfWorkbook.write(out);
+            byte[] bytes = out.toByteArray();
+            FileUtils.getFileByBytes(bytes, "检索条件", ".xlsx");
+        } catch (FileNotFoundException e) {
+            throw new FileNotFoundException();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+}

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

@@ -61,8 +61,8 @@ spring:
     #初始化表结构
     jdbc:
       initialize-schema: always
-authorUrl: http://localhost:8885
-PCSUrl: http://localhost:8885
+authorUrl: http://localhost:8871
+PCSUrl: http://localhost:8871
 #OPSUrl: http://192.168.2.24:5001
 OPSUrl: http://139.224.24.90:5001
 PASUrl: http://localhost:8879

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

@@ -767,7 +767,7 @@
     "value": "ipcLevel5",
     "field": "IC",
     "esField": "mipc.level5",
-    "esClass": "keyWordQueryBuilder",
+    "esClass": "prefixQueryBuilder",
     "ifSearch": "false",
     "ifGroup": "false",
     "ifShow": "false",
@@ -885,7 +885,7 @@
     "value": "cpcLevel5",
     "field": "CPC",
     "esField": "mcpc.level5",
-    "esClass": "keyWordQueryBuilder",
+    "esClass": "prefixQueryBuilder",
     "ifSearch": "false",
     "ifGroup": "false",
     "ifShow": "false",