Quellcode durchsuchen

定时任务开关

dos vor 2 Monaten
Ursprung
Commit
4f35513848

+ 5 - 0
game-admin/src/main/resources/application.yml

@@ -140,5 +140,10 @@ xss:
   # 匹配链接
   urlPatterns: /system/*,/monitor/*,/tool/*
 
+#websocket开关
 websocket:
   switch: false
+
+#定时任务开关
+task:
+  switch: false

+ 6 - 0
game-business/src/main/java/com/game/business/task/AppGameItemTask.java

@@ -2,6 +2,7 @@ package com.game.business.task;
 
 import com.game.business.service.IAppGameItemService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
@@ -11,9 +12,14 @@ public class AppGameItemTask {
     @Autowired
     private IAppGameItemService appGameItemService;
 
+    @Value("${task.switch}")
+    private Boolean taskSwitch;
 
     @Scheduled(cron = "0 0 0 * * ?")
     public void appGameItemTask(){
+        if(!taskSwitch){
+            return;
+        }
         appGameItemService.emptyLotteryCount();
     }
 }

+ 25 - 6
game-business/src/main/java/com/game/business/task/AppUserCountTask.java

@@ -16,6 +16,7 @@ import com.game.common.utils.DateUtils;
 import com.game.common.utils.StringUtils;
 import lombok.extern.log4j.Log4j2;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
 import java.math.BigDecimal;
@@ -64,16 +65,22 @@ public class AppUserCountTask {
     @Autowired
     private RedisCache redisCache;
 
+    @Value("${task.switch}")
+    private Boolean taskSwitch;
+
 
     /**
      * 统计用户前一天
      * */
     public void statistics(String dateTime){
+        if(!taskSwitch){
+            return;
+        }
         String redisKey = CacheConstants.USER_STATICS_COUNT.concat("statistics");
-        if(!redisCache.redisTemplate.opsForValue().setIfAbsent(redisKey,1)){
+        /*if(!redisCache.redisTemplate.opsForValue().setIfAbsent(redisKey,1)){
             log.info("停止统计用户每日直播、游戏、佣金,已在其他机器执行");
             return;
-        }
+        }*/
         log.info("开始统计用户每日直播、游戏、佣金");
         try {
             Date curDate = DateUtil.offsetDay(DateUtils.getNowDate(), -1);
@@ -212,11 +219,14 @@ public class AppUserCountTask {
      * 统计用户直播/充值 (增量更新 1分钟)
      * */
     public void statisticsLive(){
+        if(!taskSwitch){
+            return;
+        }
         String redisKey = CacheConstants.USER_STATICS_COUNT.concat("statisticsLive");
-        if(!redisCache.redisTemplate.opsForValue().setIfAbsent(redisKey,1)){
+        /*if(!redisCache.redisTemplate.opsForValue().setIfAbsent(redisKey,1)){
             log.info("停止增量更新用户每日直播、佣金,已在其他机器执行");
             return;
-        }
+        }*/
         log.info("开始增量更新用户每日直播、佣金");
         try {
             Long userId = null;
@@ -303,11 +313,14 @@ public class AppUserCountTask {
      * */
     @DSTransactional
     public void calculateDividends(String dateTime){
+        if(!taskSwitch){
+            return;
+        }
         String redisKey = CacheConstants.USER_STATICS_COUNT.concat("calculateDividends");
-        if(!redisCache.redisTemplate.opsForValue().setIfAbsent(redisKey,1)){
+        /*if(!redisCache.redisTemplate.opsForValue().setIfAbsent(redisKey,1)){
             log.info("停止每周代理分红,已在其他机器执行");
             return;
-        }
+        }*/
         try {
             log.info("开始每周代理分红");
             String dateNo =  dealDividendsNew(dateTime);
@@ -513,6 +526,9 @@ public class AppUserCountTask {
      * 更新用户下级列表
      * */
     public void statisticsTeam(){
+        if(!taskSwitch){
+            return;
+        }
         AppUserAgent query = new AppUserAgent();
         List<AppUserAgent> userAgents = appUserAgentService.selectAppUserAgentList(query);
         userAgents.forEach(appUserAgent -> {
@@ -525,6 +541,9 @@ public class AppUserCountTask {
     }
 
     public void reloadDividendCache(String dateTime,String topUserId){
+        if(!taskSwitch){
+            return;
+        }
         appUserCountDividendService.reloadCache(dateTime,StringUtils.isBlank(topUserId)?null:Arrays.asList(Long.valueOf(topUserId)));
     }
 

+ 7 - 1
game-business/src/main/java/com/game/business/task/AppUserLiveDividedTask.java

@@ -7,6 +7,7 @@ import com.game.common.constant.finance.FinTranType2;
 import com.game.common.constant.finance.FinTranType3;
 import com.game.common.core.redis.RedisCache;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 import org.springframework.transaction.annotation.Transactional;
@@ -36,9 +37,14 @@ public class AppUserLiveDividedTask {
     @Autowired
     private RedisCache redisCache;
 
+    @Value("${task.switch}")
+    private Boolean taskSwitch;
+
     @Scheduled(cron = "0 0/5 * * * ? ")
     public void liveDividedTask(){
-
+        if(!taskSwitch){
+            return;
+        }
         AppUserLiveDivided appUserLiveDivided = new AppUserLiveDivided();
         appUserLiveDivided.setStatus(0);
         List<AppUserLiveDivided> list = appUserLiveDividedService.selectAppUserLiveDividedList(appUserLiveDivided);

+ 7 - 0
game-business/src/main/java/com/game/business/task/WebSokcetTask.java

@@ -1,6 +1,7 @@
 package com.game.business.task;
 
 import com.game.business.util.Common;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
@@ -10,8 +11,14 @@ import java.io.IOException;
 @Component
 public class WebSokcetTask {
 
+    @Value("${task.switch}")
+    private Boolean taskSwitch;
+
     @Scheduled(cron = "0/5 * * * * ? ")
     public void liveDividedTask() throws IOException {
+        if(!taskSwitch){
+            return;
+        }
 
         if(Common.sessionMap.containsKey(Common.GAME_ONE_CODE)){
             Session session = Common.sessionMap.get(Common.GAME_ONE_CODE);