learshaw 2 месяцев назад
Родитель
Сommit
f6bc4500df

+ 24 - 13
ems/ems-cloud/ems-server/src/main/java/com/ruoyi/ems/task/InspectionScheduler.java

@@ -8,6 +8,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
 import org.springframework.scheduling.support.CronExpression;
 import org.springframework.scheduling.support.CronTrigger;
@@ -18,7 +19,12 @@ import javax.annotation.PreDestroy;
 import java.time.LocalDateTime;
 import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.ScheduledThreadPoolExecutor;
@@ -40,6 +46,9 @@ public class InspectionScheduler {
 
     private static final DateTimeFormatter DATETIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
 
+    @Value("${schedulerCfg.inspection-scheduler:disable}")
+    private String schedulerEnable;
+
     @Autowired
     private InspectionPlanMapper planMapper;
 
@@ -66,22 +75,24 @@ public class InspectionScheduler {
      */
     @PostConstruct
     public void init() {
-        log.info("========== 初始化巡检调度器 ==========");
+        if ("enable".equals(schedulerEnable)) {
+            log.info("========== 初始化巡检调度器 ==========");
 
-        // 创建任务调度器
-        taskScheduler = new ThreadPoolTaskScheduler();
-        taskScheduler.setPoolSize(5);
-        taskScheduler.setThreadNamePrefix("inspection-scheduler-");
-        taskScheduler.setWaitForTasksToCompleteOnShutdown(true);
-        taskScheduler.setAwaitTerminationSeconds(60);
-        taskScheduler.initialize();
+            // 创建任务调度器
+            taskScheduler = new ThreadPoolTaskScheduler();
+            taskScheduler.setPoolSize(5);
+            taskScheduler.setThreadNamePrefix("inspection-scheduler-");
+            taskScheduler.setWaitForTasksToCompleteOnShutdown(true);
+            taskScheduler.setAwaitTerminationSeconds(60);
+            taskScheduler.initialize();
 
-        startTime = LocalDateTime.now();
+            startTime = LocalDateTime.now();
 
-        // 加载已启用的计划
-        loadEnabledPlans();
+            // 加载已启用的计划
+            loadEnabledPlans();
 
-        log.info("========== 巡检调度器初始化完成,已注册 {} 个计划 ==========", scheduledTasks.size());
+            log.info("========== 巡检调度器初始化完成,已注册 {} 个计划 ==========", scheduledTasks.size());
+        }
     }
 
     /**

+ 8 - 2
ems/ems-cloud/ems-server/src/main/java/com/ruoyi/ems/task/StrategyScheduler.java

@@ -10,6 +10,7 @@ import com.ruoyi.ems.strategy.PollingMonitorService;
 import com.ruoyi.ems.strategy.executor.StrategyExecutor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.ApplicationContext;
 import org.springframework.scheduling.TaskScheduler;
 import org.springframework.scheduling.support.CronTrigger;
@@ -60,6 +61,9 @@ public class StrategyScheduler {
 
     private StrategyExecutor strategyExecutor;
 
+    @Value("${schedulerCfg.strategy-scheduler:disable}")
+    private String schedulerEnable;
+
     /**
      * 定时任务缓存
      * key: strategyCode:triggerId
@@ -92,8 +96,10 @@ public class StrategyScheduler {
 
     @PostConstruct
     public void init() {
-        log.info("====== 策略调度器初始化(重构版) ======");
-        loadEnabledStrategies();
+        if ("enable".equals(schedulerEnable)) {
+            log.info("====== 策略调度器初始化 ======");
+            loadEnabledStrategies();
+        }
     }
 
     @PreDestroy

+ 8 - 4
ems/ems-core/src/main/java/com/ruoyi/ems/service/impl/AreaServiceImpl.java

@@ -116,8 +116,10 @@ public class AreaServiceImpl implements IAreaService {
         fillAncestors(area);
         int cnt = areaMapper.insertArea(area);
 
-        if (null != area.getAreaAttr()) {
-            attrService.insertAreaAttr(area.getAreaAttr());
+        AreaAttr areaAttr = area.getAreaAttr();
+        if (null != areaAttr) {
+            areaAttr.setAreaCode(area.getAreaCode());
+            attrService.insertAreaAttr(areaAttr);
         }
 
         return cnt;
@@ -134,8 +136,10 @@ public class AreaServiceImpl implements IAreaService {
         fillAncestors(area);
         int cnt = areaMapper.updateArea(area);
 
-        if (null != area.getAreaAttr()) {
-            attrService.updateAreaAttr(area.getAreaAttr());
+        AreaAttr areaAttr = area.getAreaAttr();
+        if (null != areaAttr) {
+            areaAttr.setAreaCode(area.getAreaCode());
+            attrService.updateAreaAttr(areaAttr);
         }
 
         return cnt;

+ 7 - 5
ems/ems-core/src/main/resources/mapper/ems/AreaAttrMapper.xml

@@ -52,11 +52,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <include refid="selectAreaAttrVo"/>
         where area_code = #{areaCode}
     </select>
-        
+
     <insert id="insertAreaAttr" parameterType="com.ruoyi.ems.domain.AreaAttr" useGeneratedKeys="true" keyProperty="id">
         insert into adm_area_attr
         <trim prefix="(" suffix=")" suffixOverrides=",">
-            <if test="areaCode != null and areaCode != ''">area_code,</if>
+            area_code,
+
             <if test="attrOrg != null">attr_org,</if>
             <if test="mgrOrg != null">mgr_org,</if>
             <if test="leader != null">leader,</if>
@@ -67,9 +68,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="floor != null">floor,</if>
             <if test="longitude != null">longitude,</if>
             <if test="latitude != null">latitude,</if>
-         </trim>
+        </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
-            <if test="areaCode != null and areaCode != ''">#{areaCode},</if>
+            #{areaCode},
+
             <if test="attrOrg != null">#{attrOrg},</if>
             <if test="mgrOrg != null">#{mgrOrg},</if>
             <if test="leader != null">#{leader},</if>
@@ -80,7 +82,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="floor != null">#{floor},</if>
             <if test="longitude != null">#{longitude},</if>
             <if test="latitude != null">#{latitude},</if>
-         </trim>
+        </trim>
     </insert>
 
     <update id="updateAreaAttr" parameterType="com.ruoyi.ems.domain.AreaAttr">