|
@@ -0,0 +1,74 @@
|
|
|
+package com.yx.face.service.job;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.yx.face.boot.uitls.RedisUtil;
|
|
|
+import com.yx.face.dao.FaceLogDao;
|
|
|
+import com.yx.face.dao.FaceLogFromDao;
|
|
|
+import com.yx.face.dao.ShortTermFaceLogDao;
|
|
|
+import com.yx.face.model.entity.FaceLogFrom;
|
|
|
+import com.yx.face.model.entity.ScanCodeBoxCode;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.annotation.Configuration;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
+import org.springframework.scheduling.annotation.EnableAsync;
|
|
|
+import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
+import tk.mybatis.mapper.entity.Example;
|
|
|
+import tk.mybatis.mapper.weekend.WeekendSqls;
|
|
|
+
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.LinkedList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+
|
|
|
+@Configuration //1.主要用于标记配置类,兼备Component的效果。
|
|
|
+@EnableScheduling // 2.开启定时任务
|
|
|
+@EnableAsync
|
|
|
+@Slf4j
|
|
|
+@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
|
|
+public class ClearDataJob {
|
|
|
+
|
|
|
+ private final FaceLogFromDao faceLogFromDao;
|
|
|
+ private final FaceLogDao faceLogDao;
|
|
|
+ private final ShortTermFaceLogDao shortTermFaceLogDao;
|
|
|
+ private final ThreadPoolTaskExecutor executor;
|
|
|
+ private final RedisUtil redisUtil;
|
|
|
+
|
|
|
+
|
|
|
+ @Async
|
|
|
+ @Scheduled(cron = "0 0 3 * * ? ", zone = "Asia/Shanghai")
|
|
|
+ public void zeroTask() {
|
|
|
+ executor.execute(()->{
|
|
|
+ log.info("-----------开始清除记录-----------");
|
|
|
+ //1.查询最大的id
|
|
|
+ DateTime dateTime = DateUtil.offsetMonth(DateUtil.date(), -3);
|
|
|
+ Integer maxFaceLogId = faceLogDao.selectMaxIdByFaceTime(dateTime);
|
|
|
+
|
|
|
+ while (true){
|
|
|
+ List<Integer> faceLogIdList = faceLogDao.selectFaceLogIdList(maxFaceLogId);
|
|
|
+ if(CollUtil.isEmpty(faceLogIdList)){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ String faceLogIdListString = StrUtil.join(",", faceLogIdList);
|
|
|
+ int faceLogDaoNum = faceLogDao.deleteByIds(faceLogIdListString);
|
|
|
+ int faceLogFromDaoNum = faceLogFromDao.deleteByExample(Example.builder(FaceLogFrom.class)
|
|
|
+ .where(WeekendSqls.<FaceLogFrom>custom()
|
|
|
+ .andIn(FaceLogFrom::getFaceLogId, faceLogIdList)
|
|
|
+ ).build()
|
|
|
+ );
|
|
|
+ int shortTermFaceLogDaoNum = shortTermFaceLogDao.deleteByIds(faceLogIdListString);
|
|
|
+ log.info("faceLogDaoNum:{},faceLogFromDaoNum:{},shortTermFaceLogDaoNum:{}",faceLogDaoNum,faceLogFromDaoNum,shortTermFaceLogDaoNum);
|
|
|
+ }
|
|
|
+ log.info("-----------结束清除记录-----------");
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|