Selaa lähdekoodia

剔除xxl-job的定时任务的调度,改为本地

zhangqiankun 2 vuotta sitten
vanhempi
commit
ab147c5762

+ 2 - 0
src/main/java/com/persagy/WorkCalendarApplication.java

@@ -5,11 +5,13 @@ import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
 import org.springframework.cloud.openfeign.EnableFeignClients;
+import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.transaction.annotation.EnableTransactionManagement;
 
 import com.persagy.common.annotation.EnableControllerLog;
 import com.persagy.common.annotation.EnableIdGenerator;
 
+@EnableScheduling
 @EnableIdGenerator
 @EnableControllerLog
 @EnableDiscoveryClient

+ 2 - 2
src/main/java/com/persagy/calendar/controller/CommonController.java

@@ -102,10 +102,10 @@ public class CommonController {
 		this.workCalendarDateHandler.paserWorkCalendarRule(calendarDateMap, ruleList, dateStart, betweenDay);
 		
 		// 4.自定义与规则的进行判断,存在的自定义的将不再进行插入
-		List<WorkCalendarDate> workCalendarDates = this.workCalendarDateHandler.handleParseCalendarRule(queryVO, customDateList, calendarDateMap);
+		List<WorkCalendarDate> workCalendarDates = this.workCalendarDateHandler.handleParseCalendarRule(customDateList, calendarDateMap);
 		
 		// 5.删除更新
-    	boolean result = this.workCalendarDateHandler.createCalendarDateByDelete(workCalendarDates, queryVO.getWorkDateStart(), queryVO.getWorkDateEnd());
+    	boolean result = this.workCalendarDateHandler.createCalendarDateByDelete(workCalendarDates, queryVO);
 		return result ? ResponseUtil.successResult("执行成功") : ResponseUtil.errorResult("执行失败");
     }
     

+ 22 - 36
src/main/java/com/persagy/calendar/handle/WorkCalendarDateHandler.java

@@ -1,31 +1,16 @@
 package com.persagy.calendar.handle;
 
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-import org.springframework.beans.BeanUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-import org.springframework.transaction.annotation.Transactional;
-
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.date.DateField;
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUnit;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.google.common.collect.Lists;
 import com.persagy.calendar.constant.WorkCalendarConstant;
 import com.persagy.calendar.pojo.dto.WorkCalendar;
 import com.persagy.calendar.pojo.dto.WorkCalendarDate;
 import com.persagy.calendar.pojo.dto.WorkCalendarRule;
-import com.persagy.calendar.pojo.vo.CalendarDateResult;
-import com.persagy.calendar.pojo.vo.CustomCalendarVO;
-import com.persagy.calendar.pojo.vo.WorkCalendarDateCreateVO;
-import com.persagy.calendar.pojo.vo.WorkCalendarDateQueryVO;
-import com.persagy.calendar.pojo.vo.WorkCalendarDateUpdateVO;
-import com.persagy.calendar.pojo.vo.WorkCalendarMoreDateCreateVO;
+import com.persagy.calendar.pojo.vo.*;
 import com.persagy.calendar.service.IWorkCalendarDateService;
 import com.persagy.calendar.service.IWorkCalendarDictService;
 import com.persagy.calendar.service.IWorkCalendarRuleService;
@@ -35,12 +20,14 @@ import com.persagy.common.exception.BusinessException;
 import com.persagy.common.utils.DateUtil;
 import com.persagy.common.utils.IdGenerator;
 import com.persagy.common.utils.StringUtil;
