zoujiajian 3 anos atrás
pai
commit
482f71ff01

+ 2 - 0
netflix-dao/src/main/java/com/cyksj/mapper/GroupsRelationMapper.java

@@ -30,4 +30,6 @@ public interface GroupsRelationMapper extends BaseMapper<GroupsRelation> {
 	List<GroupsRelationView> selectRelationByGoodsId(@Param("goodsId") Long goodsId, @Param("userId") Long userId);
 
 	GroupsRelationView getGroupRelationViewByUserIdAndRelationId(@Param("userId") Long userId, @Param("relationId") Long relationId);
+
+	List<GroupsRelation> gptList();
 }

+ 14 - 0
netflix-dao/src/main/java/com/cyksj/mapper/TransGroupsRecordMapper.java

@@ -0,0 +1,14 @@
+package com.cyksj.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.cyksj.model.entity.TransGroupsRecord;
+
+/*
+ *项目名: netflix
+ *文件名: TransGroupsRecordMapper
+ *创建者: JavaZou
+ *创建时间:2023/5/6 16:52
+ */
+public interface TransGroupsRecordMapper
+		extends BaseMapper<TransGroupsRecord> {
+}

+ 3 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/GroupsRelation.java

@@ -20,6 +20,9 @@ public class GroupsRelation extends BaseEntity {
 
     private Long userId;
 
+    @TableField(exist = false)
+    private Long skuId;
+
     private Date startTime;
 
     private Date expiryTime;

+ 35 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/TransGroupsRecord.java

@@ -0,0 +1,35 @@
+package com.cyksj.model.entity;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.Date;
+
+/*
+ *项目名: netflix
+ *文件名: TransGroupsRecord
+ *创建者: JavaZou
+ *创建时间:2023/5/6 16:01
+ */
+@Getter
+@Setter
+public class TransGroupsRecord extends BaseEntity{
+
+	private Long userId;
+
+	private Long skuId;
+
+	private Long relationId;
+
+	private Date sTime;
+
+	private Date eTime;
+
+	private Long newRelationId;
+
+	private Date nSTime;
+
+	private Date nETime;
+
+	private Long groupsId;
+}

+ 120 - 4
netflix-dao/src/main/resources/mapper/GroupRelationMapper.xml

@@ -21,8 +21,8 @@
     <select id="getAccountIdsByUserIdOrNickNameOrSubmitAccount" resultType="java.lang.Long">
         select gr.groups_id
         from groups_relation gr,
-             `user` u
-                where  gr.user_id = u.id
+        `user` u
+        where gr.user_id = u.id
         <if test="nickName != null and nickName != ''">
             and u.nickname like '%${nickName}%'
         </if>
@@ -36,7 +36,10 @@
     </select>
 
     <select id="getGroupTripsSkuIdByRelationId" resultType="java.lang.Long">
-        select gt.sku_id from `groups_trips` gt left join `groups_relation` gr on gr.groups_id = gt.id where gr.id = #{relationId} limit 1
+        select gt.sku_id
+        from `groups_trips` gt
+                 left join `groups_relation` gr on gr.groups_id = gt.id
+        where gr.id = #{relationId} limit 1
     </select>
 
     <select id="selectSimilarExpiredRelation" resultType="java.lang.Long">
@@ -77,6 +80,119 @@
                  left join groups_trips gt on gt.id = gr.groups_id
                  left join account a on a.id = gt.account_id
                  left join goods_don g on g.id = a.goods_id
-        where gr.id = #{relationId} and gr.user_id = #{userId}
+        where gr.id = #{relationId}
+          and gr.user_id = #{userId}
+    </select>
+
+    <select id="gptList" resultType="com.cyksj.model.entity.GroupsRelation">
+        select gr.id, gt.sku_id, gr.user_id, groups_id, gr.start_time, gr.expiry_time
+        from `groups_trips` gt
+                 left join groups_relation gr
+                           on gr.groups_id = gt.id
+        where sku_id in (select id from goods_don_sku where goods_id = 18)
+          and gr.expiry_time is not null
+          and gr.start_time between '2023-05-06' and '2023-05-07'
+          and gr.expiry_time > '2023-05-15 23:59:59'
+          and gr.user_id = 152982
+          and gr.status = 'validity'
+          and gr.created_time &lt; '2023-05-06 15:30:00'
+          and gt.id not in (select gt.id
+                            from `groups_trips` gt
+                            where account_id in (select id
+                                                 from `account`
+                                                 where account in ('aiwysu6t@faker.icu',
+                                                                   'avbcbr6r@faker.icu',
+                                                                   'agunbc6e@faker.icu',
+                                                                   'acnrth6w@faker.icu',
+                                                                   'athizx6q@faker.icu',
+                                                                   'atvkft6f@faker.icu',
+                                                                   'afhowh69@faker.icu',
+                                                                   'ayfgph68@faker.icu',
+                                                                   'adpiyz67@faker.icu',
+                                                                   'asevqh66@faker.icu',
+                                                                   'aerzxm65@faker.icu',
+                                                                   'azjxtk64@faker.icu',
+                                                                   'akcytx63@faker.icu',
+                                                                   'aglogk62@faker.icu',
+                                                                   'acptec61@faker.icu',
+                                                                   'abztab60@faker.icu',
+                                                                   'ahvwuy5n@faker.icu',
+                                                                   'atqzuh5b@faker.icu',
+                                                                   'apjajk5x@faker.icu',
+                                                                   'auylas5z@faker.icu',
+                                                                   'atwzkb5l@faker.icu',
+                                                                   'agziui5k@faker.icu',
+                                                                   'aeykcx5j@faker.icu',
+                                                                   'ayetlj5h@faker.icu',
+                                                                   'adtpsa5g@faker.icu',
+                                                                   'ajivax5o@faker.icu',
+                                                                   'aitass5d@faker.icu',
+                                                                   'aldkwy5s@faker.icu',
+                                                                   'aapvtw5a@faker.icu',
+                                                                   'appkoc5p@faker.icu',
+                                                                   'ayvjol5i@faker.icu',
+                                                                   'aykley5u@faker.icu',
+                                                                   'aouhnu5y@faker.icu',
+                                                                   'admgan5t@faker.icu',
+                                                                   'afwwqv5w@faker.icu',
+                                                                   'aocywb5q@faker.icu',
+                                                                   'akeohi1k@faker.icu',
+                                                                   'auigda6j@yinhelx.com',
+                                                                   'fjj242113@yhlx.vip',
+                                                                   'abyqmw62@yinhelx.com',
+                                                                   'vitverbschafalin@mail.com',
+                                                                   'aowrre50@yinhelx.com',
+                                                                   'avdjet54@yinhelx.com',
+                                                                   'arnush53@yinhelx.com',
+                                                                   'acypus52@yinhelx.com',
+                                                                   'ameusj4c@yinhelx.com',
+                                                                   'ashutw4x@yinhelx.com',
+                                                                   'awuvwc4l@yinhelx.com',
+                                                                   'aiqqzb4s@yinhelx.com',
+                                                                   'aiihfe4i@yinhelx.com',
+                                                                   'linkturfijohnnu@mail.com',
+                                                                   'abecxz4r@yinhelx.com',
+                                                                   'atzqljxv@yinhelx.com',
+                                                                   'onerqgdo7s@yinhelx.com',
+                                                                   'amcaln3i@yinhelx.com',
+                                                                   'fjj523282@yhlx.vip',
+                                                                   'onefwzeo62@yinhelx.com',
+                                                                   'onemxegx64@yinhelx.com',
+                                                                   'oneofixk65@yinhelx.com',
+                                                                   'oneoftol66@yinhelx.com',
+                                                                   'onexwfdu68@yinhelx.com',
+                                                                   'oneoscqn69@yinhelx.com',
+                                                                   'oneguwdu6q@yinhelx.com',
+                                                                   'oneotsls6w@yinhelx.com',
+                                                                   'oneydncd6e@yinhelx.com',
+                                                                   'onererzn61@yinhelx.com',
+                                                                   'onefbqto60@yinhelx.com',
+                                                                   'oneyrcni@yinhelx.com',
+                                                                   'oneaudal@yinhelx.com',
+                                                                   'oneykkyi@yinhelx.com',
+                                                                   'onervusz@yinhelx.com',
+                                                                   'onenjitr@yinhelx.com',
+                                                                   'onevdvpg@yinhelx.com',
+                                                                   'aatxoh1t@faker.icu',
+                                                                   'fjj531020@yhlx.vip',
+                                                                   'fjj232184@yhlx.vip',
+                                                                   'fjj783866@yhlx.vip',
+                                                                   'oneyrljd9k@yinhelx.com',
+                                                                   'aercxg1p@faker.icu',
+                                                                   'azpfqo14@faker.icu',
+                                                                   'amdxyy13@faker.icu',
+                                                                   'azjlpc@faker.icu',
+                                                                   'adssml1d@faker.icu',
+                                                                   'onenjkocfc@yinhelx.com',
+                                                                   'oneugclafv@yinhelx.com',
+                                                                   '2714868409@qq.com',
+                                                                   'yinhe8856@gmail.com',
+                                                                   'cccjx1234@gmail.com',
+                                                                   'fjj100356@yhlx.vip',
+                                                                   'fjj854624@yhlx.vip',
+                                                                   'fjj175785@yhlx.vip',
+                                                                   'fjj755103@yhlx.vip')
+                                                   and goods_id = 18))
+        order by gt.sku_id, groups_id, expiry_time
     </select>
 </mapper>

+ 163 - 0
netflix-web/src/main/java/com/cyksj/web/controller/manage/group/CmsGroupController.java

@@ -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("车位异常");
+        }
+    }
 }