|
@@ -0,0 +1,165 @@
|
|
|
|
+package com.rongwei.trainingcommon.sys.service.impl;
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.thread.ExecutorBuilder;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.rongwei.rwcommon.base.BaseDo;
|
|
|
|
+import com.rongwei.rwcommon.utils.StringUtils;
|
|
|
|
+import com.rongwei.safecommon.utils.CXCommonUtils;
|
|
|
|
+import com.rongwei.training.domain.EmpExamDo;
|
|
|
|
+import com.rongwei.training.domain.PlanDo;
|
|
|
|
+import com.rongwei.training.domain.PlanPaperDo;
|
|
|
|
+import com.rongwei.training.domain.TrainingDemandSurveyBackupsDo;
|
|
|
|
+import com.rongwei.trainingcommon.sys.service.EmpExamService;
|
|
|
|
+import com.rongwei.trainingcommon.sys.service.PlanPaperService;
|
|
|
|
+import com.rongwei.trainingcommon.sys.service.PlanService;
|
|
|
|
+import com.rongwei.trainingcommon.sys.service.SendNotifyService;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import java.util.Arrays;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.Set;
|
|
|
|
+import java.util.concurrent.ThreadPoolExecutor;
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+import static com.rongwei.safecommon.utils.SaveConstans.NotifyType.TRAINING;
|
|
|
|
+import static com.rongwei.safecommon.utils.SaveConstans.NotifyType.TRAININGFORM;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * SendNotifyService class
|
|
|
|
+ *
|
|
|
|
+ * @author XH
|
|
|
|
+ * @date 2023/12/15
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class SendNotifyServiceImpl implements SendNotifyService {
|
|
|
|
+ private final Logger log = LoggerFactory.getLogger(this.getClass().getName());
|
|
|
|
+ public static final ThreadPoolExecutor threadPool = ExecutorBuilder.create()
|
|
|
|
+ .setCorePoolSize(8)
|
|
|
|
+ .setMaxPoolSize(16)
|
|
|
|
+ .setKeepAliveTime(0, TimeUnit.SECONDS)
|
|
|
|
+ .build();
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private PlanService planService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private PlanPaperService planPaperService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private SendMailServiceImpl sendMailService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private EmpExamService empExamService;
|
|
|
|
+ public static final String CUT_OFF_TRAIN_TITLE = "培训截止提醒";
|
|
|
|
+ public static final String CUT_OFF_TRAIN_CONTENT = "培训考试将于%tF截止,请尽快参加考试。";
|
|
|
|
+ public static final String TRAIN_NOTIFY_TITLE = "我的培训";
|
|
|
|
+ public static final String TRAIN_NOTIFY_CONTENT = "%s,培训时间:%tF-%tF";
|
|
|
|
+
|
|
|
|
+ public static final String CANCEL_TRAIN_TITLE = "培训取消提醒";
|
|
|
|
+ public static final String CANCEL_TRAIN_CONTENT = "%s已取消";
|
|
|
|
+
|
|
|
|
+ public static final String QUESTIONNAIRE_SURVEY_TITLE="培训需求调查提醒";
|
|
|
|
+ public static final String QUESTIONNAIRE_SURVEY_CONTENT="%s年%s培训需求,已发布";
|
|
|
|
+
|
|
|
|
+ // 培训计划已发布
|
|
|
|
+ private static final String TRAINING_PLAN_PUBLISH = "y";
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void endReminderEmail() {
|
|
|
|
+ // 获取培训计划
|
|
|
|
+ List<PlanDo> planDoList = planService.list(new LambdaQueryWrapper<PlanDo>().eq(BaseDo::getDeleted, "0")
|
|
|
|
+ .eq(PlanDo::getPublish, TRAINING_PLAN_PUBLISH));
|
|
|
|
+ if (planDoList.isEmpty()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ log.info("获取到培训计划:{}", planDoList);
|
|
|
|
+ // 根据培训计划获取对应的试卷信息
|
|
|
|
+ List<PlanPaperDo> planPaperList = planPaperService.list(new LambdaQueryWrapper<PlanPaperDo>()
|
|
|
|
+ .eq(BaseDo::getDeleted, "0")
|
|
|
|
+ .in(PlanPaperDo::getTrainingplanid, planDoList.stream().map(PlanDo::getId).collect(Collectors.toSet())));
|
|
|
|
+ log.info("获取到的试卷信息:{}", planPaperList);
|
|
|
|
+ // 筛选出距离截止日期还有3天的试卷信息
|
|
|
|
+ List<PlanPaperDo> closePlanPaper = planPaperList
|
|
|
|
+ .parallelStream()
|
|
|
|
+ .filter(planPaper -> planPaper.getDeadline() != null && sendMailService.aFewDaysApart(planPaper.getDeadline()) == 3)
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ if (closePlanPaper.isEmpty()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // 即将截止的试卷Id
|
|
|
|
+ Set<String> paperId = closePlanPaper.stream().map(PlanPaperDo::getPaperid).collect(Collectors.toSet());
|
|
|
|
+ // 试卷所属的培训计划
|
|
|
|
+ Set<String> planId = closePlanPaper.stream().map(PlanPaperDo::getTrainingplanid).collect(Collectors.toSet());
|
|
|
|
+ /*****获取没有参与考试的培训员工******/
|
|
|
|
+ List<EmpExamDo> toTestInfoList = empExamService.list(new LambdaQueryWrapper<EmpExamDo>()
|
|
|
|
+ .eq(BaseDo::getDeleted, "0").eq(EmpExamDo::getExamstatus, "待考试").in(EmpExamDo::getPlanid, planId)
|
|
|
|
+ .in(EmpExamDo::getPaperid, paperId));
|
|
|
|
+ if (toTestInfoList.isEmpty()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // 按照培训计划ID 进行分组
|
|
|
|
+ Map<String, List<EmpExamDo>> infoMap = toTestInfoList.stream()
|
|
|
|
+ .collect(Collectors.groupingBy(EmpExamDo::getPlanid, Collectors.toList()));
|
|
|
|
+ // 发送考试截止提醒邮件
|
|
|
|
+ infoMap.forEach((k, v) -> {
|
|
|
|
+ PlanDo planDo = planDoList.stream().filter(info -> info.getId().equals(k)).findFirst().get();
|
|
|
|
+ log.info("准备发送考试截止提醒邮件");
|
|
|
|
+ CXCommonUtils.sendNotify(CUT_OFF_TRAIN_TITLE, String.format(CUT_OFF_TRAIN_CONTENT, planDo.getTrainingendtimt()), "",
|
|
|
|
+ v.stream().map(EmpExamDo::getEmpid).distinct().filter(StringUtils::isNotBlank).collect(Collectors.toList())
|
|
|
|
+ , planDo.getId(), TRAINING);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void trainingPlan() {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void questionnaireSurvey() {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 问卷调查提现
|
|
|
|
+ *
|
|
|
|
+ * @param planAndUserIdMap
|
|
|
|
+ */
|
|
|
|
+ public void sendQuestionnaireSurveyNotify(List<TrainingDemandSurveyBackupsDo> saveDemandSurveyBackupsDos) {
|
|
|
|
+ // 获取用户id
|
|
|
|
+ saveDemandSurveyBackupsDos.forEach((info) -> {
|
|
|
|
+ List<String> userIds = Arrays.asList(info.getNoparticipatinguserid().split(","));
|
|
|
|
+ CXCommonUtils.sendNotify(QUESTIONNAIRE_SURVEY_TITLE, String.format(QUESTIONNAIRE_SURVEY_CONTENT, info.getYear(),
|
|
|
|
+ info.getName()), "", userIds, info.getId(), TRAININGFORM);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 培训计划提醒
|
|
|
|
+ *
|
|
|
|
+ * @param planAndUserIdMap
|
|
|
|
+ */
|
|
|
|
+ public void sendTrainingPlanNotify(Map<PlanDo, Set<String>> planAndUserIdMap) {
|
|
|
|
+ // 获取用户id
|
|
|
|
+ planAndUserIdMap.forEach((k, v) -> {
|
|
|
|
+ CXCommonUtils.sendNotify(TRAIN_NOTIFY_TITLE, String.format(TRAIN_NOTIFY_CONTENT, k.getCoursename(),
|
|
|
|
+ k.getTrainingstarttime(), k.getTrainingendtimt()), "", (List<String>) v, k.getId(), TRAINING);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 培训计划取消提醒
|
|
|
|
+ *
|
|
|
|
+ * @param planAndUserIdMap
|
|
|
|
+ */
|
|
|
|
+ public void sendTrainingPlanCancelNotify(Map<PlanDo, Set<String>> planAndUserIdMap) {
|
|
|
|
+ planAndUserIdMap.forEach((k, v) -> {
|
|
|
|
+ CXCommonUtils.sendNotify(CANCEL_TRAIN_TITLE, String.format(CANCEL_TRAIN_CONTENT, k.getCoursename()), "", (List<String>) v, null, TRAINING);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|