Browse Source

添加游戏分组code

master
zhangye 5 years ago
parent
commit
8e1c82026d
  1. 13
      cloudutil/src/main/java/com/ccsens/cloudutil/feign/TallFeignClient.java
  2. 4
      game/src/main/java/com/ccsens/game/bean/dto/ClientDto.java
  3. 1
      game/src/main/java/com/ccsens/game/bean/dto/message/ChangeStatusMessageDto.java
  4. 11
      game/src/main/java/com/ccsens/game/bean/po/GameGroup.java
  5. 70
      game/src/main/java/com/ccsens/game/bean/po/GameGroupExample.java
  6. 12
      game/src/main/java/com/ccsens/game/bean/vo/ScreenVo.java
  7. 53
      game/src/main/java/com/ccsens/game/service/ClientService.java
  8. 269
      game/src/main/java/com/ccsens/game/service/ScreenService.java
  9. 11
      game/src/main/java/com/ccsens/game/util/GameConstant.java
  10. 53
      game/src/main/java/com/ccsens/game/util/SendMsg.java
  11. 29
      game/src/main/resources/mapper_raw/GameGroupMapper.xml
  12. 4
      game/src/main/resources/mbg.xml
  13. 11
      mt/src/main/java/com/ccsens/mt/bean/po/MtSigninBasic.java
  14. 60
      mt/src/main/java/com/ccsens/mt/bean/po/MtSigninBasicExample.java
  15. 51
      mt/src/main/java/com/ccsens/mt/service/SigninService.java
  16. 4
      mt/src/main/resources/application.yml
  17. 31
      mt/src/main/resources/mapper_raw/MtSigninBasicMapper.xml
  18. 1
      tall/src/main/java/com/ccsens/tall/config/SpringConfig.java
  19. 2
      tall/src/main/java/com/ccsens/tall/service/ISysPluginService.java
  20. 11
      tall/src/main/java/com/ccsens/tall/service/SysPluginService.java
  21. 12
      tall/src/main/java/com/ccsens/tall/web/PluginController.java
  22. 4
      util/src/main/java/com/ccsens/util/WebConstant.java

13
cloudutil/src/main/java/com/ccsens/cloudutil/feign/TallFeignClient.java

@ -85,7 +85,7 @@ public interface TallFeignClient {
JsonResponse log(LogDto logDto);
/**
* 通过任务id获得项目id
* 通过任务id获得任务信息
*
* @param taskId
* @return
@ -140,6 +140,12 @@ public interface TallFeignClient {
@GetMapping("/plugins/fuzzy")
List<String> getSignFuzzy(@RequestParam(name = "taskPluginId") Long taskPluginId, @RequestParam(name = "signinName") String signinName, @RequestParam(name = "key") String key);
/**
* 通过插件id获取签到字段和详细信息
*/
@GetMapping("/plugins/task")
Long getTaskIdByTaskPluginId(@RequestParam(name = "taskPluginId") Long taskPluginId);
}
@Slf4j
@ -217,6 +223,11 @@ class TallFeignClientFallBack implements FallbackFactory<TallFeignClient> {
public List<String> getSignFuzzy(Long taskPluginId, String signinName, String key) {
return null;
}
@Override
public Long getTaskIdByTaskPluginId(Long taskPluginId) {
return null;
}
};
}

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

