mirror of
				https://github.com/continew-org/continew-admin.git
				synced 2025-10-31 10:57:13 +08:00 
			
		
		
		
	chore: 完善演示环境任务重置演示环境数据定时任务
This commit is contained in:
		| @@ -25,6 +25,8 @@ import lombok.RequiredArgsConstructor; | ||||
| import org.springframework.stereotype.Component; | ||||
| import org.springframework.transaction.annotation.Transactional; | ||||
| import top.continew.admin.common.constant.CacheConstants; | ||||
| import top.continew.admin.open.mapper.AppMapper; | ||||
| import top.continew.admin.open.model.entity.AppDO; | ||||
| import top.continew.admin.system.mapper.*; | ||||
| import top.continew.admin.system.model.entity.*; | ||||
| import top.continew.starter.cache.redisson.util.RedisUtils; | ||||
| @@ -56,14 +58,13 @@ public class DemoEnvironmentJob { | ||||
|     private final MenuMapper menuMapper; | ||||
|     private final DeptMapper deptMapper; | ||||
|  | ||||
|     private static final Long DICT_ITEM_FLAG = 4L; | ||||
|     private static final Long DICT_FLAG = 2L; | ||||
|     private static final Long STORAGE_FLAG = 2L; | ||||
|     private static final Long NOTICE_FLAG = 7L; | ||||
|     private final AppMapper appMapper; | ||||
|     private final ClientMapper clientsMapper; | ||||
|  | ||||
|     private static final Long DELETE_FLAG = 10000L; | ||||
|     private static final Long MESSAGE_FLAG = 0L; | ||||
|     private static final Long[] USER_FLAG = {1L, 547889293968801831L}; | ||||
|     private static final Long ROLE_FLAG = 547888897925840928L; | ||||
|     private static final Long MENU_FLAG = 10000L; | ||||
|     private static final Long DEPT_FLAG = 547888580614160409L; | ||||
|  | ||||
|     /** | ||||
| @@ -76,13 +77,13 @@ public class DemoEnvironmentJob { | ||||
|             SnailJobLog.REMOTE.info("定时任务 [重置演示环境数据] 开始执行。"); | ||||
|             // 检测待清理数据 | ||||
|             SnailJobLog.REMOTE.info("开始检测演示环境待清理数据项,请稍候..."); | ||||
|             Long dictItemCount = dictItemMapper.lambdaQuery().gt(DictItemDO::getId, DICT_ITEM_FLAG).count(); | ||||
|             Long dictItemCount = dictItemMapper.lambdaQuery().gt(DictItemDO::getId, DELETE_FLAG).count(); | ||||
|             this.log(dictItemCount, "字典项"); | ||||
|             Long dictCount = dictMapper.lambdaQuery().gt(DictDO::getId, DICT_FLAG).count(); | ||||
|             Long dictCount = dictMapper.lambdaQuery().gt(DictDO::getId, DELETE_FLAG).count(); | ||||
|             this.log(dictCount, "字典"); | ||||
|             Long storageCount = storageMapper.lambdaQuery().gt(StorageDO::getId, STORAGE_FLAG).count(); | ||||
|             Long storageCount = storageMapper.lambdaQuery().gt(StorageDO::getId, DELETE_FLAG).count(); | ||||
|             this.log(storageCount, "存储"); | ||||
|             Long noticeCount = noticeMapper.lambdaQuery().gt(NoticeDO::getId, NOTICE_FLAG).count(); | ||||
|             Long noticeCount = noticeMapper.lambdaQuery().gt(NoticeDO::getId, DELETE_FLAG).count(); | ||||
|             this.log(noticeCount, "公告"); | ||||
|             Long messageCount = messageMapper.lambdaQuery().count(); | ||||
|             this.log(messageCount, "通知"); | ||||
| @@ -90,22 +91,28 @@ public class DemoEnvironmentJob { | ||||
|             this.log(userCount, "用户"); | ||||
|             Long roleCount = roleMapper.lambdaQuery().gt(RoleDO::getId, ROLE_FLAG).count(); | ||||
|             this.log(roleCount, "角色"); | ||||
|             Long menuCount = menuMapper.lambdaQuery().gt(MenuDO::getId, MENU_FLAG).count(); | ||||
|             Long menuCount = menuMapper.lambdaQuery().gt(MenuDO::getId, DELETE_FLAG).count(); | ||||
|             this.log(menuCount, "菜单"); | ||||
|             Long deptCount = deptMapper.lambdaQuery().gt(DeptDO::getId, DEPT_FLAG).count(); | ||||
|             this.log(deptCount, "部门"); | ||||
|             Long appCount = appMapper.lambdaQuery().gt(AppDO::getId, DELETE_FLAG).count(); | ||||
|             this.log(appCount, "应用"); | ||||
|             Long clientCount = clientsMapper.lambdaQuery().gt(ClientDO::getId, DELETE_FLAG).count(); | ||||
|             this.log(clientCount, "客户端"); | ||||
|             // 清理数据 | ||||
|             InterceptorIgnoreHelper.handle(IgnoreStrategy.builder().blockAttack(true).build()); | ||||
|             SnailJobLog.REMOTE.info("演示环境待清理数据项检测完成,开始执行清理。"); | ||||
|             this.clean(dictItemCount, "字典项", null, () -> dictItemMapper.lambdaUpdate() | ||||
|                 .gt(DictItemDO::getId, DICT_ITEM_FLAG) | ||||
|                 .gt(DictItemDO::getId, DELETE_FLAG) | ||||
|                 .remove()); | ||||
|             this.clean(dictCount, "字典", CacheConstants.DICT_KEY_PREFIX, () -> dictMapper.lambdaUpdate() | ||||
|                 .gt(DictDO::getId, DELETE_FLAG) | ||||
|                 .remove()); | ||||
|             this.clean(dictCount, "字典", null, () -> dictMapper.lambdaUpdate().gt(DictDO::getId, DICT_FLAG).remove()); | ||||
|             this.clean(storageCount, "存储", null, () -> storageMapper.lambdaUpdate() | ||||
|                 .gt(StorageDO::getId, STORAGE_FLAG) | ||||
|                 .gt(StorageDO::getId, DELETE_FLAG) | ||||
|                 .remove()); | ||||
|             this.clean(noticeCount, "公告", null, () -> noticeMapper.lambdaUpdate() | ||||
|                 .gt(NoticeDO::getId, NOTICE_FLAG) | ||||
|                 .gt(NoticeDO::getId, DELETE_FLAG) | ||||
|                 .remove()); | ||||
|             this.clean(messageCount, "通知", null, () -> { | ||||
|                 messageUserMapper.lambdaUpdate().gt(MessageUserDO::getMessageId, MESSAGE_FLAG).remove(); | ||||
| @@ -122,9 +129,13 @@ public class DemoEnvironmentJob { | ||||
|                 return roleMapper.lambdaUpdate().gt(RoleDO::getId, ROLE_FLAG).remove(); | ||||
|             }); | ||||
|             this.clean(menuCount, "菜单", CacheConstants.MENU_KEY_PREFIX, () -> menuMapper.lambdaUpdate() | ||||
|                 .gt(MenuDO::getId, MENU_FLAG) | ||||
|                 .gt(MenuDO::getId, DELETE_FLAG) | ||||
|                 .remove()); | ||||
|             this.clean(deptCount, "部门", null, () -> deptMapper.lambdaUpdate().gt(DeptDO::getId, DEPT_FLAG).remove()); | ||||
|             this.clean(appCount, "应用", null, () -> appMapper.lambdaUpdate().gt(AppDO::getId, DEPT_FLAG).remove()); | ||||
|             this.clean(clientCount, "客户端", null, () -> clientsMapper.lambdaUpdate() | ||||
|                 .gt(ClientDO::getId, DEPT_FLAG) | ||||
|                 .remove()); | ||||
|             SnailJobLog.REMOTE.info("演示环境数据已清理完成。"); | ||||
|             SnailJobLog.REMOTE.info("定时任务 [重置演示环境数据] 执行结束。"); | ||||
|         } finally { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user