|
@ -1,23 +1,23 @@ |
|
|
package com.qs.serve.modules.tbs.service; |
|
|
package com.qs.serve.modules.tbs.service; |
|
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.qs.serve.common.model.consts.SysConfigKey; |
|
|
import com.qs.serve.common.model.consts.SysConfigKey; |
|
|
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.bms.service.BmsSupplierService; |
|
|
|
|
|
import com.qs.serve.modules.seeyon.service.SeeYonService; |
|
|
|
|
|
import com.qs.serve.modules.sys.service.SysConfigService; |
|
|
import com.qs.serve.modules.sys.service.SysConfigService; |
|
|
import com.qs.serve.modules.sys.service.SysUserService; |
|
|
import com.qs.serve.modules.tbs.common.TbsGoodsType; |
|
|
import com.qs.serve.modules.tbs.common.util.TbsBudgetCostUtil; |
|
|
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.TbsActivityMapper; |
|
|
|
|
|
import com.qs.serve.modules.tbs.mapper.TbsBudgetMapper; |
|
|
import lombok.AllArgsConstructor; |
|
|
import lombok.AllArgsConstructor; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.jetbrains.annotations.NotNull; |
|
|
import org.jetbrains.annotations.NotNull; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
import java.math.BigDecimal; |
|
|
import java.time.temporal.ChronoField; |
|
|
|
|
|
import java.util.*; |
|
|
import java.util.*; |
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
@ -31,24 +31,16 @@ import java.util.stream.Collectors; |
|
|
@AllArgsConstructor |
|
|
@AllArgsConstructor |
|
|
public class TbsBudgetApplicationService { |
|
|
public class TbsBudgetApplicationService { |
|
|
|
|
|
|
|
|
private TbsCostApplyService tbsCostApplyService; |
|
|
|
|
|
private TbsActivityService tbsActivityService; |
|
|
|
|
|
private TbsActivityCenterGoodsService tbsActivityCenterGoodsService; |
|
|
private TbsActivityCenterGoodsService tbsActivityCenterGoodsService; |
|
|
private TbsScheduleItemBudgetService tbsScheduleItemBudgetService; |
|
|
private TbsScheduleItemBudgetService tbsScheduleItemBudgetService; |
|
|
|
|
|
private TbsBudgetMapper tbsBudgetMapper; |
|
|
private TbsBudgetService tbsBudgetService; |
|
|
|
|
|
private TbsBudgetConditionService tbsBudgetConditionService; |
|
|
private TbsBudgetConditionService tbsBudgetConditionService; |
|
|
private TbsBudgetCostItemService tbsBudgetCostItemService; |
|
|
private TbsBudgetCostItemService tbsBudgetCostItemService; |
|
|
|
|
|
|
|
|
private BmsSupplierService bmsSupplierService; |
|
|
|
|
|
|
|
|
|
|
|
private SysUserService sysUserService; |
|
|
|
|
|
private SysConfigService configService; |
|
|
private SysConfigService configService; |
|
|
|
|
|
private TbsActivityMapper activityMapper; |
|
|
private SeeYonService seeYonService; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* |
|
|
* 创建费用占用结果 |
|
|
* @param costApplyId |
|
|
* @param costApplyId |
|
|
* @param throwEx 是否需要抛出异常 |
|
|
* @param throwEx 是否需要抛出异常 |
|
|
* @param buildTableFlag 创建表VO |
|
|
* @param buildTableFlag 创建表VO |
|
@ -57,12 +49,11 @@ public class TbsBudgetApplicationService { |
|
|
//允许超出预算标识
|
|
|
//允许超出预算标识
|
|
|
boolean overspend = configService.getByKey(SysConfigKey.TbsBudgetOverspend).getConfigValue().equals("1"); |
|
|
boolean overspend = configService.getByKey(SysConfigKey.TbsBudgetOverspend).getConfigValue().equals("1"); |
|
|
//加载活动
|
|
|
//加载活动
|
|
|
List<TbsActivity> activityList = tbsActivityService.listByCostApplyId(costApplyId); |
|
|
LambdaQueryWrapper<TbsActivity> activityLqw = new LambdaQueryWrapper<>(); |
|
|
|
|
|
activityLqw.eq(TbsActivity::getCostApplyId,costApplyId); |
|
|
|
|
|
List<TbsActivity> activityList = activityMapper.selectList(activityLqw); |
|
|
if(activityList.size()<1){ |
|
|
if(activityList.size()<1){ |
|
|
if(throwEx){ |
|
|
Assert.throwEx("当前费用未设置活动"); |
|
|
Assert.throwEx("当前费用未设置活动"); |
|
|
|
|
|
} |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
} |
|
|
//考核期有关的预算id,判断逻辑为活动需要允许在
|
|
|
//考核期有关的预算id,判断逻辑为活动需要允许在
|
|
|
List<Long> budgetIds = new ArrayList<>(); |
|
|
List<Long> budgetIds = new ArrayList<>(); |
|
@ -72,13 +63,21 @@ public class TbsBudgetApplicationService { |
|
|
List<TbsScheduleItemBudget> scheduleItemList = this.loadScheduleBudgetAndSetting(activityList, budgetIds, noBudgetActivityIds); |
|
|
List<TbsScheduleItemBudget> scheduleItemList = this.loadScheduleBudgetAndSetting(activityList, budgetIds, noBudgetActivityIds); |
|
|
//加载预算占用历史
|
|
|
//加载预算占用历史
|
|
|
List<Long> scheduleItemBudgetIds = scheduleItemList.stream().map(TbsScheduleItemBudget::getId).collect(Collectors.toList()); |
|
|
List<Long> scheduleItemBudgetIds = scheduleItemList.stream().map(TbsScheduleItemBudget::getId).collect(Collectors.toList()); |
|
|
List<TbsBudgetCostItem> hisBudgetCostItemList = tbsBudgetCostItemService.listByScheduleItemBudgetIds(scheduleItemBudgetIds); |
|
|
List<TbsBudgetCostItem> hisBudgetCostItemList = tbsBudgetCostItemService.listByScheduleItemBudgetIds(scheduleItemBudgetIds,costApplyId); |
|
|
Map<Long,List<TbsBudgetCostItem>> hisCostGroupByItemBudget = hisBudgetCostItemList.stream() |
|
|
Map<Long,List<TbsBudgetCostItem>> hisCostGroupByItemBudget = hisBudgetCostItemList.stream() |
|
|
.collect(Collectors.groupingBy(TbsBudgetCostItem::getScheduleItemBudgetId)); |
|
|
.collect(Collectors.groupingBy(TbsBudgetCostItem::getScheduleItemBudgetId)); |
|
|
// 构建预算费用占用明细
|
|
|
// 构建预算费用占用明细
|
|
|
List<TbsActivityCenterGoods> centerGoodsList = tbsActivityCenterGoodsService.listByCostApplyId(costApplyId); |
|
|
List<TbsActivityCenterGoods> centerGoodsList = tbsActivityCenterGoodsService.listByCostApplyId(costApplyId); |
|
|
// 加载所有条件
|
|
|
// 加载所有条件
|
|
|
List<TbsBudget> budgetList = budgetIds.size()>0?tbsBudgetService.listByIds(budgetIds):new ArrayList<>(); |
|
|
List<TbsBudget> budgetList; |
|
|
|
|
|
if(budgetIds.size()>0){ |
|
|
|
|
|
LambdaQueryWrapper<TbsBudget> budgetLqw = new LambdaQueryWrapper<>(); |
|
|
|
|
|
budgetLqw.in(TbsBudget::getId,budgetIds); |
|
|
|
|
|
budgetLqw.eq(TbsBudget::getBudgetState,1); |
|
|
|
|
|
budgetList = tbsBudgetMapper.selectList(budgetLqw); |
|
|
|
|
|
}else { |
|
|
|
|
|
budgetList = new ArrayList<>(); |
|
|
|
|
|
} |
|
|
List<TbsBudget> noConditionBudgetList = new ArrayList<>(); |
|
|
List<TbsBudget> noConditionBudgetList = new ArrayList<>(); |
|
|
boolean budgetNoCondition = this.loadConditionByBudgetsAndMatch(budgetList, noConditionBudgetList); |
|
|
boolean budgetNoCondition = this.loadConditionByBudgetsAndMatch(budgetList, noConditionBudgetList); |
|
|
//活动拦截
|
|
|
//活动拦截
|
|
@ -127,7 +126,6 @@ public class TbsBudgetApplicationService { |
|
|
List<TbsBudgetCostItem> allBudgetItem = new ArrayList<>(); |
|
|
List<TbsBudgetCostItem> allBudgetItem = new ArrayList<>(); |
|
|
allBudgetItem.addAll(budgetMatchList); |
|
|
allBudgetItem.addAll(budgetMatchList); |
|
|
allBudgetItem.addAll(budgetUnMatchList); |
|
|
allBudgetItem.addAll(budgetUnMatchList); |
|
|
|
|
|
|
|
|
TbsBudgetTableVo tableVo = new TbsBudgetTableVo(); |
|
|
TbsBudgetTableVo tableVo = new TbsBudgetTableVo(); |
|
|
List<TbsBudgetTableVo.TopTheadHeader> topTheadHeaders = new ArrayList<>(); |
|
|
List<TbsBudgetTableVo.TopTheadHeader> topTheadHeaders = new ArrayList<>(); |
|
|
Map<Long,List<TbsBudgetCostItem>> tmpMap = allBudgetItem.stream().collect(Collectors.groupingBy(TbsBudgetCostItem::getScheduleItemBudgetId)); |
|
|
Map<Long,List<TbsBudgetCostItem>> tmpMap = allBudgetItem.stream().collect(Collectors.groupingBy(TbsBudgetCostItem::getScheduleItemBudgetId)); |
|
@ -149,7 +147,6 @@ public class TbsBudgetApplicationService { |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
TbsBudgetTableVo.TopTheadHeader theadHeader = new TbsBudgetTableVo.TopTheadHeader(); |
|
|
TbsBudgetTableVo.TopTheadHeader theadHeader = new TbsBudgetTableVo.TopTheadHeader(); |
|
|
theadHeader.setId(scheduleItemBudgetId+""); |
|
|
theadHeader.setId(scheduleItemBudgetId+""); |
|
|
theadHeader.setLabel(budgetCode+"("+scheduleItemName+")"); |
|
|
theadHeader.setLabel(budgetCode+"("+scheduleItemName+")"); |
|
@ -160,7 +157,7 @@ public class TbsBudgetApplicationService { |
|
|
//自定义超额预算
|
|
|
//自定义超额预算
|
|
|
TbsBudgetTableVo.TopTheadHeader overTopHeader = new TbsBudgetTableVo.TopTheadHeader(); |
|
|
TbsBudgetTableVo.TopTheadHeader overTopHeader = new TbsBudgetTableVo.TopTheadHeader(); |
|
|
overTopHeader.setId("0"); |
|
|
overTopHeader.setId("0"); |
|
|
overTopHeader.setLabel("超额预算"); |
|
|
overTopHeader.setLabel("其它预算"); |
|
|
overTopHeader.setBudgetAmount(BigDecimal.ZERO); |
|
|
overTopHeader.setBudgetAmount(BigDecimal.ZERO); |
|
|
topTheadHeaders.add(overTopHeader); |
|
|
topTheadHeaders.add(overTopHeader); |
|
|
|
|
|
|
|
@ -170,13 +167,29 @@ public class TbsBudgetApplicationService { |
|
|
for (TbsActivity obj : activityList) { |
|
|
for (TbsActivity obj : activityList) { |
|
|
if(obj.getId().equals(centerGoods.getActivityId())){ |
|
|
if(obj.getId().equals(centerGoods.getActivityId())){ |
|
|
activity = obj; |
|
|
activity = obj; |
|
|
|
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
String actCode = activity==null?centerGoods.getActivityId().toString():activity.getActivityCode(); |
|
|
TbsBudgetTableVo.LeftTheadHeader theadHeader = new TbsBudgetTableVo.LeftTheadHeader(); |
|
|
TbsBudgetTableVo.LeftTheadHeader theadHeader = new TbsBudgetTableVo.LeftTheadHeader(); |
|
|
|
|
|
theadHeader.setActivityCode(actCode); |
|
|
theadHeader.setId(centerGoods.getCenterGoodItemId()+""); |
|
|
theadHeader.setId(centerGoods.getCenterGoodItemId()+""); |
|
|
String label = (activity==null?centerGoods.getActivityId():activity.getActivityCode())+"-"+centerGoods.getCenterName()+"-" |
|
|
theadHeader.setSubjectId(centerGoods.getSubjectId()); |
|
|
+centerGoods.getSubjectName()+"-"+centerGoods.getTargetName(); |
|
|
theadHeader.setSubjectName(centerGoods.getSubjectName()); |
|
|
theadHeader.setLabel(label); |
|
|
theadHeader.setCenterId(centerGoods.getCenterId()); |
|
|
|
|
|
theadHeader.setCenterName(centerGoods.getCenterName()); |
|
|
|
|
|
theadHeader.setTargetType(centerGoods.getTargetType()); |
|
|
|
|
|
theadHeader.setTargetId(centerGoods.getTargetId()); |
|
|
|
|
|
if(centerGoods.getTargetType().equals(TbsGoodsType.sku.name())){ |
|
|
|
|
|
centerGoods.initSpuSkuName(); |
|
|
|
|
|
theadHeader.setLabel(centerGoods.getSpuName()+"("+centerGoods.getSkuName()+")"); |
|
|
|
|
|
}else { |
|
|
|
|
|
theadHeader.setLabel(centerGoods.getTargetName()); |
|
|
|
|
|
} |
|
|
|
|
|
theadHeader.setLabelCombo(actCode+"-" |
|
|
|
|
|
+theadHeader.getSubjectName()+"-" |
|
|
|
|
|
+theadHeader.getCenterName()+"-" |
|
|
|
|
|
+theadHeader.getLabel()); |
|
|
leftTheadHeaders.add(theadHeader); |
|
|
leftTheadHeaders.add(theadHeader); |
|
|
} |
|
|
} |
|
|
List<TbsBudgetTableVo.TableValue> tableValueList = new ArrayList<>(); |
|
|
List<TbsBudgetTableVo.TableValue> tableValueList = new ArrayList<>(); |
|
@ -195,16 +208,16 @@ public class TbsBudgetApplicationService { |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 匹配的主要方法 |
|
|
* 匹配的主要方法 |
|
|
* @param activityCostItem |
|
|
* @param activityCostItem 活动项 |
|
|
* @param throwEx |
|
|
* @param throwEx 预算不够时抛出异常 |
|
|
* @param overspend |
|
|
* @param overspend 超值标识 |
|
|
* @param activityList |
|
|
* @param activityList 所有活动 |
|
|
* @param hisCostGroupByItemBudget 历史费用组 |
|
|
* @param hisCostGroupByItemBudget 历史费用组 |
|
|
* @param budgetList |
|
|
* @param budgetList 所有预算 |
|
|
* @param noConditionBudgetList |
|
|
* @param noConditionBudgetList 没有条件的预算列表 |
|
|
* @param counterMap |
|
|
* @param counterMap 历史预算占用 |
|
|
* @param actMatchList |
|
|
* @param actMatchList 匹配预算占用的费用(含超支预算) |
|
|
* @param actUnMatchList |
|
|
* @param actUnMatchList 没有匹配预算的费用 |
|
|
*/ |
|
|
*/ |
|
|
private void matchActivityMain(TbsActivityCenterGoods activityCostItem, |
|
|
private void matchActivityMain(TbsActivityCenterGoods activityCostItem, |
|
|
Boolean throwEx, |
|
|
Boolean throwEx, |
|
|