Sfoglia il codice sorgente

定时任务-推送公告-调整为通过配置文件使其本地不执行定时任务

LHB 1 mese fa
parent
commit
5352a6c435

+ 8 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/job/SystemMsgJob.java

@@ -10,6 +10,7 @@ import org.springblade.manager.entity.SystemMsg;
 import org.springblade.manager.service.ISystemMsgService;
 import org.springblade.websocket.vo.MsgVO;
 import org.springblade.websocket.vo.SystMsgVO;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.jdbc.core.BeanPropertyRowMapper;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.scheduling.annotation.Scheduled;
@@ -34,11 +35,18 @@ public class SystemMsgJob {
 
     private final JdbcTemplate jdbcTemplate;
 
+    // 读取配置并设置默认值
+    @Value("${scheduler.enabled:true}")
+    private boolean schedulerEnabled;
+
     /**
      *  定时推送公告-取消公告-修改公告状态,不想污染日志,使用jdbc
      */
     @Scheduled(cron = "0/10 * * * * ?")
     public void autoUpdateMsgStatus(){
+        // 本地环境跳过执行(可添加日志输出)
+        if (!schedulerEnabled) return;
+
         /** 普通公告推送*/
         String sql1 = "select * from m_system_msg where is_deleted = 0 and msg_type = 2 and push_status = 1 and push_end_date_time >= now()";
         List<SystemMsg> list1 = jdbcTemplate.query(sql1,new BeanPropertyRowMapper<>(SystemMsg.class));