|
@@ -3,11 +3,12 @@ package com.yohoufo.promotion.service.impl; |
|
@@ -3,11 +3,12 @@ package com.yohoufo.promotion.service.impl; |
3
|
import com.yoho.tools.common.utils.DateUtil;
|
3
|
import com.yoho.tools.common.utils.DateUtil;
|
4
|
import com.yohobuy.ufo.model.promotion.constant.PromotionProductLimitEnum;
|
4
|
import com.yohobuy.ufo.model.promotion.constant.PromotionProductLimitEnum;
|
5
|
import com.yohobuy.ufo.model.promotion.constant.PromotionTypeEnum;
|
5
|
import com.yohobuy.ufo.model.promotion.constant.PromotionTypeEnum;
|
|
|
6
|
+import com.yohobuy.ufo.model.promotion.request.ProductPromotionListReq;
|
|
|
7
|
+import com.yohobuy.ufo.model.promotion.response.ProductPromotionListRsp;
|
6
|
import com.yohobuy.ufo.model.promotion.response.promotionActivity.PromotionActivityRspBo;
|
8
|
import com.yohobuy.ufo.model.promotion.response.promotionActivity.PromotionActivityRspBo;
|
7
|
import com.yohobuy.ufo.model.promotion.response.promotionActivity.PromotionAmountConditionBo;
|
9
|
import com.yohobuy.ufo.model.promotion.response.promotionActivity.PromotionAmountConditionBo;
|
8
|
import com.yohobuy.ufo.model.promotion.response.promotionActivity.PromotionJoinTimeLimitBo;
|
10
|
import com.yohobuy.ufo.model.promotion.response.promotionActivity.PromotionJoinTimeLimitBo;
|
9
|
import com.yohobuy.ufo.model.promotion.response.promotionActivity.PromotionProductScopeBo;
|
11
|
import com.yohobuy.ufo.model.promotion.response.promotionActivity.PromotionProductScopeBo;
|
10
|
-import com.yohoufo.common.constant.BusinessClientEnum;
|
|
|
11
|
import com.yohoufo.dal.product.ProductPoolDetailMapper;
|
12
|
import com.yohoufo.dal.product.ProductPoolDetailMapper;
|
12
|
import com.yohoufo.dal.product.model.ProductPoolDetail;
|
13
|
import com.yohoufo.dal.product.model.ProductPoolDetail;
|
13
|
import com.yohoufo.dal.promotion.IActivityAmountConditionMapper;
|
14
|
import com.yohoufo.dal.promotion.IActivityAmountConditionMapper;
|
|
@@ -17,17 +18,14 @@ import com.yohoufo.dal.promotion.model.Activity; |
|
@@ -17,17 +18,14 @@ import com.yohoufo.dal.promotion.model.Activity; |
17
|
import com.yohoufo.dal.promotion.model.ActivityAmountCondition;
|
18
|
import com.yohoufo.dal.promotion.model.ActivityAmountCondition;
|
18
|
import com.yohoufo.dal.promotion.model.ActivityProductScope;
|
19
|
import com.yohoufo.dal.promotion.model.ActivityProductScope;
|
19
|
import com.yohoufo.promotion.service.IActivityService;
|
20
|
import com.yohoufo.promotion.service.IActivityService;
|
|
|
21
|
+import org.apache.commons.collections.CollectionUtils;
|
20
|
import org.apache.commons.lang3.StringUtils;
|
22
|
import org.apache.commons.lang3.StringUtils;
|
21
|
import org.slf4j.Logger;
|
23
|
import org.slf4j.Logger;
|
22
|
import org.slf4j.LoggerFactory;
|
24
|
import org.slf4j.LoggerFactory;
|
23
|
import org.springframework.beans.factory.annotation.Autowired;
|
25
|
import org.springframework.beans.factory.annotation.Autowired;
|
24
|
import org.springframework.stereotype.Service;
|
26
|
import org.springframework.stereotype.Service;
|
25
|
-import org.springframework.util.CollectionUtils;
|
|
|
26
|
|
27
|
|
27
|
-import java.util.ArrayList;
|
|
|
28
|
-import java.util.Collections;
|
|
|
29
|
-import java.util.List;
|
|
|
30
|
-import java.util.Objects;
|
28
|
+import java.util.*;
|
31
|
import java.util.stream.Collectors;
|
29
|
import java.util.stream.Collectors;
|
32
|
|
30
|
|
33
|
@Service
|
31
|
@Service
|
|
@@ -48,18 +46,51 @@ public class ActivityServiceImpl implements IActivityService { |
|
@@ -48,18 +46,51 @@ public class ActivityServiceImpl implements IActivityService { |
48
|
IActivityAmountConditionMapper activityAmountConditionMapper;
|
46
|
IActivityAmountConditionMapper activityAmountConditionMapper;
|
49
|
|
47
|
|
50
|
|
48
|
|
|
|
49
|
+ @Override
|
|
|
50
|
+ public ProductPromotionListRsp getPromotionListForProduct(ProductPromotionListReq req) {
|
|
|
51
|
+ logger.debug("getPromotionListForProduct: enter. req {}", req);
|
|
|
52
|
+ List<PromotionActivityRspBo> datas = getActivityListForProduct(req);
|
|
|
53
|
+ if (CollectionUtils.isEmpty(datas)){
|
|
|
54
|
+ logger.warn("getPromotionListForProduct result is null, req {}", req);
|
|
|
55
|
+ return null;
|
|
|
56
|
+ }
|
|
|
57
|
+ Map<Integer, PromotionActivityRspBo> typeGroupMap = new HashMap<>(datas.size());
|
|
|
58
|
+
|
|
|
59
|
+ for(PromotionActivityRspBo paRsp : datas){
|
|
|
60
|
+ Integer promotionType;
|
|
|
61
|
+ if (typeGroupMap.containsKey(promotionType = paRsp.getPromotionType())){
|
|
|
62
|
+ continue;
|
|
|
63
|
+ }
|
|
|
64
|
+ typeGroupMap.put(promotionType, convertTypeGroupPromotion(paRsp));
|
|
|
65
|
+ }
|
|
|
66
|
+
|
|
|
67
|
+ List<PromotionActivityRspBo> typeGroupList = new ArrayList<>(typeGroupMap.values());
|
|
|
68
|
+ return ProductPromotionListRsp.builder().promotionActivityList(datas)
|
|
|
69
|
+ .promotionTypeGroupList(typeGroupList).build();
|
|
|
70
|
+ }
|
|
|
71
|
+
|
|
|
72
|
+ private static PromotionActivityRspBo convertTypeGroupPromotion(PromotionActivityRspBo rspBo){
|
|
|
73
|
+ PromotionActivityRspBo typeGroupPromotion = new PromotionActivityRspBo();
|
|
|
74
|
+ typeGroupPromotion.setPromotionType(rspBo.getPromotionType());
|
|
|
75
|
+ typeGroupPromotion.setPromotionTypeStr(rspBo.getPromotionTypeStr());
|
|
|
76
|
+ return typeGroupPromotion;
|
|
|
77
|
+ }
|
|
|
78
|
+
|
51
|
/**
|
79
|
/**
|
52
|
* 根据商品id返回符合条件的促销活动
|
80
|
* 根据商品id返回符合条件的促销活动
|
53
|
- * @param productId
|
81
|
+ * @param req
|
54
|
* @return
|
82
|
* @return
|
55
|
*/
|
83
|
*/
|
56
|
@Override
|
84
|
@Override
|
57
|
- public List<PromotionActivityRspBo> getActivityListForProduct(Integer productId, String businessClient) {
|
|
|
58
|
- logger.info("getPromotionActivityList: enter. productId is {}, businessClient is {}", productId, businessClient);
|
85
|
+ public List<PromotionActivityRspBo> getActivityListForProduct(ProductPromotionListReq req) {
|
|
|
86
|
+
|
|
|
87
|
+ logger.debug("getPromotionActivityList: enter. req {}", req);
|
|
|
88
|
+ Integer productId = req.getProductId();
|
|
|
89
|
+ String businessClient = req.getBusinessClient();
|
59
|
//获取当前正在进行中活动
|
90
|
//获取当前正在进行中活动
|
60
|
List<Activity> activityList = activityMapper.selectRunningActivity(DateUtil.getCurrentTimeSeconds());
|
91
|
List<Activity> activityList = activityMapper.selectRunningActivity(DateUtil.getCurrentTimeSeconds());
|
61
|
if(CollectionUtils.isEmpty(activityList)){
|
92
|
if(CollectionUtils.isEmpty(activityList)){
|
62
|
- logger.warn("getActivityListForProduct: no running activity. productId {},businessClient {}", productId,businessClient);
|
93
|
+ logger.warn("getActivityListForProduct: no running activity. req {}", req);
|
63
|
return Collections.emptyList();
|
94
|
return Collections.emptyList();
|
64
|
}
|
95
|
}
|
65
|
//匹配对用购买渠道的活动(同一时间最多两个促销活动,闲鱼,ufo各一个)
|
96
|
//匹配对用购买渠道的活动(同一时间最多两个促销活动,闲鱼,ufo各一个)
|
|
@@ -67,7 +98,7 @@ public class ActivityServiceImpl implements IActivityService { |
|
@@ -67,7 +98,7 @@ public class ActivityServiceImpl implements IActivityService { |
67
|
.filter(x -> StringUtils.isNotEmpty(x.getBusinessClient()) && x.getBusinessClient().contains(businessClient))
|
98
|
.filter(x -> StringUtils.isNotEmpty(x.getBusinessClient()) && x.getBusinessClient().contains(businessClient))
|
68
|
.collect(Collectors.toList());
|
99
|
.collect(Collectors.toList());
|
69
|
if(CollectionUtils.isEmpty(businessClientActivityList)){
|
100
|
if(CollectionUtils.isEmpty(businessClientActivityList)){
|
70
|
- logger.warn("getActivityListForProduct: no running activity. productId is {}, businessClient is {}", productId, businessClient);
|
101
|
+ logger.warn("getActivityListForProduct: no running activity. req {}", req);
|
71
|
return Collections.emptyList();
|
102
|
return Collections.emptyList();
|
72
|
}
|
103
|
}
|
73
|
|
104
|
|
|
@@ -108,11 +139,15 @@ public class ActivityServiceImpl implements IActivityService { |
|
@@ -108,11 +139,15 @@ public class ActivityServiceImpl implements IActivityService { |
108
|
rspBo.setEndTimeStr(com.yohoufo.common.utils.DateUtil.getDateFormatEx(activity.getEndTime(), com.yohoufo.common.utils.DateUtil.MM_dd_yyyy_HH_mm_ss_long));
|
139
|
rspBo.setEndTimeStr(com.yohoufo.common.utils.DateUtil.getDateFormatEx(activity.getEndTime(), com.yohoufo.common.utils.DateUtil.MM_dd_yyyy_HH_mm_ss_long));
|
109
|
rspBo.setPromotionType(activity.getPromotionType());
|
140
|
rspBo.setPromotionType(activity.getPromotionType());
|
110
|
rspBo.setLabel(activity.getLabel());
|
141
|
rspBo.setLabel(activity.getLabel());
|
111
|
- rspBo.setPromotionTypeStr(null == activity.getPromotionType() ? "" : PromotionTypeEnum.getDescByCode(activity.getPromotionType()));
|
142
|
+ rspBo.setPromotionTypeStr(parsePromotionTypeDesc(activity.getPromotionType()));
|
112
|
return rspBo;
|
143
|
return rspBo;
|
113
|
|
144
|
|
114
|
}
|
145
|
}
|
115
|
|
146
|
|
|
|
147
|
+ private static String parsePromotionTypeDesc(Integer promotionType){
|
|
|
148
|
+ return null == promotionType ? "" : PromotionTypeEnum.getDescByCode(promotionType);
|
|
|
149
|
+ }
|
|
|
150
|
+
|
116
|
|
151
|
|
117
|
@Override
|
152
|
@Override
|
118
|
public List<PromotionActivityRspBo> getActivityListForOrder() {
|
153
|
public List<PromotionActivityRspBo> getActivityListForOrder() {
|