|
@@ -21,7 +21,6 @@ import com.cyksj.mapper.manage.exchange.ExchangeCodeMapper;
|
|
|
import com.cyksj.mapper.market.draw.LuckyDrawRecordMapper;
|
|
import com.cyksj.mapper.market.draw.LuckyDrawRecordMapper;
|
|
|
import com.cyksj.model.entity.*;
|
|
import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.model.excel.ExcelExchangeCodeData;
|
|
import com.cyksj.model.excel.ExcelExchangeCodeData;
|
|
|
-import com.cyksj.model.manage.views.AccountView;
|
|
|
|
|
import com.cyksj.model.request.ExchangeCodeReq;
|
|
import com.cyksj.model.request.ExchangeCodeReq;
|
|
|
import com.cyksj.model.request.ExchangeCodeTicket;
|
|
import com.cyksj.model.request.ExchangeCodeTicket;
|
|
|
import com.cyksj.redis.RedisService;
|
|
import com.cyksj.redis.RedisService;
|
|
@@ -30,7 +29,6 @@ import com.cyksj.service.relation.GroupRelationFrontService;
|
|
|
import com.cyksj.service.relation.GroupsRelationExpiryRecordService;
|
|
import com.cyksj.service.relation.GroupsRelationExpiryRecordService;
|
|
|
import com.cyksj.service.shop.YhShopFrontService;
|
|
import com.cyksj.service.shop.YhShopFrontService;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
-import com.ejlchina.searcher.util.MapUtils;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
@@ -360,61 +358,15 @@ public class ExchangeCodeServiceImpl extends ServiceImpl<ExchangeCodeMapper, Exc
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public GroupsRelation getRelationNoOrder(GoodsDonSku sku, Long userId, Long yhsId) {
|
|
public GroupsRelation getRelationNoOrder(GoodsDonSku sku, Long userId, Long yhsId) {
|
|
|
- GroupsRelation relation = null;
|
|
|
|
|
Integer retryNum = 1;
|
|
Integer retryNum = 1;
|
|
|
List<Long> errorsRelationIds = new ArrayList<>();
|
|
List<Long> errorsRelationIds = new ArrayList<>();
|
|
|
- relation = getFinalRelation(sku, userId, relation, retryNum, yhsId, errorsRelationIds);
|
|
|
|
|
|
|
+ GroupsRelation relation = getFinalRelation(sku, userId, retryNum, yhsId, errorsRelationIds);
|
|
|
return relation;
|
|
return relation;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public GroupsRelation getFinalRelation(GoodsDonSku sku, Long userId, GroupsRelation relation, Integer retryNum, Long yhsId, List<Long> errorsRelationIds) {
|
|
|
|
|
- //寻找差不多过期时间规格的车位
|
|
|
|
|
- relation = groupRelationFrontService.getSimilarExpiredGroupRelation(sku.getId(), sku.getDays(), sku.getMonths(), errorsRelationIds);
|
|
|
|
|
- if (relation == null) {
|
|
|
|
|
- GroupsTrips groups = groupsMapper.selectOne(Wrappers.lambdaQuery(GroupsTrips.class)
|
|
|
|
|
- .eq(GroupsTrips::getSkuId, sku.getId())
|
|
|
|
|
- .gt(GroupsTrips::getAvailableNum, 0).last("limit 1")
|
|
|
|
|
- .eq(GroupsTrips::getStatus, GroupsTrips.Status.validity)
|
|
|
|
|
- .orderByAsc(GroupsTrips::getAvailableNum));
|
|
|
|
|
- if (groups == null) {
|
|
|
|
|
- //若是ChatGPT Plus 、MidJourney
|
|
|
|
|
- //获取额外的车位
|
|
|
|
|
- relation = getOutSideRelationIfAi(userId, groups, sku);
|
|
|
|
|
- if (relation != null) {
|
|
|
|
|
- groups = groupsMapper.selectById(relation.getGroupsId());
|
|
|
|
|
- }
|
|
|
|
|
- //待发车
|
|
|
|
|
- if (relation == null) {
|
|
|
|
|
- groups = groupsMapper.selectOne(Wrappers.lambdaQuery(GroupsTrips.class)
|
|
|
|
|
- .eq(GroupsTrips::getSkuId, sku.getId())
|
|
|
|
|
- .gt(GroupsTrips::getAvailableNum, 0).last("limit 1")
|
|
|
|
|
- .eq(GroupsTrips::getStatus, GroupsTrips.Status.waiting)
|
|
|
|
|
- .orderByAsc(GroupsTrips::getAvailableNum));
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- if (groups == null) {
|
|
|
|
|
- //新增车位 并关联
|
|
|
|
|
- relation = createNewGroupTripsAndRelation(sku, groups, relation);
|
|
|
|
|
- log.info("无合适规格车队,新增新车队,获取车位relationId:{}", relation.getId());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (relation == null) {
|
|
|
|
|
- //寻找快满编车队进行占座
|
|
|
|
|
- relation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
|
|
|
|
|
- .eq(GroupsRelation::getGroupsId, groups.getId())
|
|
|
|
|
- .notIn(errorsRelationIds != null && errorsRelationIds.size() > 0, GroupsRelation::getId, errorsRelationIds)
|
|
|
|
|
- .eq(GroupsRelation::getStatus, "none")
|
|
|
|
|
- .eq(GroupsRelation::getUserId, 0)
|
|
|
|
|
- .orderByAsc(GroupsRelation::getNum)
|
|
|
|
|
- .last("limit 1")
|
|
|
|
|
- );
|
|
|
|
|
- log.info("寻找快满编车队的车位relationId:{}", relation.getId());
|
|
|
|
|
- //如果占位失败 新增车位并关联
|
|
|
|
|
- if (relation == null) {
|
|
|
|
|
- relation = getOutSideRelationIfAi(userId, groups, sku);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ public GroupsRelation getFinalRelation(GoodsDonSku sku, Long userId, Integer retryNum, Long yhsId, List<Long> errorsRelationIds) {
|
|
|
|
|
+ //获取车票车位
|
|
|
|
|
+ GroupsRelation relation = groupRelationFrontService.getRelation(null, userId, sku);
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
//锁定座位
|
|
//锁定座位
|
|
@@ -450,7 +402,7 @@ public class ExchangeCodeServiceImpl extends ServiceImpl<ExchangeCodeMapper, Exc
|
|
|
throw BusinessRuntimeException.getInstance("获取车票异常,请联系客服");
|
|
throw BusinessRuntimeException.getInstance("获取车票异常,请联系客服");
|
|
|
}
|
|
}
|
|
|
//失败重新给他分配车位
|
|
//失败重新给他分配车位
|
|
|
- getFinalRelation(sku, userId, relation, ++retryNum, yhsId, errorsRelationIds);
|
|
|
|
|
|
|
+ getFinalRelation(sku, userId, ++retryNum, yhsId, errorsRelationIds);
|
|
|
}
|
|
}
|
|
|
return relation;
|
|
return relation;
|
|
|
}
|
|
}
|
|
@@ -475,82 +427,4 @@ public class ExchangeCodeServiceImpl extends ServiceImpl<ExchangeCodeMapper, Exc
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 新增新车位并关联车位
|
|
|
|
|
- */
|
|
|
|
|
- private GroupsRelation createNewGroupTripsAndRelation(GoodsDonSku sku, GroupsTrips groups, GroupsRelation relation) {
|
|
|
|
|
- //通过兑换码兑换车票 新增车位
|
|
|
|
|
- if (groups == null) {
|
|
|
|
|
- groups = new GroupsTrips();
|
|
|
|
|
- }
|
|
|
|
|
- //补充占位
|
|
|
|
|
- if (relation == null) {
|
|
|
|
|
- relation = new GroupsRelation();
|
|
|
|
|
- }
|
|
|
|
|
- groups.setSkuId(sku.getId());
|
|
|
|
|
- groups.setNum(sku.getNum());
|
|
|
|
|
- groups.setAvailableNum(sku.getNum());
|
|
|
|
|
- if (sku.getGoodsId() == 23) {
|
|
|
|
|
- AccountView accountView = beanSearcher.searchFirst(AccountView.class, MapUtils.builder().field(AccountView::getGoodsId, 23).onlySelect(AccountView::getId).build());
|
|
|
|
|
- if (accountView != null) {
|
|
|
|
|
- groups.setAccountId(accountView.getId());
|
|
|
|
|
- groups.setStatus(GroupsTrips.Status.validity);
|
|
|
|
|
- groups.setRemark("已设置唯一账号");
|
|
|
|
|
- }else {
|
|
|
|
|
- groups.setStatus(GroupsTrips.Status.waiting);
|
|
|
|
|
- groups.setRemark("等待设置账号");
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- groups.setStatus(GroupsTrips.Status.waiting);
|
|
|
|
|
- groups.setRemark("等待设置账号");
|
|
|
|
|
- }
|
|
|
|
|
- groupsMapper.insert(groups);
|
|
|
|
|
- relation.setGroupsId(groups.getId());
|
|
|
|
|
- relation.setNum(1);
|
|
|
|
|
- relation.setStatus(GroupsRelation.Status.none);
|
|
|
|
|
- relation.setGroupsId(groups.getId());
|
|
|
|
|
- groupsRelationMapper.insert(relation);
|
|
|
|
|
- //补充其他占位
|
|
|
|
|
- for (int i = 2; i <= groups.getNum(); i++) {
|
|
|
|
|
- GroupsRelation groupsRelation = new GroupsRelation();
|
|
|
|
|
- groupsRelation.setGroupsId(groups.getId());
|
|
|
|
|
- groupsRelation.setNum(i);
|
|
|
|
|
- groupsRelation.setStatus(GroupsRelation.Status.none);
|
|
|
|
|
- groupsRelationMapper.insert(groupsRelation);
|
|
|
|
|
- }
|
|
|
|
|
- return relation;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public GroupsRelation getOutSideRelationIfAi(Long userId, GroupsTrips groups, GoodsDonSku sku) {
|
|
|
|
|
- //若是MidJourney、ChatGPT PLUS每个已满车队 硬塞5个座位
|
|
|
|
|
- //主账号过期时间10天以外
|
|
|
|
|
- GroupsRelation relation = null;
|
|
|
|
|
- if (sku.getNum() > 1 && Constant.AI_goodsIds.contains(sku.getGoodsId())) {
|
|
|
|
|
- DateTime tenExpiry = DateUtil.offsetDay(DateUtil.beginOfDay(DateTime.now()), 10);
|
|
|
|
|
- Long groupsId = groupsRelationMapper.getOutSideGroupsTripsRelationByGoodsId(sku.getId(), tenExpiry, 5, userId, sku.getNum());
|
|
|
|
|
- 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) {
|
|
|
|
|
- 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"));
|
|
|
|
|
- Integer nextNum = maxNumRelation.getNum() + 1;
|
|
|
|
|
- if (redisService.setNx(RedisService.key.GROUPS_TRIPS_OUTSIDE_RELATION.getNameFormat(groupsId, nextNum), nextNum, RedisService.key.GROUPS_TRIPS_OUTSIDE_RELATION.getTimeout())) {
|
|
|
|
|
- relation.setNum(nextNum);
|
|
|
|
|
- groupsRelationMapper.insert(relation);
|
|
|
|
|
- } else {
|
|
|
|
|
- throw BusinessRuntimeException.getInstance("系统繁忙,请重新兑换");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- return relation;
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|