Przeglądaj źródła

Merge remote-tracking branch 'origin/master' into prod_test

lwhhszx 1 rok temu
rodzic
commit
94f35a9951

+ 94 - 0
src/main/java/cn/cslg/pas/common/utils/DateUtils2.java

@@ -1,6 +1,7 @@
 package cn.cslg.pas.common.utils;
 
 
+import cn.cslg.pas.common.utils.utilVO.CheckDateConditionVO;
 import cn.cslg.pas.common.utils.utilVO.NowDateFirstMessVO;
 import cn.hutool.core.date.DateUtil;
 import org.joda.time.DateTime;
@@ -243,5 +244,98 @@ public class DateUtils2 {
 
     }
 
+    public static CheckDateConditionVO checkDateCycleCondition(LocalDate today) {
+        if (today == null) {
+            today = LocalDate.now();
+        }
+        // 假设我们以周一为一周的第一天
+        DayOfWeek firstDayOfWeek = DayOfWeek.SUNDAY;
+        // 判断是否是这周的第一天
+
+        // 判断是否是这个月的第一天
+        boolean  ifMeetMonth = today.getDayOfMonth() >=7;
+
+        // 找到当前月份的第一天
+        // 检查这个第一天是否也是季度的第一天
+        // 季度月份是1月、4月、7月、10月
+        boolean ifQuarter = (today.getMonthValue() % 3 == 1);
+        boolean ifMeetQuarterDay = today.getDayOfMonth() <7;
+        // 判断是否是季度的第一天
+        Boolean ifMeetQuarter = !(ifQuarter&&ifMeetQuarterDay);
+        // 判断是否是这年的第一天
+        boolean ifMeetYear = today.getDayOfYear() >=7;
+        CheckDateConditionVO checkDateConditionVO = new CheckDateConditionVO();
+        checkDateConditionVO.setIfMeetMonth(ifMeetMonth);
+        checkDateConditionVO.setIfMeetYear(ifMeetYear);
+        checkDateConditionVO.setIfMeetQuarter(ifMeetQuarter);
+        return checkDateConditionVO;
+    }
+
+
+    public static List<String> getWeekRange(LocalDate localDate){
+        List<String> ranges =new ArrayList<>();
+        LocalDate firstDayOfWeek = localDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
+        LocalDate lastDayOfWeek = firstDayOfWeek.plusDays(6);
+        java.time.format.DateTimeFormatter formatter =java.time.format.DateTimeFormatter.ofPattern("yyyyMMdd");
+        // 使用formatter将LocalDate转换为字符串
+        String formattedDate1 = firstDayOfWeek.format(formatter);
+        String formattedDate2 =lastDayOfWeek.format(formatter);
+        ranges.add(formattedDate1);
+        ranges.add(formattedDate2);
+        return ranges;
+    }
+
+    public static List<String> getMonthRange(LocalDate localDate){
+        List<String> ranges =new ArrayList<>();
+        LocalDate firstDayOfMonth = localDate.with(TemporalAdjusters.firstDayOfMonth());
+        LocalDate lastDayOfMonth= localDate.with(TemporalAdjusters.lastDayOfMonth());
+        java.time.format.DateTimeFormatter formatter =java.time.format.DateTimeFormatter.ofPattern("yyyyMMdd");
+        // 使用formatter将LocalDate转换为字符串
+        String formattedDate1 = firstDayOfMonth.format(formatter);
+        String formattedDate2 =lastDayOfMonth.format(formatter);
+        ranges.add(formattedDate1);
+        ranges.add(formattedDate2);
+        return ranges;
+    }
+
+    public static List<String> getQuartzRange(LocalDate localDate){
+
+        List<String> ranges =new ArrayList<>();
+        // 计算当前季度的起始月份
+        int startMonth = (localDate.getMonthValue() - 1) / 3 * 3 + 1;
+
+        // 获取当前季度的第一天
+        LocalDate firstDayOfQuarter = LocalDate.of(localDate.getYear(), startMonth, 1);
+
+        // 计算当前季度的结束月份
+        int endMonth = startMonth + 3;
+
+        // 获取当前季度的最后一天
+        LocalDate lastDayOfQuarter = LocalDate.of(localDate.getYear(), endMonth, 1).minusDays(1);
+        java.time.format.DateTimeFormatter formatter =java.time.format.DateTimeFormatter.ofPattern("yyyyMMdd");
+        // 使用formatter将LocalDate转换为字符串
+        String formattedDate1 = firstDayOfQuarter.format(formatter);
+        String formattedDate2 =lastDayOfQuarter.format(formatter);
+        ranges.add(formattedDate1);
+        ranges.add(formattedDate2);
+        return ranges;
+    }
+
+    public static List<String> getYearRange(LocalDate localDate){
+        List<String> ranges =new ArrayList<>();
+
+        // 获取当前年的第一天(1月1日)
+        LocalDate firstDayOfYear = LocalDate.of(localDate.getYear(), 1, 1);
+
+        // 获取当前年的最后一天(12月31日)
+        LocalDate lastDayOfYear = LocalDate.of(localDate.getYear(), 12, 31);
+        java.time.format.DateTimeFormatter formatter =java.time.format.DateTimeFormatter.ofPattern("yyyyMMdd");
+        String formattedDate1 = firstDayOfYear.format(formatter);
+        String formattedDate2 =lastDayOfYear.format(formatter);
+        ranges.add(formattedDate1);
+        ranges.add(formattedDate2);
+        return ranges;
+    }
+
 
 }

