Browse Source

修改游戏推送参数

master
zhangye 5 years ago
parent
commit
cba9e46dc7
  1. 14
      game/src/main/java/com/ccsens/game/bean/dto/message/ChangeStatusMessageDto.java
  2. 15
      game/src/main/java/com/ccsens/game/bean/vo/ClientVo.java
  3. 4
      game/src/main/java/com/ccsens/game/bean/vo/ScreenVo.java
  4. 61
      game/src/main/java/com/ccsens/game/service/ClientService.java
  5. 8
      game/src/main/java/com/ccsens/game/service/IClientService.java
  6. 3
      game/src/main/java/com/ccsens/game/service/IScreenService.java
  7. 12
      game/src/main/java/com/ccsens/game/service/ScreenService.java
  8. 40
      game/src/main/java/com/ccsens/game/util/SendMsg.java

14
game/src/main/java/com/ccsens/game/bean/dto/message/ChangeStatusMessageDto.java

@ -1,5 +1,6 @@
package com.ccsens.game.bean.dto.message;
import com.ccsens.game.bean.vo.ClientVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ -42,6 +43,19 @@ public class ChangeStatusMessageDto {
private Integer sort;
@ApiModelProperty("超过百分之多少人")
private Integer over;
@ApiModelProperty("队伍分数信息")
private ClientVo.GroupScore groupScore;
}
@Data
@ApiModel
public static class GroupScore{
@ApiModelProperty("次数")
private Integer groupTimes;
@ApiModelProperty("分数")
private Integer groupScore;
@ApiModelProperty("排名次序")
private Integer groupSort;
}
}

15
game/src/main/java/com/ccsens/game/bean/vo/ClientVo.java

