Authored by TANLING

优惠券限制

  1 +package com.yohoufo.common.helper;
  2 +
  3 +import com.google.common.collect.Lists;
  4 +import com.google.common.collect.Maps;
  5 +import com.yohobuy.ufo.model.order.bo.ShoppingProductInfo;
  6 +import com.yohobuy.ufo.model.promotion.ConditionLimitValue;
  7 +import com.yohobuy.ufo.model.promotion.ConditionLimitValueReplacement;
  8 +import com.yohobuy.ufo.model.promotion.constant.CouponProductLimitTypeEnum;
  9 +import org.apache.commons.collections.CollectionUtils;
  10 +import org.slf4j.Logger;
  11 +import org.slf4j.LoggerFactory;
  12 +import org.springframework.beans.BeansException;
  13 +import org.springframework.beans.factory.InitializingBean;
  14 +import org.springframework.context.ApplicationContext;
  15 +import org.springframework.stereotype.Component;
  16 +
  17 +import java.util.List;
  18 +import java.util.Map;
  19 +import java.util.function.Function;
  20 +import java.util.stream.Collectors;
  21 +
  22 +@Component
  23 +public class ConditionLimitValueProcessor implements InitializingBean {
  24 +
  25 + private final static Logger logger = LoggerFactory.getLogger(ConditionLimitValueProcessor.class);
  26 +
  27 +
  28 + // key=限制类型,value=处理器
  29 + Map<String, LimitValueHandler> handlerMapOfType = Maps.newHashMap();
  30 +
  31 +
  32 + /**
  33 + * 将限制条件对象list展开
  34 + * @param conditionLimitValues
  35 + * @return
  36 + */
  37 + public ConditionLimitValueReplacement flattenCondLimitValues(List<ConditionLimitValue> conditionLimitValues){
  38 +
  39 + ConditionLimitValueReplacement productLimitInfo = new ConditionLimitValueReplacement();
  40 +
  41 + if (CollectionUtils.isEmpty(conditionLimitValues)){
  42 + return productLimitInfo;
  43 + }
  44 +
  45 + for (ConditionLimitValue conditionLimitValue : conditionLimitValues){
  46 +
  47 + LimitValueHandler limitValueHandler = handlerMapOfType.get(String.valueOf(conditionLimitValue.getLimitType()));
  48 +
  49 + if (limitValueHandler!=null){
  50 + limitValueHandler.setProductLimitValue(productLimitInfo, conditionLimitValue);
  51 + }
  52 + }
  53 +
  54 + return productLimitInfo;
  55 +
  56 + }
  57 +
  58 +
  59 + /**
  60 + * 该商品是否满足所有的限制条件
  61 + * @param shoppingProductInfo
  62 + * @param conditionLimitValues
  63 + * @return
  64 + */
  65 + public boolean match(String couponCode,
  66 + ShoppingProductInfo shoppingProductInfo, List<ConditionLimitValue> conditionLimitValues){
  67 +
  68 + for (ConditionLimitValue conditionLimitValue : conditionLimitValues){
  69 + LimitValueHandler limitValueHandler = handlerMapOfType.get(String.valueOf(conditionLimitValue.getLimitType()));
  70 +
  71 + if (limitValueHandler == null){
  72 + continue;
  73 + }
  74 +
  75 + if (!limitValueHandler.isMatch(shoppingProductInfo, conditionLimitValue)){
  76 + logger.info("[{}] ProductLimitRuleMatcher Condition <<< {},{}; Result <<< [{}] not matched",
  77 + couponCode, shoppingProductInfo, conditionLimitValue, limitValueHandler.getLimitValue());
  78 + return false;
  79 + }
  80 + }
  81 +
  82 + logger.info("[{}] ProductLimitRuleMatcher Condition <<< {},{}; Result <<< matched", couponCode, shoppingProductInfo, conditionLimitValues);
  83 +
  84 + return true;
  85 + }
  86 +
  87 +
  88 +
  89 + @Override
  90 + public void afterPropertiesSet() throws Exception {
  91 +
  92 + List<LimitValueHandler> limitValueHandlers = Lists.newArrayList();
  93 + limitValueHandlers.add(new BrandLimitValueHandler());
  94 + limitValueHandlers.add(new CategoryLimitValueHandler());
  95 + limitValueHandlers.add(new SeriesLimitValueHandler());
  96 + limitValueHandlers.add(new ProductExcludeLimitValueHandler());
  97 + limitValueHandlers.add(new ProductIncludeLimitValueHandler());
  98 +
  99 + handlerMapOfType = limitValueHandlers.stream().collect(Collectors.toMap(LimitValueHandler::getLimitValue, Function.identity()));
  100 + }
  101 +
  102 +
  103 + public interface LimitValueHandler {
  104 + /**
  105 + * 商品限制类型
  106 + * @return
  107 + */
  108 + String getLimitValue();
  109 +
  110 + /**
  111 + * 商品限制的值
  112 + */
  113 + void setProductLimitValue(ConditionLimitValueReplacement productLimitInfo, ConditionLimitValue conditionLimitValue);
  114 +
  115 + /**
  116 + * 是否满足使用条件
  117 + * @return
  118 + */
  119 + boolean isMatch(ShoppingProductInfo shoppingProductInfo, ConditionLimitValue conditionLimitValue);
  120 +
  121 + }
  122 +
  123 +
  124 +
  125 + private class BrandLimitValueHandler implements LimitValueHandler {
  126 +
  127 + @Override
  128 + public String getLimitValue() {
  129 + return CouponProductLimitTypeEnum.SPECIFIC_BRAND.getLimitType();
  130 + }
  131 +
  132 + @Override
  133 + public void setProductLimitValue(ConditionLimitValueReplacement productLimitInfo, ConditionLimitValue conditionLimitValue) {
  134 + productLimitInfo.setBrandInclude(conditionLimitValue.getLimitValues());
  135 +
  136 + }
  137 +
  138 + @Override
  139 + public boolean isMatch(ShoppingProductInfo shoppingProductInfo, ConditionLimitValue conditionLimitValue) {
  140 +
  141 + return CollectionUtils.isNotEmpty(conditionLimitValue.getLimitValues())
  142 + && conditionLimitValue.getLimitValues().contains(shoppingProductInfo.getBrandId());
  143 + }
  144 +
  145 + }
  146 +
  147 + private class CategoryLimitValueHandler implements LimitValueHandler {
  148 +
  149 + @Override
  150 + public String getLimitValue() {
  151 + return CouponProductLimitTypeEnum.SPECIFIC_CATEGORY.getLimitType();
  152 + }
  153 +
  154 + @Override
  155 + public void setProductLimitValue(ConditionLimitValueReplacement productLimitInfo, ConditionLimitValue conditionLimitValue) {
  156 + productLimitInfo.setCategoryInclude(conditionLimitValue.getLimitValues());
  157 + }
  158 +
  159 + @Override
  160 + public boolean isMatch(ShoppingProductInfo shoppingProductInfo, ConditionLimitValue conditionLimitValue) {
  161 +
  162 + return CollectionUtils.isNotEmpty(conditionLimitValue.getLimitValues())
  163 + && conditionLimitValue.getLimitValues().contains(shoppingProductInfo.getCategoryId());
  164 +
  165 + }
  166 +
  167 + }
  168 +
  169 + private class SeriesLimitValueHandler implements LimitValueHandler {
  170 +
  171 + @Override
  172 + public String getLimitValue() {
  173 + return CouponProductLimitTypeEnum.SPECIFIC_SERIES.getLimitType();
  174 + }
  175 +
  176 + @Override
  177 + public void setProductLimitValue(ConditionLimitValueReplacement productLimitInfo, ConditionLimitValue conditionLimitValue) {
  178 + productLimitInfo.setSeriesInclude((conditionLimitValue.getLimitValues()));
  179 + }
  180 +
  181 + @Override
  182 + public boolean isMatch(ShoppingProductInfo shoppingProductInfo, ConditionLimitValue conditionLimitValue) {
  183 + return (CollectionUtils.isNotEmpty(conditionLimitValue.getLimitValues())
  184 + && conditionLimitValue.getLimitValues().contains(shoppingProductInfo.getSeriesId()));
  185 + }
  186 +
  187 + }
  188 +
  189 + private class ProductIncludeLimitValueHandler implements LimitValueHandler {
  190 +
  191 + @Override
  192 + public String getLimitValue() {
  193 + return CouponProductLimitTypeEnum.SPECIFIC_PRODUCT.getLimitType();
  194 + }
  195 +
  196 + @Override
  197 + public void setProductLimitValue(ConditionLimitValueReplacement productLimitInfo, ConditionLimitValue conditionLimitValue) {
  198 + productLimitInfo.setProductIdInclude(conditionLimitValue.getLimitValues());
  199 + }
  200 +
  201 +
  202 + @Override
  203 + public boolean isMatch(ShoppingProductInfo shoppingProductInfo, ConditionLimitValue conditionLimitValue) {
  204 +
  205 + //包含商品
  206 + return CollectionUtils.isNotEmpty(conditionLimitValue.getLimitValues())
  207 + && conditionLimitValue.getLimitValues().contains(shoppingProductInfo.getProductId());
  208 + }
  209 +
  210 + }
  211 +
  212 + private class ProductExcludeLimitValueHandler implements LimitValueHandler {
  213 +
  214 + @Override
  215 + public String getLimitValue() {
  216 + return CouponProductLimitTypeEnum.EXCLUDE_PRODUCT.getLimitType();
  217 + }
  218 +
  219 + @Override
  220 + public void setProductLimitValue(ConditionLimitValueReplacement productLimitInfo, ConditionLimitValue conditionLimitValue) {
  221 + productLimitInfo.setProductIdExclude(conditionLimitValue.getLimitValues());
  222 + }
  223 +
  224 + @Override
  225 + public boolean isMatch(ShoppingProductInfo shoppingProductInfo, ConditionLimitValue conditionLimitValue) {
  226 + //排除商品
  227 + return CollectionUtils.isNotEmpty(conditionLimitValue.getLimitValues())
  228 + && !conditionLimitValue.getLimitValues().contains(shoppingProductInfo.getProductId());
  229 + }
  230 +
  231 + }
  232 +}
