|
@ -4,8 +4,12 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.qs.serve.common.util.Assert; |
|
|
import com.qs.serve.common.util.Assert; |
|
|
import com.qs.serve.common.util.CollectionUtil; |
|
|
import com.qs.serve.common.util.CollectionUtil; |
|
|
import com.qs.serve.modules.sys.service.SysConfigService; |
|
|
import com.qs.serve.modules.sys.service.SysConfigService; |
|
|
|
|
|
import com.qs.serve.modules.tbs.common.TbsGoodsType; |
|
|
|
|
|
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.dto.TbsBudgetItemCostResult; |
|
|
|
|
|
import com.qs.serve.modules.tbs.entity.vo.TbsBudgetTableVo; |
|
|
import com.qs.serve.modules.tbs.mapper.TbsBudgetMapper; |
|
|
import com.qs.serve.modules.tbs.mapper.TbsBudgetMapper; |
|
|
import com.qs.serve.modules.tbs.mapper.TbsScheduleItemBudgetMapper; |
|
|
import com.qs.serve.modules.tbs.mapper.TbsScheduleItemBudgetMapper; |
|
|
import com.qs.serve.modules.tbs.service.TbsBudgetApplicationService; |
|
|
import com.qs.serve.modules.tbs.service.TbsBudgetApplicationService; |
|
@ -17,6 +21,7 @@ import com.qs.serve.modules.tzc.entity.TzcPolicyGoods; |
|
|
import com.qs.serve.modules.tzc.entity.TzcPolicyItem; |
|
|
import com.qs.serve.modules.tzc.entity.TzcPolicyItem; |
|
|
import lombok.AllArgsConstructor; |
|
|
import lombok.AllArgsConstructor; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
import org.jetbrains.annotations.NotNull; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
import java.math.BigDecimal; |
|
@ -33,6 +38,7 @@ import java.util.stream.Collectors; |
|
|
public class TzcPolicyApplication { |
|
|
public class TzcPolicyApplication { |
|
|
|
|
|
|
|
|
private TzcPolicyService tzcPolicyService; |
|
|
private TzcPolicyService tzcPolicyService; |
|
|
|
|
|
private TzcPolicyItemService tzcPolicyItemService; |
|
|
private TzcPolicyGoodsService tzcPolicyGoodsService; |
|
|
private TzcPolicyGoodsService tzcPolicyGoodsService; |
|
|
private TbsBudgetApplicationService budgetApplicationService; |
|
|
private TbsBudgetApplicationService budgetApplicationService; |
|
|
private TbsScheduleItemBudgetService tbsScheduleItemBudgetService; |
|
|
private TbsScheduleItemBudgetService tbsScheduleItemBudgetService; |
|
@ -49,21 +55,25 @@ public class TzcPolicyApplication { |
|
|
//
|
|
|
//
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public TbsBudgetCostResult buildBudgetCostResult(Long policyId, |
|
|
|
|
|
Boolean throwEx, |
|
|
|
|
|
Boolean buildTableFlag){ |
|
|
|
|
|
Boolean overspend = false; |
|
|
|
|
|
List<TzcPolicyItem> policyItemList = tzcPolicyItemService.listByPolicyId(policyId); |
|
|
|
|
|
return this.buildBudgetCostResult(policyId,policyItemList,overspend,throwEx,buildTableFlag); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 创建费用占用结果 |
|
|
* 创建费用占用结果 |
|
|
* @param costApplyId 用于加载历史预算时,排除当前费用占比 |
|
|
* @param policyId 用于加载历史预算时,排除当前费用占比 |
|
|
* @param policyList 政策列表 |
|
|
|
|
|
* @param policyItemList 政策项列表 |
|
|
* @param policyItemList 政策项列表 |
|
|
* @param policyGoodsList 政策商品 |
|
|
|
|
|
* @param overspend 是否支持超出预算 |
|
|
* @param overspend 是否支持超出预算 |
|
|
* @param throwEx 是否需要抛出异常 |
|
|
* @param throwEx 是否需要抛出异常 |
|
|
* @param buildTableFlag 创建表VO |
|
|
* @param buildTableFlag 创建表VO |
|
|
* @return |
|
|
* @return |
|
|
*/ |
|
|
*/ |
|
|
public TbsBudgetCostResult buildBudgetCostResult(Long costApplyId, |
|
|
public TbsBudgetCostResult buildBudgetCostResult(Long policyId, |
|
|
List<TzcPolicy> policyList, |
|
|
|
|
|
List<TzcPolicyItem> policyItemList, |
|
|
List<TzcPolicyItem> policyItemList, |
|
|
List<TzcPolicyGoods> policyGoodsList, |
|
|
|
|
|
Boolean overspend, |
|
|
Boolean overspend, |
|
|
Boolean throwEx, |
|
|
Boolean throwEx, |
|
|
Boolean buildTableFlag){ |
|
|
Boolean buildTableFlag){ |
|
@ -71,7 +81,7 @@ public class TzcPolicyApplication { |
|
|
List<Long> budgetIds = new ArrayList<>(); |
|
|
List<Long> budgetIds = new ArrayList<>(); |
|
|
//没有预算的活动
|
|
|
//没有预算的活动
|
|
|
Set<Long> noBudgetPolicyIds = new HashSet<>(); |
|
|
Set<Long> noBudgetPolicyIds = new HashSet<>(); |
|
|
//所有满足条件的考核期,用于加载历史核销费用
|
|
|
//所有满足条件的考核期,用于加载历史核销费用,并设置不满足时间条件的预算
|
|
|
List<TbsScheduleItemBudget> scheduleItemList = this.loadScheduleBudgetAndSetting(policyItemList, budgetIds, noBudgetPolicyIds); |
|
|
List<TbsScheduleItemBudget> scheduleItemList = this.loadScheduleBudgetAndSetting(policyItemList, budgetIds, noBudgetPolicyIds); |
|
|
List<String> centerIds = policyItemList.stream().map(TzcPolicyItem::getCenterId).collect(Collectors.toList()); |
|
|
List<String> centerIds = policyItemList.stream().map(TzcPolicyItem::getCenterId).collect(Collectors.toList()); |
|
|
List<Long> subjectIds = policyItemList.stream().map(TzcPolicyItem::getSubjectId).distinct().collect(Collectors.toList()); |
|
|
List<Long> subjectIds = policyItemList.stream().map(TzcPolicyItem::getSubjectId).distinct().collect(Collectors.toList()); |
|
@ -89,7 +99,7 @@ public class TzcPolicyApplication { |
|
|
List<TbsBudget> noConditionBudgetList = new ArrayList<>(); |
|
|
List<TbsBudget> noConditionBudgetList = new ArrayList<>(); |
|
|
//加载预算条件和关联预算匹配,返回是否由无条件预算
|
|
|
//加载预算条件和关联预算匹配,返回是否由无条件预算
|
|
|
boolean budgetNoCondition = budgetApplicationService.loadConditionByBudgetsAndMatch(budgetList, noConditionBudgetList); |
|
|
boolean budgetNoCondition = budgetApplicationService.loadConditionByBudgetsAndMatch(budgetList, noConditionBudgetList); |
|
|
//预算条件需包含活动条件, Map结构:活动id->满足的预算id列表
|
|
|
//预算条件需包含活动条件, Map结构:政策id->满足的预算id列表
|
|
|
Map<Long,List<Long>> policyAllowBudgetIdMap = this.buildPolicyBudgetMap(policyItemList, budgetList, noConditionBudgetList); |
|
|
Map<Long,List<Long>> policyAllowBudgetIdMap = this.buildPolicyBudgetMap(policyItemList, budgetList, noConditionBudgetList); |
|
|
//活动拦截
|
|
|
//活动拦截
|
|
|
if(!budgetNoCondition){ |
|
|
if(!budgetNoCondition){ |
|
@ -100,9 +110,10 @@ public class TzcPolicyApplication { |
|
|
//统计费用申请占用金额
|
|
|
//统计费用申请占用金额
|
|
|
Map<Long,BigDecimal> budgetItemApplyAmountMap = new HashMap<>(scheduleItemList.size()); |
|
|
Map<Long,BigDecimal> budgetItemApplyAmountMap = new HashMap<>(scheduleItemList.size()); |
|
|
for (TbsScheduleItemBudget itemBudget : scheduleItemList) { |
|
|
for (TbsScheduleItemBudget itemBudget : scheduleItemList) { |
|
|
BigDecimal budgetItemApplyAmount = tbsScheduleItemBudgetMapper.totalApplyAmount(itemBudget.getId(),costApplyId); |
|
|
//TODO 需要重新检查这里
|
|
|
|
|
|
BigDecimal budgetItemApplyAmount = tbsScheduleItemBudgetMapper.totalApplyAmount(itemBudget.getId(),policyId); |
|
|
budgetItemApplyAmountMap.put(itemBudget.getId(),budgetItemApplyAmount); |
|
|
budgetItemApplyAmountMap.put(itemBudget.getId(),budgetItemApplyAmount); |
|
|
BigDecimal budgetItemAmount = tbsScheduleItemBudgetMapper.totalCostAmount(itemBudget.getBudgetId(),itemBudget.getScheduleItemId(),costApplyId); |
|
|
BigDecimal budgetItemAmount = tbsScheduleItemBudgetMapper.totalCostAmount(itemBudget.getBudgetId(),itemBudget.getScheduleItemId(),policyId); |
|
|
//因为结果为负数,需去相反数
|
|
|
//因为结果为负数,需去相反数
|
|
|
budgetItemAmount = budgetItemAmount==null?BigDecimal.ZERO:budgetItemAmount.negate(); |
|
|
budgetItemAmount = budgetItemAmount==null?BigDecimal.ZERO:budgetItemAmount.negate(); |
|
|
budgetItemAmountMap.put(itemBudget.getId(),budgetItemAmount); |
|
|
budgetItemAmountMap.put(itemBudget.getId(),budgetItemAmount); |
|
@ -110,57 +121,149 @@ public class TzcPolicyApplication { |
|
|
//统计当前活动前置项占用预算
|
|
|
//统计当前活动前置项占用预算
|
|
|
Map<Long,BigDecimal> counterMap = new HashMap<>(); |
|
|
Map<Long,BigDecimal> counterMap = new HashMap<>(); |
|
|
//匹配预算主要方法
|
|
|
//匹配预算主要方法
|
|
|
final List<TbsActivityCenterGoods> actMatchList = new ArrayList<>(); |
|
|
final List<TbsBudgetItemCostResult> actMatchList = new ArrayList<>(); |
|
|
final List<TbsActivityCenterGoods> actUnMatchList = new ArrayList<>(); |
|
|
final List<TbsBudgetItemCostResult> actUnMatchList = new ArrayList<>(); |
|
|
for (TzcPolicyGoods policyGoods : policyGoodsList) { |
|
|
for (TzcPolicyItem policyItem : policyItemList) { |
|
|
// this.matchPolicyMain(policyGoods,throwEx, overspend, activityList, budgetItemAmountMap, budgetList,
|
|
|
this.matchPolicyMain(policyItem,throwEx,overspend,budgetItemAmountMap,budgetList, |
|
|
// noConditionBudgetList, counterMap, actMatchList, actUnMatchList,policyAllowBudgetIdMap,budgetItemApplyAmountMap);
|
|
|
noConditionBudgetList,counterMap,actMatchList, |
|
|
|
|
|
actUnMatchList,policyAllowBudgetIdMap,budgetItemApplyAmountMap); |
|
|
|
|
|
} |
|
|
|
|
|
List<TbsBudgetCostItemPolicy> budgetMatchList = actMatchList.stream() |
|
|
|
|
|
.map(TbsBudgetItemCostResult::toBudgetCostItem).collect(Collectors.toList()); |
|
|
|
|
|
List<TbsBudgetCostItemPolicy> budgetUnMatchList = actUnMatchList.stream() |
|
|
|
|
|
.map(TbsBudgetItemCostResult::toBudgetCostItem).collect(Collectors.toList()); |
|
|
|
|
|
TbsBudgetTableVo tableVo = null; |
|
|
|
|
|
if(buildTableFlag){ |
|
|
|
|
|
//构建tableDTO
|
|
|
|
|
|
tableVo = this.buildBudgetTableVo(budgetItemAmountMap, budgetList, budgetMatchList, budgetUnMatchList); |
|
|
|
|
|
} |
|
|
|
|
|
TbsBudgetCostResult result = new TbsBudgetCostResult(); |
|
|
|
|
|
result.setPolicyBudgetMatchList(budgetMatchList); |
|
|
|
|
|
result.setPolicyBudgetUnMatchList(budgetUnMatchList); |
|
|
|
|
|
result.setTableData(tableVo); |
|
|
|
|
|
result.setBudgetList(budgetList); |
|
|
|
|
|
result.setPolicyItemList(policyItemList); |
|
|
|
|
|
return result; |
|
|
} |
|
|
} |
|
|
return null; |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 建立费用预算表 |
|
|
|
|
|
* @param budgetItemAmountMap |
|
|
|
|
|
* @param budgetList |
|
|
|
|
|
* @param budgetMatchList |
|
|
|
|
|
* @param budgetUnMatchList |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
private TbsBudgetTableVo buildBudgetTableVo(Map<Long,BigDecimal> budgetItemAmountMap, |
|
|
|
|
|
List<TbsBudget> budgetList, |
|
|
|
|
|
List<TbsBudgetCostItemPolicy> budgetMatchList, |
|
|
|
|
|
List<TbsBudgetCostItemPolicy> budgetUnMatchList) { |
|
|
|
|
|
List<TbsBudgetCostItemPolicy> allBudgetItem = new ArrayList<>(); |
|
|
|
|
|
allBudgetItem.addAll(budgetMatchList); |
|
|
|
|
|
allBudgetItem.addAll(budgetUnMatchList); |
|
|
|
|
|
TbsBudgetTableVo tableVo = new TbsBudgetTableVo(); |
|
|
|
|
|
List<TbsBudgetTableVo.TopTheadHeader> topTheadHeaders = new ArrayList<>(); |
|
|
|
|
|
Map<Long,List<TbsBudgetCostItemPolicy>> tmpMap = allBudgetItem.stream().collect(Collectors.groupingBy(TbsBudgetCostItemPolicy::getScheduleItemBudgetId)); |
|
|
|
|
|
for (Long scheduleItemBudgetId : tmpMap.keySet()) { |
|
|
|
|
|
if(scheduleItemBudgetId.equals(0L)){continue;} |
|
|
|
|
|
TbsBudgetCostItemPolicy budgetCostItem = tmpMap.get(scheduleItemBudgetId).get(0); |
|
|
|
|
|
String budgetCode = null; |
|
|
|
|
|
for (TbsBudget budget : budgetList) { |
|
|
|
|
|
if(budget.getId().equals(budgetCostItem.getBudgetId())){ |
|
|
|
|
|
budgetCode = budget.getBudgetCode(); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
BigDecimal budgetAmount = budgetCostItem.getScheduleItemAmount(); |
|
|
|
|
|
String scheduleItemName = budgetCostItem.getScheduleItemName(); |
|
|
|
|
|
TbsBudgetTableVo.TopTheadHeader theadHeader = new TbsBudgetTableVo.TopTheadHeader(); |
|
|
|
|
|
theadHeader.setId(scheduleItemBudgetId+""); |
|
|
|
|
|
theadHeader.setLabel(budgetCode+"("+scheduleItemName+")"); |
|
|
|
|
|
BigDecimal totalUsed = budgetItemAmountMap.get(scheduleItemBudgetId); |
|
|
|
|
|
theadHeader.setBudgetAmount(budgetAmount.subtract(totalUsed)); |
|
|
|
|
|
theadHeader.setTotalAmount(budgetAmount); |
|
|
|
|
|
BigDecimal applyAmount = budgetCostItem.getScheduleItemAmountApply()==null?BigDecimal.ZERO:budgetCostItem.getScheduleItemAmountApply(); |
|
|
|
|
|
theadHeader.setCostApplyAmount(applyAmount); |
|
|
|
|
|
theadHeader.setCostAppliedAmount(totalUsed.subtract(applyAmount)); |
|
|
|
|
|
topTheadHeaders.add(theadHeader); |
|
|
|
|
|
} |
|
|
|
|
|
//自定义超额预算
|
|
|
|
|
|
TbsBudgetTableVo.TopTheadHeader overTopHeader = new TbsBudgetTableVo.TopTheadHeader(); |
|
|
|
|
|
overTopHeader.setId("0"); |
|
|
|
|
|
overTopHeader.setLabel("其它预算"); |
|
|
|
|
|
overTopHeader.setBudgetAmount(BigDecimal.ZERO); |
|
|
|
|
|
topTheadHeaders.add(overTopHeader); |
|
|
|
|
|
|
|
|
|
|
|
List<TbsBudgetTableVo.LeftTheadHeader> leftTheadHeaders = new ArrayList<>(); |
|
|
|
|
|
for (TbsBudgetCostItemPolicy costItemPolicy : allBudgetItem) { |
|
|
|
|
|
String policyItemCode = costItemPolicy.getPolicyItemCode(); |
|
|
|
|
|
Long policyItemId = costItemPolicy.getPolicyItemId(); |
|
|
|
|
|
TbsBudgetTableVo.LeftTheadHeader theadHeader = new TbsBudgetTableVo.LeftTheadHeader(); |
|
|
|
|
|
theadHeader.setActivityCode(policyItemCode); |
|
|
|
|
|
theadHeader.setId(costItemPolicy.getPolicyItemId()+""); |
|
|
|
|
|
theadHeader.setSubjectId(costItemPolicy.getSubjectId()); |
|
|
|
|
|
theadHeader.setSubjectName(costItemPolicy.getSubjectName()); |
|
|
|
|
|
theadHeader.setCenterId(costItemPolicy.getCenterId()); |
|
|
|
|
|
theadHeader.setCenterName(costItemPolicy.getCenterName()); |
|
|
|
|
|
theadHeader.setTargetType("policy_item"); |
|
|
|
|
|
theadHeader.setTargetId(policyItemId); |
|
|
|
|
|
theadHeader.setLabel(policyItemCode); |
|
|
|
|
|
theadHeader.setLabelCombo(policyItemCode); |
|
|
|
|
|
leftTheadHeaders.add(theadHeader); |
|
|
|
|
|
} |
|
|
|
|
|
List<TbsBudgetTableVo.TableValue> tableValueList = new ArrayList<>(); |
|
|
|
|
|
for (TbsBudgetCostItemPolicy costItem : allBudgetItem) { |
|
|
|
|
|
TbsBudgetTableVo.TableValue tableValue = new TbsBudgetTableVo.TableValue(); |
|
|
|
|
|
tableValue.setTopId(costItem.getScheduleItemBudgetId()+""); |
|
|
|
|
|
tableValue.setLeftId(costItem.getPolicyId()+""); |
|
|
|
|
|
tableValue.setValue(costItem.getPolicyItemAmount()); |
|
|
|
|
|
tableValueList.add(tableValue); |
|
|
|
|
|
} |
|
|
|
|
|
tableVo.setTableValueList(tableValueList); |
|
|
|
|
|
tableVo.setTopTheadHeaderList(topTheadHeaders); |
|
|
|
|
|
tableVo.setLeftTheadHeaderList(leftTheadHeaders); |
|
|
|
|
|
return tableVo; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 匹配的主要方法 |
|
|
* 匹配的主要方法 |
|
|
* @param policyGoods 政策商品 |
|
|
* @param policyItem 政策项 |
|
|
* @param throwEx 预算不够时抛出异常 |
|
|
* @param throwEx 预算不够时抛出异常 |
|
|
* @param overspend 超值标识 |
|
|
* @param overspend 超值标识 |
|
|
* @param policyItemList 所有政策项 |
|
|
|
|
|
* @param budgetItemAmountMap 统计所有占用预算金额 |
|
|
* @param budgetItemAmountMap 统计所有占用预算金额 |
|
|
* @param allBudgetList 所有预算 |
|
|
* @param allBudgetList 所有预算 |
|
|
* @param noConditionBudgetList 没有条件的预算列表 |
|
|
* @param noConditionBudgetList 没有条件的预算列表 |
|
|
* @param counterMap 历史预算占用 |
|
|
* @param counterMap 历史预算占用 |
|
|
* @param actMatchList 匹配预算占用的费用(含超支预算) |
|
|
* @param actMatchList 匹配预算占用的费用(含超支预算) |
|
|
* @param actUnMatchList 没有匹配预算的费用 |
|
|
* @param actUnMatchList 没有匹配预算的费用 |
|
|
* @param activityAllowBudgetIdMap 满足当前活动项的费用idMap |
|
|
* @param allowBudgetIdMap 满足当前活动项的费用idMap |
|
|
* @param budgetItemApplyAmountMap 统计费用申请占用金额 |
|
|
* @param budgetItemApplyAmountMap 统计费用申请占用金额 |
|
|
*/ |
|
|
*/ |
|
|
private void matchPolicyMain(TzcPolicyGoods policyGoods, |
|
|
private void matchPolicyMain(TzcPolicyItem policyItem, |
|
|
Boolean throwEx, |
|
|
Boolean throwEx, |
|
|
boolean overspend, |
|
|
boolean overspend, |
|
|
List<TzcPolicyItem> policyItemList, |
|
|
|
|
|
Map<Long,BigDecimal> budgetItemAmountMap, |
|
|
Map<Long,BigDecimal> budgetItemAmountMap, |
|
|
final List<TbsBudget> allBudgetList, |
|
|
final List<TbsBudget> allBudgetList, |
|
|
List<TbsBudget> noConditionBudgetList, |
|
|
List<TbsBudget> noConditionBudgetList, |
|
|
Map<Long, BigDecimal> counterMap, |
|
|
Map<Long, BigDecimal> counterMap, |
|
|
final List<TzcPolicyGoods> actMatchList, |
|
|
final List<TbsBudgetItemCostResult> actMatchList, |
|
|
final List<TzcPolicyGoods> actUnMatchList, |
|
|
final List<TbsBudgetItemCostResult> actUnMatchList, |
|
|
final Map<Long,List<Long>> activityAllowBudgetIdMap, |
|
|
final Map<Long,List<Long>> allowBudgetIdMap, |
|
|
Map<Long,BigDecimal> budgetItemApplyAmountMap) { |
|
|
Map<Long,BigDecimal> budgetItemApplyAmountMap) { |
|
|
|
|
|
TbsBudgetItemCostResult budgetItemCostResult = new TbsBudgetItemCostResult(); |
|
|
|
|
|
budgetItemCostResult.setPolicyItem(policyItem); |
|
|
//过滤满全条件的预算
|
|
|
//过滤满全条件的预算
|
|
|
List<Long> allowBudgetIds = activityAllowBudgetIdMap.get(policyGoods.getPolicyItemId()); |
|
|
List<Long> allowBudgetIds = allowBudgetIdMap.get(policyItem.getId()); |
|
|
List<TbsBudget> budgetList = allBudgetList.stream().filter(obj->allowBudgetIds.contains(obj.getId())).collect(Collectors.toList()); |
|
|
|
|
|
//PS:排序规则:优先为时间条件,其次匹配品牌条件
|
|
|
//PS:排序规则:优先为时间条件,其次匹配品牌条件
|
|
|
|
|
|
List<TbsBudget> budgetList = allBudgetList.stream().filter(obj->allowBudgetIds.contains(obj.getId())).collect(Collectors.toList()); |
|
|
//按品类条件,提取可用预算(列表已按小维度到大维度排列)
|
|
|
//按品类条件,提取可用预算(列表已按小维度到大维度排列)
|
|
|
List<TbsBudget> currentItemBudgetList = budgetApplicationService.filterMatchGoodsCondition(budgetList, policyGoods.getTargetLevelPathIds()); |
|
|
List<TzcPolicyGoods> policyGoodsList = tzcPolicyGoodsService.listByItemId(policyItem.getId()); |
|
|
|
|
|
List<String> levelPathIdsList = policyGoodsList.stream().map(TzcPolicyGoods::getTargetLevelPathIds).collect(Collectors.toList()); |
|
|
|
|
|
List<TbsBudget> currentItemBudgetList = this.filterMatchGoodsCondition(budgetList, levelPathIdsList); |
|
|
//关联无条件预算
|
|
|
//关联无条件预算
|
|
|
currentItemBudgetList.addAll(noConditionBudgetList); |
|
|
currentItemBudgetList.addAll(noConditionBudgetList); |
|
|
//提取可用预算的考核期
|
|
|
//提取可用预算的考核期
|
|
|
List<TbsScheduleItemBudget> currentScheduleItemBudgets = new ArrayList<>(); |
|
|
List<TbsScheduleItemBudget> currentScheduleItemBudgets = new ArrayList<>(); |
|
|
for (TzcPolicyItem policyItem : policyItemList) { |
|
|
|
|
|
//忽略重叠情况
|
|
|
|
|
|
if(!policyGoods.getPolicyItemId().equals(policyItem.getId())){ |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
//当前科目
|
|
|
//当前科目
|
|
|
Long subjectId = policyItem.getSubjectId(); |
|
|
Long subjectId = policyItem.getSubjectId(); |
|
|
//拦截非当前成本中心
|
|
|
//拦截非当前成本中心
|
|
@ -181,82 +284,122 @@ public class TzcPolicyApplication { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
//检测是否有是否足够预算
|
|
|
//检测是否有是否足够预算
|
|
|
// BigDecimal goodsAmount = activityCostItem.getCenterGoodsAmount();
|
|
|
BigDecimal goodsAmount = policyItem.getDiscountMax(); |
|
|
// if(CollectionUtil.isNotEmpty(currentScheduleItemBudgets)){
|
|
|
if(CollectionUtil.isNotEmpty(currentScheduleItemBudgets)){ |
|
|
// boolean isMatch = false;
|
|
|
boolean isMatch = false; |
|
|
// for (TbsScheduleItemBudget itemBudget : currentScheduleItemBudgets) {
|
|
|
for (TbsScheduleItemBudget itemBudget : currentScheduleItemBudgets) { |
|
|
// //历史费用(含申请占用金额)
|
|
|
//历史费用(含申请占用金额)
|
|
|
// BigDecimal totalUsed = budgetItemAmountMap.get(itemBudget.getId());
|
|
|
BigDecimal totalUsed = budgetItemAmountMap.get(itemBudget.getId()); |
|
|
// //当前项费用
|
|
|
//当前项费用
|
|
|
// BigDecimal budgetAmount = itemBudget.getBudgetAmount();
|
|
|
BigDecimal budgetAmount = itemBudget.getBudgetAmount(); |
|
|
// //前置费用
|
|
|
//前置费用
|
|
|
// BigDecimal lastAmount = counterMap.get(itemBudget.getId());
|
|
|
BigDecimal lastAmount = counterMap.get(itemBudget.getId()); |
|
|
// if(lastAmount==null){
|
|
|
if(lastAmount==null){ |
|
|
// lastAmount = BigDecimal.ZERO;
|
|
|
lastAmount = BigDecimal.ZERO; |
|
|
// }
|
|
|
} |
|
|
// //判断是否够用
|
|
|
//判断是否够用
|
|
|
// if(budgetAmount.subtract(lastAmount).subtract(totalUsed).compareTo(goodsAmount)>0){
|
|
|
if(budgetAmount.subtract(lastAmount).subtract(totalUsed).compareTo(goodsAmount)>0){ |
|
|
// activityCostItem.setBudgetId(itemBudget.getBudgetId());
|
|
|
budgetItemCostResult.setBudgetId(itemBudget.getBudgetId()); |
|
|
// activityCostItem.setScheduleId(itemBudget.getScheduleId());
|
|
|
budgetItemCostResult.setScheduleId(itemBudget.getScheduleId()); |
|
|
// activityCostItem.setScheduleItemId(itemBudget.getScheduleItemId());
|
|
|
budgetItemCostResult.setScheduleItemId(itemBudget.getScheduleItemId()); |
|
|
// activityCostItem.setScheduleItemBudgetId(itemBudget.getId());
|
|
|
budgetItemCostResult.setScheduleItemBudgetId(itemBudget.getId()); |
|
|
// activityCostItem.setScheduleItemName(itemBudget.getItemName());
|
|
|
budgetItemCostResult.setScheduleItemName(itemBudget.getItemName()); |
|
|
// //绑定录入时可用预算
|
|
|
//绑定录入时可用预算
|
|
|
// activityCostItem.setScheduleItemAmount(budgetAmount);
|
|
|
budgetItemCostResult.setScheduleItemAmount(budgetAmount); |
|
|
// //剩余的可用预算
|
|
|
//剩余的可用预算
|
|
|
// activityCostItem.setScheduleItemAmountUsed(totalUsed);
|
|
|
budgetItemCostResult.setScheduleItemAmountUsed(totalUsed); |
|
|
// activityCostItem.setScheduleItemAmountApply(budgetItemApplyAmountMap.get(itemBudget.getId()));
|
|
|
budgetItemCostResult.setScheduleItemAmountApply(budgetItemApplyAmountMap.get(itemBudget.getId())); |
|
|
// isMatch = true;
|
|
|
isMatch = true; |
|
|
// //记录当前费用使用考核期费用
|
|
|
//记录当前费用使用考核期费用
|
|
|
// lastAmount = lastAmount.add(goodsAmount);
|
|
|
lastAmount = lastAmount.add(goodsAmount); |
|
|
// counterMap.put(itemBudget.getId(),lastAmount);
|
|
|
counterMap.put(itemBudget.getId(),lastAmount); |
|
|
// actMatchList.add(activityCostItem);
|
|
|
actMatchList.add(budgetItemCostResult); |
|
|
// break;
|
|
|
break; |
|
|
// }
|
|
|
} |
|
|
// }
|
|
|
} |
|
|
// //无匹配的预算
|
|
|
//无匹配的预算
|
|
|
// if(!isMatch){
|
|
|
if(!isMatch){ |
|
|
// if (throwEx){
|
|
|
if (throwEx){ |
|
|
// Assert.throwEx("品类["+ activityCostItem.getTargetName()+"]预算不足");
|
|
|
Assert.throwEx("政策["+ policyItem.getPolicyItemCode()+"]预算不足"); |
|
|
// }
|
|
|
} |
|
|
// if(overspend){
|
|
|
if(overspend){ |
|
|
// TbsScheduleItemBudget itemBudget = currentScheduleItemBudgets.get(0);
|
|
|
TbsScheduleItemBudget itemBudget = currentScheduleItemBudgets.get(0); |
|
|
// activityCostItem.setBudgetId(itemBudget.getBudgetId());
|
|
|
budgetItemCostResult.setBudgetId(itemBudget.getBudgetId()); |
|
|
// activityCostItem.setScheduleId(itemBudget.getScheduleId());
|
|
|
budgetItemCostResult.setScheduleId(itemBudget.getScheduleId()); |
|
|
// activityCostItem.setScheduleItemId(itemBudget.getScheduleItemId());
|
|
|
budgetItemCostResult.setScheduleItemId(itemBudget.getScheduleItemId()); |
|
|
// activityCostItem.setScheduleItemBudgetId(itemBudget.getId());
|
|
|
budgetItemCostResult.setScheduleItemBudgetId(itemBudget.getId()); |
|
|
// activityCostItem.setScheduleItemName(itemBudget.getItemName());
|
|
|
budgetItemCostResult.setScheduleItemName(itemBudget.getItemName()); |
|
|
// //记录当前费用使用考核期费用
|
|
|
//记录当前费用使用考核期费用
|
|
|
// BigDecimal lastAmount = counterMap.get(itemBudget.getId());
|
|
|
BigDecimal lastAmount = counterMap.get(itemBudget.getId()); |
|
|
// if(lastAmount==null){
|
|
|
if(lastAmount==null){ |
|
|
// lastAmount = BigDecimal.ZERO;
|
|
|
lastAmount = BigDecimal.ZERO; |
|
|
// }
|
|
|
} |
|
|
// lastAmount = lastAmount.add(goodsAmount);
|
|
|
lastAmount = lastAmount.add(goodsAmount); |
|
|
// counterMap.put(itemBudget.getId(),lastAmount);
|
|
|
counterMap.put(itemBudget.getId(),lastAmount); |
|
|
// actMatchList.add(activityCostItem);
|
|
|
actMatchList.add(budgetItemCostResult); |
|
|
// }else{
|
|
|
}else{ |
|
|
// activityCostItem.setBudgetId(0L);
|
|
|
budgetItemCostResult.setBudgetId(0L); |
|
|
// activityCostItem.setScheduleId(0L);
|
|
|
budgetItemCostResult.setScheduleId(0L); |
|
|
// activityCostItem.setScheduleItemId(0L);
|
|
|
budgetItemCostResult.setScheduleItemId(0L); |
|
|
// activityCostItem.setScheduleItemBudgetId(0L);
|
|
|
budgetItemCostResult.setScheduleItemBudgetId(0L); |
|
|
// activityCostItem.setScheduleItemName("无");
|
|
|
budgetItemCostResult.setScheduleItemName("无"); |
|
|
// actUnMatchList.add(activityCostItem);
|
|
|
actUnMatchList.add(budgetItemCostResult); |
|
|
// }
|
|
|
} |
|
|
// }
|
|
|
} |
|
|
// }else {
|
|
|
}else { |
|
|
// if(throwEx){
|
|
|
if(throwEx){ |
|
|
// Assert.throwEx("品类["+ activityCostItem.getTargetName()+"]无可用预算");
|
|
|
Assert.throwEx("政策["+ policyItem.getPolicyItemCode()+"]无可用预算"); |
|
|
// }
|
|
|
} |
|
|
// //添加到预算超支表
|
|
|
//添加到预算超支表
|
|
|
// activityCostItem.setBudgetId(0L);
|
|
|
budgetItemCostResult.setBudgetId(0L); |
|
|
// activityCostItem.setScheduleId(0L);
|
|
|
budgetItemCostResult.setScheduleId(0L); |
|
|
// activityCostItem.setScheduleItemId(0L);
|
|
|
budgetItemCostResult.setScheduleItemId(0L); |
|
|
// activityCostItem.setScheduleItemBudgetId(0L);
|
|
|
budgetItemCostResult.setScheduleItemBudgetId(0L); |
|
|
// activityCostItem.setScheduleItemName("无");
|
|
|
budgetItemCostResult.setScheduleItemName("无"); |
|
|
// actUnMatchList.add(activityCostItem);
|
|
|
actUnMatchList.add(budgetItemCostResult); |
|
|
// }
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 按品类条件,提取可用预算 |
|
|
|
|
|
* @param budgetList 预算(已关联参数_条件列表) |
|
|
|
|
|
* @param levelPathIdsList |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
@NotNull |
|
|
|
|
|
public List<TbsBudget> filterMatchGoodsCondition(List<TbsBudget> budgetList,List<String> levelPathIdsList) { |
|
|
|
|
|
List<TbsBudget> currentItemBudgetList = new ArrayList<>(); |
|
|
|
|
|
for (TbsBudget budget : budgetList) { |
|
|
|
|
|
if(budget.getConditionFlag().equals(1)){ |
|
|
|
|
|
List<TbsBudgetCondition> budgetConditionListByBudget = budget.getBudgetConditionList(); |
|
|
|
|
|
boolean anyUnMatch = true; |
|
|
|
|
|
for (String levelPath : levelPathIdsList) { |
|
|
|
|
|
boolean match = false; |
|
|
|
|
|
Set<String> levelPathSet = new LinkedHashSet<>(); |
|
|
|
|
|
levelPathSet.add(levelPath); |
|
|
|
|
|
TbsBudgetCostUtil.buildPaths(levelPath,levelPathSet); |
|
|
|
|
|
for (String conditionString : levelPathSet) { |
|
|
|
|
|
if(!match){ |
|
|
|
|
|
for (TbsBudgetCondition budgetCondition : budgetConditionListByBudget) { |
|
|
|
|
|
if(budgetCondition.getTargetLevelPathIds().contains(conditionString)){ |
|
|
|
|
|
match = true; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if(!match){ |
|
|
|
|
|
anyUnMatch = false; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if(!anyUnMatch){ |
|
|
|
|
|
currentItemBudgetList.add(budget); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return currentItemBudgetList; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|