|
@ -10,6 +10,7 @@ import com.qs.serve.modules.tbs.common.util.TbsBudgetCostUtil; |
|
|
import com.qs.serve.modules.tbs.entity.*; |
|
|
import com.qs.serve.modules.tbs.entity.*; |
|
|
import com.qs.serve.modules.tbs.entity.dto.TbsBudgetCostResult; |
|
|
import com.qs.serve.modules.tbs.entity.dto.TbsBudgetCostResult; |
|
|
import com.qs.serve.modules.tbs.entity.vo.TbsBudgetTableVo; |
|
|
import com.qs.serve.modules.tbs.entity.vo.TbsBudgetTableVo; |
|
|
|
|
|
import com.qs.serve.modules.tbs.mapper.TbsActivityGoodsMapper; |
|
|
import com.qs.serve.modules.tbs.mapper.TbsActivityMapper; |
|
|
import com.qs.serve.modules.tbs.mapper.TbsActivityMapper; |
|
|
import com.qs.serve.modules.tbs.mapper.TbsBudgetMapper; |
|
|
import com.qs.serve.modules.tbs.mapper.TbsBudgetMapper; |
|
|
import lombok.AllArgsConstructor; |
|
|
import lombok.AllArgsConstructor; |
|
@ -38,6 +39,7 @@ public class TbsBudgetApplicationService { |
|
|
private TbsBudgetCostItemService tbsBudgetCostItemService; |
|
|
private TbsBudgetCostItemService tbsBudgetCostItemService; |
|
|
private SysConfigService configService; |
|
|
private SysConfigService configService; |
|
|
private TbsActivityMapper activityMapper; |
|
|
private TbsActivityMapper activityMapper; |
|
|
|
|
|
private TbsActivityGoodsMapper activityGoodsMapper; |
|
|
|
|
|
|
|
|
public TbsBudgetTableVo buildResultTable(Long costApplyId){ |
|
|
public TbsBudgetTableVo buildResultTable(Long costApplyId){ |
|
|
//加载活动
|
|
|
//加载活动
|
|
@ -182,8 +184,10 @@ public class TbsBudgetApplicationService { |
|
|
} |
|
|
} |
|
|
List<TbsBudget> noConditionBudgetList = new ArrayList<>(); |
|
|
List<TbsBudget> noConditionBudgetList = new ArrayList<>(); |
|
|
boolean budgetNoCondition = this.loadConditionByBudgetsAndMatch(budgetList, noConditionBudgetList); |
|
|
boolean budgetNoCondition = this.loadConditionByBudgetsAndMatch(budgetList, noConditionBudgetList); |
|
|
|
|
|
//预算条件需包含活动条件, Map结构:活动id->满足的预算id列表
|
|
|
|
|
|
Map<Long,List<Long>> activityAllowBudgetIdMap = this.buildActivityBudgetMap(activityList, budgetList, noConditionBudgetList); |
|
|
//活动拦截
|
|
|
//活动拦截
|
|
|
this.handleNoBudgetActivity(throwEx, overspend, activityList, noBudgetActivityIds, budgetNoCondition); |
|
|
this.handleNoBudgetActivity(throwEx, overspend, activityList, noBudgetActivityIds, budgetNoCondition,activityAllowBudgetIdMap); |
|
|
//统计当前活动前置项占用预算
|
|
|
//统计当前活动前置项占用预算
|
|
|
Map<Long,BigDecimal> counterMap = new HashMap<>(); |
|
|
Map<Long,BigDecimal> counterMap = new HashMap<>(); |
|
|
//匹配预算主要方法
|
|
|
//匹配预算主要方法
|
|
@ -191,7 +195,7 @@ public class TbsBudgetApplicationService { |
|
|
final List<TbsActivityCenterGoods> actUnMatchList = new ArrayList<>(); |
|
|
final List<TbsActivityCenterGoods> actUnMatchList = new ArrayList<>(); |
|
|
for (TbsActivityCenterGoods activityCostItem : centerGoodsList) { |
|
|
for (TbsActivityCenterGoods activityCostItem : centerGoodsList) { |
|
|
this.matchActivityMain(activityCostItem,throwEx, overspend, activityList, hisCostGroupByItemBudget, budgetList, |
|
|
this.matchActivityMain(activityCostItem,throwEx, overspend, activityList, hisCostGroupByItemBudget, budgetList, |
|
|
noConditionBudgetList, counterMap, actMatchList, actUnMatchList); |
|
|
noConditionBudgetList, counterMap, actMatchList, actUnMatchList,activityAllowBudgetIdMap); |
|
|
} |
|
|
} |
|
|
List<TbsBudgetCostItem> budgetMatchList = actMatchList.stream() |
|
|
List<TbsBudgetCostItem> budgetMatchList = actMatchList.stream() |
|
|
.map(TbsActivityCenterGoods::toBudgetCostItem).collect(Collectors.toList()); |
|
|
.map(TbsActivityCenterGoods::toBudgetCostItem).collect(Collectors.toList()); |
|
@ -209,6 +213,57 @@ public class TbsBudgetApplicationService { |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 预算条件需包含活动条件, Map结构:活动id->满足的预算id列表 |
|
|
|
|
|
* @param activityList |
|
|
|
|
|
* @param budgetList |
|
|
|
|
|
* @param noConditionBudgetList |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
private Map<Long, List<Long>> buildActivityBudgetMap(List<TbsActivity> activityList, |
|
|
|
|
|
List<TbsBudget> budgetList, |
|
|
|
|
|
List<TbsBudget> noConditionBudgetList) { |
|
|
|
|
|
Map<Long, List<Long>> activityAllowBudgetIdMap = new HashMap<>(); |
|
|
|
|
|
for (TbsActivity activity : activityList) { |
|
|
|
|
|
List<Long> budgetIdsOfActivity = new ArrayList<>(); |
|
|
|
|
|
if(CollectionUtil.isEmpty(noConditionBudgetList)){ |
|
|
|
|
|
budgetIdsOfActivity.addAll(noConditionBudgetList.stream().map(TbsBudget::getId).collect(Collectors.toList())); |
|
|
|
|
|
} |
|
|
|
|
|
LambdaQueryWrapper<TbsActivityGoods> goodsLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
|
goodsLambdaQueryWrapper.eq(TbsActivityGoods::getActivityId,activity.getId()); |
|
|
|
|
|
List<TbsActivityGoods> activityGoodsList = activityGoodsMapper.selectList(goodsLambdaQueryWrapper); |
|
|
|
|
|
for (TbsBudget budget : budgetList) { |
|
|
|
|
|
if(budget.getConditionFlag().equals(1)){ |
|
|
|
|
|
List<TbsBudgetCondition> budgetConditionList = budget.getBudgetConditionList(); |
|
|
|
|
|
boolean hasNoMatch = false; |
|
|
|
|
|
for (TbsActivityGoods activityGoods : activityGoodsList) { |
|
|
|
|
|
boolean matchGoods = false; |
|
|
|
|
|
for (TbsBudgetCondition budgetCondition : budgetConditionList) { |
|
|
|
|
|
if(activityGoods.getTargetLevelPathIds().contains(budgetCondition.getTargetLevelPathIds())){ |
|
|
|
|
|
matchGoods = true; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if(!matchGoods){ |
|
|
|
|
|
hasNoMatch = true; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if(!hasNoMatch){ |
|
|
|
|
|
List<Long> budgetIds = activityAllowBudgetIdMap.get(activity.getId()); |
|
|
|
|
|
if(budgetIds==null){ |
|
|
|
|
|
budgetIds = new ArrayList<>(); |
|
|
|
|
|
} |
|
|
|
|
|
budgetIds.add(budget.getId()); |
|
|
|
|
|
activityAllowBudgetIdMap.put(activity.getId(),budgetIds); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
activityAllowBudgetIdMap.put(activity.getId(),budgetIdsOfActivity); |
|
|
|
|
|
} |
|
|
|
|
|
return activityAllowBudgetIdMap; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 建立费用预算表 |
|
|
* 建立费用预算表 |
|
|
* @param activityList |
|
|
* @param activityList |
|
@ -316,23 +371,28 @@ public class TbsBudgetApplicationService { |
|
|
* @param overspend 超值标识 |
|
|
* @param overspend 超值标识 |
|
|
* @param activityList 所有活动 |
|
|
* @param activityList 所有活动 |
|
|
* @param hisCostGroupByItemBudget 历史费用组 |
|
|
* @param hisCostGroupByItemBudget 历史费用组 |
|
|
* @param budgetList 所有预算 |
|
|
* @param allBudgetList 所有预算 |
|
|
* @param noConditionBudgetList 没有条件的预算列表 |
|
|
* @param noConditionBudgetList 没有条件的预算列表 |
|
|
* @param counterMap 历史预算占用 |
|
|
* @param counterMap 历史预算占用 |
|
|
* @param actMatchList 匹配预算占用的费用(含超支预算) |
|
|
* @param actMatchList 匹配预算占用的费用(含超支预算) |
|
|
* @param actUnMatchList 没有匹配预算的费用 |
|
|
* @param actUnMatchList 没有匹配预算的费用 |
|
|
|
|
|
* @param activityAllowBudgetIdMap 满足当前活动项的费用idMap |
|
|
*/ |
|
|
*/ |
|
|
private void matchActivityMain(TbsActivityCenterGoods activityCostItem, |
|
|
private void matchActivityMain(TbsActivityCenterGoods activityCostItem, |
|
|
Boolean throwEx, |
|
|
Boolean throwEx, |
|
|
boolean overspend, |
|
|
boolean overspend, |
|
|
List<TbsActivity> activityList, |
|
|
List<TbsActivity> activityList, |
|
|
Map<Long, List<TbsBudgetCostItem>> hisCostGroupByItemBudget, |
|
|
Map<Long, List<TbsBudgetCostItem>> hisCostGroupByItemBudget, |
|
|
List<TbsBudget> budgetList, |
|
|
final List<TbsBudget> allBudgetList, |
|
|
List<TbsBudget> noConditionBudgetList, |
|
|
List<TbsBudget> noConditionBudgetList, |
|
|
Map<Long, BigDecimal> counterMap, |
|
|
Map<Long, BigDecimal> counterMap, |
|
|
final List<TbsActivityCenterGoods> actMatchList, |
|
|
final List<TbsActivityCenterGoods> actMatchList, |
|
|
final List<TbsActivityCenterGoods> actUnMatchList) { |
|
|
final List<TbsActivityCenterGoods> actUnMatchList, |
|
|
//PS:排序规则:优先匹配品牌条件,其次为时间条件
|
|
|
final Map<Long,List<Long>> activityAllowBudgetIdMap) { |
|
|
|
|
|
//过滤满全条件的预算
|
|
|
|
|
|
List<Long> allowBudgetIds = activityAllowBudgetIdMap.get(activityCostItem.getActivityId()); |
|
|
|
|
|
List<TbsBudget> budgetList = allBudgetList.stream().filter(obj->allowBudgetIds.contains(obj.getId())).collect(Collectors.toList()); |
|
|
|
|
|
//PS:排序规则:优先为时间条件,其次匹配品牌条件
|
|
|
//按品类条件,提取可用预算(列表已按小维度到大维度排列)
|
|
|
//按品类条件,提取可用预算(列表已按小维度到大维度排列)
|
|
|
List<TbsBudget> currentItemBudgetList = this.filterMatchGoodsCondition(budgetList, activityCostItem); |
|
|
List<TbsBudget> currentItemBudgetList = this.filterMatchGoodsCondition(budgetList, activityCostItem); |
|
|
//关联无条件预算
|
|
|
//关联无条件预算
|
|
@ -478,7 +538,8 @@ public class TbsBudgetApplicationService { |
|
|
* @param budgetNoCondition 标识,没有条件的预算 |
|
|
* @param budgetNoCondition 标识,没有条件的预算 |
|
|
*/ |
|
|
*/ |
|
|
private void handleNoBudgetActivity(Boolean throwEx, boolean overspend, List<TbsActivity> activityList, |
|
|
private void handleNoBudgetActivity(Boolean throwEx, boolean overspend, List<TbsActivity> activityList, |
|
|
List<Long> noBudgetActivityIds, boolean budgetNoCondition) { |
|
|
List<Long> noBudgetActivityIds, boolean budgetNoCondition, |
|
|
|
|
|
Map<Long,List<Long>> activityAllowBudgetIdMap) { |
|
|
if(!overspend && !budgetNoCondition && throwEx && noBudgetActivityIds.size()>0){ |
|
|
if(!overspend && !budgetNoCondition && throwEx && noBudgetActivityIds.size()>0){ |
|
|
for (Long activityId : noBudgetActivityIds) { |
|
|
for (Long activityId : noBudgetActivityIds) { |
|
|
for (TbsActivity activity : activityList) { |
|
|
for (TbsActivity activity : activityList) { |
|
@ -489,6 +550,17 @@ public class TbsBudgetApplicationService { |
|
|
} |
|
|
} |
|
|
Assert.throwEx("活动无可用预算"); |
|
|
Assert.throwEx("活动无可用预算"); |
|
|
} |
|
|
} |
|
|
|
|
|
if(throwEx){ |
|
|
|
|
|
for (Long activityId : activityAllowBudgetIdMap.keySet()) { |
|
|
|
|
|
if(activityAllowBudgetIdMap.get(activityId).size()<1){ |
|
|
|
|
|
for (TbsActivity activity : activityList) { |
|
|
|
|
|
if(activity.getId().equals(activityId)){ |
|
|
|
|
|
Assert.throwEx("活动["+activity.getActivityCode()+"]无可用预算"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|