|
|
@@ -6,15 +6,23 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.cyksj.common.annotation.Log;
|
|
|
import com.cyksj.common.annotation.NoSubmit;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
+import com.cyksj.dto.RedisKey;
|
|
|
import com.cyksj.dto.Result;
|
|
|
import com.cyksj.enums.BusinessType;
|
|
|
import com.cyksj.enums.GatewayResponse;
|
|
|
+import com.cyksj.mapper.GoodsDonSkuMapper;
|
|
|
+import com.cyksj.mapper.GroupsMapper;
|
|
|
import com.cyksj.mapper.GroupsRelationMapper;
|
|
|
+import com.cyksj.mapper.TransGroupsRecordMapper;
|
|
|
import com.cyksj.model.entity.Account;
|
|
|
+import com.cyksj.model.entity.GoodsDonSku;
|
|
|
+import com.cyksj.model.entity.GroupsRelation;
|
|
|
import com.cyksj.model.entity.GroupsTrips;
|
|
|
+import com.cyksj.model.manage.views.AccountView;
|
|
|
import com.cyksj.model.request.AccountGroupsReq;
|
|
|
import com.cyksj.model.views.GoodsDonSkuView;
|
|
|
import com.cyksj.model.views.GroupsTripsWaitingView;
|
|
|
+import com.cyksj.redis.RedisService;
|
|
|
import com.cyksj.service.mange.CmsAccountService;
|
|
|
import com.cyksj.service.mange.CmsGroupService;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
@@ -25,6 +33,7 @@ import com.ejlchina.searcher.util.MapUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
@@ -156,4 +165,158 @@ public class CmsGroupController {
|
|
|
groupService.setAccount(groupsTrips);
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult("车队配置新账号成功");
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * chatGPT车位数打乱 并配置空车队
|
|
|
+ */
|
|
|
+ private final GroupsMapper groupsMapper;
|
|
|
+
|
|
|
+ private final GroupsRelationMapper groupsRelationMapper;
|
|
|
+
|
|
|
+ private final GoodsDonSkuMapper goodsDonSkuMapper;
|
|
|
+
|
|
|
+ private final RedisService redisService;
|
|
|
+
|
|
|
+ private final TransGroupsRecordMapper transGroupsRecordMapper;
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @GetMapping("/sync")
|
|
|
+ public Result<String> updateTrips() {
|
|
|
+ List<GroupsRelation> groupsRelations = relationMapper.gptList();
|
|
|
+// groupsRelations.forEach(relation->{
|
|
|
+// Long relationId = relation.getId();
|
|
|
+// Long skuId = relation.getSkuId();
|
|
|
+// Long groupsId = relation.getGroupsId();
|
|
|
+// Long userId = relation.getUserId();
|
|
|
+// Date startTime = relation.getStartTime();
|
|
|
+// Date expiryTime = relation.getExpiryTime();
|
|
|
+//
|
|
|
+// //分配
|
|
|
+// LambdaQueryWrapper<GroupsTrips> queryWrapper = Wrappers.lambdaQuery(GroupsTrips.class).eq(GroupsTrips::getSkuId, skuId).gt(GroupsTrips::getAvailableNum, 0).last("limit 1").orderByAsc(GroupsTrips::getAvailableNum);
|
|
|
+// queryWrapper.isNull(GroupsTrips::getAccountId);
|
|
|
+// GroupsTrips groups = groupsMapper.selectOne(queryWrapper);
|
|
|
+//
|
|
|
+// if (groups == null) {
|
|
|
+// GoodsDonSku sku = goodsDonSkuMapper.selectById(skuId);
|
|
|
+// relation = createNewGroupsTrips(sku);
|
|
|
+// } 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) {
|
|
|
+// log.error("用户:{}未分配车票", userId);
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// //锁定座位
|
|
|
+// try {
|
|
|
+// setRelation(relation.getId(), userId);
|
|
|
+// } catch (Exception e) {
|
|
|
+// log.error("用户:{}未分配车票", userId);
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// relation.setUserId(userId);
|
|
|
+// relation.setStatus(GroupsRelation.Status.validity);
|
|
|
+// relation.setStartTime(startTime);
|
|
|
+// Date newETime = expiryTime;
|
|
|
+// relation.setExpiryTime(newETime);
|
|
|
+// groupsRelationMapper.updateById(relation);
|
|
|
+//
|
|
|
+// TransGroupsRecord record = new TransGroupsRecord();
|
|
|
+// record.setUserId(userId);
|
|
|
+// record.setGroupsId(groupsId);
|
|
|
+// record.setRelationId(relationId);
|
|
|
+// Long newRelationId = relation.getId();
|
|
|
+// record.setNewRelationId(newRelationId);
|
|
|
+// record.setNSTime(startTime);
|
|
|
+// record.setNETime(newETime);
|
|
|
+// record.setSkuId(skuId);
|
|
|
+//
|
|
|
+// record.setSTime(startTime);
|
|
|
+// record.setETime(expiryTime);
|
|
|
+//
|
|
|
+// transGroupsRecordMapper.insert(record);
|
|
|
+//
|
|
|
+// GroupsRelation pastRelain = groupsRelationMapper.selectById(relationId);
|
|
|
+// Integer sucess = groupsRelationMapper.updateExpiryTime(pastRelain, expiryTime);
|
|
|
+// if (sucess == 1) {
|
|
|
+// int count = groupsMapper.incrAvailableNum(relation.getGroupsId());
|
|
|
+// if (count == 0) {
|
|
|
+// log.error("续费更换车位异常 groupId:{}", relation.getGroupsId());
|
|
|
+// }
|
|
|
+// }
|
|
|
+// });
|
|
|
+
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增空车队
|
|
|
+ */
|
|
|
+ private GroupsRelation createNewGroupsTrips(GoodsDonSku sku) {
|
|
|
+ //新增车次
|
|
|
+ GroupsTrips groups = new GroupsTrips();
|
|
|
+ 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);
|
|
|
+ GroupsRelation relation = new GroupsRelation();
|
|
|
+ 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 void setRelation(Long relationId, Long userId) {
|
|
|
+ Object value = redisService.get(RedisKey.GROUPS_RELATION_NUM_KEY + relationId);
|
|
|
+ if (value != null) {
|
|
|
+ GroupsRelation relation = groupsRelationMapper.selectById(relationId);
|
|
|
+ if (relation != null && relation.getUserId() == 0l) {
|
|
|
+ redisService.del(RedisKey.GROUPS_RELATION_NUM_KEY + relationId);
|
|
|
+ }
|
|
|
+ if (relation != null && relation.getUserId() != 0l) {
|
|
|
+ log.info("=====>用户:{}获取了已有人座位:{}", userId, relationId);
|
|
|
+ throw new BusinessRuntimeException("客官手慢啦,该座位已经有人啦!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!redisService.setNx(RedisKey.GROUPS_RELATION_NUM_KEY + relationId, userId, 60 * 5L)) {
|
|
|
+ log.info("=====>用户:{}未抢到座位:{}", userId, relationId);
|
|
|
+ throw new BusinessRuntimeException("客官手慢啦,该座位已经有人啦!");
|
|
|
+ }
|
|
|
+ GroupsRelation relation = groupsRelationMapper.selectById(relationId);
|
|
|
+ int count = groupsMapper.decrAvailableNum(relation.getGroupsId());
|
|
|
+ if (count == 0) {
|
|
|
+ log.error("车位异常 groupId:{}", relation.getGroupsId());
|
|
|
+ throw new BusinessRuntimeException("车位异常");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|