...
|
...
|
@@ -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() {
|
...
|
...
|
|