game
This commit is contained in:
2025-05-06 19:01:50 +08:00
parent 894edd9710
commit d7e582854b
18 changed files with 555 additions and 52 deletions

View File

@@ -1345,6 +1345,8 @@ public class Constant {
public static final String MINI_GAME_FOR_LEADERCC = "mini_game_for_leadercc";
public static final String PUBLIC_CHAT_TIME = "public_chat_time";
public static final String MINI_GAME_FOR_JOY = "mini_game_for_joy";
/**
* 家族模块下送礼收益分成配置
*/

View File

@@ -1453,6 +1453,13 @@ public enum RedisKey {
lucky_25_status, // 礼物消息的状态
lock_lucky_25_message, // 消费送礼物消息锁
lucky_25_high_recharge_pool,
//小游戏重复订单
joy_repeat_order,
//小游戏token
joy_token,
;
public String getKey() {

View File

@@ -0,0 +1,43 @@
package com.accompany.sharding.model;
import java.util.Date;
import java.io.Serializable;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
/**
* joy play游戏记录实体类
*
* @author
* @since 2025-05-06
*/
@Data
public class JoyGameRecord implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value = "order_id", type = IdType.NONE)
private String orderId;
private Integer gameId;
private Long uid;
private Long roomUid;
private Integer coin;
/**
* 1减金币2加金币
*/
private Integer type;
/**
* 透传参数
*/
private String ext;
/**
* 备注
*/
private String remark;
private Date createTime;
private Date updateTime;
}

View File

@@ -0,0 +1,31 @@
package com.accompany.sharding.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class JoyResponseVo<T> {
@ApiModelProperty("响应状态码")
private int code;
@ApiModelProperty("响应消息")
private String message;
@ApiModelProperty("响应数据")
private T data;
public JoyResponseVo(int code, String message, T data) {
this.code = code;
this.message = message;
this.data = data;
}
public static <T> JoyResponseVo<T> success(T data) {
return new JoyResponseVo<>(200, null, data);
}
public static <T> JoyResponseVo<T> fail(int code, String message) {
return new JoyResponseVo<>(code, message, null);
}
}

View File

@@ -0,0 +1,15 @@
package com.accompany.sharding.vo;
import lombok.Data;
@Data
public class JoySubmitBodyVo {
private String transactionId;
private Integer coins;
private Integer type;
private Long tm;
private String ext;
private String remark;
private String roomId;
}

View File

@@ -0,0 +1,10 @@
package com.accompany.sharding.vo;
import lombok.Builder;
import lombok.Data;
@Builder
@Data
public class JoySubmitResult {
private Long availableCoin;
}

View File

@@ -0,0 +1,22 @@
package com.accompany.sharding.vo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Data
public class JoyUserInfoModel {
private Long userId;
private Integer gameId;
private String pkgName;
private String nickname;
private String avatarUrl;
private Long availableCoins;
private Integer level;
private String code;
private String os;
}

View File

@@ -145,6 +145,7 @@ public class ShardingSphereConfig {
tableConfigs.add(getShardingTableRuleConfiguration("lucky_24_record",
"ds.lucky_24_record_$->{20240914..20251231}",
"create_time", "lucky24RecordStrategy"));
tableConfigs.add(getShardingTableRuleConfiguration("bravo_record",
"ds.bravo_record_$->{20250320..20251231}",
"create_time", "bravoRecordStrategy"));
@@ -152,6 +153,10 @@ public class ShardingSphereConfig {
"ds.lucky_25_record_$->{20250504..20251231}",
"create_time", "lucky25RecordStrategy"));
tableConfigs.add(getShardingTableRuleConfiguration("joy_game_record",
"ds.joy_game_record_${2025..2026}${['01','02','03', '04','05','06', '07','08','09', '10','11','12']}",
"create_time", "joyGameStrategy"));
Map<String, AlgorithmConfiguration> algorithmsConfigs = new HashMap<>();
// 账单按天分表
@@ -190,6 +195,9 @@ public class ShardingSphereConfig {
//
AlgorithmConfiguration lucky25RecordShardingAlgorithm = getLucky25RecordShardingAlgorithmConfiguration();
algorithmsConfigs.put("lucky25RecordStrategy", lucky25RecordShardingAlgorithm);
//游戏日志
AlgorithmConfiguration joyGameShardingAlgorithm = getGameGoldLogShardingAlgorithmConfiguration();
algorithmsConfigs.put("joyGameStrategy", joyGameShardingAlgorithm);
ShardingRuleConfiguration config = new ShardingRuleConfiguration();
config.setTables(tableConfigs);
@@ -228,7 +236,10 @@ public class ShardingSphereConfig {
private AlgorithmConfiguration getGameGoldLogShardingAlgorithmConfiguration() {
AlgorithmConfiguration algorithmConfiguration = getMonthShardingAlgorithmConfiguration();
return algorithmConfiguration;
}
private AlgorithmConfiguration getjoyGameShardingAlgorithmConfiguration() {
return getMonthShardingAlgorithmConfiguration();
}
private AlgorithmConfiguration getBaiShunGameRecordShardingAlgorithmConfiguration() {

View File

@@ -0,0 +1,14 @@
package com.accompany.sharding.mapper;
import com.accompany.sharding.model.JoyGameRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* joy play游戏记录 Mapper 接口
*
* @author
* @since 2025-05-06
*/
public interface JoyGameRecordMapper extends BaseMapper<JoyGameRecord> {
}

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.accompany.sharding.mapper.JoyGameRecordMapper">
</mapper>

View File

@@ -40,4 +40,8 @@ public class BaiShunGetConfigDto {
*/
private Integer gsp;
private Integer gameId;
private String appKey;
}

View File

@@ -26,6 +26,9 @@ public enum ResourceCodeEnum {
LEADERCC,
//房间福袋&新红包
LUCKY_BAG
LUCKY_BAG,
//JOY 游戏
JOYPLAY,
;
}

View File

@@ -0,0 +1,22 @@
package com.accompany.business.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@Data
@Configuration
@ConfigurationProperties(prefix = "joyplay")
public class JoyGameConfig {
/**
*
*/
private String appKey;
private String privateKey;
private String iosPgkName;
private String androidPgkName;
}

View File

@@ -0,0 +1,15 @@
package com.accompany.business.service.game;
import com.accompany.sharding.model.JoyGameRecord;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* joy play游戏记录 服务类
*
* @author
* @since 2025-05-06
*/
public interface JoyGameRecordService extends IService<JoyGameRecord> {
}

View File

@@ -0,0 +1,226 @@
package com.accompany.business.service.game;
import com.accompany.business.config.JoyGameConfig;
import com.accompany.business.enums.resource.ResourceCodeEnum;
import com.accompany.business.message.GameMsgMessage;
import com.accompany.business.model.UserPurse;
import com.accompany.business.service.mq.RocketMQService;
import com.accompany.business.service.purse.UserPurseService;
import com.accompany.business.service.record.BillRecordService;
import com.accompany.business.service.user.UsersService;
import com.accompany.business.vo.game.GameResponseVO;
import com.accompany.common.constant.Constant;
import com.accompany.common.redis.RedisKey;
import com.accompany.common.result.BusiResult;
import com.accompany.common.status.BusiStatus;
import com.accompany.common.utils.DESUtils;
import com.accompany.common.utils.DateTimeUtil;
import com.accompany.common.utils.RSAUtils;
import com.accompany.core.enumeration.BillObjTypeEnum;
import com.accompany.core.exception.ServiceException;
import com.accompany.core.model.Users;
import com.accompany.core.util.KeyStore;
import com.accompany.core.util.StringUtils;
import com.accompany.sharding.model.JoyGameRecord;
import com.accompany.sharding.vo.JoyResponseVo;
import com.accompany.sharding.vo.JoySubmitBodyVo;
import com.accompany.sharding.vo.JoySubmitResult;
import com.accompany.sharding.vo.JoyUserInfoModel;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RBucket;
import org.redisson.api.RSet;
import org.redisson.api.RedissonClient;
import org.redisson.client.codec.StringCodec;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Date;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import static com.accompany.common.redis.RedisKey.joy_token;
@Slf4j
@Service
public class JoyGameService {
@Autowired
private RedissonClient redissonClient;
@Autowired
private JoyGameConfig joyGameConfig;
@Autowired
private UsersService usersService;
@Autowired
private UserPurseService userPurseService;
@Autowired
private BillRecordService billRecordService;
@Autowired
private JoyGameRecordService joyGameRecordService;
@Autowired
private RocketMQService rocketMQService;
public JoyResponseVo<JoyUserInfoModel> getUserInfo(String token) {
try {
JoyUserInfoModel joyUserInfoModel = this.checkAndGetInfo(token);
Users users = usersService.getUsersByUid(joyUserInfoModel.getUserId());
if (users == null) {
log.info("JoyGameService.getUserInfo,empty user");
return JoyResponseVo.fail(BusiStatus.NOAUTHORITY.getCode(), BusiStatus.NOAUTHORITY.getName());
}
joyUserInfoModel.setNickname(users.getNick());
joyUserInfoModel.setAvatarUrl(users.getAvatar());
UserPurse userPurse = userPurseService.queryUserPurse(users.getUid());
joyUserInfoModel.setAvailableCoins(userPurse.getDiamonds().longValue());
return JoyResponseVo.success(joyUserInfoModel);
} catch (Exception e) {
log.info("JoyGameService.getUserInfo,token:{},e:{}", token, e.getMessage(), e);
return JoyResponseVo.fail(BusiStatus.SERVERERROR.getCode(), BusiStatus.SERVERERROR.getName());
}
}
public JoyResponseVo<JoySubmitResult> submitFlow(String token, String data) {
try {
JoyUserInfoModel joyUserInfoModel = this.checkAndGetInfo(token);
String decryptByPrivateKey = this.decryptByPrivateKey(data, joyGameConfig.getPrivateKey());
JoySubmitBodyVo joySubmitBodyVo = JSONObject.parseObject(decryptByPrivateKey, JoySubmitBodyVo.class);
if (joySubmitBodyVo.getCoins() <= 0) {
log.info("JoyGameService.submitFlow,coin less than 0,token:{},data:{}", token, data);
return JoyResponseVo.fail(BusiStatus.SERVERERROR.getCode(), BusiStatus.SERVERERROR.getName());
}
String orderId = joySubmitBodyVo.getTransactionId();
String cacheKeyForLastPreHours = DateTimeUtil.getCacheKeyForLastPreHours(1);
RSet<String> thisOrderSet = redissonClient.getSet(RedisKey.joy_repeat_order.getKey(cacheKeyForLastPreHours), StringCodec.INSTANCE);
if (!thisOrderSet.add(orderId)) {
return JoyResponseVo.fail(400, "ORDER_ID_REPEAT");
}
thisOrderSet.expire(1, TimeUnit.HOURS);
Long uid = joyUserInfoModel.getUserId();
double goldNum = joySubmitBodyVo.getCoins().doubleValue();
JoyGameRecord joyGameRecord = new JoyGameRecord();
joyGameRecord.setGameId(joyUserInfoModel.getGameId());
if (StringUtils.isNotEmpty(joySubmitBodyVo.getRoomId())) {
joyGameRecord.setRoomUid(Long.valueOf(joySubmitBodyVo.getRoomId()));
}
joyGameRecord.setOrderId(orderId);
joyGameRecord.setExt(joySubmitBodyVo.getExt());
joyGameRecord.setUid(uid);
joyGameRecord.setCoin(joySubmitBodyVo.getCoins());
joyGameRecord.setType(joySubmitBodyVo.getType());
joyGameRecord.setRemark(joySubmitBodyVo.getRemark());
joyGameRecord.setCreateTime(new Date(joySubmitBodyVo.getTm()));
joyGameRecordService.save(joyGameRecord);
UserPurse afterPurse = null;
GameMsgMessage gameMsgMessage = new GameMsgMessage();
if (joySubmitBodyVo.getType() == Constant.GameGoldType.ADD) {
// 扣减用户钻石
afterPurse = userPurseService.addDiamond(uid, goldNum, BillObjTypeEnum.LEADERCC_GAME_IN,
(up) -> billRecordService.insertGeneralBillRecord(uid, orderId, BillObjTypeEnum.LEADERCC_GAME_IN, goldNum, up));
gameMsgMessage.setPushScreen(Boolean.TRUE);
}
if (joySubmitBodyVo.getType() == Constant.GameGoldType.REDUCT) {
// 扣减用户钻石
afterPurse = userPurseService.subDiamond(uid, goldNum, BillObjTypeEnum.LEADERCC_GAME_OUT,
(up)-> billRecordService.insertGeneralBillRecord(uid, orderId, BillObjTypeEnum.LEADERCC_GAME_OUT, goldNum, up));
}
gameMsgMessage.setRoomUid(joyGameRecord.getRoomUid());
gameMsgMessage.setCoin(goldNum);
gameMsgMessage.setGameId(joyUserInfoModel.getGameId().toString());
gameMsgMessage.setType(joyGameRecord.getType());
gameMsgMessage.setUid(uid);
gameMsgMessage.setResourceCodeEnum(ResourceCodeEnum.JOYPLAY);
gameMsgMessage.setConfigId(Constant.SysConfId.MINI_GAME_FOR_JOY);
gameMsgMessage.setCreateTime(joyGameRecord.getCreateTime());
rocketMQService.sendGameMsgPushMessage(gameMsgMessage);
JoySubmitResult result = JoySubmitResult.builder().availableCoin(afterPurse.getDiamonds().longValue()).build();
return JoyResponseVo.success(result);
} catch (ServiceException e) {
log.info("JoyGameService.submitFlow,token:{},data:{},e:{}", token, data, e.getMessage(), e);
return JoyResponseVo.fail(e.getBusiStatus().getCode(), e.getBusiStatus().getName());
} catch (Exception e) {
log.info("JoyGameService.submitFlow,token:{},data:{},e:{}", token, data, e.getMessage(), e);
return JoyResponseVo.fail(BusiStatus.SERVERERROR.getCode(), BusiStatus.SERVERERROR.getName());
}
}
private JoyUserInfoModel checkAndGetInfo(String token) throws Exception {
String decodeToken = URLDecoder.decode(token, "UTF-8");
String desAndBase64Decrypt = DESUtils.DESAndBase64Decrypt(decodeToken, KeyStore.DES_ENCRYPT_KEY);
JoyUserInfoModel joyUserInfoModel = JSONObject.parseObject(desAndBase64Decrypt, JoyUserInfoModel.class);
if (joyUserInfoModel == null || joyUserInfoModel.getCode() == null || joyUserInfoModel.getUserId() == null) {
log.info("JoyGameService.checkAndGetInfo,empty joyUserInfoModel");
throw new ServiceException(BusiStatus.NOAUTHORITY);
}
String tokenCache = getToketBuket(joyUserInfoModel.getUserId()).get();
if (StringUtils.isEmpty(tokenCache) || !tokenCache.equals(joyUserInfoModel.getCode())) {
log.info("JoyGameService.checkAndGetInfo,token error");
throw new ServiceException(BusiStatus.NOAUTHORITY);
}
return joyUserInfoModel;
}
private String decryptByPrivateKey(String data, String privateKey){
try {
return RSAUtils.decryptByPrivateKeyInString(data, privateKey);
} catch (Exception e) {
log.info("JoyPlayGameService.decryptByPrivateKey,data:{},privateKey:{}", data, privateKey);
}
return null;
}
public String genCode(Integer gameId, String os, Long uid) throws Exception {
long seconds = 7 * 24 * 60 * 60;
RBucket<String> toketBuket = getToketBuket(uid);
String code;
if (toketBuket.isExists()) {
toketBuket.expire(seconds, TimeUnit.SECONDS);
code = toketBuket.get();
} else {
code = UUID.randomUUID().toString();
toketBuket.set(code, seconds, TimeUnit.SECONDS);
}
String pgkName;
if (Constant.OsType.IOS.equalsIgnoreCase(os)) {
pgkName = joyGameConfig.getIosPgkName();
} else {
pgkName = joyGameConfig.getAndroidPgkName();
}
JoyUserInfoModel userInfoModel = JoyUserInfoModel.builder().userId(uid).gameId(gameId).pkgName(pgkName).code(code).build();
return URLEncoder.encode(DESUtils.DESAndBase64Encrypt(JSONObject.toJSONString(userInfoModel), KeyStore.DES_ENCRYPT_KEY), "UTF-8");
}
public RBucket<String> getToketBuket(Long uid) {
return redissonClient.getBucket(joy_token.getKey(String.valueOf(uid)), StringCodec.INSTANCE);
}
public static void main(String[] args) throws Exception {
String token = "EEkNV6lv8H921A95VgUQwllW5WC//0raNKyqwixOdA9A78Bi8E3FrHgQeoPJ aOGspVoVWBjKzpT1lPe50/mTsNajB1mzdHRl+KQR7v43nldI9iFm7cAGJ2me LgwlEnfnnTP6QFBlEv4%3D";
token =token.replace("+","%2B");
token = URLDecoder.decode(token, "UTF-8");
token = token.replace(" ","");
String userInfoStr = DESUtils.DESAndBase64Decrypt(token, KeyStore.DES_ENCRYPT_KEY);
System.out.println(userInfoStr);
// String data = "882b63d2e6e8282c44fb7f235ae1ce6e932188032eae78d726a19bf3992a3fa175db91469572fb5e97b350ed7534ff4da059326eb05b3cbf3d6cd11ab1fcebfad7497e61d4a1521440d3c5a20f4eac2262fd8353406306dfae1569503c700febac1d51ff158e9b800242973ad8aaec8fcbc4cf59b2296632fdf0a4c59589fc925f854e7aeb66358375b33125a5f125c5de401e3c0af554fdd15f84b58238e476a9668070b109dc46fda8812048accfce0ce5b686ea6c07df24c149682f06c453de9bb139b620a16e8f52c15684b6c3b4f68d5643768dc0aca8a9c80073aaab63b7480050ffd251b1e23e2b0995983a6f67090ad6467320393e34ca8364effca6";
// String json = decryptByPrivateKey(data);
// System.out.println(json);
// GameFlowSubmitResultData resultData = JSON.parseObject(json, GameFlowSubmitResultData.class);
// System.out.println(JSON.toJSONString(resultData));
// //扩展信息
// String newExt = resultData.getExt().replace("\\", "");
// UserInfoModelExt ext = JSONObject.parseObject(newExt, UserInfoModelExt.class);
// System.out.println(JSON.toJSONString(ext));
}
}

View File

@@ -0,0 +1,19 @@
package com.accompany.business.service.game.impl;
import com.accompany.business.service.game.JoyGameRecordService;
import com.accompany.sharding.mapper.JoyGameRecordMapper;
import com.accompany.sharding.model.JoyGameRecord;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
/**
* joy play游戏记录 服务实现类
*
* @author
* @since 2025-05-06
*/
@Service
public class JoyGameRecordServiceImpl extends ServiceImpl<JoyGameRecordMapper, JoyGameRecord> implements JoyGameRecordService {
}

View File

@@ -0,0 +1,35 @@
package com.accompany.business.controller.game;
import com.accompany.business.service.game.JoyGameService;
import com.accompany.common.result.BusiResult;
import com.accompany.sharding.vo.JoyResponseVo;
import com.accompany.sharding.vo.JoySubmitResult;
import com.accompany.sharding.vo.JoyUserInfoModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@Slf4j
@RestController
@RequestMapping("/game")
public class JoyGameController {
@Autowired
private JoyGameService joyGameService;
/**
* joyp获取用户信息
*/
@GetMapping("/getUserInfo")
public JoyResponseVo<JoyUserInfoModel> getUserInfo(@RequestHeader("authorization") String token) {
return joyGameService.getUserInfo(token);
}
/**
* joyp扣加金币
*/
@PostMapping("/submitFlow")
public JoyResponseVo<JoySubmitResult> submitFlow(@RequestHeader("authorization") String token, @RequestBody String data) {
return joyGameService.submitFlow(token,data);
}
}

View File

@@ -9,10 +9,12 @@ import com.accompany.business.enums.resource.RuleCodeEnum;
import com.accompany.business.model.resource.Resource;
import com.accompany.business.service.charge.FirstChargeRewardService;
import com.accompany.business.service.game.GameService;
import com.accompany.business.service.game.JoyGameService;
import com.accompany.business.service.game.MiniGameForBaiShunService;
import com.accompany.business.service.give.GiveUserService;
import com.accompany.business.service.resource.ResourceService;
import com.accompany.common.annotation.Authorization;
import com.accompany.common.device.DeviceInfo;
import com.accompany.common.result.BusiResult;
import com.accompany.common.status.BusiStatus;
import com.accompany.core.base.UidContextHolder;
@@ -21,6 +23,7 @@ import com.accompany.payment.service.RechargeUserService;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@@ -34,6 +37,7 @@ import static com.accompany.common.constant.ApplicationConstant.PublicParameters
* @date: 2023/11/16 14:41
* @description:
*/
@Slf4j
@Api("资源位")
@RestController
@RequestMapping("/resource")
@@ -54,6 +58,8 @@ public class ResourceController {
private GiveUserService giveUserService;
@Autowired
private RechargeUserService rechargeUserService;
@Autowired
private JoyGameService joyGameService;
/**
* 房间内轮播icon列表
@@ -82,59 +88,72 @@ public class ResourceController {
@ApiOperation("房间内角标入口列表")
@GetMapping("gamePlay")
@Authorization
public BusiResult<List<Resource>> gamePlay(@RequestParam(value = "roomUid", required = false) Long roomUid, @RequestHeader(value = PUB_UID) Long pubUid) {
public BusiResult<List<Resource>> gamePlay(DeviceInfo deviceInfo,
@RequestParam(value = "roomUid", required = false) Long roomUid,
@RequestHeader(value = PUB_UID) Long pubUid) {
List<Resource> resources = resourceService.resources(ResourceTypeEnum.GAMEPLAY.ordinal());
if (CollectionUtil.isNotEmpty(resources)) {
resources = resources.stream().peek(v -> {
if (ResourceCodeEnum.BAISHUN.name().equals(v.getCode())) {
String ruleValue = v.getRuleValue();
if (StrUtil.isNotEmpty(ruleValue) && ruleValue.startsWith(StrUtil.DELIM_START) && ruleValue.endsWith(StrUtil.DELIM_END)) {
JSONObject jsonObject = JSONObject.parseObject(ruleValue);
if (jsonObject.containsKey(RuleCodeEnum.RESERVE.name())) {
String configStr = jsonObject.getString(RuleCodeEnum.RESERVE.name());
if (StrUtil.isEmpty(configStr)) {
return;
}
BaiShunGetConfigDto config = JSONObject.parseObject(configStr, BaiShunGetConfigDto.class);
Long uid = UidContextHolder.get();
String code = StrUtil.EMPTY;
if (uid != null) {
code = miniGameForBaiShunService.genCode(String.valueOf(config.getAppId()), uid);
}
config.setCode(code);
jsonObject.put(RuleCodeEnum.RESERVE.name(), JSONObject.toJSONString(config));
v.setRuleValue(jsonObject.toJSONString());
}
}
}
if (ResourceCodeEnum.LEADERCC.name().equals(v.getCode())) {
String ruleValue = v.getRuleValue();
if (StrUtil.isNotEmpty(ruleValue) && ruleValue.startsWith(StrUtil.DELIM_START) && ruleValue.endsWith(StrUtil.DELIM_END)) {
JSONObject jsonObject = JSONObject.parseObject(ruleValue);
if (jsonObject.containsKey(RuleCodeEnum.RESERVE.name())) {
String configStr = jsonObject.getString(RuleCodeEnum.RESERVE.name());
if (StrUtil.isEmpty(configStr)) {
return;
}
BaiShunGetConfigDto config = JSONObject.parseObject(configStr, BaiShunGetConfigDto.class);
Long uid = UidContextHolder.get();
String code = StrUtil.EMPTY;
if (uid != null) {
code = gameService.genCode(String.valueOf(config.getAppId()), uid);
}
config.setCode(code);
jsonObject.put(RuleCodeEnum.RESERVE.name(), JSONObject.toJSONString(config));
v.setRuleValue(jsonObject.toJSONString());
}
}
}
}).collect(Collectors.toList());
List<Long> giveUidList = giveUserService.getGiveUidList();
boolean isRechargeUser = rechargeUserService.isRechargeUser(pubUid) || giveUidList.contains(pubUid);
resources = resources.stream()
.filter(x -> !(isRechargeUser && ResourceCodeEnum.LUCKY_BAG.name().equals(x.getCode())))
.collect(Collectors.toList());
if (CollectionUtil.isEmpty(resources)) {
return BusiResult.success(resources);
}
resources = resources.stream().peek(v -> {
covertGameVo(v, deviceInfo.getOs());
}).collect(Collectors.toList());
List<Long> giveUidList = giveUserService.getGiveUidList();
boolean isRechargeUser = rechargeUserService.isRechargeUser(pubUid) || giveUidList.contains(pubUid);
resources = resources.stream()
.filter(x -> !(isRechargeUser && ResourceCodeEnum.LUCKY_BAG.name().equals(x.getCode())))
.collect(Collectors.toList());
return BusiResult.success(resources);
}
private void covertGameVo(Resource v, String os) {
try {
String ruleValue = v.getRuleValue();
if(StrUtil.isEmpty(ruleValue)
|| !ruleValue.startsWith(StrUtil.DELIM_START)
|| !ruleValue.endsWith(StrUtil.DELIM_END)){
return;
}
Long uid = UidContextHolder.get();
JSONObject jsonObject = JSONObject.parseObject(ruleValue);
if (!jsonObject.containsKey(RuleCodeEnum.RESERVE.name())) {
return;
}
String configStr = jsonObject.getString(RuleCodeEnum.RESERVE.name());
if (StrUtil.isEmpty(configStr)) {
return;
}
BaiShunGetConfigDto config = JSONObject.parseObject(configStr, BaiShunGetConfigDto.class);
if (ResourceCodeEnum.BAISHUN.name().equals(v.getCode())) {
String code = StrUtil.EMPTY;
if (uid != null) {
code = miniGameForBaiShunService.genCode(String.valueOf(config.getAppId()), uid);
}
config.setCode(code);
jsonObject.put(RuleCodeEnum.RESERVE.name(), JSONObject.toJSONString(config));
v.setRuleValue(jsonObject.toJSONString());
} else if (ResourceCodeEnum.LEADERCC.name().equals(v.getCode())) {
String code = StrUtil.EMPTY;
if (uid != null) {
code = gameService.genCode(String.valueOf(config.getAppId()), uid);
}
config.setCode(code);
jsonObject.put(RuleCodeEnum.RESERVE.name(), JSONObject.toJSONString(config));
v.setRuleValue(jsonObject.toJSONString());
} else if (ResourceCodeEnum.JOYPLAY.name().equals(v.getCode())) {
String code = StrUtil.EMPTY;
if (uid != null) {
code = joyGameService.genCode(config.getGameId(), os, uid);
}
config.setCode(code);
config.setGameId(config.getGameId());
config.setAppKey(config.getAppKey());
jsonObject.put(RuleCodeEnum.RESERVE.name(), JSONObject.toJSONString(config));
v.setRuleValue(jsonObject.toJSONString());
}
} catch (Exception e) {
log.error("ResourceController.covertGameVo,Resource:{},e:{}", JSONObject.toJSONString(v), e.getMessage(), e);
}
}
}