From 6e801ec2033173a1495ed24e188669401225d56a Mon Sep 17 00:00:00 2001 From: zy_Java <654600784@qq.com> Date: Tue, 8 Dec 2020 20:27:04 +0800 Subject: [PATCH] =?UTF-8?q?20201208mq=E5=B9=BF=E6=92=AD=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/application-util-prodsd.yml | 69 ++++++++ .../com/ccsens/game/api/DebugController.java | 22 +++ .../com/ccsens/game/bean/vo/ScreenVo.java | 8 +- .../com/ccsens/game/netty/ChannelManager.java | 49 ++++++ .../ccsens/game/service/RabbitMQListener.java | 6 +- .../service/RabbitMQListenerGameTest.java | 27 +++ .../ccsens/game/service/ScreenService.java | 166 ++++++++---------- .../com/ccsens/game/util/GameConstant.java | 7 +- game/src/main/resources/application-prod.yml | 6 +- .../src/main/resources/application-prodsd.yml | 40 +++++ game/src/main/resources/application.yml | 4 +- game/src/main/resources/druid-prodsd.yml | 33 ++++ .../src/main/resources/application-prod.yml | 3 +- health/src/main/resources/application.yml | 4 +- ht/src/main/resources/application-prod.yml | 10 +- mt/src/main/resources/application-prod.yml | 3 +- tall/src/main/resources/application-prod.yml | 4 +- .../src/main/resources/application-prodsd.yml | 44 +++++ tall/src/main/resources/druid-prodsd.yml | 33 ++++ tall/src/main/resources/logback-spring.xml | 2 +- .../main/java/com/ccsens/util/RedisUtil.java | 26 +-- .../ccsens/util/config/RabbitMQConfig.java | 25 ++- .../test/java/com/ccsens/util/FileTest.java | 40 +++++ 23 files changed, 501 insertions(+), 130 deletions(-) create mode 100644 cloudutil/src/main/resources/application-util-prodsd.yml create mode 100644 game/src/main/java/com/ccsens/game/service/RabbitMQListenerGameTest.java create mode 100644 game/src/main/resources/application-prodsd.yml create mode 100644 game/src/main/resources/druid-prodsd.yml create mode 100644 tall/src/main/resources/application-prodsd.yml create mode 100644 tall/src/main/resources/druid-prodsd.yml create mode 100644 util/src/test/java/com/ccsens/util/FileTest.java diff --git a/cloudutil/src/main/resources/application-util-prodsd.yml b/cloudutil/src/main/resources/application-util-prodsd.yml new file mode 100644 index 00000000..189c4bef --- /dev/null +++ b/cloudutil/src/main/resources/application-util-prodsd.yml @@ -0,0 +1,69 @@ +#服务端点暴露 +management: + endpoints: + web: + exposure: + # 暴露xxx端点,如需暴露多个,用,分隔;如需暴露所有端点,用'*' + include: auditevents,caches,conditions,flyway,health,heapdump,httptrace,info,integrationgraph,jolokia,logfile,loggers,liquibase,metrics,mappings,prometheus,scheduledtasks,sessions,shutdown,threaddump,hystrix.stream +# # 不暴露哪些端点 + exclude: env,beans,configprops + endpoint: + health: + # 是否展示健康检查详情 + show-details: always + health: + redis: + enabled: false +#eureka注册 +eureka: + client: + service-url: + # 指定eureka server通信地址,注意/eureka/小尾巴不能少 + #defaultZone: http://admin:admin@peer1:8761/eureka/,http://admin:admin@peer2:8762/eureka/ + +# defaultZone: http://admin:admin@81.70.54.64:7010/eureka/ + defaultZone: http://admin:admin@192.144.182.42:7010/eureka/ + + instance: + # 是否注册IP到eureka server,如不指定或设为false,那就回注册主机名到eureka server + prefer-ip-address: true + metadata-map: + management: + context-path: ${server.servlet.context-path:}/actuator + home-page-url-path: ${server.servlet.context-path:}/ + status-page-url-path: ${server.servlet.context-path:}/actuator/info + health-check-url-path: ${server.servlet.context-path:}/actuator/health +feign: + client: + config: + default: + connectTime: 5000 + readTimeout: 5000 + # NONE【性能最佳,适用于生产】:不记录任何日志(默认值)。 + # BASIC【适用于生产环境追踪问题】:仅记录请求方法、URL、响应状态代码以及执行时间。 + # HEADERS:记录BASIC级别的基础上,记录请求和响应的header。 + # FULL【比较适用于开发及测试环境定位问题】:记录请求和响应的header、body和元数据 + loggerLevel: basic + hystrix: + enabled: true +hystrix: + threadpool: + default: + coreSize: 200 #并发执行的最大线程数,默认10 + maxQueueSize: 1000 #BlockingQueue的最大队列数,默认值-1 + queueSizeRejectionThreshold: 800 #即使maxQueueSize没有达到,达到queueSizeRejectionThreshold该值后,请求也会被拒绝,默认值5 +# sleuth +logging: + level: + root: info + org.springframework.cloud.sleuth: DEBUG +spring: +# zipkin: +# base-url: http://140.143.228.3:9411 +# sleuth: +# sampler: +# # 采样率,模式0.1,也就是10%,为了便于观察效果,改为1.0,也就是100%。生产环境建议保持默认。 +# probability: 0.1 + cloud: + inetutils: + ignored-interfaces: ['VMware.*'] \ No newline at end of file diff --git a/game/src/main/java/com/ccsens/game/api/DebugController.java b/game/src/main/java/com/ccsens/game/api/DebugController.java index aaf780dd..f786be8c 100644 --- a/game/src/main/java/com/ccsens/game/api/DebugController.java +++ b/game/src/main/java/com/ccsens/game/api/DebugController.java @@ -1,9 +1,16 @@ package com.ccsens.game.api; +import com.ccsens.util.JacksonUtil; import com.ccsens.util.JsonResponse; +import com.ccsens.util.bean.message.common.InMessage; +import com.ccsens.util.bean.message.common.MessageConstant; +import com.ccsens.util.bean.message.common.ServerMessage; +import com.ccsens.util.config.RabbitMQConfig; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; +import org.springframework.amqp.core.AmqpTemplate; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; @@ -14,6 +21,8 @@ import javax.servlet.http.HttpServletRequest; @RestController @RequestMapping("/debug") public class DebugController { + @Autowired + private AmqpTemplate rabbitTemplate; @ApiOperation(value = "/测试",notes = "") @ApiImplicitParams({ @@ -24,5 +33,18 @@ public class DebugController { return JsonResponse.newInstance().ok("测试"); } + @ApiOperation(value = "/测试",notes = "") + @ApiImplicitParams({ + }) + @RequestMapping(value="/game",method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"}) + public JsonResponse testGameMq(HttpServletRequest request) throws Exception { + ServerMessage serverMessage = new ServerMessage(); + serverMessage.setType("Ping"); + InMessage inMessage = InMessage.newToServerMessage(MessageConstant.DomainType.Server,serverMessage); + String j = JacksonUtil.beanToJson(inMessage); + //FixMe 发送到消息队列 + rabbitTemplate.convertAndSend("fanoutExchange","",j); + return JsonResponse.newInstance().ok("测试"); + } } 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 6d1d75f4..3d077b2d 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 @@ -114,7 +114,13 @@ public class ScreenVo { @ApiModelProperty("游戏状态 0未开始 1准备中 2进行中 3已结束") private Byte gameStatus; @ApiModelProperty("总人数") - private int totalMembers ; + private int totalMembers; + @ApiModelProperty("时长") + private int duration; + @ApiModelProperty("本地开始时间") + private Long startLocalTime; + @ApiModelProperty("本地结束时间") + private Long endLocalTime; @ApiModelProperty("分组信息") private List groups ; diff --git a/game/src/main/java/com/ccsens/game/netty/ChannelManager.java b/game/src/main/java/com/ccsens/game/netty/ChannelManager.java index c1453616..69800d49 100644 --- a/game/src/main/java/com/ccsens/game/netty/ChannelManager.java +++ b/game/src/main/java/com/ccsens/game/netty/ChannelManager.java @@ -1,10 +1,15 @@ package com.ccsens.game.netty; import cn.hutool.core.collection.CollectionUtil; +import com.ccsens.game.util.GameConstant; +import com.ccsens.util.RedisUtil; import io.netty.channel.Channel; import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import javax.annotation.PostConstruct; +import javax.annotation.Resource; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -12,8 +17,12 @@ import java.util.concurrent.ConcurrentHashMap; * @author wei */ @Slf4j +@Component public class ChannelManager { private static ThreadLocal threadLocal = new ThreadLocal<>(); + static ChannelManager channelManager; +// @Resource +// private RedisUtil redisUtil; /** * UserId,WrappedChannel authed channels; @@ -28,6 +37,30 @@ public class ChannelManager { authedChannels = new ConcurrentHashMap<>(); rawChannels = new ConcurrentHashMap<>(); } +// @PostConstruct +// public void init(){ +// channelManager = this; +// channelManager.redisUtil = this.redisUtil; +// log.info("redis:{}",this.redisUtil); +// } +// +// private static Map> getAuthedChannels(){ +// String key = GameConstant.GAME_WS_AUTHED_CHANNELS; +// Map hmget = channelManager.redisUtil.hmget(key); +// if(CollectionUtil.isEmpty(hmget)){ +// return new HashMap<>(); +// } +// return (Map>)hmget; +// } +// +// private static Map getRawChannels(){ +// String key = GameConstant.GAME_WS_RAW_CHANNELS; +// Map hmget = channelManager.redisUtil.hmget(key); +// if(CollectionUtil.isEmpty(hmget)){ +// return new HashMap<>(); +// } +// return (Map)hmget; +// } /** * 私有构造,不允许生成该类对象 @@ -65,6 +98,7 @@ public class ChannelManager { public static synchronized void addChannel(Channel channel,String serverType){ log.info("Invoke addChannel({},{})",channel,serverType); if(null != channel) { +// channelManager.redisUtil.hset(GameConstant.GAME_WS_RAW_CHANNELS,channel, new WrapperedChannel(channel, serverType),GameConstant.WS_CHANNELS); rawChannels.put(channel, new WrapperedChannel(channel, serverType)); log.info("Add a new channel: {},{}",channel.id().asLongText(),serverType); }else{ @@ -85,9 +119,15 @@ public class ChannelManager { minor = minor != null ? minor : 0; WrapperedChannel wrapperedChannel = rawChannels.get(channel); +// WrapperedChannel wrapperedChannel = getRawChannels().get(channel); if(wrapperedChannel != null){ wrapperedChannel.whenAuthed(userId,major,minor); Set authedWchannelSet = authedChannels.computeIfAbsent(userId, k -> new HashSet<>()); +// Set wrapperedChannels = getAuthedChannels().get(userId); +// if(CollectionUtil.isEmpty(wrapperedChannels)){ +// wrapperedChannels = new HashSet<>(); +// } +// Set authedWchannelSet = wrapperedChannels; authedWchannelSet.add(wrapperedChannel); log.info("Authed channel {} with user {}", channel.id().asLongText(), userId); }else{ @@ -112,6 +152,11 @@ public class ChannelManager { if(wrapperedChannel != null){ wrapperedChannel.whenAuthed(userId,major,minor,recordId); Set authedWchannelSet = authedChannels.computeIfAbsent(userId, k -> new HashSet<>()); +// Set wrapperedChannels = getAuthedChannels().get(userId); +// if(CollectionUtil.isEmpty(wrapperedChannels)){ +// wrapperedChannels = new HashSet<>(); +// } +// Set authedWchannelSet = wrapperedChannels; authedWchannelSet.add(wrapperedChannel); log.info("Authed channel {} with user {}", channel.id().asLongText(), userId); }else{ @@ -129,6 +174,7 @@ public class ChannelManager { if(wrapperedChannel != null){ //从rawChannels集合中删除 rawChannels.remove(channel); +// channelManager.redisUtil.hdel(GameConstant.GAME_WS_RAW_CHANNELS,channel); log.info("Remove a channel from rawChannels: {}",channel.id().asLongText()); if(wrapperedChannel.isAuthed()){ Set authedChannelSet = authedChannels.get(wrapperedChannel.getUserId()); @@ -140,6 +186,7 @@ public class ChannelManager { //从authedChannel中删除,此处不用else,因为if中语句执行完毕之后,authedChannelSet也可能变成空集合 if(CollectionUtil.isEmpty(authedChannelSet)){ authedChannels.remove(wrapperedChannel.getUserId()); +// channelManager.redisUtil.hdel(GameConstant.GAME_WS_AUTHED_CHANNELS,wrapperedChannel.getUserId()); log.info("Remove a user from authedChannels: {}",wrapperedChannel.getUserId()); } } @@ -163,11 +210,13 @@ public class ChannelManager { for(WrapperedChannel wChannel : wChannelSet){ //从rawChannel中依次删除 rawChannels.remove(wChannel.getChannel()); +// channelManager.redisUtil.hdel(GameConstant.GAME_WS_RAW_CHANNELS,wChannel.getChannel()); log.info("Remove a channel from rawChannels: {}",wChannel.getChannel().id().asLongText()); } } //从authedChannel中删除 authedChannels.remove(userId); +// channelManager.redisUtil.hdel(GameConstant.GAME_WS_AUTHED_CHANNELS,userId); log.info("Remove a user from authedChannels: {}",userId); } diff --git a/game/src/main/java/com/ccsens/game/service/RabbitMQListener.java b/game/src/main/java/com/ccsens/game/service/RabbitMQListener.java index 0c2c7b07..be5b21c4 100644 --- a/game/src/main/java/com/ccsens/game/service/RabbitMQListener.java +++ b/game/src/main/java/com/ccsens/game/service/RabbitMQListener.java @@ -1,10 +1,8 @@ package com.ccsens.game.service; -import cn.hutool.core.collection.CollectionUtil; import com.ccsens.game.bean.dto.message.GameMessageWithChangeStatusOut; import com.ccsens.util.JacksonUtil; -import com.ccsens.util.WebConstant; import com.ccsens.util.config.RabbitMQConfig; import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; @@ -15,8 +13,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.io.IOException; -import java.util.List; -import java.util.TreeMap; @Slf4j @Component @@ -35,4 +31,6 @@ public class RabbitMQListener { messageService.doChangeStatusMessage(JacksonUtil.jsonToBean(messageJson, GameMessageWithChangeStatusOut.class, true)); } + + } \ No newline at end of file diff --git a/game/src/main/java/com/ccsens/game/service/RabbitMQListenerGameTest.java b/game/src/main/java/com/ccsens/game/service/RabbitMQListenerGameTest.java new file mode 100644 index 00000000..77ba08ab --- /dev/null +++ b/game/src/main/java/com/ccsens/game/service/RabbitMQListenerGameTest.java @@ -0,0 +1,27 @@ +package com.ccsens.game.service; + +import com.ccsens.util.config.RabbitMQConfig; +import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.amqp.rabbit.annotation.RabbitHandler; +import org.springframework.amqp.rabbit.annotation.RabbitListener; +import org.springframework.stereotype.Component; + +import java.io.IOException; + +@Slf4j +@Component +@RabbitListener(queues = RabbitMQConfig.GAME_MQ_A) +public class RabbitMQListenerGameTest { + private Logger logger = LoggerFactory.getLogger(RabbitMQListener.class); + + + @RabbitHandler + public void gameTest(String gameTest) throws IOException { + System.out.println("============================="+gameTest); +// List gameMessageList = JacksonUtil.jsonToBean(messageJson, +// GameMessageWithChangeStatusOut.class, true); + log.info("测试游戏MQ消息 {}",gameTest); + } +} 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 933586e9..7f00f78d 100644 --- a/game/src/main/java/com/ccsens/game/service/ScreenService.java +++ b/game/src/main/java/com/ccsens/game/service/ScreenService.java @@ -24,6 +24,7 @@ import com.ccsens.util.bean.dto.QueryDto; import com.ccsens.util.exception.BaseException; import com.ccsens.util.wx.WxXcxUtil; import com.fasterxml.jackson.core.JsonProcessingException; +import com.google.common.util.concurrent.AtomicDouble; import lombok.extern.slf4j.Slf4j; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFRow; @@ -39,6 +40,7 @@ import java.io.*; import java.util.*; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.atomic.AtomicInteger; /** * @author zy @@ -144,7 +146,7 @@ public class ScreenService implements IScreenService { } else { log.info("测试环境,不调用生成二维码"); //给一个默认测试的 - gameRecord.setQrCodeUrl(PropUtil.qrCode + "/gameQrCode/2020-08-19/1597822577181.png"); + gameRecord.setQrCodeUrl(PropUtil.qrCode + "gameQrCode/2020-08-19/1597822577181.png"); } //查找此任务下的游戏配置表 @@ -160,27 +162,28 @@ public class ScreenService implements IScreenService { //添加配置信息 saveGameRecord(wpsFilePath,gameRecord); } - //将游戏记录添加数据库 - gameRecordDao.insertSelective(gameRecord); + //如果是分组游戏 + log.info("添加游戏记录:{}",gameRecord); //配置表不存在,而且游戏类型默认为分组游戏,默认添加两个分组 if(StrUtil.isEmpty(wpsFilePath) && 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); - } - } + gameRecord.setGameGroup((byte) 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); + } + //将游戏记录添加数据库 + gameRecordDao.insertSelective(gameRecord); //5、查询该游戏的规则 List ruleList = getGameActivityRule(gameType.getId()); //6、返回 @@ -222,6 +225,9 @@ public class ScreenService implements IScreenService { */ private void saveGameRecord(String wpsFilePath,GameRecord gameRecord) throws Exception{ InputStream is = new FileInputStream(new File(wpsFilePath)); + + + //读取excel XSSFWorkbook wb = new XSSFWorkbook(is); if(ObjectUtil.isNull(wb)){ throw new BaseException(CodeEnum.NOT_CONFIG_OR_ERR); } @@ -550,8 +556,13 @@ public class ScreenService implements IScreenService { //获取游戏的购买记录和类型 GameUserPay gameUserPay = gameUserPayDao.selectByPrimaryKey(gameRecord.getUserPayId()); GameType gameType = gameTypeDao.selectByPrimaryKey(gameUserPay.getGameTypeId()); - gameStatusVo.setGameStatus(gameRecord.getGameStatus()); + //返回开始结束时间和时长 + + gameStatusVo.setStartLocalTime(gameRecord.getStartTime() + gameRecord.getTimeDifference()); + gameStatusVo.setEndLocalTime(gameRecord.getEndTime() + gameRecord.getTimeDifference()); + gameStatusVo.setDuration(gameRecord.getDuration()); + //获取分组的信息 List groupVo = getGroupScore2(gameRecord); gameStatusVo.setGroups(groupVo); @@ -701,9 +712,6 @@ public class ScreenService implements IScreenService { /** * 结束时查询胜利组的信息(总分数,总次数,平均以及前十名) */ - - - private ScreenVo.CompletedData getCompletedDataByWin(GameRecord gameRecord, int totalMember) { String groupKey = gameRecord.getId() + "_group"; Set> typedTuples = redisUtil.zsRevGetWithScore(groupKey, 0, -1); @@ -711,31 +719,32 @@ public class ScreenService implements IScreenService { ScreenVo.CompletedData completedData = new ScreenVo.CompletedData(); List list = new ArrayList<>(); + Double maxSore = 0d; + String winGroupName = null; if (CollectionUtil.isNotEmpty(typedTuples)) { - typedTuples.forEach(type -> { + for(ZSetOperations.TypedTuple type : typedTuples) { completedData.setTotalScore(completedData.getTotalScore() + type.getScore().intValue()); + GameGroup gameGroup = JSON.parseObject((String) type.getValue(), GameGroup.class); + if (gameRecord.getRankRule() == GameConstant.RANK_RULE_AVA) { + Object o = redisUtil.get(gameGroup.getId() + GameConstant.GAME_GROUP_NUM); + if (o == null || (Integer) o == 0) { + continue; + } + Integer a = (Integer) o; + if (maxSore <= type.getScore() / a) { + maxSore = type.getScore() / a; + winGroupName = gameGroup.getName(); + } + } else { + if (maxSore <= type.getScore()) { + maxSore = type.getScore(); + winGroupName = gameGroup.getName(); + } + } + } -// ScreenVo.CompletedData completedData = new ScreenVo.CompletedData(); -//// GameGroup gameGroup = JSON.parseObject((String) type.getValue(), GameGroup.class); -//// int score = type.getScore().intValue(); -//// Object o = redisUtil.get(gameGroup.getId() + GameConstant.GAME_GROUP_NUM); -//// if (o==null) { -//// o = 0; -//// } -//// completedData.setTotalMember((int)o); -//// completedData.setTotalScore(score); -//// completedData.setAverageScore((int)o == 0 ? 0 : completedData.getTotalScore()/(int)o); -//// completedData.setTotalTimes(score/100); -//// completedData.setAverageTimes((int)o == 0 ? 0 : completedData.getTotalTimes()/(int)o); -//// completedData.setWinGroup(gameGroup.getName()); -//// GameUserJoinExample joinExample = new GameUserJoinExample(); -//// joinExample.createCriteria().andRecordIdEqualTo(gameRecord.getId()).andScoreGreaterThan(completedData.getAverageTimes()); -//// long l = gameUserJoinDao.countByExample(joinExample); -//// completedData.setOver(totalMember == 0 ? 0 : (int) (l * 100 / totalMember)); -//// list.add(completedData); - }); } else { List groupVos = gameGroupDao.queryGroups(gameRecord.getId()); @@ -744,70 +753,37 @@ public class ScreenService implements IScreenService { return new ScreenVo.CompletedData(); } - groupVos.forEach(groupVo -> { - completedData.setTotalScore((groupVo.getScore() == null ? 0 : groupVo.getScore()) + completedData.getTotalScore()); -// groupVo.setScore(groupVo.getTotalMembers() == null || groupVo.getTotalMembers() == 0 ? 0 : groupVo.getScore()/groupVo.getTotalMembers()); -// ScreenVo.CompletedData completedData = new ScreenVo.CompletedData(); -// -// int members = groupVo.getTotalMembers() == null ? 0 : groupVo.getTotalMembers(); -// completedData.setTotalMember(members); -// completedData.setTotalScore(groupVo.getScore()); -// completedData.setAverageScore(members == 0 ? 0 : completedData.getTotalScore()/members); -// completedData.setTotalTimes(groupVo.getScore() == null ? 0 : groupVo.getScore()/100); -// completedData.setAverageTimes(members == 0 ? 0 : completedData.getTotalTimes()/members); -// completedData.setWinGroup(groupVo.getGroupName()); -// GameUserJoinExample joinExample = new GameUserJoinExample(); -// joinExample.createCriteria().andRecordIdEqualTo(gameRecord.getId()).andScoreGreaterThan(completedData.getAverageTimes()); -// long l = gameUserJoinDao.countByExample(joinExample); -// completedData.setOver(totalMember == 0 ? 0 : (int) (l * 100 /totalMember)); -// list.add(completedData); - }); + for(ScreenVo.GroupVo groupVo : groupVos) { + if (gameRecord.getRankRule() == GameConstant.RANK_RULE_AVA) { + if (groupVo.getTotalMembers() == null || groupVo.getTotalMembers() == 0) { + continue; + } + if (maxSore <= groupVo.getTotalScore() / groupVo.getTotalMembers()) { + maxSore = (double)groupVo.getTotalScore() / groupVo.getTotalMembers(); + winGroupName = groupVo.getGroupName(); + } + } else { + if (maxSore <= groupVo.getTotalScore()) { + maxSore = (double)groupVo.getTotalScore(); + winGroupName = groupVo.getGroupName(); + } + } + } + } completedData.setAverageScore(totalMember == 0 ? 0 : completedData.getTotalScore() / totalMember); completedData.setTotalTimes(completedData.getTotalScore() / 100); completedData.setAverageTimes(totalMember == 0 ? 0 : completedData.getTotalTimes() / totalMember); + completedData.setTotalMember(totalMember); + completedData.setWinGroup(winGroupName); + GameUserJoinExample joinExample = new GameUserJoinExample(); joinExample.createCriteria().andRecordIdEqualTo(gameRecord.getId()).andScoreGreaterThan(completedData.getAverageScore()); long l = gameUserJoinDao.countByExample(joinExample); completedData.setOver(totalMember == 0 ? 0 : (int) (l * 100 / totalMember)); -// if (gameRecord.getRankRule() == GameConstant.RANK_RULE_AVA) { -// CollectionUtil.sort(list, (t1,t2)-> t2.getAverageScore() - t1.getAverageScore()); -// } - - //TODO 1、分别查询redis内每个队伍的总分, - //2、查询获胜队伍的信息 - - //3、redis内没有则查询数据库 - //查询分组信息 -// GameGroupExample gameGroupExample = new GameGroupExample(); -// gameGroupExample.createCriteria().andRecordIdEqualTo(gameRecordId); -// List gameGroupList = gameGroupDao.selectByExample(gameGroupExample); -// if (CollectionUtil.isNotEmpty(gameGroupList)) { -// List userJoinList = null; -// //分别查找两个队伍的总分 -// Map group1 = getGroupTotalScore(gameGroupList.get(0).getId()); -// Map group2 = getGroupTotalScore(gameGroupList.get(1).getId()); -// if (CollectionUtil.isNotEmpty(group1) && CollectionUtil.isNotEmpty(group2)) { -// int score1 = (int) group1.get("totalScore"); -// int score2 = (int) group2.get("totalScore"); -// if (score1 > score2) { -// userJoinList = (List) group1.get("userJoinList"); -// completedData.setTotalMember(userJoinList.size()); -// completedData.setWinGroup(gameGroupList.get(0).getName()); -// } else { -// userJoinList = (List) group2.get("userJoinList"); -// completedData.setTotalMember(userJoinList.size()); -// completedData.setWinGroup(gameGroupList.get(1).getName()); -// } -// } -// //5、获取获胜队伍的信息 -// completedData = getCompletedData(userJoinList); -// } - //前十名 -// ScreenVo.CompletedData completedData = list.get(0); List top2 = getTopUsers(gameRecord.getId()); completedData.setMembers(top2); return completedData; diff --git a/game/src/main/java/com/ccsens/game/util/GameConstant.java b/game/src/main/java/com/ccsens/game/util/GameConstant.java index 32fdea77..b180b767 100644 --- a/game/src/main/java/com/ccsens/game/util/GameConstant.java +++ b/game/src/main/java/com/ccsens/game/util/GameConstant.java @@ -58,7 +58,12 @@ public class GameConstant { public static final byte GAME_GROUP = 1; /**游戏:单人*/ public static final byte GAME_SINGLE = 0; - + /**ws已授权的连接*/ + public static final String GAME_WS_AUTHED_CHANNELS = "authedChannels"; + /**ws全部的连接*/ + public static final String GAME_WS_RAW_CHANNELS = "rawChannels"; + /**ws连接时间*/ + public static final long WS_CHANNELS = 24 * 60 * 60L; /** * 生成游戏key * @param recordId diff --git a/game/src/main/resources/application-prod.yml b/game/src/main/resources/application-prod.yml index 207fad5e..de83d673 100644 --- a/game/src/main/resources/application-prod.yml +++ b/game/src/main/resources/application-prod.yml @@ -3,6 +3,9 @@ server: servlet: context-path: spring: + snowflake: + datacenterId: 1 + workerId: 1 application: name: game datasource: @@ -21,7 +24,8 @@ spring: max-idle: 10 max-wait: -1ms min-idle: 0 - password: '' +# password: '' + password: 'areowqr!@43ef' port: 6379 timeout: 1000ms swagger: diff --git a/game/src/main/resources/application-prodsd.yml b/game/src/main/resources/application-prodsd.yml new file mode 100644 index 00000000..7cf0c946 --- /dev/null +++ b/game/src/main/resources/application-prodsd.yml @@ -0,0 +1,40 @@ +server: + port: 7050 + servlet: + context-path: +spring: + snowflake: + datacenterId: 2 + workerId: 2 + application: + name: game + datasource: + type: com.alibaba.druid.pool.DruidDataSource + rabbitmq: + host: www.tall.wiki + password: 111111 + port: 5672 + username: admin + redis: + database: 0 + host: www.tall.wiki + jedis: + pool: + max-active: 200 + max-idle: 10 + max-wait: -1ms + min-idle: 0 + password: 'areowqr!@43ef' + port: 6379 + timeout: 1000ms +swagger: + enable: true +eureka: + instance: + ip-address: 81.70.54.64 + +gatewayUrl: https://www.tall.wiki/gateway/ +notGatewayUrl: https://www.tall.wiki/ +file: + qrCode: https://www.tall.wiki/gateway/tall/v1.0/uploads/ + openWX: 1 \ No newline at end of file diff --git a/game/src/main/resources/application.yml b/game/src/main/resources/application.yml index 5889ff7f..5c2cd5c4 100644 --- a/game/src/main/resources/application.yml +++ b/game/src/main/resources/application.yml @@ -1,4 +1,4 @@ spring: profiles: - active: test - include: common, util-test \ No newline at end of file + active: dev + include: common, util-dev \ No newline at end of file diff --git a/game/src/main/resources/druid-prodsd.yml b/game/src/main/resources/druid-prodsd.yml new file mode 100644 index 00000000..a31149d8 --- /dev/null +++ b/game/src/main/resources/druid-prodsd.yml @@ -0,0 +1,33 @@ +spring: + datasource: + druid: + connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 + driverClassName: com.mysql.cj.jdbc.Driver + dynamicUrl: jdbc:mysql://localhost:3306/${schema} + filterExclusions: '*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*' + filterName: druidFilter + filterProfileEnable: true + filterUrlPattern: /* + filters: stat,wall + initialSize: 5 + maxActive: 20 + maxPoolPreparedStatementPerConnectionSize: 20 + maxWait: 60000 + minEvictableIdleTimeMillis: 300000 + minIdle: 5 + password: 37080c1f223685592316b02dad8816c019290a476e54ebb638f9aa3ba8b6bdb9 + poolPreparedStatements: true + servletLogSlowSql: true + servletLoginPassword: 111111 + servletLoginUsername: druid + servletName: druidServlet + servletResetEnable: true + servletUrlMapping: /druid/* + testOnBorrow: false + testOnReturn: false + testWhileIdle: true + timeBetweenEvictionRunsMillis: 60000 + url: jdbc:mysql://www.tall.wiki/game?useUnicode=true&characterEncoding=UTF-8 + username: root + validationQuery: SELECT 1 FROM DUAL + env: CCSENS_GAME \ No newline at end of file diff --git a/health/src/main/resources/application-prod.yml b/health/src/main/resources/application-prod.yml index 6db11ffa..7d033160 100644 --- a/health/src/main/resources/application-prod.yml +++ b/health/src/main/resources/application-prod.yml @@ -24,7 +24,8 @@ spring: max-idle: 10 max-wait: -1ms min-idle: 0 - password: '' +# password: '' + password: 'areowqr!@43ef' port: 6379 timeout: 1000ms swagger: diff --git a/health/src/main/resources/application.yml b/health/src/main/resources/application.yml index c3b11fb6..5abf2423 100644 --- a/health/src/main/resources/application.yml +++ b/health/src/main/resources/application.yml @@ -1,4 +1,4 @@ spring: profiles: - active: test - include: common, util-test + active: prod + include: common, util-prod diff --git a/ht/src/main/resources/application-prod.yml b/ht/src/main/resources/application-prod.yml index c2a54f79..c3cc8976 100644 --- a/ht/src/main/resources/application-prod.yml +++ b/ht/src/main/resources/application-prod.yml @@ -21,11 +21,8 @@ spring: max-idle: 10 max-wait: -1ms min-idle: 0 -<<<<<<< HEAD - password: '' -======= password: 'areowqr!@43ef' ->>>>>>> pt + port: 6379 timeout: 1000ms @@ -42,8 +39,5 @@ ht: name: 认知功能评测云平台系统 eureka: instance: -<<<<<<< HEAD ip-address: 81.70.54.64 -======= - ip-address: 71.80.54.64 ->>>>>>> pt + diff --git a/mt/src/main/resources/application-prod.yml b/mt/src/main/resources/application-prod.yml index a262e849..27606410 100644 --- a/mt/src/main/resources/application-prod.yml +++ b/mt/src/main/resources/application-prod.yml @@ -21,7 +21,8 @@ spring: max-idle: 10 max-wait: -1ms min-idle: 0 - password: '' +# password: '' + password: 'areowqr!@43ef' port: 6379 timeout: 1000ms swagger: diff --git a/tall/src/main/resources/application-prod.yml b/tall/src/main/resources/application-prod.yml index 6d3d0d97..e31f8289 100644 --- a/tall/src/main/resources/application-prod.yml +++ b/tall/src/main/resources/application-prod.yml @@ -24,8 +24,8 @@ spring: max-idle: 10 max-wait: -1ms min-idle: 0 - password: '' -# password: +# password: '' + password: 'areowqr!@43ef' port: 6379 timeout: 1000ms swagger: diff --git a/tall/src/main/resources/application-prodsd.yml b/tall/src/main/resources/application-prodsd.yml new file mode 100644 index 00000000..1177ad28 --- /dev/null +++ b/tall/src/main/resources/application-prodsd.yml @@ -0,0 +1,44 @@ +server: + port: 7031 + servlet: + context-path: /v1.0 +spring: + snowflake: + datacenterId: 2 + workerId: 2 + application: + name: tall + datasource: + type: com.alibaba.druid.pool.DruidDataSource + rabbitmq: + host: www.tall.wiki + password: 111111 + port: 5672 + username: admin + redis: + database: 0 + host: www.tall.wiki + jedis: + pool: + max-active: 200 + max-idle: 10 + max-wait: -1ms + min-idle: 0 + password: 'areowqr!@43ef' + port: 6379 + timeout: 1000ms +swagger: + enable: false +eureka: + instance: + ip-address: 81.70.54.64 + +gatewayUrl: https://www.tall.wiki/gateway/ +notGatewayUrl: https://www.tall.wiki/ +smsCode: 1 +wx: + prefixUrl: https://www.tall.wiki/wxconfigurer-api/ +file: + path: /home/cloud/tall/uploads/ + domain: https://www.tall.wiki/gateway/tall/v1.0/ + imgDomain: https://www.tall.wiki/gateway/tall/v1.0/uploads \ No newline at end of file diff --git a/tall/src/main/resources/druid-prodsd.yml b/tall/src/main/resources/druid-prodsd.yml new file mode 100644 index 00000000..51238023 --- /dev/null +++ b/tall/src/main/resources/druid-prodsd.yml @@ -0,0 +1,33 @@ +spring: + datasource: + druid: + connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 + driverClassName: com.mysql.cj.jdbc.Driver + dynamicUrl: jdbc:mysql://127.0.0.1:3306/${schema} + filterExclusions: '*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*' + filterName: druidFilter + filterProfileEnable: true + filterUrlPattern: /* + filters: stat,wall + initialSize: 5 + maxActive: 20 + maxPoolPreparedStatementPerConnectionSize: 20 + maxWait: 60000 + minEvictableIdleTimeMillis: 300000 + minIdle: 5 + password: 37080c1f223685592316b02dad8816c019290a476e54ebb638f9aa3ba8b6bdb9 + poolPreparedStatements: true + servletLogSlowSql: true + servletLoginPassword: 111111 + servletLoginUsername: druid + servletName: druidServlet + servletResetEnable: true + servletUrlMapping: /druid/* + testOnBorrow: false + testOnReturn: false + testWhileIdle: true + timeBetweenEvictionRunsMillis: 60000 + url: jdbc:mysql://www.tall.wiki/tall?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true + username: root + validationQuery: SELECT 1 FROM DUAL + env: CCSENS_GAME \ No newline at end of file diff --git a/tall/src/main/resources/logback-spring.xml b/tall/src/main/resources/logback-spring.xml index 12977b28..05caf6e3 100644 --- a/tall/src/main/resources/logback-spring.xml +++ b/tall/src/main/resources/logback-spring.xml @@ -9,7 +9,7 @@ logback - + diff --git a/util/src/main/java/com/ccsens/util/RedisUtil.java b/util/src/main/java/com/ccsens/util/RedisUtil.java index eb416311..46975d57 100644 --- a/util/src/main/java/com/ccsens/util/RedisUtil.java +++ b/util/src/main/java/com/ccsens/util/RedisUtil.java @@ -1,20 +1,21 @@ package com.ccsens.util; -import org.springframework.beans.factory.annotation.Autowired; +import lombok.extern.slf4j.Slf4j; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.ZSetOperations; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; +import javax.annotation.Resource; import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; - +@Slf4j @Component public class RedisUtil { - @Autowired - private RedisTemplate redisTemplate; + @Resource + private RedisTemplate redisTemplate; /** * 指定缓存失效时间 @@ -175,7 +176,7 @@ public class RedisUtil { * @param key 键 * @return 对应的多个键值 */ - public Map hmget(String key) { + public Map hmget(String key) { return redisTemplate.opsForHash().entries(key); } @@ -244,14 +245,17 @@ public class RedisUtil { * @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间 * @return true 成功 false失败 */ - public boolean hset(String key, String item, Object value, long time) { + public boolean hset(String key, Object item, Object value, long time) { + log.info("存hash:{}:{}:{}:{}",key,item,value,time); try { redisTemplate.opsForHash().put(key, item, value); if (time > 0) { expire(key, time); } + log.info("存hash成功:{}:{}:{}:{}",key,item,value,time); return true; } catch (Exception e) { + log.error("存hash异常",e); e.printStackTrace(); return false; } @@ -456,7 +460,6 @@ public class RedisUtil { * * @param key 键 * @param value 值 - * @param time 时间(秒) * @return */ public boolean lSet(String key, Object value) { @@ -480,7 +483,9 @@ public class RedisUtil { public boolean lSet(String key, Object value, long time) { try { redisTemplate.opsForList().rightPush(key, value); - if (time > 0) expire(key, time); + if (time > 0) { + expire(key, time); + } return true; } catch (Exception e) { e.printStackTrace(); @@ -493,7 +498,6 @@ public class RedisUtil { * * @param key 键 * @param value 值 - * @param time 时间(秒) * @return */ public boolean lSet(String key, List value) { @@ -517,7 +521,9 @@ public class RedisUtil { public boolean lSet(String key, List value, long time) { try { redisTemplate.opsForList().rightPushAll(key, value); - if (time > 0) expire(key, time); + if (time > 0) { + expire(key, time); + } return true; } catch (Exception e) { e.printStackTrace(); diff --git a/util/src/main/java/com/ccsens/util/config/RabbitMQConfig.java b/util/src/main/java/com/ccsens/util/config/RabbitMQConfig.java index d240028f..f4d8045a 100644 --- a/util/src/main/java/com/ccsens/util/config/RabbitMQConfig.java +++ b/util/src/main/java/com/ccsens/util/config/RabbitMQConfig.java @@ -1,6 +1,10 @@ package com.ccsens.util.config; +import org.springframework.amqp.core.Binding; +import org.springframework.amqp.core.BindingBuilder; +import org.springframework.amqp.core.FanoutExchange; import org.springframework.amqp.core.Queue; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -14,6 +18,8 @@ public class RabbitMQConfig { private static final String GAME_STATUS_DELAY_SEND_EXCHANGE = "gameStatusDelaySendExchange"; private static final String GAME_STATUS_DELAY_SEND_ROUTING_KEY = "gameStatusDelaySendRoutingKey"; + public static final String GAME_MQ_A = "gameMqA"; + /**消息队列发送*/ public static final String MESSAGE_QUEUE_NAME = "tall_message_1"; @@ -27,7 +33,7 @@ public class RabbitMQConfig { return new Queue(GAME_STATUS); } @Bean - public Queue queue (){ + public Queue queue(){ return new Queue(RabbitMQ_QUEUE_NAME); } @Bean @@ -44,6 +50,11 @@ public class RabbitMQConfig { return new Queue(GAME_SCORE); } + @Bean + public Queue queueGame(){ + return new Queue(GAME_MQ_A); + } + // /** // * 延时发送队列 // * @return @@ -74,4 +85,16 @@ public class RabbitMQConfig { // } + //创建Fanout交换器 + @Bean + FanoutExchange fanoutExchange() { + return new FanoutExchange("fanoutExchange"); + } + //将对列绑定到Fanout交换器 + @Bean + Binding bindingExchangeA(Queue queueGame, FanoutExchange fanoutExchange) { + return BindingBuilder.bind(queueGame).to(fanoutExchange); + } + + } diff --git a/util/src/test/java/com/ccsens/util/FileTest.java b/util/src/test/java/com/ccsens/util/FileTest.java new file mode 100644 index 00000000..76aeab73 --- /dev/null +++ b/util/src/test/java/com/ccsens/util/FileTest.java @@ -0,0 +1,40 @@ +package com.ccsens.util; + +import cn.hutool.core.util.ObjectUtil; +import com.ccsens.util.exception.BaseException; +import org.apache.poi.xssf.usermodel.XSSFRow; +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.junit.Test; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.net.URL; +import java.net.URLConnection; + +public class FileTest { + /**加密*/ + @Test + public void fileToString () throws Exception { + InputStream in = null; + BufferedInputStream bin = null; + ByteArrayOutputStream baos = null; + BufferedOutputStream bout = null; + try { + URL url = new URL("http://192.144.182.42:7030/v1.0/file/download/数钱游戏配置表1.xlsx?path=wps/202012071/f93826c0e81e499f9c749d7a9d0da5d1.xlsx"); + URLConnection conn = url.openConnection(); + in = conn.getInputStream(); + System.out.println(in.available()); + //读取excel + XSSFWorkbook wb = new XSSFWorkbook(in); + if(ObjectUtil.isNull(wb)){ throw new BaseException(CodeEnum.NOT_CONFIG_OR_ERR); } + //读取sheet + XSSFSheet sheet = wb.getSheet("游戏配置表"); + System.out.println(sheet.getSheetName()); + } finally { + in.close(); + } + } +}