From 5ab018fd483dac88a31a1136d8f24cb57e2fc4bc Mon Sep 17 00:00:00 2001 From: zy_Java <654600784@qq.com> Date: Thu, 20 Aug 2020 09:05:34 +0800 Subject: [PATCH] =?UTF-8?q?0905=5F1.0=E9=98=9F=E4=BC=8D=E5=88=86=E6=95=B0?= =?UTF-8?q?=E5=AD=98redis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ccsens/game/bean/vo/ScreenVo.java | 2 +- .../com/ccsens/game/mq/GameScoreListener.java | 3 +- .../game/netty/wsserver/WebSocketHandler.java | 11 ++++++ .../ccsens/game/service/ScreenService.java | 38 ++++++++++++++++--- game/src/main/resources/application-dev.yml | 5 ++- game/src/main/resources/application-prod.yml | 3 +- game/src/main/resources/application-test.yml | 3 +- tall/src/main/resources/application.yml | 4 +- 8 files changed, 55 insertions(+), 14 deletions(-) diff --git a/game/src/main/java/com/ccsens/game/bean/vo/ScreenVo.java b/game/src/main/java/com/ccsens/game/bean/vo/ScreenVo.java index 2c38b461..1fcd26d4 100644 --- a/game/src/main/java/com/ccsens/game/bean/vo/ScreenVo.java +++ b/game/src/main/java/com/ccsens/game/bean/vo/ScreenVo.java @@ -159,7 +159,7 @@ public class ScreenVo { @ApiModelProperty("头像") private String headPortraitUrl; @ApiModelProperty("该组的总分/均分") - private int score; + private Integer score; @ApiModelProperty("该组总人数") private int totalMembers; @ApiModelProperty("code") diff --git a/game/src/main/java/com/ccsens/game/mq/GameScoreListener.java b/game/src/main/java/com/ccsens/game/mq/GameScoreListener.java index 2dcdcd2b..ccb4a5fd 100644 --- a/game/src/main/java/com/ccsens/game/mq/GameScoreListener.java +++ b/game/src/main/java/com/ccsens/game/mq/GameScoreListener.java @@ -99,9 +99,8 @@ public class GameScoreListener { gameMessageCountOut.getData().setTotalTimes(score/100); return gameMessageCountOut; } - }; + } return gameMessageCountOut; } - } diff --git a/game/src/main/java/com/ccsens/game/netty/wsserver/WebSocketHandler.java b/game/src/main/java/com/ccsens/game/netty/wsserver/WebSocketHandler.java index 705d778a..ffc96f45 100644 --- a/game/src/main/java/com/ccsens/game/netty/wsserver/WebSocketHandler.java +++ b/game/src/main/java/com/ccsens/game/netty/wsserver/WebSocketHandler.java @@ -4,8 +4,10 @@ package com.ccsens.game.netty.wsserver; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.ccsens.game.bean.dto.ClientDto; import com.ccsens.game.bean.dto.message.*; +import com.ccsens.game.bean.po.GameGroup; import com.ccsens.game.netty.ChannelManager; import com.ccsens.game.service.IClientService; import com.ccsens.game.service.IMessageService; @@ -171,6 +173,15 @@ public class WebSocketHandler extends SimpleChannelInboundHandler objectSet = redisUtil.zsGet(groupKey, 0, -1); + objectSet.forEach(o -> { + GameGroup gameGroup = JSONObject.parseObject((String) o, GameGroup.class); + if(gameGroup.getId().longValue() == user.getGroupId().longValue()){ + Double o1 = (Double)redisUtil.zsGetScore(groupKey, o); + redisUtil.zsSet(groupKey, o, o1 + 100,600); + } + }); gameMessageCountOut.getData().setTotalScore(score); gameMessageCountOut.getData().setTotalTimes(score/100); return gameMessageCountOut; diff --git a/game/src/main/java/com/ccsens/game/service/ScreenService.java b/game/src/main/java/com/ccsens/game/service/ScreenService.java index e7e8931c..06ebfd9a 100644 --- a/game/src/main/java/com/ccsens/game/service/ScreenService.java +++ b/game/src/main/java/com/ccsens/game/service/ScreenService.java @@ -7,6 +7,7 @@ import cn.hutool.core.lang.Snowflake; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.ccsens.cloudutil.bean.tall.dto.WpsDto; import com.ccsens.cloudutil.feign.TallFeignClient; import com.ccsens.game.bean.dto.ClientDto; @@ -253,13 +254,13 @@ public class ScreenService implements IScreenService { if(ObjectUtil.isNotNull(groupRow)){ String groupName = ExcelUtil.getCellValue(groupRow.getCell(0)); String groupUrl = ExcelUtil.getCellValue(groupRow.getCell(1)); - if(ObjectUtil.isNotNull(groupName)){ + if(StrUtil.isNotEmpty(groupName)){ GameGroup gameGroup = new GameGroup(); gameGroup.setId(snowflake.nextId()); gameGroup.setRecordId(gameRecord.getId()); gameGroup.setName(groupName); // gameGroup.setCode(GameConstant.FIRST_GROUP); - if(ObjectUtil.isNotNull(groupUrl)){ + if(StrUtil.isNotEmpty(groupUrl)){ gameGroup.setHeadPortraitUrl(groupUrl); } gameGroupDao.insertSelective(gameGroup); @@ -280,14 +281,16 @@ public class ScreenService implements IScreenService { recordExample.setOrderByClause("created_at DESC"); List recordList = gameRecordDao.selectByExample(recordExample); if (CollectionUtil.isNotEmpty(recordList)) { + GameRecord record1 = new GameRecord(); GameRecord record = recordList.get(0); if(record.getGameStatus() == GameConstant.GAME_PREPARATION || record.getGameStatus() == GameConstant.GAME_PROCESSING){ throw new BaseException(CodeEnum.GAME_NO_END); } if(record.getGameStatus() == GameConstant.GAME_PENDING){ - record.setGameStatus(GameConstant.GAME_COMPLETED); - gameRecordDao.updateByPrimaryKeySelective(record); + record1.setId(record.getId()); + record1.setGameStatus(GameConstant.GAME_COMPLETED); + gameRecordDao.updateByPrimaryKeySelective(record1); } } } @@ -590,6 +593,22 @@ public class ScreenService implements IScreenService { * 进行中查询每个组的信息 */ private List getGroupScore2(GameRecord gameRecord) { + String groupKey = gameRecord.getId() + "_group"; + Set> typedTuples = redisUtil.zsRevGetWithScore(groupKey, 0, -1); + if(CollectionUtil.isNotEmpty(typedTuples)){ + List vos = new ArrayList<>(); + typedTuples.forEach(type -> { + GameGroup gameGroup = JSON.parseObject((String)type.getValue(), GameGroup.class); + int score = type.getScore().intValue(); + ScreenVo.GroupVo groupVo = new ScreenVo.GroupVo(); + groupVo.setGroupId(gameGroup.getId()); + groupVo.setGroupName(gameGroup.getName()); + groupVo.setScore(score); + groupVo.setHeadPortraitUrl(gameGroup.getHeadPortraitUrl()); + vos.add(groupVo); + }); + return vos; + } List vos = gameGroupDao.queryGroups(gameRecord.getId()); if (CollectionUtil.isEmpty(vos) || gameRecord.getRankRule() == GameConstant.RANK_RULE_TOTAL) { return vos; @@ -1028,6 +1047,15 @@ public class ScreenService implements IScreenService { gameRecordDao.updateByPrimaryKeySelective(gameRecord); //设置redis 游戏状态 准备中 redisUtil.set(GameConstant.generateGameStatusKey(gameRecord.getId()), JSON.toJSONString(gameRecord), GameConstant.REDIS_TIME); + String groupKey = gameRecord.getId() + "_group"; + GameGroupExample groupExample = new GameGroupExample(); + groupExample.createCriteria().andRecordIdEqualTo(gameRecord.getId()); + List gameGroupList = gameGroupDao.selectByExample(groupExample); + if(CollectionUtil.isNotEmpty(gameGroupList)){ + gameGroupList.forEach(gameGroup -> { + redisUtil.zsSet(groupKey, JSONObject.toJSONString(gameGroup),0,600); + }); + } //再玩一次 if (start.getStartStatus() != null && start.getStartStatus().byteValue() == GameConstant.GAME_RESTART_STATUS) { //再玩一次,设置参见的用户为无效用户 @@ -1200,7 +1228,7 @@ public class ScreenService implements IScreenService { GameRecordExample recordExample = new GameRecordExample(); recordExample.createCriteria().andTaskIdEqualTo(taskId); - recordExample.setOrderByClause("created_at DESC"); + recordExample.setOrderByClause("id DESC"); List gameRecordList = gameRecordDao.selectByExample(recordExample); if (CollectionUtil.isNotEmpty(gameRecordList)) { if (StrUtil.isNotEmpty(gameType)) { diff --git a/game/src/main/resources/application-dev.yml b/game/src/main/resources/application-dev.yml index b5bcc059..9e0b4c23 100644 --- a/game/src/main/resources/application-dev.yml +++ b/game/src/main/resources/application-dev.yml @@ -8,7 +8,7 @@ spring: datasource: type: com.alibaba.druid.pool.DruidDataSource rabbitmq: - host: 192.168.0.99 + host: 81.70.54.64 password: 111111 port: 5672 username: admin @@ -29,4 +29,5 @@ swagger: gatewayUrl: https://test.tall.wiki/gateway/ notGatewayUrl: https://test.tall.wiki/ -qrCode: https://test.tall.wiki/gateway/tall/uploads/ +file: + qrCode: https://test.tall.wiki/gateway/tall/uploads/ diff --git a/game/src/main/resources/application-prod.yml b/game/src/main/resources/application-prod.yml index bd7e6b13..c0f6363e 100644 --- a/game/src/main/resources/application-prod.yml +++ b/game/src/main/resources/application-prod.yml @@ -32,4 +32,5 @@ eureka: gatewayUrl: https://www.tall.wiki/gateway/ notGatewayUrl: https://www.tall.wiki/ -qrCode: https://www.tall.wiki/gateway/tall/uploads/ \ No newline at end of file +file: + qrCode: https://www.tall.wiki/gateway/tall/v1.0/uploads/ \ No newline at end of file diff --git a/game/src/main/resources/application-test.yml b/game/src/main/resources/application-test.yml index f34f76ef..31d43e97 100644 --- a/game/src/main/resources/application-test.yml +++ b/game/src/main/resources/application-test.yml @@ -32,4 +32,5 @@ eureka: gatewayUrl: https://test.tall.wiki/gateway/ notGatewayUrl: https://test.tall.wiki/ -qrCode: https://test.tall.wiki/gateway/tall/uploads/ \ No newline at end of file +file: + qrCode: https://test.tall.wiki/gateway/tall/v1.0/uploads/ \ No newline at end of file diff --git a/tall/src/main/resources/application.yml b/tall/src/main/resources/application.yml index c88e995d..b2acd365 100644 --- a/tall/src/main/resources/application.yml +++ b/tall/src/main/resources/application.yml @@ -1,4 +1,4 @@ spring: profiles: - active: test - include: util-test,common + active: dev + include: util-dev,common