Просмотр исходного кода

fix 寻找车队的车位类似过期时间优先上车

zoujiajian 3 лет назад
Родитель
Сommit
337920ab00

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

@@ -1,5 +1,6 @@
 package com.cyksj.mapper;
 
+import cn.hutool.core.date.DateTime;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.cyksj.model.entity.GroupsRelation;
 import org.apache.ibatis.annotations.Param;
@@ -22,4 +23,6 @@ public interface GroupsRelationMapper extends BaseMapper<GroupsRelation> {
 
 	@Update("update groups_relation set customer_service = null where id = #{id}")
 	void updateCustomerService(Long id);
+
+	Long selectSimilarExpiredRelation(@Param("skuId") Long skuId, @Param("minExpiryTime") DateTime minExpiryTime);
 }

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

@@ -35,4 +35,20 @@
     <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>
+
+    <select id="selectSimilarExpiredRelation" resultType="java.lang.Long">
+        select s.id
+        from (select gt.id, min(gr.expiry_time) minExpiryTime
+              from `groups_trips` gt
+                       left join `groups_relation` gr on gr.groups_id = gt.id
+              where gt.sku_id = #{skuId}
+                and gt.available_num > 0
+                and gt.status = 'validity'
+                and gr.status = 'validity'
+                and gr.user_id != 0
+              and gr.expiry_time is not null
+              group by gr.groups_id) s
+        where s.minExpiryTime >= #{minExpiryTime}
+        order by minExpiryTime limit 1
+    </select>
 </mapper>

+ 36 - 16
netflix-service/src/main/java/com/cyksj/service/order/impl/OrderDonServiceImpl.java

@@ -223,22 +223,26 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 					}
 
 				} else {
-					//TODO 如果没指定座位,等待逻辑确认
-					GroupsTrips groups = groupsMapper.selectOne(Wrappers.lambdaQuery(GroupsTrips.class).eq(GroupsTrips::getSkuId, payRequest.getSkuId()).gt(GroupsTrips::getAvailableNum, 0).last("limit 1").orderByAsc(GroupsTrips::getAvailableNum));
-					if (groups == null) {
-						relation = createNewGroupsTrips(sku, true);
-						isNew = true;
-					} 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) {
-							throw new BusinessRuntimeException(GROUP_INDEX_NOT_FIND.getCode(), GROUP_INDEX_NOT_FIND.getMsg());
+					//寻找差不多过期时间规格的车位
+					relation = getSimilarExpiredGroupRelation(sku.getId(), sku.getMonths());
+					if (relation == null) {
+						//TODO 如果没指定座位,等待逻辑确认
+						GroupsTrips groups = groupsMapper.selectOne(Wrappers.lambdaQuery(GroupsTrips.class).eq(GroupsTrips::getSkuId, payRequest.getSkuId()).gt(GroupsTrips::getAvailableNum, 0).last("limit 1").orderByAsc(GroupsTrips::getAvailableNum));
+						if (groups == null) {
+							relation = createNewGroupsTrips(sku, true);
+							isNew = true;
+						} 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) {
+								throw new BusinessRuntimeException(GROUP_INDEX_NOT_FIND.getCode(), GROUP_INDEX_NOT_FIND.getMsg());
+							}
 						}
 					}
 				}
@@ -350,6 +354,22 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 		return orderDon;
 	}
 
+	private GroupsRelation getSimilarExpiredGroupRelation(Long skuId, Integer months) {
+		DateTime expiryTime = DateUtil.offsetMonth(DateTime.now(), months);
+		DateTime minExpiryTime = DateUtil.offsetDay(expiryTime, -5);
+		Long groupsId = groupsRelationMapper.selectSimilarExpiredRelation(skuId, minExpiryTime);
+		if (groupsId == null) {
+			return null;
+		}
+		GroupsRelation relation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
+				.eq(GroupsRelation::getGroupsId, groupsId)
+				.eq(GroupsRelation::getStatus, GroupsRelation.Status.none)
+				.eq(GroupsRelation::getUserId, 0)
+				.orderByAsc(GroupsRelation::getNum)
+				.last("limit 1"));
+		return relation;
+	}
+
 	@Override
 	public H5JsPayParams pay(Long orderId, String tradeType) throws Exception {
 		log.info("调起微信支付[start] orderId:{}", orderId);