Commit 718fbfc9999876a6f5fb620e53968b34877149ec
1 parent
019cd3d6
根据创建时间删除指定表记录(2)
Signed-off-by: TanYibin <5491541@qq.com>
Showing
1 changed file
with
22 additions
and
7 deletions
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/monitor/job/TableCleanTesk.java
... | ... | @@ -9,6 +9,7 @@ import java.util.List; |
9 | 9 | |
10 | 10 | import org.apache.ibatis.session.SqlSession; |
11 | 11 | import org.jeecg.common.util.DateUtils; |
12 | +import org.jeecg.modules.system.mapper.SysLogMapper; | |
12 | 13 | import org.jeecg.modules.wms.monitor.job.dto.TableCleanDto; |
13 | 14 | import org.jeecg.utils.LocalDateUtils; |
14 | 15 | import org.quartz.DisallowConcurrentExecution; |
... | ... | @@ -23,9 +24,15 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
23 | 24 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
24 | 25 | |
25 | 26 | import cn.hutool.core.util.StrUtil; |
27 | +import cn.monitor4all.logRecord.annotation.OperationLog; | |
26 | 28 | import dm.jdbc.util.ReflectUtil; |
27 | 29 | import lombok.extern.slf4j.Slf4j; |
28 | 30 | |
31 | +/** | |
32 | + * 根据创建时间删除指定表记录定时任务 | |
33 | + * @author TanYibin | |
34 | + * @createDate 2023年3月16日 | |
35 | + */ | |
29 | 36 | @Slf4j |
30 | 37 | @PersistJobDataAfterExecution |
31 | 38 | @DisallowConcurrentExecution |
... | ... | @@ -54,7 +61,7 @@ public class TableCleanTesk implements Job { |
54 | 61 | if (createTimeField != null) { |
55 | 62 | QueryWrapper<?> queryWrapper = new QueryWrapper<>(); |
56 | 63 | LocalDateTime createTime = LocalDateUtils.minus(LocalDateTime.now(), tableCleanDto.getRetentionDays(), ChronoUnit.DAYS); |
57 | - queryWrapper.select("id").lt("create_time", createTime); | |
64 | + queryWrapper.lt("create_time", createTime); | |
58 | 65 | BaseMapper baseMapper = (BaseMapper)this.sqlSession.getMapper(mapperClass); |
59 | 66 | Integer deleteCount = baseMapper.delete(queryWrapper); |
60 | 67 | log.info("定时任务 TableCleanTesk 删除 {} {} 天前数据 {} 行", className, tableCleanDto.getRetentionDays(), deleteCount); |
... | ... | @@ -66,14 +73,22 @@ public class TableCleanTesk implements Job { |
66 | 73 | } |
67 | 74 | } |
68 | 75 | |
76 | + /** | |
77 | + * 参数范例 | |
78 | + * @author TanYibin | |
79 | + * @createDate 2023年3月16日 | |
80 | + * @param args | |
81 | + */ | |
69 | 82 | public static void main(String[] args) { |
70 | 83 | List<TableCleanDto> tableCleanList = new ArrayList<TableCleanDto>(); |
71 | - TableCleanDto tableCleanDto = new TableCleanDto(); | |
72 | - tableCleanDto.setMapperName("org.jeecg.modules.system.mapper.SysLogMapper"); | |
73 | - tableCleanDto.setRetentionDays(90); | |
74 | - tableCleanDto.setMapperName("org.jeecg.modules.system.mapper.SysLogMapper"); | |
75 | - tableCleanDto.setRetentionDays(90); | |
76 | - tableCleanList.add(tableCleanDto); | |
84 | + TableCleanDto tableCleanDto1 = new TableCleanDto(); | |
85 | + tableCleanDto1.setMapperName(SysLogMapper.class.getName()); | |
86 | + tableCleanDto1.setRetentionDays(90); | |
87 | + TableCleanDto tableCleanDto2 = new TableCleanDto(); | |
88 | + tableCleanDto2.setMapperName(OperationLog.class.getName()); | |
89 | + tableCleanDto2.setRetentionDays(90); | |
90 | + tableCleanList.add(tableCleanDto1); | |
91 | + tableCleanList.add(tableCleanDto2); | |
77 | 92 | System.out.println(JSON.toJSONString(tableCleanList)); |
78 | 93 | } |
79 | 94 | } |
... | ... |