|
|
@@ -309,6 +309,10 @@ public class ExchangeCodeServiceImpl extends ServiceImpl<ExchangeCodeMapper, Exc
|
|
|
//兑换码兑换
|
|
|
orderDon.setType(orderDonTye);
|
|
|
orderDon.setUserId(user.getId());
|
|
|
+ StringBuilder payTitle = new StringBuilder();
|
|
|
+ payTitle.append(goodsDon.getTitle());
|
|
|
+ payTitle.append(sku.getSpecVal());
|
|
|
+ orderDon.setPayTitle(payTitle.toString());
|
|
|
orderDonMapper.insert(orderDon);
|
|
|
log.info("用户{}兑换规格:{}车位成功", user.getId(), orderDon.getSkuId());
|
|
|
}
|
|
|
@@ -369,9 +373,9 @@ public class ExchangeCodeServiceImpl extends ServiceImpl<ExchangeCodeMapper, Exc
|
|
|
.orderByAsc(GroupsTrips::getAvailableNum));
|
|
|
}
|
|
|
if (groups == null) {
|
|
|
- //新增车位 并关联
|
|
|
- relation = createNewGroupTripsAndRelation(sku, groups, relation);
|
|
|
- log.info("无合适规格车队,新增新车队,获取车位relationId:{}", relation.getId());
|
|
|
+ //若是ChatGPT Plus 、MidJourney
|
|
|
+ //获取额外的车位
|
|
|
+ relation = getOutSideRelationIfAi(userId, groups, sku);
|
|
|
} else {
|
|
|
//寻找快满编车队进行占座
|
|
|
relation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
|
|
|
@@ -385,15 +389,14 @@ public class ExchangeCodeServiceImpl extends ServiceImpl<ExchangeCodeMapper, Exc
|
|
|
log.info("寻找快满编车队的车位relationId:{}", relation.getId());
|
|
|
//如果占位失败 新增车位并关联
|
|
|
if (relation == null) {
|
|
|
- relation = createNewGroupTripsAndRelation(sku, groups, relation);
|
|
|
- log.info("占位新车队车位失败,再次新增新车队,获取车位relationId:{}", relation.getId());
|
|
|
+ relation = getOutSideRelationIfAi(userId, groups, sku);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
//锁定座位
|
|
|
- setRelation(relation.getId(), userId);
|
|
|
+ setRelation(relation.getId(), userId, relation.getGroupsId(), relation.getStatus());
|
|
|
relation.setUserId(userId);
|
|
|
GroupsTrips groupsTrips = groupsMapper.selectById(relation.getGroupsId());
|
|
|
if (GroupsTrips.Status.validity.equals(groupsTrips.getStatus())) {
|
|
|
@@ -408,19 +411,10 @@ public class ExchangeCodeServiceImpl extends ServiceImpl<ExchangeCodeMapper, Exc
|
|
|
relation.setExpiryTime(newDate);
|
|
|
relation.setStartTime(relation.getStartTime() == null ? new Date() : null);
|
|
|
}
|
|
|
- relation.setStatus(GroupsRelation.Status.validity);
|
|
|
- int isSuccess = groupsRelationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
|
|
|
- .set(GroupsRelation::getUserId, userId)
|
|
|
- .set(GroupsRelation::getStatus, GroupsRelation.Status.validity)
|
|
|
- .set(GroupsRelation::getStartTime, relation.getStartTime())
|
|
|
- .set(GroupsRelation::getExpiryTime, relation.getExpiryTime())
|
|
|
- .eq(GroupsRelation::getId, relation.getId())
|
|
|
- .eq(GroupsRelation::getUserId, 0)
|
|
|
- .eq(GroupsRelation::getStatus, GroupsRelation.Status.none));
|
|
|
- if (isSuccess != 1) {
|
|
|
- log.error("该车位已被占,用户userId:{}更新上车relationId:{}状态失败", userId, relation.getId());
|
|
|
- throw BusinessRuntimeException.getInstance("该车位已被占");
|
|
|
+ if (relation.getStatus() != GroupsRelation.Status.outside) {
|
|
|
+ relation.setStatus(GroupsRelation.Status.validity);
|
|
|
}
|
|
|
+ groupsRelationMapper.updateById(relation);
|
|
|
redisService.del(RedisKey.GROUPS_RELATION_NUM_KEY + relation.getId());
|
|
|
} catch (Exception e) {
|
|
|
Object value = redisService.get(RedisKey.GROUPS_RELATION_NUM_KEY + relation.getId());
|
|
|
@@ -438,7 +432,7 @@ public class ExchangeCodeServiceImpl extends ServiceImpl<ExchangeCodeMapper, Exc
|
|
|
return relation;
|
|
|
}
|
|
|
|
|
|
- private void setRelation(Long relationId, Long userId) {
|
|
|
+ private void setRelation(Long relationId, Long userId, Long groupsId, GroupsRelation.Status status) {
|
|
|
if (redisService.get(RedisKey.GROUPS_RELATION_NUM_KEY + relationId) != null) {
|
|
|
log.info("=====>用户:{}获取了已有人座位:{}", userId, relationId);
|
|
|
throw new BusinessRuntimeException("客官手慢啦,该座位已经有人啦!");
|
|
|
@@ -447,11 +441,13 @@ public class ExchangeCodeServiceImpl extends ServiceImpl<ExchangeCodeMapper, Exc
|
|
|
log.info("=====>用户:{}未抢到座位:{}", userId, relationId);
|
|
|
throw new BusinessRuntimeException("客官手慢啦,该座位已经有人啦!");
|
|
|
}
|
|
|
- GroupsRelation relation = groupsRelationMapper.selectById(relationId);
|
|
|
- int count = groupsMapper.decrAvailableNum(relation.getGroupsId());
|
|
|
+ if (status == GroupsRelation.Status.outside) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ int count = groupsMapper.decrAvailableNum(groupsId);
|
|
|
if (count == 0) {
|
|
|
- log.error("车位异常 groupId:{}", relation.getGroupsId());
|
|
|
- groupsMapper.updateAvailableNum(relation.getGroupsId());
|
|
|
+ log.error("车位异常 groupId:{}", groupsId);
|
|
|
+ groupsMapper.updateAvailableNum(groupsId);
|
|
|
throw new BusinessRuntimeException("车位异常");
|
|
|
}
|
|
|
}
|
|
|
@@ -502,4 +498,38 @@ public class ExchangeCodeServiceImpl extends ServiceImpl<ExchangeCodeMapper, Exc
|
|
|
}
|
|
|
return relation;
|
|
|
}
|
|
|
+
|
|
|
+ public GroupsRelation getOutSideRelationIfAi(Long userId, GroupsTrips groups, GoodsDonSku sku) {
|
|
|
+ //若是MidJourney、ChatGPT PLUS每个已满车队 硬塞5个座位
|
|
|
+ //主账号过期时间10天以外
|
|
|
+ GroupsRelation relation = null;
|
|
|
+ if (Constant.AI_goodsIds.contains(sku.getGoodsId())) {
|
|
|
+ DateTime tenExpiry = DateUtil.offsetDay(DateUtil.beginOfDay(DateTime.now()), 10);
|
|
|
+ Long groupsId = groupsRelationMapper.getOutSideGroupsTripsRelationByGoodsId(sku.getId(), tenExpiry, 5);
|
|
|
+ if (groupsId != null) {
|
|
|
+ relation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
|
|
|
+ .eq(GroupsRelation::getGroupsId, groupsId)
|
|
|
+ .eq(GroupsRelation::getUserId, 0)
|
|
|
+ .eq(GroupsRelation::getStatus, GroupsRelation.Status.outside)
|
|
|
+ .last("limit 1"));
|
|
|
+ if (relation == null) {
|
|
|
+ if (!redisService.setNx(RedisService.key.GROUPS_TRIPS_OUTSIDE_RELATION.getName() + groupsId, groupsId, RedisService.key.GROUPS_TRIPS_OUTSIDE_RELATION.getTimeout())) {
|
|
|
+ relation = new GroupsRelation();
|
|
|
+ relation.setStatus(GroupsRelation.Status.outside);
|
|
|
+ relation.setUserId(userId);
|
|
|
+ relation.setGroupsId(groupsId);
|
|
|
+ GroupsRelation maxNumRelation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class).eq(GroupsRelation::getGroupsId, groupsId).orderByDesc(GroupsRelation::getNum).last("limit 1"));
|
|
|
+ relation.setNum(maxNumRelation.getNum() + 1);
|
|
|
+ groupsRelationMapper.insert(relation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (relation == null) {
|
|
|
+ //新增车位 并关联
|
|
|
+ relation = createNewGroupTripsAndRelation(sku, groups, relation);
|
|
|
+ log.info("无合适规格车队,新增新车队,获取车位relationId:{}", relation.getId());
|
|
|
+ }
|
|
|
+ return relation;
|
|
|
+ }
|
|
|
}
|