From ae584451aabf6b6c211fe054f44be99836c8f856 Mon Sep 17 00:00:00 2001 From: caihaohan Date: Fri, 2 Aug 2024 17:35:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BB=A3=E6=9B=BF=E6=A0=87=E5=87=86?= =?UTF-8?q?=E5=88=B0=E5=AE=9E=E6=96=BD=E6=97=A5=E6=9C=9F=E5=8F=91=E6=B6=88?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../constant/MessageTemplateCodeCommon.java | 23 +-- .../job/ReplaceImplementationDateMsgJob.java | 186 ++++++++++++++++++ 2 files changed, 189 insertions(+), 20 deletions(-) diff --git a/laws-modules/src/main/java/com/jero/modules/laws/common/constant/MessageTemplateCodeCommon.java b/laws-modules/src/main/java/com/jero/modules/laws/common/constant/MessageTemplateCodeCommon.java index 520b850a..a1230b6b 100644 --- a/laws-modules/src/main/java/com/jero/modules/laws/common/constant/MessageTemplateCodeCommon.java +++ b/laws-modules/src/main/java/com/jero/modules/laws/common/constant/MessageTemplateCodeCommon.java @@ -10,27 +10,10 @@ public class MessageTemplateCodeCommon { private MessageTemplateCodeCommon() {} public static final String LAWS_NEWS_FEED = "laws_news_feed"; // 【动态消息】通知 - public static final String LAWS_PROBLEM_LIBRARY = "laws_problem_library"; // 【问答库】回答已置顶 - public static final String NEW_MODEL_IMPLEMENTATION = "new_model_implementation"; // 【新车型实施预警】 - public static final String ON_THE_PRODUCTION = "on_the_production"; // 【在产车实施预警】 - public static final String LAWS_STANDARD_SHARING = "laws_standard_sharing"; // 【分享】收到分享 - public static final String ES_INSPECT_PLAN = "es_inspect_plan"; // 【企标稽查计划】流程结束 - public static final String STANDARD_DECLARE = "standard_declare"; // 【标准宣贯】流程结束 public static final String DATA_CENTER = "data_center"; // 【资料中心】推送范围 - public static final String STANDARD_CHANGE_REPLACE = "standard_change_replace"; // 【法规变更】代替 - public static final String STANDARD_CHANGE_REPLACE_BY = "standard_change_replace_by"; // 【法规变更】被代替标准变更 - public static final String STANDARD_CHANGE_REFERENCE = "standard_change_reference"; // 【法规变更】引用标准变更 - public static final String STANDARD_CONSULTATION = "standard_consultation"; // 【征求意见结果提醒】 - public static final String PROJECT_ASSESS_COMPLETE = "project_assess_complete"; // 【项目合规评估完成提醒】 - public static final String PROJECT_STANDARD_COMPLETE = "project_standard_complete"; // 【法规合规评估完成提醒】 public static final String URGING = "urging"; // 催办 - public static final String ES_INIT_CHANGE_NEW_MAIN_DRAFT_LEADER_END = "es_init_change_new_main_draft_leader_end"; // 【企标立项变更】新起草部门主管级领导确认选择会签人员 - public static final String ES_INIT_CHANGE_MAIN_DRAFT_USER_COPY = "es_init_change_main_draft_user_copy"; // 【企标立项变更】抄送主起草人 - public static final String ES_REVISION_STANDARD_RELEASE = "es_revision_standard_release"; // 【企标修订】标准发布 - public static final String ES_REVISION_ADVICE = "es_revision_advice"; // 【企标修订】征求意见 - public static final String ES_ANNUAL_REPORT_CONTACT_USER = "es_annual_report_contact_user"; // 【企标年度制修订-各部门主动上报】部门联络人下发 - public static final String FB_STANDARD_PURCHASE = "fb_standard_purchase"; // 【法规采购】流程结束 - public static final String NOT_MET_WARNING = "not_met_warning"; // 【未符合项跟踪流程】超期预警 - public static final String BIND_PART_ADD = "bind_part_add"; // 【绑定零部件】新增完成提醒 + public static final String REPLACE_STANDARD_NEW = "replace_standard_new"; // 当前标准引用的标准有新版本标准 + public static final String IMPLEMENTATION_DATE_NEW_STANDARD = "implementation_date_new_standard"; // 代替标准到实施日期 + } 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 index 86b45e04..d5209a0a 100644 --- 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 @@ -1,14 +1,200 @@ package com.jero.modules.laws.standard.job; +import cn.hutool.core.collection.CollUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.jero.common.api.SendMessageAPI; +import com.jero.common.api.dto.message.SendMessageDTO; +import com.jero.modules.laws.common.constant.MessageTemplateCodeCommon; +import com.jero.modules.laws.standard.entity.LawsDomesticStandard; +import com.jero.modules.laws.standard.entity.LawsEnterpriseStandard; +import com.jero.modules.laws.standard.entity.LawsReplacedStandard; +import com.jero.modules.laws.standard.service.ILawsDomesticStandardService; +import com.jero.modules.laws.standard.service.ILawsEnterpriseStandardService; +import com.jero.modules.laws.standard.service.ILawsReplacedStandardService; +import com.jero.modules.personal.entity.LawsStandardCollection; +import com.jero.modules.personal.service.ILawsStandardCollectionService; import lombok.extern.slf4j.Slf4j; import org.quartz.Job; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; +import javax.annotation.Resource; +import java.text.SimpleDateFormat; +import java.util.*; +import java.util.stream.Collectors; + @Slf4j public class ReplaceImplementationDateMsgJob implements Job { + + @Resource + private ILawsEnterpriseStandardService esService; + + @Resource + private ILawsDomesticStandardService dsService; + + @Resource + private ILawsReplacedStandardService replacedStandardService; + + @Resource + private SendMessageAPI sendMessageAPI; + + @Resource + private ILawsStandardCollectionService collectionService; + @Override public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { + this.sendGbStandardMsg(); + this.sendEsStandardMsg(); + } + private void sendEsStandardMsg() { + List allExpireStandardNumberList = new ArrayList<>(); + // 获取所有已经到了外部标准 + List standardList = esService.list(); + if (standardList.isEmpty()) { + log.info("没有需要更新的标准"); + return; + } + Map standardMap = + standardList.stream().collect(Collectors.toMap(LawsEnterpriseStandard::getId, es -> es)); + // 根据新认证车实施日期筛选出已经到期的标准 + for (LawsEnterpriseStandard es : standardList) { + Date implementationDate = es.getImplementationDate(); + if (implementationDate == null) { + continue; + } + // 判断当前时间是否大于实施日期且实施日期没到后一天 + if (implementationDate.getTime() <= System.currentTimeMillis() && + implementationDate.before(new Date(implementationDate.getTime() + 24 * 60 * 60 * 1000))) { + allExpireStandardNumberList.add(es.getStandardNumber()); + } + } + + if (allExpireStandardNumberList.isEmpty()) { + log.info("没有需要发消息的标准"); + return; + } + + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); + for (String s : allExpireStandardNumberList) { + LawsEnterpriseStandard mainStandard = standardMap.get(s); + // 根据所有到期的标准编号,找到他们代替的标准 + LambdaQueryWrapper replaceStandardWrapper = new LambdaQueryWrapper<>(); + replaceStandardWrapper.in(LawsReplacedStandard::getReplacedBy, allExpireStandardNumberList); + replaceStandardWrapper.eq(LawsReplacedStandard::getType, 1); + List replacedStandardList = replacedStandardService.list(replaceStandardWrapper); + if (replacedStandardList.isEmpty()) { + continue; + } + + List replacedStandardNumberList = replacedStandardList.stream() + .map(LawsReplacedStandard::getReplaced).collect(Collectors.toList()); + + // 发消息 + SendMessageDTO sendMessageDTO = new SendMessageDTO(); + sendMessageDTO.setTemplateCode(MessageTemplateCodeCommon.REPLACE_STANDARD_NEW); + Map sendMap = new HashMap<>(); + sendMap.put("standardNumber", mainStandard.getStandardNumber()); + sendMap.put("standardName", mainStandard.getStandardName()); + sendMap.put("implementationDate", simpleDateFormat.format(mainStandard.getImplementationDate())); + + Set userIdList = new HashSet<>(); + // 拼接发送人员 + for (String standard : replacedStandardNumberList) { + LawsEnterpriseStandard replaceStandard = standardMap.get(standard); + // 被代替标准的主起草人,责任人,收藏标准的人员 + userIdList.add(replaceStandard.getMainDraftingUser()); + // 获取收藏标准的所有人员 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(LawsStandardCollection::getStandardId, replaceStandard.getId()); + List standardCollectionList = collectionService.list(wrapper); + for (LawsStandardCollection standardCollection : standardCollectionList) { + userIdList.add(standardCollection.getCollectorId()); + } + } + // 去除最后一个分号 + if (CollUtil.isEmpty(userIdList)) { + continue; + } + sendMessageDTO.setToUserId(String.join(",", userIdList)); + sendMessageDTO.setMap(sendMap); + sendMessageAPI.sendMessage(sendMessageDTO); + } + } + + private void sendGbStandardMsg() { + // 新标准到实施日期后,老标准状态变为废止 + List allExpireStandardNumberList = new ArrayList<>(); + // 获取所有已经到了外部标准 + List standardList = dsService.list(); + if (standardList.isEmpty()) { + log.info("没有需要更新的标准"); + return; + } + Map standardMap = + standardList.stream().collect(Collectors.toMap(LawsDomesticStandard::getId, es -> es)); + // 根据新认证车实施日期筛选出已经到期的标准 + for (LawsDomesticStandard es : standardList) { + Date implementationDate = es.getImplementationDate(); + if (implementationDate == null) { + continue; + } + // 判断当前时间是否大于实施日期且实施日期没到后一天 + if (implementationDate.getTime() <= System.currentTimeMillis() && + implementationDate.before(new Date(implementationDate.getTime() + 24 * 60 * 60 * 1000))) { + allExpireStandardNumberList.add(es.getStandardNumber()); + } + } + + if (allExpireStandardNumberList.isEmpty()) { + log.info("没有需要发消息的标准"); + return; + } + + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); + for (String s : allExpireStandardNumberList) { + LawsDomesticStandard mainStandard = standardMap.get(s); + // 根据所有到期的标准编号,找到他们代替的标准 + LambdaQueryWrapper replaceStandardWrapper = new LambdaQueryWrapper<>(); + replaceStandardWrapper.in(LawsReplacedStandard::getReplacedBy, allExpireStandardNumberList); + replaceStandardWrapper.eq(LawsReplacedStandard::getType, 1); + List replacedStandardList = replacedStandardService.list(replaceStandardWrapper); + if (replacedStandardList.isEmpty()) { + continue; + } + + List replacedStandardNumberList = replacedStandardList.stream() + .map(LawsReplacedStandard::getReplaced).collect(Collectors.toList()); + + // 发消息 + SendMessageDTO sendMessageDTO = new SendMessageDTO(); + sendMessageDTO.setTemplateCode(MessageTemplateCodeCommon.REPLACE_STANDARD_NEW); + Map sendMap = new HashMap<>(); + sendMap.put("standardNumber", mainStandard.getStandardNumber()); + sendMap.put("standardName", mainStandard.getStandardName()); + sendMap.put("implementationDate", simpleDateFormat.format(mainStandard.getImplementationDate())); + + Set userIdList = new HashSet<>(); + // 拼接发送人员 + for (String standard : replacedStandardNumberList) { + LawsDomesticStandard replaceStandard = standardMap.get(standard); + // 被代替标准的主起草人,责任人,收藏标准的人员 + userIdList.add(replaceStandard.getResponsibleUser()); + // 获取收藏标准的所有人员 + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(LawsStandardCollection::getStandardId, replaceStandard.getId()); + List standardCollectionList = collectionService.list(wrapper); + for (LawsStandardCollection standardCollection : standardCollectionList) { + userIdList.add(standardCollection.getCollectorId()); + } + } + // 去除最后一个分号 + if (CollUtil.isEmpty(userIdList)) { + continue; + } + sendMessageDTO.setToUserId(String.join(",", userIdList)); + sendMessageDTO.setMap(sendMap); + sendMessageAPI.sendMessage(sendMessageDTO); + } } }