Преглед изворни кода

feat : 消息推送策略代码提交01

bilingfeng пре 10 месеци
родитељ
комит
d8d6c317f8

+ 1 - 1
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/ManageApplication.java

@@ -23,7 +23,7 @@ public class ManageApplication {
 
     public static void main(String[] args) {
         SpringApplication.run(ManageApplication.class, args);
-        System.out.println("赞象Manage服务启动成功 < (消息推送策略・・)ノ(._.`) \n" +
+        System.out.println("赞象Manage服务启动成功 < (消息推送策略01・・)ノ(._.`) \n" +
                 "___  ___  ___   _   _   ___  _____  _____ \n" +
                 "|  \\/  | / _ \\ | \\ | | / _ \\|  __ \\|  ___|\n" +
                 "| .  . |/ /_\\ \\|  \\| |/ /_\\ \\ |  \\/| |__  \n" +

+ 24 - 19
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/rpc/impl/PushMsgRpcImpl.java

@@ -69,29 +69,34 @@ public class PushMsgRpcImpl implements IPushMsgRpc {
         log.error("消息推送,, 接收到等级更新消息, param : {}", JsonUtil.toString(param));
         //等级变更, 过滤战力变化, 1小时执行一次
         String lock = RedisKeyConstant.GAME_USER_ROLE_UP_LOCK + param.getUserId() + "_" + param.getGameId() + "_"
-                + param.getServerId() + "_" + param.getRoleId() + "_" + param.getRoleLevel();
-        if (!distributedLockComponent.doLock(lock, 0L, 1L, TimeUnit.HOURS)) {
+                + param.getServerId() + "_" + param.getRoleId();
+        if (!distributedLockComponent.doLock(lock, 0L, 10L, TimeUnit.MINUTES)) {
             log.error("消息推送, 等级变化碰撞线程锁, 消息不执行 param : {}", JsonUtil.toString(param));
             return;
         }
-        //全局策略控制是否限制
-        if (this.defaultStrategyCheck(param)) {
-            log.error("等级更新消息, 全局策略判断不执行, param : {}", JsonUtil.toString(param));
-            return;
-        }
-        //查询等级策略
-        PushMsgStrategy pushMsgStrategy = pushMsgStrategyService.getOne(new LambdaQueryWrapper<PushMsgStrategy>()
-                .eq(PushMsgStrategy::getStrategyType, PushMsgStrategyTypeEnum.PUSH_MSG_STRATEGY_LEVEL.getValue())
-                .eq(PushMsgStrategy::getGameId, param.getGameId())
-                .le(PushMsgStrategy::getRoleLevelMin, param.getRoleLevel())
-                .ge(PushMsgStrategy::getRoleLevelMax, param.getRoleLevel())
-                .orderByDesc(PushMsgStrategy::getCreateTime)
-                .last("limit 1"));
-        if (pushMsgStrategy == null) {
-            log.error("等级更新消息, 查询策略为空, param : {}", JsonUtil.toString(param));
-            return;
+        try {
+            //全局策略控制是否限制
+            if (this.defaultStrategyCheck(param)) {
+                log.error("等级更新消息, 全局策略判断不执行, param : {}", JsonUtil.toString(param));
+                return;
+            }
+            //查询等级策略
+            PushMsgStrategy pushMsgStrategy = pushMsgStrategyService.getOne(new LambdaQueryWrapper<PushMsgStrategy>()
+                    .eq(PushMsgStrategy::getStrategyType, PushMsgStrategyTypeEnum.PUSH_MSG_STRATEGY_LEVEL.getValue())
+                    .eq(PushMsgStrategy::getGameId, param.getGameId())
+                    .le(PushMsgStrategy::getRoleLevelMin, param.getRoleLevel())
+                    .ge(PushMsgStrategy::getRoleLevelMax, param.getRoleLevel())
+                    .orderByDesc(PushMsgStrategy::getCreateTime)
+                    .last("limit 1"));
+            if (pushMsgStrategy == null) {
+                log.error("等级更新消息, 查询策略为空, param : {}", JsonUtil.toString(param));
+                return;
+            }
+            pushMsgStrategyService.strategyPushMsgRun(pushMsgStrategy, param);
+        } catch (Exception ignored) {
+        } finally {
+            distributedLockComponent.unlock(lock);
         }
-        pushMsgStrategyService.strategyPushMsgRun(pushMsgStrategy, param);
     }
 
     private boolean defaultStrategyCheck(PushMsgParam param) {

+ 1 - 1
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/SDKApplication.java

@@ -23,7 +23,7 @@ public class SDKApplication {
 
     public static void main(String[] args) {
         SpringApplication.run(SDKApplication.class, args);
-        System.out.println("赞象SDK服务启动成功 <消息推送策略> ( ´・・)ノ(._.`) \n" +
+        System.out.println("赞象SDK服务启动成功 <消息推送策略01> ( ´・・)ノ(._.`) \n" +
                 " ___________ _   __\n" +
                 "/  ___|  _  \\ | / /\n" +
                 "\\ `--.| | | | |/ / \n" +

+ 1 - 15
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/controller/UserController.java

@@ -3,7 +3,6 @@ package com.zanxiang.game.module.sdk.controller;
 
 import com.zanxiang.game.module.sdk.annotation.UnSignCheck;
 import com.zanxiang.game.module.sdk.annotation.ValidLogin;
-import com.zanxiang.game.module.sdk.enums.DataTypeEnum;
 import com.zanxiang.game.module.sdk.pojo.param.*;
 import com.zanxiang.game.module.sdk.pojo.vo.CustomerVO;
 import com.zanxiang.game.module.sdk.pojo.vo.GameShareVO;
@@ -21,7 +20,6 @@ import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
-import java.util.Objects;
 
 /**
  * @author : lingfeng
@@ -46,9 +44,6 @@ public class UserController {
     @Autowired
     private IUserShareService userShareService;
 
-    @Autowired
-    private IPushMsgService pushMsgService;
-
     @Autowired
     private IGameShellLogService gameShellLogService;
 
@@ -116,16 +111,7 @@ public class UserController {
     @PostMapping("/update/game/role")
     @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = Boolean.class)})
     public ResultVO<Boolean> updateUserGameRole(@Validated @RequestBody GameUserRoleUpdateParam param, @ValidLogin UserData userData) {
-        Boolean result = gameUserRoleService.updateUserGameRole(param, userData);
-        //创建角色通知监听服务
-        if (Objects.equals(param.getDataType(), DataTypeEnum.TYPE_CREATE_ROLE.getDateType())) {
-            gameUserRoleService.callListenIn(param, userData);
-        }
-        //等级提升, 消息推送
-        if (Objects.equals(param.getDataType(), DataTypeEnum.TYPE_LEVEL_UP.getDateType())) {
-            pushMsgService.pushMsgByLevelUpdate(param, userData);
-        }
-        return ResultVO.ok(result);
+        return ResultVO.ok(gameUserRoleService.updateUserGameRole(param, userData));
     }
 
     @ApiOperation(value = "用户活跃信息上报")

+ 0 - 8
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/IGameUserRoleService.java

@@ -35,14 +35,6 @@ public interface IGameUserRoleService extends IService<GameUserRole> {
      */
     void userGuideGameRoleCheck(User user, User relationUser);
 
-    /**
-     * 通知监听服务
-     *
-     * @param param    参数
-     * @param userData 用户数据
-     */
-    void callListenIn(GameUserRoleUpdateParam param, UserData userData);
-
     /**
      * 游戏角色活跃上报
      *

+ 23 - 4
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/GameUserRoleServiceImpl.java

@@ -66,6 +66,9 @@ public class GameUserRoleServiceImpl extends ServiceImpl<GameUserRoleMapper, Gam
     @Autowired
     private IDistributedLockComponent distributedLockComponent;
 
+    @Autowired
+    private IPushMsgService pushMsgService;
+
     @Autowired
     private IGameExtService gameExtService;
 
@@ -105,7 +108,14 @@ public class GameUserRoleServiceImpl extends ServiceImpl<GameUserRoleMapper, Gam
                 .eq(GameUserRole::getRoleId, gameUserRoleParam.getRoleId()));
         //更新游戏角色
         if (gameUserRole != null) {
+            //判断是否等级变更
+            boolean updateRoleLevel = gameUserRoleParam.getRoleLevel() > gameUserRole.getRoleLevel();
+            //角色更新
             this.gameRoleUpdate(gameUserRoleParam, gameUserRole, userData);
+            //玩家消息推送
+            if (updateRoleLevel) {
+                pushMsgService.pushMsgByLevelUpdate(gameUserRoleParam, userData);
+            }
             return Boolean.TRUE;
         }
         //新建游戏角色
@@ -154,8 +164,16 @@ public class GameUserRoleServiceImpl extends ServiceImpl<GameUserRoleMapper, Gam
                     LoginTypeEnum.LOGIN_IN.getLoginType());
         }
         //等级提升更新
-        if (Objects.equals(dataType, DataTypeEnum.TYPE_LEVEL_UP.getDateType())) {
-            return this.gameRoleUpdate(param, gameUserRole, userData);
+        if (gameUserRole != null && Objects.equals(dataType, DataTypeEnum.TYPE_LEVEL_UP.getDateType())) {
+            //判断是否等级变更
+            boolean updateRoleLevel = param.getRoleLevel() > gameUserRole.getRoleLevel();
+            //角色更新
+            boolean result = this.gameRoleUpdate(param, gameUserRole, userData);
+            //玩家消息推送
+            if (updateRoleLevel) {
+                pushMsgService.pushMsgByLevelUpdate(param, userData);
+            }
+            return result;
         }
         //退出游戏
         if (Objects.equals(dataType, DataTypeEnum.TYPE_EXIT_GAME.getDateType())) {
@@ -245,6 +263,8 @@ public class GameUserRoleServiceImpl extends ServiceImpl<GameUserRoleMapper, Gam
         callBackService.roleCallBack(userRole, userData);
         //用户创角埋点数据发送到卡夫卡
         kafkaService.eventTrack(KafkaEventTrackEnum.KAFKA_EVENT_TRACK_ROLE_CREATE, JsonUtil.toString(userRole));
+        //创建角色通知监听服务
+        this.callListenIn(param, userData);
     }
 
     private GameUserRole transform(GameUserRoleUpdateParam param, UserData userData, GameUser gameUser, User user) {
@@ -326,8 +346,7 @@ public class GameUserRoleServiceImpl extends ServiceImpl<GameUserRoleMapper, Gam
                 .build();
     }
 
-    @Override
-    public void callListenIn(GameUserRoleUpdateParam param, UserData userData) {
+    private void callListenIn(GameUserRoleUpdateParam param, UserData userData) {
         Map<String, String> map = new HashMap<>(2);
         map.put("json", JsonUtil.toString(param));
         map.put("userData", JsonUtil.toString(userData));