Przeglądaj źródła

fix : 客服系统新增自动回复以及非客服人员禁止接入

bilingfeng 1 rok temu
rodzic
commit
2ff5ba7a95

+ 7 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/IGameAuthRoleService.java

@@ -17,6 +17,13 @@ import java.util.Map;
  */
 public interface IGameAuthRoleService extends IService<GameAuthRole> {
 
+    /**
+     * 是否是客服
+     *
+     * @return boolean
+     */
+    boolean isCustomer();
+
     /**
      * 获取用户身份验证类型
      *

+ 8 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/GameAuthRoleServiceImpl.java

@@ -47,6 +47,14 @@ public class GameAuthRoleServiceImpl extends ServiceImpl<GameAuthRoleMapper, Gam
     @Autowired
     private IGameAuthService gameAuthService;
 
+    @Override
+    public boolean isCustomer() {
+        return super.count(new LambdaQueryWrapper<GameAuthRole>()
+                .eq(GameAuthRole::getAuthType, GameAuthEnum.CUSTOMER.getValue())
+                .eq(GameAuthRole::getUserId, SecurityUtil.getUserId())
+        ) > 0;
+    }
+
     @Override
     public Map<Long, String> getUserByAuthType(String authType) {
         List<GameAuthRole> authRoleList = super.list(new LambdaQueryWrapper<GameAuthRole>()

+ 20 - 4
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/KfAppletMsgServiceImpl.java

@@ -95,7 +95,6 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
 
     @Override
     public void appletMsg(String postData) {
-        log.error("接收到SDK转发的小程序消息, postData : {}", postData);
         KfAppletMsgDTO kfAppletMsgDTO = JsonUtil.toObj(postData, KfAppletMsgDTO.class);
         GameApplet gameApplet = gameAppletService.getOne(new LambdaQueryWrapper<GameApplet>()
                 .eq(GameApplet::getGhId, kfAppletMsgDTO.getToUserName()));
@@ -126,6 +125,8 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
         if (Strings.isNotBlank(orderId) && this.orderHandle(orderId, gameApplet.getGameId(), kfAppletMsgDTO, kfRoom, kfRoomMsg)) {
             return;
         }
+        //客服休息时间, 发送自动回复
+        this.systemReplyHandle(gameApplet.getGameId(), kfAppletMsgDTO.getFromUserName(), kfRoom);
         //保存房间消息
         kfRoomMsgService.save(kfRoomMsg);
         //玩家状态更新为待接入状态
@@ -140,14 +141,29 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
         this.pushMessage(this.transform(kfRoom, gameApplet.getGameId(), kfRoomMsg, msgContent));
     }
 
-    private void systemReplyHandle(Long gameId){
+    private void systemReplyHandle(Long gameId, String openId, KfRoom kfRoom) {
         //获取自动回复配置
         KfSystemReply kfSystemReply = kfSystemReplyService.getById(gameId);
-        if (kfSystemReply == null){
+        if (kfSystemReply == null) {
             return;
         }
         //判断当前时间是否在时间内
-//        LocalTime.parse(kfSystemReply.getStartTime());
+        LocalTime nowTime = LocalTime.now();
+        LocalTime startTime = LocalTime.parse(kfSystemReply.getStartTime());
+        LocalTime endTime = LocalTime.parse(kfSystemReply.getEndTime());
+        if (nowTime.isAfter(startTime) && nowTime.isBefore(endTime)) {
+            return;
+        }
+        //休息时间, 发送指定消息
+        Map<String, Object> textMap = new HashMap<>(1);
+        textMap.put("content", kfSystemReply.getSysReply());
+        Map<String, Object> msgParamMap = new HashMap<>(3);
+        msgParamMap.put("touser", openId);
+        msgParamMap.put("msgtype", KfRoomMsgTypeEnum.KF_MSG_TYPE_TEXT.getValue());
+        msgParamMap.put("text", textMap);
+        kfWxApiService.sendCustomMessageApi(gameId, msgParamMap);
+        //保存消息
+        kfRoomMsgService.save(this.transform(openId, gameId, kfRoom, JsonUtil.toString(msgParamMap)));
     }
 
     private boolean orderHandle(String orderId, Long gameId, KfAppletMsgDTO kfAppletMsgDTO, KfRoom kfRoom, KfRoomMsg kfRoomMsg) {

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

@@ -10,10 +10,7 @@ import com.zanxiang.game.module.manage.enums.KfRoomMsgTypeEnum;
 import com.zanxiang.game.module.manage.enums.KfWebSocketMsgEnum;
 import com.zanxiang.game.module.manage.pojo.dto.KfWebSocketMsgDTO;
 import com.zanxiang.game.module.manage.pojo.params.KfWebSocketMsgParam;
-import com.zanxiang.game.module.manage.service.IKfQuickReplyService;
-import com.zanxiang.game.module.manage.service.IKfRoomMsgService;
-import com.zanxiang.game.module.manage.service.IKfRoomService;
-import com.zanxiang.game.module.manage.service.IKfSessionUserService;
+import com.zanxiang.game.module.manage.service.*;
 import com.zanxiang.game.module.manage.service.api.KfWxApiService;
 import com.zanxiang.game.module.manage.utils.FileUtil;
 import com.zanxiang.game.module.mybatis.entity.KfRoom;
@@ -66,6 +63,9 @@ public class KfMsgWebsocketHandler implements WebSocketHandler {
     @Autowired
     private KfWxApiService wxApiService;
 
+    @Autowired
+    private IGameAuthRoleService gameAuthRoleService;
+
     @Autowired
     private IKfQuickReplyService kfQuickReplyService;
 
@@ -327,6 +327,8 @@ public class KfMsgWebsocketHandler implements WebSocketHandler {
                 .gameId(gameId)
                 .roomList(onlineRoomList)
                 .build());
+        //释放锁
+        distributedLockComponent.unlock(RedisKeyConstant.KF_MSG_USER_CONNECT_JOIN + kfRoom.getOpenId());
     }
 
     private void finishRoomList(WebSocketSession session, KfWebSocketMsgParam param) {
@@ -368,15 +370,16 @@ public class KfMsgWebsocketHandler implements WebSocketHandler {
     }
 
     private void userConnectJoin(WebSocketSession session, KfWebSocketMsgParam param) {
+        //参数判断
         if (Strings.isBlank(param.getOpenId())) {
             this.sendMessage(session, KfWebSocketMsgDTO.fail(param.getWebSocketMsgType(),
                     "接入玩家参数错误, openId不可为空, param : " + JsonUtil.toString(param)));
             return;
         }
-        //触发玩家接入线程锁
-        if (!distributedLockComponent.doLock(RedisKeyConstant.KF_MSG_USER_CONNECT_JOIN + param.getOpenId(),
-                0L, 5L, TimeUnit.MINUTES)) {
-            this.sendMessage(session, KfWebSocketMsgDTO.fail(param.getWebSocketMsgType(), "玩家已被其他客服接入"));
+        //判断是否为客服
+        if (!gameAuthRoleService.isCustomer()) {
+            this.sendMessage(session, KfWebSocketMsgDTO.fail(param.getWebSocketMsgType(),
+                    "非客服人员, 不可接待玩家, param : " + JsonUtil.toString(param)));
             return;
         }
         //玩家信息, 判断玩家是否已经被接入
@@ -385,6 +388,12 @@ public class KfMsgWebsocketHandler implements WebSocketHandler {
             this.sendMessage(session, KfWebSocketMsgDTO.fail(param.getWebSocketMsgType(), "玩家已被其他客服接入"));
             return;
         }
+        //触发玩家接入线程锁
+        if (!distributedLockComponent.doLock(RedisKeyConstant.KF_MSG_USER_CONNECT_JOIN + param.getOpenId(),
+                0L, 5L, TimeUnit.MINUTES)) {
+            this.sendMessage(session, KfWebSocketMsgDTO.fail(param.getWebSocketMsgType(), "玩家已被其他客服接入"));
+            return;
+        }
         //玩家更新为已接入
         kfSessionUserService.update(new LambdaUpdateWrapper<KfSessionUser>()
                 .set(KfSessionUser::getIsWait, Boolean.FALSE)
@@ -417,8 +426,6 @@ public class KfMsgWebsocketHandler implements WebSocketHandler {
                 .gameId(param.getGameId())
                 .waitUserList(waitUserList)
                 .build());
-        //释放锁
-        distributedLockComponent.unlock(RedisKeyConstant.KF_MSG_USER_CONNECT_JOIN + param.getOpenId());
     }
 
     private void kfCreateConnect(WebSocketSession session, KfWebSocketMsgEnum msgTypeEnum, Long gameId) {

+ 5 - 5
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/KfSystemReply.java

@@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.*;
 
-import java.util.Date;
+import java.time.LocalDateTime;
 
 /**
  * @author : lingfeng
@@ -39,20 +39,20 @@ public class KfSystemReply {
     /**
      * 开始时间
      */
-    private Date startTime;
+    private String startTime;
 
     /**
      * 结束时间
      */
-    private Date endTime;
+    private String endTime;
 
     /**
      * 创建时间
      */
-    private Date createTime;
+    private LocalDateTime createTime;
 
     /**
      * 更新时间
      */
-    private Date updateTime;
+    private LocalDateTime updateTime;
 }