|
@@ -10,10 +10,13 @@ import cn.hutool.http.HttpStatus;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
import cn.hutool.http.HttpUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
+import com.cyksj.common.constant.Constant;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
|
|
+import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
|
|
|
import com.cyksj.common.util.StringUtil;
|
|
import com.cyksj.common.util.StringUtil;
|
|
|
import com.cyksj.common.util.TicketCodeCommonUtil;
|
|
import com.cyksj.common.util.TicketCodeCommonUtil;
|
|
|
import com.cyksj.enums.GatewayApiCode;
|
|
import com.cyksj.enums.GatewayApiCode;
|
|
|
|
|
+import com.cyksj.mapper.GroupsMapper;
|
|
|
import com.cyksj.mapper.GroupsRelationLoginCodeRecordMapper;
|
|
import com.cyksj.mapper.GroupsRelationLoginCodeRecordMapper;
|
|
|
import com.cyksj.mapper.GroupsRelationMapper;
|
|
import com.cyksj.mapper.GroupsRelationMapper;
|
|
|
import com.cyksj.mapper.UserMapper;
|
|
import com.cyksj.mapper.UserMapper;
|
|
@@ -22,6 +25,7 @@ import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.model.views.*;
|
|
import com.cyksj.model.views.*;
|
|
|
import com.cyksj.redis.RedisService;
|
|
import com.cyksj.redis.RedisService;
|
|
|
import com.cyksj.service.chatgpt.ChatGptAuthService;
|
|
import com.cyksj.service.chatgpt.ChatGptAuthService;
|
|
|
|
|
+import com.cyksj.service.groups.GroupsFuncService;
|
|
|
import com.cyksj.service.mail.CuiQiuMailService;
|
|
import com.cyksj.service.mail.CuiQiuMailService;
|
|
|
import com.cyksj.service.mange.coupon.CouponCommonService;
|
|
import com.cyksj.service.mange.coupon.CouponCommonService;
|
|
|
import com.cyksj.service.relation.GroupRelationFrontService;
|
|
import com.cyksj.service.relation.GroupRelationFrontService;
|
|
@@ -40,6 +44,9 @@ import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
+import static com.cyksj.enums.GatewayApiCode.GROUP_INDEX_ALREADY_BE_USER;
|
|
|
|
|
+import static com.cyksj.enums.GatewayApiCode.GROUP_INDEX_NOT_FIND;
|
|
|
|
|
+
|
|
|
/*
|
|
/*
|
|
|
*项目名: netflix
|
|
*项目名: netflix
|
|
|
*文件名: GroupRelationFrontServiceImpl
|
|
*文件名: GroupRelationFrontServiceImpl
|
|
@@ -60,6 +67,8 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
|
|
|
|
|
|
|
|
private final GroupsRelationMapper groupsRelationMapper;
|
|
private final GroupsRelationMapper groupsRelationMapper;
|
|
|
|
|
|
|
|
|
|
+ private final GroupsMapper groupsMapper;
|
|
|
|
|
+
|
|
|
private final ChatGptAuthService chatGptAuthService;
|
|
private final ChatGptAuthService chatGptAuthService;
|
|
|
|
|
|
|
|
private final RedisService redisService;
|
|
private final RedisService redisService;
|
|
@@ -72,6 +81,10 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
|
|
|
|
|
|
|
|
private final GroupsRelationNetflixService groupsRelationNetflixService;
|
|
private final GroupsRelationNetflixService groupsRelationNetflixService;
|
|
|
|
|
|
|
|
|
|
+ private final GroupsFuncService groupsFuncService;
|
|
|
|
|
+
|
|
|
|
|
+ private static final GlobalThreadPoolTaskExecutor TASK_EXECUTOR = GlobalThreadPoolTaskExecutor.getInstance();
|
|
|
|
|
+
|
|
|
//脆球邮箱后缀
|
|
//脆球邮箱后缀
|
|
|
private final static String CUI_QIU_EMAIL_SUFFIX = "@kindvd.com";
|
|
private final static String CUI_QIU_EMAIL_SUFFIX = "@kindvd.com";
|
|
|
|
|
|
|
@@ -177,15 +190,24 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public GroupsRelation getSimilarExpiredGroupRelation(Long skuId, Integer days, Integer months, List<Long> errorsRelationIds) {
|
|
|
|
|
|
|
+ public GroupsRelation getSimilarExpiredGroupRelation(GoodsDonSku sku, List<Long> errorsRelationIds, String ip) {
|
|
|
|
|
+ Long skuId = sku.getId();
|
|
|
|
|
+ Integer days = sku.getDays();
|
|
|
|
|
+ Integer months = sku.getMonths();
|
|
|
|
|
+ Integer maxNum = sku.getNum();
|
|
|
DateTime expiryTime = null;
|
|
DateTime expiryTime = null;
|
|
|
if (days != null && days > 0) {
|
|
if (days != null && days > 0) {
|
|
|
expiryTime = DateUtil.offsetDay(DateTime.now(), days);
|
|
expiryTime = DateUtil.offsetDay(DateTime.now(), days);
|
|
|
} else {
|
|
} else {
|
|
|
expiryTime = DateUtil.offsetMonth(DateTime.now(), months);
|
|
expiryTime = DateUtil.offsetMonth(DateTime.now(), months);
|
|
|
}
|
|
}
|
|
|
|
|
+ Integer extraNum = 5;
|
|
|
|
|
+ if (sku.getId() == 178l) {
|
|
|
|
|
+ extraNum = 2;
|
|
|
|
|
+ }
|
|
|
|
|
+ maxNum += extraNum;
|
|
|
DateTime minExpiryTime = DateUtil.offsetDay(expiryTime, -5);
|
|
DateTime minExpiryTime = DateUtil.offsetDay(expiryTime, -5);
|
|
|
- Long groupsId = groupsRelationMapper.selectSimilarExpiredRelation(skuId, minExpiryTime);
|
|
|
|
|
|
|
+ Long groupsId = groupsRelationMapper.selectSimilarExpiredRelation(skuId, minExpiryTime, maxNum, ip);
|
|
|
if (groupsId == null) {
|
|
if (groupsId == null) {
|
|
|
log.info("暂无相似过期时间车队");
|
|
log.info("暂无相似过期时间车队");
|
|
|
return null;
|
|
return null;
|
|
@@ -264,6 +286,93 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
|
|
|
return code;
|
|
return code;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public GroupsRelation getRelation(Long payRelationId, Long userId, GoodsDonSku sku, String ip) {
|
|
|
|
|
+ GroupsRelation relation = null;
|
|
|
|
|
+ Integer maxNum = sku.getNum();
|
|
|
|
|
+ if (payRelationId != null && payRelationId > 0) {
|
|
|
|
|
+ relation = groupsRelationMapper.selectById(payRelationId);
|
|
|
|
|
+ if (relation == null) {
|
|
|
|
|
+ throw new BusinessRuntimeException(GROUP_INDEX_NOT_FIND.getCode(), GROUP_INDEX_NOT_FIND.getMsg());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (relation.getUserId() != null && relation.getUserId() > 0L) {
|
|
|
|
|
+ throw new BusinessRuntimeException(GROUP_INDEX_ALREADY_BE_USER.getCode(), GROUP_INDEX_ALREADY_BE_USER.getMsg());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ GroupsTrips groups = null;
|
|
|
|
|
+ //ChatGpt Plus、Midjourney非独立规格 上车先获取硬塞座位 硬塞5个座位
|
|
|
|
|
+ //主账号过期时间25天以外
|
|
|
|
|
+ //23-12-06 MidJourney 不硬塞
|
|
|
|
|
+ if (sku.getNum() > 1 && Constant.AI_goodsIds.get(0) == sku.getGoodsId()) {
|
|
|
|
|
+ Integer extraNum = 5;
|
|
|
|
|
+ if (sku.getId() == 178l || sku.getId() == 423l) {
|
|
|
|
|
+ extraNum = 2;
|
|
|
|
|
+ }
|
|
|
|
|
+ maxNum += extraNum;
|
|
|
|
|
+ DateTime time = DateUtil.offsetDay(DateUtil.beginOfDay(DateTime.now()), 25);
|
|
|
|
|
+ //不塞存在该用户的车队
|
|
|
|
|
+ Long groupsId = groupsRelationMapper.getOutSideGroupsTripsRelationByGoodsId(sku.getId(), time, extraNum, userId, sku.getNum(), maxNum);
|
|
|
|
|
+ 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("系统繁忙,请重试...");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ groups = groupsMapper.selectById(groupsId);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (groups == null) {
|
|
|
|
|
+ //寻找差不多过期时间规格的车位
|
|
|
|
|
+ relation = getSimilarExpiredGroupRelation(sku, null, ip);
|
|
|
|
|
+ if (relation == null) {
|
|
|
|
|
+ //TODO 如果没指定座位,等待逻辑确认
|
|
|
|
|
+ groups = groupsMapper.selectTicketGroups(sku.getId(), GroupsTrips.Status.validity, maxNum, ip);
|
|
|
|
|
+
|
|
|
|
|
+ if (groups == null) {
|
|
|
|
|
+ //待发车
|
|
|
|
|
+ groups = groupsMapper.selectTicketGroups(sku.getId(), GroupsTrips.Status.waiting, maxNum, ip);
|
|
|
|
|
+ }
|
|
|
|
|
+ //新增空车队
|
|
|
|
|
+ if (groups == null) {
|
|
|
|
|
+ relation = groupsFuncService.createNewGroupsTrips(sku);
|
|
|
|
|
+ }
|
|
|
|
|
+ //获取车位
|
|
|
|
|
+ if (relation == null) {
|
|
|
|
|
+ //寻找快满编车队进行占座
|
|
|
|
|
+ relation = groupsRelationMapper.selectRandomOneRelationByGroupsId(groups.getId());
|
|
|
|
|
+ if (relation == null) {
|
|
|
|
|
+ Long groupsId = groups.getId();
|
|
|
|
|
+ TASK_EXECUTOR.execute(() -> groupsMapper.updateAvailableNum(groupsId));
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("系统繁忙,请重试...");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (groups == null) {
|
|
|
|
|
+ groups = groupsMapper.selectById(relation.getGroupsId());
|
|
|
|
|
+ }
|
|
|
|
|
+ //车队目前可用停车数
|
|
|
|
|
+ relation.setGroupsAvailParkingNum(groups.getAvailableParkingNum());
|
|
|
|
|
+ relation.setMaxNum(maxNum);
|
|
|
|
|
+ }
|
|
|
|
|
+ return relation;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
public String getDifferentGoodsCode(Long goodsId, String body, Integer type, Boolean sync) {
|
|
public String getDifferentGoodsCode(Long goodsId, String body, Integer type, Boolean sync) {
|
|
|
String code = null;
|
|
String code = null;
|