Pārlūkot izejas kodu

fix 额外硬塞车位

zoujiajian 2 gadi atpakaļ
vecāks
revīzija
280bd502ed

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

@@ -52,7 +52,7 @@ public interface GroupsRelationMapper extends BaseMapper<GroupsRelation> {
 
 	Page<UserRecommendGoodsFrontView> getRecommendGoodsViews(@Param("page") Page<UserRecommendGoodsFrontView> page, @Param("list") List<Long> filter_goods_id, @Param("isPayNf") Boolean isPayNf);
 
-	Long getOutSideGroupsTripsRelationByGoodsId(@Param("skuId") Long skuId, @Param("beginOfDay") DateTime beginOfDay, @Param("extraNum") Integer extraNum, @Param("userId") Long userId);
+	Long getOutSideGroupsTripsRelationByGoodsId(@Param("skuId") Long skuId, @Param("beginOfDay") DateTime beginOfDay, @Param("extraNum") Integer extraNum, @Param("userId") Long userId, @Param("skuNum") Integer skuNum);
 
 	Integer selectAvailableRelation(@Param("skuId") Long skuId, @Param("skuNum") Integer skuNum);
 

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

@@ -223,7 +223,7 @@
           and a.expiry_time >= #{beginOfDay}
           and (select count(*)
                from groups_relation gr
-               where gr.status = 'outside'
+               where gr.num > #{skuNum}
                  and gr.groups_id = gt.id
                  and gr.user_id
             != 0)

+ 1 - 1
netflix-service/src/main/java/com/cyksj/redis/RedisService.java

@@ -651,7 +651,7 @@ public class RedisService {
         TASK_RECEIVED_KEY("task_received_key:%s:%s", "领取任务奖励key", 10l),
         CORP_GROUP_CHAT_LIST("corp_group_chat_list:%s", "企业微信客户群列表", 60 * 60 * 24),
         PLUS_GOODS_ADDRESS_KEY("plus_goods_address_key:", "优惠加购实物地址key", 10 * 60l),
-        GROUPS_TRIPS_OUTSIDE_RELATION("groups_trips_outside_relation:key", "额外车位", 30l),
+        GROUPS_TRIPS_OUTSIDE_RELATION("groups_trips_outside_relation:key:%s:%s", "额外车位", 30l),
         DISTRIBUTE_RULE_TIME_KEY("DISTRIBUTE_RULE_TIME_KEY", "渠道规格记录时间key", 5 * 60L),
 
         //巨量广告平台临时存储 callback

+ 11 - 8
netflix-service/src/main/java/com/cyksj/service/exchange/impl/ExchangeCodeServiceImpl.java

@@ -528,7 +528,7 @@ public class ExchangeCodeServiceImpl extends ServiceImpl<ExchangeCodeMapper, Exc
 		GroupsRelation relation = null;
 		if (sku.getNum() > 1 && Constant.AI_goodsIds.contains(sku.getGoodsId())) {
 			DateTime tenExpiry = DateUtil.offsetDay(DateUtil.beginOfDay(DateTime.now()), 10);
-			Long groupsId = groupsRelationMapper.getOutSideGroupsTripsRelationByGoodsId(sku.getId(), tenExpiry, 5, userId);
+			Long groupsId = groupsRelationMapper.getOutSideGroupsTripsRelationByGoodsId(sku.getId(), tenExpiry, 5, userId, sku.getNum());
 			if (groupsId != null) {
 				relation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
 						.eq(GroupsRelation::getGroupsId, groupsId)
@@ -536,14 +536,17 @@ public class ExchangeCodeServiceImpl extends ServiceImpl<ExchangeCodeMapper, Exc
 						.eq(GroupsRelation::getStatus, GroupsRelation.Status.outside)
 						.last("limit 1"));
 				if (relation == null) {
-					if (!redisService.setNx(RedisService.key.GROUPS_TRIPS_OUTSIDE_RELATION.getName() + groupsId, groupsId, RedisService.key.GROUPS_TRIPS_OUTSIDE_RELATION.getTimeout())) {
-						relation = new GroupsRelation();
-						relation.setStatus(GroupsRelation.Status.outside);
-						relation.setUserId(userId);
-						relation.setGroupsId(groupsId);
-						GroupsRelation maxNumRelation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class).eq(GroupsRelation::getGroupsId, groupsId).orderByDesc(GroupsRelation::getNum).last("limit 1"));
-						relation.setNum(maxNumRelation.getNum() + 1);
+					relation = new GroupsRelation();
+					relation.setStatus(GroupsRelation.Status.outside);
+					relation.setUserId(userId);
+					relation.setGroupsId(groupsId);
+					GroupsRelation maxNumRelation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class).eq(GroupsRelation::getGroupsId, groupsId).orderByDesc(GroupsRelation::getNum).last("limit 1"));
+					Integer nextNum = maxNumRelation.getNum() + 1;
+					if (redisService.setNx(RedisService.key.GROUPS_TRIPS_OUTSIDE_RELATION.getNameFormat(groupsId, nextNum), nextNum, RedisService.key.GROUPS_TRIPS_OUTSIDE_RELATION.getTimeout())) {
+						relation.setNum(nextNum);
 						groupsRelationMapper.insert(relation);
+					} else {
+						throw BusinessRuntimeException.getInstance("系统繁忙,请重新兑换");
 					}
 				}
 			}

