Procházet zdrojové kódy

fix : 解决玩家反馈信息, 新增充值玩家的充值自动回复

bilingfeng před 1 rokem
rodič
revize
cdd5b7fca8

+ 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服务启动成功 < (解决玩家反馈信息, 新增充值玩家的充值自动回复´・・)ノ(._.`) \n" +
                 "___  ___  ___   _   _   ___  _____  _____ \n" +
                 "|  \\/  | / _ \\ | \\ | | / _ \\|  __ \\|  ___|\n" +
                 "| .  . |/ /_\\ \\|  \\| |/ /_\\ \\ |  \\/| |__  \n" +

+ 5 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/constant/RedisKeyConstant.java

@@ -42,4 +42,9 @@ public class RedisKeyConstant {
      */
     public static final String GAME_CUSTOM_PAY_SIGN = "game_sdk_manage_custom_pay_sign_";
 
+    /**
+     * 客服系统玩家信息更新
+     */
+    public static final String KF_MSG_USER_SESSION_UPDATE = RedisKeyConstant.REDIS_PREFIX + "kf_msg_user_session_update_";
+
 }

+ 5 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/pojo/dto/KfAppletMsgDTO.java

@@ -18,6 +18,11 @@ public class KfAppletMsgDTO {
      */
     public static final String MSG_TYPE_EVENT = "event";
 
+    /**
+     * 玩家反馈消息
+     */
+    public static final String MSG_USER_FEEDBACK = "【来源于用户反馈】";
+
     /**
      * 用户进入会话事件
      */

+ 28 - 7
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/KfAppletMsgServiceImpl.java

@@ -19,6 +19,7 @@ import com.zanxiang.game.module.manage.utils.FileUtil;
 import com.zanxiang.game.module.manage.utils.RedisUtil;
 import com.zanxiang.game.module.mybatis.entity.*;
 import com.zanxiang.module.oss.service.IOssService;
+import com.zanxiang.module.redis.service.IDistributedLockComponent;
 import com.zanxiang.module.util.JsonUtil;
 import com.zanxiang.module.util.bean.BeanUtil;
 import com.zanxiang.module.util.exception.BaseException;
@@ -37,6 +38,7 @@ import java.net.URI;
 import java.time.LocalDateTime;
 import java.time.LocalTime;
 import java.util.*;
+import java.util.concurrent.TimeUnit;
 
 /**
  * @author : lingfeng
@@ -101,6 +103,9 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
     @Autowired
     private RedisUtil<String> redisUtil;
 
+    @Autowired
+    private IDistributedLockComponent distributedLockComponent;
+
     @Override
     public void appletMsg(String postData) {
         KfAppletMsgDTO kfAppletMsgDTO = JsonUtil.toObj(postData, KfAppletMsgDTO.class);
@@ -119,6 +124,11 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
         if (kfAppletMsgDTO.getMsgId() == null) {
             return;
         }
+        //判断是否为玩家反馈信息, 如果是反馈信息需要检查玩家身份信息是否存在, 腾讯个坑比先给消息再给客服进入事件
+        if (Strings.isNotBlank(kfAppletMsgDTO.getContent())
+                && kfAppletMsgDTO.getContent().contains(KfAppletMsgDTO.MSG_USER_FEEDBACK)) {
+            this.kfSessionUserUpdateSave(kfAppletMsgDTO, gameApplet);
+        }
         //查询玩家的房间连接状态
         KfRoom kfRoom = kfRoomService.getOne(new LambdaQueryWrapper<KfRoom>()
                 .eq(KfRoom::getOpenId, kfAppletMsgDTO.getFromUserName())
@@ -321,7 +331,12 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
     }
 
     private void kfSessionUserUpdateSave(KfAppletMsgDTO kfAppletMsgDTO, GameApplet gameApplet) {
-        KfSessionUser kfSessionUser = kfSessionUserService.getById(kfAppletMsgDTO.getFromUserName());
+        //上锁
+        String lockKey = RedisKeyConstant.KF_MSG_USER_SESSION_UPDATE
+                + kfAppletMsgDTO.getFromUserName() + "_" + gameApplet.getGameId();
+        if (!distributedLockComponent.doLock(lockKey, 0L, 5L, TimeUnit.MINUTES)) {
+            return;
+        }
         //查询用户
         User user = userService.getOne(new LambdaQueryWrapper<User>()
                 .eq(User::getGameId, gameApplet.getGameId())
@@ -332,17 +347,23 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
             gameUserRole = gameUserRoleService.getLastGameUserRoleName(user.getId(), user.getGameId());
         }
         //不存在玩家信息, 创建保存
-        if (kfSessionUser == null) {
+        if (kfSessionUserService.count(new LambdaQueryWrapper<KfSessionUser>()
+                .eq(KfSessionUser::getOpenId, kfAppletMsgDTO.getFromUserName())
+        ) <= 0) {
             kfSessionUserService.save(this.transform(kfAppletMsgDTO, gameApplet, user, gameUserRole));
             return;
         }
+        //不存在角色信息, 不做更新
+        if (gameUserRole == null) {
+            return;
+        }
         //存在, 更新玩家信息
         kfSessionUserService.update(new LambdaUpdateWrapper<KfSessionUser>()
-                .set(KfSessionUser::getUserId, user == null ? null : user.getId())
-                .set(KfSessionUser::getLastRoleId, gameUserRole == null ? null : gameUserRole.getRoleId())
-                .set(KfSessionUser::getLastRoleName, gameUserRole == null ? "神秘人[未创角]" : gameUserRole.getRoleName())
-                .set(gameUserRole != null, KfSessionUser::getServerId, gameUserRole == null ? null : gameUserRole.getServerId())
-                .set(gameUserRole != null, KfSessionUser::getServerName, gameUserRole == null ? null : gameUserRole.getServerName())
+                .set(KfSessionUser::getUserId, user.getId())
+                .set(KfSessionUser::getLastRoleId, gameUserRole.getRoleId())
+                .set(KfSessionUser::getLastRoleName, gameUserRole.getRoleName())
+                .set(KfSessionUser::getServerId, gameUserRole.getServerId())
+                .set(KfSessionUser::getServerName, gameUserRole.getServerName())
                 .set(KfSessionUser::getUpdateTime, LocalDateTime.now())
                 .eq(KfSessionUser::getOpenId, kfAppletMsgDTO.getFromUserName()));
     }

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

@@ -395,7 +395,7 @@ public class KfMsgWebsocketHandler implements WebSocketHandler {
             return;
         }
         //触发玩家接入线程锁
-        String lockKey = RedisKeyConstant.KF_MSG_USER_CONNECT_JOIN + param.getOpenId();
+        String lockKey = RedisKeyConstant.KF_MSG_USER_CONNECT_JOIN + param.getOpenId() + "_" + param.getGameId();
         log.error("玩家接入触发线程锁, key : {}", lockKey);
         if (!redisUtil.setIfAbsent(lockKey, lockKey, ExpireTimeEnum.FIVE_MIN.getTime())) {
             log.error("玩家接入锁碰撞, 未接入成功, key : {}", lockKey);