|
|
@ -9,6 +9,8 @@ import com.qs.serve.modules.sys.service.SysConfigService; |
|
|
|
import com.qs.serve.modules.sys.service.SysUserService; |
|
|
|
import com.qs.serve.modules.tbs.common.util.TbsBudgetCostUtil; |
|
|
|
import com.qs.serve.modules.tbs.entity.*; |
|
|
|
import com.qs.serve.modules.tbs.entity.dto.TbsBudgetCostResult; |
|
|
|
import com.qs.serve.modules.tbs.entity.vo.TbsBudgetTableVo; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.jetbrains.annotations.NotNull; |
|
|
@ -49,12 +51,19 @@ public class TbsBudgetApplicationService { |
|
|
|
* |
|
|
|
* @param costApplyId |
|
|
|
* @param throwEx 是否需要抛出异常 |
|
|
|
* @param buildTableFlag 创建表VO |
|
|
|
*/ |
|
|
|
public void commit(Long costApplyId,Boolean throwEx){ |
|
|
|
public TbsBudgetCostResult buildBudgetCostResult(Long costApplyId,Boolean throwEx,Boolean buildTableFlag){ |
|
|
|
//允许超出预算标识
|
|
|
|
boolean overspend = configService.getByKey(SysConfigKey.TbsBudgetOverspend).getConfigValue().equals("1"); |
|
|
|
//加载待核销活动
|
|
|
|
List<TbsActivity> activityList = tbsActivityService.listByCostApplyIdAndTodoState(costApplyId); |
|
|
|
//加载活动
|
|
|
|
List<TbsActivity> activityList = tbsActivityService.listByCostApplyId(costApplyId); |
|
|
|
if(activityList.size()<1){ |
|
|
|
if(throwEx){ |
|
|
|
Assert.throwEx("当前费用未设置活动"); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
//考核期有关的预算id,判断逻辑为活动需要允许在
|
|
|
|
List<Long> budgetIds = new ArrayList<>(); |
|
|
|
//没有预算的活动
|
|
|
@ -69,7 +78,7 @@ public class TbsBudgetApplicationService { |
|
|
|
// 构建预算费用占用明细
|
|
|
|
List<TbsActivityCenterGoods> centerGoodsList = tbsActivityCenterGoodsService.listByCostApplyId(costApplyId); |
|
|
|
// 加载所有条件
|
|
|
|
List<TbsBudget> budgetList = tbsBudgetService.listByIds(budgetIds); |
|
|
|
List<TbsBudget> budgetList = budgetIds.size()>0?tbsBudgetService.listByIds(budgetIds):new ArrayList<>(); |
|
|
|
List<TbsBudget> noConditionBudgetList = new ArrayList<>(); |
|
|
|
boolean budgetNoCondition = this.loadConditionByBudgetsAndMatch(budgetList, noConditionBudgetList); |
|
|
|
//活动拦截
|
|
|
@ -80,10 +89,108 @@ public class TbsBudgetApplicationService { |
|
|
|
final List<TbsActivityCenterGoods> actMatchList = new ArrayList<>(); |
|
|
|
final List<TbsActivityCenterGoods> actUnMatchList = new ArrayList<>(); |
|
|
|
for (TbsActivityCenterGoods activityCostItem : centerGoodsList) { |
|
|
|
this.matchActivityMain(activityCostItem,throwEx, overspend, activityList, hisCostGroupByItemBudget, budgetList, noConditionBudgetList, counterMap, actMatchList, actUnMatchList); |
|
|
|
this.matchActivityMain(activityCostItem,throwEx, overspend, activityList, hisCostGroupByItemBudget, budgetList, |
|
|
|
noConditionBudgetList, counterMap, actMatchList, actUnMatchList); |
|
|
|
} |
|
|
|
List<TbsBudgetCostItem> budgetMatchList = actMatchList.stream() |
|
|
|
.map(TbsActivityCenterGoods::toBudgetCostItem).collect(Collectors.toList()); |
|
|
|
List<TbsBudgetCostItem> budgetUnMatchList = actUnMatchList.stream() |
|
|
|
.map(TbsActivityCenterGoods::toBudgetCostItem).collect(Collectors.toList()); |
|
|
|
TbsBudgetTableVo tableVo = null; |
|
|
|
if(buildTableFlag){ |
|
|
|
//构建tableDTO
|
|
|
|
tableVo = this.buildBudgetTableVo(activityList, scheduleItemList, hisCostGroupByItemBudget, budgetList, budgetMatchList, budgetUnMatchList); |
|
|
|
} |
|
|
|
TbsBudgetCostResult result = new TbsBudgetCostResult(); |
|
|
|
result.setBudgetMatchList(budgetMatchList); |
|
|
|
result.setBudgetUnMatchList(budgetUnMatchList); |
|
|
|
result.setTableData(tableVo); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 建立费用预算表 |
|
|
|
* @param activityList |
|
|
|
* @param scheduleItemList |
|
|
|
* @param hisCostGroupByItemBudget |
|
|
|
* @param budgetList |
|
|
|
* @param budgetMatchList |
|
|
|
* @param budgetUnMatchList |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private TbsBudgetTableVo buildBudgetTableVo(List<TbsActivity> activityList, |
|
|
|
List<TbsScheduleItemBudget> scheduleItemList, |
|
|
|
Map<Long, List<TbsBudgetCostItem>> hisCostGroupByItemBudget, |
|
|
|
List<TbsBudget> budgetList, |
|
|
|
List<TbsBudgetCostItem> budgetMatchList, |
|
|
|
List<TbsBudgetCostItem> budgetUnMatchList) { |
|
|
|
List<TbsBudgetCostItem> allBudgetItem = new ArrayList<>(); |
|
|
|
allBudgetItem.addAll(budgetMatchList); |
|
|
|
allBudgetItem.addAll(budgetUnMatchList); |
|
|
|
|
|
|
|
TbsBudgetTableVo tableVo = new TbsBudgetTableVo(); |
|
|
|
List<TbsBudgetTableVo.TopTheadHeader> topTheadHeaders = new ArrayList<>(); |
|
|
|
Map<Long,List<TbsBudgetCostItem>> tmpMap = allBudgetItem.stream().collect(Collectors.groupingBy(TbsBudgetCostItem::getScheduleItemBudgetId)); |
|
|
|
for (Long scheduleItemBudgetId : tmpMap.keySet()) { |
|
|
|
TbsBudgetCostItem itemBudget = tmpMap.get(scheduleItemBudgetId).get(0); |
|
|
|
String budgetCode = null; |
|
|
|
for (TbsBudget budget : budgetList) { |
|
|
|
if(budget.getId().equals(itemBudget.getBudgetId())){ |
|
|
|
budgetCode = budget.getBudgetCode(); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
BigDecimal budgetAmount = BigDecimal.ZERO; |
|
|
|
String scheduleItemName = null; |
|
|
|
for (TbsScheduleItemBudget scheduleItemBudget : scheduleItemList) { |
|
|
|
if(scheduleItemBudget.getId().equals(scheduleItemBudgetId)){ |
|
|
|
budgetAmount = scheduleItemBudget.getBudgetAmount(); |
|
|
|
scheduleItemName = scheduleItemBudget.getItemName(); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
TbsBudgetTableVo.TopTheadHeader theadHeader = new TbsBudgetTableVo.TopTheadHeader(); |
|
|
|
theadHeader.setId(scheduleItemBudgetId+""); |
|
|
|
theadHeader.setLabel(budgetCode+"("+scheduleItemName+")"); |
|
|
|
BigDecimal totalUsed = TbsBudgetCostUtil.totalHisCost(hisCostGroupByItemBudget.get(itemBudget.getId())); |
|
|
|
theadHeader.setBudgetAmount(budgetAmount.subtract(totalUsed)); |
|
|
|
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 (TbsBudgetCostItem centerGoods : allBudgetItem) { |
|
|
|
TbsActivity activity = null; |
|
|
|
for (TbsActivity obj : activityList) { |
|
|
|
if(obj.getId().equals(centerGoods.getActivityId())){ |
|
|
|
activity = obj; |
|
|
|
} |
|
|
|
} |
|
|
|
TbsBudgetTableVo.LeftTheadHeader theadHeader = new TbsBudgetTableVo.LeftTheadHeader(); |
|
|
|
theadHeader.setId(centerGoods.getCenterGoodItemId()+""); |
|
|
|
String label = (activity==null?centerGoods.getActivityId():activity.getActivityCode())+"-"+centerGoods.getCenterName()+"-" |
|
|
|
+centerGoods.getSubjectName()+"-"+centerGoods.getTargetName(); |
|
|
|
theadHeader.setLabel(label); |
|
|
|
leftTheadHeaders.add(theadHeader); |
|
|
|
} |
|
|
|
List<TbsBudgetTableVo.TableValue> tableValueList = new ArrayList<>(); |
|
|
|
for (TbsBudgetCostItem costItem : allBudgetItem) { |
|
|
|
TbsBudgetTableVo.TableValue tableValue = new TbsBudgetTableVo.TableValue(); |
|
|
|
tableValue.setTopId(costItem.getScheduleItemBudgetId()+""); |
|
|
|
tableValue.setLeftId(costItem.getCenterGoodItemId()+""); |
|
|
|
tableValue.setValue(costItem.getCenterGoodsAmount()); |
|
|
|
tableValueList.add(tableValue); |
|
|
|
} |
|
|
|
List<TbsBudgetCostItem> budgetCostItems1 = TbsBudgetCostUtil.createBudgetCostItems(actMatchList); |
|
|
|
List<TbsBudgetCostItem> budgetCostItems2 = TbsBudgetCostUtil.createBudgetCostItems(actUnMatchList); |
|
|
|
tableVo.setTableValueList(tableValueList); |
|
|
|
tableVo.setTopTheadHeaderList(topTheadHeaders); |
|
|
|
tableVo.setLeftTheadHeaderList(leftTheadHeaders); |
|
|
|
return tableVo; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -178,6 +285,10 @@ public class TbsBudgetApplicationService { |
|
|
|
} |
|
|
|
if(overspend){ |
|
|
|
//添加到预算超支表
|
|
|
|
activityCostItem.setBudgetId(0L); |
|
|
|
activityCostItem.setScheduleId(0L); |
|
|
|
activityCostItem.setScheduleItemId(0L); |
|
|
|
activityCostItem.setScheduleItemBudgetId(0L); |
|
|
|
actUnMatchList.add(activityCostItem); |
|
|
|
} |
|
|
|
} |
|
|
@ -246,7 +357,8 @@ public class TbsBudgetApplicationService { |
|
|
|
* @param noBudgetActivityIds 没有预算的活动id |
|
|
|
* @param budgetNoCondition 标识,没有条件的预算 |
|
|
|
*/ |
|
|
|
private void handleNoBudgetActivity(Boolean throwEx, boolean overspend, List<TbsActivity> activityList, List<Long> noBudgetActivityIds, boolean budgetNoCondition) { |
|
|
|
private void handleNoBudgetActivity(Boolean throwEx, boolean overspend, List<TbsActivity> activityList, |
|
|
|
List<Long> noBudgetActivityIds, boolean budgetNoCondition) { |
|
|
|
if(!overspend && !budgetNoCondition && throwEx && noBudgetActivityIds.size()>0){ |
|
|
|
for (Long activityId : noBudgetActivityIds) { |
|
|
|
for (TbsActivity activity : activityList) { |
|
|
@ -267,7 +379,8 @@ public class TbsBudgetApplicationService { |
|
|
|
* @param budgetIds |
|
|
|
* @param noBudgetActivityIds |
|
|
|
*/ |
|
|
|
public List<TbsScheduleItemBudget> loadScheduleBudgetAndSetting(List<TbsActivity> activityList, List<Long> budgetIds, List<Long> noBudgetActivityIds) { |
|
|
|
public List<TbsScheduleItemBudget> loadScheduleBudgetAndSetting(List<TbsActivity> activityList, |
|
|
|
List<Long> budgetIds, List<Long> noBudgetActivityIds) { |
|
|
|
List<TbsScheduleItemBudget> scheduleItemList = new ArrayList<>(); |
|
|
|
Set<Long> budgetIdsSet = new HashSet<>(); |
|
|
|
Map<Long,TbsScheduleItemBudget> allAllowScheduleItemTempMap = new HashMap<>(); |
|
|
|