|
@@ -33,6 +33,7 @@ import reactor.util.function.Tuple3;
|
|
|
import reactor.util.function.Tuples;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.util.Base64;
|
|
|
import java.util.Collections;
|
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
@@ -135,6 +136,8 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
|
|
|
//下单
|
|
|
kafkaService.eventTrack(KafkaEventTrackEnum.KAFKA_EVENT_TRACK_ORDER_PAY, JsonUtil.toString(order));
|
|
|
}
|
|
|
+ //日志更新
|
|
|
+ cpPushErrorLogService.errorLogUpdate(game.getId(), CpPushDataEnum.CP_PUSH_DATA_ORDER, param);
|
|
|
//构造返回
|
|
|
return CpPushResultVO.builder().result(Boolean.TRUE).build();
|
|
|
}
|
|
@@ -151,14 +154,12 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
|
|
|
.eq(User::getOpenId, param.getOpenId())
|
|
|
.eq(User::getGameId, game.getId()));
|
|
|
if (user == null) {
|
|
|
- log.error("[订单推送]游戏玩家信息不存在, game : {}, param : {}", JsonUtil.toString(game), JsonUtil.toString(param));
|
|
|
throw new BaseException("[订单推送]玩家信息不存在");
|
|
|
}
|
|
|
//玩家信息
|
|
|
GameUser gameUser = gameUserService.getOne(new LambdaQueryWrapper<GameUser>()
|
|
|
.eq(GameUser::getUserId, user.getId()));
|
|
|
if (gameUser == null) {
|
|
|
- log.error("[订单推送]游戏玩家信息不存在, game : {}, param : {}", JsonUtil.toString(game), JsonUtil.toString(param));
|
|
|
throw new BaseException("[订单推送]游戏玩家信息不存在");
|
|
|
}
|
|
|
//角色信息
|
|
@@ -167,7 +168,6 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
|
|
|
.eq(GameUserRole::getUserId, user.getId())
|
|
|
.eq(GameUserRole::getRoleId, param.getRoleId()));
|
|
|
if (gameUserRole == null) {
|
|
|
- log.error("[订单推送]角色信息不存在, game : {}, param : {}", JsonUtil.toString(game), JsonUtil.toString(param));
|
|
|
throw new BaseException("[订单推送]角色信息不存在");
|
|
|
}
|
|
|
//构造订单
|
|
@@ -246,6 +246,8 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
|
|
|
//抛出异常
|
|
|
throw new BaseException(e.getMessage());
|
|
|
}
|
|
|
+ //日志更新
|
|
|
+ cpPushErrorLogService.errorLogUpdate(game.getId(), CpPushDataEnum.CP_PUSH_DATA_ACTIVE, param);
|
|
|
//构造返回
|
|
|
return CpPushResultVO.builder().result(Boolean.TRUE).build();
|
|
|
}
|
|
@@ -254,6 +256,7 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
|
|
|
public CpPushResultVO pushServer(String gameAppId, CpPushServerParam param) {
|
|
|
//查询游戏
|
|
|
Game game = this.getGameByGameAppId(gameAppId);
|
|
|
+ boolean result;
|
|
|
// 手动开启事务
|
|
|
TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
|
|
|
try {
|
|
@@ -274,19 +277,21 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
|
|
|
gameServer.setUpdateTime(LocalDateTime.now());
|
|
|
}
|
|
|
//区服添加或者更新
|
|
|
- boolean result = gameServerService.saveOrUpdate(gameServer);
|
|
|
- // 提交事务
|
|
|
+ result = gameServerService.saveOrUpdate(gameServer);
|
|
|
+ //提交事务
|
|
|
dataSourceTransactionManager.commit(transactionStatus);
|
|
|
- //构造返回
|
|
|
- return CpPushResultVO.builder().result(result).build();
|
|
|
} catch (Exception e) {
|
|
|
- // 回滚事务
|
|
|
+ //回滚事务
|
|
|
dataSourceTransactionManager.rollback(transactionStatus);
|
|
|
//保存错误日志
|
|
|
cpPushErrorLogService.createLog(game.getId(), CpPushDataEnum.CP_PUSH_DATA_SERVER, param, e.getMessage());
|
|
|
//抛出异常
|
|
|
throw new BaseException(e.getMessage());
|
|
|
}
|
|
|
+ //日志更新
|
|
|
+ cpPushErrorLogService.errorLogUpdate(game.getId(), CpPushDataEnum.CP_PUSH_DATA_SERVER, param);
|
|
|
+ //构造返回
|
|
|
+ return CpPushResultVO.builder().result(result).build();
|
|
|
}
|
|
|
|
|
|
private GameServer transform(Long superGameId, CpPushServerParam param) {
|
|
@@ -310,6 +315,7 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
|
|
|
public CpPushResultVO pushRole(String gameAppId, CpPushRoleParam param) {
|
|
|
//查询游戏
|
|
|
Game game = this.getGameByGameAppId(gameAppId);
|
|
|
+ boolean result;
|
|
|
// 手动开启事务
|
|
|
TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
|
|
|
try {
|
|
@@ -318,7 +324,6 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
|
|
|
.eq(User::getGameId, game.getId())
|
|
|
.eq(User::getOpenId, param.getOpenId()));
|
|
|
if (user == null) {
|
|
|
- log.error("[角色推送]玩家信息不存在, game : {}, param : {}", JsonUtil.toString(game), JsonUtil.toString(param));
|
|
|
throw new BaseException("[角色推送]玩家信息不存在");
|
|
|
}
|
|
|
//查询玩家角色信息
|
|
@@ -326,7 +331,6 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
|
|
|
.eq(GameUserRole::getUserId, user.getId())
|
|
|
.eq(GameUserRole::getGameId, user.getGameId())
|
|
|
.eq(GameUserRole::getRoleId, param.getRoleId()));
|
|
|
- boolean result;
|
|
|
if (gameUserRole == null) {
|
|
|
result = this.gameRoleCreate(param, user);
|
|
|
} else {
|
|
@@ -334,8 +338,6 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
|
|
|
}
|
|
|
// 提交事务
|
|
|
dataSourceTransactionManager.commit(transactionStatus);
|
|
|
- //构造返回
|
|
|
- return CpPushResultVO.builder().result(result).build();
|
|
|
} catch (Exception e) {
|
|
|
// 回滚事务
|
|
|
dataSourceTransactionManager.rollback(transactionStatus);
|
|
@@ -344,6 +346,10 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
|
|
|
//抛出异常
|
|
|
throw new BaseException(e.getMessage());
|
|
|
}
|
|
|
+ //日志更新
|
|
|
+ cpPushErrorLogService.errorLogUpdate(game.getId(), CpPushDataEnum.CP_PUSH_DATA_ROLE, param);
|
|
|
+ //构造返回
|
|
|
+ return CpPushResultVO.builder().result(result).build();
|
|
|
}
|
|
|
|
|
|
private boolean gameRoleCreate(CpPushRoleParam param, User user) {
|
|
@@ -352,7 +358,6 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
|
|
|
.eq(GameUser::getGameId, user.getGameId())
|
|
|
.eq(GameUser::getUserId, user.getId()));
|
|
|
if (gameUser == null) {
|
|
|
- log.error("[角色推送]游戏玩家信息不存在, param : {}, user : {}", JsonUtil.toString(param), JsonUtil.toString(user));
|
|
|
throw new BaseException("[角色推送]游戏玩家信息不存在");
|
|
|
}
|
|
|
//上锁
|
|
@@ -436,26 +441,23 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
|
|
|
public CpPushUserVO pushUser(String gameAppId, CpPushUserParam param) {
|
|
|
//查询游戏
|
|
|
Game game = this.getGameByGameAppId(gameAppId);
|
|
|
+ //结果信息
|
|
|
+ CpPushUserVO cpPushUserVO;
|
|
|
// 手动开启事务
|
|
|
TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
|
|
|
try {
|
|
|
- //渠道参数判断
|
|
|
- String channel = param.getChannel();
|
|
|
- Tuple2<Boolean, Boolean> jsonAndEmpty = this.isJsonAndEmpty(channel);
|
|
|
//中间数据
|
|
|
UserData userData = UserData.builder().gameId(game.getId()).channel(param.getChannel()).ip(param.getIp()).ua(param.getUa()).build();
|
|
|
//根据openId查询用户
|
|
|
User user = userService.getOne(new LambdaQueryWrapper<User>()
|
|
|
.eq(User::getGameId, game.getId())
|
|
|
.eq(User::getOpenId, param.getOpenId()));
|
|
|
- //结果信息
|
|
|
- CpPushUserVO cpPushUserVO;
|
|
|
//玩家信息不存在
|
|
|
if (user == null) {
|
|
|
- cpPushUserVO = this.createUser(game, userData, param, jsonAndEmpty);
|
|
|
+ cpPushUserVO = this.createUser(game, userData, param);
|
|
|
} else {
|
|
|
//玩家信息更新
|
|
|
- Map<String, String> channelMap = this.updateUser(user, param, game, userData, jsonAndEmpty);
|
|
|
+ Map<String, String> channelMap = this.updateUser(user, param, game, userData);
|
|
|
cpPushUserVO = CpPushUserVO.builder().userId(user.getId())
|
|
|
.sdkUser(!Objects.equals(user.getAgentId(), Agent.DEFAULT_AGENT))
|
|
|
.channel(JsonUtil.toString(channelMap))
|
|
@@ -463,8 +465,6 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
|
|
|
}
|
|
|
// 提交事务
|
|
|
dataSourceTransactionManager.commit(transactionStatus);
|
|
|
- //返回结果
|
|
|
- return cpPushUserVO;
|
|
|
} catch (Exception e) {
|
|
|
// 回滚事务
|
|
|
dataSourceTransactionManager.rollback(transactionStatus);
|
|
@@ -473,9 +473,13 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
|
|
|
//抛出异常
|
|
|
throw new BaseException(e.getMessage());
|
|
|
}
|
|
|
+ //日志更新
|
|
|
+ cpPushErrorLogService.errorLogUpdate(game.getId(), CpPushDataEnum.CP_PUSH_DATA_USER, param);
|
|
|
+ //返回结果
|
|
|
+ return cpPushUserVO;
|
|
|
}
|
|
|
|
|
|
- private CpPushUserVO createUser(Game game, UserData userData, CpPushUserParam param, Tuple2<Boolean, Boolean> jsonAndEmpty) {
|
|
|
+ private CpPushUserVO createUser(Game game, UserData userData, CpPushUserParam param) {
|
|
|
//游戏id
|
|
|
Long gameId = game.getId();
|
|
|
//线程锁Key
|
|
@@ -496,10 +500,10 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
|
|
|
.eq(User::getGameId, gameId)
|
|
|
.eq(User::getOpenId, param.getShareOpenId())
|
|
|
.last("limit 1"));
|
|
|
- user = this.transform(gameId, shareUser.getAgentId(), shareUser, param);
|
|
|
+ user = this.transform(gameId, shareUser, param);
|
|
|
} else {
|
|
|
- Tuple2<Long, Map<String, String>> tuple2 = this.getUserAgentChannel(game, userData, jsonAndEmpty);
|
|
|
- user = this.transform(gameId, tuple2.getT1(), null, param);
|
|
|
+ Tuple2<Long, Map<String, String>> tuple2 = this.getUserAgentChannel(game, userData);
|
|
|
+ user = this.transform(gameId, tuple2, param);
|
|
|
channelMap = tuple2.getT2();
|
|
|
}
|
|
|
userService.save(user);
|
|
@@ -530,19 +534,15 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private Map<String, String> updateUser(User user, CpPushUserParam param, Game game, UserData userData, Tuple2<Boolean, Boolean> jsonAndEmpty) {
|
|
|
+ private Map<String, String> updateUser(User user, CpPushUserParam param, Game game, UserData userData) {
|
|
|
//活跃间隔时长
|
|
|
long inactiveDay = 15L;
|
|
|
//判定不活跃时长是否达到限制
|
|
|
if (param.getActiveTime().plusDays(inactiveDay).isAfter(LocalDateTime.now())) {
|
|
|
return Collections.emptyMap();
|
|
|
}
|
|
|
- //如果没有携带参数, 不判定重新买量
|
|
|
- if (!param.getChannel().contains("clue_token")) {
|
|
|
- return Collections.emptyMap();
|
|
|
- }
|
|
|
//渠道id, 链接参数
|
|
|
- Tuple2<Long, Map<String, String>> tuple2 = this.getUserAgentChannel(game, userData, jsonAndEmpty);
|
|
|
+ Tuple2<Long, Map<String, String>> tuple2 = this.getUserAgentChannel(game, userData);
|
|
|
//查询渠道
|
|
|
Agent agent = agentService.getById(tuple2.getT1());
|
|
|
if (agent == null) {
|
|
@@ -563,7 +563,14 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
|
|
|
return tuple2.getT2();
|
|
|
}
|
|
|
|
|
|
- private Tuple2<Long, Map<String, String>> getUserAgentChannel(Game game, UserData userData, Tuple2<Boolean, Boolean> jsonAndEmpty) {
|
|
|
+ private Tuple2<Long, Map<String, String>> getUserAgentChannel(Game game, UserData userData) {
|
|
|
+ //解析渠道信息
|
|
|
+ String channel = new String(Base64.getDecoder().decode(userData.getChannel()));
|
|
|
+ //没有携带渠道标识, 无法解析渠道信息, 判定为自然量
|
|
|
+ if (!channel.contains("agentKey") || !channel.contains("state")) {
|
|
|
+ return Tuples.of(0L, Collections.emptyMap());
|
|
|
+ }
|
|
|
+ Tuple2<Boolean, Boolean> jsonAndEmpty = this.isJsonAndEmpty(channel);
|
|
|
//channel渠道信息非json格式, 或者是空json
|
|
|
if (!jsonAndEmpty.getT1() || jsonAndEmpty.getT2()) {
|
|
|
//返回自然量渠道
|
|
@@ -575,12 +582,32 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
|
|
|
return Tuples.of(tuple3.getT1(), tuple3.getT2());
|
|
|
}
|
|
|
|
|
|
- private User transform(Long gameId, Long agentId, User shareUser, CpPushUserParam param) {
|
|
|
+ private User transform(Long gameId, User shareUser, CpPushUserParam param) {
|
|
|
+ return User.builder()
|
|
|
+ .openId(param.getOpenId())
|
|
|
+ .regAgentId(shareUser.getRegAgentId())
|
|
|
+ .agentId(shareUser.getAgentId())
|
|
|
+ .channel(shareUser.getChannel())
|
|
|
+ .gameId(gameId)
|
|
|
+ .username(param.getOpenId())
|
|
|
+ .nickname(RegisterUtil.randomNickName(param.getOpenId()))
|
|
|
+ .deviceType(DeviceTypeEnum.DEVICE_TYPE_MINI_APP.getDeviceType())
|
|
|
+ .status(BanStatusEnum.NORMAL_STATUS.getStatus())
|
|
|
+ .authentication(0)
|
|
|
+ .createTime(param.getRegTime())
|
|
|
+ .updateTime(LocalDateTime.now())
|
|
|
+ .deviceSystem(param.getOs())
|
|
|
+ .ip(param.getIp())
|
|
|
+ .shareUserId(shareUser.getId())
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+
|
|
|
+ private User transform(Long gameId, Tuple2<Long, Map<String, String>> tuple2, CpPushUserParam param) {
|
|
|
return User.builder()
|
|
|
.openId(param.getOpenId())
|
|
|
- .regAgentId(agentId)
|
|
|
- .agentId(agentId)
|
|
|
- .channel(param.getChannel())
|
|
|
+ .regAgentId(tuple2.getT1())
|
|
|
+ .agentId(tuple2.getT1())
|
|
|
+ .channel(JsonUtil.toString(tuple2))
|
|
|
.gameId(gameId)
|
|
|
.username(param.getOpenId())
|
|
|
.nickname(RegisterUtil.randomNickName(param.getOpenId()))
|
|
@@ -591,7 +618,6 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
|
|
|
.updateTime(LocalDateTime.now())
|
|
|
.deviceSystem(param.getOs())
|
|
|
.ip(param.getIp())
|
|
|
- .shareUserId(shareUser == null ? null : shareUser.getId())
|
|
|
.build();
|
|
|
}
|
|
|
|