瀏覽代碼

fix : 欢迎语修改

bilingfeng 1 年之前
父節點
當前提交
f95ab88654

+ 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" +

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

@@ -137,7 +137,7 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
             kfRoomMsgService.save(kfRoomMsg);
             return;
         }
-        //发送自动回复
+        //客服休息时间, 发送自动回复
         this.systemReplyHandle(gameApplet.getGameId(), kfAppletMsgDTO.getFromUserName(), kfRoom);
         //消息报警监测
         this.monitorWordHandle(gameApplet, kfAppletMsgDTO);
@@ -188,11 +188,12 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
         LocalTime nowTime = LocalTime.now();
         LocalTime startTime = LocalTime.parse(kfSystemReply.getStartTime());
         LocalTime endTime = LocalTime.parse(kfSystemReply.getEndTime());
-        //判断要发送的消息内容
-        String content = nowTime.isAfter(startTime) && nowTime.isBefore(endTime) ? kfSystemReply.getWorkSysReply() : kfSystemReply.getSysReply();
-        //发送消息
+        if (nowTime.isAfter(startTime) && nowTime.isBefore(endTime)) {
+            return;
+        }
+        //休息时间, 发送指定消息
         Map<String, Object> textMap = new HashMap<>(1);
-        textMap.put("content", content);
+        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());
@@ -200,7 +201,7 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
         kfWxApiService.sendCustomMessageApi(gameId, msgParamMap);
         //保存消息
         Map<String, Object> kfRoomMsgMap = new HashMap<>(1);
-        kfRoomMsgMap.put("text", content);
+        kfRoomMsgMap.put("text", kfSystemReply.getSysReply());
         kfRoomMsgService.save(this.transform(openId, gameId, kfRoom, KfRoomMsgTypeEnum.KF_MSG_TYPE_TEXT, JsonUtil.toString(kfRoomMsgMap)));
     }
 

+ 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) {