diff --git a/laws-modules/src/main/java/com/jero/modules/laws/common/service/impl/LawsCommonServiceImpl.java b/laws-modules/src/main/java/com/jero/modules/laws/common/service/impl/LawsCommonServiceImpl.java index 4be21b42..40709ce7 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/common/service/impl/LawsCommonServiceImpl.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/common/service/impl/LawsCommonServiceImpl.java @@ -825,7 +825,7 @@ public class LawsCommonServiceImpl implements ILawsCommonService { // 同步es数据库 lawsHomeSearchService.updateEsData(module, id, LawsHomeSearchCommon.LAWS_ES_ADD); - return ResultCommon.OK; + return id; } private void processPartName(Map parameterMap, String standardId) { diff --git a/laws-modules/src/main/java/com/jero/modules/laws/standard/controller/LawsEnterpriseController.java b/laws-modules/src/main/java/com/jero/modules/laws/standard/controller/LawsEnterpriseController.java index 4d2014e6..5fef4951 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/standard/controller/LawsEnterpriseController.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/standard/controller/LawsEnterpriseController.java @@ -14,6 +14,7 @@ import com.jero.modules.laws.common.service.ILawsCommonService; import com.jero.modules.laws.enterprise.entity.EnterpriseStandardRmrEvaluateDetail; import com.jero.modules.laws.enterprise.service.EnterpriseStandardReviewMeetingRecordService; import com.jero.modules.laws.standard.service.ILawsNodeRelationService; +import com.jero.modules.laws.standard.service.ILawsReplacedStandardService; import com.jero.modules.personal.service.ILawsStandardCollectionService; import com.jero.modules.split.service.ISarFileSplitInfoService; import com.jero.modules.tag.entity.LawsTag; @@ -30,6 +31,7 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import java.util.List; import java.util.Map; +import java.util.concurrent.CompletableFuture; /** * @Author: liao @@ -58,6 +60,9 @@ public class LawsEnterpriseController { @Resource private ISarFileCompareInfoService compareInfoService; + @Resource + private ILawsReplacedStandardService replacedStandardService; + private static final String MODULE_VALUE = TableNameEnum.ENTERPRISE_STANDARDS.getValue(); @AutoLog(value = "企业法规标准-分页列表查询") @@ -96,7 +101,9 @@ public class LawsEnterpriseController { @RequiresPermissions("enterpriseStandard:add") public Result commonAdd(@RequestBody @ApiParam("标签管理") Map parameterMap) { parameterMap.put(FieldCommon.MODULE, MODULE_VALUE); - return Result.OK(lawsCommonService.commonAdd(parameterMap)); + String id = lawsCommonService.commonAdd(parameterMap); + CompletableFuture.runAsync(() -> replacedStandardService.newVersionESSendMsg(id)); + return Result.OK(); } @AutoLog(value = "企业法规标准-编辑数据") diff --git a/laws-modules/src/main/java/com/jero/modules/laws/standard/service/ILawsReplacedStandardService.java b/laws-modules/src/main/java/com/jero/modules/laws/standard/service/ILawsReplacedStandardService.java index 7dce8909..2ca4c314 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/standard/service/ILawsReplacedStandardService.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/standard/service/ILawsReplacedStandardService.java @@ -58,4 +58,9 @@ public interface ILawsReplacedStandardService extends IService implements ILawsReplacedStandardService { - @Autowired - private ILawsCommonService lawsCommonService; - @Resource private LawsReplacedStandardMapper replacedStandardMapper; + @Resource + private ILawsEnterpriseStandardService esService; + + @Resource + private SendMessageAPI sendMessageAPI; + /** * @Author: liao * @Date: 2023/9/19 11:06 @@ -131,4 +139,63 @@ public class LawsReplacedStandardServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(LawsEnterpriseStandard::getStandardNumberTemp, es.getStandardNumberTemp()); + queryWrapper.eq(LawsEnterpriseStandard::getStandardCode, es.getStandardCode()); + queryWrapper.eq(LawsEnterpriseStandard::getNameCode, es.getNameCode()); + queryWrapper.eq(LawsEnterpriseStandard::getCategoryCode, es.getCategoryCode()); + queryWrapper.ne(LawsEnterpriseStandard::getYearNumber, es.getYearNumber()); + List oldVersionStandard = esService.list(queryWrapper); + if (CollUtil.isEmpty(oldVersionStandard)) { + log.info("企业标准没有老版本,id:" + standardId); + return; + } + // 找到年代号最大的那个 + LawsEnterpriseStandard maxYearNumberStandard = oldVersionStandard.stream() + .max(Comparator.comparing(LawsEnterpriseStandard::getYearNumber)).get(); + // 找到所有引用这些标准的标准 + LambdaQueryWrapper replacedStandardWrapper = new LambdaQueryWrapper<>(); + replacedStandardWrapper.eq(LawsReplacedStandard::getType, "2"); + replacedStandardWrapper.like(LawsReplacedStandard::getReplaced, maxYearNumberStandard.getStandardNumber()); + List replacedStandardList = list(replacedStandardWrapper); + if (CollUtil.isEmpty(replacedStandardList)) { + log.info("企业标准没有被引用,id:" + standardId); + return; + } + LambdaQueryWrapper esWrapper = new LambdaQueryWrapper<>(); + esWrapper.in(LawsEnterpriseStandard::getStandardNumber, replacedStandardList.stream() + .map(LawsReplacedStandard::getReplacedBy).collect(Collectors.toSet())); + List replacedStandard = esService.list(esWrapper); + + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); + // 发消息 + for (LawsEnterpriseStandard standard : replacedStandard) { + SendMessageDTO sendMessageDTO = new SendMessageDTO(); + sendMessageDTO.setTemplateCode(MessageTemplateCodeCommon.IMPLEMENTATION_DATE_NEW_STANDARD); + Map sendMap = new HashMap<>(); + sendMap.put("standardNumber", standard.getStandardNumber()); + sendMap.put("standardName", standard.getStandardName()); + sendMap.put("implementationDate", simpleDateFormat.format(standard.getImplementationDate())); + + Set userIdList = new HashSet<>(); + // 拼接发送人员 + userIdList.add(standard.getMainDraftingUser()); + // 去除最后一个分号 + if (CollUtil.isEmpty(userIdList)) { + continue; + } + sendMessageDTO.setToUserId(String.join(",", userIdList)); + sendMessageDTO.setMap(sendMap); + sendMessageAPI.sendMessage(sendMessageDTO); + } + } }