Browse Source

添加手机再玩一次

master
zy_Java 5 years ago
parent
commit
4a720d6bdf
  1. 2
      cloudutil/src/main/java/com/ccsens/cloudutil/feign/TallFeignClient.java
  2. 10
      game/src/main/java/com/ccsens/game/api/ScreenController.java
  3. 9
      game/src/main/java/com/ccsens/game/bean/dto/ScreenDto.java
  4. 4
      game/src/main/java/com/ccsens/game/bean/vo/ScreenVo.java
  5. 12
      game/src/main/java/com/ccsens/game/service/IScreenService.java
  6. 77
      game/src/main/java/com/ccsens/game/service/ScreenService.java
  7. 33
      game/src/main/java/com/ccsens/game/util/SendMsg.java
  8. 2
      tall/src/main/java/com/ccsens/tall/config/SpringConfig.java
  9. 3
      tall/src/main/java/com/ccsens/tall/service/UserService.java
  10. 3
      tall/src/main/java/com/ccsens/tall/web/UserController.java
  11. 4
      tall/src/main/resources/application.yml

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

@ -113,7 +113,7 @@ public interface TallFeignClient {
*
* @return
*/
@GetMapping("/users/userInfo")
@GetMapping("/users/getUserInfo")
JsonResponse<MemberVo.MemberInfo> getUserByUserId(@RequestParam(name = "userId") Long userId);

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

@ -83,6 +83,16 @@ public class ScreenController {
return JsonResponse.newInstance().ok(url);
}
@Login
@ApiOperation(value = "手机端再玩一次", notes = "")
@ApiImplicitParams({
})
@RequestMapping(value = "startAgainByPhone", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse<String> startAgainByPhone(@ApiParam @Validated @RequestBody QueryDto<ScreenDto.StartAgainByPhone> params) throws Exception {
log.info("手机端再玩一次:{}",params);
Long recordId = screenService.startAgainByPhone(params);
return JsonResponse.newInstance().ok(recordId);
}
@Login
@ApiOperation(value = "自定义游戏时查询游戏配置信息excel", notes = "")

9
game/src/main/java/com/ccsens/game/bean/dto/ScreenDto.java

@ -4,6 +4,7 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@Data
@ -35,6 +36,14 @@ public class ScreenDto {
private Long projectId;
}
@Data
@ApiModel("手机端再玩一次")
public static class StartAgainByPhone{
@NotEmpty
@ApiModelProperty("游戏类型")
private String gameType;
}
@Data
@ApiModel
public static class MemberRecordAndTime{

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

@ -166,6 +166,10 @@ public class ScreenVo {
private Integer score;
@ApiModelProperty("该组的总次数/均次数")
private Integer times;
@ApiModelProperty("该组的总分")
private Integer totalScore;
@ApiModelProperty("该组的总次数")
private Integer totalTimes;
@ApiModelProperty("该组总人数")
private Integer totalMembers;
@ApiModelProperty("code")

12
game/src/main/java/com/ccsens/game/service/IScreenService.java

@ -15,6 +15,13 @@ public interface IScreenService {
ScreenVo.GameStatusVo getGameStatusVo(QueryDto<ScreenDto.MemberRecord> params);
/**
* 查找分组信息排序
* @param gameRecord 游戏记录
* @return 返回排序后的每个组的信息
*/
List<ScreenVo.GroupVo> getGroupScore2(GameRecord gameRecord);
String startAgain(QueryDto<ScreenDto.MemberRecord> params) throws Exception;
/**
@ -56,4 +63,9 @@ public interface IScreenService {
* @return
*/
List<String> getConfig(QueryDto<ScreenDto.GetConfig> params)throws Exception;
/**
* 手机端再玩一次
*/
Long startAgainByPhone(QueryDto<ScreenDto.StartAgainByPhone> params);
}

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

@ -599,7 +599,8 @@ public class ScreenService implements IScreenService {
/**
* 进行中查询每个组的信息
*/
private List<ScreenVo.GroupVo> getGroupScore2(GameRecord gameRecord) {
@Override
public List<ScreenVo.GroupVo> getGroupScore2(GameRecord gameRecord) {
String groupKey = gameRecord.getId() + "_group";
Set<ZSetOperations.TypedTuple<Object>> typedTuples = redisUtil.zsRevGetWithScore(groupKey, 0, -1);
if(CollectionUtil.isNotEmpty(typedTuples)){
@ -616,7 +617,8 @@ public class ScreenService implements IScreenService {
o = 0;
}
groupVo.setTotalMembers((int)o);
groupVo.setTotalScore(score);
groupVo.setTotalTimes(score / 100);
if(gameRecord.getRankRule() == GameConstant.RANK_RULE_AVA){
groupVo.setScore((int)o == 0 ? 0 : score / (int)o);
groupVo.setTimes(groupVo.getScore() /100);
@ -637,6 +639,10 @@ public class ScreenService implements IScreenService {
return vos;
}
List<ScreenVo.GroupVo> vos = gameGroupDao.queryGroups(gameRecord.getId());
vos.forEach(vo ->{
vo.setTotalScore(vo.getScore());
vo.setTotalTimes(vo.getScore() == null ? 0 : vo.getScore() / 100);
});
if (CollectionUtil.isEmpty(vos) || gameRecord.getRankRule() == GameConstant.RANK_RULE_TOTAL) {
return vos;
}
@ -1433,4 +1439,71 @@ public class ScreenService implements IScreenService {
return wpsPath;
}
/**
* 手机端再玩一次
* @param params 游戏类型
* @return 返回游戏id
*/
@Override
public Long startAgainByPhone(QueryDto<ScreenDto.StartAgainByPhone> params) {
log.info("手机端再玩一次:{}",params);
ScreenDto.StartAgainByPhone startAgainByPhone = params.getParam();
Long userId = params.getUserId();
//查找游戏
GameTypeExample gameTypeExample = new GameTypeExample();
gameTypeExample.createCriteria().andCodeEqualTo(startAgainByPhone.getGameType());
List<GameType> gameTypeList = gameTypeDao.selectByExample(gameTypeExample);
if (CollectionUtil.isEmpty(gameTypeList)) {
throw new BaseException(CodeEnum.NOT_GAME_TYPE);
}
GameType gameType = gameTypeList.get(0);
log.info("查找游戏类型:{}",gameType);
//2、查找此用户购买的此游戏的信息,若没有则添加一条记录,默认已付款,结束时间为添加后的一个月,默认次数为10次
GameUserPay gameUserPay = getGameUserPay(userId, gameType);
//3、根据用户购买的记录,添加一场新的游戏记录
GameRecord gameRecord = new GameRecord();
gameRecord.setId(snowflake.nextId());
gameRecord.setUserPayId(gameUserPay.getId());
gameRecord.setGameGroup((byte) 0);
//添加路径
String gameUrl = PropUtil.notGatewayUrl + WebConstant.TEST_URL_GAME_SQ;
switch (gameType.getCode()){
case GameConstant.GAME_TYPE_SQ: break;
case GameConstant.GAME_TYPE_SP: gameUrl = PropUtil.notGatewayUrl + WebConstant.TEST_URL_GAME_SP; break;
case GameConstant.GAME_TYPE_BH: gameUrl = PropUtil.notGatewayUrl + WebConstant.TEST_URL_GAME_BH; break;
default:break;
}
gameRecord.setUrl(gameUrl + gameType.getScreenUrl() + "?id=" + gameRecord.getId());
gameRecordDao.insertSelective(gameRecord);
log.info("添加游戏记录:{}",gameRecord);
//配置表不存在,而且游戏类型默认为分组游戏,默认添加两个分组
if (gameType.getIsGroup() == 1) {
GameGroup gameGroupRed = new GameGroup();
gameGroupRed.setId(snowflake.nextId());
gameGroupRed.setRecordId(gameRecord.getId());
gameGroupRed.setName("红队");
gameGroupRed.setCode(GameConstant.FIRST_GROUP);
gameGroupDao.insertSelective(gameGroupRed);
GameGroup gameGroupBlue = new GameGroup();
gameGroupBlue.setId(snowflake.nextId());
gameGroupBlue.setRecordId(gameRecord.getId());
gameGroupBlue.setName("蓝队");
gameGroupBlue.setCode(GameConstant.SECOND_GROUP);
gameGroupDao.insertSelective(gameGroupBlue);
}
//5、查询该游戏的规则
List<String> ruleList = getGameActivityRule(gameType.getId());
//6、返回
ScreenVo.UrlVo urlVo = new ScreenVo.UrlVo();
urlVo.setId(gameRecord.getId());
urlVo.setUrl(gameRecord.getUrl());
urlVo.setRuleList(ruleList);
return gameRecord.getId();
}
}

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

@ -8,7 +8,9 @@ import com.ccsens.game.bean.dto.message.ChangeStatusMessageDto;
import com.ccsens.game.bean.dto.message.GameMessageWithChangeStatusOut;
import com.ccsens.game.bean.po.GameRecord;
import com.ccsens.game.bean.vo.ClientVo;
import com.ccsens.game.service.ClientService;
import com.ccsens.game.bean.vo.ScreenVo;
import com.ccsens.game.service.IClientService;
import com.ccsens.game.service.IScreenService;
import com.ccsens.util.JacksonUtil;
import com.ccsens.util.RedisUtil;
import com.ccsens.util.WebConstant;
@ -16,10 +18,11 @@ import com.ccsens.util.config.RabbitMQConfig;
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@ -35,11 +38,14 @@ import java.util.concurrent.TimeUnit;
@Service
@Slf4j
public class SendMsg {
@Autowired
private ClientService clientService;
@Autowired
@Resource
private IClientService clientService;
@Lazy
@Resource
private IScreenService screenService;
@Resource
private AmqpTemplate rabbitTemplate;
@Autowired
@Resource
private RedisUtil redisUtil;
public void sendStatus(GameRecord gameRecord, List<ClientDto.RedisUser> userJoins, byte status) throws JsonProcessingException {
@ -84,7 +90,20 @@ public class SendMsg {
ChangeStatusMessageDto.CompletedData completedData = new ChangeStatusMessageDto.CompletedData();
//如果是分组游戏,获取本组分数信息
if (ObjectUtil.isNotNull(join.getGroupId())) {
ClientVo.GroupScore groupScore = clientService.getGroupScore(join.getGroupId(),gameRecord.getId());
// ClientVo.GroupScore groupScore = clientService.getGroupScore(join.getGroupId(),gameRecord.getId());
// completedData.setGroupScore(groupScore);
ClientVo.GroupScore groupScore = new ClientVo.GroupScore();
List<ScreenVo.GroupVo> groupVoList = screenService.getGroupScore2(gameRecord);
for (int i = 0; i < groupVoList.size(); i++) {
ScreenVo.GroupVo groupVo = groupVoList.get(i);
if(groupVo.getGroupId().longValue() == join.getGroupId().longValue()){
groupScore = new ClientVo.GroupScore();
groupScore.setGroupScore(groupVo.getTotalScore());
groupScore.setGroupTimes(groupVo.getTotalTimes());
groupScore.setGroupSort(i+1);
break;
}
}
completedData.setGroupScore(groupScore);
}
completedData.setTimes(join.getTimes());

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

@ -147,7 +147,7 @@ public class SpringConfig implements WebMvcConfigurer {
.excludePathPatterns("/users/userId")
.excludePathPatterns("/users/mergeUserId")
.excludePathPatterns("/users/code")
.excludePathPatterns("/users/userInfo")
.excludePathPatterns("/users/getUserInfo")
.addPathPatterns("/plugins/**")
.excludePathPatterns("/plugins/sign")
.excludePathPatterns("/plugins/fuzzy")

3
tall/src/main/java/com/ccsens/tall/service/UserService.java

@ -1361,6 +1361,7 @@ public class UserService implements IUserService {
public UserVo.WxInfo updateUserInfo(Long currentUserId, UserDto.WxInfo userInfo) {
//通过userId查找到用户
SysUser user = userDao.selectByPrimaryKey(currentUserId);
log.info("查找到原来的user信息,{}",user);
if (ObjectUtil.isNull(user)) {
throw new BaseException(CodeEnum.NOT_LOGIN);
}
@ -1387,7 +1388,7 @@ public class UserService implements IUserService {
user.setLanguage(userInfo.getLanguage());
}
userDao.updateByPrimaryKeySelective(user);
log.info("修改后的user信息,{}",user);
UserVo.WxInfo wxInfo = new UserVo.WxInfo();
BeanUtil.copyProperties(user, wxInfo);
wxInfo.setHeadImgUrl(user.getAvatarUrl());

3
tall/src/main/java/com/ccsens/tall/web/UserController.java

@ -245,6 +245,7 @@ public class UserController {
@RequestMapping(value = "/userInfo", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
public JsonResponse<UserVo.WxInfo> updateUserInfo(HttpServletRequest request,
@ApiParam @RequestBody UserDto.WxInfo userInfo) throws Exception {
log.info("修改用户信息,{}",userInfo);
Long currentUserId = Long.valueOf(((Claims) request.getAttribute(WebConstant.REQUEST_KEY_CLAIMS)).getSubject());
UserVo.WxInfo wxInfo = userService.updateUserInfo(currentUserId, userInfo);
return JsonResponse.newInstance().ok(wxInfo);
@ -448,7 +449,7 @@ public class UserController {
/**
* 查询user的信息
*/
@RequestMapping(value = "userInfo", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
@RequestMapping(value = "getUserInfo", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
public JsonResponse<MemberVo.MemberInfo> getUserInfoByUserId(Long userId) throws Exception {
MemberVo.MemberInfo memberInfo = proMemberService.getUserInfoByUserId(userId);

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

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

Loading…
Cancel
Save