Task.java 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package com.ruoyi.system.service.impl;
  2. import com.google.gson.Gson;
  3. import com.ruoyi.common.utils.DateUtils;
  4. import com.ruoyi.system.domain.checkPoint.CheckPointManage;
  5. import com.ruoyi.system.domain.checkPoint.CheckPointRecord;
  6. import com.ruoyi.system.mapper.CheckPointManageMapper;
  7. import com.ruoyi.system.mapper.CheckPointRecordMapper;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.scheduling.annotation.Async;
  10. import org.springframework.scheduling.annotation.Scheduled;
  11. import org.springframework.stereotype.Component;
  12. import java.util.List;
  13. /**
  14. * 定时任务
  15. * @author tang
  16. */
  17. @Component
  18. public class Task {
  19. @Autowired
  20. private CheckPointManageMapper checkPointManageMapper;
  21. private CheckPointRecordMapper checkPointRecordMapper;
  22. private static final Gson GSON = new Gson();
  23. /***
  24. *每日巡更记录的定时任务
  25. * 每天23点执行
  26. */
  27. @Async
  28. @Scheduled(cron = "0 0 23 * * ? ")
  29. public void popover() throws Exception {
  30. CheckPointManage checkPointManage = new CheckPointManage();
  31. List<CheckPointManage> checkPointManages = checkPointManageMapper.selectCheckPointManageList(checkPointManage);
  32. if (checkPointManages != null && checkPointManages.size() > 0){
  33. for (CheckPointManage pointManage : checkPointManages) {
  34. CheckPointRecord checkPointRecord = GSON.fromJson(GSON.toJson(pointManage), CheckPointRecord.class);
  35. checkPointRecord.setCreateTime(DateUtils.getNowDate());
  36. checkPointRecordMapper.insertCheckPointRecord(checkPointRecord);
  37. }
  38. }
  39. }
  40. }