TimeTask.java 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package org.springblade.modules.timer;
  2. import lombok.AllArgsConstructor;
  3. import org.springblade.bank.checklist.service.IChecklistService;
  4. import org.springblade.bank.checklist.vo.ChecklistVO;
  5. import org.springblade.common.utils.CommonUtil;
  6. import org.springblade.core.boot.ctrl.BladeController;
  7. import org.springblade.core.tool.utils.DateUtil;
  8. import org.springblade.modules.desk.service.INoticeService;
  9. import org.springblade.modules.system.entity.Dept;
  10. import org.springblade.modules.system.service.IDeptService;
  11. import org.springframework.context.annotation.Configuration;
  12. import org.springframework.scheduling.annotation.EnableScheduling;
  13. import org.springframework.scheduling.annotation.Scheduled;
  14. import org.springframework.web.bind.annotation.RestController;
  15. import java.util.List;
  16. import java.util.Map;
  17. @Configuration //1.主要用于标记配置类,兼备Component的效果。
  18. @EnableScheduling // 2.开启定时任务
  19. @RestController
  20. @AllArgsConstructor
  21. public class TimeTask extends BladeController {
  22. private final IDeptService deptService;
  23. private final IChecklistService checklistService;
  24. private final INoticeService noticeService;
  25. //3.添加定时任务
  26. @Scheduled(cron = "0 0 22 * * ?")
  27. // @Scheduled(cron = "0/10 * * * * ?")
  28. //或直接指定时间间隔,例如:5秒
  29. //@Scheduled(fixedRate=5000)
  30. private void configureTasks() {
  31. System.err.println("执行静态定时任务时间: " + DateUtil.format(DateUtil.now(), "yyyy-MM-dd HH:mm:ss"));
  32. //1、每天 (排除週六日,週末)
  33. if (!CommonUtil.isWeekend(DateUtil.format(DateUtil.now(), CommonUtil.pattern))){
  34. dayTask();
  35. }
  36. //2、每周
  37. if (CommonUtil.isWeekLastDay(DateUtil.format(DateUtil.now(), CommonUtil.pattern))){
  38. weekTask();
  39. }
  40. //3、每月
  41. if (CommonUtil.isMonthLastDay(DateUtil.format(DateUtil.now(), CommonUtil.pattern))){
  42. monthTask();
  43. }
  44. }
  45. private void checklistTask(String cycle){
  46. Dept yybDept = deptService.getByOrgNo("51007");
  47. //1、每天
  48. List<Long> deptChildIds = deptService.getDeptChildIds(yybDept.getId());
  49. deptChildIds.forEach(deptId -> {
  50. Dept dept = deptService.getById(deptId);
  51. ChecklistVO checklist = new ChecklistVO();
  52. checklist.setCycle(cycle);
  53. checklist.setOrgNo(dept.getOrgNo());
  54. List<Map> dayReport = checklistService.getReport(checklist);
  55. boolean flag = false;
  56. for (int i = 0; i < dayReport.size(); i++) {
  57. Map map = dayReport.get(i);
  58. int nocheck = Integer.parseInt(map.get("nocheck").toString());
  59. flag = flag || nocheck >= 1;
  60. }
  61. if (flag){
  62. //給支行管理層發送行信通知
  63. noticeService.sendChecklistNotice(checklist.getCycle(), dept);
  64. }
  65. });
  66. }
  67. private void dayTask(){
  68. checklistTask("day");
  69. }
  70. private void weekTask(){
  71. checklistTask("week");
  72. }
  73. private void monthTask(){
  74. checklistTask("month");
  75. }
  76. }