认证清单-截止当天、截止前三天、逾期发送飞书消息定时器开发。
This commit is contained in:
+328
@@ -0,0 +1,328 @@
|
||||
package com.jero.modules.project.job;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.jero.common.util.DateUtils;
|
||||
import com.jero.modules.feishu.enums.TemplateInfoEnum2;
|
||||
import com.jero.modules.feishu.service.IFeishuService;
|
||||
import com.jero.modules.project.entity.ProjectCertificationInventoryEO;
|
||||
import com.jero.modules.project.entity.ProjectLibraryBase;
|
||||
import com.jero.modules.project.enums.CertificationInventoryFlowStatusEnum;
|
||||
import com.jero.modules.project.service.IProjectCertificationInventoryEOService;
|
||||
import com.jero.modules.project.service.IProjectLibraryBaseService;
|
||||
import com.jero.modules.system.entity.SysUser;
|
||||
import com.jero.modules.system.service.ISysUserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.quartz.Job;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 认证清单定时器
|
||||
* @Author: wzj
|
||||
* @Date: 2023/3/10 18:46
|
||||
**/
|
||||
@Slf4j
|
||||
public class CertificationInventoryJob implements Job {
|
||||
|
||||
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
@Autowired
|
||||
private IProjectLibraryBaseService projectLibraryBaseService;
|
||||
@Autowired
|
||||
private IProjectCertificationInventoryEOService projectCertificationInventoryEOService;
|
||||
@Autowired
|
||||
private ISysUserService sysUserService;
|
||||
@Autowired
|
||||
private IFeishuService feishuService;
|
||||
|
||||
@Override
|
||||
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
||||
log.info("认证清单,定时任务开启 =====================================================");
|
||||
|
||||
List<String> flowStatusList = new ArrayList<>();
|
||||
flowStatusList.add(CertificationInventoryFlowStatusEnum.LIST_TO_BE_CHECKED.getValue());
|
||||
flowStatusList.add(CertificationInventoryFlowStatusEnum.TASK_TO_BE_CONFIRMED.getValue());
|
||||
flowStatusList.add(CertificationInventoryFlowStatusEnum.REFUSAL_OF_RESPONSIBLE_PERSON.getValue());
|
||||
flowStatusList.add(CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_SUBMITTED.getValue());
|
||||
flowStatusList.add(CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_REVIEWED.getValue());
|
||||
flowStatusList.add(CertificationInventoryFlowStatusEnum.REVIEW_AND_RETURN.getValue());
|
||||
QueryWrapper<ProjectCertificationInventoryEO> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().in(ProjectCertificationInventoryEO::getFlowStatus,flowStatusList);
|
||||
List<ProjectCertificationInventoryEO> projectCertificationInventoryEOList = this.projectCertificationInventoryEOService.list(queryWrapper);
|
||||
|
||||
if(CollectionUtils.isNotEmpty(projectCertificationInventoryEOList)){
|
||||
Map<String, List<ProjectCertificationInventoryEO>> dataMaps = projectCertificationInventoryEOList
|
||||
.stream().collect(Collectors.groupingBy(ProjectCertificationInventoryEO::getProjectLibraryId));
|
||||
|
||||
if(ObjectUtils.isNotEmpty(dataMaps)){
|
||||
|
||||
for (Map.Entry<String, List<ProjectCertificationInventoryEO>> dataMap : dataMaps.entrySet()) {
|
||||
String projectLibraryId = dataMap.getKey();
|
||||
List<ProjectCertificationInventoryEO> projectCertificationInventoryEOS = dataMap.getValue();
|
||||
|
||||
if(CollectionUtils.isNotEmpty(projectCertificationInventoryEOS)){
|
||||
ProjectLibraryBase projectLibraryBase = this.projectLibraryBaseService.selectById(projectLibraryId);
|
||||
|
||||
if(StringUtils.isNotEmpty(projectLibraryBase.getCertificationEngineer())){
|
||||
// 消息提醒 认证工程师 认证清单数据
|
||||
this.remindCertificationEngineer(projectCertificationInventoryEOS,projectLibraryBase);
|
||||
}
|
||||
// 消息提醒 责任人 认证清单数据
|
||||
this.remindDutyPerson(projectCertificationInventoryEOS,projectLibraryBase);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
log.info("认证清单,定时任务结束 =====================================================");
|
||||
}
|
||||
|
||||
/**
|
||||
* 提醒认证工程师
|
||||
* @param projectCertificationInventoryEOS
|
||||
*/
|
||||
private void remindCertificationEngineer( List<ProjectCertificationInventoryEO> projectCertificationInventoryEOS,ProjectLibraryBase projectLibraryBase) {
|
||||
List<ProjectCertificationInventoryEO> certificationInventoryEOList = projectCertificationInventoryEOS.stream().filter(data -> {
|
||||
boolean flag = (
|
||||
StringUtils.equals(data.getFlowStatus(), CertificationInventoryFlowStatusEnum.LIST_TO_BE_CHECKED.getValue())
|
||||
|| StringUtils.equals(data.getFlowStatus(), CertificationInventoryFlowStatusEnum.REFUSAL_OF_RESPONSIBLE_PERSON.getValue())
|
||||
|| StringUtils.equals(data.getFlowStatus(), CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_REVIEWED.getValue())
|
||||
);
|
||||
return flag;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
if(CollectionUtils.isNotEmpty(certificationInventoryEOList)){
|
||||
Map<String, Object> sendMsgDataListMap = this.disposeSendMsgDataList(certificationInventoryEOList);
|
||||
|
||||
List<String> certificationEngineerIdList = Arrays.asList(projectLibraryBase.getCertificationEngineer().split(","));
|
||||
List<SysUser> certificationEngineerList = this.sysUserService.querySysUserListByIdList(certificationEngineerIdList);
|
||||
|
||||
// 三天后结束的
|
||||
List<ProjectCertificationInventoryEO> threeDaysList = (List<ProjectCertificationInventoryEO>) sendMsgDataListMap.get("threeDaysList");
|
||||
if(CollectionUtils.isNotEmpty(threeDaysList)){
|
||||
for (String certificationEngineerId : certificationEngineerIdList) {
|
||||
this.sendLarkCardMsgByTemplate(
|
||||
projectLibraryBase,
|
||||
certificationEngineerList,
|
||||
certificationEngineerId,
|
||||
threeDaysList,
|
||||
TemplateInfoEnum2.CERTIFICATION_MESSAGE6.getValue()
|
||||
);
|
||||
}
|
||||
}
|
||||
// 当天结束的
|
||||
List<ProjectCertificationInventoryEO> currentDaysList = (List<ProjectCertificationInventoryEO>) sendMsgDataListMap.get("currentDaysList");
|
||||
if(CollectionUtils.isNotEmpty(currentDaysList)){
|
||||
for (String certificationEngineerId : certificationEngineerIdList) {
|
||||
this.sendLarkCardMsgByTemplate(
|
||||
projectLibraryBase,
|
||||
certificationEngineerList,
|
||||
certificationEngineerId,
|
||||
currentDaysList,
|
||||
TemplateInfoEnum2.CERTIFICATION_MESSAGE7.getValue()
|
||||
);
|
||||
}
|
||||
}
|
||||
// 逾期的
|
||||
List<ProjectCertificationInventoryEO> overdueList = (List<ProjectCertificationInventoryEO>) sendMsgDataListMap.get("overdueList");
|
||||
if(CollectionUtils.isNotEmpty(overdueList)){
|
||||
for (String certificationEngineerId : certificationEngineerIdList) {
|
||||
this.sendLarkCardMsgByTemplate(
|
||||
projectLibraryBase,
|
||||
certificationEngineerList,
|
||||
certificationEngineerId,
|
||||
overdueList,
|
||||
TemplateInfoEnum2.CERTIFICATION_MESSAGE8.getValue()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提醒责任人
|
||||
* @param projectCertificationInventoryEOS
|
||||
* @param projectLibraryBase
|
||||
*/
|
||||
private void remindDutyPerson(List<ProjectCertificationInventoryEO> projectCertificationInventoryEOS,ProjectLibraryBase projectLibraryBase) {
|
||||
Map<String, List<ProjectCertificationInventoryEO>> certifycationInventoryListByDutyPersonMap = projectCertificationInventoryEOS.stream().filter(data -> {
|
||||
boolean flag = (
|
||||
StringUtils.equals(data.getFlowStatus(), CertificationInventoryFlowStatusEnum.TASK_TO_BE_CONFIRMED.getValue())
|
||||
|| StringUtils.equals(data.getFlowStatus(), CertificationInventoryFlowStatusEnum.RESULTS_TO_BE_SUBMITTED.getValue())
|
||||
|| StringUtils.equals(data.getFlowStatus(), CertificationInventoryFlowStatusEnum.REVIEW_AND_RETURN.getValue())
|
||||
);
|
||||
return flag;
|
||||
}).collect(Collectors.groupingBy(ProjectCertificationInventoryEO::getDutyPerson));
|
||||
|
||||
if(ObjectUtils.isNotEmpty(certifycationInventoryListByDutyPersonMap)){
|
||||
List<String> dutyPersonIdList = projectCertificationInventoryEOS.stream().map(ProjectCertificationInventoryEO::getDutyPerson).distinct().collect(Collectors.toList());
|
||||
List<SysUser> dutyPersonList = this.sysUserService.querySysUserListByIdList(dutyPersonIdList);
|
||||
|
||||
for (Map.Entry<String, List<ProjectCertificationInventoryEO>> dataByDutyPersonMap : certifycationInventoryListByDutyPersonMap.entrySet()) {
|
||||
String dutyPersonUserId = dataByDutyPersonMap.getKey();
|
||||
List<ProjectCertificationInventoryEO> dutyPersonDataList = dataByDutyPersonMap.getValue();
|
||||
if(CollectionUtils.isEmpty(dutyPersonDataList)){
|
||||
continue;
|
||||
}
|
||||
|
||||
Map<String, Object> sendMsgDataListMap = this.disposeSendMsgDataList(dutyPersonDataList);
|
||||
// 三天后结束的
|
||||
List<ProjectCertificationInventoryEO> threeDaysList = (List<ProjectCertificationInventoryEO>) sendMsgDataListMap.get("threeDaysList");
|
||||
if(CollectionUtils.isNotEmpty(threeDaysList)){
|
||||
this.sendLarkCardMsgByTemplate(
|
||||
projectLibraryBase,
|
||||
dutyPersonList,
|
||||
dutyPersonUserId,
|
||||
threeDaysList,
|
||||
TemplateInfoEnum2.CERTIFICATION_MESSAGE6.getValue()
|
||||
);
|
||||
}
|
||||
// 当天结束的
|
||||
List<ProjectCertificationInventoryEO> currentDaysList = (List<ProjectCertificationInventoryEO>) sendMsgDataListMap.get("currentDaysList");
|
||||
if(CollectionUtils.isNotEmpty(currentDaysList)){
|
||||
this.sendLarkCardMsgByTemplate(
|
||||
projectLibraryBase,
|
||||
dutyPersonList,
|
||||
dutyPersonUserId,
|
||||
currentDaysList,
|
||||
TemplateInfoEnum2.CERTIFICATION_MESSAGE7.getValue()
|
||||
);
|
||||
}
|
||||
// 逾期的
|
||||
List<ProjectCertificationInventoryEO> overdueList = (List<ProjectCertificationInventoryEO>) sendMsgDataListMap.get("overdueList");
|
||||
if(CollectionUtils.isNotEmpty(overdueList)){
|
||||
this.sendLarkCardMsgByTemplate(
|
||||
projectLibraryBase,
|
||||
dutyPersonList,
|
||||
dutyPersonUserId,
|
||||
overdueList,
|
||||
TemplateInfoEnum2.CERTIFICATION_MESSAGE8.getValue()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理需要发送消息的数据
|
||||
* @param dutyPersonDataList
|
||||
* @return
|
||||
*/
|
||||
private Map<String,Object> disposeSendMsgDataList(List<ProjectCertificationInventoryEO> dutyPersonDataList) {
|
||||
Map<String,Object> result = new HashMap<>();
|
||||
Date currentDate = new Date();
|
||||
|
||||
//获取后三天前的时间
|
||||
Calendar calendar=new GregorianCalendar();
|
||||
calendar.setTime(new Date());
|
||||
calendar.add(Calendar.DATE,3);
|
||||
Date threeDays = calendar.getTime();
|
||||
|
||||
String threeDaysStr = sdf.format(threeDays);
|
||||
String currentDateStr = sdf.format(currentDate);
|
||||
|
||||
// 当天结束的
|
||||
List<ProjectCertificationInventoryEO> currentDaysList = dutyPersonDataList.stream().filter(data -> {
|
||||
boolean flag = false;
|
||||
//结束日期是当前日期
|
||||
if (StringUtils.equals(currentDateStr, sdf.format(data.getEndTime()))) {
|
||||
flag = true;
|
||||
}
|
||||
return flag;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
// 三天后结束的
|
||||
List<ProjectCertificationInventoryEO> threeDaysList = dutyPersonDataList.stream().filter(data -> {
|
||||
boolean flag = false;
|
||||
//结束日期是当前日期
|
||||
if (StringUtils.equals(threeDaysStr, sdf.format(data.getEndTime()))) {
|
||||
flag = true;
|
||||
}
|
||||
return flag;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
// 逾期的
|
||||
List<ProjectCertificationInventoryEO> overdueList = dutyPersonDataList.stream().filter(data -> {
|
||||
// 逾期3天、七天、14天
|
||||
Calendar day3Later = new GregorianCalendar();
|
||||
day3Later.setTime(data.getEndTime());
|
||||
day3Later.add(Calendar.DATE, 3);
|
||||
Date overdue3Days = day3Later.getTime();
|
||||
|
||||
Calendar day7Later = new GregorianCalendar();
|
||||
day7Later.setTime(data.getEndTime());
|
||||
day7Later.add(Calendar.DATE, 7);
|
||||
Date overdue7Days = day7Later.getTime();
|
||||
|
||||
Calendar day14Later = new GregorianCalendar();
|
||||
day14Later.setTime(data.getEndTime());
|
||||
day14Later.add(Calendar.DATE, 14);
|
||||
Date overdue14Days = day14Later.getTime();
|
||||
|
||||
boolean flag = (
|
||||
StringUtils.equals(sdf.format(overdue3Days), sdf.format(currentDate))
|
||||
|| StringUtils.equals(sdf.format(overdue7Days), sdf.format(currentDate))
|
||||
|| StringUtils.equals(sdf.format(overdue14Days), sdf.format(currentDate))
|
||||
);
|
||||
return flag;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
result.put("currentDaysList",currentDaysList);
|
||||
result.put("threeDaysList",threeDaysList);
|
||||
result.put("overdueList",overdueList);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据模板 发送飞书消息
|
||||
* @param projectLibraryBase
|
||||
* @param userList
|
||||
* @param userId
|
||||
* @param list
|
||||
*/
|
||||
private void sendLarkCardMsgByTemplate(ProjectLibraryBase projectLibraryBase, List<SysUser> userList,String userId,List<ProjectCertificationInventoryEO> list,String templateId) {
|
||||
String thirdId = this.sysUserService.getUserThirdIdByUserId(userList,userId);
|
||||
|
||||
if(StringUtils.isNotEmpty(thirdId)){
|
||||
String PRN_EN = projectLibraryBase.getProjectNameEn();//项目名称 英文
|
||||
String PRN_CN = projectLibraryBase.getProjectNameCn();//项目名称 中文
|
||||
|
||||
// 获取认证清单 - 飞书跳转链接
|
||||
Map<String, Object> hrefFeishuMap = this.projectCertificationInventoryEOService.getCertificationInventoryLinkHrefFeishu(projectLibraryBase.getId(), PRN_CN, PRN_EN);
|
||||
String hrefFeishu_CN = (String) hrefFeishuMap.get("hrefFeishu_CN");
|
||||
String hrefFeishu_EN = (String) hrefFeishuMap.get("hrefFeishu_EN");
|
||||
|
||||
Map<String, Object> standNameAndItemName = this.projectCertificationInventoryEOService.getStandNameAndItemName(list);
|
||||
String standName = (String) standNameAndItemName.get("standName");
|
||||
String itemName = (String) standNameAndItemName.get("itemName");
|
||||
|
||||
try {
|
||||
JSONObject larkMesJson = new JSONObject();
|
||||
larkMesJson.put("template_id", templateId);
|
||||
larkMesJson.put("userIds",thirdId);
|
||||
|
||||
Map<String,Object> templateVariableMap = new HashMap<>();
|
||||
templateVariableMap.put("projectNameCn", PRN_CN);
|
||||
templateVariableMap.put("projectNameEn", PRN_EN);
|
||||
templateVariableMap.put("standName",standName);
|
||||
templateVariableMap.put("itemName",itemName);
|
||||
templateVariableMap.put("Initiator", projectLibraryBase.getStudioEngineerName());
|
||||
templateVariableMap.put("endTime", DateUtils.formatDate(list.get(0).getEndTime()));
|
||||
templateVariableMap.put("viewBtnUrlCn",hrefFeishu_CN);
|
||||
templateVariableMap.put("viewBtnUrlEn",hrefFeishu_EN);
|
||||
|
||||
larkMesJson.put("templateVariableMap",templateVariableMap);
|
||||
this.feishuService.batchSendLarkCardMsgByTemplate2(larkMesJson);
|
||||
} catch (Exception e) {
|
||||
log.error("飞书消息推送失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user