Browse Source

Merge remote-tracking branch 'origin/package' into package

zhangxianyu 1 year ago
parent
commit
10937030b5

+ 2 - 0
game-module/game-module-base/src/main/java/com/zanxiang/game/module/base/util/PageUtil.java

@@ -18,6 +18,8 @@ import java.util.List;
 @Builder
 public class PageUtil<T> implements Serializable {
 
+    private static final long serialVersionUID = 1L;
+
     /**
      * 查询数据列表
      */

+ 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服务启动成功 <CP推送消息代码提交 ( ´・・)ノ(._.`) \n" +
+        System.out.println("赞象Manage服务启动成功 <区服指派接口调试修改 ( ´・・)ノ(._.`) \n" +
                 "___  ___  ___   _   _   ___  _____  _____ \n" +
                 "|  \\/  | / _ \\ | \\ | | / _ \\|  __ \\|  ___|\n" +
                 "| .  . |/ /_\\ \\|  \\| |/ /_\\ \\ |  \\/| |__  \n" +

+ 0 - 148
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/CpCallServiceImpl.java

@@ -1,148 +0,0 @@
-package com.zanxiang.game.module.manage.service.impl;
-
-import com.zanxiang.game.module.manage.pojo.dto.CpSendMsgResultDTO;
-import com.zanxiang.module.util.JsonUtil;
-import com.zanxiang.module.util.exception.BaseException;
-import org.springframework.http.HttpEntity;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.MediaType;
-import org.springframework.web.client.RestTemplate;
-
-import java.nio.charset.StandardCharsets;
-import java.security.MessageDigest;
-import java.util.*;
-
-/**
- * @author : lingfeng
- * @time : 2024-02-22
- * @description : CP接口交互 demo类, 测试完成要删除
- */
-public class CpCallServiceImpl {
-
-    /**
-     * MD5加密
-     */
-    private static final String SIGN_MD5 = "MD5";
-
-//    public static void main(String[] args) throws Exception {
-//
-//        String text = "尊敬的尊享玩家“角色名”:\n" +
-//                "叮,尊享管家小诗正在微信上等待与您的见面,根据您的游戏角色成长,小诗特意为您定制一份战力快速升级的攻略和几个尊享限定礼包,助您快速提升~\n" +
-//                "您要尽快通过游戏内“联系客服”按钮与我联系,时间有限,请您尽快与我联系哦。\n" +
-//                "联系时请您带上此页面截图,同时请您保密勿将此内容分享给其他玩家,可能会导致尊享限定礼包被冒领哦!";
-////        test();
-//        CpSendMsgResultDTO result = cpSendMsgApi("testMsgId2", "668", Collections.singletonList("821112073166082222"), text);
-//        System.out.println("11111111" + JsonUtil.toString(result));
-//    }
-
-    public static CpSendMsgResultDTO cpSendMsgApi(String msgId, String serverId, List<String> roleIdList, String text) throws Exception {
-        long time = System.currentTimeMillis() / 1000;
-        Map<String, Object> param = new HashMap<>(8);
-        param.put("msgId", msgId);
-        param.put("strRan", msgId);
-        param.put("time", time);
-        param.put("sign", MD5("key=" + "355b7f07125c1ef71cfd10166e0b90aa" + "&msgId=" + msgId + "&strRan=" + msgId + "&time=" + time));
-        param.put("pushType", 1);
-        param.put("serverid", serverId);
-        param.put("roleIds", roleIdList);
-        //图片地址弄一张最小的, CP方不会用, 有默认底图
-        List<String> imgList = Collections.singletonList("https://manage.84game.cn/image/WechatIMG56.jpeg");
-        Map<String, Object> msgContent = new HashMap<>(2);
-        msgContent.put("text", text);
-        msgContent.put("imgs", JsonUtil.toString(imgList));
-        param.put("msgContent", msgContent);
-        //请求头
-        HttpHeaders headers = new HttpHeaders();
-        headers.setContentType(MediaType.APPLICATION_JSON);
-        headers.set(HttpHeaders.ACCEPT_CHARSET, "UTF-8");
-        HttpEntity<String> request = new HttpEntity<>(JsonUtil.toString(param), headers);
-        String result;
-        try {
-            RestTemplate restTemplate = new RestTemplate();
-            result = restTemplate.postForObject("https://ht.lttx.t5yx.cn/extapi?action=BgzszhSendTip",
-                    request, String.class);
-        } catch (Exception e) {
-            System.out.println(e.getMessage());
-            throw new BaseException("消息发送失败");
-        }
-        System.out.println("返回结果" + result);
-        CpSendMsgResultDTO cpSendMsgResultDTO = JsonUtil.toObj(result, CpSendMsgResultDTO.class);
-        return cpSendMsgResultDTO;
-    }
-
-    public static void test() throws Exception {
-        String key = "355b7f07125c1ef71cfd10166e0b90aa";
-        RestTemplate restTemplate = new RestTemplate();
-
-        String url = "https://ht.lttx.t5yx.cn/extapi?action=BgzszhSendTip";
-
-        Map<String, Object> param = new HashMap<>();
-
-        String msgId = "testMsgId2";
-        param.put("msgId", msgId);
-
-        String strRan = "strRan1";
-        param.put("strRan", strRan);
-
-        Long time = 1709002794L;
-        param.put("time", time);
-
-        String signStr = "key=355b7f07125c1ef71cfd10166e0b90aa&msgId=" + msgId + "&strRan=" + strRan + "&time=" + time;
-
-        System.out.println("加密字符串 : " + signStr);
-
-
-        param.put("sign", CpCallServiceImpl.MD5(signStr));
-
-//        param.put("serverid", 226);
-        param.put("serverid", 668);
-        List<String> roleIds = new ArrayList<>();
-//        roleIds.add("798136461189027272");
-        roleIds.add("821112073166082222");
-        param.put("roleIds", roleIds);
-
-        param.put("pushType", 1);
-
-        String text = "尊敬的尊享玩家“角色名”:\n" +
-                "叮,尊享管家小诗正在微信上等待与您的见面,根据您的游戏角色成长,小诗特意为您定制一份战力快速升级的攻略和几个尊享限定礼包,助您快速提升~\n" +
-                "您要尽快通过游戏内“联系客服”按钮与我联系,时间有限,请您尽快与我联系哦。\n" +
-                "联系时请您带上此页面截图,同时请您保密勿将此内容分享给其他玩家,可能会导致尊享限定礼包被冒领哦!";
-        Map<String, Object> msgContent = new HashMap<>();
-        msgContent.put("text", text);
-
-        List<String> imgs = new ArrayList<>();
-        //图片地址弄一张最小的, CP方不会用, 有默认底图
-        imgs.add("https://manage.84game.cn/image/WechatIMG56.jpeg");
-        msgContent.put("imgs", JsonUtil.toString(imgs));
-
-        param.put("msgContent", msgContent);
-
-        System.out.println("接口参数 param :" + JsonUtil.toString(param));
-
-        HttpHeaders headers = new HttpHeaders();
-        headers.setContentType(MediaType.APPLICATION_JSON);
-        headers.set(HttpHeaders.ACCEPT_CHARSET, "UTF-8");
-
-        HttpEntity<String> request = new HttpEntity<>(JsonUtil.toString(param), headers);
-
-        String result = restTemplate.postForObject(url, request, String.class);
-
-        System.out.println("返回结果" + result);
-    }
-
-    /**
-     * MD5加密
-     *
-     * @param data 待处理数据
-     * @return MD5结果
-     */
-    public static String MD5(String data) throws Exception {
-        java.security.MessageDigest md = MessageDigest.getInstance(SIGN_MD5);
-        byte[] array = md.digest(data.getBytes(StandardCharsets.UTF_8));
-        StringBuilder sb = new StringBuilder();
-        for (byte item : array) {
-            sb.append(Integer.toHexString((item & 0xFF) | 0x100), 1, 3);
-        }
-        return sb.toString();
-    }
-}

+ 1 - 0
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/CpSendMsgLogServiceImpl.java

@@ -92,6 +92,7 @@ public class CpSendMsgLogServiceImpl extends ServiceImpl<CpSendMsgLogMapper, CpS
                 .successCount(0L)
                 .failCount(0L)
                 .createTime(LocalDateTime.now())
+                .updateTime(LocalDateTime.now())
                 .build();
     }
 