+ 1 - 1
netflix-service/src/main/java/com/cyksj/service/mange/group/CmsGroupServiceImpl.java

@@ -376,7 +376,7 @@ public class CmsGroupServiceImpl extends ServiceImpl<GroupsMapper,GroupsTrips> i
         if (Constant.AI_goodsIds.contains(sku.getGoodsId()) && sku.getNum() > 1) {
             Integer extraNum = Constant.AI_EXTRACT_NUM;
             Integer maxNum = skuNum + extraNum;
-            DateTime tenExpiry = DateUtil.offsetDay(DateTime.now(), 10);
+            DateTime tenExpiry = DateUtil.offsetDay(DateUtil.beginOfDay(DateTime.now()), 10);
             Integer available = relationMapper.selectAvailableRelation(skuId, skuNum);
             //额外硬塞
             Integer special_available = relationMapper.selectSpecialGroupsRelationAvailable(skuId, maxNum, skuNum, extraNum, tenExpiry);

+ 11 - 9
netflix-service/src/main/java/com/cyksj/service/order/impl/OrderDonServiceImpl.java

@@ -1935,7 +1935,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 					if (sku.getNum() > 1 && Constant.AI_goodsIds.contains(sku.getGoodsId())) {
 						DateTime tenExpiry = DateUtil.offsetDay(DateUtil.beginOfDay(DateTime.now()), 10);
 						//不塞存在该用户的车队
-						Long groupsId = groupsRelationMapper.getOutSideGroupsTripsRelationByGoodsId(sku.getId(), tenExpiry, 5, userId);
+						Long groupsId = groupsRelationMapper.getOutSideGroupsTripsRelationByGoodsId(sku.getId(), tenExpiry, 5, userId, sku.getNum());
 						if (groupsId != null) {
 							relation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class)
 									.eq(GroupsRelation::getGroupsId, groupsId)
@@ -1943,15 +1943,17 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 									.eq(GroupsRelation::getStatus, GroupsRelation.Status.outside)
 									.last("limit 1"));
 							if (relation == null) {
-								if (redisService.setNx(RedisService.key.GROUPS_TRIPS_OUTSIDE_RELATION.getName() + groupsId, groupsId, RedisService.key.GROUPS_TRIPS_OUTSIDE_RELATION.getTimeout())) {
-									relation = new GroupsRelation();
-									relation.setStatus(GroupsRelation.Status.outside);
-									relation.setUserId(userId);
-									relation.setGroupsId(groupsId);
-									GroupsRelation maxNumRelation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class).eq(GroupsRelation::getGroupsId, groupsId).orderByDesc(GroupsRelation::getNum).last("limit 1"));
-									relation.setNum(maxNumRelation.getNum() + 1);
+								relation = new GroupsRelation();
+								relation.setStatus(GroupsRelation.Status.outside);
+								relation.setUserId(userId);
+								relation.setGroupsId(groupsId);
+								GroupsRelation maxNumRelation = groupsRelationMapper.selectOne(Wrappers.lambdaQuery(GroupsRelation.class).eq(GroupsRelation::getGroupsId, groupsId).orderByDesc(GroupsRelation::getNum).last("limit 1"));
+								Integer nextNum = maxNumRelation.getNum() + 1;
+								if (redisService.setNx(RedisService.key.GROUPS_TRIPS_OUTSIDE_RELATION.getNameFormat(groupsId, nextNum), nextNum, RedisService.key.GROUPS_TRIPS_OUTSIDE_RELATION.getTimeout())) {
+									relation.setNum(nextNum);
 									groupsRelationMapper.insert(relation);
-									redisService.del(RedisService.key.GROUPS_TRIPS_OUTSIDE_RELATION.getName() + groupsId);
+								} else {
+									throw BusinessRuntimeException.getInstance("系统繁忙,请重试...");
 								}
 							}
 							groups = groupsMapper.selectById(groupsId);