1 -package com.yohoufo.common.helper;  
2 -  
3 -import com.google.common.collect.Lists;  
4 -import com.yohobuy.ufo.model.order.bo.ShoppingProductInfo;  
5 -import com.yohobuy.ufo.model.promotion.constant.CouponProductLimitTypeEnum;  
6 -import com.yohobuy.ufo.model.promotion.request.ProductLimitValueBo;  
7 -import com.yohobuy.ufo.model.promotion.response.ProductLimitInfo;  
8 -import org.apache.commons.collections.CollectionUtils;  
9 -import org.slf4j.Logger;  
10 -import org.slf4j.LoggerFactory;  
11 -import java.util.Arrays;  
12 -import java.util.List;  
13 -import java.util.Optional;  
14 -import java.util.stream.Collectors;  
15 -  
16 -public class ProductLimitCollector {  
17 -  
18 - private final static Logger logger = LoggerFactory.getLogger(ProductLimitCollector.class);  
19 -  
20 - private static List<LimitValueHandler> LIMIT_VALUES_LIST = Lists.newArrayList();  
21 -  
22 - static{  
23 - LIMIT_VALUES_LIST.add(new NoLimitValueHandler());  
24 - LIMIT_VALUES_LIST.add(new BrandLimitValueHandler());  
25 - LIMIT_VALUES_LIST.add(new CategoryLimitValueHandler());  
26 - LIMIT_VALUES_LIST.add(new SeriesLimitValueHandler());  
27 - LIMIT_VALUES_LIST.add(new ProductIncludeLimitValueHandler());  
28 - LIMIT_VALUES_LIST.add(new ProductExcludeLimitValueHandler());  
29 - }  
30 -  
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(String couponCode,  
62 - ShoppingProductInfo shoppingProductInfo, ProductLimitInfo productLimitInfo){  
63 - for (LimitValueHandler limitValueHandler : LIMIT_VALUES_LIST){  
64 -  
65 - if (!limitValueHandler.isMatch(shoppingProductInfo, productLimitInfo)){  
66 - logger.info("[{}] ProductLimitRuleMatcher Condition <<< {},{}; Result <<< [{}] not matched",  
67 - couponCode, shoppingProductInfo, productLimitInfo, limitValueHandler.getLimitValue());  
68 - return false;  
69 - }  
70 - }  
71 -  
72 - logger.info("[{}] ProductLimitRuleMatcher Condition <<< {},{}; Result <<< matched", couponCode, shoppingProductInfo, productLimitInfo);  
73 -  
74 - return true;  
75 - }  
76 -  
77 -  
78 - private static List<Integer> covertProductLimitValueList(String productLimitValue) {  
79 - List<Integer> limitValues = Lists.newArrayList();  
80 - try{  
81 - limitValues = Arrays.stream(productLimitValue.split(",")).map(Integer::valueOf).collect(Collectors.toList());  
82 - }catch (Exception e){  
83 - logger.warn("error happened. productLimitValue {}", productLimitValue);  
84 - }  
85 -  
86 - return limitValues;  
87 -  
88 - }  
89 -  
90 -  
91 - public interface LimitValueHandler {  
92 - /**  
93 - * 商品限制类型  
94 - * @return  
95 - */  
96 - CouponProductLimitTypeEnum getLimitValue();  
97 -  
98 - /**  
99 - * 商品限制的值  
100 - * @param productIds  
101 - * @param productLimitValue  
102 - */  
103 - void setProductLimitValue(ProductLimitInfo productLimitInfo, List<Integer> productIds, String productLimitValue);  
104 -  
105 - /**  
106 - * 是否满足使用条件  
107 - * @param productLimitInfo  
108 - * @return  
109 - */  
110 - boolean isMatch(ShoppingProductInfo shoppingProductInfo, ProductLimitInfo productLimitInfo);  
111 - }  
112 -  
113 - private static class NoLimitValueHandler implements LimitValueHandler {  
114 -  
115 - @Override  
116 - public CouponProductLimitTypeEnum getLimitValue() {  
117 - return CouponProductLimitTypeEnum.NON;  
118 - }  
119 -  
120 - @Override  
121 - public void setProductLimitValue(ProductLimitInfo productLimitInfo, List<Integer> productIds, String productLimitValue) {  
122 -  
123 - }  
124 -  
125 -  
126 - @Override  
127 - public boolean isMatch(ShoppingProductInfo shoppingProductInfo, ProductLimitInfo productLimitInfo) {  
128 - return true;  
129 - }  
130 -  
131 - }  
132 -  
133 -  
134 -  
135 - private static class BrandLimitValueHandler implements LimitValueHandler {  
136 -  
137 - @Override  
138 - public CouponProductLimitTypeEnum getLimitValue() {  
139 - return CouponProductLimitTypeEnum.SPECIFIC_BRAND;  
140 - }  
141 -  
142 - @Override  
143 - public void setProductLimitValue(ProductLimitInfo productLimitInfo, List<Integer> productIds, String productLimitValue) {  
144 - productLimitInfo.setBrandInclude(covertProductLimitValueList(productLimitValue));  
145 - }  
146 -  
147 - public boolean isMatch(ShoppingProductInfo shoppingProductInfo, ProductLimitInfo productLimitInfo) {  
148 -  
149 - return CollectionUtils.isEmpty(productLimitInfo.getBrandInclude()) || (CollectionUtils.isNotEmpty(productLimitInfo.getBrandInclude())  
150 - && productLimitInfo.getBrandInclude().contains(shoppingProductInfo.getBrandId()));  
151 - }  
152 -  
153 - }  
154 -  
155 - private static class CategoryLimitValueHandler implements LimitValueHandler {  
156 -  
157 - @Override  
158 - public CouponProductLimitTypeEnum getLimitValue() {  
159 - return CouponProductLimitTypeEnum.SPECIFIC_CATEGORY;  
160 - }  
161 -  
162 - @Override  
163 - public void setProductLimitValue(ProductLimitInfo productLimitInfo, List<Integer> productIds, String productLimitValue) {  
164 - productLimitInfo.setCategoryInclude(covertProductLimitValueList(productLimitValue));  
165 - }  
166 -  
167 -  
168 - @Override  
169 - public boolean isMatch(ShoppingProductInfo shoppingProductInfo, ProductLimitInfo productLimitInfo) {  
170 -  
171 - return CollectionUtils.isEmpty(productLimitInfo.getCategoryInclude()) ||  
172 - (CollectionUtils.isNotEmpty(productLimitInfo.getCategoryInclude())  
173 - && productLimitInfo.getCategoryInclude().contains(shoppingProductInfo.getCategoryId()));  
174 -  
175 - }  
176 -  
177 - }  
178 -  
179 - private static class SeriesLimitValueHandler implements LimitValueHandler {  
180 -  
181 - @Override  
182 - public CouponProductLimitTypeEnum getLimitValue() {  
183 - return CouponProductLimitTypeEnum.SPECIFIC_SERIES;  
184 - }  
185 -  
186 - @Override  
187 - public void setProductLimitValue(ProductLimitInfo productLimitInfo, List<Integer> productIds, String productLimitValue) {  
188 - productLimitInfo.setSeriesInclude((covertProductLimitValueList(productLimitValue)));  
189 - }  
190 -  
191 - @Override  
192 - public boolean isMatch(ShoppingProductInfo shoppingProductInfo, ProductLimitInfo productLimitInfo) {  
193 - return CollectionUtils.isEmpty(productLimitInfo.getSeriesInclude())  
194 - || (CollectionUtils.isNotEmpty(productLimitInfo.getSeriesInclude())  
195 - && productLimitInfo.getSeriesInclude().contains(shoppingProductInfo.getSeriesId()));  
196 - }  
197 -  
198 - }  
199 -  
200 - private static class ProductIncludeLimitValueHandler implements LimitValueHandler {  
201 -  
202 - @Override  
203 - public CouponProductLimitTypeEnum getLimitValue() {  
204 - return CouponProductLimitTypeEnum.SPECIFIC_PRODUCT;  
205 - }  
206 -  
207 - @Override  
208 - public void setProductLimitValue(ProductLimitInfo productLimitInfo, List<Integer> productIds, String productLimitValue) {  
209 - productLimitInfo.setProductIdInclude(productIds);  
210 - }  
211 -  
212 -  
213 - @Override  
214 - public boolean isMatch(ShoppingProductInfo shoppingProductInfo, ProductLimitInfo productLimitInfo) {  
215 -  
216 - //包含商品  
217 - return CollectionUtils.isEmpty(productLimitInfo.getProductIdInclude())  
218 - || (CollectionUtils.isNotEmpty(productLimitInfo.getProductIdInclude())  
219 - && productLimitInfo.getProductIdInclude().contains(shoppingProductInfo.getProductId()));  
220 - }  
221 -  
222 - }  
223 -  
224 - private static class ProductExcludeLimitValueHandler implements LimitValueHandler {  
225 -  
226 - @Override  
227 - public CouponProductLimitTypeEnum getLimitValue() {  
228 - return CouponProductLimitTypeEnum.EXCLUDE_PRODUCT;  
229 - }  
230 -  
231 - @Override  
232 - public void setProductLimitValue(ProductLimitInfo productLimitInfo, List<Integer> productIds, String productLimitValue) {  
233 - productLimitInfo.setProductIdExclude(productIds);  
234 - }  
235 -  
236 - @Override  
237 - public boolean isMatch(ShoppingProductInfo shoppingProductInfo, ProductLimitInfo productLimitInfo) {  
238 - //排除商品  
239 - return CollectionUtils.isEmpty(productLimitInfo.getProductIdExclude())  
240 - || (CollectionUtils.isNotEmpty(productLimitInfo.getProductIdExclude())  
241 - && !productLimitInfo.getProductIdExclude().contains(shoppingProductInfo.getProductId()));  
242 - }  
243 -  
244 - }  
245 -}  
@@ -5,18 +5,20 @@ import com.yohobuy.ufo.model.order.constants.OrderConstant; @@ -5,18 +5,20 @@ import com.yohobuy.ufo.model.order.constants.OrderConstant;
5 import com.yohobuy.ufo.model.order.constants.RegionEnum; 5 import com.yohobuy.ufo.model.order.constants.RegionEnum;
6 import com.yohobuy.ufo.model.order.constants.SkupType; 6 import com.yohobuy.ufo.model.order.constants.SkupType;
7 import com.yohobuy.ufo.model.promotion.UserCouponsBo; 7 import com.yohobuy.ufo.model.promotion.UserCouponsBo;
8 -import com.yohobuy.ufo.model.promotion.constant.CouponProductLimitTypeEnum;  
9 import com.yohobuy.ufo.model.promotion.constant.CouponTypeEnum; 8 import com.yohobuy.ufo.model.promotion.constant.CouponTypeEnum;
10 import com.yohobuy.ufo.model.promotion.constant.CouponUseLimitTypeEnum; 9 import com.yohobuy.ufo.model.promotion.constant.CouponUseLimitTypeEnum;
11 -import com.yohoufo.common.helper.ProductLimitCollector; 10 +import com.yohoufo.common.helper.ConditionLimitValueProcessor;
12 import com.yohoufo.order.charge.model.ChargeGoods; 11 import com.yohoufo.order.charge.model.ChargeGoods;
13 import com.yohoufo.order.charge.model.CouponMatchResult; 12 import com.yohoufo.order.charge.model.CouponMatchResult;
14 import com.yohoufo.order.utils.LoggerUtils; 13 import com.yohoufo.order.utils.LoggerUtils;
15 -import org.apache.commons.collections.CollectionUtils; 14 +import net.sf.oval.guard.Post;
16 import org.apache.commons.lang3.StringUtils; 15 import org.apache.commons.lang3.StringUtils;
17 import org.slf4j.Logger; 16 import org.slf4j.Logger;
  17 +import org.springframework.beans.factory.InitializingBean;
  18 +import org.springframework.beans.factory.annotation.Autowired;
