...
|
...
|
@@ -18,13 +18,16 @@ import com.yohobuy.ufo.model.promotion.constant.PromotionStatusEnum; |
|
|
import com.yohobuy.ufo.model.promotion.constant.PromotionTypeEnum;
|
|
|
import com.yohobuy.ufo.model.promotion.request.PromotionActivityReq;
|
|
|
import com.yohobuy.ufo.model.promotion.response.promotionActivity.*;
|
|
|
import org.apache.commons.lang.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.Arrays;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -127,11 +130,12 @@ public class PromotionServiceImpl implements IPromotionService { |
|
|
activityRsp.setJoinLimitTimes(activity.getJoinLimitTimes());
|
|
|
activityRsp.setProductLimitType(activity.getProductLimitType());
|
|
|
activityRsp.setStatus(activity.getStatus());
|
|
|
if(activity.getProductLimitType().split(",").length == 9){//是否选择全部商品类型
|
|
|
if(activity.getProductLimitType().split(",").length == 10){//是否选择全部商品类型
|
|
|
activityRsp.setIsProductTypeAll(1);
|
|
|
}else {
|
|
|
activityRsp.setIsProductTypeAll(0);
|
|
|
}
|
|
|
activityRsp.setBusinessClient(activity.getBusinessClient());
|
|
|
|
|
|
//2、获取活动取促销满减金额/折扣配置
|
|
|
List<PromotionTypeCondition> amountConditions = typeConditionMapper.selectByPromotionId(id);
|
...
|
...
|
@@ -193,8 +197,11 @@ public class PromotionServiceImpl implements IPromotionService { |
|
|
log.info("updateStatusById with id:{},status:{},user:{}",id,status,operator.getUserId());
|
|
|
if(status == 1) {
|
|
|
PromotionActivity activity = activityMapper.selectByPrimaryKey(id);//获取当前活动的开始结束时间
|
|
|
PromotionActivity activityCheck = activityMapper.selectActivityWithinTime(activity.getStartTime(), activity.getEndTime(), id);
|
|
|
if (activityCheck != null) {
|
|
|
if(StringUtils.isEmpty(activity.getBusinessClient())){
|
|
|
log.warn("updateStatusById fail: activity not set businessClient. id is {}, status is {}", id, status);
|
|
|
return new ApiResponse.ApiResponseBuilder().code(201).message("该活动未设置购买渠道,请先设置购买渠道!").build();
|
|
|
}
|
|
|
if (isExistRunningActivity(id, activity.getStartTime(), activity.getEndTime(), activity.getBusinessClient())) {
|
|
|
log.warn("updateStatusById fail: exist same promotionType activity. id is {}, status is {}", id, status);
|
|
|
return new ApiResponse.ApiResponseBuilder().code(201).message("该时段已经存在相同类型的活动,请修改活动时间").build();
|
|
|
}
|
...
|
...
|
@@ -221,6 +228,7 @@ public class PromotionServiceImpl implements IPromotionService { |
|
|
activity.setStartTime(DateUtil.getTimeSecondsFromStr(req.getStartTimeStr(),DateUtil.DATE_TIME_FORMAT));
|
|
|
activity.setEndTime(DateUtil.getTimeSecondsFromStr(req.getEndTimeStr(), DateUtil.DATE_TIME_FORMAT));
|
|
|
activity.setStatus(req.getInitStatus());
|
|
|
activity.setBusinessClient(req.getBusinessClient());
|
|
|
activityMapper.insert(activity);
|
|
|
return activity.getId();
|
|
|
}
|
...
|
...
|
@@ -239,6 +247,7 @@ public class PromotionServiceImpl implements IPromotionService { |
|
|
activity.setProductLimitType(req.getProductTypeLimitList());
|
|
|
activity.setStartTime(DateUtil.getTimeSecondsFromStr(req.getStartTimeStr(), DateUtil.DATE_TIME_FORMAT));
|
|
|
activity.setEndTime(DateUtil.getTimeSecondsFromStr(req.getEndTimeStr(), DateUtil.DATE_TIME_FORMAT));
|
|
|
activity.setBusinessClient(req.getBusinessClient());
|
|
|
activityMapper.updateByPrimaryKey(activity);
|
|
|
}
|
|
|
|
...
|
...
|
@@ -273,7 +282,7 @@ public class PromotionServiceImpl implements IPromotionService { |
|
|
typeConditionMapper.insertBatch(typeConditions);
|
|
|
}
|
|
|
|
|
|
//保存营销活动是校验
|
|
|
//保存营销活动时校验
|
|
|
private ApiResponse checkParams(PromotionActivityReq req){
|
|
|
Integer startTime = DateUtil.getTimeSecondsFromStr(req.getStartTimeStr(), DateUtil.DATE_TIME_FORMAT);
|
|
|
Integer endTime = DateUtil.getTimeSecondsFromStr(req.getEndTimeStr(), DateUtil.DATE_TIME_FORMAT);
|
...
|
...
|
@@ -282,7 +291,7 @@ public class PromotionServiceImpl implements IPromotionService { |
|
|
return new ApiResponse.ApiResponseBuilder().code(201).message("结束时间必须大于开始时间").build();
|
|
|
}
|
|
|
if(req.getInitStatus().equals(PromotionStatusEnum.OPEN.getCode())
|
|
|
&&(activityMapper.selectActivityWithinTime(startTime, endTime, req.getId()) != null)){
|
|
|
&&(isExistRunningActivity(req.getId(), startTime, endTime, req.getBusinessClient()))){
|
|
|
log.warn("checkParams fail: exist same promotionType activity. req is {}", req);
|
|
|
return new ApiResponse.ApiResponseBuilder().code(201).message("该时段已经存在相同类型的活动,请修改活动时间").build();
|
|
|
}
|
...
|
...
|
@@ -305,6 +314,25 @@ public class PromotionServiceImpl implements IPromotionService { |
|
|
return new ApiResponse.ApiResponseBuilder().code(200).message("校验成功").build();
|
|
|
}
|
|
|
|
|
|
//开启活动时,校验:同一时间,相同渠道的,只能有一个促销活动
|
|
|
private boolean isExistRunningActivity(Integer activityId, Integer startTime, Integer endTime, String businessClient){
|
|
|
//(1) 查询该时间段内是否有其他活动正在生效中
|
|
|
List<PromotionActivity> activityList = activityMapper.selectActivityWithinTime(startTime, endTime, activityId);
|
|
|
if(CollectionUtils.isEmpty(activityList)){
|
|
|
return false;
|
|
|
}
|
|
|
//(2) 校验该时间段生效活动的购买渠道是否和当前开启活动的购买渠道重复
|
|
|
String[] businessClientNew = businessClient.split(",");
|
|
|
for(PromotionActivity activity: activityList){
|
|
|
if(StringUtils.isEmpty(activity.getBusinessClient())) continue;
|
|
|
List<String> businessClientExist = Arrays.asList(activity.getBusinessClient().split(","));
|
|
|
for(String newClient: businessClientNew){
|
|
|
if(businessClientExist.contains(newClient)) return true;
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
private String getActivityStatusStr(PromotionActivity activity){
|
|
|
if(PromotionStatusEnum.CLOSE.getCode().equals(activity.getStatus())){
|
|
|
return "已关闭";
|
...
|
...
|
|