|
|
@ -57,10 +57,10 @@ public class ClientService implements IClientService { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public ClientVo.Join join(ClientDto.Join join, Long userId){ |
|
|
|
public ClientVo.Join join(ClientDto.Join join, Long userId) { |
|
|
|
log.info("加入游戏:{}, userId:{}", join, userId); |
|
|
|
|
|
|
|
int timeMore = (int)(join.getLocalTime() - System.currentTimeMillis()); |
|
|
|
int timeMore = (int) (join.getLocalTime() - System.currentTimeMillis()); |
|
|
|
log.info("{}时间差:{}", userId, timeMore); |
|
|
|
//获取游戏信息
|
|
|
|
GameRecord gameRecord = screenService.getGameRecord(join.getUrlId()); |
|
|
@ -83,7 +83,7 @@ public class ClientService implements IClientService { |
|
|
|
// 已加入
|
|
|
|
if (CollectionUtil.isNotEmpty(gameUserJoins)) { |
|
|
|
//查询结果,返回对应的信息
|
|
|
|
return joinResult(gameUserJoins.get(0), gameRecord,isGroup,join.getGroupId()); |
|
|
|
return joinResult(gameUserJoins.get(0), gameRecord, isGroup, join.getGroupId()); |
|
|
|
} |
|
|
|
|
|
|
|
//游戏已结束
|
|
|
@ -113,38 +113,38 @@ public class ClientService implements IClientService { |
|
|
|
userJoin.setLocalEndTime(prepare || processing ? gameRecord.getEndTime() + timeMore : 0); |
|
|
|
// 获取头像和用户名
|
|
|
|
JsonResponse<MemberVo.MemberInfo> memberInfo = tallFeignClient.getMemberByUserId(userId, join.getProjectId()); |
|
|
|
if(memberInfo.getData() == null){ |
|
|
|
if (memberInfo.getData() == null) { |
|
|
|
memberInfo = tallFeignClient.getUserByUserId(userId); |
|
|
|
} |
|
|
|
if (memberInfo.getCode().intValue() == CodeEnum.SUCCESS.getCode() && memberInfo.getData() != null) { |
|
|
|
userJoin.setAvatarUrl(memberInfo.getData().getAvatarUrl()); |
|
|
|
userJoin.setNickname(memberInfo.getData().getNickname()); |
|
|
|
|
|
|
|
if(StrUtil.isNotEmpty(memberInfo.getData().getNickname())){ |
|
|
|
if (StrUtil.isNotEmpty(memberInfo.getData().getNickname())) { |
|
|
|
userJoin.setNickname(memberInfo.getData().getNickname()); |
|
|
|
}else { |
|
|
|
if(StrUtil.isNotEmpty(memberInfo.getData().getPhone())){ |
|
|
|
} else { |
|
|
|
if (StrUtil.isNotEmpty(memberInfo.getData().getPhone())) { |
|
|
|
String phone = memberInfo.getData().getPhone(); |
|
|
|
String phoneNumber = phone.substring(0, 3) + "****" + phone.substring(7, phone.length()); |
|
|
|
userJoin.setNickname(phoneNumber); |
|
|
|
}else { |
|
|
|
} else { |
|
|
|
userJoin.setNickname(""); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(StrUtil.isNotEmpty(memberInfo.getData().getAvatarUrl())){ |
|
|
|
if (StrUtil.isNotEmpty(memberInfo.getData().getAvatarUrl())) { |
|
|
|
userJoin.setAvatarUrl(memberInfo.getData().getAvatarUrl()); |
|
|
|
}else { |
|
|
|
} else { |
|
|
|
userJoin.setAvatarUrl(""); |
|
|
|
} |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
userJoin.setAvatarUrl(""); |
|
|
|
userJoin.setNickname(""); |
|
|
|
} |
|
|
|
gameUserJoinDao.insertSelective(userJoin); |
|
|
|
//如果是分组游戏,则添加用户与组的关联表
|
|
|
|
if(isGroup){ |
|
|
|
if(ObjectUtil.isNotNull(join.getGroupId())){ |
|
|
|
//如果是分组游戏,则添加用户与组的关联表并添加redis
|
|
|
|
if (isGroup) { |
|
|
|
if (ObjectUtil.isNull(join.getGroupId())) { |
|
|
|
log.info("分组信息为空"); |
|
|
|
throw new BaseException(CodeEnum.PARAM_ERROR); |
|
|
|
} |
|
|
@ -153,16 +153,15 @@ public class ClientService implements IClientService { |
|
|
|
userJoinGroup.setUserJoinId(userJoin.getId()); |
|
|
|
userJoinGroup.setGameGroupId(join.getGroupId()); |
|
|
|
userJoinGroupDao.insertSelective(userJoinGroup); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 3.更新redis(sort set key:分数 value:头像,姓名)
|
|
|
|
if (prepare || processing) { |
|
|
|
ClientDto.RedisUser user = ClientDto.RedisUser.getInstance(userJoin); |
|
|
|
redisUtil.zsSet(GameConstant.generateGameKey(gameRecord.getId()), JSON.toJSONString(user), 0, GameConstant.REDIS_TIME); |
|
|
|
} |
|
|
|
|
|
|
|
//5.返回状态
|
|
|
|
return joinResult(userJoin, gameRecord,isGroup,join.getGroupId()); |
|
|
|
return joinResult(userJoin, gameRecord, isGroup, join.getGroupId()); |
|
|
|
} |
|
|
|
|
|
|
|
// private ClientVo.Join joinResultWithGroup(ClientDto.Join join, Long userId, GameRecord gameRecord ){
|
|
|
@ -178,11 +177,14 @@ public class ClientService implements IClientService { |
|
|
|
//
|
|
|
|
// }
|
|
|
|
|
|
|
|
private ClientVo.Join joinResult(GameUserJoin join, GameRecord gameRecord,Boolean isGroup,Long groupId){ |
|
|
|
private ClientVo.Join joinResult(GameUserJoin join, GameRecord gameRecord, Boolean isGroup, Long groupId) { |
|
|
|
ClientVo.Join joinVo = initStatusAndCount(gameRecord); |
|
|
|
if(isGroup && ObjectUtil.isNotNull(groupId)){ |
|
|
|
if (isGroup && ObjectUtil.isNotNull(groupId)) { |
|
|
|
//获取分组的信息
|
|
|
|
GameGroup gameGroup = gameGroupDao.selectByPrimaryKey(groupId); |
|
|
|
if (ObjectUtil.isNull(gameGroup)) { |
|
|
|
throw new BaseException(CodeEnum.PARAM_ERROR); |
|
|
|
} |
|
|
|
ClientVo.Group group = new ClientVo.Group(); |
|
|
|
group.setGroupId(gameGroup.getId()); |
|
|
|
group.setGroupName(gameGroup.getName()); |
|
|
@ -191,49 +193,52 @@ public class ClientService implements IClientService { |
|
|
|
} |
|
|
|
|
|
|
|
switch (gameRecord.getGameStatus()) { |
|
|
|
case GameConstant.GAME_PENDING : |
|
|
|
case GameConstant.GAME_PENDING: |
|
|
|
// 未开始
|
|
|
|
joinVo.setPendingData(new ClientVo.PendingData()); |
|
|
|
break; |
|
|
|
case GameConstant.GAME_PREPARATION : |
|
|
|
case GameConstant.GAME_PREPARATION: |
|
|
|
// 准备中
|
|
|
|
ClientVo.PreparingData preparingData = new ClientVo.PreparingData(); |
|
|
|
preparingData.setStartLocalTime(join.getLocalStartTime() + join.getTimeDifference()); |
|
|
|
preparingData.setEndLocalTime(join.getLocalEndTime() + join.getTimeDifference()); |
|
|
|
joinVo.setPreparingData(preparingData); |
|
|
|
break; |
|
|
|
case GameConstant.GAME_PROCESSING : |
|
|
|
case GameConstant.GAME_PROCESSING: |
|
|
|
// 进行中
|
|
|
|
ClientVo.ProcessingData processingData = new ClientVo.ProcessingData(); |
|
|
|
processingData.setStartLocalTime(join.getLocalStartTime()); |
|
|
|
processingData.setEndLocalTime(join.getLocalEndTime()); |
|
|
|
joinVo.setProcessingData(processingData); |
|
|
|
break; |
|
|
|
case GameConstant.GAME_COMPLETED : |
|
|
|
case GameConstant.GAME_COMPLETED: |
|
|
|
//已结束
|
|
|
|
ClientVo.CompletedData completedData = new ClientVo.CompletedData(); |
|
|
|
completedData.setTimes(join.getTimes()); |
|
|
|
completedData.setScore(join.getScore()); |
|
|
|
Integer sort = gameUserJoinDao.getRanking(join.getUserId(), gameRecord.getId()); |
|
|
|
if(ObjectUtil.isNotNull(sort)){ |
|
|
|
if (ObjectUtil.isNotNull(sort)) { |
|
|
|
completedData.setSort(sort); |
|
|
|
}else { |
|
|
|
} else { |
|
|
|
completedData.setSort(1); |
|
|
|
} |
|
|
|
int low = gameUserJoinDao.overNum(gameRecord.getId(), join.getScore()); |
|
|
|
GameUserJoinExample joinExample = new GameUserJoinExample(); |
|
|
|
joinExample.createCriteria().andRecordIdEqualTo(gameRecord.getId()); |
|
|
|
long count = gameUserJoinDao.countByExample(joinExample); |
|
|
|
completedData.setOver((int) (low * 100/count)); |
|
|
|
completedData.setOver((int) (low * 100 / count)); |
|
|
|
joinVo.setCompletedData(completedData); |
|
|
|
break; |
|
|
|
default: break; |
|
|
|
default: |
|
|
|
break; |
|
|
|
} |
|
|
|
log.info("参加游戏:{}", joinVo); |
|
|
|
return joinVo; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 设置状态和总人数 |
|
|
|
* |
|
|
|
* @param gameRecord |
|
|
|
*/ |
|
|
|
private ClientVo.Join initStatusAndCount(GameRecord gameRecord) { |
|
|
@ -289,8 +294,10 @@ public class ClientService implements IClientService { |
|
|
|
//
|
|
|
|
// return rankingAll;
|
|
|
|
// }
|
|
|
|
|
|
|
|
/** |
|
|
|
* 查询总排名表 |
|
|
|
* |
|
|
|
* @param params |
|
|
|
* @return |
|
|
|
*/ |
|
|
@ -306,7 +313,7 @@ public class ClientService implements IClientService { |
|
|
|
GameUserJoinExample userJoinExample = new GameUserJoinExample(); |
|
|
|
userJoinExample.createCriteria().andRecordIdEqualTo(gatRanking.getRecordId()); |
|
|
|
List<GameUserJoin> userJoinList = gameUserJoinDao.selectByExample(userJoinExample); |
|
|
|
totalMembers = userJoinList == null ? 0 : (long)userJoinList.size(); |
|
|
|
totalMembers = userJoinList == null ? 0 : (long) userJoinList.size(); |
|
|
|
} |
|
|
|
rankingAll.setTotalMembers(totalMembers.intValue()); |
|
|
|
|
|
|
@ -318,13 +325,13 @@ public class ClientService implements IClientService { |
|
|
|
if (CollectionUtil.isNotEmpty(typedTuples)) { |
|
|
|
List<ClientVo.MemberInfo> finalMemberInfo = memberInfo; |
|
|
|
typedTuples.forEach(type -> { |
|
|
|
ClientDto.RedisUser user = JSON.parseObject((String)type.getValue(), ClientDto.RedisUser.class); |
|
|
|
ClientDto.RedisUser user = JSON.parseObject((String) type.getValue(), ClientDto.RedisUser.class); |
|
|
|
ClientVo.MemberInfo info = new ClientVo.MemberInfo(); |
|
|
|
info.setId(user.getId()); |
|
|
|
info.setHeadImgUrl(user.getAvatarUrl()); |
|
|
|
info.setNickname(user.getNickname()); |
|
|
|
info.setScore(type.getScore().intValue()); |
|
|
|
info.setTimes(type.getScore().intValue()/100); |
|
|
|
info.setTimes(type.getScore().intValue() / 100); |
|
|
|
Long sort = redisUtil.zsReverseRank(userKey, type.getValue()); |
|
|
|
info.setSort(sort == null ? 1 : sort.intValue()); |
|
|
|
finalMemberInfo.add(info); |
|
|
@ -344,20 +351,21 @@ public class ClientService implements IClientService { |
|
|
|
|
|
|
|
/** |
|
|
|
* 滑动时添加记录 |
|
|
|
* |
|
|
|
* @param userId |
|
|
|
* @param recordId |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public GameMessageCountOut clientAddTimes(String userId,String recordId) { |
|
|
|
public GameMessageCountOut clientAddTimes(String userId, String recordId) { |
|
|
|
GameMessageCountOut gameMessageCountOut = new GameMessageCountOut(); |
|
|
|
log.info("userId:{}", userId); |
|
|
|
if(ObjectUtil.isNotNull(userId)){ |
|
|
|
if (ObjectUtil.isNotNull(userId)) { |
|
|
|
GameUserJoinExample gameUserJoinExample = new GameUserJoinExample(); |
|
|
|
gameUserJoinExample.createCriteria().andUserIdEqualTo(Long.valueOf(userId)).andRecordIdEqualTo(Long.valueOf(recordId)); |
|
|
|
List<GameUserJoin> userJoinList = gameUserJoinDao.selectByExample(gameUserJoinExample); |
|
|
|
log.info("游戏对象:{}", userJoinList); |
|
|
|
if(CollectionUtil.isNotEmpty(userJoinList)){ |
|
|
|
if (CollectionUtil.isNotEmpty(userJoinList)) { |
|
|
|
GameUserJoin userJoin = userJoinList.get(0); |
|
|
|
userJoin.setTimes(userJoin.getTimes() + 1); |
|
|
|
userJoin.setScore(userJoin.getScore() + 100); |
|
|
@ -365,9 +373,9 @@ public class ClientService implements IClientService { |
|
|
|
gameUserJoinDao.updateByPrimaryKeySelective(userJoin); |
|
|
|
//更新redis
|
|
|
|
ClientDto.RedisUser user = ClientDto.RedisUser.getInstance(userJoin); |
|
|
|
log.info("游戏id:{}, 对象:{}, 分数:{}", recordId, user,userJoin.getScore()); |
|
|
|
log.info("游戏id:{}, 对象:{}, 分数:{}", recordId, user, userJoin.getScore()); |
|
|
|
redisUtil.zsSet(GameConstant.generateGameKey(Long.parseLong(recordId)), JSON.toJSONString(user), userJoin.getScore(), GameConstant.REDIS_TIME); |
|
|
|
gameMessageCountOut = new GameMessageCountOut(userJoin.getTimes(),userJoin.getScore()); |
|
|
|
gameMessageCountOut = new GameMessageCountOut(userJoin.getTimes(), userJoin.getScore()); |
|
|
|
} |
|
|
|
} |
|
|
|
return gameMessageCountOut; |
|
|
|