标签:temp dateutils service nbsp object com public cep tst
1,要求证书到期的前三个月的当天发送邮件给运营管理人员
@Service
public class CertificateExpiresMessageJob extends Task {
@Resource(type = SmeConfiguration.class)
private SmeConfiguration smeConfiguration;
@Resource(type = MessageProducer.class)
private MessageProducer messageProducer;
@Resource(type = SipaSigReqMService.class)
private SipaSigReqMService sipaSigReqMService;
@Resource(type = FbpaOrgMService.class)
private FbpaOrgMService fbpaOrgMService;
@Override
protected boolean active() {
// 若未配置邮箱,则不发送
final String byPublicMailbox = smeConfiguration.getByPublicMailbox();
if (StringUtils.isBlank(byPublicMailbox)) {
return false;
}
return true;
}
@TaskClusterLock(logger = @TaskExecuteLog("证书到期提醒任务执行"))
@Override
public Integer execute() throws IOException {
Integer flogCount = null;
LocalDateTime pDaysForCertificateDuedate = LocalDate.now().atStartOfDay().plusMonths(3); ---------------------------------这里获取的是后三个月的日期
List<SipaSigReqMVo> sigReqMVoList = sipaSigReqMService.listCertificateByExpire(pDaysForCertificateDuedate); --------------------因为只发一次,这里的判定条件是当前时间往后推三个月
FbpaOrgM orgM = null;
Integer day = null;
SipaSigReqMVo sipaSigReqMVo = new SipaSigReqMVo();
if (CollectionUtils.isNotEmpty(sigReqMVoList)) {
flogCount = sigReqMVoList.size();
for (SipaSigReqMVo sigReqMVo : sigReqMVoList) {
// 获取企业信息
orgM = fbpaOrgMService.getById(sigReqMVo.getOrgRefcode());
sipaSigReqMVo.setSigDueDate(sigReqMVo.getSigDueDate());
day = DateUtils.getDayBetween(LocalDate.now(), pDaysForCertificateDuedate.toLocalDate()) - DateUtils.getDayBetween(sipaSigReqMVo.getSigDueDate().toLocalDate(), pDaysForCertificateDuedate.toLocalDate())----这里有一个封装,求的是两个日期之间的天数;
// 获取收件人邮箱
Set<SipaBurMVo> receiver = new HashSet<>();
SipaBurMVo sipaBurMVo = new SipaBurMVo();
sipaBurMVo.setEmail(smeConfiguration.getByPublicMailbox());
receiver.add(sipaBurMVo);
// 发送邮件
Map<String, Object> model = new HashMap<>(5);
model.put("orgname", orgM.getOrgname()); // 客户名称
model.put("sigDueDate", sipaSigReqMVo.getSigDueDate().toLocalDate()); // 到期日
model.put("day", day); // 天数
model.put("brandName", smeConfiguration.getBrandName()); // 品牌 -------------这里是邮件的一些模板,我们项目是封装了工具类,直接调用的
model.put("reviewDate", LocalDateTime.now().format(DateUtils.FMT_DATE)); // 日期
MessageModel messageModel = MessageModel.build().createMessageModel(null, receiver,
MessageTemplateConstants.CERTIFICATE_EXPIRES.getTemplateName(), FieldContants.FbtxNot.PUSH_TYPE_SYSTEM, model,
new MessageModel.Channel[]{MessageModel.Channel.EMAIL});
messageProducer.send(messageModel);
}
}
return flogCount;
}
}
2.配置文件,添加了定时时间,默认每天七点更新
3.发送的邮件效果
---------orgname 张三丰 -------sigduedate 2020-08-19 -------day 92
标签:temp dateutils service nbsp object com public cep tst
原文地址:https://www.cnblogs.com/fshow/p/12915950.html