|
@@ -6,10 +6,7 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
import com.zanxiang.erp.security.util.SecurityUtil;
|
|
import com.zanxiang.erp.security.util.SecurityUtil;
|
|
import com.zanxiang.game.back.base.pojo.enums.OrderStatusEnum;
|
|
import com.zanxiang.game.back.base.pojo.enums.OrderStatusEnum;
|
|
import com.zanxiang.game.module.manage.constant.RedisKeyConstant;
|
|
import com.zanxiang.game.module.manage.constant.RedisKeyConstant;
|
|
-import com.zanxiang.game.module.manage.enums.KfRoomMsgOwnerEnum;
|
|
|
|
-import com.zanxiang.game.module.manage.enums.KfRoomMsgTypeEnum;
|
|
|
|
-import com.zanxiang.game.module.manage.enums.KfWebSocketMsgEnum;
|
|
|
|
-import com.zanxiang.game.module.manage.enums.OrderStateEnum;
|
|
|
|
|
|
+import com.zanxiang.game.module.manage.enums.*;
|
|
import com.zanxiang.game.module.manage.pojo.dto.KfAppletMsgDTO;
|
|
import com.zanxiang.game.module.manage.pojo.dto.KfAppletMsgDTO;
|
|
import com.zanxiang.game.module.manage.pojo.dto.KfWebSocketMsgDTO;
|
|
import com.zanxiang.game.module.manage.pojo.dto.KfWebSocketMsgDTO;
|
|
import com.zanxiang.game.module.manage.pojo.dto.PayApplicationDTO;
|
|
import com.zanxiang.game.module.manage.pojo.dto.PayApplicationDTO;
|
|
@@ -110,9 +107,18 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
|
|
@Autowired
|
|
@Autowired
|
|
private IDistributedLockComponent distributedLockComponent;
|
|
private IDistributedLockComponent distributedLockComponent;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private IKfAppletReplyService kfAppletReplyService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private IUserAppletService userAppletService;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void appletMsg(String postData) {
|
|
public void appletMsg(String postData) {
|
|
|
|
+ log.error("接收到客服消息, postData : {}", postData);
|
|
KfAppletMsgDTO kfAppletMsgDTO = JsonUtil.toObj(postData, KfAppletMsgDTO.class);
|
|
KfAppletMsgDTO kfAppletMsgDTO = JsonUtil.toObj(postData, KfAppletMsgDTO.class);
|
|
|
|
+ log.error("接收到客服消息, kfAppletMsgDTO : {}", JsonUtil.toString(kfAppletMsgDTO));
|
|
|
|
+ log.error("SessionFrom : {}", kfAppletMsgDTO.getSessionFrom());
|
|
GameApplet gameApplet = gameAppletService.getOne(new LambdaQueryWrapper<GameApplet>()
|
|
GameApplet gameApplet = gameAppletService.getOne(new LambdaQueryWrapper<GameApplet>()
|
|
.eq(GameApplet::getGhId, kfAppletMsgDTO.getToUserName()));
|
|
.eq(GameApplet::getGhId, kfAppletMsgDTO.getToUserName()));
|
|
//小游戏信息不存在, 消息不处理
|
|
//小游戏信息不存在, 消息不处理
|
|
@@ -155,6 +161,8 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
|
|
}
|
|
}
|
|
//客服休息时间, 发送自动回复
|
|
//客服休息时间, 发送自动回复
|
|
this.systemReplyHandle(gameApplet.getGameId(), kfAppletMsgDTO.getFromUserName(), kfRoom);
|
|
this.systemReplyHandle(gameApplet.getGameId(), kfAppletMsgDTO.getFromUserName(), kfRoom);
|
|
|
|
+ //小程序自动回复
|
|
|
|
+ this.appletReplyHandle(gameApplet.getGameId(), kfAppletMsgDTO.getFromUserName(), kfRoom, gameApplet.getAppId());
|
|
//消息报警监测
|
|
//消息报警监测
|
|
this.monitorWordHandle(gameApplet, kfAppletMsgDTO);
|
|
this.monitorWordHandle(gameApplet, kfAppletMsgDTO);
|
|
//保存房间消息
|
|
//保存房间消息
|
|
@@ -165,6 +173,7 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
|
|
.set(KfSessionUser::getIsWait, Boolean.TRUE)
|
|
.set(KfSessionUser::getIsWait, Boolean.TRUE)
|
|
.set(KfSessionUser::getWaitStartTime, LocalDateTime.now())
|
|
.set(KfSessionUser::getWaitStartTime, LocalDateTime.now())
|
|
.set(KfSessionUser::getUpdateTime, LocalDateTime.now())
|
|
.set(KfSessionUser::getUpdateTime, LocalDateTime.now())
|
|
|
|
+ .isNull(KfSessionUser::getSessionFrom)
|
|
.eq(KfSessionUser::getOpenId, kfAppletMsgDTO.getFromUserName())
|
|
.eq(KfSessionUser::getOpenId, kfAppletMsgDTO.getFromUserName())
|
|
.eq(KfSessionUser::getGameId, gameApplet.getGameId())
|
|
.eq(KfSessionUser::getGameId, gameApplet.getGameId())
|
|
);
|
|
);
|
|
@@ -173,6 +182,72 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
|
|
this.pushMessage(this.transform(kfRoom, gameApplet.getGameId(), kfAppletMsgDTO.getFromUserName(), kfRoomMsg, msgContent));
|
|
this.pushMessage(this.transform(kfRoom, gameApplet.getGameId(), kfAppletMsgDTO.getFromUserName(), kfRoomMsg, msgContent));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void appletReplyHandle(Long gameId, String openId, KfRoom kfRoom, String appId) {
|
|
|
|
+ //玩家信息
|
|
|
|
+ KfSessionUser kfSessionUser = kfSessionUserService.getById(openId, gameId);
|
|
|
|
+ //来源类型
|
|
|
|
+ KfSessionFromEnum kfSessionFrom = KfSessionFromEnum.getKfSessionFrom(kfSessionUser.getSessionFrom());
|
|
|
|
+ if (kfSessionFrom == null) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ //获取自动回复配置
|
|
|
|
+ KfAppletReply kfAppletReply = kfAppletReplyService.getById(gameId);
|
|
|
|
+ if (kfAppletReply == null) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ //判断是否来源与平台
|
|
|
|
+ if (Objects.equals(kfSessionFrom, KfSessionFromEnum.KF_SESSION_FROM_PLATFORM)) {
|
|
|
|
+ //回复默认消息
|
|
|
|
+ if (Strings.isNotBlank(kfAppletReply.getReplyDefault())) {
|
|
|
|
+ this.sysMsgSend(gameId, openId, kfAppletReply.getReplyDefault(), kfRoom);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //判断是否来源于广告
|
|
|
|
+ if (Objects.equals(kfSessionFrom, KfSessionFromEnum.KF_SESSION_FROM_AD)) {
|
|
|
|
+ //存在文本消息发送
|
|
|
|
+ if (Strings.isNotBlank(kfAppletReply.getReplyText())) {
|
|
|
|
+ this.sysMsgSend(gameId, openId, kfAppletReply.getReplyText(), kfRoom);
|
|
|
|
+ }
|
|
|
|
+ //存在图片发送
|
|
|
|
+ if (Strings.isNotBlank(kfAppletReply.getReplyImg())) {
|
|
|
|
+ this.sysImgMsgSend(gameId, openId, kfAppletReply.getReplyImg(), kfRoom);
|
|
|
|
+ }
|
|
|
|
+ //存在链接发送
|
|
|
|
+ if (Strings.isNotBlank(kfAppletReply.getReplyLink())) {
|
|
|
|
+ //链接消息参数转换
|
|
|
|
+ Map<String, String> linkMap = JsonUtil.toMap(kfAppletReply.getReplyLink(), Map.class, String.class);
|
|
|
|
+ String url = linkMap.get("url");
|
|
|
|
+ //链接拼接短链id
|
|
|
|
+ if (Strings.isNotBlank(url)) {
|
|
|
|
+ UserApplet userApplet = userAppletService.getOne(new LambdaQueryWrapper<UserApplet>()
|
|
|
|
+ .eq(UserApplet::getAppId, appId)
|
|
|
|
+ .eq(UserApplet::getOpenId, openId)
|
|
|
|
+ .orderByDesc(UserApplet::getCreateTime)
|
|
|
|
+ .last("limit 1"));
|
|
|
|
+ if (userApplet != null) {
|
|
|
|
+ linkMap.put("url", url + "?customer_channel=" + userApplet.getId());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ this.sysLinkMsgSend(gameId, openId, kfRoom, linkMap);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void sysLinkMsgSend(Long gameId, String openId, KfRoom kfRoom, Map<String, String> linkMap) {
|
|
|
|
+ //发送消息
|
|
|
|
+ Map<String, Object> msgParamMap = new HashMap<>(3);
|
|
|
|
+ msgParamMap.put("touser", openId);
|
|
|
|
+ msgParamMap.put("link", linkMap);
|
|
|
|
+ msgParamMap.put("msgtype", KfRoomMsgTypeEnum.KF_MSG_TYPE_LINK.getValue());
|
|
|
|
+ Tuple2<Long, String> tuple2 = kfWxApiService.sendCustomMessageApi(gameId, msgParamMap);
|
|
|
|
+ //发送失败
|
|
|
|
+ if (!Objects.equals(tuple2.getT1(), 0L)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ //保存发送的支付链接消息
|
|
|
|
+ kfRoomMsgService.save(this.transform(openId, gameId, kfRoom, KfRoomMsgTypeEnum.KF_MSG_TYPE_LINK, JsonUtil.toString(msgParamMap)));
|
|
|
|
+ }
|
|
|
|
+
|
|
private void monitorWordHandle(GameApplet gameApplet, KfAppletMsgDTO kfAppletMsgDTO) {
|
|
private void monitorWordHandle(GameApplet gameApplet, KfAppletMsgDTO kfAppletMsgDTO) {
|
|
//非文本消息
|
|
//非文本消息
|
|
if (!Objects.equals(kfAppletMsgDTO.getMsgType(), KfRoomMsgTypeEnum.KF_MSG_TYPE_TEXT.getValue())) {
|
|
if (!Objects.equals(kfAppletMsgDTO.getMsgType(), KfRoomMsgTypeEnum.KF_MSG_TYPE_TEXT.getValue())) {
|
|
@@ -399,20 +474,22 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
//不存在角色信息, 不做更新
|
|
//不存在角色信息, 不做更新
|
|
- if (gameUserRole == null) {
|
|
|
|
|
|
+ if (user == null && Strings.isBlank(kfAppletMsgDTO.getSessionFrom())) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
//存在, 更新玩家信息
|
|
//存在, 更新玩家信息
|
|
kfSessionUserService.update(new LambdaUpdateWrapper<KfSessionUser>()
|
|
kfSessionUserService.update(new LambdaUpdateWrapper<KfSessionUser>()
|
|
- .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(user != null, KfSessionUser::getUserId, user == null ? null : user.getId())
|
|
|
|
+ .set(gameUserRole != null, KfSessionUser::getLastRoleId, gameUserRole == null ? null : gameUserRole.getRoleId())
|
|
|
|
+ .set(gameUserRole != null, KfSessionUser::getLastRoleName, gameUserRole == null ? null : gameUserRole.getRoleName())
|
|
|
|
+ .set(gameUserRole != null, KfSessionUser::getServerId, gameUserRole == null ? null : gameUserRole.getServerId())
|
|
|
|
+ .set(gameUserRole != null, KfSessionUser::getServerName, gameUserRole == null ? null : gameUserRole.getServerName())
|
|
|
|
+ .set(Strings.isNotBlank(kfAppletMsgDTO.getSessionFrom()), KfSessionUser::getSessionFrom, kfAppletMsgDTO.getSessionFrom())
|
|
.set(KfSessionUser::getUpdateTime, LocalDateTime.now())
|
|
.set(KfSessionUser::getUpdateTime, LocalDateTime.now())
|
|
.eq(KfSessionUser::getOpenId, kfAppletMsgDTO.getFromUserName())
|
|
.eq(KfSessionUser::getOpenId, kfAppletMsgDTO.getFromUserName())
|
|
.eq(KfSessionUser::getGameId, gameApplet.getGameId())
|
|
.eq(KfSessionUser::getGameId, gameApplet.getGameId())
|
|
);
|
|
);
|
|
|
|
+ distributedLockComponent.unlock(lockKey);
|
|
}
|
|
}
|
|
|
|
|
|
private KfSessionUser transform(KfAppletMsgDTO kfAppletMsgDTO, GameApplet gameApplet, User user, GameUserRole gameUserRole) {
|
|
private KfSessionUser transform(KfAppletMsgDTO kfAppletMsgDTO, GameApplet gameApplet, User user, GameUserRole gameUserRole) {
|
|
@@ -425,6 +502,7 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
|
|
.lastRoleName(gameUserRole == null ? "神秘人[未创角]" : gameUserRole.getRoleName())
|
|
.lastRoleName(gameUserRole == null ? "神秘人[未创角]" : gameUserRole.getRoleName())
|
|
.serverId(gameUserRole == null ? null : gameUserRole.getServerId())
|
|
.serverId(gameUserRole == null ? null : gameUserRole.getServerId())
|
|
.serverName(gameUserRole == null ? null : gameUserRole.getServerName())
|
|
.serverName(gameUserRole == null ? null : gameUserRole.getServerName())
|
|
|
|
+ .sessionFrom(kfAppletMsgDTO.getSessionFrom())
|
|
.createTime(LocalDateTime.now())
|
|
.createTime(LocalDateTime.now())
|
|
.updateTime(LocalDateTime.now())
|
|
.updateTime(LocalDateTime.now())
|
|
.build();
|
|
.build();
|