@ -43,8 +43,9 @@ public class ClientDto {
private Integer timeDifference;
private Long localStartTime;
private Long localEndTime;
private Long groupId;
public static RedisUser getInstance(GameUserJoin userJoin){
public static RedisUser getInstance(GameUserJoin userJoin,Long groupId){
ClientDto.RedisUser user = new ClientDto.RedisUser();
user.setId(userJoin.getId());
user.setAvatarUrl(userJoin.getAvatarUrl());
@ -53,6 +54,7 @@ public class ClientDto {
user.setTimeDifference(userJoin.getTimeDifference());
user.setLocalStartTime(userJoin.getLocalStartTime());
user.setLocalEndTime(userJoin.getLocalEndTime());
user.setGroupId(groupId);
return user;
}
}

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

@ -43,4 +43,5 @@ public class ChangeStatusMessageDto {
@ApiModelProperty("超过百分之多少人")
private Integer over;
}
}

11
game/src/main/java/com/ccsens/game/bean/po/GameGroup.java

@ -8,6 +8,8 @@ public class GameGroup implements Serializable {
private Long recordId;
private String code;
private String name;
private Date createdAt;
@ -34,6 +36,14 @@ public class GameGroup implements Serializable {
this.recordId = recordId;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code == null ? null : code.trim();
}
public String getName() {
return name;
}
@ -74,6 +84,7 @@ public class GameGroup implements Serializable {
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", recordId=").append(recordId);
sb.append(", code=").append(code);
sb.append(", name=").append(name);
sb.append(", createdAt=").append(createdAt);
sb.append(", updatedAt=").append(updatedAt);

70
game/src/main/java/com/ccsens/game/bean/po/GameGroupExample.java

@ -225,6 +225,76 @@ public class GameGroupExample {
return (Criteria) this;
}
public Criteria andCodeIsNull() {
addCriterion("code is null");
return (Criteria) this;
}
public Criteria andCodeIsNotNull() {
addCriterion("code is not null");
return (Criteria) this;
}
public Criteria andCodeEqualTo(String value) {
addCriterion("code =", value, "code");
return (Criteria) this;
}
public Criteria andCodeNotEqualTo(String value) {
addCriterion("code <>", value, "code");
return (Criteria) this;
}
public Criteria andCodeGreaterThan(String value) {
addCriterion("code >", value, "code");
return (Criteria) this;
}
public Criteria andCodeGreaterThanOrEqualTo(String value) {
addCriterion("code >=", value, "code");
return (Criteria) this;
}
public Criteria andCodeLessThan(String value) {
addCriterion("code <", value, "code");
return (Criteria) this;
}
public Criteria andCodeLessThanOrEqualTo(String value) {
addCriterion("code <=", value, "code");
return (Criteria) this;
}
public Criteria andCodeLike(String value) {
addCriterion("code like", value, "code");
return (Criteria) this;
}
public Criteria andCodeNotLike(String value) {
addCriterion("code not like", value, "code");
return (Criteria) this;
}
public Criteria andCodeIn(List<String> values) {
addCriterion("code in", values, "code");
return (Criteria) this;
}
public Criteria andCodeNotIn(List<String> values) {
addCriterion("code not in", values, "code");
return (Criteria) this;
}
public Criteria andCodeBetween(String value1, String value2) {
addCriterion("code between", value1, value2, "code");
return (Criteria) this;
}
public Criteria andCodeNotBetween(String value1, String value2) {
addCriterion("code not between", value1, value2, "code");
return (Criteria) this;
}
public Criteria andNameIsNull() {
addCriterion("name is null");
return (Criteria) this;

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

@ -35,7 +35,7 @@ public class ScreenVo {
@ApiModelProperty("总人数")
private int totalMembers ;
@ApiModelProperty("分组信息")
private List<Group> groups ;
private List<GroupVo> groups ;
@ApiModelProperty("未开始")
private PendingData pendingData;
@ -55,6 +55,8 @@ public class ScreenVo {
private Long groupId ;
@ApiModelProperty("分组名称")
private String groupName ;
@ApiModelProperty("该组参赛总人数")
private int totalGroupMembers ;
}
@ -99,12 +101,14 @@ public class ScreenVo {
}
@Data
@ApiModel("进行中")
@ApiModel("游戏状态")
public static class GameStatusVo{
@ApiModelProperty("游戏状态 0未开始 1准备中 2进行中 3已结束")
private Byte gameStatus;
@ApiModelProperty("总人数")
private int totalMembers ;
@ApiModelProperty("分组信息")
private List<GroupVo> groups ;
@ApiModelProperty("未开始")
private PendingData pendingData;
@ -152,10 +156,12 @@ public class ScreenVo {
private int score;
@ApiModelProperty("该组总人数")
private int totalMembers;
@ApiModelProperty("该组总人数")
private String code;
}
@Data
@ApiModel("分组的信息")
@ApiModel
public static class RecordInfo{
@ApiModelProperty("游戏记录id")
private Long id;

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

@ -156,7 +156,7 @@ public class ClientService implements IClientService {
}
// 3.更新redis(sort set key:分数 value:头像,姓名)
if (prepare || processing) {
ClientDto.RedisUser user = ClientDto.RedisUser.getInstance(userJoin);
ClientDto.RedisUser user = ClientDto.RedisUser.getInstance(userJoin, join.getGroupId());
redisUtil.zsSet(GameConstant.generateGameKey(gameRecord.getId()), JSON.toJSONString(user), 0, GameConstant.REDIS_TIME);
}
@ -367,58 +367,59 @@ public class ClientService implements IClientService {
return gameMessageCountOut;
}
long t8 = System.currentTimeMillis();
log.info("判断耗时:{}", t8-t1);
log.info("判断耗时:{}", t8 - t1);
Long recordIdLong = Long.parseLong(recordId);
String gameUserKey = GameConstant.generateGameKey(recordIdLong);
long t3 = System.currentTimeMillis();
log.info("生成key耗时:{}", t3-t2);
log.info("生成key耗时:{}", t3 - t2);
Set<ZSetOperations.TypedTuple<Object>> typedTuples = redisUtil.zsRevGetWithScore(gameUserKey, 0, -1);
long t4 = System.currentTimeMillis();
log.info("查询分数耗时:{}", t4-t3);
log.info("查询分数耗时:{}", t4 - t3);
if (CollectionUtil.isEmpty(typedTuples)) {
return gameMessageCountOut;
}
long t5 = System.currentTimeMillis();
log.info("判断分数是否为空耗时:{}", t5-t4);
log.info("判断分数是否为空耗时:{}", t5 - t4);
log.info("查询耗时:{}", t5 - t8);
for(ZSetOperations.TypedTuple<Object> type : typedTuples) {
for (ZSetOperations.TypedTuple<Object> type : typedTuples) {
long a1 = System.currentTimeMillis();
ClientDto.RedisUser user = JSON.parseObject((String)type.getValue(), ClientDto.RedisUser.class);
ClientDto.RedisUser user = JSON.parseObject((String) type.getValue(), ClientDto.RedisUser.class);
long a2 = System.currentTimeMillis();
log.info("json转换耗时:{}", a2-a1);
log.info("json转换耗时:{}", a2 - a1);
if (user.getUserId().longValue() == Long.parseLong(userId)) {
int score = type.getScore().intValue();
long a3 = System.currentTimeMillis();
log.info("获取分数耗时:{}", a3-a2);
log.info("获取分数耗时:{}", a3 - a2);
String userStatus = GameConstant.generateGameStatusKey(recordIdLong);
long a4 = System.currentTimeMillis();
log.info("生成游戏状态key耗时:{}", a4-a3);
String gameStausObj = (String)redisUtil.get(userStatus);
log.info("生成游戏状态key耗时:{}", a4 - a3);
String gameStausObj = (String) redisUtil.get(userStatus);
long a5 = System.currentTimeMillis();
log.info("获取状态耗时:{}", a5-a4);
log.info("gameStatus:{},equals:{}",gameStausObj, gameStausObj.equals(String.valueOf(GameConstant.GAME_COMPLETED)));
if (StrUtil.isBlank(gameStausObj) || gameStausObj.equals(String.valueOf(GameConstant.GAME_COMPLETED))){
gameMessageCountOut = new GameMessageCountOut(score/100, score);
log.info("获取状态耗时:{}", a5 - a4);
log.info("gameStatus:{},equals:{}", gameStausObj, gameStausObj.equals(String.valueOf(GameConstant.GAME_COMPLETED)));
if (StrUtil.isBlank(gameStausObj) || gameStausObj.equals(String.valueOf(GameConstant.GAME_COMPLETED))) {
gameMessageCountOut = new GameMessageCountOut(score / 100, score);
return gameMessageCountOut;
}
long a6 = System.currentTimeMillis();
log.info("判断游戏结束耗时:{}", a6-a5);
log.info("判断游戏结束耗时:{}", a6 - a5);
score += 100;
redisUtil.zsSet(gameUserKey, JSON.toJSONString(user), score);
long a7 = System.currentTimeMillis();
log.info("更新redis耗时:{}", a7-a6);
log.info("更新redis耗时:{}", a7 - a6);
gameMessageCountOut.getData().setTotalScore(score);
gameMessageCountOut.getData().setTotalTimes(score/100);
gameMessageCountOut.getData().setTotalTimes(score / 100);
long t = System.currentTimeMillis();
log.info("循环耗时:{}", t - t5);
log.info("返回耗时:{},循环耗时:{}", t-a7, t-t5);
log.info("返回耗时:{},循环耗时:{}", t - a7, t - t5);
return gameMessageCountOut;
}
};
}
;
long t = System.currentTimeMillis();
log.info("总耗时:{}", t- t1);
log.info("总耗时:{}", t - t1);
// if (ObjectUtil.isNotNull(userId)) {
// GameUserJoinExample gameUserJoinExample = new GameUserJoinExample();
@ -440,4 +441,14 @@ public class ClientService implements IClientService {
// }
return gameMessageCountOut;
}
/**
* 查询游戏是否是分组游戏
*/
public List<GameGroup> isGroupGame(Long recordId) {
GameGroupExample gameGroupExample = new GameGroupExample();
gameGroupExample.createCriteria().andRecordIdEqualTo(recordId);
List<GameGroup> gameGroupList = gameGroupDao.selectByExample(gameGroupExample);
return gameGroupList;
}
}

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

@ -41,7 +41,9 @@ import java.util.concurrent.*;
@Slf4j
@Service
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class ScreenService implements IScreenService{
public class ScreenService implements IScreenService {
@Autowired
private ClientService clientService;
@Autowired
private GameUserPayDao gameUserPayDao;
@Autowired
@ -74,6 +76,7 @@ public class ScreenService implements IScreenService{
/**
* 传入用户信息返回游戏大屏路径
*
* @return
*/
@Override
@ -84,10 +87,10 @@ public class ScreenService implements IScreenService{
GameTypeExample gameTypeExample = new GameTypeExample();
gameTypeExample.createCriteria().andCodeEqualTo(memberGame.getGameType());
List<GameType> gameTypeList = gameTypeDao.selectByExample(gameTypeExample);
if(CollectionUtil.isNotEmpty(gameTypeList)){
if (CollectionUtil.isNotEmpty(gameTypeList)) {
gameType = gameTypeList.get(0);
}
if(ObjectUtil.isNull(gameType)){
if (ObjectUtil.isNull(gameType)) {
throw new BaseException(CodeEnum.NOT_GAME_TYPE);
}
//2、查找此用户购买的此游戏的信息,若没有则添加一条记录,默认已付款,结束时间为添加后的一个月,默认次数为10次
@ -95,9 +98,9 @@ public class ScreenService implements IScreenService{
GameUserPayExample gameUserPayExample = new GameUserPayExample();
gameUserPayExample.createCriteria().andUserIdEqualTo(params.getUserId()).andGameTypeIdEqualTo(gameType.getId());
List<GameUserPay> gameUserPayList = gameUserPayDao.selectByExample(gameUserPayExample);
if(CollectionUtil.isNotEmpty(gameUserPayList)){
if (CollectionUtil.isNotEmpty(gameUserPayList)) {
gameUserPay = gameUserPayList.get(0);
}else {
} else {
gameUserPay = new GameUserPay();
gameUserPay.setId(snowflake.nextId());
gameUserPay.setUserId(params.getUserId());
@ -105,11 +108,11 @@ public class ScreenService implements IScreenService{
gameUserPay.setTotalCount(10);
gameUserPay.setUsedCount(0);
gameUserPay.setCreatedTime(System.currentTimeMillis());
gameUserPay.setDueTime(gameUserPay.getCreatedTime() + (3600*24*30));
gameUserPay.setDueTime(gameUserPay.getCreatedTime() + (3600 * 24 * 30));
gameUserPayDao.insertSelective(gameUserPay);
}
//查询该任务下的游戏记录信息
if(ObjectUtil.isNotNull(memberGame.getTaskId())) {
if (ObjectUtil.isNotNull(memberGame.getTaskId())) {
GameRecordExample recordExample = new GameRecordExample();
recordExample.createCriteria().andTaskIdEqualTo(memberGame.getTaskId());
recordExample.setOrderByClause("created_at DESC");
@ -127,20 +130,30 @@ public class ScreenService implements IScreenService{
gameRecord.setId(snowflake.nextId());
gameRecord.setUserPayId(gameUserPay.getId());
gameRecord.setTaskId(memberGame.getTaskId());
gameRecord.setUrl(WebConstant.TEST_URL_GAME + gameType.getScreenUrl() + "?id="+gameRecord.getId());
gameRecord.setQrCodeUrl(WebConstant.TEST_URL_GAME + gameRecord.getId() + File.separator + gameType.getClientUrl());
//添加路径
String gameUrl = WebConstant.TEST_URL_GAME_SQ;
switch (gameType.getCode()){
case GameConstant.GAME_TYPE_SQ: break;
case GameConstant.GAME_TYPE_SP: gameUrl = WebConstant.TEST_URL_GAME_SP; break;
case GameConstant.GAME_TYPE_BH: gameUrl = WebConstant.TEST_URL_GAME_BH; break;
default:break;
}
gameRecord.setUrl(gameUrl + gameType.getScreenUrl() + "?id=" + gameRecord.getId());
gameRecord.setQrCodeUrl(gameUrl + gameRecord.getId() + File.separator + gameType.getClientUrl());
gameRecordDao.insertSelective(gameRecord);
//4、 判断是否有分组,如果是分组游戏,添加两条分组信息
if(gameType.getIsGroup() == 1){
if (gameType.getIsGroup() == 1) {
GameGroup gameGroupRed = new GameGroup();
gameGroupRed.setId(snowflake.nextId());
gameGroupRed.setRecordId(gameRecord.getId());
gameGroupRed.setName(memberGame.getFirstTeam());
gameGroupRed.setCode(GameConstant.FIRST_GROUP);
gameGroupDao.insertSelective(gameGroupRed);
GameGroup gameGroupBlue = new GameGroup();
gameGroupBlue.setId(snowflake.nextId());
gameGroupBlue.setRecordId(gameRecord.getId());
gameGroupBlue.setName(memberGame.getSecondTeam());
gameGroupBlue.setCode(GameConstant.SECOND_GROUP);
gameGroupDao.insertSelective(gameGroupBlue);
}
@ -153,15 +166,15 @@ public class ScreenService implements IScreenService{
urlVo.setRuleList(ruleList);
//路径(添加项目id)
String url = gameRecord.getUrl() + "&projectId="+ memberGame.getProjectId();
String url = gameRecord.getUrl() + "&projectId=" + memberGame.getProjectId();
//给所有人发送消息发送消息
ChromeMessageDto chromeMessageDto = new ChromeMessageDto(url,gameRecord.getId(),memberGame.getProjectId());
ChromeMessageDto chromeMessageDto = new ChromeMessageDto(url, gameRecord.getId(), memberGame.getProjectId());
BaseMessageDto.MessageUser messageUser = null;
List<BaseMessageDto.MessageUser> messageUserList = new ArrayList<>();
//获取项目下所有成员
List<Long> memberIdList = tallFeignClient.getMemberIdListByProject(memberGame.getProjectId());
if(CollectionUtil.isNotEmpty(memberIdList)){
for(Long memberId:memberIdList){
if (CollectionUtil.isNotEmpty(memberIdList)) {
for (Long memberId : memberIdList) {
messageUser = new BaseMessageDto.MessageUser();
messageUser.setUserId(memberId);
messageUserList.add(messageUser);
@ -175,6 +188,7 @@ public class ScreenService implements IScreenService{
/**
* 获取游戏基本信息
*
* @return
*/
@Override
@ -187,7 +201,7 @@ public class ScreenService implements IScreenService{
GameRecord gameRecord = getGameRecord(memberRecord.getMemberRecord());
GameUserPay gameUserPay = gameUserPayDao.selectByPrimaryKey(gameRecord.getUserPayId());
if(ObjectUtil.isNull(gameUserPay)){
if (ObjectUtil.isNull(gameUserPay)) {
throw new BaseException(CodeEnum.NOT_GAME_TYPE);
}
@ -204,23 +218,10 @@ public class ScreenService implements IScreenService{
}
//总人数
gameInfoVo.setTotalMembers(totalUsers == null ? 0 : totalUsers.intValue());
//获取分组信息
GameGroupExample gameGroupExample = new GameGroupExample();
gameGroupExample.createCriteria().andRecordIdEqualTo(gameRecord.getId());
List<GameGroup> gameGroupList = gameGroupDao.selectByExample(gameGroupExample);
if(CollectionUtil.isNotEmpty(gameGroupList)){
List<ScreenVo.Group> groups = new ArrayList<>();
for(GameGroup gameGroup:gameGroupList){
ScreenVo.Group group = new ScreenVo.Group();
group.setGroupId(gameGroup.getId());
group.setGroupName(gameGroup.getName());
groups.add(group);
}
gameInfoVo.setGroups(groups);
}
switch (gameInfoVo.getGameStatus()){
//获取分组的信息
List<ScreenVo.GroupVo> groupVo = getGroupScore(gameRecord.getId());
gameInfoVo.setGroups(groupVo);
switch (gameInfoVo.getGameStatus()) {
case 0:
ScreenVo.PendingData pendingData = new ScreenVo.PendingData();
//查询活动规则
@ -236,9 +237,9 @@ public class ScreenService implements IScreenService{
break;
case 1:
ScreenVo.PreparingData preparingData = new ScreenVo.PreparingData();
if(ObjectUtil.isNull(params.getUserId())){
if (ObjectUtil.isNull(params.getUserId())) {
preparingData.setStartLocalTime(gameRecord.getStartTime() + gameRecord.getTimeDifference());
}else {
} else {
GameUserJoin userJoin = getGameUserJoin(params.getUserId(), gameRecord.getId());
log.info("用户信息:{}", userJoin);
if (userJoin == null) {
@ -254,9 +255,9 @@ public class ScreenService implements IScreenService{
//查询游戏是否有分组
GameType gameType = gameTypeDao.selectByPrimaryKey(gameUserPay.getGameTypeId());
ScreenVo.CompletedData completedData = null;
if(gameType.getIsGroup() == 0) {
if (gameType.getIsGroup() == 0) {
completedData = getCompletedData(memberRecord.getMemberRecord());
}else {
} else {
completedData = getCompletedDataByWin(memberRecord.getMemberRecord());
}
gameInfoVo.setCompletedData(completedData);
@ -268,7 +269,6 @@ public class ScreenService implements IScreenService{
}
/**
* 获取游戏状态
*/
@ -284,8 +284,9 @@ public class ScreenService implements IScreenService{
GameType gameType = gameTypeDao.selectByPrimaryKey(gameUserPay.getGameTypeId());
gameStatusVo.setGameStatus(gameRecord.getGameStatus());
//获取分组的信息
List<ScreenVo.GroupVo> groupVo = getGroupScore(gameRecord.getId());
gameStatusVo.setGroups(groupVo);
// 查询总人数
Long total = redisUtil.zsGetSize(GameConstant.generateGameKey(gameRecord.getId()));
log.info("redis查询gameRecordID:{}总人数:{}", gameRecord.getId(), total);
@ -296,41 +297,42 @@ public class ScreenService implements IScreenService{
}
gameStatusVo.setTotalMembers(total == null ? 0 : total.intValue());
switch (gameStatusVo.getGameStatus()){
case 0:
switch (gameStatusVo.getGameStatus()) {
case GameConstant.GAME_PENDING:
break;
case 1:
case GameConstant.GAME_PREPARATION:
ScreenVo.PreparingData preparingData = new ScreenVo.PreparingData();
if(ObjectUtil.isNull(params.getUserId())){
if (ObjectUtil.isNull(params.getUserId())) {
// 无userId,默认大屏,获取大屏的游戏开始时间
preparingData.setStartLocalTime(gameRecord.getStartTime() + gameRecord.getTimeDifference());
}else {
} else {
// 获取用户的开始时间
GameUserJoin userJoin = getGameUserJoin(params.getUserId(), gameRecord.getId());
preparingData.setStartLocalTime(gameRecord.getStartTime() + userJoin.getTimeDifference());
}
gameStatusVo.setPreparingData(preparingData);
break;
case 2:
case GameConstant.GAME_PROCESSING:
//查询游戏是否有分组
if(gameType.getIsGroup() == 0) {
if (gameType.getIsGroup() == 0) {
//普通游戏返回前十名的信息
ScreenVo.ProcessingData processingData = new ScreenVo.ProcessingData();
// 查询前十名(列表顺序即前十名顺序)
List<ScreenVo.TopUsers> tops = getTopUsers(gameRecordId);
processingData.setTopMembers(tops);
gameStatusVo.setProcessingData(processingData);
}else {
} else {
//分组游戏则返回每个分组的信息
List<ScreenVo.GroupVo> groupVoList = getGroupScore(gameRecordId);
gameStatusVo.setProcessingData(groupVoList);
}
break;
case 3:
case GameConstant.GAME_COMPLETED:
ScreenVo.CompletedData completedData = null;
if(gameType.getIsGroup() == 0) {
if (gameType.getIsGroup() == 0) {
completedData = getCompletedData(memberRecord.getMemberRecord());
}else {
} else {
completedData = getCompletedDataByWin(memberRecord.getMemberRecord());
}
gameStatusVo.setCompletedData(completedData);
@ -344,20 +346,21 @@ public class ScreenService implements IScreenService{
/**
* 进行中查询每个组的信息
*/
private List<ScreenVo.GroupVo> getGroupScore(Long gameRecordId){
private List<ScreenVo.GroupVo> getGroupScore(Long gameRecordId) {
List<ScreenVo.GroupVo> groupVoList = new ArrayList<>();
//查询分组信息
GameGroupExample gameGroupExample = new GameGroupExample();
gameGroupExample.createCriteria().andRecordIdEqualTo(gameRecordId);
List<GameGroup> gameGroupList = gameGroupDao.selectByExample(gameGroupExample);
if(CollectionUtil.isNotEmpty(gameGroupList)){
for(GameGroup gameGroup : gameGroupList){
if (CollectionUtil.isNotEmpty(gameGroupList)) {
for (GameGroup gameGroup : gameGroupList) {
ScreenVo.GroupVo groupVo = new ScreenVo.GroupVo();
groupVo.setGroupId(gameGroup.getId());
groupVo.setGroupName(gameGroup.getName());
groupVo.setCode(gameGroup.getCode());
Map<String,Object> group = getGroupTotalScore(gameGroup.getId());
if(CollectionUtil.isNotEmpty(group)){
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());
@ -381,17 +384,17 @@ public class ScreenService implements IScreenService{
GameGroupExample gameGroupExample = new GameGroupExample();
gameGroupExample.createCriteria().andRecordIdEqualTo(gameRecordId);
List<GameGroup> gameGroupList = gameGroupDao.selectByExample(gameGroupExample);
if(CollectionUtil.isNotEmpty(gameGroupList)){
if (CollectionUtil.isNotEmpty(gameGroupList)) {
List<GameUserJoin> userJoinList = null;
//分别查找两个队伍的总分
Map<String,Object> group1 = getGroupTotalScore(gameGroupList.get(0).getId());
Map<String,Object> group2 = getGroupTotalScore(gameGroupList.get(1).getId());
if(CollectionUtil.isNotEmpty(group1) && CollectionUtil.isNotEmpty(group2)){
Map<String, Object> group1 = getGroupTotalScore(gameGroupList.get(0).getId());
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");
if(score1 > score2){
if (score1 > score2) {
userJoinList = (List<GameUserJoin>) group1.get("userJoinList");
}else {
} else {
userJoinList = (List<GameUserJoin>) group2.get("userJoinList");
}
}
@ -400,27 +403,28 @@ public class ScreenService implements IScreenService{
}
return completedData;
}
/**
* 获取队伍的总分
*/
private Map<String,Object> getGroupTotalScore(Long groupId){
Map<String,Object> groupMap = null;
private Map<String, Object> getGroupTotalScore(Long groupId) {
Map<String, Object> groupMap = null;
//查找队伍的参赛人
GameUserJoinGroupExample joinGroupExample = new GameUserJoinGroupExample();
joinGroupExample.createCriteria().andGameGroupIdEqualTo(groupId);
List<GameUserJoinGroup> userJoinGroupList = gameUserJoinGroupDao.selectByExample(joinGroupExample);
if(CollectionUtil.isNotEmpty(userJoinGroupList)){
if (CollectionUtil.isNotEmpty(userJoinGroupList)) {
groupMap = new HashMap<>();
int totalScore = 0;
List<GameUserJoin> userJoinList = new ArrayList<>();
for (GameUserJoinGroup userJoinGroup : userJoinGroupList){
for (GameUserJoinGroup userJoinGroup : userJoinGroupList) {
GameUserJoin userJoin = gameUserJoinDao.selectByPrimaryKey(userJoinGroup.getUserJoinId());
totalScore += userJoin.getScore();
userJoinList.add(userJoin);
}
groupMap.put("totalScore",totalScore);
groupMap.put("userJoinList",userJoinList);
groupMap.put("totalScore", totalScore);
groupMap.put("userJoinList", userJoinList);
}
return groupMap;
}
@ -428,6 +432,7 @@ public class ScreenService implements IScreenService{
/**
* 查询总分数总次数平均以及前十名
*
* @param gameRecordId
* @return
*/
@ -441,10 +446,10 @@ public class ScreenService implements IScreenService{
//总分数
completedData.setTotalScore(totalScore);
// 总次数
completedData.setTotalTimes(totalScore/100);
completedData.setTotalTimes(totalScore / 100);
// 平均次数
int totalUsers = redisUtil.zsGetSize(key).intValue();
int averageTimes = completedData.getTotalTimes()/totalUsers;
int averageTimes = completedData.getTotalTimes() / totalUsers;
completedData.setAverageTimes(averageTimes);
// 平均超过多少用户
int averageScore = totalScore / totalUsers;
@ -458,7 +463,7 @@ public class ScreenService implements IScreenService{
GameUserJoinExample gameuserJoinExample = new GameUserJoinExample();
gameuserJoinExample.createCriteria().andRecordIdEqualTo(gameRecordId);
List<GameUserJoin> userJoins = gameUserJoinDao.selectByExample(gameuserJoinExample);
if(CollectionUtil.isNotEmpty(userJoins)){
if (CollectionUtil.isNotEmpty(userJoins)) {
completedData = getCompletedData(userJoins);
}
}
@ -471,6 +476,7 @@ public class ScreenService implements IScreenService{
/**
* 查询参加游戏的用户信息
*
* @param userId
* @param gameRecordId
* @return
@ -488,16 +494,17 @@ public class ScreenService implements IScreenService{
/**
* 查询游戏信息
*
* @param gameRecordId
* @return
*/
@Override
public GameRecord getGameRecord(long gameRecordId) {
String gameRecordStr = (String)redisUtil.get(GameConstant.generateGameStatusKey(gameRecordId));
String gameRecordStr = (String) redisUtil.get(GameConstant.generateGameStatusKey(gameRecordId));
GameRecord gameRecord = null;
if (StrUtil.isBlank(gameRecordStr)) {
gameRecord = gameRecordDao.selectByPrimaryKey(gameRecordId);
if(ObjectUtil.isNull(gameRecord)){
if (ObjectUtil.isNull(gameRecord)) {
throw new BaseException(CodeEnum.NOT_GAME_RECORD);
}
} else {
@ -508,6 +515,7 @@ public class ScreenService implements IScreenService{
/**
* 查询前十名
*
* @param gameRecordId
* @return
*/
@ -525,7 +533,7 @@ public class ScreenService implements IScreenService{
topUser.setHeadImgUrl(user.getAvatarUrl());
topUser.setNickname(user.getNickname());
topUser.setScore(type.getScore().intValue());
topUser.setTimes(type.getScore().intValue()/100);
topUser.setTimes(type.getScore().intValue() / 100);
finalTops.add(topUser);
});
@ -542,44 +550,52 @@ public class ScreenService implements IScreenService{
public String startAgain(QueryDto<ScreenDto.MemberRecord> params) throws Exception {
ScreenDto.MemberRecord memberRecord = params.getParam();
GameRecord gameRecord = gameRecordDao.selectByPrimaryKey(memberRecord.getMemberRecord());
if(ObjectUtil.isNull(gameRecord)){
if (ObjectUtil.isNull(gameRecord)) {
throw new BaseException(CodeEnum.NOT_GAME_RECORD);
}
GameUserPay gameUserPay = gameUserPayDao.selectByPrimaryKey(gameRecord.getUserPayId());
if(ObjectUtil.isNull(gameUserPay)){
if (ObjectUtil.isNull(gameUserPay)) {
throw new BaseException(CodeEnum.NOT_GAME_TYPE);
}
GameType gameType = gameTypeDao.selectByPrimaryKey(gameUserPay.getGameTypeId());
if(ObjectUtil.isNull(gameType)){
if (ObjectUtil.isNull(gameType)) {
throw new BaseException(CodeEnum.NOT_GAME_TYPE);
}
if(gameUserPay.getUsedCount() >= gameUserPay.getTotalCount()){
throw new BaseException(CodeEnum. GAME_NOT_TIMES);
if (gameUserPay.getUsedCount() >= gameUserPay.getTotalCount()) {
throw new BaseException(CodeEnum.GAME_NOT_TIMES);
}
GameRecord gameRecordNew = null;
if(gameRecord.getGameStatus() == 3){
if (gameRecord.getGameStatus() == 3) {
//添加一场新的游戏记录
gameRecordNew = new GameRecord();
gameRecordNew.setId(snowflake.nextId());
gameRecordNew.setUserPayId(gameUserPay.getId());
gameRecordNew.setUrl(WebConstant.TEST_URL_GAME + gameType.getScreenUrl() + "?id="+gameRecordNew.getId());
gameRecordNew.setQrCodeUrl(WebConstant.TEST_URL_GAME + gameRecordNew.getId() + File.separator + gameType.getClientUrl());
//添加路径
String gameUrl = WebConstant.TEST_URL_GAME_SQ;
switch (gameType.getCode()){
case GameConstant.GAME_TYPE_SQ: break;
case GameConstant.GAME_TYPE_SP: gameUrl = WebConstant.TEST_URL_GAME_SP ; break;
case GameConstant.GAME_TYPE_BH: gameUrl = WebConstant.TEST_URL_GAME_BH; break;
default:break;
}
gameRecordNew.setUrl(gameUrl + gameType.getScreenUrl() + "?id=" + gameRecordNew.getId());
gameRecordNew.setQrCodeUrl(gameUrl+ gameRecordNew.getId() + File.separator + gameType.getClientUrl());
gameRecordDao.insertSelective(gameRecordNew);
//修改购买的游戏的使用次数
gameUserPay.setUsedCount(gameUserPay.getUsedCount() + 1);
gameUserPayDao.updateByPrimaryKeySelective(gameUserPay);
//路径(添加项目id)
String url = gameRecord.getUrl() + "&projectId="+ memberRecord.getProjectId();
String url = gameRecord.getUrl() + "&projectId=" + memberRecord.getProjectId();
//给所有人发送消息发送消息
ChromeMessageDto chromeMessageDto = new ChromeMessageDto(url,gameRecord.getId(),memberRecord.getProjectId());
ChromeMessageDto chromeMessageDto = new ChromeMessageDto(url, gameRecord.getId(), memberRecord.getProjectId());
BaseMessageDto.MessageUser messageUser = null;
List<BaseMessageDto.MessageUser> messageUserList = new ArrayList<>();
//获取项目下所有成员
List<Long> memberIdList = tallFeignClient.getMemberIdListByProject(memberRecord.getProjectId());
if(CollectionUtil.isNotEmpty(memberIdList)){
for(Long memberId:memberIdList){
if (CollectionUtil.isNotEmpty(memberIdList)) {
for (Long memberId : memberIdList) {
messageUser = new BaseMessageDto.MessageUser();
messageUser.setUserId(memberId);
messageUserList.add(messageUser);
@ -588,7 +604,7 @@ public class ScreenService implements IScreenService{
chromeMessageDto.setReceivers(messageUserList);
messageService.sendGameMessageWithGetUrl(chromeMessageDto);
}else {
} else {
throw new BaseException(CodeEnum.GAME_NO_END);
}
return gameRecordNew.getUrl();
@ -598,10 +614,10 @@ public class ScreenService implements IScreenService{
* 查找活动规则
*/
@Override
public List<String> getGameActivityRule(Long gameTypeId){
public List<String> getGameActivityRule(Long gameTypeId) {
List<String> ruleList = new ArrayList<>();
if(ObjectUtil.isNotNull(gameTypeId)) {
if (ObjectUtil.isNotNull(gameTypeId)) {
GameActivityRuleExample activityRuleExample = new GameActivityRuleExample();
activityRuleExample.createCriteria().andGameIdEqualTo(gameTypeId);
List<GameActivityRule> gameActivityRuleList = activityRuleDao.selectByExample(activityRuleExample);
@ -613,14 +629,15 @@ public class ScreenService implements IScreenService{
}
return ruleList;
}
/**
* 查询活动奖品
*/
@Override
public List<String> getGameActivityPrize(Long gameTypeId){
public List<String> getGameActivityPrize(Long gameTypeId) {
List<String> prizeList = new ArrayList<>();
if(ObjectUtil.isNotNull(gameTypeId)) {
if (ObjectUtil.isNotNull(gameTypeId)) {
GameActivityPrizeExample activityPrizeExample = new GameActivityPrizeExample();
activityPrizeExample.createCriteria().andGameIdEqualTo(gameTypeId);
List<GameActivityPrize> gameActivityPrizeList = activityPrizeDao.selectByExample(activityPrizeExample);
@ -632,14 +649,15 @@ public class ScreenService implements IScreenService{
}
return prizeList;
}
/**
* 奖券使用说明表
*/
@Override
public List<String> getGamePrizeInstructions(Long gameTypeId){
public List<String> getGamePrizeInstructions(Long gameTypeId) {
List<String> instructionsList = new ArrayList<>();
if(ObjectUtil.isNotNull(gameTypeId)) {
if (ObjectUtil.isNotNull(gameTypeId)) {
GamePrizeInstructionsExample prizeInstructionsExample = new GamePrizeInstructionsExample();
prizeInstructionsExample.createCriteria().andGameIdEqualTo(gameTypeId);
List<GamePrizeInstructions> gamePrizeInstructionsList = prizeInstructionsDao.selectByExample(prizeInstructionsExample);
@ -655,21 +673,21 @@ public class ScreenService implements IScreenService{
/**
* 已结束时的返回值
*/
private ScreenVo.CompletedData getCompletedData(List<GameUserJoin> userJoinList){
private ScreenVo.CompletedData getCompletedData(List<GameUserJoin> userJoinList) {
ScreenVo.CompletedData completedData = new ScreenVo.CompletedData();
int totalTimes = 0;
int totalScore = 0;
int averageTimes = 0;
int over = 0;
if(CollectionUtil.isNotEmpty(userJoinList)){
for(GameUserJoin userJoin : userJoinList){
if (CollectionUtil.isNotEmpty(userJoinList)) {
for (GameUserJoin userJoin : userJoinList) {
totalTimes += userJoin.getTimes();
totalScore += userJoin.getScore();
}
averageTimes = totalTimes / userJoinList.size();
int a = 0;
for(GameUserJoin userJoin : userJoinList){
if(userJoin.getTimes() < averageTimes){
for (GameUserJoin userJoin : userJoinList) {
if (userJoin.getTimes() < averageTimes) {
a++;
}
}
@ -683,11 +701,9 @@ public class ScreenService implements IScreenService{
}
/**
* 开始游戏
*
* @param start
* @return
*/
@ -704,8 +720,10 @@ public class ScreenService implements IScreenService{
}
//判断游戏状态,仅未开始允许操作开始
switch (gameRecord.getGameStatus().byteValue()) {
case GameConstant.GAME_PREPARATION: throw new BaseException(CodeEnum.GAME_PREPARATION);
case GameConstant.GAME_PROCESSING: throw new BaseException(CodeEnum.GAME_PROCESSING);
case GameConstant.GAME_PREPARATION:
throw new BaseException(CodeEnum.GAME_PREPARATION);
case GameConstant.GAME_PROCESSING:
throw new BaseException(CodeEnum.GAME_PROCESSING);
case GameConstant.GAME_COMPLETED:
if (start.getStartStatus() == null || start.getStartStatus().byteValue() != GameConstant.GAME_RESTART_STATUS) {
throw new BaseException(CodeEnum.GAME_COMPLETED);
@ -716,7 +734,7 @@ public class ScreenService implements IScreenService{
gameRecord.setGameStatus(GameConstant.GAME_PREPARATION);
gameRecord.setStartTime(current + GameConstant.COUNT_DOWN_TIME);
gameRecord.setEndTime(gameRecord.getStartTime() + GameConstant.GAME_TIME);
gameRecord.setTimeDifference((int)moreTime);
gameRecord.setTimeDifference((int) moreTime);
gameRecordDao.updateByPrimaryKeySelective(gameRecord);
//设置redis 游戏状态 准备中
redisUtil.set(GameConstant.generateGameStatusKey(gameRecord.getId()), JSON.toJSONString(gameRecord), GameConstant.REDIS_TIME);
@ -727,7 +745,7 @@ public class ScreenService implements IScreenService{
delUserJoin.setRecStatus(WebConstant.REC_STATUS.Deleted.value);
GameUserJoinExample example = new GameUserJoinExample();
example.createCriteria().andRecordIdEqualTo(start.getMemberRecord());
gameUserJoinDao.updateByExampleSelective(delUserJoin,example);
gameUserJoinDao.updateByExampleSelective(delUserJoin, example);
redisUtil.del(GameConstant.generateGameKey(start.getMemberRecord()));
}
//延时通知
@ -758,7 +776,7 @@ public class ScreenService implements IScreenService{
GameUserJoin join = new GameUserJoin();
join.setId(user.getId());
join.setScore(score);
join.setTimes(score/100);
join.setTimes(score / 100);
gameUserJoinDao.updateByPrimaryKeySelective(join);
});
}
@ -778,8 +796,15 @@ public class ScreenService implements IScreenService{
List<GameUserJoin> userJoins = gameUserJoinDao.selectByExample(joinExample);
if (CollectionUtil.isNotEmpty(userJoins)) {
userJoins.forEach( userJoin -> {
ClientDto.RedisUser user = ClientDto.RedisUser.getInstance(userJoin);
userJoins.forEach(userJoin -> {
Long groupId = null;
GameUserJoinGroupExample joinGroupExample = new GameUserJoinGroupExample();
joinGroupExample.createCriteria().andUserJoinIdEqualTo(userJoin.getId());
List<GameUserJoinGroup> gameUserJoinGroups = gameUserJoinGroupDao.selectByExample(joinGroupExample);
if (CollectionUtil.isNotEmpty(gameUserJoinGroups)) {
groupId = gameUserJoinGroups.get(0).getGameGroupId();
}
ClientDto.RedisUser user = ClientDto.RedisUser.getInstance(userJoin, groupId);
redisUtil.zsSet(GameConstant.generateGameKey(gameRecord.getId()), JSON.toJSONString(user), 0, GameConstant.REDIS_TIME);
});
}
@ -791,16 +816,16 @@ public class ScreenService implements IScreenService{
}
/**
* 推送客户端状态
*
* @param gameRecord
* @param executor
*/
private void pushClient(GameRecord gameRecord, ScheduledExecutorService executor) {
new Thread(()->{
sendMsg.sendMsg(executor, 0, ()->{
new Thread(() -> {
sendMsg.sendMsg(executor, 0, () -> {
try {
//查询游戏用户,通知游戏倒计时
List<ClientDto.RedisUser> userJoins = sendMsg.getAllScore(gameRecord);
@ -811,7 +836,7 @@ public class ScreenService implements IScreenService{
}
});
long startTime = gameRecord.getStartTime() - System.currentTimeMillis();
sendMsg.sendMsg(executor, startTime > 0 ? startTime : 0, ()->{
sendMsg.sendMsg(executor, startTime > 0 ? startTime : 0, () -> {
//查询游戏用户,通知游戏开始
List<ClientDto.RedisUser> userJoins = sendMsg.getAllScore(gameRecord);
try {
@ -824,7 +849,7 @@ public class ScreenService implements IScreenService{
long endTime = gameRecord.getEndTime() - System.currentTimeMillis();
System.out.println("游戏结束");
sendMsg.sendMsg(executor, endTime > 0 ? endTime : 0, ()->{
sendMsg.sendMsg(executor, endTime > 0 ? endTime : 0, () -> {
try {
//查询游戏用户,通知游戏结束
List<ClientDto.RedisUser> userJoins = sendMsg.getAllScore(gameRecord);
@ -844,15 +869,15 @@ public class ScreenService implements IScreenService{
* 查询游戏类型id
*/
@Override
public Long getGameTypeId(Long recordId){
public Long getGameTypeId(Long recordId) {
Long gameTypeId = null;
GameRecord gameRecord = gameRecordDao.selectByPrimaryKey(recordId);
if(ObjectUtil.isNotNull(gameRecord)){
if (ObjectUtil.isNotNull(gameRecord)) {
//获取游戏的购买记录和类型
GameUserPay gameUserPay = gameUserPayDao.selectByPrimaryKey(gameRecord.getUserPayId());
if(ObjectUtil.isNotNull(gameUserPay)) {
if (ObjectUtil.isNotNull(gameUserPay)) {
GameType gameType = gameTypeDao.selectByPrimaryKey(gameUserPay.getGameTypeId());
if(ObjectUtil.isNotNull(gameType)){
if (ObjectUtil.isNotNull(gameType)) {
gameTypeId = gameType.getId();
}
}
@ -867,9 +892,9 @@ public class ScreenService implements IScreenService{
GameGroupExample gameGroupExample = new GameGroupExample();
gameGroupExample.createCriteria().andRecordIdEqualTo(recordId);
List<GameGroup> gameGroupList = gameGroupDao.selectByExample(gameGroupExample);
if(CollectionUtil.isNotEmpty(gameGroupList)){
if (CollectionUtil.isNotEmpty(gameGroupList)) {
groupList = new ArrayList<>();
for(GameGroup gameGroup:gameGroupList){
for (GameGroup gameGroup : gameGroupList) {
ScreenVo.Group group = new ScreenVo.Group();
group.setGroupId(gameGroup.getId());
group.setGroupName(gameGroup.getName());
@ -880,15 +905,15 @@ public class ScreenService implements IScreenService{
}
@Override
public ScreenVo.RecordInfo getRecordByTaskId(Long taskId,String gameType) {
public ScreenVo.RecordInfo getRecordByTaskId(Long taskId, String gameType) {
ScreenVo.RecordInfo recordInfo = new ScreenVo.RecordInfo();
GameRecordExample recordExample = new GameRecordExample();
recordExample.createCriteria().andTaskIdEqualTo(taskId);
recordExample.setOrderByClause("created_at DESC");
List<GameRecord> gameRecordList = gameRecordDao.selectByExample(recordExample);
if(CollectionUtil.isNotEmpty(gameRecordList)){
if(StrUtil.isNotEmpty(gameType)) {
if (CollectionUtil.isNotEmpty(gameRecordList)) {
if (StrUtil.isNotEmpty(gameType)) {
for (GameRecord record : gameRecordList) {
GameUserPay gameUserPay = gameUserPayDao.selectByPrimaryKey(record.getUserPayId());
if (ObjectUtil.isNotNull(gameUserPay)) {
@ -900,7 +925,7 @@ public class ScreenService implements IScreenService{
}
}
}
}else {
} else {
recordInfo.setId(gameRecordList.get(0).getId());
recordInfo.setGameStatus(gameRecordList.get(0).getGameStatus());
}

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

@ -6,6 +6,17 @@ package com.ccsens.game.util;
* @create: 2019/12/26 17:32
*/
public class GameConstant {
/**游戏类型:数钱*/
public static final String GAME_TYPE_SQ = "SQ";
/**游戏类型:赛跑*/
public static final String GAME_TYPE_SP = "SP";
/**游戏类型:拔河*/
public static final String GAME_TYPE_BH = "BH";
/**游戏类型:第一个队伍*/
public static final String FIRST_GROUP = "firstGroup";
/**游戏类型:第一个队伍*/
public static final String SECOND_GROUP = "secondGroup";
/**游戏状态:未开始*/
public static final byte GAME_PENDING = 0;

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

@ -1,6 +1,7 @@
package com.ccsens.game.util;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.ccsens.game.bean.dto.ClientDto;
import com.ccsens.game.bean.dto.message.ChangeStatusMessageDto;
@ -10,10 +11,12 @@ import com.ccsens.game.bean.po.GameGroupExample;
import com.ccsens.game.bean.po.GameRecord;
import com.ccsens.game.persist.dao.GameGroupDao;
import com.ccsens.game.persist.dao.GameUserJoinDao;
import com.ccsens.game.service.ClientService;
import com.ccsens.util.JacksonUtil;
import com.ccsens.util.RedisUtil;
import com.ccsens.util.config.RabbitMQConfig;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
@ -35,6 +38,8 @@ import java.util.concurrent.TimeUnit;
@Service
@Slf4j
public class SendMsg {
@Autowired
private ClientService clientService;
@Autowired
private GameUserJoinDao gameUserJoinDao;
@Autowired
@ -52,16 +57,16 @@ public class SendMsg {
return;
}
userJoins.forEach(join -> {
outs.add(getMsg(gameRecord, join, status));
outs.add(getMsg(userJoins, gameRecord, join, status));
});
if (CollectionUtil.isNotEmpty(outs)) {
rabbitTemplate.convertAndSend(RabbitMQConfig.GAME_STATUS, JacksonUtil.beanToJson(outs));
log.info("发送成功:{}",JacksonUtil.beanToJson(outs));
log.info("发送成功:{}", JacksonUtil.beanToJson(outs));
}
}
public GameMessageWithChangeStatusOut getMsg(GameRecord gameRecord, ClientDto.RedisUser join, byte gameStatus) {
public GameMessageWithChangeStatusOut getMsg(List<ClientDto.RedisUser> userJoins, GameRecord gameRecord, ClientDto.RedisUser join, byte gameStatus) {
GameMessageWithChangeStatusOut out = new GameMessageWithChangeStatusOut();
GameMessageWithChangeStatusOut.Data data = new GameMessageWithChangeStatusOut.Data();
@ -71,12 +76,32 @@ public class SendMsg {
ChangeStatusMessageDto dtos = new ChangeStatusMessageDto();
switch (gameStatus) {
case GameConstant.GAME_COMPLETED:
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);
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);
}
break;
case GameConstant.GAME_PREPARATION:
//preparingData
@ -115,9 +140,9 @@ public class SendMsg {
if (CollectionUtil.isNotEmpty(typedTuples)) {
List<ClientDto.RedisUser> userJoins = new ArrayList<>();
typedTuples.forEach( type -> {
ClientDto.RedisUser user = JSON.parseObject((String)type.getValue(), ClientDto.RedisUser.class);
user.setTimes(type.getScore().intValue()/100);
typedTuples.forEach(type -> {
ClientDto.RedisUser user = JSON.parseObject((String) type.getValue(), ClientDto.RedisUser.class);
user.setTimes(type.getScore().intValue() / 100);
user.setScore(type.getScore().intValue());
log.info("{} score: {}", type.getValue(), type.getScore());
Long sort = redisUtil.zsReverseRank(userKey, type.getValue());
@ -126,7 +151,7 @@ public class SendMsg {
Set<Object> overs = redisUtil.zsGetByScore(userKey, 0, user.getScore() - 1);
Long total = redisUtil.zsGetSize(userKey);
log.info("超过用户数:{},总用户数:{}", overs == null ? 0 : overs.size(), total);
user.setOver(overs == null || total == null || total.intValue() == 0 ? 0 : overs.size()*100/total.intValue());
user.setOver(overs == null || total == null || total.intValue() == 0 ? 0 : overs.size() * 100 / total.intValue());
userJoins.add(user);
});
return userJoins;
@ -134,4 +159,6 @@ public class SendMsg {
}
return null;
}
}

29
game/src/main/resources/mapper_raw/GameGroupMapper.xml

@ -4,6 +4,7 @@
<resultMap id="BaseResultMap" type="com.ccsens.game.bean.po.GameGroup">
<id column="id" jdbcType="BIGINT" property="id" />
<result column="record_id" jdbcType="BIGINT" property="recordId" />
<result column="code" jdbcType="VARCHAR" property="code" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
<result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt" />
@ -68,7 +69,7 @@
</where>
</sql>
<sql id="Base_Column_List">
id, record_id, name, created_at, updated_at, rec_status
id, record_id, code, name, created_at, updated_at, rec_status
</sql>
<select id="selectByExample" parameterType="com.ccsens.game.bean.po.GameGroupExample" resultMap="BaseResultMap">
select
@ -101,12 +102,12 @@
</if>
</delete>
<insert id="insert" parameterType="com.ccsens.game.bean.po.GameGroup">
insert into t_game_group (id, record_id, name,
created_at, updated_at, rec_status
)
values (#{id,jdbcType=BIGINT}, #{recordId,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR},
#{createdAt,jdbcType=TIMESTAMP}, #{updatedAt,jdbcType=TIMESTAMP}, #{recStatus,jdbcType=TINYINT}
)
insert into t_game_group (id, record_id, code,
name, created_at, updated_at,
rec_status)
values (#{id,jdbcType=BIGINT}, #{recordId,jdbcType=BIGINT}, #{code,jdbcType=VARCHAR},
#{name,jdbcType=VARCHAR}, #{createdAt,jdbcType=TIMESTAMP}, #{updatedAt,jdbcType=TIMESTAMP},
#{recStatus,jdbcType=TINYINT})
</insert>
<insert id="insertSelective" parameterType="com.ccsens.game.bean.po.GameGroup">
insert into t_game_group
@ -117,6 +118,9 @@
<if test="recordId != null">
record_id,
</if>
<if test="code != null">
code,
</if>
<if test="name != null">
name,
</if>
@ -137,6 +141,9 @@
<if test="recordId != null">
#{recordId,jdbcType=BIGINT},
</if>
<if test="code != null">
#{code,jdbcType=VARCHAR},
</if>
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
@ -166,6 +173,9 @@
<if test="record.recordId != null">
record_id = #{record.recordId,jdbcType=BIGINT},
</if>
<if test="record.code != null">
code = #{record.code,jdbcType=VARCHAR},
</if>
<if test="record.name != null">
name = #{record.name,jdbcType=VARCHAR},
</if>
@ -187,6 +197,7 @@
update t_game_group
set id = #{record.id,jdbcType=BIGINT},
record_id = #{record.recordId,jdbcType=BIGINT},
code = #{record.code,jdbcType=VARCHAR},
name = #{record.name,jdbcType=VARCHAR},
created_at = #{record.createdAt,jdbcType=TIMESTAMP},
updated_at = #{record.updatedAt,jdbcType=TIMESTAMP},
@ -201,6 +212,9 @@
<if test="recordId != null">
record_id = #{recordId,jdbcType=BIGINT},
</if>
<if test="code != null">
code = #{code,jdbcType=VARCHAR},
</if>
<if test="name != null">
name = #{name,jdbcType=VARCHAR},
</if>
@ -219,6 +233,7 @@
<update id="updateByPrimaryKey" parameterType="com.ccsens.game.bean.po.GameGroup">
update t_game_group
set record_id = #{recordId,jdbcType=BIGINT},
code = #{code,jdbcType=VARCHAR},
name = #{name,jdbcType=VARCHAR},
created_at = #{createdAt,jdbcType=TIMESTAMP},
updated_at = #{updatedAt,jdbcType=TIMESTAMP},

4
game/src/main/resources/mbg.xml

@ -57,14 +57,14 @@
</javaClientGenerator>
<!-- <table tableName="t_game_type" domainObjectName="GameType"></table>-->
<!--<table tableName="t_game_user_pay" domainObjectName="GameUserPay"></table>-->
<table tableName="t_game_record" domainObjectName="GameRecord"></table>
<!-- <table tableName="t_game_record" domainObjectName="GameRecord"></table>-->
<!-- <table tableName="t_game_user_join" domainObjectName="GameUserJoin"></table>-->
<!--<table tableName="t_game_score_log" domainObjectName="GameScoreLog"></table>-->
<!--<table tableName="t_game_activity_rule" domainObjectName="GameActivityRule"></table>-->
<!--<table tableName="t_game_activity_prize" domainObjectName="GameActivityPrize"></table>-->
<!--<table tableName="t_game_prize_instructions" domainObjectName="GamePrizeInstructions"></table>-->
<!-- <table tableName="t_game_user_join_group" domainObjectName="GameUserJoinGroup"></table>-->
<!-- <table tableName="t_game_group" domainObjectName="GameGroup"></table>-->
<table tableName="t_game_group" domainObjectName="GameGroup"></table>
<!-- 有些表的字段需要指定java类型

11
mt/src/main/java/com/ccsens/mt/bean/po/MtSigninBasic.java

@ -10,6 +10,8 @@ public class MtSigninBasic implements Serializable {
private Long taskPluginId;
private Long taskId;
private Long signinTime;
private Integer sequence;
@ -48,6 +50,14 @@ public class MtSigninBasic implements Serializable {
this.taskPluginId = taskPluginId;
}
public Long getTaskId() {
return taskId;
}
public void setTaskId(Long taskId) {
this.taskId = taskId;
}
public Long getSigninTime() {
return signinTime;
}
@ -105,6 +115,7 @@ public class MtSigninBasic implements Serializable {
sb.append(", id=").append(id);
sb.append(", userId=").append(userId);
sb.append(", taskPluginId=").append(taskPluginId);
sb.append(", taskId=").append(taskId);
sb.append(", signinTime=").append(signinTime);
sb.append(", sequence=").append(sequence);
sb.append(", isSign=").append(isSign);

60
mt/src/main/java/com/ccsens/mt/bean/po/MtSigninBasicExample.java

@ -285,6 +285,66 @@ public class MtSigninBasicExample {
return (Criteria) this;
}
public Criteria andTaskIdIsNull() {
addCriterion("task_id is null");
return (Criteria) this;
}
public Criteria andTaskIdIsNotNull() {
addCriterion("task_id is not null");
return (Criteria) this;
}
public Criteria andTaskIdEqualTo(Long value) {
addCriterion("task_id =", value, "taskId");
return (Criteria) this;
}
public Criteria andTaskIdNotEqualTo(Long value) {
addCriterion("task_id <>", value, "taskId");
return (Criteria) this;
}
public Criteria andTaskIdGreaterThan(Long value) {
addCriterion("task_id >", value, "taskId");
return (Criteria) this;
}
public Criteria andTaskIdGreaterThanOrEqualTo(Long value) {
addCriterion("task_id >=", value, "taskId");
return (Criteria) this;
}
public Criteria andTaskIdLessThan(Long value) {
addCriterion("task_id <", value, "taskId");
return (Criteria) this;
}
public Criteria andTaskIdLessThanOrEqualTo(Long value) {
addCriterion("task_id <=", value, "taskId");
return (Criteria) this;
}
public Criteria andTaskIdIn(List<Long> values) {
addCriterion("task_id in", values, "taskId");
return (Criteria) this;
}
public Criteria andTaskIdNotIn(List<Long> values) {
addCriterion("task_id not in", values, "taskId");
return (Criteria) this;
}
public Criteria andTaskIdBetween(Long value1, Long value2) {
addCriterion("task_id between", value1, value2, "taskId");
return (Criteria) this;
}
public Criteria andTaskIdNotBetween(Long value1, Long value2) {
addCriterion("task_id not between", value1, value2, "taskId");
return (Criteria) this;
}
public Criteria andSigninTimeIsNull() {
addCriterion("signin_time is null");
return (Criteria) this;

51
mt/src/main/java/com/ccsens/mt/service/SigninService.java

@ -202,32 +202,35 @@ public class SigninService implements ISigninService{
@Override
public List<SigninVo.GetSignInfoVo> getSignVoAllByTaskId(Long taskPluginId, Long userId) {
List<SigninVo.GetSignInfoVo> getSignInfoVoList = new ArrayList<>();
//1.查找所有签到的用户
MtSigninBasicExample signinBasicExample = new MtSigninBasicExample();
signinBasicExample.createCriteria().andTaskPluginIdEqualTo(taskPluginId);
List<MtSigninBasic> signinBasicList = signinBasicDao.selectByExample(signinBasicExample);
if(CollectionUtil.isNotEmpty(signinBasicList)){
for(MtSigninBasic mtSigninBasic : signinBasicList){
SigninVo.GetSignInfoVo signInfoVo = new SigninVo.GetSignInfoVo();
//已签到,返回签到的信息
List<SigninVo.SaveSignInfo> saveSignInfos = new ArrayList<>();
MtSigninOtherExample signinOtherExample = new MtSigninOtherExample();
signinOtherExample.createCriteria().andSigninBasicIdEqualTo(mtSigninBasic.getId());
List<MtSigninOther> signinOtherList = signinOtherDao.selectByExample(signinOtherExample);
if(CollectionUtil.isNotEmpty(signinOtherList)){
for (MtSigninOther signinOther : signinOtherList){
SigninVo.SaveSignInfo saveSignInfo = new SigninVo.SaveSignInfo();
saveSignInfo.setKey(signinOther.getsKey());
saveSignInfo.setValue(signinOther.getsValue());
saveSignInfos.add(saveSignInfo);
//根据pluginId查询任务id
Long taskId = tallFeignClient.getTaskIdByTaskPluginId(taskPluginId);
if(ObjectUtil.isNotNull(taskId)){
//1.查找所有签到的用户
MtSigninBasicExample signinBasicExample = new MtSigninBasicExample();
signinBasicExample.createCriteria().andTaskIdEqualTo(taskId);
List<MtSigninBasic> signinBasicList = signinBasicDao.selectByExample(signinBasicExample);
if(CollectionUtil.isNotEmpty(signinBasicList)){
for(MtSigninBasic mtSigninBasic : signinBasicList){
SigninVo.GetSignInfoVo signInfoVo = new SigninVo.GetSignInfoVo();
//已签到,返回签到的信息
List<SigninVo.SaveSignInfo> saveSignInfos = new ArrayList<>();
MtSigninOtherExample signinOtherExample = new MtSigninOtherExample();
signinOtherExample.createCriteria().andSigninBasicIdEqualTo(mtSigninBasic.getId());
List<MtSigninOther> signinOtherList = signinOtherDao.selectByExample(signinOtherExample);
if(CollectionUtil.isNotEmpty(signinOtherList)){
for (MtSigninOther signinOther : signinOtherList){
SigninVo.SaveSignInfo saveSignInfo = new SigninVo.SaveSignInfo();
saveSignInfo.setKey(signinOther.getsKey());
saveSignInfo.setValue(signinOther.getsValue());
saveSignInfos.add(saveSignInfo);
}
}
signInfoVo.setIsSign(1);
signInfoVo.setSequence(mtSigninBasic.getSequence());
signInfoVo.setSignTime(mtSigninBasic.getSigninTime());
signInfoVo.setSignField(saveSignInfos);
getSignInfoVoList.add(signInfoVo);
}
signInfoVo.setIsSign(1);
signInfoVo.setSequence(mtSigninBasic.getSequence());
signInfoVo.setSignTime(mtSigninBasic.getSigninTime());
signInfoVo.setSignField(saveSignInfos);
getSignInfoVoList.add(signInfoVo);
}
}
return getSignInfoVoList;

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

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

31
mt/src/main/resources/mapper_raw/MtSigninBasicMapper.xml

@ -5,6 +5,7 @@
<id column="id" jdbcType="BIGINT" property="id" />
<result column="user_id" jdbcType="BIGINT" property="userId" />
<result column="task_plugin_id" jdbcType="BIGINT" property="taskPluginId" />
<result column="task_id" jdbcType="BIGINT" property="taskId" />
<result column="signin_time" jdbcType="BIGINT" property="signinTime" />
<result column="sequence" jdbcType="INTEGER" property="sequence" />
<result column="is_sign" jdbcType="TINYINT" property="isSign" />
@ -71,8 +72,8 @@
</where>
</sql>
<sql id="Base_Column_List">
id, user_id, task_plugin_id, signin_time, sequence, is_sign, created_at, updated_at,
rec_status
id, user_id, task_plugin_id, task_id, signin_time, sequence, is_sign, created_at,
updated_at, rec_status
</sql>
<select id="selectByExample" parameterType="com.ccsens.mt.bean.po.MtSigninBasicExample" resultMap="BaseResultMap">
select
@ -106,13 +107,13 @@
</delete>
<insert id="insert" parameterType="com.ccsens.mt.bean.po.MtSigninBasic">
insert into t_mt_signin_basic (id, user_id, task_plugin_id,
signin_time, sequence, is_sign,
created_at, updated_at, rec_status
)
task_id, signin_time, sequence,
is_sign, created_at, updated_at,
rec_status)
values (#{id,jdbcType=BIGINT}, #{userId,jdbcType=BIGINT}, #{taskPluginId,jdbcType=BIGINT},
#{signinTime,jdbcType=BIGINT}, #{sequence,jdbcType=INTEGER}, #{isSign,jdbcType=TINYINT},
#{createdAt,jdbcType=TIMESTAMP}, #{updatedAt,jdbcType=TIMESTAMP}, #{recStatus,jdbcType=TINYINT}
)
#{taskId,jdbcType=BIGINT}, #{signinTime,jdbcType=BIGINT}, #{sequence,jdbcType=INTEGER},
#{isSign,jdbcType=TINYINT}, #{createdAt,jdbcType=TIMESTAMP}, #{updatedAt,jdbcType=TIMESTAMP},
#{recStatus,jdbcType=TINYINT})
</insert>
<insert id="insertSelective" parameterType="com.ccsens.mt.bean.po.MtSigninBasic">
insert into t_mt_signin_basic
@ -126,6 +127,9 @@
<if test="taskPluginId != null">
task_plugin_id,
</if>
<if test="taskId != null">
task_id,
</if>
<if test="signinTime != null">
signin_time,
</if>
@ -155,6 +159,9 @@
<if test="taskPluginId != null">
#{taskPluginId,jdbcType=BIGINT},
</if>
<if test="taskId != null">
#{taskId,jdbcType=BIGINT},
</if>
<if test="signinTime != null">
#{signinTime,jdbcType=BIGINT},
</if>
@ -193,6 +200,9 @@
<if test="record.taskPluginId != null">
task_plugin_id = #{record.taskPluginId,jdbcType=BIGINT},
</if>
<if test="record.taskId != null">
task_id = #{record.taskId,jdbcType=BIGINT},
</if>
<if test="record.signinTime != null">
signin_time = #{record.signinTime,jdbcType=BIGINT},
</if>
@ -221,6 +231,7 @@
set id = #{record.id,jdbcType=BIGINT},
user_id = #{record.userId,jdbcType=BIGINT},
task_plugin_id = #{record.taskPluginId,jdbcType=BIGINT},
task_id = #{record.taskId,jdbcType=BIGINT},
signin_time = #{record.signinTime,jdbcType=BIGINT},
sequence = #{record.sequence,jdbcType=INTEGER},
is_sign = #{record.isSign,jdbcType=TINYINT},
@ -240,6 +251,9 @@
<if test="taskPluginId != null">
task_plugin_id = #{taskPluginId,jdbcType=BIGINT},
</if>
<if test="taskId != null">
task_id = #{taskId,jdbcType=BIGINT},
</if>
<if test="signinTime != null">
signin_time = #{signinTime,jdbcType=BIGINT},
</if>
@ -265,6 +279,7 @@
update t_mt_signin_basic
set user_id = #{userId,jdbcType=BIGINT},
task_plugin_id = #{taskPluginId,jdbcType=BIGINT},
task_id = #{taskId,jdbcType=BIGINT},
signin_time = #{signinTime,jdbcType=BIGINT},
sequence = #{sequence,jdbcType=INTEGER},
is_sign = #{isSign,jdbcType=TINYINT},

1
tall/src/main/java/com/ccsens/tall/config/SpringConfig.java

@ -145,6 +145,7 @@ public class SpringConfig implements WebMvcConfigurer {
.addPathPatterns("/plugins/**")
.excludePathPatterns("/plugins/sign")
.excludePathPatterns("/plugins/fuzzy")
.excludePathPatterns("/plugins/task")
.addPathPatterns("/delivers/**")
.addPathPatterns("/tasks/**")
.excludePathPatterns("/tasks/projectId")

2
tall/src/main/java/com/ccsens/tall/service/ISysPluginService.java

@ -10,4 +10,6 @@ public interface ISysPluginService {
List<PluginVo.PluginSignField> getSignByPlugin(Long taskPluginId);
List<String> getSignFuzzy(Long taskPluginId, String signinName, String key);
Long getTaskDetailIdByPlugin(Long taskPluginId);
}

11
tall/src/main/java/com/ccsens/tall/service/SysPluginService.java

@ -105,4 +105,15 @@ public class SysPluginService implements ISysPluginService{
}
return keys;
}
@Override
public Long getTaskDetailIdByPlugin(Long taskPluginId) {
Long taskDetailId = null;
ProTaskPlugin taskPlugin = taskPluginDao.selectByPrimaryKey(taskPluginId);
if(ObjectUtil.isNotNull(taskPlugin)){
taskDetailId = taskPlugin.getTaskDetailId();
}
return taskDetailId;
}
}

12
tall/src/main/java/com/ccsens/tall/web/PluginController.java

@ -57,4 +57,16 @@ public class PluginController {
return keys;
}
/**
* 通过插件id查询签到的信息
*/
@RequestMapping(value = "/task", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
public Long getTaskDetailIdByPlugin(Long taskPluginId) throws Exception {
Long taskDetailId = sysPluginService.getTaskDetailIdByPlugin(taskPluginId);
return taskDetailId;
}
}

4
util/src/main/java/com/ccsens/util/WebConstant.java

@ -74,7 +74,9 @@ public class WebConstant {
public static final String UPLOAD_PROJECT_WBS = UPLOAD_PATH_BASE + File.separator + "project";
public static final String URL_BASE = "https://api.ccsens.com/ptpro/uploads/";
public static final String TEST_URL = "https://test.tall.wiki/";
public static final String TEST_URL_GAME = TEST_URL + "game-dev/";
public static final String TEST_URL_GAME_SQ = TEST_URL + "game-dev/";
public static final String TEST_URL_GAME_SP = TEST_URL + "game-sp/";
public static final String TEST_URL_GAME_BH = TEST_URL + "game-bh/";
public static final String TEST_URL_BASE = TEST_URL + "gateway/tall/v1.0/uploads/";
public static final Integer Expired_Verify_Code_In_Seconds = 120;

Loading…
Cancel
Save