Browse Source

修改分组

master
zhizhi wu 5 years ago
parent
commit
e68e8343ef
  1. 2
      game/src/main/java/com/ccsens/game/api/ClientController.java
  2. 4
      game/src/main/java/com/ccsens/game/api/ScreenController.java
  3. 17
      game/src/main/java/com/ccsens/game/bean/vo/ClientVo.java
  4. 8
      game/src/main/java/com/ccsens/game/bean/vo/ScreenVo.java
  5. 20
      game/src/main/java/com/ccsens/game/persist/dao/GameGroupDao.java
  6. 57
      game/src/main/java/com/ccsens/game/service/ClientService.java
  7. 15
      game/src/main/java/com/ccsens/game/service/IClientService.java
  8. 31
      game/src/main/java/com/ccsens/game/service/ScreenService.java
  9. 9
      game/src/main/java/com/ccsens/game/util/GameConstant.java
  10. 41
      game/src/main/resources/mapper_dao/GameGroupDao.xml

2
game/src/main/java/com/ccsens/game/api/ClientController.java

@ -46,7 +46,7 @@ public class ClientController {
})
@RequestMapping(value = "joinGame", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse<ClientVo.Join> joinGame(@ApiParam @Validated @RequestBody QueryDto<ClientDto.Join> params) throws Exception {
log.info("查看全部排行榜:{}",params);
log.info("参加游戏:{}",params);
ClientVo.Join join = clientService.join(params.getParam(), params.getUserId());
return JsonResponse.newInstance().ok(join);
}

4
game/src/main/java/com/ccsens/game/api/ScreenController.java

@ -85,8 +85,8 @@ public class ScreenController {
@RequestMapping(value = "/config", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse<String> getConfig(@ApiParam @Validated @RequestBody QueryDto<ScreenDto.MemberRecord> params) throws Exception {
log.info("再玩一次:{}",params);
String url = screenService.getConfig(params);
return JsonResponse.newInstance().ok(url);
// String url = screenService.getConfig(params);
return JsonResponse.newInstance().ok();
}
}

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

@ -85,6 +85,23 @@ public class ClientVo {
private Integer groupSort;
}
@Data
@ApiModel("分组的信息")
public static class GroupVo{
@ApiModelProperty("分组的id")
private Long groupId;
@ApiModelProperty("分组的名称")
private String groupName;
@ApiModelProperty("头像")
private String headPortraitUrl;
@ApiModelProperty("该组的总分/均分")
private int groupScore;
@ApiModelProperty("该组总次数")
private int groupTimes;
@ApiModelProperty("code")
private String code;
}
@Data
@ApiModel("RankingAll")
public static class RankingAll{

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

@ -154,14 +154,18 @@ public class ScreenVo {
private Long groupId;
@ApiModelProperty("分组的名称")
private String groupName;
@ApiModelProperty("该组的总分")
@ApiModelProperty("头像")
private String headPortraitUrl;
@ApiModelProperty("该组的总分/均分")
private int score;
@ApiModelProperty("该组总人数")
private int totalMembers;
@ApiModelProperty("该组总人数")
@ApiModelProperty("code")
private String code;
}
@Data
@ApiModel
public static class RecordInfo{

20
game/src/main/java/com/ccsens/game/persist/dao/GameGroupDao.java

@ -1,9 +1,29 @@
package com.ccsens.game.persist.dao;
import com.ccsens.game.bean.po.GameGroup;
import com.ccsens.game.bean.vo.ClientVo;
import com.ccsens.game.bean.vo.ScreenVo;
import com.ccsens.game.persist.mapper.GameGroupMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface GameGroupDao extends GameGroupMapper {
/**
* 查询分组信息
* @param id 游戏ID
* @return 分组信息
*/
List<ScreenVo.GroupVo> queryGroups(@Param("gameId") Long id);
/**
* 查询各组分数次数
* @param groupId 分组ID
* @param gameId 游戏ID
* @param rankRule 排序规则
* @return 分组分数次数
*/
List<ClientVo.GroupVo> queryScores(@Param("groupId") long groupId, @Param("gameId") long gameId, @Param("rankRule") byte rankRule);
}

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

@ -18,17 +18,17 @@ import com.ccsens.util.JsonResponse;
import com.ccsens.util.RedisUtil;
import com.ccsens.util.exception.BaseException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.ccsens.util.bean.dto.QueryDto;
import javax.annotation.Resource;
import java.util.*;
/**
* @description:
* @description: 游戏客户端接口
* @author: wuHuiJuan
* @create: 2019/12/26 15:01
*/
@ -36,25 +36,25 @@ import java.util.*;
@Service
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class ClientService implements IClientService {
@Autowired
@Resource
private GameUserPayDao gameUserPayDao;
@Autowired
@Resource
private GameTypeDao gameTypeDao;
@Autowired
@Resource
private GameUserJoinDao gameUserJoinDao;
@Autowired
@Resource
private GameUserJoinGroupDao gameUserJoinGroupDao;
@Autowired
@Resource
private GameGroupDao gameGroupDao;
@Autowired
@Resource
private GameUserJoinGroupDao userJoinGroupDao;
@Autowired
@Resource
private Snowflake snowflake;
@Autowired
@Resource
private RedisUtil redisUtil;
@Autowired
@Resource
private TallFeignClient tallFeignClient;
@Autowired
@Resource
private IScreenService screenService;
@ -66,17 +66,15 @@ public class ClientService implements IClientService {
log.info("{}时间差:{}", userId, timeMore);
//获取游戏信息
GameRecord gameRecord = screenService.getGameRecord(join.getUrlId());
//获取游戏的购买记录和类型
GameUserPay gameUserPay = gameUserPayDao.selectByPrimaryKey(gameRecord.getUserPayId());
GameType gameType = gameTypeDao.selectByPrimaryKey(gameUserPay.getGameTypeId());
Boolean isGroup = gameType.getIsGroup() == 1;
log.info("游戏信息:{}", gameRecord);
if (gameRecord == null) {
log.info("未找到游戏信息");
throw new BaseException(CodeEnum.PARAM_ERROR);
}
//获取游戏的购买记录和类型
// TODO 暂时没有购买相关的,先不查询
// GameUserPay gameUserPay = gameUserPayDao.selectByPrimaryKey(gameRecord.getUserPayId());
Boolean isGroup = gameRecord.getGroup() == GameConstant.GAME_GROUP;
//根据游戏ID和用户ID查询用户是否加入
GameUserJoinExample example = new GameUserJoinExample();
@ -98,7 +96,8 @@ public class ClientService implements IClientService {
completedData.setOver(0);
if(isGroup){
ClientVo.GroupScore groupScore = getGroupScore(join.getGroupId(),gameRecord.getId());
ClientVo.GroupScore groupScore = getGroupScore(join.getGroupId(), gameRecord);
// getGroupScore(join.getGroupId(),gameRecord.getId());
completedData.setGroupScore(groupScore);
}
joinVo.setCompletedData(completedData);
@ -223,7 +222,7 @@ public class ClientService implements IClientService {
ClientVo.CompletedData completedData = new ClientVo.CompletedData();
//如果是分组游戏,获取本组信息
if(isGroup){
ClientVo.GroupScore groupScore = getGroupScore(groupId,gameRecord.getId());
ClientVo.GroupScore groupScore = getGroupScore(groupId,gameRecord);
completedData.setGroupScore(groupScore);
}
completedData.setTimes(join.getTimes());
@ -247,7 +246,23 @@ public class ClientService implements IClientService {
log.info("参加游戏:{}", joinVo);
return joinVo;
}
@Override
public ClientVo.GroupScore getGroupScore(long groupId,GameRecord record){
log.info("查询成绩:{},{}", groupId, record);
ClientVo.GroupScore score = new ClientVo.GroupScore();
List<ClientVo.GroupVo> scores = gameGroupDao.queryScores(groupId, record.getId(), record.getRankRule());
for (int i = 0; i < scores.size(); i++) {
ClientVo.GroupVo groupVo = scores.get(i);
if (groupVo.getGroupId() == groupId) {
score.setGroupSort(i);
score.setGroupScore(groupVo.getGroupScore());
score.setGroupTimes(groupVo.getGroupTimes());
return score;
}
}
log.info("{},{}没有找到组信息", groupId, record);
return score;
}
/**
* 获取本组的信息
*/

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

@ -3,6 +3,7 @@ package com.ccsens.game.service;
import com.ccsens.game.bean.dto.ClientDto;
import com.ccsens.game.bean.dto.message.BaseMessageDto;
import com.ccsens.game.bean.dto.message.GameMessageCountOut;
import com.ccsens.game.bean.po.GameRecord;
import com.ccsens.game.bean.vo.ClientVo;
import com.ccsens.util.bean.dto.QueryDto;
@ -30,9 +31,17 @@ public interface IClientService {
/**
* 查询本组游戏的分数信息
* @param groupId
* @param recordId
* @return
* @param groupId 分组ID
* @param recordId 游戏ID
* @return 分组信息
*/
ClientVo.GroupScore getGroupScore(Long groupId,Long recordId);
/**
* 查询本组游戏的分数信息
* @param groupId 分组ID
* @param record 游戏信息
* @return 分组信息
*/
ClientVo.GroupScore getGroupScore(long groupId, GameRecord record);
}

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

@ -22,6 +22,7 @@ import com.ccsens.util.bean.dto.QueryDto;
import com.ccsens.util.exception.BaseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.sun.org.apache.bcel.internal.generic.RETURN;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ZSetOperations;
@ -222,7 +223,7 @@ public class ScreenService implements IScreenService {
//总人数
gameInfoVo.setTotalMembers(totalUsers == null ? 0 : totalUsers.intValue());
//获取分组的信息
List<ScreenVo.GroupVo> groupVo = getGroupScore(gameRecord.getId());
List<ScreenVo.GroupVo> groupVo = getGroupScore2(gameRecord);
gameInfoVo.setGroups(groupVo);
switch (gameInfoVo.getGameStatus()) {
case 0:
@ -288,7 +289,7 @@ public class ScreenService implements IScreenService {
gameStatusVo.setGameStatus(gameRecord.getGameStatus());
//获取分组的信息
List<ScreenVo.GroupVo> groupVo = getGroupScore(gameRecord.getId());
List<ScreenVo.GroupVo> groupVo = getGroupScore2(gameRecord);
gameStatusVo.setGroups(groupVo);
// 查询总人数
Long total = redisUtil.zsGetSize(GameConstant.generateGameKey(gameRecord.getId()));
@ -327,7 +328,7 @@ public class ScreenService implements IScreenService {
gameStatusVo.setProcessingData(processingData);
} else {
//分组游戏则返回每个分组的信息
List<ScreenVo.GroupVo> groupVoList = getGroupScore(gameRecordId);
List<ScreenVo.GroupVo> groupVoList = getGroupScore(gameRecord);
gameStatusVo.setProcessingData(groupVoList);
}
break;
@ -349,11 +350,25 @@ public class ScreenService implements IScreenService {
/**
* 进行中查询每个组的信息
*/
private List<ScreenVo.GroupVo> getGroupScore(Long gameRecordId) {
private List<ScreenVo.GroupVo> getGroupScore2(GameRecord gameRecord) {
List<ScreenVo.GroupVo> vos = gameGroupDao.queryGroups(gameRecord.getId());
if (CollectionUtil.isEmpty(vos) || gameRecord.getRankRule() == GameConstant.RANK_RULE_TOTAL) {
return vos;
}
vos.forEach(vo -> {
vo.setScore(vo.getTotalMembers() == 0 ? 0 : vo.getScore()/vo.getTotalMembers());
});
vos.sort((t1,t2)-> t2.getScore() - t1.getScore());
return vos;
}
/**
* 进行中查询每个组的信息
*/
private List<ScreenVo.GroupVo> getGroupScore(GameRecord gameRecord) {
List<ScreenVo.GroupVo> groupVoList = new ArrayList<>();
//查询分组信息
GameGroupExample gameGroupExample = new GameGroupExample();
gameGroupExample.createCriteria().andRecordIdEqualTo(gameRecordId);
gameGroupExample.createCriteria().andRecordIdEqualTo(gameRecord.getId());
List<GameGroup> gameGroupList = gameGroupDao.selectByExample(gameGroupExample);
if (CollectionUtil.isNotEmpty(gameGroupList)) {
for (GameGroup gameGroup : gameGroupList) {
@ -365,8 +380,10 @@ public class ScreenService implements IScreenService {
Map<String, Object> group = getGroupTotalScore(gameGroup.getId());
if (CollectionUtil.isNotEmpty(group)) {
List<GameUserJoin> userJoinList = (List<GameUserJoin>) group.get("userJoinList");
groupVo.setScore((Integer) group.get("totalScore"));
groupVo.setTotalMembers(userJoinList.size());
int totalScore = (Integer) group.getOrDefault("totalScore", 0);
int members = userJoinList.size();
groupVo.setScore(gameRecord.getRankRule() == GameConstant.RANK_RULE_AVA ? (members == 0 ? 0 : totalScore/members) : totalScore);
groupVo.setTotalMembers(members);
}
groupVoList.add(groupVo);
}

9
game/src/main/java/com/ccsens/game/util/GameConstant.java

@ -38,6 +38,15 @@ public class GameConstant {
/**再来一次*/
public static final byte GAME_RESTART_STATUS = 1;
/**排序规则:总分*/
public static final byte RANK_RULE_AVA = 1;
/**排序规则:均分*/
public static final byte RANK_RULE_TOTAL = 0;
/**游戏:分组*/
public static final byte GAME_GROUP = 1;
/**游戏:单人*/
public static final byte GAME_SINGLE = 1;
/**
* 生成游戏key
* @param recordId

41
game/src/main/resources/mapper_dao/GameGroupDao.xml

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ccsens.game.persist.dao.GameGroupDao">
<select id="queryGroups" resultType="com.ccsens.game.bean.vo.ScreenVo$GroupVo">
SELECT
g.id AS groupId,
g.NAME AS groupName,
g.head_portrait_url as headPortraitUrl,
sum( u.score ) AS score,
count( ug.id ) AS totalMembers
FROM
t_game_group g
LEFT JOIN ( SELECT * FROM t_game_user_join_group WHERE rec_status = 0 ) ug ON g.id = ug.game_group_id
LEFT JOIN ( SELECT * FROM t_game_user_join WHERE rec_status = 0 ) u ON ug.user_join_id = u.id
WHERE
g.rec_status = 0
AND g.record_id = #{gameId}
GROUP BY
g.id
order by sum(u.score) desc
</select>
<select id="queryScores" resultType="com.ccsens.game.bean.vo.ClientVo$GroupVo">
SELECT
g.id AS groupId,
g.head_portrait_url as headPortraitUrl,
g.NAME AS groupName,
if (${rankRule}=1,sum(u.score),(if(count( ug.id )=0, 0 ,sum(u.score)/count( ug.id )))) AS groupScore,
sum(u.times) as groupTimes
FROM
t_game_group g
LEFT JOIN ( SELECT * FROM t_game_user_join_group WHERE rec_status = 0 ) ug ON g.id = ug.game_group_id
LEFT JOIN ( SELECT * FROM t_game_user_join WHERE rec_status = 0 ) u ON ug.user_join_id = u.id
WHERE
g.rec_status = 0
AND g.record_id = #{gameId}
GROUP BY
g.id
order by groupScore desc
</select>
</mapper>
Loading…
Cancel
Save