+ 11 - 0
src/main/java/cn/cslg/pas/common/utils/utilVO/CheckDateConditionVO.java

@@ -0,0 +1,11 @@
+package cn.cslg.pas.common.utils.utilVO;
+
+import lombok.Data;
+
+@Data
+public class CheckDateConditionVO {
+    private Boolean ifMeetWeek;
+    private Boolean ifMeetMonth;
+    private Boolean ifMeetQuarter;
+    private Boolean ifMeetYear;
+}

+ 1 - 0
src/main/java/cn/cslg/pas/controller/CommonController.java

@@ -158,6 +158,7 @@ public class CommonController {
         qrtzTaskDTO.setQuartzVO(quartzVO);
         qrtzTaskDTO.setJobClass("cn.cslg.pas.service.quartzService.SysImportPatentJobService");
         qrtzTaskDTO.setCron("0 0 0 * * ? *");
+        //qrtzTaskDTO.setCron("0/10 * * * * ?");
         jobService.addJob(qrtzTaskDTO);
         return Response.success("");
     }

+ 62 - 0
src/main/java/cn/cslg/pas/factorys/EsBuilderFactory/ExistsQueryBuilder.java

@@ -0,0 +1,62 @@
+package cn.cslg.pas.factorys.EsBuilderFactory;
+
+
+import co.elastic.clients.elasticsearch._types.query_dsl.Query;
+import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
+import org.springframework.stereotype.Component;
+
+import java.text.ParseException;
+
+@Component
+public class ExistsQueryBuilder implements IQueryBuilder{
+    public String field = "";
+    public String value = "";
+    public String operator = "";
+    public String path = "";
+    public Integer projectId = null;
+
+    @Override
+    public Query creteQuery() throws ParseException {
+        return QueryBuilders.exists(i -> i.field(field));
+    }
+
+    public String getField() {
+        return field;
+    }
+
+    public void setField(String field) {
+        this.field = field;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+    public String getOperator() {
+        return operator;
+    }
+
+    public void setOperator(String operator) {
+        this.operator = operator;
+    }
+
+    public String getPath() {
+        return path;
+    }
+
+    public void setPath(String path) {
+        this.path = path;
+    }
+
+    public Integer getProjectId() {
+        return projectId;
+    }
+
+    public void setProjectId(Integer projectId) {
+        this.projectId = projectId;
+    }
+}

+ 4 - 4
src/main/java/cn/cslg/pas/service/MailSendService.java

@@ -128,7 +128,7 @@ public class MailSendService {
         map.put("title", "任务通知");
         map.put("template", "mail/eTask.html");
         map.put("value1", handlePerson);
-        map.put("img", "\\src\\main\\resources\\mail\\logo.png");
+        map.put("img", "/logo.png");
         map.put("email", email);
         map.put("value2", addPerson);
         map.put("value3", taskName);
@@ -151,7 +151,7 @@ public class MailSendService {
             map.put("title", "任务通知");
             map.put("template", "mail/eTaskDone.html");
             map.put("value1", personnel.getPersonnelName());
-            map.put("img", "\\src\\main\\resources\\mail\\logo.png");
+            map.put("img", "/logo.png");
             map.put("email", personnel.getPersonnelEmail());
             map.put("value2", taskTypeName);
             map.put("value3", taskName);
@@ -178,7 +178,7 @@ public class MailSendService {
             map.put("title", "监控通知");
             map.put("template", "mail/cycleTaskDone.html");
             map.put("value1", personnel.getPersonnelName());
-            map.put("img", "\\src\\main\\resources\\mail\\logo.png");
+            map.put("img", "/logo.png");
             map.put("email", personnel.getPersonnelEmail());
             map.put("value2", project.getName());
             String dateRange = "";
@@ -213,7 +213,7 @@ public class MailSendService {
         Map<String, Object> map = new LinkedHashMap<>();
         map.put("title", "监控通知");
         map.put("template", "mail/sysCycleStart.html");
-        map.put("img", "\\src\\main\\resources\\mail\\logo.png");
+        map.put("img", "/logo.png");
         if (systemDictList != null && systemDictList.size() > 0) {
             SystemDict systemDict = systemDictList.remove(0);
             map.put("email", systemDict.getValue());

+ 56 - 30
src/main/java/cn/cslg/pas/service/business/ImportTaskService.java

@@ -1,5 +1,6 @@
 package cn.cslg.pas.service.business;
 
+import cn.cslg.pas.common.core.base.Cycle;
 import cn.cslg.pas.common.dto.ExportTaskDTO;
 import cn.cslg.pas.common.dto.ImportTaskDTO;
 import cn.cslg.pas.common.dto.PatentStarListDTO;
@@ -42,6 +43,7 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.*;
+import java.time.LocalDate;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -84,7 +86,8 @@ public class ImportTaskService extends ServiceImpl<ImportTaskMapper, ImportTask>
     private ImportTaskConditionService importTaskConditionService;
     @Autowired
     private MailSendService mailSendService;
-
+    @Autowired
+    private PatentProjectService patentProjectService;
     @Override
     public Object queryMessage(QueryRequest queryRequest) throws Exception {
         List<String> sqls = formatQueryService.reSqls(queryRequest, "importTask");
@@ -493,6 +496,10 @@ public class ImportTaskService extends ServiceImpl<ImportTaskMapper, ImportTask>
             if (exportTaskDTO.getDefaultNum() != null) {
                 importTask.setDefaultNum(exportTaskDTO.getDefaultNum());
             }
+            if (exportTaskDTO.getDoneNum() != null) {
+                importTask.setDoneNum(exportTaskDTO.getDoneNum());
+
+            }
             importTask.setFinishTime(exportTaskDTO.getFinishTime());
             importTask.updateById();
         }
@@ -549,36 +556,55 @@ public class ImportTaskService extends ServiceImpl<ImportTaskMapper, ImportTask>
         return importTask.getId();
     }
 
-    public void addImportTaskByCondition(ImportTaskCondition importTaskCondition) {
-
-        ImportTask importTask = new ImportTask();
-        //根据id查询最近更新的任务
+    public void addImportTaskByCondition(ImportTaskCondition importTaskCondition,PatentProject project) {
+        String condition = importTaskCondition.getSearchCondition();
+        String updateCycle = project.getUpdateCycle();
+
+        if (updateCycle == null) {
+            return;
+        }
+        LocalDate localDate = LocalDate.now();
+        List<String> dateRange = new ArrayList<>();
+        switch (updateCycle) {
+            case Cycle.WEEK:
+                LocalDate localDateWeek = localDate.minusWeeks(2);
+                dateRange = DateUtils2.getWeekRange(localDateWeek);
+                break;
+            case Cycle.MONTH:
+                LocalDate localDateMonth = localDate.minusMonths(1);
+                dateRange = DateUtils2.getMonthRange(localDateMonth);
+                break;
+            case Cycle.QUARTER:
+                LocalDate localDateQuartz = localDate.minusMonths(4);
+                dateRange = DateUtils2.getQuartzRange(localDateQuartz);
+                break;
+            case Cycle.YEAR:
+                LocalDate localYear = localDate.minusYears(1);
+                dateRange = DateUtils2.getYearRange(localYear);
+                break;
+        }
+        if (dateRange.size() < 2) {
+            return;
+        }
+        Date start = DateUtils.strToDate(dateRange.get(0));
+        Date end = DateUtils.strToDate((dateRange.get(1)));
         LambdaQueryWrapper<ImportTask> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.eq(ImportTask::getImportTaskConditionId, importTaskCondition.getId())
-                .orderByDesc(ImportTask::getUpdateToDate);
+                .eq(ImportTask::getUpdateToDate, end)
+                .eq(ImportTask::getLastUpdateToDate, start);
         ImportTask lastImportTask = this.getOne(queryWrapper, false);
-        String condition = importTaskCondition.getSearchCondition();
-        Date date = new Date();
-        Date toDate = DateUtils.getDate(date, -7);
-        if (lastImportTask == null) {
-            String toDateStr = DateUtils2.dateTimeToPatentStr(toDate);
-            condition = condition + " and ( PD<" + toDateStr + " or GD<" + toDateStr+")";
-            importTask.setUpdateToDate(toDate);
-        } else if (lastImportTask != null && lastImportTask.getUpdateToDate() != null) {
-            Date fromDate = DateUtils.getDate(lastImportTask.getUpdateToDate(), 1);
-            String fromDateStr = DateUtils2.dateTimeToPatentStr(fromDate);
-            String todateStr = DateUtils2.dateTimeToPatentStr(toDate);
-            importTask.setLastUpdateToDate(fromDate);
-            importTask.setUpdateToDate(toDate);
-            condition = condition + " and (PD=" + fromDateStr + "~" + todateStr + " or GD=" + fromDateStr + "~" + todateStr + ")";
-        } else if (lastImportTask != null && lastImportTask.getUpdateToDate() == null) {
-            Date fromDate = DateUtils.getDate(lastImportTask.getCreateTime(), -7);
-            String fromDateStr = DateUtils2.dateTimeToPatentStr(fromDate);
-            String todateStr = DateUtils2.dateTimeToPatentStr(toDate);
-            importTask.setLastUpdateToDate(fromDate);
-            importTask.setUpdateToDate(toDate);
-            condition = condition + " and (PD=" + fromDateStr + "~" + todateStr + " or GD=" + fromDateStr + "~" + todateStr + ")";
+        if (lastImportTask != null) {
+            return;
         }
+        ImportTask importTask = new ImportTask();
+
+
+            String fromDateStr = DateUtils2.dateTimeToPatentStr(start);
+            String todateStr = DateUtils2.dateTimeToPatentStr(end);
+            importTask.setLastUpdateToDate(start);
+            importTask.setUpdateToDate(end);
+            condition = condition + " and (PD=" + fromDateStr + "~" + todateStr + " or GD=" + fromDateStr + "~" + todateStr + ")";
+
         PatentStarListDTO patentStarListDto = new PatentStarListDTO()
                 .setCurrentQuery(condition)
                 .setPageNum(1)
@@ -589,7 +615,7 @@ public class ImportTaskService extends ServiceImpl<ImportTaskMapper, ImportTask>
         try {
             Map<String, Object> resultMap = patentStarApiService.patentStarSearchApi(patentStarListDto);
             if (resultMap == null) {
-                    importTask.setAllNum(-1);
+                importTask.setAllNum(-1);
             } else {
 
                 importTask.setAllNum((Integer) resultMap.get("total"));
@@ -605,9 +631,9 @@ public class ImportTaskService extends ServiceImpl<ImportTaskMapper, ImportTask>
         importTask.setSearchCondition(condition);
         importTask.setCreateId(importTaskCondition.getCreateId());
         importTask.setIfCreateBySys(true);
-        if (importTask.getAllNum() !=null&&importTask.getAllNum() <= 0) {
+        if (importTask.getAllNum() != null && importTask.getAllNum() <= 0) {
             importTask.setState(2);
-            //mailSendService.sendCycleImportTaskDoneEmail(importTask);
+            mailSendService.sendCycleImportTaskDoneEmail(importTask);
             importTask.insert();
         } else {
             importTask.insert();

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

@@ -1056,7 +1056,7 @@ public class MergePersonService extends ServiceImpl<MergePersonMapper, MergePers
 
     public Integer delete(List<String> ids) {
         Query query = QueryBuilders.ids(n -> n.values(ids));
-        DeleteByQueryRequest request = DeleteByQueryRequest.of(i -> i.index("patent").query(query));
+        DeleteByQueryRequest request = DeleteByQueryRequest.of(i -> i.index("patent").refresh(true).query(query));
         try {
             client.deleteByQuery(request);
             return 1;

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

@@ -258,15 +258,7 @@ public class PatentExportService {
             }
             hssfWorkbook.write(out);
             log.info("导出excel结束,总数据量={},耗时={}ms", total, System.currentTimeMillis() - startTime);
-            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);
@@ -280,7 +272,15 @@ public class PatentExportService {
             if (taskId == null) {
                 throw new XiaoShiException("导出记录失败");
             }
-
+            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);
         } catch (FileNotFoundException e) {
             throw new FileNotFoundException();
         } catch (Exception e) {
@@ -488,7 +488,7 @@ public class PatentExportService {
                 index++;
                 importTaskAMVO.setDoneNum(index);
 
-                this.sendWebSocketMessage(projectId, taskId, createId, total.intValue(), index, true);
+                this.sendWebSocketMessage(projectId, taskId, createId, total.intValue(), index, false);
 
             }
 
@@ -513,6 +513,7 @@ public class PatentExportService {
 
         }
 
+        this.sendWebSocketMessage(projectId, taskId, createId, total.intValue(), index, true);
 
         try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
 
@@ -524,12 +525,15 @@ public class PatentExportService {
             }
             exportTask.setFileGuid(fileGuid);
             exportTask.setState(2);
+            exportTask.setDoneNum(index);
             Integer reTaskId = importTaskService.updateExportTask(exportTask);
             if (reTaskId == null) {
                 throw new XiaoShiException("导出记录失败");
             }
 
-        } catch (FileNotFoundException e) {
+        }
+
+        catch (FileNotFoundException e) {
             e.printStackTrace();
             throw new FileNotFoundException();
         } catch (Exception e) {

+ 18 - 15
src/main/java/cn/cslg/pas/service/business/ProductCategoryService.java

@@ -283,14 +283,17 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
         assoProductCategoryPeople.add(assoProductCategoryAdmin);
         //设置的管理员
         List<String> adminIds = updateProductCategoryDTO.getAdminIds();
-        for (String adminId : adminIds) {
-            AssoProductCategoryPerson admin = new AssoProductCategoryPerson();
-            admin.setProductCategoryId(productCategory.getId());
-            admin.setPersonId(adminId);
-            admin.setRole(0);
-            admin.setCreateId(personnelVO.getId());
-            assoProductCategoryPeople.add(admin);
+        if (!CollectionUtils.isEmpty(adminIds)) {
+            for (String adminId : adminIds) {
+                AssoProductCategoryPerson admin = new AssoProductCategoryPerson();
+                admin.setProductCategoryId(productCategory.getId());
+                admin.setPersonId(adminId);
+                admin.setRole(0);
+                admin.setCreateId(personnelVO.getId());
+                assoProductCategoryPeople.add(admin);
+            }
         }
+
         //判断可见类型:
         Integer showType = updateProductCategoryDTO.getShowType();
         if (showType != 0 && showType != 1) {
@@ -326,13 +329,13 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
         List<AssoProductCategoryFile> assoFiles = assoProductCategoryFileService.list(wrapper);
         List<String> fileGuIds = assoFiles.stream().map(AssoProductCategoryFile::getFileGuid).collect(Collectors.toList());
         //获取更新后的附件ids
-        List<String> updateFileGuIds = new ArrayList<>();
-        if (updateProductCategoryDTO.getGuids() != null && updateProductCategoryDTO.getGuids().size() != 0) {
-            updateFileGuIds = updateProductCategoryDTO.getGuids();
-            fileGuIds.retainAll(updateFileGuIds);
-        }
-        //做差获得被删除的文件id
-        if (fileGuIds.size() != 0) {
+//        List<String> updateFileGuIds = new ArrayList<>();
+//        if (updateProductCategoryDTO.getGuids() != null && updateProductCategoryDTO.getGuids().size() != 0) {
+//            updateFileGuIds = updateProductCategoryDTO.getGuids();
+//            fileGuIds.retainAll(updateFileGuIds);
+//        }
+        //根据guid进行删除产品分类和文件关联表以及文件
+        if (!CollectionUtils.isEmpty(fileGuIds)) {
             //根据文件id删除产品类别与文件关联表记录
             LambdaQueryWrapper<AssoProductCategoryFile> deleteWrapper = new LambdaQueryWrapper<>();
             deleteWrapper.in(AssoProductCategoryFile::getFileGuid, fileGuIds);
@@ -345,7 +348,7 @@ public class ProductCategoryService extends ServiceImpl<ProductCategoryMapper, P
             }
         }
         //添加文件
-        if (files != null && files.size() != 0) {
+        if (!CollectionUtils.isEmpty(files)) {
             try {
                 List<String> guids = fileManagerService.uploadFileGetGuid(files);
                 List<AssoProductCategoryFile> assoProductCategoryFiles = new ArrayList<>();

+ 16 - 13
src/main/java/cn/cslg/pas/service/business/ProductService.java

@@ -310,14 +310,17 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
         assoProductPeople.add(assoProductAdmin);
         //设置的管理员
         List<String> adminIds = updateProductDTO.getAdminIds();
-        for (String adminId : adminIds) {
-            AssoProductPerson admin = new AssoProductPerson();
-            admin.setProductId(product.getId());
-            admin.setPersonId(adminId);
-            admin.setRole(0);
-            admin.setCreateId(personnelVO.getId());
-            assoProductPeople.add(admin);
+        if (!CollectionUtils.isEmpty(adminIds)) {
+            for (String adminId : adminIds) {
+                AssoProductPerson admin = new AssoProductPerson();
+                admin.setProductId(product.getId());
+                admin.setPersonId(adminId);
+                admin.setRole(0);
+                admin.setCreateId(personnelVO.getId());
+                assoProductPeople.add(admin);
+            }
         }
+
         //判断可见类型:
         Integer showType = updateProductDTO.getShowType();
         if (showType != 0 && showType != 1) {
@@ -353,13 +356,13 @@ public class ProductService extends ServiceImpl<ProductMapper, Product> implemen
         List<AssoProductFile> assoFiles = assoProductFileService.list(wrapper);
         List<String> fileGuIds = assoFiles.stream().map(AssoProductFile::getFileGuid).collect(Collectors.toList());
         //获取更新后的附件ids
-        List<String> updateFileGuIds = new ArrayList<>();
-        if (updateProductDTO.getGuids() != null && updateProductDTO.getGuids().size() != 0) {
-            updateFileGuIds = updateProductDTO.getGuids();
-            fileGuIds.retainAll(updateFileGuIds);
-        }
+//        List<String> updateFileGuIds = new ArrayList<>();
+//        if (updateProductDTO.getGuids() != null && updateProductDTO.getGuids().size() != 0) {
+//            updateFileGuIds = updateProductDTO.getGuids();
+//            fileGuIds.retainAll(updateFileGuIds);
+//        }
         //做差获得被删除的文件id
-        if (fileGuIds.size() != 0) {
+        if (!CollectionUtils.isEmpty(fileGuIds)) {
             //根据文件id删除产品与文件关联表记录
             LambdaQueryWrapper<AssoProductFile> deleteWrapper = new LambdaQueryWrapper<>();
             deleteWrapper.in(AssoProductFile::getFileGuid, fileGuIds);

+ 51 - 39
src/main/java/cn/cslg/pas/service/business/es/EsCountService.java

@@ -28,6 +28,7 @@ import co.elastic.clients.elasticsearch.core.SearchRequest;
 import co.elastic.clients.elasticsearch.core.SearchResponse;
 import co.elastic.clients.elasticsearch.core.search.FieldCollapse;
 import co.elastic.clients.elasticsearch.core.search.Hit;
+import co.elastic.clients.elasticsearch.core.search.TotalHits;
 import com.alibaba.fastjson.JSON;
 import lombok.RequiredArgsConstructor;
 import org.apache.commons.lang3.StringUtils;
@@ -204,7 +205,7 @@ public class EsCountService {
                         }
                     } else if (childList.contains(field)) {
                         if (CollectionUtils.isEmpty(values)) {
-                            this.getChildCountDTOS(agg, field, fieldType, topN, detailDTOS, esCountDTO,projectId,fieldId,query,null);
+                            this.getChildCountDTOS(agg, field, fieldType, topN, detailDTOS, esCountDTO,projectId,fieldId,query);
                         } else {
                             this.getChildAnalysisDTOS(agg, field, fieldType, topN,
                                     detailDTOS, esCountDTO, firstName, map, values);
@@ -743,7 +744,7 @@ public class EsCountService {
      */
     public void getChildCountDTOS(Aggregate agg, String field, Integer fieldType, Integer topN,
                                   List<EsCountDetailDTO> detailDTOS, EsCountDTO esCountDTO,Integer projectId,
-                                  String fieldId,Query query,String esField) throws Exception {
+                                  String fieldId,Query query) throws Exception {
         esCountDTO.setAllNumber(agg.children().docCount());
         Aggregate childAgg = agg.children().aggregations().get("childAgg");
         List<StringTermsBucket> list = childAgg.sterms().buckets().array();
@@ -765,12 +766,12 @@ public class EsCountService {
             });
         });
         if (fieldType == null || fieldType != 6) {
-            Integer customNum1 = this.getUnselectedCustomNum1(projectId, fieldId, query);
+            Long customNum = this.getUnselectedCustomNum1(projectId, fieldId, query);
             EsCountDetailDTO detail = new EsCountDetailDTO();
             detail.setField(field);
             detail.setName("未选择");
-            if (customNum1 != null) {
-                detail.setNumber(customNum1.longValue());
+            if (customNum != null) {
+                detail.setNumber(customNum);
             } else {
                 detail.setNumber(0L);
             }
@@ -800,28 +801,42 @@ public class EsCountService {
     }
 
     //统计未选择数量
-    public Integer getUnselectedCustomNum1(Integer projectId, String fieldId, Query query) throws Exception {
+    public Long getUnselectedCustomNum1(Integer projectId, String fieldId, Query query) throws Exception {
         SearchRequest.Builder builder = new SearchRequest.Builder();
         //设置查询索引
         builder.index("patent");
         builder.query(query);
-        builder.from(0).size(10000);
-        builder.trackTotalHits(i -> i.enabled(true));
         SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
-        List<Hit<Patent>> hits = response.hits().hits();
-        List<String> list = new ArrayList<>();
-        for (Hit<Patent> hit : hits) {
-            String id = hit.id();
-            list.add(id);
-        }
-        if (!CollectionUtils.isEmpty(list)) {
-            return this.ifExistChild1(list, projectId, fieldId);
+        long total = response.hits().total().value();
+        final long childCount = this.ifExistChild1(projectId, fieldId,query);
+        return total - childCount;
+    }
+
+    public Long ifExistChild1(Integer projectId, String fieldId,Query query) throws IOException {
+        SearchRequest.Builder builder = new SearchRequest.Builder();
+        //设置查询索引
+        builder.index("patent");
+        Query q1 = QueryBuilders.exists(i -> i.field("custom_field"));
+        Query q2 = QueryBuilders.exists(i -> i.field("custom_field.field_value"));
+        Query q3 = QueryBuilders.term(i -> i.field("custom_field.if_new").value(1));
+        Query q4 = QueryBuilders.term(i -> i.field("custom_field.project_id").value(projectId));
+        Query q5 = QueryBuilders.term(i -> i.field("custom_field.field").value(fieldId));
+        Query bool = QueryBuilders.bool(i -> i.must(q1,q2, q3, q4, q5));
+        Query childQ = QueryBuilders.hasChild(i -> i.type("project_customfield").query(bool));
+        if (query != null) {
+            Query bool1 = QueryBuilders.bool(i -> i.must(query, childQ));
+            builder.query(bool1);
+        } else {
+            builder.query(childQ);
         }
-        return 0;
+        SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
+        return response.hits().total().value();
     }
 
     //根据未选择查询专利
     public GetUnselectedDTO getUnselectedCustomNum(Integer projectId, String fieldId) throws Exception {
+        Integer pageNum = 0;
+        Integer pageSize = 1000;
         GetUnselectedDTO dto = new GetUnselectedDTO();
         SearchRequest.Builder builder = new SearchRequest.Builder();
         //设置查询索引
@@ -829,7 +844,7 @@ public class EsCountService {
         Query query = QueryBuilders.term(i -> i.field("project_id").value(projectId));
         Query q = QueryBuilders.hasChild(i -> i.type("project").query(query));
         builder.query(q);
-        builder.from(0).size(10000);
+        builder.from(pageNum).size(pageSize);
         builder.trackTotalHits(i -> i.enabled(true));
         SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
         List<Hit<Patent>> hits = response.hits().hits();
@@ -838,35 +853,24 @@ public class EsCountService {
             String id = hit.id();
             list.add(id);
         }
+        long total = response.hits().total().value();
+        int sum = pageSize;
+        while (sum < total) {
+            pageNum = sum;
+            sum += 1000;
+            List<String> list1 = this.loadingBatchData(projectId, null, pageNum, pageSize);
+            list.addAll(list1);
+        }
         if (!CollectionUtils.isEmpty(list)) {
             dto = this.ifExistChild(list, projectId, fieldId);
         }
         return dto;
     }
 
-    public Integer ifExistChild1(List<String> list, Integer projectId, String fieldId) throws IOException {
-        int count = 0;
-        SearchRequest.Builder builder = new SearchRequest.Builder();
-        //设置查询索引
-        builder.index("patent");
-        Query ids = QueryBuilders.ids(i -> i.values(list));
-        Query q1 = QueryBuilders.hasParent(i -> i.parentType("patent").query(ids));
-        Query q2 = QueryBuilders.exists(i -> i.field("custom_field"));
-        Query q3 = QueryBuilders.term(i -> i.field("custom_field.if_new").value(1));
-        Query q4 = QueryBuilders.term(i -> i.field("custom_field.project_id").value(projectId));
-        Query q5 = QueryBuilders.term(i -> i.field("custom_field.field").value(fieldId));
-        Query bool = QueryBuilders.bool(i -> i.must(q1, q2, q3, q4, q5));
-        builder.query(bool);
-        SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
-        if (response.hits().total() != null) {
-            long total = response.hits().total().value();
-            count = list.size() - (int) total;
-        }
-        return count;
-    }
-
     //查询到对应的ids
     public GetUnselectedDTO ifExistChild(List<String> list, Integer projectId, String fieldId) throws IOException {
+        Integer pageNum = 0;
+        Integer pageSize = 1000;
         GetUnselectedDTO dto = new GetUnselectedDTO();
         SearchRequest.Builder builder = new SearchRequest.Builder();
         //设置查询索引
@@ -884,6 +888,14 @@ public class EsCountService {
         SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
         List<Hit<Patent>> hits = response.hits().hits();
         List<String> collect = hits.stream().map(Hit::routing).collect(Collectors.toList());
+        long total = response.hits().total().value();
+        int sum = pageSize;
+        while (sum < total) {
+            pageNum = sum;
+            sum += 1000;
+            List<String> list1 = this.loadingBatchData(projectId, null, pageNum, pageSize);
+            list.addAll(list1);
+        }
         list.removeAll(collect);
         dto.setBeinglessChildIds(list);
         return dto;

+ 1 - 1
src/main/java/cn/cslg/pas/service/business/es/EsProductPatentService.java

@@ -96,7 +96,7 @@ public class EsProductPatentService {
 
     public Integer delProduct(List<String> ids) {
         Query query = QueryBuilders.ids(n -> n.values(ids));
-        DeleteByQueryRequest request = DeleteByQueryRequest.of(i -> i.index("patent").query(query));
+        DeleteByQueryRequest request = DeleteByQueryRequest.of(i -> i.index("patent").refresh(true).query(query));
         try {
             client.deleteByQuery(request);
             return 1;

+ 3 - 15
src/main/java/cn/cslg/pas/service/business/es/EsService.java

@@ -465,7 +465,6 @@ public class EsService {
         int m = 1;
         int n = 0;
         StringBuilder builder = new StringBuilder();
-        long start = System.currentTimeMillis();
         if (customFields.size() > m) {
             for (int i = 0; i < customFields.size(); i++) {
                 EsCustomFieldValueDTO customField = customFields.get(i);
@@ -489,9 +488,6 @@ public class EsService {
                 }
             }
         }
-
-        long end = System.currentTimeMillis();
-        System.out.println("耗时" + (end - start));
         return builder.toString();
     }
 
@@ -500,10 +496,6 @@ public class EsService {
                           Integer projectId, Integer taskId) throws Exception {
         builder.append("field").append("=").append(customField.getFieldId());
         List<String> values = customField.getFieldValue();
-        if (values.contains("未选择")) {
-            values.removeIf(value -> value.equals("未选择"));
-            values.add("未选择");
-        }
         if (!CollectionUtils.isEmpty(values)) {
             builder.append(" ").append("and").append(" ");
             if (ifHaveChild) {
@@ -520,9 +512,7 @@ public class EsService {
                         builder.append(s).append(" ").append("or").append(" ");
                     } else {
                         if (s.equals("未选择")) {
-                            GetUnselectedDTO unselectedDTO = esCountService.getUnselectedCustomNum(projectId, customField.getFieldId());
-                            List<String> childIds = unselectedDTO.getBeinglessChildIds();
-                            String noCondition = this.appendIds(childIds);
+                            String noCondition = "(field = (NOT " + customField.getFieldId() + ")" + " OR " + "(field = " + customField.getFieldId() + " AND " + "fieldValue1 = 1))";
                             builder.append(s).append(")").append(" ").append("OR")
                                     .append(" ").append("(").append(noCondition).append(")").append(")");
                         } else {
@@ -533,9 +523,7 @@ public class EsService {
             } else {
                 for (String value : values) {
                     if (value.equals("未选择")) {
-                        GetUnselectedDTO unselectedDTO = esCountService.getUnselectedCustomNum(projectId, customField.getFieldId());
-                        List<String> childIds = unselectedDTO.getBeinglessChildIds();
-                        String noCondition = this.appendIds(childIds);
+                        String noCondition = "(field = (NOT " + customField.getFieldId() + ")" + " OR " + "(field = " + customField.getFieldId() + " AND " + "fieldValue1 = 1))";
                         builder.append(value).append(" ").append("OR").append(" ").append(noCondition).append(")");
                     } else {
                         builder.append(value).append(")");
@@ -1421,7 +1409,7 @@ public class EsService {
 
     public Integer deleteByIds(List<String> ids) {
         Query query = QueryBuilders.ids(n -> n.values(ids));
-        DeleteByQueryRequest request = DeleteByQueryRequest.of(i -> i.index("patent").query(query)
+        DeleteByQueryRequest request = DeleteByQueryRequest.of(i -> i.index("patent").refresh(true).query(query)
                 .refresh(true));
         try {
             client.deleteByQuery(request);

+ 0 - 1
src/main/java/cn/cslg/pas/service/quartzService/ImportPatentJobService.java

@@ -31,7 +31,6 @@ private final ImportTaskService importTaskService;
                     .eq(ImportTaskCondition::getIfUpdate,true);
         List<ImportTaskCondition> importTaskConditions =importTaskConditionService.list(queryWrapper);
             importTaskConditions.forEach(item->{
-                importTaskService.addImportTaskByCondition(item);
             });
 
     }

+ 12 - 28
src/main/java/cn/cslg/pas/service/quartzService/SysImportPatentJobService.java

@@ -2,6 +2,7 @@ package cn.cslg.pas.service.quartzService;
 
 import cn.cslg.pas.common.core.base.Cycle;
 import cn.cslg.pas.common.utils.DateUtils2;
+import cn.cslg.pas.common.utils.utilVO.CheckDateConditionVO;
 import cn.cslg.pas.common.utils.utilVO.NowDateFirstMessVO;
 import cn.cslg.pas.domain.business.ImportTaskCondition;
 import cn.cslg.pas.domain.business.PatentProject;
@@ -33,24 +34,21 @@ public class SysImportPatentJobService extends QuartzJobBean {
 
     @Override
     public void executeInternal(JobExecutionContext context) throws JobExecutionException {
-//        mailSendService.sendSysCycleStartEmail();
-        LocalDate localDate = LocalDate.of(2024, 9, 1);
-        NowDateFirstMessVO messVO = DateUtils2.getNowDateFirstMessage(localDate);
-        Boolean isFirstDayOfWeek = messVO.getIsFirstDayOfWeek();
-        Boolean isFirstDayOfMonth = messVO.getIsFirstDayOfMonth();
-        Boolean isFirstDayOfQuarter = messVO.getIsFirstDayOfQuarter();
-        Boolean isFirstDayOfYear = messVO.getIsFirstDayOfYear();
+       // mailSendService.sendSysCycleStartEmail();
+        CheckDateConditionVO checkDateConditionVO = DateUtils2.checkDateCycleCondition(null);
+        Boolean ifMeetMonth = checkDateConditionVO.getIfMeetMonth();
+        Boolean ifMeetQuarter = checkDateConditionVO.getIfMeetQuarter();
+        Boolean ifMeetYear = checkDateConditionVO.getIfMeetYear();
         List<String> cycles = new ArrayList<>();
-        if (isFirstDayOfWeek != null && isFirstDayOfWeek) {
             cycles.add(Cycle.WEEK);
-        }
-        if (isFirstDayOfMonth != null && isFirstDayOfMonth) {
+
+        if (ifMeetMonth != null && ifMeetMonth) {
             cycles.add(Cycle.MONTH);
         }
-        if (isFirstDayOfQuarter != null && isFirstDayOfQuarter) {
+        if (ifMeetQuarter != null && ifMeetQuarter) {
             cycles.add(Cycle.QUARTER);
         }
-        if (isFirstDayOfYear != null && isFirstDayOfYear) {
+        if (ifMeetYear != null && ifMeetYear) {
             cycles.add(Cycle.YEAR);
         }
 
@@ -71,27 +69,13 @@ public class SysImportPatentJobService extends QuartzJobBean {
             List<ImportTaskCondition> importTaskConditions = importTaskConditionService.list(queryWrapper1);
 
             importTaskConditions.forEach(item -> {
-                importTaskService.addImportTaskByCondition(item);
+            PatentProject project=    patentProjects.stream().filter(t->t.getProjectId().equals(item.getProjectId())).findFirst().orElse(null);
+                importTaskService.addImportTaskByCondition(item,project);
             });
         }
 
 
     }
 
-    private void addProjectCycleTask(Integer projectId) {
-        LambdaQueryWrapper<PatentProject> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.eq(PatentProject::getIfUpdate, true)
-                .eq(PatentProject::getUpdateCycle, "");
-        //根据id查询检索条件
-        LambdaQueryWrapper<ImportTaskCondition> queryWrapper2 = new LambdaQueryWrapper<>();
-        queryWrapper2.eq(ImportTaskCondition::getProjectId, projectId);
-        queryWrapper2.eq(ImportTaskCondition::getIfCycle, true)
-                .eq(ImportTaskCondition::getIfUpdate, true);
-        List<ImportTaskCondition> importTaskConditions = importTaskConditionService.list(queryWrapper2);
-        importTaskConditions.forEach(item -> {
-            importTaskService.addImportTaskByCondition(item);
-        });
-
 
-    }
 }

+ 12 - 0
src/main/resources/jsons/patent.json

@@ -1363,6 +1363,18 @@
     "ifAsCondition": "true"
   },
   {
+    "name": "自定义栏位值1",
+    "type": "String",
+    "value": "fieldValue1",
+    "field": "fieldValue1",
+    "esField": "custom_field.field_value",
+    "esClass": "existsQueryBuilder",
+    "ifSearch": "false",
+    "ifGroup": "false",
+    "ifShow": "false",
+    "ifAsCondition": "true"
+  },
+  {
     "name": "自定义栏位统计值",
     "type": "String",
     "value": "statsValue",

+ 69 - 0
src/test/java/cn/cslg/pas/service/DateUtil2Tests.java

@@ -0,0 +1,69 @@
+package cn.cslg.pas.service;
+
+import cn.cslg.pas.common.dto.DomainFieldDTO;
+import cn.cslg.pas.common.utils.DateUtils2;
+import cn.cslg.pas.common.utils.GenerateObjectUtil;
+import cn.cslg.pas.controller.AvoidDesignController;
+import cn.cslg.pas.domain.business.FollowUp;
+import cn.cslg.pas.service.business.AvoidDesignService;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import java.time.LocalDate;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @Author xiexiang
+ * @Date 2023/12/5
+ */
+@SpringBootTest
+public class DateUtil2Tests {
+    @Autowired
+    private AvoidDesignService avoidDesignService;
+
+    @Autowired
+    private AvoidDesignController avoidDesignController;
+
+    @Autowired
+    private GenerateObjectUtil generateObjectUtil;
+
+    @Test
+    public void test() throws Exception {
+
+    }
+
+    @Test
+    public void testUpdate() {
+        LocalDate date =LocalDate.of(2023,9,13);
+     List<String>a=   DateUtils2.getMonthRange(date);
+System.out.println(a);
+    }
+
+    @Test
+    public void testUpdate1() {
+        LocalDate date =LocalDate.of(2023,9,13);
+        List<String>a=   DateUtils2.getYearRange(date);
+        System.out.println(a);
+    }
+
+    @Test
+    public void testUpdate2() {
+        LocalDate date =LocalDate.of(2023,9,13);
+        List<String>a=   DateUtils2.getQuartzRange(date);
+        System.out.println(a);
+    }
+
+    @Test
+    public void testUpdate3() {
+        LocalDate date =LocalDate.of(2023,9,13);
+        List<String>a=   DateUtils2.getMonthRange(date);
+        System.out.println(a);
+    }
+
+    @Test
+    public void testGet() throws Exception {
+
+    }
+}