diff --git a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/job/DisableAIExpiredAccount.java b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/job/DisableAIExpiredAccount.java index 1a986f7..2efde53 100644 --- a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/job/DisableAIExpiredAccount.java +++ b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/job/DisableAIExpiredAccount.java @@ -76,6 +76,7 @@ public class DisableAIExpiredAccount implements JobHandler{ long minutes = brotherDuration.toMinutes(); LambdaQueryWrapper aiUserQueryWrapper = new LambdaQueryWrapper<>(); aiUserQueryWrapper.eq(AdminUserDO::getTenantId, tenantId); + aiUserQueryWrapper.eq(AdminUserDO::getAiChat, 1); List aiUserList = userMapper.selectList(aiUserQueryWrapper); int aiAccountNum = 0 ; if (minutes >= 0) { diff --git a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/job/DisableBrotherExpiredAccount.java b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/job/DisableBrotherExpiredAccount.java index 21e9842..e85de99 100644 --- a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/job/DisableBrotherExpiredAccount.java +++ b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/job/DisableBrotherExpiredAccount.java @@ -32,7 +32,7 @@ import java.util.List; */ @Slf4j @Component -public class DisableBrotherExpiredAccount implements JobHandler{ +public class DisableBrotherExpiredAccount implements JobHandler { /** * 租户数据访问对象 @@ -64,28 +64,56 @@ public class DisableBrotherExpiredAccount implements JobHandler{ */ @Override @TenantJob + /** + * 执行禁用过期大哥账号的定时任务 + * @param param 任务参数(未使用) + * @return 执行结果信息 + * @throws Exception 执行过程中可能抛出的异常 + */ public String execute(String param) throws Exception { + // 获取当前租户ID Long tenantId = TenantContextHolder.getTenantId(); + // 查询当前租户信息 TenantDO tenant = tenantMapper.selectById(tenantId); - if (tenant.getBrotherExpireTime()==null) { + + // 检查租户是否配置了大哥账号过期时间,如未配置则直接返回提示 + if (tenant.getBrotherExpireTime() == null) { return "租户未配置大哥过期时间"; } + + // 计算从租户设置的过期时间到当前时间的时间差 Duration brotherDuration = LocalDateTimeUtil.between(tenant.getBrotherExpireTime(), LocalDateTime.now()); + // 转换为分钟数 long minutes = brotherDuration.toMinutes(); - LambdaQueryWrapper aiUserQueryWrapper = new LambdaQueryWrapper<>(); - aiUserQueryWrapper.eq(AdminUserDO::getTenantId, tenantId); - List aiUserList = userMapper.selectList(aiUserQueryWrapper); - int brotherAccountNum = 0 ; + + // 创建查询条件,查找当前租户下的所有大哥账号 + LambdaQueryWrapper brotherUserQueryWrapper = new LambdaQueryWrapper<>(); + brotherUserQueryWrapper.eq(AdminUserDO::getTenantId, tenantId); + brotherUserQueryWrapper.eq(AdminUserDO::getBigBrother, 1); + + // 查询符合条件的大哥账号列表 + List aiUserList = userMapper.selectList(brotherUserQueryWrapper); + + // 统计被禁用的大哥账号数量 + int brotherAccountNum = 0; + + // 如果已过过期时间(minutes >= 0表示当前时间已超过过期时间) if (minutes >= 0) { + // 遍历所有大哥账号进行禁用操作 for (AdminUserDO adminUserDO : aiUserList) { + // 将BigBrother标志设置为0,表示禁用大哥权限 adminUserDO.setBigBrother((byte) 0); + // 更新用户信息到数据库 userMapper.updateById(adminUserDO); + // 更新统计计数 brotherAccountNum++; + // 记录禁用操作日志 log.info("禁用过期大哥账号,账号ID:{}", adminUserDO.getId()); } } - - // 返回操作结果:包含禁用的AI账号和大哥账号数量统计 + // 返回操作结果:包含禁用的大哥账号数量统计 return "禁用过期账号成功,禁用了 " + brotherAccountNum + " 个 大哥账号。"; } + + } \ No newline at end of file