-
-import cn.hutool.core.collection.CollectionUtil;
-import cn.hutool.core.date.DateField;
-import cn.hutool.core.date.DateTime;
-import cn.hutool.core.date.DateUnit;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * @version 
@@ -69,16 +56,15 @@ public class WorkCalendarDateHandler {
 	 * 创建工作历作息时间信息,先删除在创建
 	 * 
 	 * @param workCalendarDates
-	 * @param workDateStart 不能为空
-	 * @param workDateEnd 不能为空
 	 * @return
 	 */
 	@Transactional
-	public boolean createCalendarDateByDelete(List<WorkCalendarDate> workCalendarDates, String workDateStart, String workDateEnd) {
+	public boolean createCalendarDateByDelete(List<WorkCalendarDate> workCalendarDates, WorkCalendarDateQueryVO queryVO) {
 		// 1.防止重复执行,优先删除从今日开始的非自定义的作息时间信息
 		QueryWrapper<WorkCalendarDate> queryWrapper = new WorkCalendarDate.Builder().createQueryWrapper()
-				.customFlagEq(WorkCalendarConstant.CUSTOM_CALENDAR_DATE_NO)
-				.workDateGe(workDateStart).workDateLe(workDateEnd).builderQueryWrapper();
+				.groupCodeEq(queryVO.getGroupCode()).projectIdEq(queryVO.getProjectId(), null)
+				.workDateGe(queryVO.getWorkDateStart()).workDateLe(queryVO.getWorkDateEnd())
+				.customFlagEq(WorkCalendarConstant.CUSTOM_CALENDAR_DATE_NO).builderQueryWrapper();
 		this.workCalendarDateService.remove(queryWrapper);
 		
 		// 2.信息插入
@@ -223,14 +209,12 @@ public class WorkCalendarDateHandler {
     
     /**
 	 * 自定义与规则的进行判断,存在的自定义的将不再进行插入
-	 * 
-	 * @param queryVO
+	 *
 	 * @param customDateList
 	 * @param calendarDateMap
 	 * @return
 	 */
-	public List<WorkCalendarDate> handleParseCalendarRule(WorkCalendarDateQueryVO queryVO, List<WorkCalendarDate> customDateList,
-			Map<String, List<WorkCalendarDate>> calendarDateMap) {
+	public List<WorkCalendarDate> handleParseCalendarRule(List<WorkCalendarDate> customDateList, Map<String, List<WorkCalendarDate>> calendarDateMap) {
 		List<WorkCalendarDate> resultList = new ArrayList<WorkCalendarDate>();
 		
 		Set<String> keySet = calendarDateMap.keySet();
@@ -417,12 +401,13 @@ public class WorkCalendarDateHandler {
 	 * 获取满足条件的所有新版规则信息
 	 * TODO 这里工作历和项目ID不传参,则无影响,若传参了,目前仅支持工作历级别的规则解析
 	 * 
-	 * @param workCalendarDateQueryVO
+	 * @param queryVO
 	 * @param dictTypeLevel 0-集团级别,1-项目级别,2-工作历级别,null-默认工作历级别
 	 * @return
 	 */
 	public List<WorkCalendarRule> selectWorkCalendarRuleList(WorkCalendarDateQueryVO queryVO, Integer dictTypeLevel) {
-		QueryWrapper<WorkCalendarRule> queryWrapper = new WorkCalendarRule.Builder().createQueryWrapper().projectIdEq(queryVO.getProjectId(), dictTypeLevel)
+		QueryWrapper<WorkCalendarRule> queryWrapper = new WorkCalendarRule.Builder().createQueryWrapper()
+				.groupCodeEq(queryVO.getGroupCode()).projectIdEq(queryVO.getProjectId(), dictTypeLevel)
 				.calendarIdEq(queryVO.getCalendarId(), dictTypeLevel).ruleDateBetween(queryVO.getWorkDateStart(), queryVO.getWorkDateEnd())
 				.dictTypeEq(queryVO.getDictType()).dictCodeIn(queryVO.getDictCode()).dictTypeIn(queryVO.getDictTypes())
 				.idEq(queryVO.getRuleId()).delFlagEq(WorkCalendarConstant.WORK_CALENDAR_DEL_FLAG_NOR)
@@ -437,6 +422,7 @@ public class WorkCalendarDateHandler {
      */
 	public List<WorkCalendarDate> selectWorkCalendarDateList(WorkCalendarDateQueryVO workCalendarDateQueryVO, String customFlag, Integer dictTypeLevel) {
 		QueryWrapper<WorkCalendarDate> queryWrapper = new WorkCalendarDate.Builder().createQueryWrapper()
+				.groupCodeEq(workCalendarDateQueryVO.getGroupCode())
 				.projectIdEq(workCalendarDateQueryVO.getProjectId(), dictTypeLevel).idEq(workCalendarDateQueryVO.getId())
 				.ruleIdEq(workCalendarDateQueryVO.getRuleId()).calendarIdEq(workCalendarDateQueryVO.getCalendarId(), dictTypeLevel)
 				.workDateGe(workCalendarDateQueryVO.getWorkDateStart()).workDateLe(workCalendarDateQueryVO.getWorkDateEnd())

+ 4 - 1
src/main/java/com/persagy/calendar/pojo/vo/WorkCalendarDateQueryVO.java

@@ -28,7 +28,10 @@ public class WorkCalendarDateQueryVO {
 	
 	//@ApiModelProperty(name = "ID", value = "主键ID,更新时不可为空")
 	private String id;
-	
+
+	//@ApiModelProperty(value = "集团编码", required = true)
+	private String groupCode;  // 集团编码
+
 	//@ApiModelProperty(value = "项目ID", required = true)
 	private String projectId;  // 项目
 	

+ 58 - 0
src/main/java/com/persagy/calendar/schedule/WorkDateCalendarSchedule.java

@@ -0,0 +1,58 @@
+package com.persagy.calendar.schedule;
+
+import cn.hutool.core.collection.CollectionUtil;
+import com.persagy.calendar.constant.WorkCalendarConstant;
+import com.persagy.calendar.controller.CommonController;
+import com.persagy.calendar.pojo.dto.WorkCalendar;
+import com.persagy.calendar.pojo.vo.WorkCalendarDateQueryVO;
+import com.persagy.calendar.service.IWorkCalendarService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * 每日定时解析工作历作息规则
+ *
+ * @author zhangqiankun
+ * @version 1.0.0
+ * @company persagy
+ * @date 2023/1/14 14:36
+ */
+@Slf4j
+@Component
+public class WorkDateCalendarSchedule {
+
+    @Autowired
+    private CommonController commonController;
+
+    @Autowired
+    private IWorkCalendarService workCalendarService;
+
+    //@Scheduled(cron = "0 30 0 * * ?")
+    @Scheduled(cron = "0/30 * * * * ?")
+    public void updateAlarmIsolationInfo() throws Exception {
+        // 获取所有的集团和项目信息
+        List<WorkCalendar> workCalendars = this.workCalendarService.lambdaQuery().eq(WorkCalendar::getDelFlag, WorkCalendarConstant.WORK_CALENDAR_DEL_FLAG_NOR)
+                .groupBy(Arrays.asList(WorkCalendar::getGroupCode, WorkCalendar::getProjectId)).select(WorkCalendar::getGroupCode, WorkCalendar::getProjectId)
+                .list();
+        if (CollectionUtil.isNotEmpty(workCalendars)) {
+            String now = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
+            for (WorkCalendar workCalendar : workCalendars) {
+                WorkCalendarDateQueryVO queryVO = new WorkCalendarDateQueryVO();
+                queryVO.setUserId("systemId");
+                queryVO.setGroupCode(workCalendar.getGroupCode());
+                queryVO.setProjectId(workCalendar.getProjectId());
+                queryVO.setWorkDateStart(now);
+                queryVO.setWorkDateEnd(now);
+                this.commonController.handleParseCalendarRule(queryVO);
+            }
+        }
+    }
+
+}