|
|
@@ -227,46 +227,9 @@ public class ExchangeCodeServiceImpl extends ServiceImpl<ExchangeCodeMapper, Exc
|
|
|
if (user == null) {
|
|
|
throw BusinessRuntimeException.getInstance("用户不存在");
|
|
|
}
|
|
|
- GroupsRelation relation = null;
|
|
|
- //寻找差不多过期时间规格的车位
|
|
|
- relation = groupRelationFrontService.getSimilarExpiredGroupRelation(sku.getId(), sku.getMonths());
|
|
|
- if (relation == null) {
|
|
|
- GroupsTrips groups = groupsMapper.selectOne(Wrappers.lambdaQuery(GroupsTrips.class).eq(GroupsTrips::getSkuId, sku.getId()).gt(GroupsTrips::getAvailableNum, 0).last("limit 1").orderByAsc(GroupsTrips::getAvailableNum));
|
|
|
- if (groups == null) {
|
|
|
- //新增车位 并关联
|
|
|
- relation = createNewGroupTripsAndRelation(sku, groups, relation);
|
|
|
- } else {
|
|
|
- //寻找快满编车队进行占座
|
|
|
- relation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
|
|
|
- .eq(GroupsRelation::getGroupsId, groups.getId())
|
|
|
- .eq(GroupsRelation::getStatus, "none")
|
|
|
- .eq(GroupsRelation::getUserId, 0)
|
|
|
- .orderByAsc(GroupsRelation::getNum)
|
|
|
- .last("limit 1")
|
|
|
- );
|
|
|
- //如果占位失败 新增车位并关联
|
|
|
- if (relation == null) {
|
|
|
- relation = createNewGroupTripsAndRelation(sku, groups, relation);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- try {
|
|
|
- //锁定座位
|
|
|
- setRelation(relation.getId(), userId);
|
|
|
- } catch (Exception e) {
|
|
|
- //失败重新给他分配车位
|
|
|
- getGroupTripsTicket(sku, userId, exCodeOrderDon, orderDonTye);
|
|
|
- redisService.del(RedisKey.GROUPS_RELATION_NUM_KEY + relation.getId());
|
|
|
- }
|
|
|
- relation.setUserId(userId);
|
|
|
- relation.setStatus(GroupsRelation.Status.validity);
|
|
|
- //如果续费增加时间,如果首次则设置当前时间为初始时间
|
|
|
- Date expiryTime = Optional.ofNullable(relation.getExpiryTime()).orElse(new Date());
|
|
|
- Date newDate = DateUtil.offset(expiryTime, DateField.MONTH, sku.getMonths() * 1);
|
|
|
- relation.setExpiryTime(newDate);
|
|
|
- relation.setStartTime(relation.getStartTime() == null ? new Date() : null);
|
|
|
- groupsRelationMapper.updateById(relation);
|
|
|
+ GroupsRelation relation = getRelationNoOrder(sku, userId);
|
|
|
+
|
|
|
Long relationId = relation.getId();
|
|
|
OrderDon orderDon;
|
|
|
if (exCodeOrderDon != null) {
|
|
|
@@ -323,6 +286,56 @@ public class ExchangeCodeServiceImpl extends ServiceImpl<ExchangeCodeMapper, Exc
|
|
|
return relation;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public GroupsRelation getRelationNoOrder(GoodsDonSku sku, Long userId) {
|
|
|
+ GroupsRelation relation = null;
|
|
|
+ relation = getFinalRelation(sku, userId, relation);
|
|
|
+ return relation;
|
|
|
+ }
|
|
|
+
|
|
|
+ public GroupsRelation getFinalRelation(GoodsDonSku sku, Long userId, GroupsRelation relation) {
|
|
|
+ //寻找差不多过期时间规格的车位
|
|
|
+ relation = groupRelationFrontService.getSimilarExpiredGroupRelation(sku.getId(), sku.getMonths());
|
|
|
+ if (relation == null) {
|
|
|
+ GroupsTrips groups = groupsMapper.selectOne(Wrappers.lambdaQuery(GroupsTrips.class).eq(GroupsTrips::getSkuId, sku.getId()).gt(GroupsTrips::getAvailableNum, 0).last("limit 1").orderByAsc(GroupsTrips::getAvailableNum));
|
|
|
+ if (groups == null) {
|
|
|
+ //新增车位 并关联
|
|
|
+ relation = createNewGroupTripsAndRelation(sku, groups, relation);
|
|
|
+ } else {
|
|
|
+ //寻找快满编车队进行占座
|
|
|
+ relation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
|
|
|
+ .eq(GroupsRelation::getGroupsId, groups.getId())
|
|
|
+ .eq(GroupsRelation::getStatus, "none")
|
|
|
+ .eq(GroupsRelation::getUserId, 0)
|
|
|
+ .orderByAsc(GroupsRelation::getNum)
|
|
|
+ .last("limit 1")
|
|
|
+ );
|
|
|
+ //如果占位失败 新增车位并关联
|
|
|
+ if (relation == null) {
|
|
|
+ relation = createNewGroupTripsAndRelation(sku, groups, relation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ //锁定座位
|
|
|
+ setRelation(relation.getId(), userId);
|
|
|
+ relation.setUserId(userId);
|
|
|
+ relation.setStatus(GroupsRelation.Status.validity);
|
|
|
+ //如果续费增加时间,如果首次则设置当前时间为初始时间
|
|
|
+ Date expiryTime = Optional.ofNullable(relation.getExpiryTime()).orElse(new Date());
|
|
|
+ Date newDate = DateUtil.offset(expiryTime, DateField.MONTH, sku.getMonths() * 1);
|
|
|
+ relation.setExpiryTime(newDate);
|
|
|
+ relation.setStartTime(relation.getStartTime() == null ? new Date() : null);
|
|
|
+ groupsRelationMapper.updateById(relation);
|
|
|
+ } catch (Exception e) {
|
|
|
+ //失败重新给他分配车位
|
|
|
+ getFinalRelation(sku, userId, relation);
|
|
|
+ redisService.del(RedisKey.GROUPS_RELATION_NUM_KEY + relation.getId());
|
|
|
+ }
|
|
|
+ return relation;
|
|
|
+ }
|
|
|
+
|
|
|
private void setRelation(Long relationId, Long userId) {
|
|
|
if (redisService.get(RedisKey.GROUPS_RELATION_NUM_KEY + relationId) != null) {
|
|
|
throw new BusinessRuntimeException("客官手慢啦,该座位已经有人啦!");
|