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

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 * @return LoginUser
*/ */
public static LoginUserDto get() { 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(); Map<String, Object> map = CommonHolder.get();
if (CollectionUtils.isEmpty(map)) { if (CollectionUtils.isEmpty(map)) {
throw new UnauthorizedError(); return null;
} }
if (map.get(BootCommonConstant.AUTH) instanceof LoginUserDto loginUserDto) { if (map.get(BootCommonConstant.AUTH) instanceof LoginUserDto loginUserDto) {
return loginUserDto; return loginUserDto;
@@ -163,7 +176,7 @@ public class AuthUtils implements BaseParams {
if (map.get(BootCommonConstant.AUTHORIZATION) instanceof String accessToken) { if (map.get(BootCommonConstant.AUTHORIZATION) instanceof String accessToken) {
return get(accessToken); return get(accessToken);
} }
throw new UnauthorizedError(); return null;
} }
/** /**
@@ -180,11 +180,9 @@ public class SysParamServiceImpl implements SysParamService, BaseParams {
throw new BizWarning("数据不存在"); throw new BizWarning("数据不存在");
} }
entity.setId(oldEntity.getId()); entity.setId(oldEntity.getId());
try { LoginUserDto loginUser = AuthUtils.getDefNull();
LoginUserDto loginUser = AuthUtils.get(); if (Objects.nonNull(loginUser)) {
entity.setUpdateBy(loginUser.getId()); entity.setUpdateBy(loginUser.getId());
} catch (Exception e) {
log.debug("job更新");
} }
boolean updated = sysParamBaseService.updateById(entity); boolean updated = sysParamBaseService.updateById(entity);
if (!updated) { if (!updated) {
@@ -390,11 +390,11 @@ public class SysUserServiceImpl implements SysUserService, BaseParams {
private String cleanSysUser() { private String cleanSysUser() {
SysUserPasswdRule rule = sysUserPasswdRuleService.getByCode(null); SysUserPasswdRule rule = sysUserPasswdRuleService.getByCode(null);
if (Objects.isNull(rule)) { if (Objects.isNull(rule)) {
return "安全规则不存在"; return "执行完成,安全规则不存在,无法清理禁用账号";
} }
Integer lockCancelDays = rule.getLockCancelDays(); Integer lockCancelDays = rule.getLockCancelDays();
if (lockCancelDays <= CP_NUM0) { if (lockCancelDays <= CP_NUM0) {
return "清理时间为0,则不清理禁用账号"; return "执行完成,安全规则设置[清理时间:0],不清理禁用账号";
} }
Instant time = Instant.now().plus(-lockCancelDays, ChronoUnit.DAYS); 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.eq(SysUser::getStatus, CP_NUM0);
query.le(SysUser::getAccountDisabledTime, time); query.le(SysUser::getAccountDisabledTime, time);
sysUserBaseService.remove(query); sysUserBaseService.remove(query);
return "清理成功"; return "执行完成,清理禁用账号成功,安全规则设置[清理时间:" + lockCancelDays + "]";
} }
} }