18 import org.springframework.stereotype.Component; 19 import org.springframework.stereotype.Component;
19 20
  21 +import javax.annotation.PostConstruct;
20 import java.math.BigDecimal; 22 import java.math.BigDecimal;
21 import java.util.*; 23 import java.util.*;
22 24
@@ -25,25 +27,15 @@ import java.util.*; @@ -25,25 +27,15 @@ import java.util.*;
25 * 券匹配 27 * 券匹配
26 */ 28 */
27 @Component 29 @Component
28 -public class CouponRuleMatcher { 30 +public class CouponRuleMatcher implements InitializingBean {
29 31
30 private final Logger logger = LoggerUtils.getBuyerOrderLogger(); 32 private final Logger logger = LoggerUtils.getBuyerOrderLogger();
31 33
32 - private static List<IRuleMatcher> RULE_MATCHERS = new LinkedList<>(); 34 + private List<IRuleMatcher> RULE_MATCHERS = new LinkedList<>();
33 35
34 - static {  
35 - // 商品匹配  
36 - RULE_MATCHERS.add(new ProductLimitRuleMatcher());  
37 -  
38 - // 金额匹配  
39 - RULE_MATCHERS.add(new UseLimitRuleMatcher());  
40 -  
41 - // skup type 匹配  
42 - RULE_MATCHERS.add(new SkupTypeRuleMatcher()); 36 + @Autowired
  37 + ConditionLimitValueProcessor conditionLimitValueProcessor;
43 38
44 - // 是否寄存决定运费券  
45 - RULE_MATCHERS.add(new DepositRequirementRuleMatcher());  
46 - }  
47 39
48 /** 40 /**
49 * 匹配 41 * 匹配
@@ -83,6 +75,21 @@ public class CouponRuleMatcher { @@ -83,6 +75,21 @@ public class CouponRuleMatcher {
83 return matchResult; 75 return matchResult;
84 } 76 }
85 77
  78 + @Override
  79 + public void afterPropertiesSet() throws Exception {
  80 + // 商品匹配
  81 + RULE_MATCHERS.add(new ProductLimitRuleMatcher());
  82 +
  83 + // 金额匹配
  84 + RULE_MATCHERS.add(new UseLimitRuleMatcher());
  85 +
  86 + // skup type 匹配
  87 + RULE_MATCHERS.add(new SkupTypeRuleMatcher());
  88 +
  89 + // 是否寄存决定运费券
  90 + RULE_MATCHERS.add(new DepositRequirementRuleMatcher());
  91 + }
  92 +
86 private interface IRuleMatcher { 93 private interface IRuleMatcher {
87 /** 94 /**
88 * 规则名称 95 * 规则名称
@@ -101,7 +108,7 @@ public class CouponRuleMatcher { @@ -101,7 +108,7 @@ public class CouponRuleMatcher {
101 boolean match(ChargeGoods chargeGoods, UserCouponsBo couponsBo); 108 boolean match(ChargeGoods chargeGoods, UserCouponsBo couponsBo);
102 } 109 }
103 110
104 - private static class ProductLimitRuleMatcher implements IRuleMatcher { 111 + private class ProductLimitRuleMatcher implements IRuleMatcher {
105 @Override 112 @Override
106 public String ruleName() { 113 public String ruleName() {
107 return "ProductLimit"; 114 return "ProductLimit";
@@ -110,12 +117,12 @@ public class CouponRuleMatcher { @@ -110,12 +117,12 @@ public class CouponRuleMatcher {
110 @Override 117 @Override
111 public boolean match(ChargeGoods chargeGoods, UserCouponsBo couponsBo) { 118 public boolean match(ChargeGoods chargeGoods, UserCouponsBo couponsBo) {
112 119
113 - return ProductLimitCollector.match(couponsBo.getCouponCode() ,chargeGoods.getShoppingProductInfo(), couponsBo.getProductLimitInfo()); 120 + return conditionLimitValueProcessor.match(couponsBo.getCouponCode() ,chargeGoods.getShoppingProductInfo(), couponsBo.getConditionLimitValues());
114 121
115 } 122 }
116 } 123 }
117 124
118 - private static class UseLimitRuleMatcher implements IRuleMatcher { 125 + private class UseLimitRuleMatcher implements IRuleMatcher {
119 @Override 126 @Override
120 public String ruleName() { 127 public String ruleName() {
121 return "UseLimit"; 128 return "UseLimit";
@@ -137,7 +144,7 @@ public class CouponRuleMatcher { @@ -137,7 +144,7 @@ public class CouponRuleMatcher {
137 } 144 }
138 } 145 }
139 146
140 - private static class SkupTypeRuleMatcher implements IRuleMatcher { 147 + private class SkupTypeRuleMatcher implements IRuleMatcher {
141 148
142 private SkupForbidRuleMatcher skupForbidRuleMatcher = new SkupForbidRuleMatcher(); 149 private SkupForbidRuleMatcher skupForbidRuleMatcher = new SkupForbidRuleMatcher();
143 private SkupAllowRuleMatcher skupAllowRuleMatcher = new SkupAllowRuleMatcher(); 150 private SkupAllowRuleMatcher skupAllowRuleMatcher = new SkupAllowRuleMatcher();
@@ -159,7 +166,7 @@ public class CouponRuleMatcher { @@ -159,7 +166,7 @@ public class CouponRuleMatcher {
159 } 166 }
160 } 167 }
161 168
162 - private static class SkupForbidRuleMatcher implements IRuleMatcher { 169 + private class SkupForbidRuleMatcher implements IRuleMatcher {
163 @Override 170 @Override
164 public String ruleName() { 171 public String ruleName() {
165 return "SkupForbid"; 172 return "SkupForbid";
@@ -185,7 +192,7 @@ public class CouponRuleMatcher { @@ -185,7 +192,7 @@ public class CouponRuleMatcher {
185 } 192 }
186 } 193 }
187 194
188 - private static class SkupAllowRuleMatcher implements IRuleMatcher{ 195 + private class SkupAllowRuleMatcher implements IRuleMatcher{
189 196
190 @Override 197 @Override
191 public String ruleName() { 198 public String ruleName() {
@@ -231,7 +238,7 @@ public class CouponRuleMatcher { @@ -231,7 +238,7 @@ public class CouponRuleMatcher {
231 } 238 }
232 } 239 }
233 240
234 - private static class DepositRequirementRuleMatcher implements IRuleMatcher{ 241 + private class DepositRequirementRuleMatcher implements IRuleMatcher{
235 242
236 243
237 @Override 244 @Override
@@ -8,7 +8,7 @@ import com.yoho.core.rest.client.ServiceCaller; @@ -8,7 +8,7 @@ import com.yoho.core.rest.client.ServiceCaller;
8 import com.yoho.core.rest.exception.ServiceNotAvaibleException; 8 import com.yoho.core.rest.exception.ServiceNotAvaibleException;
9 import com.yohobuy.ufo.model.enums.StorageTypeEnum; 9 import com.yohobuy.ufo.model.enums.StorageTypeEnum;
10 import com.yohobuy.ufo.model.promotion.response.CouponInfo; 10 import com.yohobuy.ufo.model.promotion.response.CouponInfo;
11 -import com.yohobuy.ufo.model.promotion.response.ProductLimitInfo; 11 +import com.yohobuy.ufo.model.promotion.ConditionLimitValueReplacement;
12 import com.yohoufo.common.helper.ImageUrlAssist; 12 import com.yohoufo.common.helper.ImageUrlAssist;
13 import com.yohoufo.common.utils.ArrayListUtil; 13 import com.yohoufo.common.utils.ArrayListUtil;
14 import com.yohoufo.common.utils.MathUtil; 14 import com.yohoufo.common.utils.MathUtil;
@@ -284,7 +284,7 @@ public class ProductSearchAssistService { @@ -284,7 +284,7 @@ public class ProductSearchAssistService {
284 return; 284 return;
285 } 285 }
286 286
287 - ProductLimitInfo pLimitInfo = info.getProductLimitInfo(); 287 + ConditionLimitValueReplacement pLimitInfo = info.getProductLimitInfo();
288 288
289 req.setId(StringUtils.isEmpty(info.getContainsProductIds()) ? ArrayListUtil.listToStr(pLimitInfo.getProductIdInclude(), ",") : info.getContainsProductIds()) 289 req.setId(StringUtils.isEmpty(info.getContainsProductIds()) ? ArrayListUtil.listToStr(pLimitInfo.getProductIdInclude(), ",") : info.getContainsProductIds())
290 .setNot_id(StringUtils.isEmpty(info.getExcludeProductIds()) ? ArrayListUtil.listToStr(pLimitInfo.getProductIdExclude(), ",") : info.getExcludeProductIds()) 290 .setNot_id(StringUtils.isEmpty(info.getExcludeProductIds()) ? ArrayListUtil.listToStr(pLimitInfo.getProductIdExclude(), ",") : info.getExcludeProductIds())
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.yohobuy.ufo.model.promotion.ConditionLimitValue;
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.*;
7 -import com.yohobuy.ufo.model.promotion.request.ProductLimitValueBo;  
8 import com.yohobuy.ufo.model.promotion.response.CouponInfo; 8 import com.yohobuy.ufo.model.promotion.response.CouponInfo;
9 -import com.yohobuy.ufo.model.promotion.response.ProductLimitInfo;  
10 -import com.yohoufo.common.helper.ProductLimitCollector;  
11 import com.yohoufo.common.utils.BigDecimalHelper; 9 import com.yohoufo.common.utils.BigDecimalHelper;
12 import com.yohoufo.common.utils.DateUtil; 10 import com.yohoufo.common.utils.DateUtil;
13 import com.yohoufo.dal.promotion.model.Coupon; 11 import com.yohoufo.dal.promotion.model.Coupon;
14 import com.yohoufo.dal.promotion.model.CouponAndType; 12 import com.yohoufo.dal.promotion.model.CouponAndType;
15 import com.yohoufo.dal.promotion.model.CouponType; 13 import com.yohoufo.dal.promotion.model.CouponType;
16 import com.yohoufo.dal.promotion.model.UserCoupon; 14 import com.yohoufo.dal.promotion.model.UserCoupon;
  15 +import com.yohoufo.promotion.helper.ConditionLimitValueBuilder;
17 import org.apache.commons.lang3.StringUtils; 16 import org.apache.commons.lang3.StringUtils;
18 import org.slf4j.Logger; 17 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory; 18 import org.slf4j.LoggerFactory;
@@ -22,7 +21,6 @@ import java.text.MessageFormat; @@ -22,7 +21,6 @@ import java.text.MessageFormat;
22 import java.util.Arrays; 21 import java.util.Arrays;
23 import java.util.List; 22 import java.util.List;
24 import java.util.Objects; 23 import java.util.Objects;
25 -import java.util.stream.Collectors;  
26 24
27 public class CouponConvert { 25 public class CouponConvert {
28 //3天的秒数 26 //3天的秒数
@@ -31,15 +29,17 @@ public class CouponConvert { @@ -31,15 +29,17 @@ public class CouponConvert {
31 29
32 private final static Logger logger = LoggerFactory.getLogger(CouponConvert.class); 30 private final static Logger logger = LoggerFactory.getLogger(CouponConvert.class);
33 31
  32 +
  33 +
34 /** 34 /**
35 * 订单默认使用 35 * 订单默认使用
36 * @param userCoupon 36 * @param userCoupon
37 * @param coupon 37 * @param coupon
38 * @param couponType 38 * @param couponType
39 - * @param productLimitValueBo 39 + * @param conditionLimitValueBo
40 * @return 40 * @return
41 */ 41 */
42 - public static UserCouponsBo covertCouponBo(UserCoupon userCoupon, Coupon coupon, CouponType couponType, List<ProductLimitValueBo> productLimitValueBo){ 42 + public static UserCouponsBo covertCouponBo(UserCoupon userCoupon, Coupon coupon, CouponType couponType, List<ConditionLimitValue> conditionLimitValues){
43 43
44 UserCouponsBo couponBo = new UserCouponsBo(); 44 UserCouponsBo couponBo = new UserCouponsBo();
45 45
@@ -47,7 +47,7 @@ public class CouponConvert { @@ -47,7 +47,7 @@ public class CouponConvert {
47 47
48 couponBo.setCouponAmount(coupon.getCouponAmount()); 48 couponBo.setCouponAmount(coupon.getCouponAmount());
49 couponBo.setCouponName(coupon.getCouponName()); 49 couponBo.setCouponName(coupon.getCouponName());
50 - couponBo.setProductLimitType(coupon.getProductLimitType()!=null ? String.valueOf(coupon.getProductLimitType()):""); 50 +// couponBo.setProductLimitType(coupon.getProductLimitType()!=null ? String.valueOf(coupon.getProductLimitType()):"");
51 couponBo.setUseLimitType(coupon.getUseLimitType()!=null ? String.valueOf(coupon.getUseLimitType()) : ""); 51 couponBo.setUseLimitType(coupon.getUseLimitType()!=null ? String.valueOf(coupon.getUseLimitType()) : "");
52 couponBo.setUseLimitValue(coupon.getUseLimitValue()!=null ? String.valueOf(coupon.getUseLimitValue()) : ""); 52 couponBo.setUseLimitValue(coupon.getUseLimitValue()!=null ? String.valueOf(coupon.getUseLimitValue()) : "");
53 53
@@ -74,9 +74,7 @@ public class CouponConvert { @@ -74,9 +74,7 @@ public class CouponConvert {
74 couponBo.setCouponTypeName(couponType.getCaption()); 74 couponBo.setCouponTypeName(couponType.getCaption());
75 } 75 }
76 76
77 -  
78 - ProductLimitInfo productLimitInfo = ProductLimitCollector.getProductLimitInfo(productLimitValueBo, coupon.getProductLimitType(), coupon.getProductLimitValue());  
79 - couponBo.setProductLimitInfo(productLimitInfo); 77 + couponBo.setConditionLimitValues(ConditionLimitValueBuilder.getAllConditionLimit(conditionLimitValues, coupon));
80 78
81 couponBo.setBusinessClient(coupon.getBusinessClient()); 79 couponBo.setBusinessClient(coupon.getBusinessClient());
82 80
  1 +package com.yohoufo.promotion.helper;
  2 +
  3 +import com.google.common.collect.Lists;
  4 +import com.yohobuy.ufo.model.promotion.ConditionLimitValue;
  5 +import com.yohoufo.dal.promotion.model.Coupon;
  6 +import org.apache.commons.collections.CollectionUtils;
  7 +
  8 +import java.util.Arrays;
  9 +import java.util.List;
  10 +import java.util.stream.Collectors;
  11 +
  12 +public class ConditionLimitValueBuilder {
  13 +
  14 + /**
  15 + * 获取所有的限制
  16 + * @param conditionLimitValue
  17 + * @param coupon
  18 + */
  19 + public static List<ConditionLimitValue> getAllConditionLimit(List<ConditionLimitValue> conditionLimitValue, Coupon coupon){
  20 + if (CollectionUtils.isEmpty(conditionLimitValue)){
  21 + conditionLimitValue = Lists.newArrayList();
  22 + }
  23 +
  24 + List<Integer> conditionLimitType = conditionLimitValue.stream().map(ConditionLimitValue::getLimitType).collect(Collectors.toList());
  25 + if (conditionLimitType.contains(coupon.getProductLimitType())){
  26 + return conditionLimitValue;
  27 + }
  28 +
  29 + // 不存在的限制类型才能继续添加到 限制条件集合中
  30 + conditionLimitValue.add(new ConditionLimitValue(coupon.getProductLimitType(),
  31 + Arrays.stream(coupon.getProductLimitValue().split(",")).map(Integer::valueOf).collect(Collectors.toList())));
  32 +
  33 + return conditionLimitValue;
  34 + }
  35 +
  36 +}
1 package com.yohoufo.promotion.service; 1 package com.yohoufo.promotion.service;
2 2
3 -import com.yohobuy.ufo.model.promotion.request.ProductLimitValueBo; 3 +import com.yohobuy.ufo.model.promotion.ConditionLimitValue;
4 import com.yohoufo.dal.promotion.model.Coupon; 4 import com.yohoufo.dal.promotion.model.Coupon;
5 import com.yohoufo.dal.promotion.model.CouponAndType; 5 import com.yohoufo.dal.promotion.model.CouponAndType;
6 import com.yohoufo.dal.promotion.model.CouponType; 6 import com.yohoufo.dal.promotion.model.CouponType;
@@ -45,5 +45,5 @@ public interface ICouponCacheService { @@ -45,5 +45,5 @@ public interface ICouponCacheService {
45 * @param productLimitCouponIds 45 * @param productLimitCouponIds
46 * @return 46 * @return
47 */ 47 */
48 - public Map<Integer, List<ProductLimitValueBo>> getLimitProductValueWithCache(List<Integer> productLimitCouponIds); 48 + public Map<Integer, List<ConditionLimitValue>> getLimitProductValueWithCache(List<Integer> productLimitCouponIds);
49 } 49 }
@@ -4,7 +4,7 @@ package com.yohoufo.promotion.service.impl; @@ -4,7 +4,7 @@ package com.yohoufo.promotion.service.impl;
4 import com.google.common.collect.Lists; 4 import com.google.common.collect.Lists;
5 import com.google.common.collect.Maps; 5 import com.google.common.collect.Maps;
6 import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder; 6 import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
7 -import com.yohobuy.ufo.model.promotion.request.ProductLimitValueBo; 7 +import com.yohobuy.ufo.model.promotion.ConditionLimitValue;
8 import com.yohoufo.common.cache.CacheClient; 8 import com.yohoufo.common.cache.CacheClient;
9 import com.yohoufo.dal.promotion.CouponMapper; 9 import com.yohoufo.dal.promotion.CouponMapper;
10 import com.yohoufo.dal.promotion.CouponProductLimitMapper; 10 import com.yohoufo.dal.promotion.CouponProductLimitMapper;
@@ -118,18 +118,18 @@ public class CouponCacheServiceImpl implements ICouponCacheService { @@ -118,18 +118,18 @@ public class CouponCacheServiceImpl implements ICouponCacheService {
118 * @param productLimitCouponIds 118 * @param productLimitCouponIds
119 * @return 119 * @return
120 */ 120 */
121 - public Map<Integer, List<ProductLimitValueBo>> getLimitProductValueWithCache(List<Integer> productLimitCouponIds) {  
122 - Map<Integer, List<ProductLimitValueBo>> result = Maps.newHashMap(); 121 + public Map<Integer, List<ConditionLimitValue>> getLimitProductValueWithCache(List<Integer> productLimitCouponIds) {
  122 + Map<Integer, List<ConditionLimitValue>> result = Maps.newHashMap();
123 123
124 List<Integer> missCouponIdList = Lists.newArrayList(); 124 List<Integer> missCouponIdList = Lists.newArrayList();
125 125
126 for (Integer couponId : productLimitCouponIds){ 126 for (Integer couponId : productLimitCouponIds){
127 - List<ProductLimitValueBo> productIds = cacheClient.range(KeyBuilder.buildCouponLimitProductValueCacheKey(couponId), ProductLimitValueBo.class,0, -1); 127 + List<ConditionLimitValue> limitValues = cacheClient.range(KeyBuilder.buildCouponLimitProductValueCacheKey(couponId), ConditionLimitValue.class,0, -1);
128 128
129 - if (CollectionUtils.isEmpty(productIds)){ 129 + if (CollectionUtils.isEmpty(limitValues)){
130 missCouponIdList.add(couponId); 130 missCouponIdList.add(couponId);
131 }else{ 131 }else{
132 - result.put(couponId, productIds); 132 + result.put(couponId, limitValues);
133 } 133 }
134 } 134 }
135 135
@@ -137,7 +137,7 @@ public class CouponCacheServiceImpl implements ICouponCacheService { @@ -137,7 +137,7 @@ public class CouponCacheServiceImpl implements ICouponCacheService {
137 return result; 137 return result;
138 } 138 }
139 139
140 - Map<Integer, List<ProductLimitValueBo>> resultCache = getAssociatedProductLimitValueMap(missCouponIdList); 140 + Map<Integer, List<ConditionLimitValue>> resultCache = getAssociatedProductLimitValueMap(missCouponIdList);
141 result.putAll(resultCache); 141 result.putAll(resultCache);
142 142
143 for (Integer key : resultCache.keySet()){ 143 for (Integer key : resultCache.keySet()){
@@ -154,7 +154,7 @@ public class CouponCacheServiceImpl implements ICouponCacheService { @@ -154,7 +154,7 @@ public class CouponCacheServiceImpl implements ICouponCacheService {
154 * @param couponIdList 154 * @param couponIdList
155 * @return 155 * @return
156 */ 156 */
157 - private Map<Integer, List<ProductLimitValueBo>> getAssociatedProductLimitValueMap(List<Integer> couponIdList){ 157 + private Map<Integer, List<ConditionLimitValue>> getAssociatedProductLimitValueMap(List<Integer> couponIdList){
158 158
159 159
160 List<CouponProductLimit> couponProductLimitList = couponProductLimitMapper.selectByCouponIds(couponIdList); 160 List<CouponProductLimit> couponProductLimitList = couponProductLimitMapper.selectByCouponIds(couponIdList);
@@ -162,21 +162,19 @@ public class CouponCacheServiceImpl implements ICouponCacheService { @@ -162,21 +162,19 @@ public class CouponCacheServiceImpl implements ICouponCacheService {
162 Map<Integer, List<CouponProductLimit>> map = couponProductLimitList.stream().collect(Collectors.groupingBy(CouponProductLimit::getCouponId)); 162 Map<Integer, List<CouponProductLimit>> map = couponProductLimitList.stream().collect(Collectors.groupingBy(CouponProductLimit::getCouponId));
163 163
164 // key=couponId, value= 164 // key=couponId, value=
165 - Map<Integer, List<ProductLimitValueBo>> productLimitValueBoMap = Maps.newHashMap(); 165 + Map<Integer, List<ConditionLimitValue>> productLimitValueBoMap = Maps.newHashMap();
166 166
167 for (Integer couponId : map.keySet()){ 167 for (Integer couponId : map.keySet()){
168 168
169 - List<ProductLimitValueBo> productLimitValueBos = Lists.newArrayList(); 169 + List<ConditionLimitValue> conditionLimitValues = Lists.newArrayList();
170 170
171 // key=limitType, value= 171 // key=limitType, value=
172 Map<Integer, List<CouponProductLimit>> typeToItem = map.get(couponId).stream().collect(Collectors.groupingBy(CouponProductLimit::getLimitType)); 172 Map<Integer, List<CouponProductLimit>> typeToItem = map.get(couponId).stream().collect(Collectors.groupingBy(CouponProductLimit::getLimitType));
173 for (Integer type : typeToItem.keySet()){ 173 for (Integer type : typeToItem.keySet()){
174 - productLimitValueBos.add(ProductLimitValueBo.builder()  
175 - .limitType(type)  
176 - .productIds(typeToItem.get(type).stream().map(CouponProductLimit::getProductId).collect(Collectors.toList())).build()); 174 + conditionLimitValues.add(new ConditionLimitValue(type, typeToItem.get(type).stream().map(CouponProductLimit::getProductId).collect(Collectors.toList())));
177 } 175 }
178 176
179 - productLimitValueBoMap.put(couponId, productLimitValueBos); 177 + productLimitValueBoMap.put(couponId, conditionLimitValues);
180 178
181 } 179 }
182 180
@@ -12,17 +12,17 @@ import com.yohobuy.ufo.model.promotion.UserCouponsListBo; @@ -12,17 +12,17 @@ import com.yohobuy.ufo.model.promotion.UserCouponsListBo;
12 import com.yohobuy.ufo.model.promotion.constant.CouponProductLimitTypeEnum; 12 import com.yohobuy.ufo.model.promotion.constant.CouponProductLimitTypeEnum;
13 import com.yohobuy.ufo.model.promotion.constant.CouponUseStatusEnum; 13 import com.yohobuy.ufo.model.promotion.constant.CouponUseStatusEnum;
14 import com.yohobuy.ufo.model.promotion.constant.CouponsStatusEnum; 14 import com.yohobuy.ufo.model.promotion.constant.CouponsStatusEnum;
15 -import com.yohobuy.ufo.model.promotion.request.ProductLimitValueBo; 15 +import com.yohobuy.ufo.model.promotion.ConditionLimitValue;
16 import com.yohoufo.dal.promotion.CouponProductLimitMapper; 16 import com.yohoufo.dal.promotion.CouponProductLimitMapper;
  17 +import com.yohoufo.promotion.helper.ConditionLimitValueBuilder;
17 import com.yohoufo.promotion.model.CouponReceiveChannel; 18 import com.yohoufo.promotion.model.CouponReceiveChannel;
18 import com.yohobuy.ufo.model.promotion.request.CouponSendType; 19 import com.yohobuy.ufo.model.promotion.request.CouponSendType;
19 import com.yohobuy.ufo.model.promotion.request.UserCouponListReq; 20 import com.yohobuy.ufo.model.promotion.request.UserCouponListReq;
20 import com.yohobuy.ufo.model.promotion.response.CouponInfo; 21 import com.yohobuy.ufo.model.promotion.response.CouponInfo;
21 import com.yohobuy.ufo.model.promotion.response.CouponInfoListBo; 22 import com.yohobuy.ufo.model.promotion.response.CouponInfoListBo;
22 import com.yohobuy.ufo.model.promotion.response.CouponSendBo; 23 import com.yohobuy.ufo.model.promotion.response.CouponSendBo;
23 -import com.yohobuy.ufo.model.promotion.response.ProductLimitInfo;  
24 import com.yohoufo.common.exception.UfoServiceException; 24 import com.yohoufo.common.exception.UfoServiceException;
25 -import com.yohoufo.common.helper.ProductLimitCollector; 25 +import com.yohoufo.common.helper.ConditionLimitValueProcessor;
26 import com.yohoufo.common.lock.RedisLock; 26 import com.yohoufo.common.lock.RedisLock;
27 import com.yohoufo.common.lock.RedisLockFactory; 27 import com.yohoufo.common.lock.RedisLockFactory;
28 import com.yohoufo.common.utils.DateUtil; 28 import com.yohoufo.common.utils.DateUtil;
@@ -40,7 +40,6 @@ import org.slf4j.LoggerFactory; @@ -40,7 +40,6 @@ import org.slf4j.LoggerFactory;
40 import org.springframework.beans.factory.annotation.Autowired; 40 import org.springframework.beans.factory.annotation.Autowired;
41 import org.springframework.stereotype.Service; 41 import org.springframework.stereotype.Service;
42 42
43 -import java.lang.reflect.Array;  
44 import java.time.LocalDate; 43 import java.time.LocalDate;
45 import java.time.LocalDateTime; 44 import java.time.LocalDateTime;
46 import java.time.LocalTime; 45 import java.time.LocalTime;
@@ -74,6 +73,9 @@ public class CouponServiceImpl implements ICouponService { @@ -74,6 +73,9 @@ public class CouponServiceImpl implements ICouponService {
74 @Autowired 73 @Autowired
75 private RedisLockFactory redisLockFactory; 74 private RedisLockFactory redisLockFactory;
76 75
  76 + @Autowired
  77 + ConditionLimitValueProcessor conditionLimitValueProcessor;
  78 +
77 79
78 private final Logger logger = LoggerFactory.getLogger(getClass()); 80 private final Logger logger = LoggerFactory.getLogger(getClass());
79 81
@@ -103,14 +105,12 @@ public class CouponServiceImpl implements ICouponService { @@ -103,14 +105,12 @@ public class CouponServiceImpl implements ICouponService {
103 // info.setExcludeProductIds(productIds); 105 // info.setExcludeProductIds(productIds);
104 // } 106 // }
105 107
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());  
110 - } 108 + Map<Integer, List<ConditionLimitValue>> productLimitValueBoMap = getConditionLimitMap(Arrays.asList(coupon));
  109 +
  110 + List<ConditionLimitValue> conditionLimitValue = ConditionLimitValueBuilder.getAllConditionLimit(productLimitValueBoMap.get(coupon.getId()), coupon);
111 111
112 CouponInfo info = new CouponInfo(); 112 CouponInfo info = new CouponInfo();
113 - info.setProductLimitInfo(ProductLimitCollector.getProductLimitInfo(productLimitValueBo, coupon.getProductLimitType(), coupon.getProductLimitValue())); 113 + info.setProductLimitInfo(conditionLimitValueProcessor.flattenCondLimitValues(conditionLimitValue));
114 114
115 return info; 115 return info;
116 } 116 }
@@ -433,7 +433,7 @@ public class CouponServiceImpl implements ICouponService { @@ -433,7 +433,7 @@ public class CouponServiceImpl implements ICouponService {
433 433
434 // 优惠券商品限制 key=couponId, value=ProductId集合 434 // 优惠券商品限制 key=couponId, value=ProductId集合
435 // 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); 436 + Map<Integer, List<ConditionLimitValue>> productLimitValueBoMap = getConditionLimitMap(couponList);
437 437
438 //包装返回结果 438 //包装返回结果
439 List<UserCouponsBo> couponBoList = list.stream() 439 List<UserCouponsBo> couponBoList = list.stream()
@@ -449,7 +449,7 @@ public class CouponServiceImpl implements ICouponService { @@ -449,7 +449,7 @@ public class CouponServiceImpl implements ICouponService {
449 * @param couponList 449 * @param couponList
450 * @return 450 * @return
451 */ 451 */
452 - private Map<Integer, List<ProductLimitValueBo>> getAssociatedProductIdMap(List<Coupon> couponList){ 452 + private Map<Integer, List<ConditionLimitValue>> getConditionLimitMap(List<Coupon> couponList){
453 453
454 if (CollectionUtils.isEmpty(couponList)){ 454 if (CollectionUtils.isEmpty(couponList)){
455 return Maps.newHashMap(); 455 return Maps.newHashMap();
@@ -504,7 +504,7 @@ public class CouponServiceImpl implements ICouponService { @@ -504,7 +504,7 @@ public class CouponServiceImpl implements ICouponService {
504 504
505 // 优惠券商品限制 key=couponId, value=ProductId集合 505 // 优惠券商品限制 key=couponId, value=ProductId集合
506 // Map<Integer, List<Integer>> couponProductIdMap = getAssociatedProductIdListMap(couponList); 506 // Map<Integer, List<Integer>> couponProductIdMap = getAssociatedProductIdListMap(couponList);
507 - Map<Integer, List<ProductLimitValueBo>> productLimitValueBoMap = getAssociatedProductIdMap(couponList); 507 + Map<Integer, List<ConditionLimitValue>> productLimitValueBoMap = getConditionLimitMap(couponList);
508 508
509 509
510 int time = DateUtil.getCurrentTimeSecond(); 510 int time = DateUtil.getCurrentTimeSecond();
@@ -547,12 +547,12 @@ public class CouponServiceImpl implements ICouponService { @@ -547,12 +547,12 @@ public class CouponServiceImpl implements ICouponService {
547 return UserCouponsListBo.builder().coupons(couponBoList).build(); 547 return UserCouponsListBo.builder().coupons(couponBoList).build();
548 } 548 }
549 549
550 - private UserCouponsBo wrapperUserCoupon(final UserCoupon userCoupon, final Coupon coupon, final List<ProductLimitValueBo> productLimitValueBo) { 550 + private UserCouponsBo wrapperUserCoupon(final UserCoupon userCoupon, final Coupon coupon, final List<ConditionLimitValue> conditionLimitValue) {
551 551
552 // 单个获取couponType 552 // 单个获取couponType
553 CouponType couponType = couponCacheService.getCouponTypeWithCache(userCoupon.getCouponType() != null ? userCoupon.getCouponType().intValue() : null); 553 CouponType couponType = couponCacheService.getCouponTypeWithCache(userCoupon.getCouponType() != null ? userCoupon.getCouponType().intValue() : null);
554 554
555 - UserCouponsBo couponBo = CouponConvert.covertCouponBo(userCoupon, coupon, couponType, productLimitValueBo); 555 + UserCouponsBo couponBo = CouponConvert.covertCouponBo(userCoupon, coupon, couponType, conditionLimitValue);
556 556
557 return couponBo; 557 return couponBo;
558 } 558 }