Browse Source

0818_2.0冲突

master
zy_Java 5 years ago
parent
commit
d9af571005
  1. 17
      game/src/main/java/com/ccsens/game/api/ClientController.java
  2. 8
      game/src/main/java/com/ccsens/game/api/ScreenController.java
  3. 11
      game/src/main/java/com/ccsens/game/bean/dto/ClientDto.java
  4. 17
      game/src/main/java/com/ccsens/game/bean/vo/ClientVo.java
  5. 8
      game/src/main/java/com/ccsens/game/bean/vo/ScreenVo.java
  6. 27
      game/src/main/java/com/ccsens/game/persist/dao/GameGroupDao.java
  7. 67
      game/src/main/java/com/ccsens/game/service/ClientService.java
  8. 23
      game/src/main/java/com/ccsens/game/service/IClientService.java
  9. 33
      game/src/main/java/com/ccsens/game/service/ScreenService.java
  10. 13
      game/src/main/java/com/ccsens/game/util/GameConstant.java
  11. 4
      game/src/main/resources/application.yml
  12. 59
      game/src/main/resources/mapper_dao/GameGroupDao.xml

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

@ -2,13 +2,13 @@ package com.ccsens.game.api;
import com.ccsens.cloudutil.annotation.MustLogin;
import com.ccsens.game.bean.dto.ClientDto;
import com.ccsens.game.bean.dto.ScreenDto;
import com.ccsens.game.bean.vo.ClientVo;
import com.ccsens.game.bean.vo.ScreenVo;
import com.ccsens.game.service.IClientService;
import com.ccsens.game.service.IScreenService;
import com.ccsens.util.JsonResponse;
import com.ccsens.util.bean.dto.QueryDto;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
@ -30,11 +30,22 @@ public class ClientController {
@Autowired
private IScreenService screenService;
@ApiOperation(value = "查看组内排行榜", notes = "")
@ApiImplicitParams({
})
@RequestMapping(value = "groupMembers", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse<ClientVo.RankingAll> groupMembers(@ApiParam @Validated @RequestBody QueryDto<ClientDto.GroupRanking> params) throws Exception {
log.info("查看组内排行榜:{}",params);
PageInfo<ClientVo.MemberInfo> rankingAll = clientService.groupMembers(params.getParam());
return JsonResponse.newInstance().ok(rankingAll);
}
@ApiOperation(value = "查看全部排行榜", notes = "")
@ApiImplicitParams({
})
@RequestMapping(value = "members", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse<ClientVo.RankingAll> startAgain(@ApiParam @Validated @RequestBody QueryDto<ClientDto.GatRanking> params) throws Exception {
public JsonResponse<ClientVo.RankingAll> members(@ApiParam @Validated @RequestBody QueryDto<ClientDto.GatRanking> params) throws Exception {
log.info("查看全部排行榜:{}",params);
ClientVo.RankingAll rankingAll = clientService.getRankingAll(params);
return JsonResponse.newInstance().ok(rankingAll);
@ -46,7 +57,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);
}

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

@ -12,21 +12,25 @@ import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
/**
* 大屏相关接口
* @author zy
*/
@Slf4j
@Api(tags = "大屏相关api" , description = "ScreenController")
@RestController
@RequestMapping("/screen")
public class ScreenController {
@Autowired
@Resource
private IScreenService screenService;
@MustLogin

11
game/src/main/java/com/ccsens/game/bean/dto/ClientDto.java

@ -70,5 +70,16 @@ public class ClientDto {
private int pageSize;
}
@Data
@ApiModel("getRanking")
public static class GroupRanking{
@ApiModelProperty("分组id")
private Long groupId;
@ApiModelProperty("页数")
private int pageNum;
@ApiModelProperty("每页多少条")
private int pageSize;
}
}

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{

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

@ -1,9 +1,36 @@
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);
/**
* 查询组内成员排名
* @param groupId 组ID
* @return 成员信息
*/
List<ClientVo.MemberInfo> groupMemberRank(@Param("groupId") Long groupId);
}

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

@ -17,18 +17,20 @@ import com.ccsens.util.CodeEnum;
import com.ccsens.util.JsonResponse;
import com.ccsens.util.RedisUtil;
import com.ccsens.util.exception.BaseException;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
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 +38,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 +68,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.getGameGroup() == GameConstant.GAME_GROUP;
//根据游戏ID和用户ID查询用户是否加入
GameUserJoinExample example = new GameUserJoinExample();
@ -98,7 +98,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 +224,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,6 +248,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;
}
/**
* 获取本组的信息
@ -517,4 +535,13 @@ public class ClientService implements IClientService {
List<GameGroup> gameGroupList = gameGroupDao.selectByExample(gameGroupExample);
return gameGroupList;
}
@Override
public PageInfo<ClientVo.MemberInfo> groupMembers(ClientDto.GroupRanking groupRanking) {
log.info("查询组内成员排序:{}", groupRanking);
PageHelper.startPage(groupRanking.getPageNum(), groupRanking.getPageSize());
List<ClientVo.MemberInfo> infos = gameGroupDao.groupMemberRank(groupRanking.getGroupId());
log.info("结果:{}", infos);
return new PageInfo<>(infos);
}
}

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

@ -3,8 +3,10 @@ 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;
import com.github.pagehelper.PageInfo;
/**
* @description:
@ -30,9 +32,24 @@ 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);
/**
* 查询组内成员排行
* @param groupRanking
* @return 排行
*/
PageInfo<ClientVo.MemberInfo> groupMembers(ClientDto.GroupRanking groupRanking);
}

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

@ -195,7 +195,8 @@ public class ScreenService implements IScreenService {
XSSFRow gamePatternRow = sheet.getRow(1);
if(ObjectUtil.isNotNull(gamePatternRow)){
String gamePattern = ExcelUtil.getCellValue(gamePatternRow.getCell(1));
if(gamePattern.equalsIgnoreCase(GameConstant.GAME_GROUP)){
if(gamePattern.equalsIgnoreCase(GameConstant.EXCEL_GAME_GROUP)){
gameRecord.setGameGroup((byte) 1);
}
}
@ -435,7 +436,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:
@ -498,7 +499,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()));
@ -537,7 +538,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;
@ -559,11 +560,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) {
@ -575,8 +590,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);
}

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

@ -38,14 +38,23 @@ public class GameConstant {
/**再来一次*/
public static final byte GAME_RESTART_STATUS = 1;
/**个人*/
public static final String GAME_INDIVIDUAL = "个人";
public static final String EXCEL_GAME_INDIVIDUAL = "个人";
/**团体*/
public static final String GAME_GROUP = "团体";
public static final String EXCEL_GAME_GROUP = "团体";
/**按人均分排名*/
public static final String GAME_RANK_AVE = "按人均分排名";
/**按总分排名*/
public static final String GAME_RANK_TOTAL = "按总分排名";
/**排序规则:总分*/
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

4
game/src/main/resources/application.yml

@ -1,4 +1,4 @@
spring:
profiles:
active: dev
include: common, util-dev
active: test
include: common, util-test

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

@ -0,0 +1,59 @@
<?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>
<select id="groupMemberRank" resultType="com.ccsens.game.bean.vo.ClientVo$MemberInfo">
SELECT
u.id,
u.avatar_url AS headImgUrl,
u.nickname,
u.score,
u.times
FROM
t_game_user_join u,
t_game_user_join_group g
WHERE
u.id = g.user_join_id
AND g.game_group_id = #{groupId}
AND u.rec_status = 0
AND g.rec_status = 0
ORDER BY
u.score DESC
</select>
</mapper>
Loading…
Cancel
Save