优化登录账号获取方法,优化定时器文案

This commit is contained in:
2026-06-12 08:44:57 +08:00
parent faa9549299
commit 56f0e4c509
3 changed files with 20 additions and 9 deletions
@@ -153,9 +153,22 @@ public class AuthUtils implements BaseParams {
* @return LoginUser
*/
public static LoginUserDto get() {
LoginUserDto dto = getDefNull();
if (Objects.isNull(dto)) {
throw new UnauthorizedError();
}
return dto;
}
/**
* 获取 LoginUser
*
* @return LoginUser
*/
public static LoginUserDto getDefNull() {
Map<String, Object> map = CommonHolder.get();
if (CollectionUtils.isEmpty(map)) {
throw new UnauthorizedError();
return null;
}
if (map.get(BootCommonConstant.AUTH) instanceof LoginUserDto loginUserDto) {
return loginUserDto;
@@ -163,7 +176,7 @@ public class AuthUtils implements BaseParams {
if (map.get(BootCommonConstant.AUTHORIZATION) instanceof String accessToken) {
return get(accessToken);
}
throw new UnauthorizedError();
return null;
}
/**
@@ -180,11 +180,9 @@ public class SysParamServiceImpl implements SysParamService, BaseParams {
throw new BizWarning("数据不存在");
}
entity.setId(oldEntity.getId());
try {
LoginUserDto loginUser = AuthUtils.get();
LoginUserDto loginUser = AuthUtils.getDefNull();
if (Objects.nonNull(loginUser)) {
entity.setUpdateBy(loginUser.getId());
} catch (Exception e) {
log.debug("job更新");
}
boolean updated = sysParamBaseService.updateById(entity);
if (!updated) {
@@ -390,11 +390,11 @@ public class SysUserServiceImpl implements SysUserService, BaseParams {
private String cleanSysUser() {
SysUserPasswdRule rule = sysUserPasswdRuleService.getByCode(null);
if (Objects.isNull(rule)) {
return "安全规则不存在";
return "执行完成,安全规则不存在,无法清理禁用账号";
}
Integer lockCancelDays = rule.getLockCancelDays();
if (lockCancelDays <= CP_NUM0) {
return "清理时间为0,则不清理禁用账号";
return "执行完成,安全规则设置[清理时间:0],不清理禁用账号";
}
Instant time = Instant.now().plus(-lockCancelDays, ChronoUnit.DAYS);
// 创建查询条件
@@ -402,7 +402,7 @@ public class SysUserServiceImpl implements SysUserService, BaseParams {
query.eq(SysUser::getStatus, CP_NUM0);
query.le(SysUser::getAccountDisabledTime, time);
sysUserBaseService.remove(query);
return "清理成功";
return "执行完成,清理禁用账号成功,安全规则设置[清理时间:" + lockCancelDays + "]";
}
}