@ -71,9 +71,20 @@ public class ClientVo {
private Integer sort;
@ApiModelProperty("超过百分之多少人")
private Integer over;
@ApiModelProperty("是否是胜利组")
private Boolean isWin;
@ApiModelProperty("队伍分数信息")
private GroupScore groupScore;
}
@Data
@ApiModel
public static class GroupScore{
@ApiModelProperty("次数")
private Integer groupTimes;
@ApiModelProperty("分数")
private Integer groupScore;
@ApiModelProperty("排名次序")
private Integer groupSort;
}
@Data
@ApiModel("RankingAll")
public static class RankingAll{

4
game/src/main/java/com/ccsens/game/bean/vo/ScreenVo.java

@ -96,6 +96,10 @@ public class ScreenVo {
private int averageTimes;
@ApiModelProperty("平均次数超过百分之多少人")
private int over;
@ApiModelProperty("总人数")
private int totalMember;
@ApiModelProperty("获胜的队伍的名字")
private String winGroup;
@ApiModelProperty("前十名的信息")
private List<TopUsers> members;
}

61
game/src/main/java/com/ccsens/game/service/ClientService.java

@ -43,6 +43,8 @@ public class ClientService implements IClientService {
@Autowired
private GameUserJoinDao gameUserJoinDao;
@Autowired
private GameUserJoinGroupDao gameUserJoinGroupDao;
@Autowired
private GameGroupDao gameGroupDao;
@Autowired
private GameUserJoinGroupDao userJoinGroupDao;
@ -142,7 +144,7 @@ public class ClientService implements IClientService {
userJoin.setNickname("");
}
gameUserJoinDao.insertSelective(userJoin);
//如果是分组游戏,则添加用户与组的关联表并添加redis
//如果是分组游戏,则添加用户与组的关联表
if (isGroup) {
if (ObjectUtil.isNull(join.getGroupId())) {
log.info("分组信息为空");
@ -214,6 +216,11 @@ public class ClientService implements IClientService {
case GameConstant.GAME_COMPLETED:
//已结束
ClientVo.CompletedData completedData = new ClientVo.CompletedData();
//如果是分组游戏,获取本组信息
if(isGroup){
ClientVo.GroupScore groupScore = getGroupScore(groupId,gameRecord.getId());
completedData.setGroupScore(groupScore);
}
completedData.setTimes(join.getTimes());
completedData.setScore(join.getScore());
Integer sort = gameUserJoinDao.getRanking(join.getUserId(), gameRecord.getId());
@ -236,9 +243,59 @@ public class ClientService implements IClientService {
return joinVo;
}
/**
* 获取本组的信息
*/
@Override
public ClientVo.GroupScore getGroupScore(Long groupId,Long recordId){
ClientVo.GroupScore groupScore = new ClientVo.GroupScore();
int otherGroupScore = 0;
//查找所有队伍
GameGroupExample gameGroupExample = new GameGroupExample();
gameGroupExample.createCriteria().andRecordIdEqualTo(recordId);
List<GameGroup> gameGroupList = gameGroupDao.selectByExample(gameGroupExample);
if (CollectionUtil.isNotEmpty(gameGroupList)) {
for (GameGroup gameGroup : gameGroupList) {
if (gameGroup.getId().longValue() == groupId) {
//查找队伍的总分
GameUserJoinGroupExample joinGroupExample = new GameUserJoinGroupExample();
joinGroupExample.createCriteria().andGameGroupIdEqualTo(groupId);
List<GameUserJoinGroup> userJoinGroupList = gameUserJoinGroupDao.selectByExample(joinGroupExample);
if (CollectionUtil.isNotEmpty(userJoinGroupList)) {
int totalScore = 0;
int totalTimes = 0;
for (GameUserJoinGroup userJoinGroup : userJoinGroupList) {
GameUserJoin userJoin = gameUserJoinDao.selectByPrimaryKey(userJoinGroup.getUserJoinId());
totalScore += userJoin.getScore();
totalTimes += userJoin.getTimes();
}
groupScore.setGroupTimes(totalTimes);
groupScore.setGroupScore(totalScore);
}
}else {
GameUserJoinGroupExample joinGroupExample = new GameUserJoinGroupExample();
joinGroupExample.createCriteria().andGameGroupIdEqualTo(groupId);
List<GameUserJoinGroup> userJoinGroupList = gameUserJoinGroupDao.selectByExample(joinGroupExample);
if (CollectionUtil.isNotEmpty(userJoinGroupList)) {
for (GameUserJoinGroup userJoinGroup : userJoinGroupList) {
GameUserJoin userJoin = gameUserJoinDao.selectByPrimaryKey(userJoinGroup.getUserJoinId());
otherGroupScore += userJoin.getScore();
}
}
}
}
}
if(groupScore.getGroupScore() >= otherGroupScore){
groupScore.setGroupSort(1);
}else {
groupScore.setGroupSort(2);
}
return groupScore;
}
/**
* 设置状态和总人数
*
* @param gameRecord
*/
private ClientVo.Join initStatusAndCount(GameRecord gameRecord) {

8
game/src/main/java/com/ccsens/game/service/IClientService.java

@ -27,4 +27,12 @@ public interface IClientService {
* 滑动时增加次数
*/
GameMessageCountOut clientAddTimes(String userId, String recordId);
/**
* 查询本组游戏的分数信息
* @param groupId
* @param recordId
* @return
*/
ClientVo.GroupScore getGroupScore(Long groupId,Long recordId);
}

3
game/src/main/java/com/ccsens/game/service/IScreenService.java

@ -6,6 +6,7 @@ import com.ccsens.game.bean.vo.ScreenVo;
import com.ccsens.util.bean.dto.QueryDto;
import java.util.List;
import java.util.Map;
public interface IScreenService {
ScreenVo.UrlVo getScreenUrl(QueryDto<ScreenDto.MemberGame> params) throws Exception;
@ -41,4 +42,6 @@ public interface IScreenService {
List<ScreenVo.Group> getGroupByRecordId(Long recordId);
ScreenVo.RecordInfo getRecordByTaskId(Long taskId,String gameType);
Map<String, Object> getGroupTotalScore(Long groupId);
}

12
game/src/main/java/com/ccsens/game/service/ScreenService.java

@ -391,23 +391,31 @@ public class ScreenService implements IScreenService {
Map<String, Object> group2 = getGroupTotalScore(gameGroupList.get(1).getId());
if (CollectionUtil.isNotEmpty(group1) && CollectionUtil.isNotEmpty(group2)) {
int score1 = (int) group1.get("totalScore");
int score2 = (int) group1.get("totalScore");
int score2 = (int) group2.get("totalScore");
if (score1 > score2) {
userJoinList = (List<GameUserJoin>) group1.get("userJoinList");
completedData.setTotalMember(userJoinList.size());
completedData.setWinGroup(gameGroupList.get(0).getName());
} else {
userJoinList = (List<GameUserJoin>) group2.get("userJoinList");
completedData.setTotalMember(userJoinList.size());
completedData.setWinGroup(gameGroupList.get(1).getName());
}
}
//5、获取获胜队伍的信息
completedData = getCompletedData(userJoinList);
}
//前十名
List<ScreenVo.TopUsers> top2 = getTopUsers(gameRecordId);
completedData.setMembers(top2);
return completedData;
}
/**
* 获取队伍的总分
*/
private Map<String, Object> getGroupTotalScore(Long groupId) {
@Override
public Map<String, Object> getGroupTotalScore(Long groupId) {
Map<String, Object> groupMap = null;
//查找队伍的参赛人

40
game/src/main/java/com/ccsens/game/util/SendMsg.java

@ -9,6 +9,7 @@ import com.ccsens.game.bean.dto.message.GameMessageWithChangeStatusOut;
import com.ccsens.game.bean.po.GameGroup;
import com.ccsens.game.bean.po.GameGroupExample;
import com.ccsens.game.bean.po.GameRecord;
import com.ccsens.game.bean.vo.ClientVo;
import com.ccsens.game.persist.dao.GameGroupDao;
import com.ccsens.game.persist.dao.GameUserJoinDao;
import com.ccsens.game.service.ClientService;
@ -41,10 +42,6 @@ public class SendMsg {
@Autowired
private ClientService clientService;
@Autowired
private GameUserJoinDao gameUserJoinDao;
@Autowired
private GameGroupDao gameGroupDao;
@Autowired
private AmqpTemplate rabbitTemplate;
@Autowired
private RedisUtil redisUtil;
@ -76,32 +73,19 @@ public class SendMsg {
ChangeStatusMessageDto dtos = new ChangeStatusMessageDto();
switch (gameStatus) {
case GameConstant.GAME_COMPLETED:
ChangeStatusMessageDto.CompletedData completedData = new ChangeStatusMessageDto.CompletedData();
//如果是分组游戏,获取本组分数信息
if (ObjectUtil.isNotNull(join.getGroupId())) {
Integer times = 0;
Integer score = 0;
Integer sort = 1;
for (ClientDto.RedisUser user : userJoins) {
if (user.getGroupId().longValue() == join.getGroupId().longValue()) {
times += user.getTimes();
score += user.getScore();
if(user.getScore() > join.getScore()){
sort++;
}
}
}
ChangeStatusMessageDto.CompletedData completedData = new ChangeStatusMessageDto.CompletedData();
completedData.setTimes(times);
completedData.setScore(score);
completedData.setSort(sort);
dtos.setCompletedData(completedData);
} else {
ChangeStatusMessageDto.CompletedData completedData = new ChangeStatusMessageDto.CompletedData();
completedData.setTimes(join.getTimes());
completedData.setScore(join.getScore());
completedData.setSort(join.getSort());
completedData.setOver(join.getOver());
dtos.setCompletedData(completedData);
ClientVo.GroupScore groupScore = clientService.getGroupScore(join.getGroupId(),gameRecord.getId());
completedData.setGroupScore(groupScore);
}
completedData.setTimes(join.getTimes());
completedData.setScore(join.getScore());
completedData.setSort(join.getSort());
completedData.setOver(join.getOver());
dtos.setCompletedData(completedData);
break;
case GameConstant.GAME_PREPARATION:
//preparingData

Loading…
Cancel
Save