zoujiajian 2 年 前
コミット
a74e4694e4

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

@@ -39,4 +39,6 @@ public interface GroupsMapper extends BaseMapper<GroupsTrips> {
 	Long selectMidJourneySameSpecItemGroups(@Param("groupsId") Long groupsId, @Param("skuId") Long skuId, @Param("expiryTime") Date expiryTime);
 
 	Integer countExpiredNum(Long accountId);
+
+	GroupsTrips selectTicketGroups(@Param("skuId") Long skuId, @Param("status") GroupsTrips.Status status, @Param("maxNum") Integer maxNum, @Param("ip") String ip);
 }

+ 0 - 5
netflix-dao/src/main/resources/mapper/GroupRelationMapper.xml

@@ -114,11 +114,6 @@
         where groups_id = #{groupsId}
           and user_id = 0
           and status = 'none'
-        <if test="ip != null">
-            and not exists (select 1 from (select id, user_id from groups_relation gnr where gnr.groups_id = groups_id and gnr.user_id != 0) gr inner join
-            order_don o on o.user_id = gr.user_id and o.relation_id = gr.id
-            inner join order_don_location_relate ocr on ocr.order_id = o.id where ocr.ip = #{ip} limit 1)
-        </if>
         order by rand() limit 1
     </select>
 

+ 20 - 0
netflix-dao/src/main/resources/mapper/GroupsMapper.xml

@@ -78,4 +78,24 @@
           and deleted is true
           and source = 'self'
     </select>
+
+    <select id="selectTicketGroups" resultType="com.cyksj.model.entity.GroupsTrips">
+        select *
+        from groups_trips gt
+        where gt.sku_id = #{skuId}
+        and gt.status = #{status}
+        and gt.available_num > 0
+        <if test="ip != null">
+            and not exists (select 1 from (select id, user_id from groups_relation gnr where gnr.groups_id = groups_id
+            and gnr.user_id != 0) gr inner join
+            order_don o on o.user_id = gr.user_id and o.relation_id = gr.id
+            inner join order_don_location_relate ocr on ocr.order_id = o.id where ocr.ip = #{ip} limit 1)
+        </if>
+        and (available_parking_num = 0 or available_parking_num > (select count(*)
+        from groups_relation gr
+        where gr.groups_id = groups_trips.id
+        and gr.user_id != 0 and gr.num &lt;= #{maxNum}))
+        order by available_num asc
+        limit 1
+    </select>
 </mapper>

+ 3 - 12
netflix-service/src/main/java/com/cyksj/service/relation/impl/GroupRelationFrontServiceImpl.java

@@ -400,20 +400,11 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 				relation = getSimilarExpiredGroupRelation(sku, null, ip);
 				if (relation == null) {
 					//TODO 如果没指定座位,等待逻辑确认
-					groups = groupsMapper.selectOne(Wrappers.lambdaQuery(GroupsTrips.class)
-							.eq(GroupsTrips::getSkuId, sku.getId())
-							.gt(GroupsTrips::getAvailableNum, 0).last("limit 1")
-							.apply(String.format("(available_parking_num = 0 or available_parking_num > (select count(*) from groups_relation gr where gr.groups_id = groups_trips.id and gr.user_id != 0 and gr.num <= %s))", maxNum))
-							.eq(GroupsTrips::getStatus, GroupsTrips.Status.validity)
-							.orderByAsc(GroupsTrips::getAvailableNum));
+					groups = groupsMapper.selectTicketGroups(sku.getId(), GroupsTrips.Status.validity, maxNum, ip);
+
 					if (groups == 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)
-								.apply(String.format("(available_parking_num = 0 or available_parking_num > (select count(*) from groups_relation gr where gr.groups_id = groups_trips.id and gr.user_id != 0 and gr.num <= %s))", maxNum))
-								.orderByAsc(GroupsTrips::getAvailableNum));
+						groups = groupsMapper.selectTicketGroups(sku.getId(), GroupsTrips.Status.waiting, maxNum, ip);
 					}
 					//新增空车队
 					if (groups == null) {