diff --git a/laws-modules/src/main/java/com/jero/modules/laws/standard/job/ReplaceImplementationDateMsgJob.java b/laws-modules/src/main/java/com/jero/modules/laws/standard/job/ReplaceImplementationDateMsgJob.java new file mode 100644 index 00000000..86b45e04 --- /dev/null +++ b/laws-modules/src/main/java/com/jero/modules/laws/standard/job/ReplaceImplementationDateMsgJob.java @@ -0,0 +1,14 @@ +package com.jero.modules.laws.standard.job; + +import lombok.extern.slf4j.Slf4j; +import org.quartz.Job; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; + +@Slf4j +public class ReplaceImplementationDateMsgJob implements Job { + @Override + public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { + + } +} diff --git a/laws-modules/src/main/java/com/jero/modules/laws/standard/job/UpdateStandardStatusJob.java b/laws-modules/src/main/java/com/jero/modules/laws/standard/job/UpdateStandardStatusJob.java index 0891a9bd..b9fa0064 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/standard/job/UpdateStandardStatusJob.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/standard/job/UpdateStandardStatusJob.java @@ -20,6 +20,7 @@ import org.quartz.JobExecutionException; import javax.annotation.Resource; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -43,26 +44,68 @@ public class UpdateStandardStatusJob implements Job { @Override public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { this.updateGbStandardState(); -// this.updateEsStandardState(); + this.updateEsStandardState(); } private void updateEsStandardState() { - // 企标状态更新 - List needUpdateEsList = new ArrayList<>(); - LambdaQueryWrapper esWrapper = new LambdaQueryWrapper<>(); - esWrapper.eq(LawsEnterpriseStandard::getDelFlag, YesOrNoEnum.NO.getInteger()); - esWrapper.isNotNull(LawsEnterpriseStandard::getReleaseDate); - esWrapper.isNotNull(LawsEnterpriseStandard::getImplementationDate); - esWrapper.eq(LawsEnterpriseStandard::getStandardState, StandardStateEnum.CURRENTLY_EFFECTIVE.getStateValue()); - List esList = esService.list(esWrapper); + // 新标准到实施日期后,老标准状态变为废止 + List allExpireStandardNumberList = new ArrayList<>(); + List needAbolishStandardIdList = new ArrayList<>(); + // 获取所有已经到了外部标准 + List esList = esService.list(); + if (esList.isEmpty()) { + log.info("没有需要更新的标准"); + return; + } + Map esMap = + esList.stream().collect(Collectors.toMap(LawsEnterpriseStandard::getStandardNumber, es -> es)); + // 根据新认证车实施日期筛选出已经到期的标准 for (LawsEnterpriseStandard es : esList) { - // 实施日期及之后的标准 状态更新为现行有效 - if (es.getImplementationDate().getTime() <= System.currentTimeMillis()) { - es.setStandardState(StandardStateEnum.CURRENTLY_EFFECTIVE.getStateValue()); - needUpdateEsList.add(es); + Date implementationDate = es.getImplementationDate(); + if (implementationDate == null) { + continue; + } + // 判断当前时间是否大于实施日期 + if (implementationDate.getTime() <= System.currentTimeMillis()) { + allExpireStandardNumberList.add(es.getStandardNumber()); } } - esService.updateBatchById(needUpdateEsList); + + if (allExpireStandardNumberList.isEmpty()) { + log.info("没有需要更新的标准"); + return; + } + + // 根据所有到期的标准编号,找到他们代替的标准 + LambdaQueryWrapper replaceStandardWrapper = new LambdaQueryWrapper<>(); + replaceStandardWrapper.in(LawsReplacedStandard::getReplacedBy, allExpireStandardNumberList); + replaceStandardWrapper.eq(LawsReplacedStandard::getType, 1); + List replacedStandardList = replacedStandardService.list(replaceStandardWrapper); + + if (replacedStandardList.isEmpty()) { + log.info("没有需要更新的标准"); + return; + } + + List replacedStandardNumberList = replacedStandardList.stream() + .map(LawsReplacedStandard::getReplaced).collect(Collectors.toList()); + + for (String s : replacedStandardNumberList) { + LawsEnterpriseStandard es = esMap.get(s); + if (es != null) { + needAbolishStandardIdList.add(es.getId()); + } + } + + if (needAbolishStandardIdList.isEmpty()) { + log.info("没有需要更新的标准"); + return; + } + + LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); + updateWrapper.in(LawsEnterpriseStandard::getId, needAbolishStandardIdList); + updateWrapper.set(LawsEnterpriseStandard::getStandardState, StandardStateEnum.ABOLISH.getStateValue()); + esService.update(updateWrapper); } private void updateGbStandardState() {