|  | @@ -20,6 +20,7 @@ import com.zanxiang.game.module.mybatis.mapper.GameGiftPackCodeLogMapper;
 | 
	
		
			
				|  |  |  import com.zanxiang.module.redis.service.IDistributedLockComponent;
 | 
	
		
			
				|  |  |  import com.zanxiang.module.util.JsonUtil;
 | 
	
		
			
				|  |  |  import com.zanxiang.module.util.bean.BeanUtil;
 | 
	
		
			
				|  |  | +import com.zanxiang.module.util.exception.BaseException;
 | 
	
		
			
				|  |  |  import lombok.extern.slf4j.Slf4j;
 | 
	
		
			
				|  |  |  import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  |  import org.apache.logging.log4j.util.Strings;
 | 
	
	
		
			
				|  | @@ -147,17 +148,14 @@ public class GameGiftPackCodeLogServiceImpl extends ServiceImpl<GameGiftPackCode
 | 
	
		
			
				|  |  |          roleOperateService.roleOperateUpdate(userPhone, linkLog);
 | 
	
		
			
				|  |  |          //构造记录
 | 
	
		
			
				|  |  |          GameGiftPackCodeLog gameGiftPackCodeLog = this.transform(linkLog, userPhone);
 | 
	
		
			
				|  |  | -        //从缓存中获取一个礼包码id, 如果缓存中不存在则是领完了
 | 
	
		
			
				|  |  | -        String codeId = redisUtil.popOfSet(RedisKeyConstant.GAME_GIFT_PACK_CODE + linkLog.getLinkId());
 | 
	
		
			
				|  |  | -        if (Strings.isBlank(codeId)) {
 | 
	
		
			
				|  |  | +        //判断礼包码是否存在, 缓存不存在, 或者长度为零, 没有礼包码可领取
 | 
	
		
			
				|  |  | +        String codeKey = RedisKeyConstant.GAME_GIFT_PACK_CODE + linkLog.getLinkId();
 | 
	
		
			
				|  |  | +        if (!redisUtil.hasKey(codeKey) || redisUtil.getSetSize(codeKey) <= 0) {
 | 
	
		
			
				|  |  |              String msg = "该礼包已被领取完, 请联系客服小姐姐领取其他礼包";
 | 
	
		
			
				|  |  |              gameGiftPackCodeLog.setMsg(msg);
 | 
	
		
			
				|  |  |              super.save(gameGiftPackCodeLog);
 | 
	
		
			
				|  |  |              return Tuple2.with(Boolean.FALSE, msg);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        //查询礼包码具体信息, 礼包码必须存在, 且未被领取, 否则数据错误
 | 
	
		
			
				|  |  | -        GameGiftPackCode gameGiftPackCode = gameGiftPackCodeService.getById(Long.valueOf(codeId));
 | 
	
		
			
				|  |  | -        Assert.notNull(gameGiftPackCode, "礼包码数据错误, 请联系客服小姐姐处理");
 | 
	
		
			
				|  |  |          //判断是否满足领取条件
 | 
	
		
			
				|  |  |          Tuple2<Boolean, String> conditionCheck = this.conditionCheck(linkLog);
 | 
	
		
			
				|  |  |          //设置判定消息
 | 
	
	
		
			
				|  | @@ -167,8 +165,26 @@ public class GameGiftPackCodeLogServiceImpl extends ServiceImpl<GameGiftPackCode
 | 
	
		
			
				|  |  |              super.save(gameGiftPackCodeLog);
 | 
	
		
			
				|  |  |              return Tuple2.with(Boolean.FALSE, "角色不满足该礼包领取条件, 请联系客服领取其他礼包");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        //从缓存中获取一个礼包码id, 如果缓存中不存在则是领完了
 | 
	
		
			
				|  |  | +        String codeId = redisUtil.popOfSet(codeKey);
 | 
	
		
			
				|  |  | +        if (Strings.isBlank(codeId)) {
 | 
	
		
			
				|  |  | +            String msg = "该礼包已被领取完, 请联系客服小姐姐领取其他礼包";
 | 
	
		
			
				|  |  | +            gameGiftPackCodeLog.setMsg(msg);
 | 
	
		
			
				|  |  | +            super.save(gameGiftPackCodeLog);
 | 
	
		
			
				|  |  | +            return Tuple2.with(Boolean.FALSE, msg);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //查询礼包码具体信息, 礼包码必须存在, 且未被领取, 否则数据错误
 | 
	
		
			
				|  |  | +        GameGiftPackCode gameGiftPackCode = gameGiftPackCodeService.getById(Long.valueOf(codeId));
 | 
	
		
			
				|  |  | +        Assert.notNull(gameGiftPackCode, "礼包码数据错误, 请联系客服小姐姐处理");
 | 
	
		
			
				|  |  |          //成功领取礼包码记录数据更新
 | 
	
		
			
				|  |  | -        this.codeSendUpdate(gameGiftPackCode, linkLog, gameGiftPackCodeLog);
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            this.codeSendUpdate(gameGiftPackCode, linkLog, gameGiftPackCodeLog);
 | 
	
		
			
				|  |  | +        } catch (Exception e) {
 | 
	
		
			
				|  |  | +            //出现数据更新异常, 礼包码放回去
 | 
	
		
			
				|  |  | +            redisUtil.addToSet(codeKey);
 | 
	
		
			
				|  |  | +            log.error("数据库表同步更新异常, e: {}", e.getMessage(), e);
 | 
	
		
			
				|  |  | +            throw new BaseException("礼包码数据更新异常, 请联系客服小姐姐处理");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |          //返回礼包码
 | 
	
		
			
				|  |  |          return Tuple2.with(Boolean.TRUE, gameGiftPackCode.getCode());
 | 
	
		
			
				|  |  |      }
 |