WorkDateCalendarSchedule.java 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package com.persagy.calendar.schedule;
  2. import cn.hutool.core.collection.CollectionUtil;
  3. import com.persagy.calendar.constant.WorkCalendarConstant;
  4. import com.persagy.calendar.controller.CommonController;
  5. import com.persagy.calendar.pojo.dto.WorkCalendar;
  6. import com.persagy.calendar.pojo.vo.WorkCalendarDateQueryVO;
  7. import com.persagy.calendar.service.IWorkCalendarService;
  8. import lombok.extern.slf4j.Slf4j;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.scheduling.annotation.Scheduled;
  11. import org.springframework.stereotype.Component;
  12. import java.time.LocalDateTime;
  13. import java.time.format.DateTimeFormatter;
  14. import java.util.Arrays;
  15. import java.util.List;
  16. /**
  17. * 每日定时解析工作历作息规则
  18. *
  19. * @author zhangqiankun
  20. * @version 1.0.0
  21. * @company persagy
  22. * @date 2023/1/14 14:36
  23. */
  24. @Slf4j
  25. @Component
  26. public class WorkDateCalendarSchedule {
  27. @Autowired
  28. private CommonController commonController;
  29. @Autowired
  30. private IWorkCalendarService workCalendarService;
  31. //@Scheduled(cron = "0 30 0 * * ?")
  32. @Scheduled(cron = "0/30 * * * * ?")
  33. public void updateAlarmIsolationInfo() throws Exception {
  34. // 获取所有的集团和项目信息
  35. List<WorkCalendar> workCalendars = this.workCalendarService.lambdaQuery().eq(WorkCalendar::getDelFlag, WorkCalendarConstant.WORK_CALENDAR_DEL_FLAG_NOR)
  36. .groupBy(Arrays.asList(WorkCalendar::getGroupCode, WorkCalendar::getProjectId)).select(WorkCalendar::getGroupCode, WorkCalendar::getProjectId)
  37. .list();
  38. if (CollectionUtil.isNotEmpty(workCalendars)) {
  39. String now = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
  40. for (WorkCalendar workCalendar : workCalendars) {
  41. WorkCalendarDateQueryVO queryVO = new WorkCalendarDateQueryVO();
  42. queryVO.setUserId("systemId");
  43. queryVO.setGroupCode(workCalendar.getGroupCode());
  44. queryVO.setProjectId(workCalendar.getProjectId());
  45. queryVO.setWorkDateStart(now);
  46. queryVO.setWorkDateEnd(now);
  47. this.commonController.handleParseCalendarRule(queryVO);
  48. }
  49. }
  50. }
  51. }