UpdatePasswordJob.java
2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.skua.modules.quartz;
import com.skua.core.util.ConvertUtils;
import com.skua.modules.alarmtmp.vo.SystemNoticeVO;
import com.skua.modules.system.entity.SysUser;
import com.skua.modules.system.service.ISysUserService;
import com.skua.modules.util.SystemNoticeUtils;
import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.List;
/**
* 发送消息任务
*/
@Slf4j
@Component
public class UpdatePasswordJob implements Job {
@Autowired
private ISysUserService sysUserService;
@Autowired
private SystemNoticeUtils systemNoticeUtils;
@Override
public void execute(JobExecutionContext jobExecutionContext) {
int beforeNumber = 90;//未修改密码天数
String editTime = getBeforeDay(beforeNumber);
log.info("开始检查长期未修改密码人员,提醒修改密码");
List<SysUser> userList = sysUserService.getNoUpdatePasswordUserList(editTime);
if (userList.size() > 0) {
String userIds = "";
for (SysUser sysUser : userList) {
if(ConvertUtils.isNotEmpty(sysUser.getPhone())){
userIds = sysUser.getId() + "," + userIds;
}
}
SystemNoticeVO systemNoticeVO = new SystemNoticeVO();
systemNoticeVO.setUserIds(userIds);
systemNoticeVO.setContent("您的密码已经超过"+beforeNumber+"天未修改密码,建议更换密码!");
systemNoticeUtils.passwordNoticeMessage(systemNoticeVO);
log.info("长期未修改密码检测完成");
} else {
log.info("没有需要修改密码的人员");
}
}
//获取n天前的日期
private static String getBeforeDay(int beforeNumber) {
LocalDate currentDate = LocalDate.now();
LocalDate daysAgo = currentDate.minus(beforeNumber, ChronoUnit.DAYS);// 计算n天前的日期
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
return daysAgo.format(formatter)+" 00:00:00";
}
}