Authored by chenchao

new api response

... ... @@ -26,6 +26,8 @@
select <include refid="Base_Column_List"/> from promotion_activity
where status = 1
and #{currentTime, jdbcType=INTEGER} between start_time and end_time
order by id desc
limit 50
</select>
</mapper>
\ No newline at end of file
... ...
package com.yohoufo.promotion.controller;
import com.yohobuy.ufo.model.promotion.request.ProductPromotionListReq;
import com.yohobuy.ufo.model.promotion.response.promotionActivity.PromotionActivityRspBo;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.annotation.IgnoreSession;
... ... @@ -37,11 +38,23 @@ public class ActivityController {
@IgnoreSession
@Cachable(expire = 60)
public ApiResponse getPromotionActivityList(@RequestParam(value = "product_id", required = true) Integer productId,
@RequestParam(value = "api_version", required = false, defaultValue = "0") int apiVersion,
@RequestParam(value = "app_version", required = false)String appVersion,
@RequestParam(value = "business_client", required = false, defaultValue = "ufo") String businessClient) {
logger.info("Method:ufo.promotion.activityListForProduct. enter, productId is {}", productId);
List<PromotionActivityRspBo> activityListForProduct = activityService.getActivityListForProduct(productId, businessClient);
logger.info("Method:ufo.promotion.activityListForProduct. out, productId is {}", productId);
return new ApiResponse.ApiResponseBuilder().code(200).data(activityListForProduct).build();
ProductPromotionListReq req = ProductPromotionListReq.builder().productId(productId)
.apiVersion(apiVersion)
.appVersion(appVersion)
.businessClient(businessClient).build();
logger.info("Method:ufo.promotion.activityListForProduct. enter, req {}", req);
Object data = null;
if (apiVersion == 0){
data = activityService.getActivityListForProduct(req);
}else if (apiVersion == 1){
data = activityService.getPromotionListForProduct(req);
}
logger.info("Method:ufo.promotion.activityListForProduct. out, req {}", req);
return new ApiResponse.ApiResponseBuilder().code(200).data(data).build();
}
/**
... ...
package com.yohoufo.promotion.service;
import com.yohobuy.ufo.model.promotion.request.ProductPromotionListReq;
import com.yohobuy.ufo.model.promotion.response.ProductPromotionListRsp;
import com.yohobuy.ufo.model.promotion.response.promotionActivity.PromotionActivityRspBo;
import java.util.List;
public interface IActivityService {
/**
* from v6.9.24
* @param req
* @return
*/
ProductPromotionListRsp getPromotionListForProduct(ProductPromotionListReq req);
/**
* 获取商品促销活动列表展示信息
* @param productId
* @param req
* @return
*/
List<PromotionActivityRspBo> getActivityListForProduct(Integer productId, String businessClient);
List<PromotionActivityRspBo> getActivityListForProduct(ProductPromotionListReq req);
/**
* 获取当前促销活动详情
... ...
... ... @@ -3,11 +3,12 @@ package com.yohoufo.promotion.service.impl;
import com.yoho.tools.common.utils.DateUtil;
import com.yohobuy.ufo.model.promotion.constant.PromotionProductLimitEnum;
import com.yohobuy.ufo.model.promotion.constant.PromotionTypeEnum;
import com.yohobuy.ufo.model.promotion.request.ProductPromotionListReq;
import com.yohobuy.ufo.model.promotion.response.ProductPromotionListRsp;
import com.yohobuy.ufo.model.promotion.response.promotionActivity.PromotionActivityRspBo;
import com.yohobuy.ufo.model.promotion.response.promotionActivity.PromotionAmountConditionBo;
import com.yohobuy.ufo.model.promotion.response.promotionActivity.PromotionJoinTimeLimitBo;
import com.yohobuy.ufo.model.promotion.response.promotionActivity.PromotionProductScopeBo;
import com.yohoufo.common.constant.BusinessClientEnum;
import com.yohoufo.dal.product.ProductPoolDetailMapper;
import com.yohoufo.dal.product.model.ProductPoolDetail;
import com.yohoufo.dal.promotion.IActivityAmountConditionMapper;
... ... @@ -17,17 +18,14 @@ import com.yohoufo.dal.promotion.model.Activity;
import com.yohoufo.dal.promotion.model.ActivityAmountCondition;
import com.yohoufo.dal.promotion.model.ActivityProductScope;
import com.yohoufo.promotion.service.IActivityService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;
@Service
... ... @@ -48,18 +46,51 @@ public class ActivityServiceImpl implements IActivityService {
IActivityAmountConditionMapper activityAmountConditionMapper;
@Override
public ProductPromotionListRsp getPromotionListForProduct(ProductPromotionListReq req) {
logger.debug("getPromotionListForProduct: enter. req {}", req);
List<PromotionActivityRspBo> datas = getActivityListForProduct(req);
if (CollectionUtils.isEmpty(datas)){
logger.warn("getPromotionListForProduct result is null, req {}", req);
return null;
}
Map<Integer, PromotionActivityRspBo> typeGroupMap = new HashMap<>(datas.size());
for(PromotionActivityRspBo paRsp : datas){
Integer promotionType;
if (typeGroupMap.containsKey(promotionType = paRsp.getPromotionType())){
continue;
}
typeGroupMap.put(promotionType, convertTypeGroupPromotion(paRsp));
}
List<PromotionActivityRspBo> typeGroupList = new ArrayList<>(typeGroupMap.values());
return ProductPromotionListRsp.builder().promotionActivityList(datas)
.promotionTypeGroupList(typeGroupList).build();
}
private static PromotionActivityRspBo convertTypeGroupPromotion(PromotionActivityRspBo rspBo){
PromotionActivityRspBo typeGroupPromotion = new PromotionActivityRspBo();
typeGroupPromotion.setPromotionType(rspBo.getPromotionType());
typeGroupPromotion.setPromotionTypeStr(rspBo.getPromotionTypeStr());
return typeGroupPromotion;
}
/**
* 根据商品id返回符合条件的促销活动
* @param productId
* @param req
* @return
*/
@Override
public List<PromotionActivityRspBo> getActivityListForProduct(Integer productId, String businessClient) {
logger.info("getPromotionActivityList: enter. productId is {}, businessClient is {}", productId, businessClient);
public List<PromotionActivityRspBo> getActivityListForProduct(ProductPromotionListReq req) {
logger.debug("getPromotionActivityList: enter. req {}", req);
Integer productId = req.getProductId();
String businessClient = req.getBusinessClient();
//获取当前正在进行中活动
List<Activity> activityList = activityMapper.selectRunningActivity(DateUtil.getCurrentTimeSeconds());
if(CollectionUtils.isEmpty(activityList)){
logger.warn("getActivityListForProduct: no running activity. productId {},businessClient {}", productId,businessClient);
logger.warn("getActivityListForProduct: no running activity. req {}", req);
return Collections.emptyList();
}
//匹配对用购买渠道的活动(同一时间最多两个促销活动,闲鱼,ufo各一个)
... ... @@ -67,7 +98,7 @@ public class ActivityServiceImpl implements IActivityService {
.filter(x -> StringUtils.isNotEmpty(x.getBusinessClient()) && x.getBusinessClient().contains(businessClient))
.collect(Collectors.toList());
if(CollectionUtils.isEmpty(businessClientActivityList)){
logger.warn("getActivityListForProduct: no running activity. productId is {}, businessClient is {}", productId, businessClient);
logger.warn("getActivityListForProduct: no running activity. req {}", req);
return Collections.emptyList();
}
... ... @@ -108,11 +139,15 @@ public class ActivityServiceImpl implements IActivityService {
rspBo.setEndTimeStr(com.yohoufo.common.utils.DateUtil.getDateFormatEx(activity.getEndTime(), com.yohoufo.common.utils.DateUtil.MM_dd_yyyy_HH_mm_ss_long));
rspBo.setPromotionType(activity.getPromotionType());
rspBo.setLabel(activity.getLabel());
rspBo.setPromotionTypeStr(null == activity.getPromotionType() ? "" : PromotionTypeEnum.getDescByCode(activity.getPromotionType()));
rspBo.setPromotionTypeStr(parsePromotionTypeDesc(activity.getPromotionType()));
return rspBo;
}
private static String parsePromotionTypeDesc(Integer promotionType){
return null == promotionType ? "" : PromotionTypeEnum.getDescByCode(promotionType);
}
@Override
public List<PromotionActivityRspBo> getActivityListForOrder() {
... ...