临时用户生效日期
This commit is contained in:
parent
a5c5cfb4f9
commit
3c89e98c84
|
|
@ -332,7 +332,7 @@ public class SysUserController extends BaseController {
|
|||
}
|
||||
user.setCreateBy(SecurityUtils.getUsername());
|
||||
user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
|
||||
setUserStatus(user);
|
||||
userService.setUserStatus(user);
|
||||
return toAjax(userService.insertUser(user));
|
||||
} catch (Exception e) {
|
||||
logger.error(e.toString(), e);
|
||||
|
|
@ -340,16 +340,6 @@ public class SysUserController extends BaseController {
|
|||
return error("系统异常,请联系管理员");
|
||||
}
|
||||
|
||||
private static void setUserStatus(SysUser user) {
|
||||
if (UserPermanentEnum.TEMP_USER.getCode().equals(user.getIsPermanent())) {
|
||||
Date now = new Date();
|
||||
if (Objects.nonNull(user.getEffectiveStartDay()) && user.getEffectiveStartDay().after(now)
|
||||
|| Objects.nonNull(user.getEffectiveEndDay()) && user.getEffectiveEndDay().before(now)) {
|
||||
user.setStatus(UserStatus.DISABLE.getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户
|
||||
*/
|
||||
|
|
@ -372,7 +362,7 @@ public class SysUserController extends BaseController {
|
|||
return error("内置用户不允许修改");
|
||||
}
|
||||
user.setUpdateBy(SecurityUtils.getUsername());
|
||||
setUserStatus(user);
|
||||
userService.setUserStatus(user);
|
||||
return toAjax(userService.updateUser(user));
|
||||
} catch (Exception e) {
|
||||
logger.error(e.toString(), e);
|
||||
|
|
|
|||
|
|
@ -133,6 +133,8 @@ public interface ISysUserService {
|
|||
*/
|
||||
public void checkUserDataScope(Long userId);
|
||||
|
||||
public void setUserStatus(SysUser user);
|
||||
|
||||
/**
|
||||
* 新增用户信息
|
||||
*
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package com.bonus.system.service.impl;
|
|||
import com.bonus.common.core.constant.Constants;
|
||||
import com.bonus.common.core.constant.UserConstants;
|
||||
import com.bonus.common.core.domain.R;
|
||||
import com.bonus.common.core.enums.UserPermanentEnum;
|
||||
import com.bonus.common.core.enums.UserStatus;
|
||||
import com.bonus.common.core.exception.ServiceException;
|
||||
import com.bonus.common.core.utils.SpringUtils;
|
||||
import com.bonus.common.core.utils.StringUtils;
|
||||
|
|
@ -37,6 +39,7 @@ import org.springframework.util.CollectionUtils;
|
|||
import javax.annotation.Resource;
|
||||
import javax.validation.Validator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
|
@ -325,6 +328,18 @@ public class SysUserServiceImpl implements ISysUserService {
|
|||
}
|
||||
}
|
||||
|
||||
public void setUserStatus(SysUser user) {
|
||||
if (UserPermanentEnum.TEMP_USER.getCode().equals(user.getIsPermanent())) {
|
||||
Date now = new Date();
|
||||
if (Objects.nonNull(user.getEffectiveStartDay()) && user.getEffectiveStartDay().after(now)
|
||||
|| Objects.nonNull(user.getEffectiveEndDay()) && user.getEffectiveEndDay().before(now)) {
|
||||
user.setStatus(UserStatus.DISABLE.getCode());
|
||||
} else {
|
||||
user.setStatus(UserStatus.OK.getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增保存用户信息
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,12 +1,15 @@
|
|||
package com.bonus.system.warning;
|
||||
|
||||
import com.bonus.system.api.domain.SysUser;
|
||||
import com.bonus.system.service.ISysLogService;
|
||||
import com.bonus.system.service.ISysUserService;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class ScheduledTasks {
|
||||
|
|
@ -16,6 +19,9 @@ public class ScheduledTasks {
|
|||
@Resource(name = "ISysLogService")
|
||||
private ISysLogService service;
|
||||
|
||||
@Resource
|
||||
private ISysUserService userService;
|
||||
|
||||
// 每5分钟执行一次
|
||||
@Scheduled(fixedRate = 300000)
|
||||
public void taskWithFixedRate() {
|
||||
|
|
@ -23,6 +29,17 @@ public class ScheduledTasks {
|
|||
System.out.println("数据库容量固定速率任务执行时间:" + LocalDateTime.now().format(formatter));
|
||||
}
|
||||
|
||||
// 每6个小时执行
|
||||
@Scheduled(cron = "0 */6 * * *")
|
||||
public void taskToChangeUserStatus() {
|
||||
System.out.println("用户状态修正任务开始执行,执行时间:" + LocalDateTime.now().format(formatter));
|
||||
List<SysUser> sysUsers = userService.selectUserList(new SysUser());
|
||||
for (SysUser sysUser : sysUsers) {
|
||||
userService.setUserStatus(sysUser);
|
||||
userService.updateUser(sysUser);
|
||||
}
|
||||
}
|
||||
|
||||
// // 每天凌晨1点执行
|
||||
// @Scheduled(cron = "0 */5 * * * ?")
|
||||
// public void taskWithCron() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue