Browse Source

初始化比赛换到比赛service里

johnclot69 2 months ago
parent
commit
4ee3b3d18b

+ 0 - 35
incubator-game/src/main/java/com/incubator/game/GGame.java

@@ -1,8 +1,5 @@
 package com.incubator.game;
 
-import cn.hutool.json.JSONArray;
-import cn.hutool.json.JSONException;
-import cn.hutool.json.JSONObject;
 import com.incubator.common.MessageHandler;
 import com.incubator.common.env.Environment;
 import com.incubator.common.game.AbstractService;
@@ -18,9 +15,7 @@ import com.incubator.common.util.RandomUtil;
 import com.incubator.core.net.http.HttpHandler;
 import com.incubator.core.quartz.QuartzServer;
 import com.incubator.core.quartz.QuartzTask;
-import com.incubator.game.constant.RedisKeyConstant;
 import com.incubator.game.contest.ContestService;
-import com.incubator.game.data.jedis.RedisUtil;
 import com.incubator.game.listener.CenterClientListener;
 import com.incubator.game.listener.HttpInnerListener;
 import com.incubator.core.net.ws.NetHandler;
@@ -34,7 +29,6 @@ import com.incubator.game.player.PlayerPool;
 import com.incubator.game.room.RoomService;
 import com.incubator.game.timer.FlushDB;
 import com.incubator.game.timer.RefreshNewDay;
-import com.incubator.game.util.ContestUtil;
 import com.incubator.game.util.GameDataUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.reflections.Reflections;
@@ -138,8 +132,6 @@ public class GGame extends AbstractService {
         this.initHandler();
         // 6.初始化网络服务
         this.initNetService();
-        //7.查询赛事信息
-        this.getContestList();
     }
 
     @Override
@@ -186,7 +178,6 @@ public class GGame extends AbstractService {
      */
     private PropertiesUtil loadProperties(String fileName) throws Exception {
         String filePath = env.getConfDir() + "/" + fileName;
-        filePath = "E:\\zjGame\\incubator-game\\conf\\"+fileName;
         Log.info("加载配置文件: {}", filePath);
         return new PropertiesUtil(filePath);
     }
@@ -428,32 +419,6 @@ public class GGame extends AbstractService {
         }
     }
 
-    /**
-     * 7.初始化赛事信息
-     */
-    private void getContestList() {
-        Log.info("初始化赛事信息...");
-        String competeListStr = RedisUtil.get(RedisKeyConstant.COMPETE_LIST);
-        if (StringUtils.isEmpty(competeListStr)) {
-            Log.info("赛事信息为空,跳过初始化...");
-            return;
-        }
-        JSONArray jsonArray = null;
-        try {
-            jsonArray = new JSONArray(competeListStr);
-            Log.info("赛事信息获取成功正在初始化...");
-        } catch (JSONException e) {
-            e.printStackTrace();
-            Log.error("JSON信息转换异常: {}", e.getMessage(), e);
-            return;
-        }
-        for (Object o : jsonArray) {
-            JSONObject jsonObject = (JSONObject) o;
-            ContestUtil.createJsonContest(jsonObject);
-        }
-        Log.info("赛事信息初始化完成");
-    }
-
     /**
      * 生成唯一的用户名,格式为 user_123456
      *

+ 30 - 0
incubator-game/src/main/java/com/incubator/game/contest/ContestService.java

@@ -1,10 +1,17 @@
 package com.incubator.game.contest;
 
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONException;
+import cn.hutool.json.JSONObject;
 import com.incubator.common.log4j.Log;
 import com.incubator.common.util.RandomUtil;
+import com.incubator.game.constant.RedisKeyConstant;
 import com.incubator.game.data.data.GameData;
 import com.incubator.game.data.data.ext.ContestExt;
+import com.incubator.game.data.jedis.RedisUtil;
 import com.incubator.game.player.Player;
+import com.incubator.game.util.ContestUtil;
+import org.apache.commons.lang3.StringUtils;
 
 import java.util.Map;
 import java.util.concurrent.*;
@@ -45,6 +52,29 @@ public class ContestService {
 //                return;
 //            }
 //        }
+        // 初始化赛事信息
+        this.initContestList();
+    }
+
+    private void initContestList() {
+        String competeListStr = RedisUtil.get(RedisKeyConstant.COMPETE_LIST);
+        if (StringUtils.isEmpty(competeListStr)) {
+            Log.info("赛事信息为空,跳过初始化...");
+            return;
+        }
+        JSONArray jsonArray = null;
+        try {
+            jsonArray = new JSONArray(competeListStr);
+            Log.info("赛事信息获取成功正在初始化...");
+        } catch (JSONException e) {
+            e.printStackTrace();
+            Log.error("JSON信息转换异常: {}", e.getMessage(), e);
+            return;
+        }
+        for (Object o : jsonArray) {
+            JSONObject jsonObject = (JSONObject) o;
+            ContestUtil.createJsonContest(jsonObject);
+        }
     }
 
     /**