|
|
@@ -288,11 +288,12 @@ public class ExchangeCodeServiceImpl extends ServiceImpl<ExchangeCodeMapper, Exc
|
|
|
@Override
|
|
|
public GroupsRelation getRelationNoOrder(GoodsDonSku sku, Long userId) {
|
|
|
GroupsRelation relation = null;
|
|
|
- relation = getFinalRelation(sku, userId, relation);
|
|
|
+ Integer retryNum = 1;
|
|
|
+ relation = getFinalRelation(sku, userId, relation, retryNum);
|
|
|
return relation;
|
|
|
}
|
|
|
|
|
|
- public GroupsRelation getFinalRelation(GoodsDonSku sku, Long userId, GroupsRelation relation) {
|
|
|
+ public GroupsRelation getFinalRelation(GoodsDonSku sku, Long userId, GroupsRelation relation, Integer retryNum) {
|
|
|
//寻找差不多过期时间规格的车位
|
|
|
relation = groupRelationFrontService.getSimilarExpiredGroupRelation(sku.getId(), sku.getMonths());
|
|
|
if (relation == null) {
|
|
|
@@ -328,9 +329,16 @@ public class ExchangeCodeServiceImpl extends ServiceImpl<ExchangeCodeMapper, Exc
|
|
|
relation.setStartTime(relation.getStartTime() == null ? new Date() : null);
|
|
|
groupsRelationMapper.updateById(relation);
|
|
|
} catch (Exception e) {
|
|
|
+ Object value = redisService.get(RedisKey.GROUPS_RELATION_NUM_KEY + relation.getId());
|
|
|
+ if (value != null && userId.equals(Long.parseLong(value.toString()))) {
|
|
|
+ redisService.del(RedisKey.GROUPS_RELATION_NUM_KEY + relation.getId());
|
|
|
+ }
|
|
|
+ if (retryNum == 10) {
|
|
|
+ log.error("用户:{}获取车票:{}异常", userId, relation.getId());
|
|
|
+ throw BusinessRuntimeException.getInstance("获取车票异常,请联系客服");
|
|
|
+ }
|
|
|
//失败重新给他分配车位
|
|
|
- getFinalRelation(sku, userId, relation);
|
|
|
- redisService.del(RedisKey.GROUPS_RELATION_NUM_KEY + relation.getId());
|
|
|
+ getFinalRelation(sku, userId, relation, ++retryNum);
|
|
|
}
|
|
|
return relation;
|
|
|
}
|
|
|
@@ -339,7 +347,9 @@ public class ExchangeCodeServiceImpl extends ServiceImpl<ExchangeCodeMapper, Exc
|
|
|
if (redisService.get(RedisKey.GROUPS_RELATION_NUM_KEY + relationId) != null) {
|
|
|
throw new BusinessRuntimeException("客官手慢啦,该座位已经有人啦!");
|
|
|
} else {
|
|
|
- redisService.set(RedisKey.GROUPS_RELATION_NUM_KEY + relationId, userId, 60 * 5L);
|
|
|
+ if (!redisService.setNx(RedisKey.GROUPS_RELATION_NUM_KEY + relationId, userId, 60 * 5L)) {
|
|
|
+ throw new BusinessRuntimeException("客官手慢啦,该座位已经有人啦!");
|
|
|
+ }
|
|
|
GroupsRelation relation = groupsRelationMapper.selectById(relationId);
|
|
|
int count = groupsMapper.decrAvailableNum(relation.getGroupsId());
|
|
|
if (count == 0) {
|