| New file |
| | |
| | | package com.ycl.jxkg.job; |
| | | |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.ycl.jxkg.domain.entity.SysConfig; |
| | | import com.ycl.jxkg.mapper.SysConfigMapper; |
| | | import com.ycl.jxkg.mapper.UserMapper; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * 密码过期处理 |
| | | * |
| | | * @author:xp |
| | | * @date:2024/7/10 9:52 |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | | @RequiredArgsConstructor |
| | | public class PasswordExpireJob { |
| | | |
| | | private final UserMapper userMapper; |
| | | private final SysConfigMapper configMapper; |
| | | |
| | | /** |
| | | * 每天凌晨执行 |
| | | * |
| | | */ |
| | | @Scheduled(cron = "0 0 0 * * ?") |
| | | public void passwordExpire() { |
| | | List<SysConfig> list = new LambdaQueryChainWrapper<>(configMapper) |
| | | .list(); |
| | | if (list.size() > 1) { |
| | | log.error("系统配置大于1条,无法正确执行【密码过期】任务"); |
| | | return; |
| | | } |
| | | if (list.size() == 0) { |
| | | log.error("不存在系统配置,无法正确执行【密码过期】任务"); |
| | | return; |
| | | } |
| | | SysConfig config = list.get(0); |
| | | if (Objects.isNull(config.getPasswordExpireTime())) { |
| | | // 如果未配置密码过期时间,则默认30天密码过期 |
| | | config.setPasswordExpireTime(30); |
| | | } |
| | | userMapper.updatePasswordExpire(config.getPasswordExpireTime(), new Date()); |
| | | } |
| | | } |