From 8f74bbfbd9b53f9bb2dd608d5291f68ab35d4b15 Mon Sep 17 00:00:00 2001 From: zhangjun <879913833@qq.com> Date: Wed, 12 Oct 2022 12:09:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=B4=A2=E5=BC=95=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/ResetSearchCenterService.java | 88 ++++++++++++++++--- 1 file changed, 74 insertions(+), 14 deletions(-) diff --git a/adc-da-slrs/src/main/java/com/adc/da/search/server/ResetSearchCenterService.java b/adc-da-slrs/src/main/java/com/adc/da/search/server/ResetSearchCenterService.java index 515dce2a..b9c5a37f 100644 --- a/adc-da-slrs/src/main/java/com/adc/da/search/server/ResetSearchCenterService.java +++ b/adc-da-slrs/src/main/java/com/adc/da/search/server/ResetSearchCenterService.java @@ -45,6 +45,8 @@ import org.elasticsearch.client.transport.TransportClient; import org.json.JSONTokener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; @@ -571,6 +573,16 @@ public class ResetSearchCenterService { page.setMenuId("nomenu"); page.setStandType("ALL"); List rowsStand = iSarStandardsInfoService.getSarStandardsInfoPage(page); + //如果时自动触发,删除需要根据全部的结果进行数据处理 + SarStandardsInfoEOPage infoEOPage = new SarStandardsInfoEOPage(); + List allStand = null; + if (StringUtils.isNotBlank(page.getSyncParam())) { + BeanUtils.copyProperties(page, infoEOPage); + infoEOPage.setSyncParam(null); + allStand = iSarStandardsInfoService.getSarStandardsInfoPage(infoEOPage); + } + String isAll = null == allStand ? "否" : "是"; + logger.info("是否查询了全部数据信息:" + isAll); List insList = new ArrayList<>(); List updList = new ArrayList<>(); List delList = new ArrayList<>(); @@ -603,8 +615,15 @@ public class ResetSearchCenterService { updList.addAll(intersection); } + List finalStandIdList = null; // 差集 (list2 - list1) 删除 - List delDataList = esIdList.stream().filter(num -> !standIdList.contains(num)) + if (allStand != null && !allStand.isEmpty()) { + finalStandIdList = allStand.stream().map(SarStandardsInfo::getId).collect(Collectors.toList()); + }else{ + finalStandIdList = rowsStand.stream().map(SarStandardsInfo::getId).collect(Collectors.toList()); + } + List finalStandIdList1 = finalStandIdList; + List delDataList = esIdList.stream().filter(num -> !finalStandIdList1.contains(num)) .collect(Collectors.toList()); // 可以更新IDLIST 删除 ES if(searchCenter.getIdList() != null && !searchCenter.getIdList().isEmpty() && "DEL".equals(searchCenter.getExecType().toUpperCase())){ @@ -622,7 +641,7 @@ public class ResetSearchCenterService { for(SarStandardsInfo sarStandardsInfoEO : updList){ countUpdateSuccess++; standFunc(sarStandardsInfoEO); - createStandMQService.sendStandMQ(sarStandardsInfoEO,"update"); +// createStandMQService.sendStandMQ(sarStandardsInfoEO,"update"); } } @@ -633,13 +652,15 @@ public class ResetSearchCenterService { if (sarStandardsInfoEO.getAttrInfoMap() != null) { sarStandardsInfoEO.setSarStandAttrEOStr(JSONObject.toJSONString(sarStandardsInfoEO.getAttrInfoMap())); } - createStandMQService.sendStandMQ(sarStandardsInfoEO,"add"); +// createStandMQService.sendStandMQ(sarStandardsInfoEO,"add"); } } - if(!delList.isEmpty() && ("DEL".equals(searchCenter.getExecType().toUpperCase()) || "ALL".equals(searchCenter.getExecType().toUpperCase()))){ - elasticsearchService.deleteBatchId(delList,"stand"); - elasticsearchService.deleteBatchId(delList,"fulltextserch"); + if(!delList.isEmpty() && !"sync".equals(page.getSyncParam()) && ("DEL".equals(searchCenter.getExecType().toUpperCase()) || "ALL".equals(searchCenter.getExecType().toUpperCase()))){ +// elasticsearchService.deleteBatchId(delList,"stand"); +// elasticsearchService.deleteBatchId(delList,"fulltextserch"); logger.info("重置国内外标准:删除-共"+delList.size()+"条数据"); + }else{ + logger.info("重置国内外标准:没有删除数据,但应该删除"+delList.size()+"条数据"); } logger.info("重置国内外标准:新增-"+ countAddSuccess + "条 更新-"+countUpdateSuccess+"条(国内外标准共:"+0+"条)删除-共"+delList.size()+"条数据"); return Result.success("重置国内外标准:新增-"+ countAddSuccess + "条 更新-"+countUpdateSuccess+"条(国内外标准共:"+0+"条)删除-共"+delList.size()+"条数据"); @@ -1091,6 +1112,16 @@ public class ResetSearchCenterService { if(count2 > 0){ sarLawsInfoEOPage.setPageSize(count2); List rowsStand = iSarLawsStandInfoService.getSarStandardsInfoPage(sarLawsInfoEOPage); + //如果时自动触发,删除需要根据全部的结果进行数据处理 + SarLawsStandInfoPage infoEOPage = new SarLawsStandInfoPage(); + List allStand = null; + if (StringUtils.isNotBlank(sarLawsInfoEOPage.getSyncParam())) { + BeanUtils.copyProperties(sarLawsInfoEOPage, infoEOPage); + infoEOPage.setSyncParam(null); + allStand = iSarLawsStandInfoService.getSarStandardsInfoPage(infoEOPage); + } + String isAll = null == allStand ? "否" : "是"; + logger.info("是否查询了全部数据信息:" + isAll); List insList = new ArrayList<>(); List updList = new ArrayList<>(); List delList = new ArrayList<>(); @@ -1124,7 +1155,15 @@ public class ResetSearchCenterService { } // 差集 (list2 - list1) 删除 - List delDataList = esIdList.stream().filter(num -> !standIdList.contains(num)) + List finalStandIdList = null; + // 差集 (list2 - list1) 删除 + if (allStand != null && !allStand.isEmpty()) { + finalStandIdList = allStand.stream().map(SarLawsStandInfo::getId).collect(Collectors.toList()); + }else{ + finalStandIdList = rowsStand.stream().map(SarLawsStandInfo::getId).collect(Collectors.toList()); + } + List finalStandIdList1 = finalStandIdList; + List delDataList = esIdList.stream().filter(num -> !finalStandIdList1.contains(num)) .collect(Collectors.toList()); // 可以更新IDLIST 删除 ES if(searchCenter.getIdList() != null && !searchCenter.getIdList().isEmpty() && "DEL".equals(searchCenter.getExecType().toUpperCase())){ @@ -1161,7 +1200,7 @@ public class ResetSearchCenterService { if (sarLawsInfoEO.getAttrInfoMap() != null) { sarLawsInfoEO.setSarStandAttrEOStr(JSONObject.toJSONString(sarLawsInfoEO.getAttrInfoMap())); } - createStandMQService.sendLawsMQ(sarLawsInfoEO,"update"); +// createStandMQService.sendLawsMQ(sarLawsInfoEO,"update"); } } @@ -1191,14 +1230,16 @@ public class ResetSearchCenterService { if (sarLawsInfoEO.getAttrInfoMap() != null) { sarLawsInfoEO.setSarStandAttrEOStr(JSONObject.toJSONString(sarLawsInfoEO.getAttrInfoMap())); } - createStandMQService.sendLawsMQ(sarLawsInfoEO,"add"); +// createStandMQService.sendLawsMQ(sarLawsInfoEO,"add"); } } - if(!delList.isEmpty() && ("DEL".equals(searchCenter.getExecType().toUpperCase()) || "ALL".equals(searchCenter.getExecType().toUpperCase()))){ - elasticsearchService.deleteBatchId(delList,"laws"); - elasticsearchService.deleteBatchId(delList,"fulltextserch"); + if(!delList.isEmpty() && !"sync".equals(sarLawsInfoEOPage.getSyncParam()) && ("DEL".equals(searchCenter.getExecType().toUpperCase()) || "ALL".equals(searchCenter.getExecType().toUpperCase()))){ +// elasticsearchService.deleteBatchId(delList,"laws"); +// elasticsearchService.deleteBatchId(delList,"fulltextserch"); logger.info("重置国内外政策:删除-共"+delList.size()+"条数据"); + }else{ + logger.info("重置国内外政策:没有删除数据,但应该删除"+delList.size()+"条数据"); } logger.info("重置国内外政策:新增-"+ countAddSuccess + "条 更新-"+countUpdateSuccess+"条(国内外政策共:"+rowsStand.size()+"条)数据"); @@ -1673,6 +1714,16 @@ public class ResetSearchCenterService { sarBussionessStandEOPage.setPageSize(count3); List rowsStand = iSarBussionessStandService.getSarBussionStandPage(sarBussionessStandEOPage); + //如果时自动触发,删除需要根据全部的结果进行数据处理 + SarBussionessStandEOPage infoEOPage = new SarBussionessStandEOPage(); + List allStand = null; + if (StringUtils.isNotBlank(sarBussionessStandEOPage.getSyncParam())) { + BeanUtils.copyProperties(sarBussionessStandEOPage, infoEOPage); + infoEOPage.setSyncParam(null); + allStand = iSarBussionessStandService.getSarBussionStandPage(infoEOPage); + } + String isAll = null == allStand ? "否" : "是"; + logger.info("是否查询了全部数据信息:" + isAll); List insList = new ArrayList<>(); List updList = new ArrayList<>(); List delList = new ArrayList<>(); @@ -1706,8 +1757,15 @@ public class ResetSearchCenterService { updList.addAll(intersection); } + List finalStandIdList = null; // 差集 (list2 - list1) 删除 - List delDataList = esIdList.stream().filter(num -> !standIdList.contains(num)) + if (allStand != null && !allStand.isEmpty()) { + finalStandIdList = allStand.stream().map(SarBussionessStand::getId).collect(Collectors.toList()); + }else{ + finalStandIdList = rowsStand.stream().map(SarBussionessStand::getId).collect(Collectors.toList()); + } + List finalStandIdList1 = finalStandIdList; + List delDataList = esIdList.stream().filter(num -> !finalStandIdList1.contains(num)) .collect(Collectors.toList()); // 可以更新IDLIST 删除 ES if(searchCenter.getIdList() != null && !searchCenter.getIdList().isEmpty() && "DEL".equals(searchCenter.getExecType().toUpperCase())){ @@ -1742,10 +1800,12 @@ public class ResetSearchCenterService { } } - if(!delList.isEmpty() && ("DEL".equals(searchCenter.getExecType().toUpperCase()) || "ALL".equals(searchCenter.getExecType().toUpperCase()))){ + if(!delList.isEmpty() && !"sync".equals(sarBussionessStandEOPage.getSyncParam()) && ("DEL".equals(searchCenter.getExecType().toUpperCase()) || "ALL".equals(searchCenter.getExecType().toUpperCase()))){ elasticsearchService.deleteBatchId(delList,"bussstand"); elasticsearchService.deleteBatchId(delList,"fulltextserch"); logger.info("重置企标:删除-共"+delList.size()+"条数据"); + }else{ + logger.info("重置企标:没有删除数据,但应该删除"+delList.size()+"条数据"); } logger.info("重置企标:新增-"+ countAddSuccess + "条 更新-"+countUpdateSuccess+"条(企标共:"+rowsStand.size()+"条)数据"); return Result.success("");