|
@@ -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())
|
|
@@ -151,7 +161,9 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
|
|
|
.set(KfSessionUser::getIsWait, Boolean.TRUE)
|
|
|
.set(KfSessionUser::getWaitStartTime, LocalDateTime.now())
|
|
|
.set(KfSessionUser::getUpdateTime, LocalDateTime.now())
|
|
|
- .eq(KfSessionUser::getOpenId, kfAppletMsgDTO.getFromUserName()));
|
|
|
+ .eq(KfSessionUser::getOpenId, kfAppletMsgDTO.getFromUserName())
|
|
|
+ .eq(KfSessionUser::getGameId, gameApplet.getGameId())
|
|
|
+ );
|
|
|
}
|
|
|
//消息转发到redis频道
|
|
|
this.pushMessage(this.transform(kfRoom, gameApplet.getGameId(), kfAppletMsgDTO.getFromUserName(), kfRoomMsg, msgContent));
|
|
@@ -187,7 +199,7 @@ public class KfAppletMsgServiceImpl implements IKfAppletMsgService {
|
|
|
return;
|
|
|
}
|
|
|
//查询玩家信息
|
|
|
- KfSessionUser kfSessionUser = kfSessionUserService.getById(openId);
|
|
|
+ KfSessionUser kfSessionUser = kfSessionUserService.getById(openId, gameId);
|
|
|
//判断是否开启充值自动回复
|
|
|
if (Objects.equals(kfSystemReply.getRechargeReplySwitch(), Boolean.TRUE)) {
|
|
|
//查询订单
|
|
@@ -321,7 +333,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,19 +349,28 @@ 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())
|
|
|
+ .eq(KfSessionUser::getGameId, gameApplet.getGameId())
|
|
|
+ ) <= 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()));
|
|
|
+ .eq(KfSessionUser::getOpenId, kfAppletMsgDTO.getFromUserName())
|
|
|
+ .eq(KfSessionUser::getGameId, gameApplet.getGameId())
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
private KfSessionUser transform(KfAppletMsgDTO kfAppletMsgDTO, GameApplet gameApplet, User user, GameUserRole gameUserRole) {
|