diff --git a/laws-modules/src/main/java/com/jero/modules/laws/standard/service/impl/LawsReplacedStandardServiceImpl.java b/laws-modules/src/main/java/com/jero/modules/laws/standard/service/impl/LawsReplacedStandardServiceImpl.java index 45cc013b..58a779af 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/standard/service/impl/LawsReplacedStandardServiceImpl.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/standard/service/impl/LawsReplacedStandardServiceImpl.java @@ -148,39 +148,42 @@ 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()); - queryWrapper.ne(LawsEnterpriseStandard::getId, es.getId()); - List oldVersionStandard = esService.list(queryWrapper); + // 找到所有代替的标准 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(LawsReplacedStandard::getType, 1); + queryWrapper.eq(LawsReplacedStandard::getReplacedBy, es.getStandardNumber()); + List replacedStandardList = list(queryWrapper); + List replaceNumberList = new ArrayList<>(); + replacedStandardList.forEach(e -> { + String standardNumber = e.getReplaced().split("《")[0]; + replaceNumberList.add(standardNumber); + }); + LambdaQueryWrapper esQueryWrapper = new LambdaQueryWrapper<>(); + esQueryWrapper.in(LawsEnterpriseStandard::getStandardNumber, replaceNumberList); + List oldVersionStandard = esService.list(esQueryWrapper); 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)) { + replacedStandardWrapper.eq(LawsReplacedStandard::getType, 2); + for (LawsEnterpriseStandard standard : oldVersionStandard) { + replacedStandardWrapper.like(LawsReplacedStandard::getReplaced, standard.getStandardNumber()).or(); + } + List referenceStandardList = list(replacedStandardWrapper); + if (CollUtil.isEmpty(referenceStandardList)) { log.info("企业标准没有被引用,id:" + standardId); return; } LambdaQueryWrapper esWrapper = new LambdaQueryWrapper<>(); - esWrapper.in(LawsEnterpriseStandard::getStandardNumber, replacedStandardList.stream() + esWrapper.in(LawsEnterpriseStandard::getStandardNumber, referenceStandardList.stream() .map(LawsReplacedStandard::getReplacedBy).collect(Collectors.toSet())); - List replacedStandard = esService.list(esWrapper); + List referenceStandard = esService.list(esWrapper); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); // 发消息 - for (LawsEnterpriseStandard standard : replacedStandard) { + for (LawsEnterpriseStandard standard : referenceStandard) { SendMessageDTO sendMessageDTO = new SendMessageDTO(); sendMessageDTO.setTemplateCode(MessageTemplateCodeCommon.IMPLEMENTATION_DATE_NEW_STANDARD); Map sendMap = new HashMap<>();