|
|
@@ -0,0 +1,144 @@
|
|
|
+package com.yhlxj.service.groups.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.cyksj.common.constant.Constant;
|
|
|
+import com.ejlchina.searcher.BeanSearcher;
|
|
|
+import com.ejlchina.searcher.util.MapUtils;
|
|
|
+import com.yhlxj.dao.mapper.AccountMapper;
|
|
|
+import com.yhlxj.dao.mapper.GroupsMapper;
|
|
|
+import com.yhlxj.dao.mapper.GroupsRelationMapper;
|
|
|
+import com.yhlxj.dao.model.entity.Account;
|
|
|
+import com.yhlxj.dao.model.entity.GoodsDonSku;
|
|
|
+import com.yhlxj.dao.model.entity.GroupsRelation;
|
|
|
+import com.yhlxj.dao.model.entity.GroupsTrips;
|
|
|
+import com.yhlxj.dao.model.view.AccountView;
|
|
|
+import com.yhlxj.service.groups.GroupsFuncService;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.dao.DuplicateKeyException;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 项目名: GroupsFuncServiceImpl
|
|
|
+ * 文件名: A
|
|
|
+ * 创建者: JavaZou
|
|
|
+ * 创建时间:2025/6/5 18:06
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Slf4j
|
|
|
+public class GroupsFuncServiceImpl implements GroupsFuncService {
|
|
|
+ private final BeanSearcher beanSearcher;
|
|
|
+
|
|
|
+ private final GroupsMapper groupsMapper;
|
|
|
+
|
|
|
+ private final GroupsRelationMapper groupsRelationMapper;
|
|
|
+
|
|
|
+ private final AccountMapper accountMapper;
|
|
|
+ @Override
|
|
|
+ public 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("等待设置账号");
|
|
|
+ }
|
|
|
+ //限制每天新车队前3天 停车数量
|
|
|
+ //10人镜像月付GPT
|
|
|
+ Integer availableParkingNum = 0;
|
|
|
+ if (sku.getId() == 161l || sku.getId() == 422l) {
|
|
|
+ availableParkingNum = 20;
|
|
|
+ }
|
|
|
+ //4人镜像月付GPT
|
|
|
+ if (sku.getId() == 178l || sku.getId() == 423l) {
|
|
|
+ availableParkingNum = 6;
|
|
|
+ }
|
|
|
+ //如果是镜像车队
|
|
|
+ setMirrorUnifyAccount(sku, groups);
|
|
|
+ groups.setAvailableParkingNum(availableParkingNum);
|
|
|
+
|
|
|
+ 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 setMirrorUnifyAccount(GoodsDonSku sku, GroupsTrips groups) {
|
|
|
+ //如果是GPT、MJ镜像车队
|
|
|
+ //设置唯一账号
|
|
|
+ Long goodsId = sku.getGoodsId();
|
|
|
+ Boolean isMirror = sku.getIsMirror();
|
|
|
+ Boolean isCar = sku.getIsCar();
|
|
|
+ String account = null;
|
|
|
+ if ((goodsId == 88 && isMirror) || (goodsId == 87 && isMirror) || (goodsId == 18 && isCar) || (goodsId == 26 && isMirror) || (goodsId == 75 && isCar)) {
|
|
|
+ if (goodsId == 18) {
|
|
|
+ account = Constant.GPT_CAR_ONLY_ACCOUNT;
|
|
|
+ }
|
|
|
+ if (goodsId == 26) {
|
|
|
+ account = Constant.MJ_MIRROR_ONLY_ACCOUNT;
|
|
|
+ }
|
|
|
+ if (goodsId == 75) {
|
|
|
+ account = Constant.CLAUDE_MIRROR_ONLY_ACCOUNT;
|
|
|
+ }
|
|
|
+ if (goodsId == 87) {
|
|
|
+ account = Constant.LUMA_MIRROR_ONLY_ACCOUNT;
|
|
|
+ }
|
|
|
+ if (goodsId == 88) {
|
|
|
+ account = Constant.GROK_MIRROR_ONLY_ACCOUNT;
|
|
|
+ }
|
|
|
+ AccountView accountView = beanSearcher.searchFirst(AccountView.class, MapUtils.builder()
|
|
|
+ .field(AccountView::getGoodsId, goodsId)
|
|
|
+ .field(AccountView::getAccount, account).
|
|
|
+ onlySelect(AccountView::getId).build());
|
|
|
+ Long accountId;
|
|
|
+ if (accountView == null) {
|
|
|
+ try {
|
|
|
+ Account insert = new Account();
|
|
|
+ insert.setAccount(account);
|
|
|
+ insert.setPassword(account);
|
|
|
+ insert.setGoodsId(goodsId);
|
|
|
+ accountMapper.insert(insert);
|
|
|
+ accountId = insert.getId();
|
|
|
+ } catch (DuplicateKeyException e) {
|
|
|
+ accountId = accountMapper.selectOne(Wrappers.lambdaQuery(Account.class)
|
|
|
+ .eq(Account::getGoodsId, goodsId)
|
|
|
+ .eq(Account::getAccount, account)
|
|
|
+ .last("limit 1")).getId();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ accountId = accountView.getId();
|
|
|
+ }
|
|
|
+ groups.setAccountId(accountId);
|
|
|
+ groups.setStatus(GroupsTrips.Status.validity);
|
|
|
+ groups.setRemark("已设置镜像车队唯一账号");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|