+ 11 - 8
game-module/game-module-manage/src/main/java/com/zanxiang/game/module/manage/service/impl/GameServerServiceImpl.java

@@ -81,6 +81,9 @@ public class GameServerServiceImpl extends ServiceImpl<GameServerMapper, GameSer
     }
 
     private void gameServerAssign(GameServerAssignParam param, GameServer gameServer) {
+        if (Objects.equals(gameServer.getIsSourceServer(), Boolean.FALSE)) {
+            return;
+        }
         //老的指派人员id
         String oldUserIds = null;
         if (Objects.equals(param.getAssignType(), GameServerAssignEnum.GAME_SERVER_ASSIGN_GS)) {
@@ -307,6 +310,14 @@ public class GameServerServiceImpl extends ServiceImpl<GameServerMapper, GameSer
         gameServerListVO.setGameName(gameSupper == null ? null : gameSupper.getName());
         //原始区服, 直接返回
         if (Objects.equals(gameServer.getIsSourceServer(), Boolean.TRUE)) {
+            //指派客服
+            if (Strings.isNotBlank(gameServer.getCustomerIds())) {
+                gameServerListVO.setCustomerList(this.getUserBeanList(gameServer.getCustomerIds()));
+            }
+            //指派GS
+            if (Strings.isNotBlank(gameServer.getGsIds())) {
+                gameServerListVO.setGsList(this.getUserBeanList(gameServer.getGsIds()));
+            }
             return gameServerListVO;
         }
         //合服
@@ -342,14 +353,6 @@ public class GameServerServiceImpl extends ServiceImpl<GameServerMapper, GameSer
         if (sourceServerIdArray != null) {
             gameServerListVO.setSourceServerList(this.getSourceServerList(sourceServerIdArray, gameServerMap));
         }
-        //指派客服
-        if (Strings.isNotBlank(gameServer.getCustomerIds())) {
-            gameServerListVO.setCustomerList(this.getUserBeanList(gameServer.getCustomerIds()));
-        }
-        //指派GS
-        if (Strings.isNotBlank(gameServer.getGsIds())) {
-            gameServerListVO.setGsList(this.getUserBeanList(gameServer.getGsIds()));
-        }
         return gameServerListVO;
     }
 

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

@@ -14,7 +14,7 @@ import com.zanxiang.game.module.manage.utils.RedisUtil;
 import com.zanxiang.game.module.mybatis.entity.KfRoom;
 import com.zanxiang.game.module.mybatis.entity.KfRoomMsg;
 import com.zanxiang.game.module.mybatis.entity.KfSessionUser;
-import com.zanxiang.module.redis.service.IDistributedLockComponent;
+import com.zanxiang.game.module.mybatis.entity.KfSystemReply;
 import com.zanxiang.module.util.JsonUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.logging.log4j.util.Strings;
@@ -27,10 +27,7 @@ import reactor.util.function.Tuple2;
 
 import java.io.IOException;
 import java.time.LocalDateTime;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
 
 /**
  * @author : lingfeng
@@ -55,7 +52,10 @@ public class KfMsgWebsocketHandler implements WebSocketHandler {
     private IKfRoomMsgService kfRoomMsgService;
 
     @Autowired
-    private IDistributedLockComponent distributedLockComponent;
+    private IKfSystemReplyService kfSystemReplyService;
+
+    @Autowired
+    private KfWxApiService kfWxApiService;
 
     @Autowired
     private KfWxApiService wxApiService;
@@ -434,6 +434,47 @@ public class KfMsgWebsocketHandler implements WebSocketHandler {
                 .gameId(param.getGameId())
                 .waitUserList(waitUserList)
                 .build());
+        //发送欢迎语
+        this.sendWelcomeMsg(param.getGameId(), param.getOpenId(), roomId, kfSessionUser.getUserId());
+    }
+
+    private void sendWelcomeMsg(Long gameId, String openId, Long roomId, Long userId) {
+        //获取自动回复配置
+        KfSystemReply kfSystemReply = kfSystemReplyService.getById(gameId);
+        if (kfSystemReply == null || Strings.isBlank(kfSystemReply.getWorkSysReply())) {
+            return;
+        }
+        //休息时间, 发送指定消息
+        Map<String, Object> textMap = new HashMap<>(1);
+        textMap.put("content", kfSystemReply.getWorkSysReply());
+        Map<String, Object> msgParamMap = new HashMap<>(3);
+        msgParamMap.put("touser", openId);
+        msgParamMap.put("text", textMap);
+        msgParamMap.put("msgtype", KfRoomMsgTypeEnum.KF_MSG_TYPE_TEXT.getValue());
+        kfWxApiService.sendCustomMessageApi(gameId, msgParamMap);
+        //保存消息
+        Map<String, Object> kfRoomMsgMap = new HashMap<>(1);
+        kfRoomMsgMap.put("text", kfSystemReply.getWorkSysReply());
+        kfRoomMsgService.save(this.transform(openId, gameId, roomId, userId, JsonUtil.toString(kfRoomMsgMap)));
+    }
+
+    private KfRoomMsg transform(String openId, Long gameId, Long roomId, Long userId, String msgContent) {
+        return KfRoomMsg.builder()
+                .msgId(UUID.randomUUID().toString().replace("-", ""))
+                .msgType(KfRoomMsgTypeEnum.KF_MSG_TYPE_TEXT.getValue())
+                .gameId(gameId)
+                .openId(openId)
+                .userId(userId)
+                .readStatus(Boolean.TRUE)
+                .roomId(roomId)
+                .kfUserId(SecurityUtil.getUserId())
+                .msgOwner(KfRoomMsgOwnerEnum.KF_MSG_OWNER_SYSTEM.getValue())
+                .content(msgContent)
+                .source(msgContent)
+                .sortTime(System.currentTimeMillis())
+                .createTime(LocalDateTime.now())
+                .updateTime(LocalDateTime.now())
+                .build();
     }
 
     private void kfCreateConnect(WebSocketSession session, KfWebSocketMsgEnum msgTypeEnum, Long gameId) {

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

@@ -32,10 +32,15 @@ public class KfSystemReply {
     private String appId;
 
     /**
-     * 回复
+     * 下班回复
      */
     private String sysReply;
 
+    /**
+     * 上班回复
+     */
+    private String workSysReply;
+
     /**
      * 开始时间
      */