|  | @@ -6,6 +6,7 @@ import com.zanxiang.game.module.base.pojo.enums.BanStatusEnum;
 | 
	
		
			
				|  |  |  import com.zanxiang.game.module.base.pojo.enums.DeleteEnum;
 | 
	
		
			
				|  |  |  import com.zanxiang.game.module.mybatis.entity.*;
 | 
	
		
			
				|  |  |  import com.zanxiang.game.module.sdk.constant.RedisKeyConstant;
 | 
	
		
			
				|  |  | +import com.zanxiang.game.module.sdk.enums.CpPushDataEnum;
 | 
	
		
			
				|  |  |  import com.zanxiang.game.module.sdk.enums.DeviceTypeEnum;
 | 
	
		
			
				|  |  |  import com.zanxiang.game.module.sdk.enums.KafkaEventTrackEnum;
 | 
	
		
			
				|  |  |  import com.zanxiang.game.module.sdk.pojo.dto.PlatformOrderDTO;
 | 
	
	
		
			
				|  | @@ -23,8 +24,10 @@ import org.apache.logging.log4j.util.Strings;
 | 
	
		
			
				|  |  |  import org.json.JSONObject;
 | 
	
		
			
				|  |  |  import org.redisson.api.RLock;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | +import org.springframework.jdbc.datasource.DataSourceTransactionManager;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | -import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  | +import org.springframework.transaction.TransactionDefinition;
 | 
	
		
			
				|  |  | +import org.springframework.transaction.TransactionStatus;
 | 
	
		
			
				|  |  |  import reactor.util.function.Tuple2;
 | 
	
		
			
				|  |  |  import reactor.util.function.Tuple3;
 | 
	
		
			
				|  |  |  import reactor.util.function.Tuples;
 | 
	
	
		
			
				|  | @@ -80,11 +83,19 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private IOrderService orderService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private TransactionDefinition transactionDefinition;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private ICpPushErrorLogService cpPushErrorLogService;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private DataSourceTransactionManager dataSourceTransactionManager;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private IDistributedLockComponent distributedLockComponent;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  | -    @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |      public CpPushResultVO pushOrder(String gameAppId, CpPushOrderParam param) {
 | 
	
		
			
				|  |  |          //查询游戏
 | 
	
		
			
				|  |  |          Game game = this.getGameByGameAppId(gameAppId);
 | 
	
	
		
			
				|  | @@ -92,15 +103,28 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
 | 
	
		
			
				|  |  |          Order order = orderService.getOne(new LambdaQueryWrapper<Order>()
 | 
	
		
			
				|  |  |                  .eq(Order::getGameId, game.getId())
 | 
	
		
			
				|  |  |                  .eq(Order::getCpOrderId, param.getOrderId()));
 | 
	
		
			
				|  |  | -        if (order == null) {
 | 
	
		
			
				|  |  | -            order = this.createOrder(game, param);
 | 
	
		
			
				|  |  | -        } else {
 | 
	
		
			
				|  |  | -            order.setStatus(param.getStatus());
 | 
	
		
			
				|  |  | -            order.setPayTime(param.getPayTime());
 | 
	
		
			
				|  |  | -            order.setUpdateTime(LocalDateTime.now());
 | 
	
		
			
				|  |  | +        // 手动开启事务
 | 
	
		
			
				|  |  | +        TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            if (order == null) {
 | 
	
		
			
				|  |  | +                order = this.createOrder(game, param);
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                order.setStatus(param.getStatus());
 | 
	
		
			
				|  |  | +                order.setPayTime(param.getPayTime());
 | 
	
		
			
				|  |  | +                order.setUpdateTime(LocalDateTime.now());
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //订单更新或者保存
 | 
	
		
			
				|  |  | +            orderService.saveOrUpdate(order);
 | 
	
		
			
				|  |  | +            // 提交事务
 | 
	
		
			
				|  |  | +            dataSourceTransactionManager.commit(transactionStatus);
 | 
	
		
			
				|  |  | +        } catch (Exception e) {
 | 
	
		
			
				|  |  | +            // 回滚事务
 | 
	
		
			
				|  |  | +            dataSourceTransactionManager.rollback(transactionStatus);
 | 
	
		
			
				|  |  | +            //保存错误日志
 | 
	
		
			
				|  |  | +            cpPushErrorLogService.createLog(game.getId(), CpPushDataEnum.CP_PUSH_DATA_ORDER, param, e.getMessage());
 | 
	
		
			
				|  |  | +            //抛出异常
 | 
	
		
			
				|  |  | +            throw new BaseException(e.getMessage());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        //订单更新或者保存
 | 
	
		
			
				|  |  | -        orderService.saveOrUpdate(order);
 | 
	
		
			
				|  |  |          //订单回传
 | 
	
		
			
				|  |  |          callBackService.orderCallBack(BeanUtil.copy(order, PlatformOrderDTO.class));
 | 
	
		
			
				|  |  |          //判断订单行为
 | 
	
	
		
			
				|  | @@ -118,7 +142,7 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
 | 
	
		
			
				|  |  |      private Order createOrder(Game game, CpPushOrderParam param) {
 | 
	
		
			
				|  |  |          String lockKey = RedisKeyConstant.ORDER_CREATE_LOCK + param.getOpenId() + "_" + param.getOrderId();
 | 
	
		
			
				|  |  |          if (!distributedLockComponent.doLock(lockKey, 0L, 1L, TimeUnit.MINUTES)) {
 | 
	
		
			
				|  |  | -            log.error("订单正在创建中, param : {}", JsonUtil.toString(param));
 | 
	
		
			
				|  |  | +            log.error("[订单推送]正在创建中, param : {}", JsonUtil.toString(param));
 | 
	
		
			
				|  |  |              throw new BaseException("接口调用订单正在创建中");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          try {
 | 
	
	
		
			
				|  | @@ -127,25 +151,30 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
 | 
	
		
			
				|  |  |                      .eq(User::getOpenId, param.getOpenId())
 | 
	
		
			
				|  |  |                      .eq(User::getGameId, game.getId()));
 | 
	
		
			
				|  |  |              if (user == null) {
 | 
	
		
			
				|  |  | -                throw new BaseException("参数错误, 玩家信息不存在");
 | 
	
		
			
				|  |  | +                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("[订单推送]游戏玩家信息不存在");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |              //角色信息
 | 
	
		
			
				|  |  |              GameUserRole gameUserRole = gameUserRoleService.getOne(new LambdaQueryWrapper<GameUserRole>()
 | 
	
		
			
				|  |  |                      .eq(GameUserRole::getGameId, game.getId())
 | 
	
		
			
				|  |  |                      .eq(GameUserRole::getUserId, user.getId())
 | 
	
		
			
				|  |  |                      .eq(GameUserRole::getRoleId, param.getRoleId()));
 | 
	
		
			
				|  |  | -            if (gameUser == null || gameUserRole == null) {
 | 
	
		
			
				|  |  | -                log.error("游戏用户信息不全, gameUser : {}, gameUserRole : {}", JsonUtil.toString(gameUser), JsonUtil.toString(gameUserRole));
 | 
	
		
			
				|  |  | -                throw new BaseException("参数错误, 游戏用户信息不全");
 | 
	
		
			
				|  |  | +            if (gameUserRole == null) {
 | 
	
		
			
				|  |  | +                log.error("[订单推送]角色信息不存在, game : {}, param : {}", JsonUtil.toString(game), JsonUtil.toString(param));
 | 
	
		
			
				|  |  | +                throw new BaseException("[订单推送]角色信息不存在");
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              //构造订单
 | 
	
		
			
				|  |  |              return this.transform(game, param, user, gameUser, gameUserRole);
 | 
	
		
			
				|  |  |          } catch (Exception e) {
 | 
	
		
			
				|  |  | -            log.error("订单数据推送创建订单异常, param : {}, e : {}", JsonUtil.toString(param), e.getMessage(), e);
 | 
	
		
			
				|  |  | -            throw new BaseException("订单数据推送创建订单异常");
 | 
	
		
			
				|  |  | +            log.error("[订单推送]订单创建出现异常, game : {}, param : {}, e : {}", JsonUtil.toString(game), JsonUtil.toString(param), e.getMessage(), e);
 | 
	
		
			
				|  |  | +            throw new BaseException("[订单推送]订单创建出现异常!");
 | 
	
		
			
				|  |  |          } finally {
 | 
	
		
			
				|  |  |              RLock rLock = distributedLockComponent.getLock(lockKey);
 | 
	
		
			
				|  |  |              if (rLock != null) {
 | 
	
	
		
			
				|  | @@ -190,55 +219,76 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
 | 
	
		
			
				|  |  |      public CpPushResultVO pushActive(String gameAppId, CpPushActiveParam param) {
 | 
	
		
			
				|  |  |          //查询游戏
 | 
	
		
			
				|  |  |          Game game = this.getGameByGameAppId(gameAppId);
 | 
	
		
			
				|  |  | -        //查询玩家信息
 | 
	
		
			
				|  |  | -        User user = userService.getOne(new LambdaQueryWrapper<User>()
 | 
	
		
			
				|  |  | -                .eq(User::getOpenId, param.getOpenId())
 | 
	
		
			
				|  |  | -                .eq(User::getGameId, game.getId()));
 | 
	
		
			
				|  |  | -        if (user == null) {
 | 
	
		
			
				|  |  | -            throw new BaseException("参数错误, 玩家信息不存在");
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        //查询角色信息
 | 
	
		
			
				|  |  | -        GameUserRole gameUserRole = gameUserRoleService.getOne(new LambdaQueryWrapper<GameUserRole>()
 | 
	
		
			
				|  |  | -                .eq(GameUserRole::getUserId, user.getId())
 | 
	
		
			
				|  |  | -                .eq(GameUserRole::getGameId, game.getId())
 | 
	
		
			
				|  |  | -                .eq(GameUserRole::getServerId, param.getServerId())
 | 
	
		
			
				|  |  | -                .eq(GameUserRole::getRoleId, param.getRoleId())
 | 
	
		
			
				|  |  | -                .orderByDesc(GameUserRole::getCreateTime)
 | 
	
		
			
				|  |  | -                .last("limit 1"));
 | 
	
		
			
				|  |  | -        if (gameUserRole == null) {
 | 
	
		
			
				|  |  | -            throw new BaseException("参数错误, 玩家角色信息不存在");
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            //查询玩家信息
 | 
	
		
			
				|  |  | +            User user = userService.getOne(new LambdaQueryWrapper<User>()
 | 
	
		
			
				|  |  | +                    .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("[活跃推送]角色信息不存在");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //查询角色信息
 | 
	
		
			
				|  |  | +            GameUserRole gameUserRole = gameUserRoleService.getOne(new LambdaQueryWrapper<GameUserRole>()
 | 
	
		
			
				|  |  | +                    .eq(GameUserRole::getUserId, user.getId())
 | 
	
		
			
				|  |  | +                    .eq(GameUserRole::getGameId, game.getId())
 | 
	
		
			
				|  |  | +                    .eq(GameUserRole::getServerId, param.getServerId())
 | 
	
		
			
				|  |  | +                    .eq(GameUserRole::getRoleId, param.getRoleId())
 | 
	
		
			
				|  |  | +                    .orderByDesc(GameUserRole::getCreateTime)
 | 
	
		
			
				|  |  | +                    .last("limit 1"));
 | 
	
		
			
				|  |  | +            if (gameUserRole == null) {
 | 
	
		
			
				|  |  | +                log.error("[活跃推送]角色信息不存在, game : {}, param : {}", JsonUtil.toString(game), JsonUtil.toString(param));
 | 
	
		
			
				|  |  | +                throw new BaseException("[活跃推送]角色信息不存在");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //角色活跃信息上报到卡夫卡
 | 
	
		
			
				|  |  | +            kafkaService.roleActiveTrack(gameUserRole, param.getActiveType());
 | 
	
		
			
				|  |  | +        } catch (Exception e) {
 | 
	
		
			
				|  |  | +            //保存错误日志
 | 
	
		
			
				|  |  | +            cpPushErrorLogService.createLog(game.getId(), CpPushDataEnum.CP_PUSH_DATA_ACTIVE, param, e.getMessage());
 | 
	
		
			
				|  |  | +            //抛出异常
 | 
	
		
			
				|  |  | +            throw new BaseException(e.getMessage());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        //角色活跃信息上报到卡夫卡
 | 
	
		
			
				|  |  | -        kafkaService.roleActiveTrack(gameUserRole, param.getActiveType());
 | 
	
		
			
				|  |  |          //构造返回
 | 
	
		
			
				|  |  |          return CpPushResultVO.builder().result(Boolean.TRUE).build();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  | -    @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |      public CpPushResultVO pushServer(String gameAppId, CpPushServerParam param) {
 | 
	
		
			
				|  |  |          //查询游戏
 | 
	
		
			
				|  |  |          Game game = this.getGameByGameAppId(gameAppId);
 | 
	
		
			
				|  |  | -        //查询区服id
 | 
	
		
			
				|  |  | -        GameServer gameServer = gameServerService.getOne(new LambdaQueryWrapper<GameServer>()
 | 
	
		
			
				|  |  | -                .eq(GameServer::getGameId, game.getSuperGameId())
 | 
	
		
			
				|  |  | -                .eq(GameServer::getServerId, param.getServerId())
 | 
	
		
			
				|  |  | -        );
 | 
	
		
			
				|  |  | -        GameServer transform = this.transform(game.getSuperGameId(), param);
 | 
	
		
			
				|  |  | -        if (gameServer == null) {
 | 
	
		
			
				|  |  | -            gameServer = transform;
 | 
	
		
			
				|  |  | -        } else {
 | 
	
		
			
				|  |  | -            gameServer.setGameId(transform.getGameId());
 | 
	
		
			
				|  |  | -            gameServer.setServerId(transform.getServerId());
 | 
	
		
			
				|  |  | -            gameServer.setServerName(transform.getServerName());
 | 
	
		
			
				|  |  | -            gameServer.setNickName(transform.getNickName());
 | 
	
		
			
				|  |  | -            gameServer.setStartTime(transform.getStartTime());
 | 
	
		
			
				|  |  | -            gameServer.setUpdateTime(LocalDateTime.now());
 | 
	
		
			
				|  |  | +        // 手动开启事务
 | 
	
		
			
				|  |  | +        TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            //查询区服id
 | 
	
		
			
				|  |  | +            GameServer gameServer = gameServerService.getOne(new LambdaQueryWrapper<GameServer>()
 | 
	
		
			
				|  |  | +                    .eq(GameServer::getGameId, game.getSuperGameId())
 | 
	
		
			
				|  |  | +                    .eq(GameServer::getServerId, param.getServerId())
 | 
	
		
			
				|  |  | +            );
 | 
	
		
			
				|  |  | +            GameServer transform = this.transform(game.getSuperGameId(), param);
 | 
	
		
			
				|  |  | +            if (gameServer == null) {
 | 
	
		
			
				|  |  | +                gameServer = transform;
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                gameServer.setGameId(transform.getGameId());
 | 
	
		
			
				|  |  | +                gameServer.setServerId(transform.getServerId());
 | 
	
		
			
				|  |  | +                gameServer.setServerName(transform.getServerName());
 | 
	
		
			
				|  |  | +                gameServer.setNickName(transform.getNickName());
 | 
	
		
			
				|  |  | +                gameServer.setStartTime(transform.getStartTime());
 | 
	
		
			
				|  |  | +                gameServer.setUpdateTime(LocalDateTime.now());
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //区服添加或者更新
 | 
	
		
			
				|  |  | +            boolean 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());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        //区服添加或者更新
 | 
	
		
			
				|  |  | -        boolean result = gameServerService.saveOrUpdate(gameServer);
 | 
	
		
			
				|  |  | -        //构造返回
 | 
	
		
			
				|  |  | -        return CpPushResultVO.builder().result(result).build();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      private GameServer transform(Long superGameId, CpPushServerParam param) {
 | 
	
	
		
			
				|  | @@ -259,30 +309,43 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  | -    @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |      public CpPushResultVO pushRole(String gameAppId, CpPushRoleParam param) {
 | 
	
		
			
				|  |  |          //查询游戏
 | 
	
		
			
				|  |  |          Game game = this.getGameByGameAppId(gameAppId);
 | 
	
		
			
				|  |  | -        //查询玩家信息
 | 
	
		
			
				|  |  | -        User user = userService.getOne(new LambdaQueryWrapper<User>()
 | 
	
		
			
				|  |  | -                .eq(User::getGameId, game.getId())
 | 
	
		
			
				|  |  | -                .eq(User::getOpenId, param.getOpenId()));
 | 
	
		
			
				|  |  | -        if (user == null) {
 | 
	
		
			
				|  |  | -            throw new BaseException("参数错误, 玩家信息不存在");
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        //查询玩家角色信息
 | 
	
		
			
				|  |  | -        GameUserRole gameUserRole = gameUserRoleService.getOne(new LambdaQueryWrapper<GameUserRole>()
 | 
	
		
			
				|  |  | -                .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 {
 | 
	
		
			
				|  |  | -            result = this.gameRoleUpdate(param, gameUserRole, user);
 | 
	
		
			
				|  |  | +        // 手动开启事务
 | 
	
		
			
				|  |  | +        TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            //查询玩家信息
 | 
	
		
			
				|  |  | +            User user = userService.getOne(new LambdaQueryWrapper<User>()
 | 
	
		
			
				|  |  | +                    .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("[角色推送]玩家信息不存在");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //查询玩家角色信息
 | 
	
		
			
				|  |  | +            GameUserRole gameUserRole = gameUserRoleService.getOne(new LambdaQueryWrapper<GameUserRole>()
 | 
	
		
			
				|  |  | +                    .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 {
 | 
	
		
			
				|  |  | +                result = this.gameRoleUpdate(param, gameUserRole, user);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            // 提交事务
 | 
	
		
			
				|  |  | +            dataSourceTransactionManager.commit(transactionStatus);
 | 
	
		
			
				|  |  | +            //构造返回
 | 
	
		
			
				|  |  | +            return CpPushResultVO.builder().result(result).build();
 | 
	
		
			
				|  |  | +        } catch (Exception e) {
 | 
	
		
			
				|  |  | +            // 回滚事务
 | 
	
		
			
				|  |  | +            dataSourceTransactionManager.rollback(transactionStatus);
 | 
	
		
			
				|  |  | +            //保存错误日志
 | 
	
		
			
				|  |  | +            cpPushErrorLogService.createLog(game.getId(), CpPushDataEnum.CP_PUSH_DATA_ROLE, param, e.getMessage());
 | 
	
		
			
				|  |  | +            //抛出异常
 | 
	
		
			
				|  |  | +            throw new BaseException(e.getMessage());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        //构造返回
 | 
	
		
			
				|  |  | -        return CpPushResultVO.builder().result(result).build();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      private boolean gameRoleCreate(CpPushRoleParam param, User user) {
 | 
	
	
		
			
				|  | @@ -291,11 +354,13 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
 | 
	
		
			
				|  |  |                  .eq(GameUser::getGameId, user.getGameId())
 | 
	
		
			
				|  |  |                  .eq(GameUser::getUserId, user.getId()));
 | 
	
		
			
				|  |  |          if (gameUser == null) {
 | 
	
		
			
				|  |  | -            throw new BaseException("参数错误, 玩家游戏信息不存在");
 | 
	
		
			
				|  |  | +            log.error("[角色推送]游戏玩家信息不存在, param : {}, user : {}", JsonUtil.toString(param), JsonUtil.toString(user));
 | 
	
		
			
				|  |  | +            throw new BaseException("[角色推送]游戏玩家信息不存在");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          //上锁
 | 
	
		
			
				|  |  |          if (!distributedLockComponent.doLock(RedisKeyConstant.ROLE_CREATE_LOCK + user.getGameId() + "_" + param.getRoleId(),
 | 
	
		
			
				|  |  |                  0L, 1L, TimeUnit.MINUTES)) {
 | 
	
		
			
				|  |  | +            log.error("[角色推送]角色正在创建中, param : {}, user : {}", JsonUtil.toString(param), JsonUtil.toString(user));
 | 
	
		
			
				|  |  |              return Boolean.TRUE;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          //创建角色
 | 
	
	
		
			
				|  | @@ -370,30 +435,46 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  | -    @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  |      public CpPushUserVO pushUser(String gameAppId, CpPushUserParam param) {
 | 
	
		
			
				|  |  | -        //渠道参数判断
 | 
	
		
			
				|  |  | -        String channel = param.getChannel();
 | 
	
		
			
				|  |  | -        Tuple2<Boolean, Boolean> jsonAndEmpty = this.isJsonAndEmpty(channel);
 | 
	
		
			
				|  |  |          //查询游戏
 | 
	
		
			
				|  |  |          Game game = this.getGameByGameAppId(gameAppId);
 | 
	
		
			
				|  |  | -        //中间数据
 | 
	
		
			
				|  |  | -        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()));
 | 
	
		
			
				|  |  | -        //玩家信息不存在
 | 
	
		
			
				|  |  | -        if (user == null) {
 | 
	
		
			
				|  |  | -            return this.createUser(game, userData, param, jsonAndEmpty);
 | 
	
		
			
				|  |  | +        // 手动开启事务
 | 
	
		
			
				|  |  | +        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);
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                //玩家信息更新
 | 
	
		
			
				|  |  | +                Map<String, String> channelMap = this.updateUser(user, param, game, userData, jsonAndEmpty);
 | 
	
		
			
				|  |  | +                cpPushUserVO = CpPushUserVO.builder().userId(user.getId())
 | 
	
		
			
				|  |  | +                        .sdkUser(!Objects.equals(user.getAgentId(), Agent.DEFAULT_AGENT))
 | 
	
		
			
				|  |  | +                        .channel(JsonUtil.toString(channelMap))
 | 
	
		
			
				|  |  | +                        .build();
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            // 提交事务
 | 
	
		
			
				|  |  | +            dataSourceTransactionManager.commit(transactionStatus);
 | 
	
		
			
				|  |  | +            //返回结果
 | 
	
		
			
				|  |  | +            return cpPushUserVO;
 | 
	
		
			
				|  |  | +        } catch (Exception e) {
 | 
	
		
			
				|  |  | +            // 回滚事务
 | 
	
		
			
				|  |  | +            dataSourceTransactionManager.rollback(transactionStatus);
 | 
	
		
			
				|  |  | +            //保存错误日志
 | 
	
		
			
				|  |  | +            cpPushErrorLogService.createLog(game.getId(), CpPushDataEnum.CP_PUSH_DATA_USER, param, e.getMessage());
 | 
	
		
			
				|  |  | +            //抛出异常
 | 
	
		
			
				|  |  | +            throw new BaseException(e.getMessage());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        //玩家信息更新
 | 
	
		
			
				|  |  | -        Map<String, String> channelMap = this.updateUser(user, param, game, userData, jsonAndEmpty);
 | 
	
		
			
				|  |  | -        //构造返回
 | 
	
		
			
				|  |  | -        return CpPushUserVO.builder().userId(user.getId())
 | 
	
		
			
				|  |  | -                .sdkUser(!Objects.equals(user.getAgentId(), Agent.DEFAULT_AGENT))
 | 
	
		
			
				|  |  | -                .channel(JsonUtil.toString(channelMap))
 | 
	
		
			
				|  |  | -                .build();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      private CpPushUserVO createUser(Game game, UserData userData, CpPushUserParam param, Tuple2<Boolean, Boolean> jsonAndEmpty) {
 | 
	
	
		
			
				|  | @@ -403,7 +484,8 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
 | 
	
		
			
				|  |  |          String lockKey = RedisKeyConstant.USER_CREATE + gameId + "_" + param.getOpenId();
 | 
	
		
			
				|  |  |          //上锁
 | 
	
		
			
				|  |  |          if (!distributedLockComponent.doLock(lockKey, 0L, 3L, TimeUnit.MINUTES)) {
 | 
	
		
			
				|  |  | -            throw new BaseException("用户信息正在注册中, 请勿重复请求!");
 | 
	
		
			
				|  |  | +            log.error("[用户推送]用户正在创建中, param : {}, game : {}", JsonUtil.toString(param), JsonUtil.toString(game));
 | 
	
		
			
				|  |  | +            throw new BaseException("[用户推送]用户正在创建中");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          //玩家信息
 | 
	
		
			
				|  |  |          User user;
 | 
	
	
		
			
				|  | @@ -440,8 +522,8 @@ public class CpPushDataServiceImpl implements ICpPushDataService {
 | 
	
		
			
				|  |  |                      .channel(JsonUtil.toString(channelMap))
 | 
	
		
			
				|  |  |                      .build();
 | 
	
		
			
				|  |  |          } catch (Exception e) {
 | 
	
		
			
				|  |  | -            log.error("玩家信息推送数据处理异常, gameId : {}, param : {}, e : {}", gameId, JsonUtil.toString(param), e.getMessage(), e);
 | 
	
		
			
				|  |  | -            throw new BaseException("玩家信息推送数据处理异常");
 | 
	
		
			
				|  |  | +            log.error("[用户推送]用户创建出现异常, gameId : {}, param : {}, e : {}", gameId, JsonUtil.toString(param), e.getMessage(), e);
 | 
	
		
			
				|  |  | +            throw new BaseException("[用户推送]用户创建出现异常");
 | 
	
		
			
				|  |  |          } finally {
 | 
	
		
			
				|  |  |              RLock rLock = distributedLockComponent.getLock(lockKey);
 | 
	
		
			
				|  |  |              if (rLock != null) {
 |