|
|
@ -14,6 +14,7 @@ import com.qs.serve.common.util.model.DateFormatString; |
|
|
|
import com.qs.serve.modules.bir.entity.BirActivityCenterGoods; |
|
|
|
import com.qs.serve.modules.bir.entity.dto.BirRoiCostDTO; |
|
|
|
import com.qs.serve.modules.bir.entity.vo.YtdQtdToOAVo; |
|
|
|
import com.qs.serve.modules.bir.service.BirCenterRateService; |
|
|
|
import com.qs.serve.modules.bir.service.BirRoiRateService; |
|
|
|
import com.qs.serve.modules.bms.entity.BmsRegion; |
|
|
|
import com.qs.serve.modules.bms.entity.BmsRegion2; |
|
|
@ -100,6 +101,7 @@ public class TbsCostApplyServiceImpl extends ServiceImpl<TbsCostApplyMapper,TbsC |
|
|
|
private TbsCostContractMapper costContractMapper; |
|
|
|
private VtbVerificationMapper verificationMapper; |
|
|
|
private SysAttachService sysAttachService; |
|
|
|
private BirCenterRateService centerRateService; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@ -609,184 +611,17 @@ public class TbsCostApplyServiceImpl extends ServiceImpl<TbsCostApplyMapper,TbsC |
|
|
|
for (String subjectName : subjectNames) { |
|
|
|
subList.add(new TbsCostSubItem.Subject(subjectName)); |
|
|
|
} |
|
|
|
//成本中心去重
|
|
|
|
Map<String,List<TbsActivityCenter>> centerMapList = tbsActivityCenters.stream().collect(Collectors.groupingBy(a->a.getCenterType()+"-"+a.getCenterId())); |
|
|
|
List<TbsActivityCenter> centerList = centerMapList.values().stream().map(a->a.get(0)).collect(Collectors.toList()); |
|
|
|
|
|
|
|
//目标费率和成本中心统计
|
|
|
|
List<TbsBudgetCostItem> tbsBudgetCostItems = result.getBudgetMatchList(); |
|
|
|
List<Long> scheduleItemBudgetIds = tbsBudgetCostItems.stream().map(a->a.getScheduleItemBudgetId()).distinct().collect(Collectors.toList()); |
|
|
|
List<TbsScheduleItemBudget> tbsScheduleItemBudgets = tbsScheduleItemBudgetMapper.selectBatchIds(scheduleItemBudgetIds); |
|
|
|
/*for(TbsScheduleItemBudget tbsScheduleItemBudget : tbsScheduleItemBudgets){ |
|
|
|
subList.add( |
|
|
|
new TbsCostSubItem.Amount( |
|
|
|
tbsScheduleItemBudget.getBudgetAmount(), |
|
|
|
tbsScheduleItemBudget.getPreDispatchAmount(), |
|
|
|
tbsScheduleItemBudget.compareTargetExpenseRate() |
|
|
|
) |
|
|
|
); |
|
|
|
}*/ |
|
|
|
|
|
|
|
//查询发货金额,并按月份分割
|
|
|
|
int year = LocalDate.now().getYear(); |
|
|
|
int month = LocalDate.now().getMonthValue(); |
|
|
|
int startMonthNum = Integer.parseInt(year+"01"); |
|
|
|
int endMonthNum = Integer.parseInt(year+"01"); |
|
|
|
tbsActivityCenters.stream().collect(Collectors.groupingBy(TbsActivityCenter::getCenterType)); |
|
|
|
BirRoiRateService roiRateService = SpringUtils.getBean(BirRoiRateService.class); |
|
|
|
BirRoiCostDTO costDTO = new BirRoiCostDTO(); |
|
|
|
costDTO.setStartMonthNum(startMonthNum); |
|
|
|
costDTO.setEndMonthNum(endMonthNum); |
|
|
|
/*成本中心维度*/ |
|
|
|
//发货单
|
|
|
|
Map<String,List<ErpDispatchSumVo>> supplierCodeMapWithCenterType = new HashMap<>(); |
|
|
|
Map<String,List<TbsActivityCenter>> centerMapList = tbsActivityCenters.stream().collect(Collectors.groupingBy(TbsActivityCenter::getCenterType)); |
|
|
|
for (String centerType : centerMapList.keySet()) { |
|
|
|
List<String> centerIds =centerMapList.get(centerType).stream().map(TbsActivityCenter::getCenterId).collect(Collectors.toList()); |
|
|
|
List<String> supplierCodeList = roiRateService.getSupplierCodesByCenter(costDTO,centerType,centerIds); |
|
|
|
//发货单
|
|
|
|
List<ErpDispatchSumVo> dispatchSumVos = null; |
|
|
|
if(supplierCodeList!=null&&supplierCodeList.size()>0){ |
|
|
|
dispatchSumVos = dispatchDataMapper.querySumCost(startMonthNum,endMonthNum,supplierCodeList); |
|
|
|
supplierCodeMapWithCenterType.put(centerType,dispatchSumVos); |
|
|
|
}else { |
|
|
|
//防止后面获取空指针
|
|
|
|
supplierCodeMapWithCenterType.put(centerType,new ArrayList<>()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//查询ROI底表,并拼接DTO
|
|
|
|
List<TbsCenterGoodBirDTO> centerGoodDTOS = new ArrayList<>(); |
|
|
|
List<BirActivityCenterGoods> birActivityCenterGoodsList = new ArrayList<>(); |
|
|
|
//按成本中心维度分组
|
|
|
|
Map<String,List<BirActivityCenterGoods>> birGroupByCenter = birActivityCenterGoodsList.stream() |
|
|
|
.collect(Collectors.groupingBy(a->a.getCenterType()+"_"+a.getCenterId())); |
|
|
|
|
|
|
|
for (TbsActivityCenter activityCenter : tbsActivityCenters) { |
|
|
|
String centerKey = activityCenter.getCenterType()+"_"+activityCenter.getCenterId(); |
|
|
|
//创建成本中心维度对象
|
|
|
|
TbsCostSubItem.CostCenter costCenter = this.buildCostCenterParam(result, tbsScheduleItemBudgets, |
|
|
|
year, month, supplierCodeMapWithCenterType, birGroupByCenter, activityCenter, centerKey); |
|
|
|
for(TbsActivityCenter center : centerList){ |
|
|
|
TbsCostSubItem.CostCenterTranStr costCenter = centerRateService.buildCostCenter(center.getCenterType(),center.getCenterId(),center.getCenterName()); |
|
|
|
subList.add(costCenter); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 创建成本中心维度对象 |
|
|
|
* @param result |
|
|
|
* @param tbsScheduleItemBudgets |
|
|
|
* @param year |
|
|
|
* @param month |
|
|
|
* @param supplierCodeMapWithCenterType |
|
|
|
* @param birGroupByCenter |
|
|
|
* @param activityCenter |
|
|
|
* @param centerKey |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@NotNull |
|
|
|
private TbsCostSubItem.CostCenter buildCostCenterParam(TbsBudgetCostResult result, List<TbsScheduleItemBudget> tbsScheduleItemBudgets, int year, int month, Map<String, List<ErpDispatchSumVo>> supplierCodeMapWithCenterType, Map<String, List<BirActivityCenterGoods>> birGroupByCenter, TbsActivityCenter activityCenter, String centerKey) { |
|
|
|
TbsCostSubItem.CostCenter costCenter = new TbsCostSubItem.CostCenter(activityCenter.getCenterName(), |
|
|
|
activityCenter.getCenterType()+"_"+ activityCenter.getCenterId()); |
|
|
|
//设置目标销量、目标预算
|
|
|
|
for (TbsBudget budget : result.getBudgetList()) { |
|
|
|
boolean eqType = activityCenter.getCenterType().equals(budget.getCenterType()); |
|
|
|
boolean eqCost = activityCenter.getCenterId().equals(budget.getCenterId()); |
|
|
|
if (eqType && eqCost) { |
|
|
|
BigDecimal totalBudgetAmount = BigDecimal.ZERO; |
|
|
|
BigDecimal totalPreDispatchAmount = BigDecimal.ZERO; |
|
|
|
for (TbsScheduleItemBudget itemBudget : tbsScheduleItemBudgets) { |
|
|
|
if (itemBudget.getBudgetId().equals(budget.getId())) { |
|
|
|
if (itemBudget.getBudgetAmount() != null) { |
|
|
|
totalBudgetAmount = totalBudgetAmount.add(itemBudget.getBudgetAmount()); |
|
|
|
} |
|
|
|
if (itemBudget.getPreDispatchAmount() != null) { |
|
|
|
totalPreDispatchAmount = totalBudgetAmount.add(itemBudget.getPreDispatchAmount()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
costCenter.setAreaBudget(totalBudgetAmount); |
|
|
|
costCenter.setTargetSales(totalPreDispatchAmount); |
|
|
|
if (totalPreDispatchAmount.compareTo(BigDecimal.ZERO) != 0) { |
|
|
|
costCenter.setTargetExpenseRate(totalBudgetAmount.divide(totalPreDispatchAmount, BigDecimal.ROUND_DOWN)); |
|
|
|
} |
|
|
|
//暂保持目标相关数据一致
|
|
|
|
costCenter.setYtdTargetSales(costCenter.getTargetSales().setScale(2,BigDecimal.ROUND_DOWN)); |
|
|
|
costCenter.setYtdTargetBudget(costCenter.getAreaBudget().setScale(2,BigDecimal.ROUND_DOWN)); |
|
|
|
costCenter.setYtdTargetExpenseRate(costCenter.getTargetExpenseRate().setScale(2,BigDecimal.ROUND_DOWN)); |
|
|
|
costCenter.setQtdTargetSales(costCenter.getTargetSales().setScale(2,BigDecimal.ROUND_DOWN)); |
|
|
|
costCenter.setQtdTargetBudget(costCenter.getAreaBudget().setScale(2,BigDecimal.ROUND_DOWN)); |
|
|
|
costCenter.setQtdTargetExpenseRate(costCenter.getTargetExpenseRate().setScale(2,BigDecimal.ROUND_DOWN)); |
|
|
|
// costCenter.setMtdTargetSales();
|
|
|
|
// costCenter.setMtdTargetBudget();
|
|
|
|
// costCenter.setMtdTargetExpenseRate();
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
//发货金额
|
|
|
|
List<ErpDispatchSumVo> erpDispatchSumVoList = supplierCodeMapWithCenterType.get(centerKey); |
|
|
|
|
|
|
|
//所有相关费率记录
|
|
|
|
List<BirActivityCenterGoods> centerGoods = birGroupByCenter.get(centerKey); |
|
|
|
if(CollectionUtil.isNotEmpty(centerGoods)){ |
|
|
|
//年费率
|
|
|
|
TbsCenterGoodBirDTO bir4Year = this.getTbsCenterGoodBirDTO(centerGoods,erpDispatchSumVoList); |
|
|
|
costCenter.setYtdRealSales(bir4Year.getRealSales()); |
|
|
|
costCenter.setYtdRealCost(bir4Year.getRealCost()); |
|
|
|
costCenter.setYtdRealExpenseRate(bir4Year.getRealExpenseRate()); |
|
|
|
|
|
|
|
//季度
|
|
|
|
List<Integer> yearMonthList =QuarterUtil.getQuarterNumbers(year, month); |
|
|
|
List<BirActivityCenterGoods> centerGoodsQuarter = centerGoods.stream() |
|
|
|
.filter(a-> yearMonthList.contains(a.getKeyNum())) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
TbsCenterGoodBirDTO bir4Quarter = this.getTbsCenterGoodBirDTO(centerGoodsQuarter,erpDispatchSumVoList); |
|
|
|
costCenter.setQtdRealSales(bir4Quarter.getRealSales()); |
|
|
|
costCenter.setQtdRealCost(bir4Quarter.getRealCost()); |
|
|
|
costCenter.setQtdRealExpenseRate(bir4Quarter.getRealExpenseRate()); |
|
|
|
|
|
|
|
//月份
|
|
|
|
String mStr = month >9? month +"":"0"+ month; |
|
|
|
Integer currYearMonth = Integer.parseInt(year +mStr); |
|
|
|
List<BirActivityCenterGoods> centerGoodsM = centerGoods.stream() |
|
|
|
.filter(a-> currYearMonth.equals(a.getKeyNum())) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
TbsCenterGoodBirDTO bir4Month = this.getTbsCenterGoodBirDTO(centerGoodsM,erpDispatchSumVoList); |
|
|
|
costCenter.setMtdRealSales(bir4Month.getRealSales()); |
|
|
|
costCenter.setMtdRealCost(bir4Month.getRealCost()); |
|
|
|
costCenter.setMtdRealExpenseRate(bir4Month.getRealExpenseRate()); |
|
|
|
} |
|
|
|
return costCenter; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 创建 成本中心 DTO |
|
|
|
* @param centerGoods |
|
|
|
* @param erpDispatchSumVoList |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@NotNull |
|
|
|
private TbsCenterGoodBirDTO getTbsCenterGoodBirDTO(List<BirActivityCenterGoods> centerGoods,List<ErpDispatchSumVo> erpDispatchSumVoList) { |
|
|
|
BigDecimal totalRealDispatch = BigDecimal.ZERO; |
|
|
|
BigDecimal totalRealCost; |
|
|
|
BigDecimal totalRealCheck = BigDecimal.ZERO; |
|
|
|
BigDecimal totalRealRelease = BigDecimal.ZERO; |
|
|
|
for (BirActivityCenterGoods centerGood : centerGoods) { |
|
|
|
totalRealCheck = totalRealCheck.add(centerGood.getSplitUsedAmount()); |
|
|
|
totalRealRelease = totalRealRelease.add(centerGood.getSplitReleaseAmount()); |
|
|
|
for (ErpDispatchSumVo dispatchSumVo : erpDispatchSumVoList) { |
|
|
|
if(centerGood.getKeyNum().equals(dispatchSumVo.getYearMonth())){ |
|
|
|
totalRealDispatch = totalRealDispatch.add(dispatchSumVo.getDispatchSumCost()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
totalRealCost = totalRealCheck.add(totalRealRelease); |
|
|
|
TbsCenterGoodBirDTO birDTO = new TbsCenterGoodBirDTO(); |
|
|
|
birDTO.setRealCost(totalRealCost); |
|
|
|
birDTO.setRealCheck(totalRealCheck); |
|
|
|
birDTO.setRealRelease(totalRealRelease); |
|
|
|
birDTO.initRealExpenseRate(); |
|
|
|
return birDTO; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 保存预算使用日志 |
|
|
|
* @param result |
|
|
|