Browse Source

20240904 导出任务修改

lwhhszx 1 năm trước cách đây
mục cha
commit
4311396259

+ 5 - 3
src/main/java/cn/cslg/pas/controller/PatentController.java

@@ -38,6 +38,7 @@ import cn.cslg.pas.service.business.es.*;
 import cn.cslg.pas.service.common.FileManagerService;
 import cn.cslg.pas.service.common.PatentStarApiService;
 import cn.cslg.pas.service.importPatent.ImportSinglePatentService;
+import cn.cslg.pas.service.importPatent.SchedulingTaskService;
 import cn.hutool.core.util.IdUtil;
 import io.swagger.v3.oas.annotations.Operation;
 import org.apache.commons.io.input.XmlStreamReaderException;
@@ -96,7 +97,8 @@ public class PatentController {
     private LoginUtils loginUtils;
     @Autowired
     private ImportSinglePatentService importSinglePatentService;
-
+ @Autowired
+ private SchedulingTaskService schedulingTaskService;
     @Operation(summary = "查询专利")
     @PostMapping("/queryPatent")
     public Response queryPatent(@RequestBody StringRequest stringRequest) throws Exception {
@@ -273,7 +275,7 @@ public class PatentController {
 
     @PostMapping("/exportPatentExcel")
     @Operation(summary = "导出专利")
-    public Response exportPatentExcel(@RequestBody EsCustomFieldBatchVO EsVO) throws IOException {
+    public Response exportPatentExcel(@RequestBody EsCustomFieldBatchVO EsVO) throws Exception {
         ExportTaskDTO exportTaskDTO = new ExportTaskDTO();
         exportTaskDTO.setProjectId(EsVO.getProjectId());
         exportTaskDTO.setType(6);
@@ -283,7 +285,7 @@ public class PatentController {
         Integer taskId = importTaskService.addExportTask(exportTaskDTO);
         exportTaskDTO.setEsVO(EsVO);
         exportTaskDTO.setTaskId(taskId);
-        patentExportService.exportPatent(exportTaskDTO);
+        schedulingTaskService.startExportTask(exportTaskDTO);
         Records records = new Records();
         records.setData("导出专利");
         return Response.success(records);

+ 20 - 12
src/main/java/cn/cslg/pas/service/business/PatentExportService.java

@@ -7,6 +7,7 @@ import cn.cslg.pas.common.dto.es.EsQueryPatentFieldsDTO;
 import cn.cslg.pas.common.dto.es.InnerFields;
 import cn.cslg.pas.common.model.cronModel.Records;
 import cn.cslg.pas.common.model.request.QueryRequest;
+import cn.cslg.pas.common.model.request.StringRequest;
 import cn.cslg.pas.common.utils.*;
 import cn.cslg.pas.common.vo.ConfigVOS.PatentConfigVO;
 import cn.cslg.pas.common.vo.FieldValueVO;
@@ -91,6 +92,7 @@ public class PatentExportService {
 
     @Autowired
     private EsPatentService esPatentService;
+
     /**
      * 导出专利
      *
@@ -317,12 +319,13 @@ public class PatentExportService {
     }
 
 
-    public Integer updateTaskStateToDoing(Integer taskId) {
+    public Integer updateTaskStateToDoing(Integer taskId,Long total) {
         ImportTask importTask = importTaskService.getById(taskId);
         if (importTask == null) {
             throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR, "导入任务不存在");
         } else {
             importTask.setState(1);
+            importTask.setAllNum(total.intValue());
             importTask.updateById();
         }
         return importTask.getId();
@@ -349,7 +352,7 @@ public class PatentExportService {
         return records;
     }
 
-
+    @Async
     public void exportPatent2(ExportTaskDTO exportTask, ImportTaskAMVO importTaskAMVO) throws Exception {
 
         EsCustomFieldBatchVO esVO = exportTask.getEsVO();
@@ -364,7 +367,6 @@ public class PatentExportService {
             throw new IllegalArgumentException("没有选择要导出的字段数据");
         }
 
-        this.updateTaskStateToDoing(taskId);
 
         List<String> headers = selectedFields.stream().filter(PatentExportVO::getSelected).map(PatentExportVO::getName).distinct().collect(Collectors.toList());
 
@@ -383,7 +385,7 @@ public class PatentExportService {
         }
         HSSFWorkbook hssfWorkbook = this.getExportHssWorkbook(headers);
         HSSFSheet hssfSheet = hssfWorkbook.createSheet();
-        QueryRequest queryRequest = new QueryRequest();
+        StringRequest queryRequest = new StringRequest();
         BeanUtils.copyProperties(esVO, queryRequest);
 
         EsQueryPatentFieldsDTO esQueryPatentFieldsDTO = new EsQueryPatentFieldsDTO();
@@ -395,16 +397,16 @@ public class PatentExportService {
         Long startNum = null;
         Long endNum = null;
         if (esVO.getStartNumber() != null) {
-            startNum = Long.getLong(esVO.getStartNumber().toString());
+            startNum =0l+esVO.getStartNumber();
         }
         if (esVO.getEndNumber() != null) {
-            endNum = Long.getLong(esVO.getEndNumber().toString());
+            endNum = 0l+esVO.getEndNumber();
         }
 
         if (startNum == null) {
             startNum = 1l;
         }
-        Long toNum = 10L;
+        Long toNum = startNum+9l;
         if (endNum != null && endNum < toNum) {
             toNum = endNum;
         }
@@ -414,7 +416,7 @@ public class PatentExportService {
 
         EsPatentCommonVO esPatentCommonVO = esService.tranPatentRequestToComVO(queryRequest);
         esPatentCommonVO.setStartNum(startNum);
-        esPatentCommonVO.setEndNum(endNum);
+        esPatentCommonVO.setEndNum(toNum);
         Records firstRecords = this.queryPatents(esPatentCommonVO);
 
         Long total = 0l;
@@ -431,6 +433,8 @@ public class PatentExportService {
         } else {
             firstRecords.getTotal();
         }
+
+        this.updateTaskStateToDoing(taskId,total);
         List<Patent> firstPatentList = (List<Patent>) firstRecords.getData();
         List<String> firstPatentNos = firstPatentList.stream().map(Patent::getPatentNo).collect(Collectors.toList());
         ;
@@ -445,6 +449,7 @@ public class PatentExportService {
             this.loadPatentCell(patent, selectedFields, patentConfigVOS, firstEsPatentFieldsVOS, hssfSheet, commonCellStyle, index);
 
             index++;
+            importTaskAMVO.setDoneNum(index);
             this.sendWebSocketMessage(projectId, taskId, createId, total.intValue(), index, false);
         }
 
@@ -478,6 +483,8 @@ public class PatentExportService {
                 this.loadPatentCell(patent, selectedFields, patentConfigVOS, esPatentFieldsVOS, hssfSheet, commonCellStyle, index);
 
                 index++;
+                importTaskAMVO.setDoneNum(index);
+
                 this.sendWebSocketMessage(projectId, taskId, createId, total.intValue(), index, false);
 
             }
@@ -486,8 +493,8 @@ public class PatentExportService {
 
         esQueryPatentFieldsDTO.setPatentNos(inNos);
         List<EsPatentFieldsVO> esPatentFieldsVOS = esCustomFieldService.getPatentFields(esQueryPatentFieldsDTO);
-        List<Patent> patentList =  esPatentService.getPatentsByNo(inNos,true,null,null);
-        for (int i=0;i<patentList.size();i++){
+        List<Patent> patentList = esPatentService.getPatentsByNo(inNos, true, null, null);
+        for (int i = 0; i < patentList.size(); i++) {
 
             Patent patent = patentList.get(i);
             if (notInNos != null && notInNos.contains(patent.getPatentNo())) {
@@ -496,6 +503,7 @@ public class PatentExportService {
             this.loadPatentCell(patent, selectedFields, patentConfigVOS, esPatentFieldsVOS, hssfSheet, commonCellStyle, index);
 
             index++;
+            importTaskAMVO.setDoneNum(index);
             this.sendWebSocketMessage(projectId, taskId, createId, total.intValue(), index, false);
 
         }
@@ -581,7 +589,7 @@ public class PatentExportService {
                                     String valueStr = fieldValueVO.getValue();
                                     sb.append(valueStr);
                                 }
-                                HSSFCell cell = row.createCell(index);
+                                HSSFCell cell = row.createCell(j);
                                 ExcelUtils.setExcelCellStyle(commonCellStyle);
                                 commonCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
                                 commonCellStyle.setWrapText(true);
@@ -602,7 +610,7 @@ public class PatentExportService {
                     GetValueImp getValueImp = patentExportFactory.getClass(exportClass);
                     if (getValueImp != null) {
                         String reValue = getValueImp.getValue(value);
-                        HSSFCell cell = row.createCell(index);
+                        HSSFCell cell = row.createCell(j);
                         cell.setCellStyle(commonCellStyle);
                         cell.setCellValue(reValue);
                     }

+ 7 - 0
src/main/java/cn/cslg/pas/service/business/PatentProjectService.java

@@ -329,6 +329,13 @@ public class PatentProjectService extends ServiceImpl<PatentProjectMapper, Paten
             projectQuartzSetDTO.setUpdateCycle(patentProjectDTO.getUpdateCycle());
             this.setProjectQuartz(projectQuartzSetDTO);
         }
+        else{
+            PatentProject patentProject = new PatentProject();
+            patentProject.setProjectId(project.getId());
+            patentProject.setIfUpdate(patentProjectDTO.getIfUpdate());
+            patentProject.setUpdateCycle(patentProjectDTO.getUpdateCycle());
+            patentProject.insert();
+        }
 
         /**
          * 装载事件与project关联

+ 10 - 1
src/main/java/cn/cslg/pas/service/importPatent/SchedulingTaskService.java

@@ -183,6 +183,15 @@ public class SchedulingTaskService {
 
     }
 
-   public void StartExportTask(ExportTaskDTO exportTask){
+   public void startExportTask(ExportTaskDTO exportTask) throws Exception{
+       if (importTaskAMVOS == null) {
+           importTaskAMVOS = new ArrayList<>();
+       }
+       ImportTaskAMVO importTaskAMVO =new ImportTaskAMVO();
+       importTaskAMVO.setDoneNum(0);
+       importTaskAMVO.setId(exportTask.getTaskId());
+       importTaskAMVO.setProjectId(exportTask.getProjectId());
+       importTaskAMVOS.add(importTaskAMVO);
+       patentExportService.exportPatent2(exportTask, importTaskAMVO);
    }
 }