From db2cc9826206fa9e96caba45c2219747970a63d5 Mon Sep 17 00:00:00 2001 From: zy_Java <654600784@qq.com> Date: Tue, 18 Aug 2020 18:01:22 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BB=E5=8F=96=E6=B8=B8=E6=88=8F=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E8=A1=A8=EF=BC=88=E6=9C=AA=E6=B5=8B=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cloudutil/feign/TallFeignClient.java | 11 + .../com/ccsens/game/api/ScreenController.java | 8 +- .../com/ccsens/game/bean/dto/ScreenDto.java | 4 + .../com/ccsens/game/bean/po/GameGroup.java | 11 + .../ccsens/game/bean/po/GameGroupExample.java | 70 +++ .../ccsens/game/service/IScreenService.java | 12 + .../ccsens/game/service/ScreenService.java | 556 +++++++++++++----- .../com/ccsens/game/util/GameConstant.java | 8 + .../resources/mapper_raw/GameGroupMapper.xml | 25 +- game/src/main/resources/mbg.xml | 4 +- .../java/com/ccsens/tall/bean/dto/WpsDto.java | 3 +- .../com/ccsens/tall/service/IWpsService.java | 12 +- .../com/ccsens/tall/service/WpsService.java | 17 + .../com/ccsens/tall/web/WpsController.java | 8 + .../main/java/com/ccsens/util/CodeEnum.java | 3 +- .../java/com/ccsens/util/WebConstant.java | 1 + 16 files changed, 596 insertions(+), 157 deletions(-) diff --git a/cloudutil/src/main/java/com/ccsens/cloudutil/feign/TallFeignClient.java b/cloudutil/src/main/java/com/ccsens/cloudutil/feign/TallFeignClient.java index cbca56a2..ff72718c 100644 --- a/cloudutil/src/main/java/com/ccsens/cloudutil/feign/TallFeignClient.java +++ b/cloudutil/src/main/java/com/ccsens/cloudutil/feign/TallFeignClient.java @@ -171,6 +171,12 @@ public interface TallFeignClient { @GetMapping("/wps/wpsId") JsonResponse getPathByWpsId(@RequestParam(name = "wpsId")Long wpsId); + /** + * 通过token获得userId(消息系统用) + */ + @GetMapping("/v1/3rd/getFilePath") + String getWpsFilePath(@RequestParam(name = "businessId") Long businessId,@RequestParam(name = "businessType") byte businessType); + } @Slf4j @@ -273,6 +279,11 @@ class TallFeignClientFallBack implements FallbackFactory { public JsonResponse getPathByWpsId(Long async) { return JsonResponse.newInstance().fail(); } + + @Override + public String getWpsFilePath(Long businessId, byte businessType) { + return null; + } }; } diff --git a/game/src/main/java/com/ccsens/game/api/ScreenController.java b/game/src/main/java/com/ccsens/game/api/ScreenController.java index 044877e4..6972df87 100644 --- a/game/src/main/java/com/ccsens/game/api/ScreenController.java +++ b/game/src/main/java/com/ccsens/game/api/ScreenController.java @@ -19,6 +19,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; +import java.util.List; + @Slf4j @Api(tags = "大屏相关api" , description = "ScreenController") @RestController @@ -83,9 +85,9 @@ public class ScreenController { @ApiImplicitParams({ }) @RequestMapping(value = "/config", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) - public JsonResponse getConfig(@ApiParam @Validated @RequestBody QueryDto params) throws Exception { - log.info("再玩一次:{}",params); - String url = screenService.getConfig(params); + public JsonResponse> getConfig(@ApiParam @Validated @RequestBody QueryDto params) throws Exception { + log.info("查询游戏配置信息excel:{}",params); + List url = screenService.getConfig(params); return JsonResponse.newInstance().ok(url); } diff --git a/game/src/main/java/com/ccsens/game/bean/dto/ScreenDto.java b/game/src/main/java/com/ccsens/game/bean/dto/ScreenDto.java index 5eaa4126..a9acd5b6 100644 --- a/game/src/main/java/com/ccsens/game/bean/dto/ScreenDto.java +++ b/game/src/main/java/com/ccsens/game/bean/dto/ScreenDto.java @@ -60,8 +60,12 @@ public class ScreenDto { @Data @ApiModel("查看配置文件") public static class GetConfig{ + @NotNull @ApiModelProperty("任务id") private Long taskId; + @NotNull + @ApiModelProperty("要创建的小游戏的类型 例如: SQ:数钱 SP:赛跑 BH:拔河") + private String gameType; } diff --git a/game/src/main/java/com/ccsens/game/bean/po/GameGroup.java b/game/src/main/java/com/ccsens/game/bean/po/GameGroup.java index 64b5aaf4..5a2af7b5 100644 --- a/game/src/main/java/com/ccsens/game/bean/po/GameGroup.java +++ b/game/src/main/java/com/ccsens/game/bean/po/GameGroup.java @@ -18,6 +18,8 @@ public class GameGroup implements Serializable { private Byte recStatus; + private String headPortraitUrl; + private static final long serialVersionUID = 1L; public Long getId() { @@ -76,6 +78,14 @@ public class GameGroup implements Serializable { this.recStatus = recStatus; } + public String getHeadPortraitUrl() { + return headPortraitUrl; + } + + public void setHeadPortraitUrl(String headPortraitUrl) { + this.headPortraitUrl = headPortraitUrl == null ? null : headPortraitUrl.trim(); + } + @Override public String toString() { StringBuilder sb = new StringBuilder(); @@ -89,6 +99,7 @@ public class GameGroup implements Serializable { sb.append(", createdAt=").append(createdAt); sb.append(", updatedAt=").append(updatedAt); sb.append(", recStatus=").append(recStatus); + sb.append(", headPortraitUrl=").append(headPortraitUrl); sb.append("]"); return sb.toString(); } diff --git a/game/src/main/java/com/ccsens/game/bean/po/GameGroupExample.java b/game/src/main/java/com/ccsens/game/bean/po/GameGroupExample.java index 8af717a2..2df4e0f8 100644 --- a/game/src/main/java/com/ccsens/game/bean/po/GameGroupExample.java +++ b/game/src/main/java/com/ccsens/game/bean/po/GameGroupExample.java @@ -544,6 +544,76 @@ public class GameGroupExample { addCriterion("rec_status not between", value1, value2, "recStatus"); return (Criteria) this; } + + public Criteria andHeadPortraitUrlIsNull() { + addCriterion("head_portrait_url is null"); + return (Criteria) this; + } + + public Criteria andHeadPortraitUrlIsNotNull() { + addCriterion("head_portrait_url is not null"); + return (Criteria) this; + } + + public Criteria andHeadPortraitUrlEqualTo(String value) { + addCriterion("head_portrait_url =", value, "headPortraitUrl"); + return (Criteria) this; + } + + public Criteria andHeadPortraitUrlNotEqualTo(String value) { + addCriterion("head_portrait_url <>", value, "headPortraitUrl"); + return (Criteria) this; + } + + public Criteria andHeadPortraitUrlGreaterThan(String value) { + addCriterion("head_portrait_url >", value, "headPortraitUrl"); + return (Criteria) this; + } + + public Criteria andHeadPortraitUrlGreaterThanOrEqualTo(String value) { + addCriterion("head_portrait_url >=", value, "headPortraitUrl"); + return (Criteria) this; + } + + public Criteria andHeadPortraitUrlLessThan(String value) { + addCriterion("head_portrait_url <", value, "headPortraitUrl"); + return (Criteria) this; + } + + public Criteria andHeadPortraitUrlLessThanOrEqualTo(String value) { + addCriterion("head_portrait_url <=", value, "headPortraitUrl"); + return (Criteria) this; + } + + public Criteria andHeadPortraitUrlLike(String value) { + addCriterion("head_portrait_url like", value, "headPortraitUrl"); + return (Criteria) this; + } + + public Criteria andHeadPortraitUrlNotLike(String value) { + addCriterion("head_portrait_url not like", value, "headPortraitUrl"); + return (Criteria) this; + } + + public Criteria andHeadPortraitUrlIn(List values) { + addCriterion("head_portrait_url in", values, "headPortraitUrl"); + return (Criteria) this; + } + + public Criteria andHeadPortraitUrlNotIn(List values) { + addCriterion("head_portrait_url not in", values, "headPortraitUrl"); + return (Criteria) this; + } + + public Criteria andHeadPortraitUrlBetween(String value1, String value2) { + addCriterion("head_portrait_url between", value1, value2, "headPortraitUrl"); + return (Criteria) this; + } + + public Criteria andHeadPortraitUrlNotBetween(String value1, String value2) { + addCriterion("head_portrait_url not between", value1, value2, "headPortraitUrl"); + return (Criteria) this; + } } public static class Criteria extends GeneratedCriteria { diff --git a/game/src/main/java/com/ccsens/game/service/IScreenService.java b/game/src/main/java/com/ccsens/game/service/IScreenService.java index 812771aa..dd7f90b8 100644 --- a/game/src/main/java/com/ccsens/game/service/IScreenService.java +++ b/game/src/main/java/com/ccsens/game/service/IScreenService.java @@ -39,9 +39,21 @@ public interface IScreenService { Long getGameTypeId(Long recordId); + /** + * 根据游戏id获取分组信息 + * @param recordId 游戏id + * @return 返回分组信息 + */ List getGroupByRecordId(Long recordId); ScreenVo.RecordInfo getRecordByTaskId(Long taskId,String gameType); Map getGroupTotalScore(Long groupId); + + /** + * 查询游戏配置excel + * @param params + * @return + */ + List getConfig(QueryDto params)throws Exception; } 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 5ec7e14e..5f90ec47 100644 --- a/game/src/main/java/com/ccsens/game/service/ScreenService.java +++ b/game/src/main/java/com/ccsens/game/service/ScreenService.java @@ -1,10 +1,12 @@ package com.ccsens.game.service; import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.date.DateUtil; 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.ccsens.cloudutil.bean.tall.dto.WpsDto; import com.ccsens.cloudutil.feign.TallFeignClient; import com.ccsens.game.bean.dto.ClientDto; import com.ccsens.game.bean.dto.ScreenDto; @@ -16,22 +18,27 @@ import com.ccsens.game.persist.dao.*; import com.ccsens.game.util.GameConstant; import com.ccsens.game.util.SendMsg; import com.ccsens.util.CodeEnum; +import com.ccsens.util.ExcelUtil; import com.ccsens.util.RedisUtil; import com.ccsens.util.WebConstant; import com.ccsens.util.bean.dto.QueryDto; import com.ccsens.util.exception.BaseException; - import com.fasterxml.jackson.core.JsonProcessingException; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.xssf.usermodel.XSSFRow; +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.springframework.data.redis.core.ZSetOperations; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; -import java.io.File; +import javax.annotation.Resource; +import java.io.*; import java.util.*; -import java.util.concurrent.*; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; /** * @author zy @@ -40,92 +47,57 @@ import java.util.concurrent.*; @Service @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) public class ScreenService implements IScreenService { - @Autowired - private ClientService clientService; - @Autowired + @Resource private GameUserPayDao gameUserPayDao; - @Autowired + @Resource private GameTypeDao gameTypeDao; - @Autowired + @Resource private GameRecordDao gameRecordDao; - @Autowired + @Resource private GameGroupDao gameGroupDao; - @Autowired + @Resource private GameUserJoinGroupDao gameUserJoinGroupDao; - @Autowired + @Resource private GameActivityRuleDao activityRuleDao; - @Autowired + @Resource private GameActivityPrizeDao activityPrizeDao; - @Autowired + @Resource private GamePrizeInstructionsDao prizeInstructionsDao; - @Autowired + @Resource private GameUserJoinDao gameUserJoinDao; - @Autowired + @Resource private TallFeignClient tallFeignClient; - @Autowired + @Resource private IMessageService messageService; - - @Autowired + @Resource private Snowflake snowflake; - @Autowired + @Resource private SendMsg sendMsg; - @Autowired + @Resource private RedisUtil redisUtil; /** - * 传入用户信息,返回游戏大屏路径 + * 创建游戏 * - * @return + * @return 返回游戏数据 */ @Override public ScreenVo.UrlVo getScreenUrl(QueryDto params) throws Exception { ScreenDto.MemberGame memberGame = params.getParam(); + Long userId = params.getUserId(); //查找游戏 - GameType gameType = null; GameTypeExample gameTypeExample = new GameTypeExample(); gameTypeExample.createCriteria().andCodeEqualTo(memberGame.getGameType()); List gameTypeList = gameTypeDao.selectByExample(gameTypeExample); - if (CollectionUtil.isNotEmpty(gameTypeList)) { - gameType = gameTypeList.get(0); - } - if (ObjectUtil.isNull(gameType)) { + if (CollectionUtil.isEmpty(gameTypeList)) { throw new BaseException(CodeEnum.NOT_GAME_TYPE); } + GameType gameType = gameTypeList.get(0); //2、查找此用户购买的此游戏的信息,若没有则添加一条记录,默认已付款,结束时间为添加后的一个月,默认次数为10次 - GameUserPay gameUserPay = null; - GameUserPayExample gameUserPayExample = new GameUserPayExample(); - gameUserPayExample.createCriteria().andUserIdEqualTo(params.getUserId()).andGameTypeIdEqualTo(gameType.getId()); - List gameUserPayList = gameUserPayDao.selectByExample(gameUserPayExample); - if (CollectionUtil.isNotEmpty(gameUserPayList)) { - gameUserPay = gameUserPayList.get(0); - } else { - gameUserPay = new GameUserPay(); - gameUserPay.setId(snowflake.nextId()); - gameUserPay.setUserId(params.getUserId()); - gameUserPay.setGameTypeId(gameType.getId()); - gameUserPay.setTotalCount(10); - gameUserPay.setUsedCount(0); - gameUserPay.setCreatedTime(System.currentTimeMillis()); - gameUserPay.setDueTime(gameUserPay.getCreatedTime() + (3600 * 24 * 30)); - gameUserPayDao.insertSelective(gameUserPay); - } - //查询该任务下的游戏记录信息 + GameUserPay gameUserPay = getGameUserPay(userId, gameType); + //查询该任务下的游戏记录信息 如果还有其他未结束的游戏则返回提示信息 if (ObjectUtil.isNotNull(memberGame.getTaskId())) { - GameRecordExample recordExample = new GameRecordExample(); - recordExample.createCriteria().andTaskIdEqualTo(memberGame.getTaskId()); - recordExample.setOrderByClause("created_at DESC"); - List recordList = gameRecordDao.selectByExample(recordExample); - if (CollectionUtil.isNotEmpty(recordList)) { - 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); - } - } + selectOldRecord(memberGame.getTaskId()); } //3、根据用户购买的记录,添加一场新的游戏记录 @@ -143,21 +115,36 @@ public class ScreenService implements IScreenService { } gameRecord.setUrl(gameUrl + gameType.getScreenUrl() + "?id=" + gameRecord.getId()); gameRecord.setQrCodeUrl(gameUrl + gameRecord.getId() + File.separator + gameType.getClientUrl()); + //查找此任务下的游戏配置表 + byte businessType = 8; + if( GameConstant.GAME_TYPE_SQ.equalsIgnoreCase(memberGame.getGameType())){ + businessType = 9; + }else if( GameConstant.GAME_TYPE_BH.equalsIgnoreCase(memberGame.getGameType())){ + businessType = 10; + } + String wpsFilePath = tallFeignClient.getWpsFilePath(memberGame.getTaskId(),businessType); + if(StrUtil.isNotEmpty(wpsFilePath)){ + //添加配置信息 + saveGameRecord(wpsFilePath,gameRecord); + } + //将游戏记录添加数据库 gameRecordDao.insertSelective(gameRecord); - //4、 判断是否有分组,如果是分组游戏,添加两条分组信息 - 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); + //配置表不存在,而且游戏类型默认为分组游戏,默认添加两个分组 + 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); + } } //5、查询该游戏的规则 @@ -172,7 +159,7 @@ public class ScreenService implements IScreenService { String url = gameRecord.getUrl() + "&projectId=" + memberGame.getProjectId(); //给所有人发送消息发送消息 ChromeMessageDto chromeMessageDto = new ChromeMessageDto(url, gameRecord.getId(), memberGame.getProjectId(),gameType.getCode()); - BaseMessageDto.MessageUser messageUser = null; + BaseMessageDto.MessageUser messageUser; List messageUserList = new ArrayList<>(); //获取项目下所有成员 List memberIdList = tallFeignClient.getMemberIdListByProject(memberGame.getProjectId()); @@ -185,14 +172,237 @@ public class ScreenService implements IScreenService { } chromeMessageDto.setReceivers(messageUserList); messageService.sendGameMessageWithGetUrl(chromeMessageDto); - return urlVo; } + /** + * 根据配置信息创建游戏 + * @param wpsFilePath 配置文件的路径 + * @param gameRecord 新建的游戏记录信息 + */ + 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); } + //读取sheet + XSSFSheet sheet = wb.getSheet("游戏配置表"); + if(ObjectUtil.isNull(sheet)){ throw new BaseException(CodeEnum.NOT_CONFIG_OR_ERR); } + //比赛模式 + XSSFRow gamePatternRow = sheet.getRow(1); + if(ObjectUtil.isNotNull(gamePatternRow)){ + String gamePattern = ExcelUtil.getCellValue(gamePatternRow.getCell(1)); + if(gamePattern.equalsIgnoreCase(GameConstant.GAME_GROUP)){ + gameRecord.setGroup((byte) 1); + } + } + //比赛时长 + XSSFRow durationRow = sheet.getRow(2); + if(ObjectUtil.isNotNull(durationRow)){ + int duration = Integer.parseInt(ExcelUtil.getCellValue(durationRow.getCell(1))); + gameRecord.setDuration(duration); + } + //人数上限 + XSSFRow memberLimitRow = sheet.getRow(3); + if(ObjectUtil.isNotNull(memberLimitRow)){ + int memberLimit = Integer.parseInt(ExcelUtil.getCellValue(durationRow.getCell(1))); + gameRecord.setMemberLimit(memberLimit); + } + //排名计算方式 + XSSFRow rankRuleRow = sheet.getRow(4); + if(ObjectUtil.isNotNull(rankRuleRow)){ + String rankRule = ExcelUtil.getCellValue(rankRuleRow.getCell(1)); + if(rankRule.equalsIgnoreCase(GameConstant.GAME_RANK_AVE)) { + gameRecord.setRankRule((byte) 1); + } + } + //添加分组信息 + if(gameRecord.getGroup() == 1){ + for (int i = 8; i < sheet.getLastRowNum(); i++){ + XSSFRow groupRow = sheet.getRow(1); + if(ObjectUtil.isNotNull(groupRow)){ + String groupName = ExcelUtil.getCellValue(groupRow.getCell(0)); + String groupUrl = ExcelUtil.getCellValue(groupRow.getCell(0)); + if(ObjectUtil.isNotNull(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)){ + gameGroup.setHeadPortraitUrl(groupUrl); + } + gameGroupDao.insertSelective(gameGroup); + } + } + } + } + } + + /** + * 查询该任务下的游戏记录信息 如果还有其他未结束的游戏则返回提示信息 + * @param taskId 任务id + */ + private void selectOldRecord(Long taskId) { + GameRecordExample recordExample = new GameRecordExample(); + recordExample.createCriteria().andTaskIdEqualTo(taskId); + recordExample.setOrderByClause("created_at DESC"); + List recordList = gameRecordDao.selectByExample(recordExample); + if (CollectionUtil.isNotEmpty(recordList)) { + 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); + } + } + } + + /** + * 查找此用户购买的此游戏的信息 + * @param userId userId + * @param gameType 游戏类型 + * @return 返回购买记录 + */ + private GameUserPay getGameUserPay(Long userId, GameType gameType) { + GameUserPay gameUserPay; + GameUserPayExample gameUserPayExample = new GameUserPayExample(); + gameUserPayExample.createCriteria().andUserIdEqualTo(userId).andGameTypeIdEqualTo(gameType.getId()); + List gameUserPayList = gameUserPayDao.selectByExample(gameUserPayExample); + if (CollectionUtil.isNotEmpty(gameUserPayList)) { + gameUserPay = gameUserPayList.get(0); + } else { + gameUserPay = new GameUserPay(); + gameUserPay.setId(snowflake.nextId()); + gameUserPay.setUserId(userId); + gameUserPay.setGameTypeId(gameType.getId()); + gameUserPay.setTotalCount(10); + gameUserPay.setUsedCount(0); + gameUserPay.setCreatedTime(System.currentTimeMillis()); + gameUserPay.setDueTime(gameUserPay.getCreatedTime() + (3600 * 24 * 30)); + gameUserPayDao.insertSelective(gameUserPay); + } + return gameUserPay; + } + +// @Override +// public ScreenVo.UrlVo getScreenUrl(QueryDto params) throws Exception { +// ScreenDto.MemberGame memberGame = params.getParam(); +// //查找游戏 +// GameType gameType = null; +// GameTypeExample gameTypeExample = new GameTypeExample(); +// gameTypeExample.createCriteria().andCodeEqualTo(memberGame.getGameType()); +// List gameTypeList = gameTypeDao.selectByExample(gameTypeExample); +// if (CollectionUtil.isNotEmpty(gameTypeList)) { +// gameType = gameTypeList.get(0); +// } +// if (ObjectUtil.isNull(gameType)) { +// throw new BaseException(CodeEnum.NOT_GAME_TYPE); +// } +// //2、查找此用户购买的此游戏的信息,若没有则添加一条记录,默认已付款,结束时间为添加后的一个月,默认次数为10次 +// GameUserPay gameUserPay = null; +// GameUserPayExample gameUserPayExample = new GameUserPayExample(); +// gameUserPayExample.createCriteria().andUserIdEqualTo(params.getUserId()).andGameTypeIdEqualTo(gameType.getId()); +// List gameUserPayList = gameUserPayDao.selectByExample(gameUserPayExample); +// if (CollectionUtil.isNotEmpty(gameUserPayList)) { +// gameUserPay = gameUserPayList.get(0); +// } else { +// gameUserPay = new GameUserPay(); +// gameUserPay.setId(snowflake.nextId()); +// gameUserPay.setUserId(params.getUserId()); +// gameUserPay.setGameTypeId(gameType.getId()); +// gameUserPay.setTotalCount(10); +// gameUserPay.setUsedCount(0); +// gameUserPay.setCreatedTime(System.currentTimeMillis()); +// gameUserPay.setDueTime(gameUserPay.getCreatedTime() + (3600 * 24 * 30)); +// gameUserPayDao.insertSelective(gameUserPay); +// } +// //查询该任务下的游戏记录信息 +// if (ObjectUtil.isNotNull(memberGame.getTaskId())) { +// GameRecordExample recordExample = new GameRecordExample(); +// recordExample.createCriteria().andTaskIdEqualTo(memberGame.getTaskId()); +// recordExample.setOrderByClause("created_at DESC"); +// List recordList = gameRecordDao.selectByExample(recordExample); +// if (CollectionUtil.isNotEmpty(recordList)) { +// 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); +// } +// } +// } +// +// //3、根据用户购买的记录,添加一场新的游戏记录 +// GameRecord gameRecord = new GameRecord(); +// gameRecord.setId(snowflake.nextId()); +// gameRecord.setUserPayId(gameUserPay.getId()); +// gameRecord.setTaskId(memberGame.getTaskId()); +// //添加路径 +// 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) { +// 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); +// } +// +// //5、查询该游戏的规则 +// List ruleList = getGameActivityRule(gameType.getId()); +// //6、返回 +// ScreenVo.UrlVo urlVo = new ScreenVo.UrlVo(); +// urlVo.setId(gameRecord.getId()); +// urlVo.setUrl(gameRecord.getUrl()); +// urlVo.setRuleList(ruleList); +// +// //路径(添加项目id) +// String url = gameRecord.getUrl() + "&projectId=" + memberGame.getProjectId(); +// //给所有人发送消息发送消息 +// ChromeMessageDto chromeMessageDto = new ChromeMessageDto(url, gameRecord.getId(), memberGame.getProjectId(),gameType.getCode()); +// BaseMessageDto.MessageUser messageUser = null; +// List messageUserList = new ArrayList<>(); +// //获取项目下所有成员 +// List memberIdList = tallFeignClient.getMemberIdListByProject(memberGame.getProjectId()); +// if (CollectionUtil.isNotEmpty(memberIdList)) { +// for (Long memberId : memberIdList) { +// messageUser = new BaseMessageDto.MessageUser(); +// messageUser.setUserId(memberId); +// messageUserList.add(messageUser); +// } +// } +// chromeMessageDto.setReceivers(messageUserList); +// messageService.sendGameMessageWithGetUrl(chromeMessageDto); +// +// return urlVo; +// } + /** * 获取游戏基本信息 - * - * @return + * @return 返回游戏基本信息 */ @Override public ScreenVo.GameInfoVo getGameInformation(QueryDto params) { @@ -252,12 +462,10 @@ public class ScreenService implements IScreenService { } gameInfoVo.setPreparingData(preparingData); break; - case 2: - break; case 3: //查询游戏是否有分组 GameType gameType = gameTypeDao.selectByPrimaryKey(gameUserPay.getGameTypeId()); - ScreenVo.CompletedData completedData = null; + ScreenVo.CompletedData completedData; if (gameType.getIsGroup() == 0) { completedData = getCompletedData(memberRecord.getMemberRecord()); } else { @@ -271,7 +479,6 @@ public class ScreenService implements IScreenService { return gameInfoVo; } - /** * 获取游戏状态 */ @@ -332,7 +539,7 @@ public class ScreenService implements IScreenService { } break; case GameConstant.GAME_COMPLETED: - ScreenVo.CompletedData completedData = null; + ScreenVo.CompletedData completedData; if (gameType.getIsGroup() == 0) { completedData = getCompletedData(memberRecord.getMemberRecord()); } else { @@ -440,12 +647,10 @@ public class ScreenService implements IScreenService { return groupMap; } - /** * 查询总分数,总次数,平均以及前十名 * - * @param gameRecordId - * @return + * @param gameRecordId 游戏id */ private ScreenVo.CompletedData getCompletedData(long gameRecordId) { ScreenVo.CompletedData completedData = new ScreenVo.CompletedData(); @@ -488,9 +693,9 @@ public class ScreenService implements IScreenService { /** * 查询参加游戏的用户信息 * - * @param userId - * @param gameRecordId - * @return + * @param userId userID + * @param gameRecordId 游戏id + * @return 返回参加游戏的用户 */ private GameUserJoin getGameUserJoin(Long userId, Long gameRecordId) { GameUserJoinExample joinExample = new GameUserJoinExample(); @@ -506,13 +711,13 @@ public class ScreenService implements IScreenService { /** * 查询游戏信息 * - * @param gameRecordId - * @return + * @param gameRecordId 游戏记录id + * @return 返回游戏信息 */ @Override public GameRecord getGameRecord(long gameRecordId) { String gameRecordStr = (String) redisUtil.get(GameConstant.generateGameStatusKey(gameRecordId)); - GameRecord gameRecord = null; + GameRecord gameRecord; if (StrUtil.isBlank(gameRecordStr)) { gameRecord = gameRecordDao.selectByPrimaryKey(gameRecordId); if (ObjectUtil.isNull(gameRecord)) { @@ -527,8 +732,8 @@ public class ScreenService implements IScreenService { /** * 查询前十名 * - * @param gameRecordId - * @return + * @param gameRecordId 游戏记录id + * @return 返回前十名信息 */ private List getTopUsers(Long gameRecordId) { List tops; @@ -573,51 +778,57 @@ public class ScreenService implements IScreenService { throw new BaseException(CodeEnum.NOT_GAME_TYPE); } - if (gameUserPay.getUsedCount() >= gameUserPay.getTotalCount()) { - throw new BaseException(CodeEnum.GAME_NOT_TIMES); - } - GameRecord gameRecordNew = null; - if (gameRecord.getGameStatus() == 3) { - //添加一场新的游戏记录 - gameRecordNew = new GameRecord(); - gameRecordNew.setId(snowflake.nextId()); - gameRecordNew.setUserPayId(gameUserPay.getId()); - //添加路径 - 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(); - //给所有人发送消息发送消息 - ChromeMessageDto chromeMessageDto = new ChromeMessageDto(url, gameRecord.getId(), memberRecord.getProjectId(),gameType.getCode()); - BaseMessageDto.MessageUser messageUser = null; - List messageUserList = new ArrayList<>(); - //获取项目下所有成员 - List memberIdList = tallFeignClient.getMemberIdListByProject(memberRecord.getProjectId()); - if (CollectionUtil.isNotEmpty(memberIdList)) { - for (Long memberId : memberIdList) { - messageUser = new BaseMessageDto.MessageUser(); - messageUser.setUserId(memberId); - messageUserList.add(messageUser); - } - } - chromeMessageDto.setReceivers(messageUserList); - messageService.sendGameMessageWithGetUrl(chromeMessageDto); - - } else { +// if (gameUserPay.getUsedCount() >= gameUserPay.getTotalCount()) { +// throw new BaseException(CodeEnum.GAME_NOT_TIMES); +// } + //之前的游戏若是准备中或进行中,则返回提示 + if(gameRecord.getGameStatus() == GameConstant.GAME_PREPARATION || + gameRecord.getGameStatus() == GameConstant.GAME_PROCESSING){ throw new BaseException(CodeEnum.GAME_NO_END); } + //若是未开始,则将之前的游戏状态改成已结束 + if(gameRecord.getGameStatus() == GameConstant.GAME_PENDING){ + gameRecord.setGameStatus(GameConstant.GAME_COMPLETED); + gameRecordDao.updateByPrimaryKeySelective(gameRecord); + } + GameRecord gameRecordNew; + //添加一场新的游戏记录 + gameRecordNew = new GameRecord(); + gameRecordNew.setId(snowflake.nextId()); + gameRecordNew.setUserPayId(gameUserPay.getId()); + //添加路径 + 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(); + //给所有人发送消息发送消息 + ChromeMessageDto chromeMessageDto = new ChromeMessageDto(url, gameRecord.getId(), memberRecord.getProjectId(),gameType.getCode()); + BaseMessageDto.MessageUser messageUser; + List messageUserList = new ArrayList<>(); + //获取项目下所有成员 + List memberIdList = tallFeignClient.getMemberIdListByProject(memberRecord.getProjectId()); + if (CollectionUtil.isNotEmpty(memberIdList)) { + for (Long memberId : memberIdList) { + messageUser = new BaseMessageDto.MessageUser(); + messageUser.setUserId(memberId); + messageUserList.add(messageUser); + } + } + chromeMessageDto.setReceivers(messageUserList); + messageService.sendGameMessageWithGetUrl(chromeMessageDto); + return gameRecordNew.getUrl(); } @@ -715,8 +926,8 @@ public class ScreenService implements IScreenService { /** * 开始游戏 * - * @param start - * @return + * @param start 游戏记录,开始时间 + * @return 返回本地开始和结束时间 */ @Override public ScreenVo.StartGame startGame(ScreenDto.Start start) { @@ -830,8 +1041,7 @@ public class ScreenService implements IScreenService { /** * 推送客户端状态 * - * @param gameRecord - * @param executor + * @param gameRecord 游戏记录 */ private void pushClient(GameRecord gameRecord, ScheduledExecutorService executor) { @@ -943,4 +1153,66 @@ public class ScreenService implements IScreenService { } return recordInfo; } + + @Override + public List getConfig(QueryDto params)throws Exception { + ScreenDto.GetConfig getConfig = params.getParam(); + //根据游戏类型获取文件类型 + byte businessType = 8; + if( GameConstant.GAME_TYPE_SQ.equalsIgnoreCase(getConfig.getGameType())){ + businessType = 9; + }else if( GameConstant.GAME_TYPE_BH.equalsIgnoreCase(getConfig.getGameType())){ + businessType = 10; + } + //查询该任务是否已有创建的游戏配置 + List wpsPath; + WpsDto.VisitWpsUrl visitWpsUrl = new WpsDto.VisitWpsUrl(); + visitWpsUrl.setBusinessId(getConfig.getTaskId()); + visitWpsUrl.setBusinessType(businessType); + visitWpsUrl.setUserId(params.getUserId()); + wpsPath = tallFeignClient.queryVisitUrls(visitWpsUrl); + //有配置直接返回 + if (CollectionUtil.isNotEmpty(wpsPath)) { + return wpsPath; + } + //没有则生成默认模板并返回, + //查找游戏 + GameTypeExample gameTypeExample = new GameTypeExample(); + gameTypeExample.createCriteria().andCodeEqualTo(getConfig.getGameType()); + List gameTypeList = gameTypeDao.selectByExample(gameTypeExample); + if (CollectionUtil.isEmpty(gameTypeList)) { + throw new BaseException(CodeEnum.NOT_GAME_TYPE); + } + GameType gameType = gameTypeList.get(0); + + //生成excel写入的数据 + String templatePath = WebConstant.HOME_STATICREC + "GameConfig.xlsx"; + InputStream is = new FileInputStream(new File(templatePath)); + Workbook wb = new XSSFWorkbook(is); + //生成文件 + String name = gameType.getName() + "游戏配置表.xlsx"; + String fileName = "game/" + DateUtil.today() + "/" + System.currentTimeMillis() + ".xlsx"; + String path = WebConstant.UPLOAD_PATH_BASE + File.separator + fileName; + File tmpFile = new File(path); + if (!tmpFile.getParentFile().exists()) { + tmpFile.getParentFile().mkdirs(); + } + OutputStream stream = new FileOutputStream(tmpFile); + wb.write(stream); + stream.close(); + //关联wps + WpsDto.Business business = new WpsDto.Business(); + business.setBusinessId(getConfig.getTaskId()); + business.setBusinessType(businessType); + business.setUserId(params.getUserId()); + business.setFileName(name); + business.setFilePath(fileName); + business.setFileSize(tmpFile.length()); + business.setOperation(WebConstant.Wps.USER_OPERATION_NEW); + business.setPrivilege(WebConstant.Wps.PROJECT_PRIVILEGE_WRITE); + tallFeignClient.saveWpsFile(business); + + return tallFeignClient.queryVisitUrls(visitWpsUrl); + } + } 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 a82ac891..7f39fae9 100644 --- a/game/src/main/java/com/ccsens/game/util/GameConstant.java +++ b/game/src/main/java/com/ccsens/game/util/GameConstant.java @@ -37,6 +37,14 @@ public class GameConstant { public static final long GAME_TIME = 60*1000; /**再来一次*/ public static final byte GAME_RESTART_STATUS = 1; + /**个人*/ + public static final String GAME_INDIVIDUAL = "个人"; + /**团体*/ + public static final String GAME_GROUP = "团体"; + /**按人均分排名*/ + public static final String GAME_RANK_AVE = "按人均分排名"; + /**按总分排名*/ + public static final String GAME_RANK_TOTAL = "按总分排名"; /** * 生成游戏key diff --git a/game/src/main/resources/mapper_raw/GameGroupMapper.xml b/game/src/main/resources/mapper_raw/GameGroupMapper.xml index 38e6baa4..747e4a8c 100644 --- a/game/src/main/resources/mapper_raw/GameGroupMapper.xml +++ b/game/src/main/resources/mapper_raw/GameGroupMapper.xml @@ -9,6 +9,7 @@ + @@ -69,7 +70,7 @@ - id, record_id, code, name, created_at, updated_at, rec_status + id, record_id, code, name, created_at, updated_at, rec_status, head_portrait_url @@ -188,6 +195,9 @@ rec_status = #{record.recStatus,jdbcType=TINYINT}, + + head_portrait_url = #{record.headPortraitUrl,jdbcType=VARCHAR}, + @@ -201,7 +211,8 @@ name = #{record.name,jdbcType=VARCHAR}, created_at = #{record.createdAt,jdbcType=TIMESTAMP}, updated_at = #{record.updatedAt,jdbcType=TIMESTAMP}, - rec_status = #{record.recStatus,jdbcType=TINYINT} + rec_status = #{record.recStatus,jdbcType=TINYINT}, + head_portrait_url = #{record.headPortraitUrl,jdbcType=VARCHAR} @@ -227,6 +238,9 @@ rec_status = #{recStatus,jdbcType=TINYINT}, + + head_portrait_url = #{headPortraitUrl,jdbcType=VARCHAR}, + where id = #{id,jdbcType=BIGINT} @@ -237,7 +251,8 @@ name = #{name,jdbcType=VARCHAR}, created_at = #{createdAt,jdbcType=TIMESTAMP}, updated_at = #{updatedAt,jdbcType=TIMESTAMP}, - rec_status = #{recStatus,jdbcType=TINYINT} + rec_status = #{recStatus,jdbcType=TINYINT}, + head_portrait_url = #{headPortraitUrl,jdbcType=VARCHAR} where id = #{id,jdbcType=BIGINT} \ No newline at end of file diff --git a/game/src/main/resources/mbg.xml b/game/src/main/resources/mbg.xml index 5618ea6e..bb23d3f1 100644 --- a/game/src/main/resources/mbg.xml +++ b/game/src/main/resources/mbg.xml @@ -57,14 +57,14 @@ -
+ - +