Showing
7 changed files
with
143 additions
and
78 deletions
1 | package com.yohoufo.common.helper; | 1 | package com.yohoufo.common.helper; |
2 | 2 | ||
3 | import com.google.common.collect.Lists; | 3 | import com.google.common.collect.Lists; |
4 | +import com.yoho.service.model.promotion.ProductLimitValueBo; | ||
4 | import com.yohobuy.ufo.model.order.bo.ShoppingProductInfo; | 5 | import com.yohobuy.ufo.model.order.bo.ShoppingProductInfo; |
5 | -import com.yohobuy.ufo.model.promotion.UserCouponsBo; | ||
6 | import com.yohobuy.ufo.model.promotion.constant.CouponProductLimitTypeEnum; | 6 | import com.yohobuy.ufo.model.promotion.constant.CouponProductLimitTypeEnum; |
7 | import com.yohobuy.ufo.model.promotion.response.ProductLimitInfo; | 7 | import com.yohobuy.ufo.model.promotion.response.ProductLimitInfo; |
8 | import org.apache.commons.collections.CollectionUtils; | 8 | import org.apache.commons.collections.CollectionUtils; |
9 | import org.slf4j.Logger; | 9 | import org.slf4j.Logger; |
10 | import org.slf4j.LoggerFactory; | 10 | import org.slf4j.LoggerFactory; |
11 | - | ||
12 | import java.util.Arrays; | 11 | import java.util.Arrays; |
13 | import java.util.List; | 12 | import java.util.List; |
14 | import java.util.Optional; | 13 | import java.util.Optional; |
@@ -29,8 +28,45 @@ public class ProductLimitCollector { | @@ -29,8 +28,45 @@ public class ProductLimitCollector { | ||
29 | LIMIT_VALUES_LIST.add(new ProductExcludeLimitValueHandler()); | 28 | LIMIT_VALUES_LIST.add(new ProductExcludeLimitValueHandler()); |
30 | } | 29 | } |
31 | 30 | ||
32 | - public static Optional<LimitValueHandler> getSpecifiedProductLimitHandler(CouponProductLimitTypeEnum productLimitTypeEnum) { | ||
33 | - return LIMIT_VALUES_LIST.stream().filter(limitValueHandler -> limitValueHandler.getLimitValue() == productLimitTypeEnum).findFirst(); | 31 | + |
32 | + public static ProductLimitInfo getProductLimitInfo(List<ProductLimitValueBo> productLimitValueBo, Integer productLimitType, String productLimitValue ){ | ||
33 | + | ||
34 | + ProductLimitInfo productLimitInfo = new ProductLimitInfo(); | ||
35 | + | ||
36 | + // 处理 排除&指定的商品 | ||
37 | + if (CollectionUtils.isNotEmpty(productLimitValueBo)){ | ||
38 | + | ||
39 | + for (ProductLimitValueBo item : productLimitValueBo){ | ||
40 | + Optional<LimitValueHandler> handler = LIMIT_VALUES_LIST.stream().filter(x->Integer.valueOf(x.getLimitValue().getLimitType()) == item.getLimitType()).findFirst(); | ||
41 | + if (handler.isPresent()){ | ||
42 | + handler.get().setProductLimitValue(productLimitInfo, item.getProductIds(), productLimitValue); | ||
43 | + } | ||
44 | + } | ||
45 | + } | ||
46 | + | ||
47 | + Optional<LimitValueHandler> limitValueHandler = LIMIT_VALUES_LIST.stream().filter(x->Integer.valueOf(x.getLimitValue().getLimitType()) == productLimitType).findFirst(); | ||
48 | + limitValueHandler.ifPresent(x->x.setProductLimitValue(productLimitInfo, null, productLimitValue)); | ||
49 | + | ||
50 | + return productLimitInfo; | ||
51 | + | ||
52 | + } | ||
53 | + | ||
54 | + | ||
55 | + /** | ||
56 | + * | ||
57 | + * @param shoppingProductInfo | ||
58 | + * @param productLimitInfo | ||
59 | + * @return | ||
60 | + */ | ||
61 | + public static boolean match(ShoppingProductInfo shoppingProductInfo, ProductLimitInfo productLimitInfo){ | ||
62 | + for (LimitValueHandler limitValueHandler : LIMIT_VALUES_LIST){ | ||
63 | + | ||
64 | + if (!limitValueHandler.isMatch(shoppingProductInfo, productLimitInfo)){ | ||
65 | + return false; | ||
66 | + } | ||
67 | + } | ||
68 | + | ||
69 | + return true; | ||
34 | } | 70 | } |
35 | 71 | ||
36 | 72 | ||
@@ -59,7 +95,7 @@ public class ProductLimitCollector { | @@ -59,7 +95,7 @@ public class ProductLimitCollector { | ||
59 | * @param productIds | 95 | * @param productIds |
60 | * @param productLimitValue | 96 | * @param productLimitValue |
61 | */ | 97 | */ |
62 | - ProductLimitInfo getProductLimitInfo(List<Integer> productIds, String productLimitValue); | 98 | + void setProductLimitValue(ProductLimitInfo productLimitInfo, List<Integer> productIds, String productLimitValue); |
63 | 99 | ||
64 | /** | 100 | /** |
65 | * 是否满足使用条件 | 101 | * 是否满足使用条件 |
@@ -77,8 +113,8 @@ public class ProductLimitCollector { | @@ -77,8 +113,8 @@ public class ProductLimitCollector { | ||
77 | } | 113 | } |
78 | 114 | ||
79 | @Override | 115 | @Override |
80 | - public ProductLimitInfo getProductLimitInfo(List<Integer> productIds, String productLimitValue) { | ||
81 | - return ProductLimitInfo.builder().build(); | 116 | + public void setProductLimitValue(ProductLimitInfo productLimitInfo, List<Integer> productIds, String productLimitValue) { |
117 | + | ||
82 | } | 118 | } |
83 | 119 | ||
84 | 120 | ||
@@ -99,15 +135,14 @@ public class ProductLimitCollector { | @@ -99,15 +135,14 @@ public class ProductLimitCollector { | ||
99 | } | 135 | } |
100 | 136 | ||
101 | @Override | 137 | @Override |
102 | - public ProductLimitInfo getProductLimitInfo(List<Integer> productIds, String productLimitValue) { | ||
103 | - return ProductLimitInfo.builder().brandInclude(covertProductLimitValueList(productLimitValue)).build(); | 138 | + public void setProductLimitValue(ProductLimitInfo productLimitInfo, List<Integer> productIds, String productLimitValue) { |
139 | + productLimitInfo.setBrandInclude(covertProductLimitValueList(productLimitValue)); | ||
104 | } | 140 | } |
105 | 141 | ||
106 | - @Override | ||
107 | public boolean isMatch(ShoppingProductInfo shoppingProductInfo, ProductLimitInfo productLimitInfo) { | 142 | public boolean isMatch(ShoppingProductInfo shoppingProductInfo, ProductLimitInfo productLimitInfo) { |
108 | 143 | ||
109 | - return CollectionUtils.isNotEmpty(productLimitInfo.getBrandInclude()) | ||
110 | - && productLimitInfo.getBrandInclude().contains(shoppingProductInfo.getBrandId()); | 144 | + return CollectionUtils.isEmpty(productLimitInfo.getBrandInclude()) || (CollectionUtils.isNotEmpty(productLimitInfo.getBrandInclude()) |
145 | + && productLimitInfo.getBrandInclude().contains(shoppingProductInfo.getBrandId())); | ||
111 | } | 146 | } |
112 | 147 | ||
113 | } | 148 | } |
@@ -120,16 +155,17 @@ public class ProductLimitCollector { | @@ -120,16 +155,17 @@ public class ProductLimitCollector { | ||
120 | } | 155 | } |
121 | 156 | ||
122 | @Override | 157 | @Override |
123 | - public ProductLimitInfo getProductLimitInfo(List<Integer> productIds, String productLimitValue) { | ||
124 | - return ProductLimitInfo.builder().categoryInclude(covertProductLimitValueList(productLimitValue)).build(); | 158 | + public void setProductLimitValue(ProductLimitInfo productLimitInfo, List<Integer> productIds, String productLimitValue) { |
159 | + productLimitInfo.setCategoryInclude(covertProductLimitValueList(productLimitValue)); | ||
125 | } | 160 | } |
126 | 161 | ||
127 | 162 | ||
128 | @Override | 163 | @Override |
129 | public boolean isMatch(ShoppingProductInfo shoppingProductInfo, ProductLimitInfo productLimitInfo) { | 164 | public boolean isMatch(ShoppingProductInfo shoppingProductInfo, ProductLimitInfo productLimitInfo) { |
130 | 165 | ||
131 | - return CollectionUtils.isNotEmpty(productLimitInfo.getCategoryInclude()) | ||
132 | - && productLimitInfo.getCategoryInclude().contains(shoppingProductInfo.getCategoryId()); | 166 | + return CollectionUtils.isEmpty(productLimitInfo.getCategoryInclude()) || |
167 | + (CollectionUtils.isNotEmpty(productLimitInfo.getCategoryInclude()) | ||
168 | + && productLimitInfo.getCategoryInclude().contains(shoppingProductInfo.getCategoryId())); | ||
133 | 169 | ||
134 | } | 170 | } |
135 | 171 | ||
@@ -143,14 +179,15 @@ public class ProductLimitCollector { | @@ -143,14 +179,15 @@ public class ProductLimitCollector { | ||
143 | } | 179 | } |
144 | 180 | ||
145 | @Override | 181 | @Override |
146 | - public ProductLimitInfo getProductLimitInfo(List<Integer> productIds, String productLimitValue) { | ||
147 | - return ProductLimitInfo.builder().seriesInclude(covertProductLimitValueList(productLimitValue)).build(); | 182 | + public void setProductLimitValue(ProductLimitInfo productLimitInfo, List<Integer> productIds, String productLimitValue) { |
183 | + productLimitInfo.setSeriesInclude((covertProductLimitValueList(productLimitValue))); | ||
148 | } | 184 | } |
149 | 185 | ||
150 | @Override | 186 | @Override |
151 | public boolean isMatch(ShoppingProductInfo shoppingProductInfo, ProductLimitInfo productLimitInfo) { | 187 | public boolean isMatch(ShoppingProductInfo shoppingProductInfo, ProductLimitInfo productLimitInfo) { |
152 | - return CollectionUtils.isNotEmpty(productLimitInfo.getSeriesInclude()) | ||
153 | - && productLimitInfo.getSeriesInclude().contains(shoppingProductInfo.getSeriesId()); | 188 | + return CollectionUtils.isEmpty(productLimitInfo.getSeriesInclude()) |
189 | + || (CollectionUtils.isNotEmpty(productLimitInfo.getSeriesInclude()) | ||
190 | + && productLimitInfo.getSeriesInclude().contains(shoppingProductInfo.getSeriesId())); | ||
154 | } | 191 | } |
155 | 192 | ||
156 | } | 193 | } |
@@ -163,8 +200,8 @@ public class ProductLimitCollector { | @@ -163,8 +200,8 @@ public class ProductLimitCollector { | ||
163 | } | 200 | } |
164 | 201 | ||
165 | @Override | 202 | @Override |
166 | - public ProductLimitInfo getProductLimitInfo(List<Integer> productIds, String productLimitValue) { | ||
167 | - return ProductLimitInfo.builder().productIdInclude(covertProductLimitValueList(productLimitValue)).build(); | 203 | + public void setProductLimitValue(ProductLimitInfo productLimitInfo, List<Integer> productIds, String productLimitValue) { |
204 | + productLimitInfo.setProductIdInclude(productIds); | ||
168 | } | 205 | } |
169 | 206 | ||
170 | 207 | ||
@@ -172,8 +209,9 @@ public class ProductLimitCollector { | @@ -172,8 +209,9 @@ public class ProductLimitCollector { | ||
172 | public boolean isMatch(ShoppingProductInfo shoppingProductInfo, ProductLimitInfo productLimitInfo) { | 209 | public boolean isMatch(ShoppingProductInfo shoppingProductInfo, ProductLimitInfo productLimitInfo) { |
173 | 210 | ||
174 | //包含商品 | 211 | //包含商品 |
175 | - return CollectionUtils.isNotEmpty(productLimitInfo.getProductIdInclude()) | ||
176 | - && productLimitInfo.getProductIdInclude().contains(shoppingProductInfo.getProductId()); | 212 | + return CollectionUtils.isEmpty(productLimitInfo.getProductIdInclude()) |
213 | + || (CollectionUtils.isNotEmpty(productLimitInfo.getProductIdInclude()) | ||
214 | + && productLimitInfo.getProductIdInclude().contains(shoppingProductInfo.getProductId())); | ||
177 | } | 215 | } |
178 | 216 | ||
179 | } | 217 | } |
@@ -186,15 +224,16 @@ public class ProductLimitCollector { | @@ -186,15 +224,16 @@ public class ProductLimitCollector { | ||
186 | } | 224 | } |
187 | 225 | ||
188 | @Override | 226 | @Override |
189 | - public ProductLimitInfo getProductLimitInfo(List<Integer> productIds, String productLimitValue) { | ||
190 | - return ProductLimitInfo.builder().productIdExclude(covertProductLimitValueList(productLimitValue)).build(); | 227 | + public void setProductLimitValue(ProductLimitInfo productLimitInfo, List<Integer> productIds, String productLimitValue) { |
228 | + productLimitInfo.setProductIdExclude(productIds); | ||
191 | } | 229 | } |
192 | 230 | ||
193 | @Override | 231 | @Override |
194 | public boolean isMatch(ShoppingProductInfo shoppingProductInfo, ProductLimitInfo productLimitInfo) { | 232 | public boolean isMatch(ShoppingProductInfo shoppingProductInfo, ProductLimitInfo productLimitInfo) { |
195 | //排除商品 | 233 | //排除商品 |
196 | - return CollectionUtils.isNotEmpty(productLimitInfo.getProductIdExclude()) | ||
197 | - && !productLimitInfo.getProductIdExclude().contains(shoppingProductInfo.getProductId()); | 234 | + return CollectionUtils.isEmpty(productLimitInfo.getProductIdExclude()) |
235 | + || (CollectionUtils.isNotEmpty(productLimitInfo.getProductIdExclude()) | ||
236 | + && !productLimitInfo.getProductIdExclude().contains(shoppingProductInfo.getProductId())); | ||
198 | } | 237 | } |
199 | 238 | ||
200 | } | 239 | } |
@@ -31,7 +31,7 @@ public class Coupon { | @@ -31,7 +31,7 @@ public class Coupon { | ||
31 | 31 | ||
32 | private Short useLimitValue; | 32 | private Short useLimitValue; |
33 | 33 | ||
34 | - private Byte productLimitType; | 34 | + private Integer productLimitType; |
35 | 35 | ||
36 | private String productLimitValue; | 36 | private String productLimitValue; |
37 | 37 | ||
@@ -167,11 +167,11 @@ public class Coupon { | @@ -167,11 +167,11 @@ public class Coupon { | ||
167 | this.useLimitValue = useLimitValue; | 167 | this.useLimitValue = useLimitValue; |
168 | } | 168 | } |
169 | 169 | ||
170 | - public Byte getProductLimitType() { | 170 | + public Integer getProductLimitType() { |
171 | return productLimitType; | 171 | return productLimitType; |
172 | } | 172 | } |
173 | 173 | ||
174 | - public void setProductLimitType(Byte productLimitType) { | 174 | + public void setProductLimitType(Integer productLimitType) { |
175 | this.productLimitType = productLimitType; | 175 | this.productLimitType = productLimitType; |
176 | } | 176 | } |
177 | 177 |
@@ -5,7 +5,7 @@ public class CouponProductLimit { | @@ -5,7 +5,7 @@ public class CouponProductLimit { | ||
5 | 5 | ||
6 | private Integer couponId; | 6 | private Integer couponId; |
7 | 7 | ||
8 | - private Byte limitType; | 8 | + private Integer limitType; |
9 | 9 | ||
10 | private Integer productId; | 10 | private Integer productId; |
11 | 11 | ||
@@ -25,11 +25,11 @@ public class CouponProductLimit { | @@ -25,11 +25,11 @@ public class CouponProductLimit { | ||
25 | this.couponId = couponId; | 25 | this.couponId = couponId; |
26 | } | 26 | } |
27 | 27 | ||
28 | - public Byte getLimitType() { | 28 | + public Integer getLimitType() { |
29 | return limitType; | 29 | return limitType; |
30 | } | 30 | } |
31 | 31 | ||
32 | - public void setLimitType(Byte limitType) { | 32 | + public void setLimitType(Integer limitType) { |
33 | this.limitType = limitType; | 33 | this.limitType = limitType; |
34 | } | 34 | } |
35 | 35 |
@@ -4,7 +4,7 @@ | @@ -4,7 +4,7 @@ | ||
4 | <resultMap id="BaseResultMap" type="com.yohoufo.dal.promotion.model.CouponProductLimit" > | 4 | <resultMap id="BaseResultMap" type="com.yohoufo.dal.promotion.model.CouponProductLimit" > |
5 | <id column="id" property="id" jdbcType="INTEGER" /> | 5 | <id column="id" property="id" jdbcType="INTEGER" /> |
6 | <result column="coupon_id" property="couponId" jdbcType="INTEGER" /> | 6 | <result column="coupon_id" property="couponId" jdbcType="INTEGER" /> |
7 | - <result column="limit_type" property="limitType" jdbcType="TINYINT" /> | 7 | + <result column="limit_type" property="limitType" jdbcType="INTEGER" /> |
8 | <result column="product_id" property="productId" jdbcType="INTEGER" /> | 8 | <result column="product_id" property="productId" jdbcType="INTEGER" /> |
9 | </resultMap> | 9 | </resultMap> |
10 | <sql id="Base_Column_List" > | 10 | <sql id="Base_Column_List" > |
@@ -109,17 +109,9 @@ public class CouponRuleMatcher { | @@ -109,17 +109,9 @@ public class CouponRuleMatcher { | ||
109 | 109 | ||
110 | @Override | 110 | @Override |
111 | public boolean match(ChargeGoods chargeGoods, UserCouponsBo couponsBo) { | 111 | public boolean match(ChargeGoods chargeGoods, UserCouponsBo couponsBo) { |
112 | - final CouponProductLimitTypeEnum limitTypeEnum = CouponProductLimitTypeEnum.of(couponsBo.getProductLimitType()).orElse(null); | ||
113 | 112 | ||
114 | - Optional<ProductLimitCollector.LimitValueHandler> valueHandlerOptional = | ||
115 | - ProductLimitCollector.getSpecifiedProductLimitHandler(limitTypeEnum); | 113 | + return ProductLimitCollector.match(chargeGoods.getShoppingProductInfo(), couponsBo.getProductLimitInfo()); |
116 | 114 | ||
117 | - if (valueHandlerOptional.isPresent()) { | ||
118 | - return valueHandlerOptional.get().isMatch(chargeGoods.getShoppingProductInfo(), couponsBo.getProductLimitInfo()); | ||
119 | - } else { | ||
120 | - //目前不存在 | ||
121 | - return false; | ||
122 | - } | ||
123 | } | 115 | } |
124 | } | 116 | } |
125 | 117 |
1 | package com.yohoufo.promotion.convert; | 1 | package com.yohoufo.promotion.convert; |
2 | 2 | ||
3 | import com.google.common.collect.Lists; | 3 | import com.google.common.collect.Lists; |
4 | +import com.yoho.service.model.promotion.ProductLimitValueBo; | ||
4 | import com.yohobuy.ufo.model.promotion.CouponSimpleBo; | 5 | import com.yohobuy.ufo.model.promotion.CouponSimpleBo; |
5 | import com.yohobuy.ufo.model.promotion.UserCouponsBo; | 6 | import com.yohobuy.ufo.model.promotion.UserCouponsBo; |
6 | import com.yohobuy.ufo.model.promotion.constant.*; | 7 | import com.yohobuy.ufo.model.promotion.constant.*; |
@@ -35,10 +36,10 @@ public class CouponConvert { | @@ -35,10 +36,10 @@ public class CouponConvert { | ||
35 | * @param userCoupon | 36 | * @param userCoupon |
36 | * @param coupon | 37 | * @param coupon |
37 | * @param couponType | 38 | * @param couponType |
38 | - * @param productIds | 39 | + * @param productLimitValueBo |
39 | * @return | 40 | * @return |
40 | */ | 41 | */ |
41 | - public static UserCouponsBo covertCouponBo(UserCoupon userCoupon, Coupon coupon, CouponType couponType, List<Integer> productIds){ | 42 | + public static UserCouponsBo covertCouponBo(UserCoupon userCoupon, Coupon coupon, CouponType couponType, List<ProductLimitValueBo> productLimitValueBo){ |
42 | 43 | ||
43 | UserCouponsBo couponBo = new UserCouponsBo(); | 44 | UserCouponsBo couponBo = new UserCouponsBo(); |
44 | 45 | ||
@@ -73,17 +74,9 @@ public class CouponConvert { | @@ -73,17 +74,9 @@ public class CouponConvert { | ||
73 | couponBo.setCouponTypeName(couponType.getCaption()); | 74 | couponBo.setCouponTypeName(couponType.getCaption()); |
74 | } | 75 | } |
75 | 76 | ||
76 | - CouponProductLimitTypeEnum productLimitTypeEnum = CouponProductLimitTypeEnum.of(String.valueOf(coupon.getProductLimitType())).orElse(null); | ||
77 | - if (productLimitTypeEnum == CouponProductLimitTypeEnum.SPECIFIC_PRODUCT) { | ||
78 | - couponBo.setProductIdInclude(productIds); | ||
79 | - } else if (productLimitTypeEnum == CouponProductLimitTypeEnum.EXCLUDE_PRODUCT) { | ||
80 | - couponBo.setProductIdExclude(productIds); | ||
81 | - } | ||
82 | - | ||
83 | - // 根据商品限制类型,设置值 | ||
84 | - ProductLimitCollector.getSpecifiedProductLimitHandler(productLimitTypeEnum) | ||
85 | - .ifPresent(limitValueSetter -> couponBo.setProductLimitInfo(limitValueSetter.getProductLimitInfo( productIds, coupon.getProductLimitValue()))); | ||
86 | 77 | ||
78 | + ProductLimitInfo productLimitInfo = ProductLimitCollector.getProductLimitInfo(productLimitValueBo, coupon.getProductLimitType(), coupon.getProductLimitValue()); | ||
79 | + couponBo.setProductLimitInfo(productLimitInfo); | ||
87 | 80 | ||
88 | couponBo.setBusinessClient(coupon.getBusinessClient()); | 81 | couponBo.setBusinessClient(coupon.getBusinessClient()); |
89 | 82 |
1 | package com.yohoufo.promotion.service.impl; | 1 | package com.yohoufo.promotion.service.impl; |
2 | 2 | ||
3 | import com.google.common.collect.Lists; | 3 | import com.google.common.collect.Lists; |
4 | +import com.google.common.collect.Maps; | ||
4 | import com.google.common.collect.Range; | 5 | import com.google.common.collect.Range; |
5 | import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder; | 6 | import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder; |
6 | import com.yoho.error.ServiceError; | 7 | import com.yoho.error.ServiceError; |
7 | import com.yoho.error.exception.ServiceException; | 8 | import com.yoho.error.exception.ServiceException; |
9 | +import com.yoho.service.model.promotion.ProductLimitValueBo; | ||
8 | import com.yohobuy.ufo.model.promotion.CouponSimpleBo; | 10 | import com.yohobuy.ufo.model.promotion.CouponSimpleBo; |
9 | import com.yohobuy.ufo.model.promotion.UserCouponsBo; | 11 | import com.yohobuy.ufo.model.promotion.UserCouponsBo; |
10 | import com.yohobuy.ufo.model.promotion.UserCouponsListBo; | 12 | import com.yohobuy.ufo.model.promotion.UserCouponsListBo; |
11 | import com.yohobuy.ufo.model.promotion.constant.CouponProductLimitTypeEnum; | 13 | import com.yohobuy.ufo.model.promotion.constant.CouponProductLimitTypeEnum; |
12 | import com.yohobuy.ufo.model.promotion.constant.CouponUseStatusEnum; | 14 | import com.yohobuy.ufo.model.promotion.constant.CouponUseStatusEnum; |
13 | import com.yohobuy.ufo.model.promotion.constant.CouponsStatusEnum; | 15 | import com.yohobuy.ufo.model.promotion.constant.CouponsStatusEnum; |
16 | +import com.yohoufo.dal.promotion.CouponProductLimitMapper; | ||
14 | import com.yohoufo.promotion.model.CouponReceiveChannel; | 17 | import com.yohoufo.promotion.model.CouponReceiveChannel; |
15 | import com.yohobuy.ufo.model.promotion.request.CouponSendType; | 18 | import com.yohobuy.ufo.model.promotion.request.CouponSendType; |
16 | import com.yohobuy.ufo.model.promotion.request.UserCouponListReq; | 19 | import com.yohobuy.ufo.model.promotion.request.UserCouponListReq; |
@@ -37,6 +40,7 @@ import org.slf4j.LoggerFactory; | @@ -37,6 +40,7 @@ import org.slf4j.LoggerFactory; | ||
37 | import org.springframework.beans.factory.annotation.Autowired; | 40 | import org.springframework.beans.factory.annotation.Autowired; |
38 | import org.springframework.stereotype.Service; | 41 | import org.springframework.stereotype.Service; |
39 | 42 | ||
43 | +import java.lang.reflect.Array; | ||
40 | import java.time.LocalDate; | 44 | import java.time.LocalDate; |
41 | import java.time.LocalDateTime; | 45 | import java.time.LocalDateTime; |
42 | import java.time.LocalTime; | 46 | import java.time.LocalTime; |
@@ -62,6 +66,9 @@ public class CouponServiceImpl implements ICouponService { | @@ -62,6 +66,9 @@ public class CouponServiceImpl implements ICouponService { | ||
62 | CouponMapper couponMapper; | 66 | CouponMapper couponMapper; |
63 | 67 | ||
64 | @Autowired | 68 | @Autowired |
69 | + CouponProductLimitMapper couponProductLimitMapper; | ||
70 | + | ||
71 | + @Autowired | ||
65 | SingleCentCouponService singleCentSyncCoupNumService; | 72 | SingleCentCouponService singleCentSyncCoupNumService; |
66 | 73 | ||
67 | @Autowired | 74 | @Autowired |
@@ -83,24 +90,27 @@ public class CouponServiceImpl implements ICouponService { | @@ -83,24 +90,27 @@ public class CouponServiceImpl implements ICouponService { | ||
83 | if (CouponProductLimitTypeEnum.NON.getLimitType().equals(coupon.getProductLimitType().toString())) { | 90 | if (CouponProductLimitTypeEnum.NON.getLimitType().equals(coupon.getProductLimitType().toString())) { |
84 | return new CouponInfo(); | 91 | return new CouponInfo(); |
85 | } | 92 | } |
86 | - Map<Integer, List<Integer>> map = getAssociatedProductIdListMap(Arrays.asList(coupon)); | ||
87 | - if (map.isEmpty()) { | ||
88 | - return null; | ||
89 | - } | ||
90 | - String productIds = StringUtils.join(map.values().iterator().next(), ","); | ||
91 | - CouponInfo info = new CouponInfo(); | ||
92 | - if (CouponProductLimitTypeEnum.SPECIFIC_PRODUCT.getLimitType().equals(coupon.getProductLimitType().toString())) { | ||
93 | - info.setContainsProductIds(productIds); | ||
94 | - } | ||
95 | - if (CouponProductLimitTypeEnum.EXCLUDE_PRODUCT.getLimitType().equals(coupon.getProductLimitType().toString())) { | ||
96 | - info.setExcludeProductIds(productIds); | 93 | +// Map<Integer, List<Integer>> map = getAssociatedProductIdListMap(Arrays.asList(coupon)); |
94 | +// if (map.isEmpty()) { | ||
95 | +// return null; | ||
96 | +// } | ||
97 | +// String productIds = StringUtils.join(map.values().iterator().next(), ","); | ||
98 | +// CouponInfo info = new CouponInfo(); | ||
99 | +// if (CouponProductLimitTypeEnum.SPECIFIC_PRODUCT.getLimitType().equals(coupon.getProductLimitType().toString())) { | ||
100 | +// info.setContainsProductIds(productIds); | ||
101 | +// } | ||
102 | +// if (CouponProductLimitTypeEnum.EXCLUDE_PRODUCT.getLimitType().equals(coupon.getProductLimitType().toString())) { | ||
103 | +// info.setExcludeProductIds(productIds); | ||
104 | +// } | ||
105 | + | ||
106 | + List<ProductLimitValueBo> productLimitValueBo = null; | ||
107 | + Map<Integer, List<ProductLimitValueBo>> productLimitValueBoMap = getAssociatedProductIdMap(Arrays.asList(coupon)); | ||
108 | + if (productLimitValueBoMap != null){ | ||
109 | + productLimitValueBo = productLimitValueBoMap.get(coupon.getId()); | ||
97 | } | 110 | } |
98 | 111 | ||
99 | - CouponProductLimitTypeEnum limitTypeEnum = CouponProductLimitTypeEnum.of( String.valueOf(coupon.getProductLimitType())).orElse(null); | ||
100 | - | ||
101 | - ProductLimitCollector.getSpecifiedProductLimitHandler(limitTypeEnum) | ||
102 | - .ifPresent(limitValueHandler -> info.setProductLimitInfo(limitValueHandler.getProductLimitInfo(map.get(coupon.getId()) , coupon.getProductLimitValue() ))); | ||
103 | - | 112 | + CouponInfo info = new CouponInfo(); |
113 | + info.setProductLimitInfo(ProductLimitCollector.getProductLimitInfo(productLimitValueBo, coupon.getProductLimitType(), coupon.getProductLimitValue())); | ||
104 | 114 | ||
105 | return info; | 115 | return info; |
106 | } | 116 | } |
@@ -422,17 +432,47 @@ public class CouponServiceImpl implements ICouponService { | @@ -422,17 +432,47 @@ public class CouponServiceImpl implements ICouponService { | ||
422 | }).collect(Collectors.toMap(Coupon::getId, Function.identity())); | 432 | }).collect(Collectors.toMap(Coupon::getId, Function.identity())); |
423 | 433 | ||
424 | // 优惠券商品限制 key=couponId, value=ProductId集合 | 434 | // 优惠券商品限制 key=couponId, value=ProductId集合 |
425 | - final Map<Integer, List<Integer>> couponProductIdMap = getAssociatedProductIdListMap(couponList); | 435 | +// final Map<Integer, List<Integer>> couponProductIdMap = getAssociatedProductIdListMap(couponList); |
436 | + Map<Integer, List<ProductLimitValueBo>> productLimitValueBoMap = getAssociatedProductIdMap(couponList); | ||
426 | 437 | ||
427 | //包装返回结果 | 438 | //包装返回结果 |
428 | List<UserCouponsBo> couponBoList = list.stream() | 439 | List<UserCouponsBo> couponBoList = list.stream() |
429 | .filter(userCoupon -> couponMap.containsKey(userCoupon.getCouponId())) | 440 | .filter(userCoupon -> couponMap.containsKey(userCoupon.getCouponId())) |
430 | - .map(userCoupon -> wrapperUserCoupon(userCoupon, couponMap.get(userCoupon.getCouponId()), couponProductIdMap.get(userCoupon.getCouponId()))) | 441 | + .map(userCoupon -> wrapperUserCoupon(userCoupon, couponMap.get(userCoupon.getCouponId()), productLimitValueBoMap.get(userCoupon.getCouponId()))) |
431 | .collect(Collectors.toList()); | 442 | .collect(Collectors.toList()); |
432 | 443 | ||
433 | return UserCouponsListBo.builder().coupons(couponBoList).build(); | 444 | return UserCouponsListBo.builder().coupons(couponBoList).build(); |
434 | } | 445 | } |
435 | 446 | ||
447 | + private Map<Integer, List<ProductLimitValueBo>> getAssociatedProductIdMap(List<Coupon> couponList){ | ||
448 | + | ||
449 | + | ||
450 | + List<CouponProductLimit> couponProductLimitList = couponProductLimitMapper.selectByCouponIds(couponList.stream().map(Coupon::getId).collect(Collectors.toList())); | ||
451 | + | ||
452 | + Map<Integer, List<CouponProductLimit>> map = couponProductLimitList.stream().collect(Collectors.groupingBy(CouponProductLimit::getCouponId)); | ||
453 | + | ||
454 | + // key=couponId, value= | ||
455 | + Map<Integer, List<ProductLimitValueBo>> productLimitValueBoMap = Maps.newHashMap(); | ||
456 | + | ||
457 | + for (Integer couponId : map.keySet()){ | ||
458 | + | ||
459 | + List<ProductLimitValueBo> productLimitValueBos = Lists.newArrayList(); | ||
460 | + | ||
461 | + // key=limitType, value= | ||
462 | + Map<Integer, List<CouponProductLimit>> typeToItem = map.get(couponId).stream().collect(Collectors.groupingBy(CouponProductLimit::getLimitType)); | ||
463 | + for (Integer type : typeToItem.keySet()){ | ||
464 | + productLimitValueBos.add(ProductLimitValueBo.builder() | ||
465 | + .limitType(type) | ||
466 | + .productIds(typeToItem.get(type).stream().map(CouponProductLimit::getProductId).collect(Collectors.toList())).build()); | ||
467 | + } | ||
468 | + | ||
469 | + productLimitValueBoMap.put(couponId, productLimitValueBos); | ||
470 | + | ||
471 | + } | ||
472 | + | ||
473 | + return productLimitValueBoMap; | ||
474 | + } | ||
475 | + | ||
436 | /** | 476 | /** |
437 | * 关联的商品id | 477 | * 关联的商品id |
438 | * | 478 | * |
@@ -478,7 +518,8 @@ public class CouponServiceImpl implements ICouponService { | @@ -478,7 +518,8 @@ public class CouponServiceImpl implements ICouponService { | ||
478 | }).collect(Collectors.toMap(Coupon::getId, Function.identity())); | 518 | }).collect(Collectors.toMap(Coupon::getId, Function.identity())); |
479 | 519 | ||
480 | // 优惠券商品限制 key=couponId, value=ProductId集合 | 520 | // 优惠券商品限制 key=couponId, value=ProductId集合 |
481 | - Map<Integer, List<Integer>> couponProductIdMap = getAssociatedProductIdListMap(couponList); | 521 | +// Map<Integer, List<Integer>> couponProductIdMap = getAssociatedProductIdListMap(couponList); |
522 | + Map<Integer, List<ProductLimitValueBo>> productLimitValueBoMap = getAssociatedProductIdMap(couponList); | ||
482 | 523 | ||
483 | 524 | ||
484 | int time = DateUtil.getCurrentTimeSecond(); | 525 | int time = DateUtil.getCurrentTimeSecond(); |
@@ -514,19 +555,19 @@ public class CouponServiceImpl implements ICouponService { | @@ -514,19 +555,19 @@ public class CouponServiceImpl implements ICouponService { | ||
514 | } | 555 | } |
515 | 556 | ||
516 | //所有的校验都通过了,生成bo | 557 | //所有的校验都通过了,生成bo |
517 | - return wrapperUserCoupon(userCoupon, coupon, couponProductIdMap.get(userCoupon.getCouponId())); | 558 | + return wrapperUserCoupon(userCoupon, coupon, productLimitValueBoMap.get(userCoupon.getCouponId())); |
518 | 559 | ||
519 | }).collect(Collectors.toList()); | 560 | }).collect(Collectors.toList()); |
520 | 561 | ||
521 | return UserCouponsListBo.builder().coupons(couponBoList).build(); | 562 | return UserCouponsListBo.builder().coupons(couponBoList).build(); |
522 | } | 563 | } |
523 | 564 | ||
524 | - private UserCouponsBo wrapperUserCoupon(final UserCoupon userCoupon, final Coupon coupon, final List<Integer> productIds) { | 565 | + private UserCouponsBo wrapperUserCoupon(final UserCoupon userCoupon, final Coupon coupon, final List<ProductLimitValueBo> productLimitValueBo) { |
525 | 566 | ||
526 | // 单个获取couponType | 567 | // 单个获取couponType |
527 | CouponType couponType = couponCacheService.getCouponTypeWithCache(userCoupon.getCouponType() != null ? userCoupon.getCouponType().intValue() : null); | 568 | CouponType couponType = couponCacheService.getCouponTypeWithCache(userCoupon.getCouponType() != null ? userCoupon.getCouponType().intValue() : null); |
528 | 569 | ||
529 | - UserCouponsBo couponBo = CouponConvert.covertCouponBo(userCoupon, coupon, couponType, productIds); | 570 | + UserCouponsBo couponBo = CouponConvert.covertCouponBo(userCoupon, coupon, couponType, productLimitValueBo); |
530 | 571 | ||
531 | return couponBo; | 572 | return couponBo; |
532 | } | 573 | } |
-
Please register or login to post a comment