Authored by chenchao

new api response

@@ -26,6 +26,8 @@ @@ -26,6 +26,8 @@
26 select <include refid="Base_Column_List"/> from promotion_activity 26 select <include refid="Base_Column_List"/> from promotion_activity
27 where status = 1 27 where status = 1
28 and #{currentTime, jdbcType=INTEGER} between start_time and end_time 28 and #{currentTime, jdbcType=INTEGER} between start_time and end_time
  29 + order by id desc
  30 + limit 50
29 </select> 31 </select>
30 32
31 </mapper> 33 </mapper>
1 package com.yohoufo.promotion.controller; 1 package com.yohoufo.promotion.controller;
2 2
  3 +import com.yohobuy.ufo.model.promotion.request.ProductPromotionListReq;
3 import com.yohobuy.ufo.model.promotion.response.promotionActivity.PromotionActivityRspBo; 4 import com.yohobuy.ufo.model.promotion.response.promotionActivity.PromotionActivityRspBo;
4 import com.yohoufo.common.ApiResponse; 5 import com.yohoufo.common.ApiResponse;
5 import com.yohoufo.common.annotation.IgnoreSession; 6 import com.yohoufo.common.annotation.IgnoreSession;
@@ -37,11 +38,23 @@ public class ActivityController { @@ -37,11 +38,23 @@ public class ActivityController {
37 @IgnoreSession 38 @IgnoreSession
38 @Cachable(expire = 60) 39 @Cachable(expire = 60)
39 public ApiResponse getPromotionActivityList(@RequestParam(value = "product_id", required = true) Integer productId, 40 public ApiResponse getPromotionActivityList(@RequestParam(value = "product_id", required = true) Integer productId,
  41 + @RequestParam(value = "api_version", required = false, defaultValue = "0") int apiVersion,
  42 + @RequestParam(value = "app_version", required = false)String appVersion,
40 @RequestParam(value = "business_client", required = false, defaultValue = "ufo") String businessClient) { 43 @RequestParam(value = "business_client", required = false, defaultValue = "ufo") String businessClient) {
41 - logger.info("Method:ufo.promotion.activityListForProduct. enter, productId is {}", productId);  
42 - List<PromotionActivityRspBo> activityListForProduct = activityService.getActivityListForProduct(productId, businessClient);  
43 - logger.info("Method:ufo.promotion.activityListForProduct. out, productId is {}", productId);  
44 - return new ApiResponse.ApiResponseBuilder().code(200).data(activityListForProduct).build(); 44 +
  45 + ProductPromotionListReq req = ProductPromotionListReq.builder().productId(productId)
  46 + .apiVersion(apiVersion)
  47 + .appVersion(appVersion)
  48 + .businessClient(businessClient).build();
  49 + logger.info("Method:ufo.promotion.activityListForProduct. enter, req {}", req);
  50 + Object data = null;
  51 + if (apiVersion == 0){
  52 + data = activityService.getActivityListForProduct(req);
  53 + }else if (apiVersion == 1){
  54 + data = activityService.getPromotionListForProduct(req);
  55 + }
  56 + logger.info("Method:ufo.promotion.activityListForProduct. out, req {}", req);
  57 + return new ApiResponse.ApiResponseBuilder().code(200).data(data).build();
45 } 58 }
46 59
47 /** 60 /**
1 package com.yohoufo.promotion.service; 1 package com.yohoufo.promotion.service;
2 2
  3 +import com.yohobuy.ufo.model.promotion.request.ProductPromotionListReq;
  4 +import com.yohobuy.ufo.model.promotion.response.ProductPromotionListRsp;
3 import com.yohobuy.ufo.model.promotion.response.promotionActivity.PromotionActivityRspBo; 5 import com.yohobuy.ufo.model.promotion.response.promotionActivity.PromotionActivityRspBo;
4 6
5 import java.util.List; 7 import java.util.List;
6 8
7 public interface IActivityService { 9 public interface IActivityService {
  10 + /**
  11 + * from v6.9.24
  12 + * @param req
  13 + * @return
  14 + */
  15 + ProductPromotionListRsp getPromotionListForProduct(ProductPromotionListReq req);
8 16
9 /** 17 /**
10 * 获取商品促销活动列表展示信息 18 * 获取商品促销活动列表展示信息
11 - * @param productId 19 + * @param req
12 * @return 20 * @return
13 */ 21 */
14 - List<PromotionActivityRspBo> getActivityListForProduct(Integer productId, String businessClient); 22 + List<PromotionActivityRspBo> getActivityListForProduct(ProductPromotionListReq req);
15 23
16 /** 24 /**
17 * 获取当前促销活动详情 25 * 获取当前促销活动详情
@@ -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() {