|
|
@ -15,6 +15,7 @@ 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.BirActivityCenterGoodsService; |
|
|
|
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; |
|
|
@ -92,6 +93,7 @@ public class TbsCostApplyServiceImpl extends ServiceImpl<TbsCostApplyMapper,TbsC |
|
|
|
private final ErpDispatchDataMapper dispatchDataMapper; |
|
|
|
private BirActivityCenterGoodsService birActivityCenterGoodsService; |
|
|
|
private TbsBudgetMapper tbsBudgetMapper; |
|
|
|
private BirCenterRateService centerRateService; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@ -422,238 +424,240 @@ public class TbsCostApplyServiceImpl extends ServiceImpl<TbsCostApplyMapper,TbsC |
|
|
|
} |
|
|
|
|
|
|
|
//查询发货金额,并按月份分割
|
|
|
|
int year = LocalDate.now().getYear(); |
|
|
|
int month = LocalDate.now().getMonthValue(); |
|
|
|
month = month>1?month:1; |
|
|
|
int startMonthNum = year*100 + 1; |
|
|
|
int endMonthNum = year*100 + month; |
|
|
|
BirRoiRateService roiRateService = SpringUtils.getBean(BirRoiRateService.class); |
|
|
|
BirRoiCostDTO costDTO = new BirRoiCostDTO(); |
|
|
|
costDTO.setStartMonthNum(startMonthNum); |
|
|
|
costDTO.setEndMonthNum(endMonthNum); |
|
|
|
// int year = LocalDate.now().getYear();
|
|
|
|
// int month = LocalDate.now().getMonthValue();
|
|
|
|
// month = month>1?month:1;
|
|
|
|
// int startMonthNum = year*100 + 1;
|
|
|
|
// int endMonthNum = year*100 + month;
|
|
|
|
// BirRoiRateService roiRateService = SpringUtils.getBean(BirRoiRateService.class);
|
|
|
|
// BirRoiCostDTO costDTO = new BirRoiCostDTO();
|
|
|
|
// costDTO.setStartMonthNum(startMonthNum);
|
|
|
|
// costDTO.setEndMonthNum(endMonthNum);
|
|
|
|
|
|
|
|
//获取BIR表的数据,用于计算实际费用率
|
|
|
|
LambdaQueryWrapper<BirActivityCenterGoods> birLwq = new LambdaQueryWrapper<>(); |
|
|
|
birLwq.in(BirActivityCenterGoods::getCenterId,tbsActivityCenters.stream().map(a->a.getCenterId()).collect(Collectors.toList())); |
|
|
|
birLwq.ge(BirActivityCenterGoods::getKeyNum,startMonthNum); |
|
|
|
birLwq.le(BirActivityCenterGoods::getKeyNum,endMonthNum); |
|
|
|
List<BirActivityCenterGoods> birActivityCenterGoodsList = birActivityCenterGoodsService.list(birLwq); |
|
|
|
Map<String,List<BirActivityCenterGoods>> birCenterCostMap = birActivityCenterGoodsList.stream().collect(Collectors.groupingBy(a->a.getCenterType() + "-"+a.getCenterId())); |
|
|
|
// LambdaQueryWrapper<BirActivityCenterGoods> birLwq = new LambdaQueryWrapper<>();
|
|
|
|
// birLwq.in(BirActivityCenterGoods::getCenterId,tbsActivityCenters.stream().map(a->a.getCenterId()).collect(Collectors.toList()));
|
|
|
|
// birLwq.ge(BirActivityCenterGoods::getKeyNum,startMonthNum);
|
|
|
|
// birLwq.le(BirActivityCenterGoods::getKeyNum,endMonthNum);
|
|
|
|
// List<BirActivityCenterGoods> birActivityCenterGoodsList = birActivityCenterGoodsService.list(birLwq);
|
|
|
|
// Map<String,List<BirActivityCenterGoods>> birCenterCostMap = birActivityCenterGoodsList.stream().collect(Collectors.groupingBy(a->a.getCenterType() + "-"+a.getCenterId()));
|
|
|
|
//成本中心去重
|
|
|
|
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()); |
|
|
|
|
|
|
|
for(TbsActivityCenter center : centerList){ |
|
|
|
String centerType = center.getCenterType(); |
|
|
|
String centerId = center.getCenterId(); |
|
|
|
String centerKey = centerType + "-" + centerId; |
|
|
|
TbsCostSubItem.CostCenterTranStr costCenter = new TbsCostSubItem.CostCenterTranStr(center.getCenterName(),centerType+"-"+centerId); |
|
|
|
/* --------------- 全年目标费用率YTD 目标预计发货,目标预算 --------------------------- */ |
|
|
|
//通过成本中心TYPE和ID取预算
|
|
|
|
LambdaQueryWrapper<TbsBudget> budgetLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
budgetLambdaQueryWrapper.eq(TbsBudget::getCenterId,centerId); |
|
|
|
budgetLambdaQueryWrapper.eq(TbsBudget::getCenterType,centerType); |
|
|
|
List<TbsBudget> tbsBudgetList = tbsBudgetMapper.selectList(budgetLambdaQueryWrapper); |
|
|
|
//通过预算ID取预算的发货和金额
|
|
|
|
LambdaQueryWrapper<TbsScheduleItemBudget> scheduleItemBudgetLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
scheduleItemBudgetLambdaQueryWrapper.in(TbsScheduleItemBudget::getBudgetId,tbsBudgetList.stream().map(a->a.getId()).collect(Collectors.toList())); |
|
|
|
List<TbsScheduleItemBudget> scheduleItemBudgetList = tbsScheduleItemBudgetMapper.selectList(scheduleItemBudgetLambdaQueryWrapper); |
|
|
|
//合计目标发货和金定额
|
|
|
|
BigDecimal targetBudgetAmout = scheduleItemBudgetList.stream().map(a->a.getBudgetAmount()).reduce(BigDecimal.ZERO,BigDecimal::add); |
|
|
|
BigDecimal targetDispatchAmout = scheduleItemBudgetList.stream().map(a->a.getPreDispatchAmount()==null?BigDecimal.ZERO:a.getPreDispatchAmount()).reduce(BigDecimal.ZERO,BigDecimal::add); |
|
|
|
costCenter.setTargetSales(targetDispatchAmout.toString()); |
|
|
|
costCenter.setAreaBudget(targetBudgetAmout.toString()); |
|
|
|
BigDecimal targetExpenseRate = BigDecimal.ZERO; |
|
|
|
if(targetDispatchAmout.compareTo(BigDecimal.ZERO)!=0) { |
|
|
|
targetExpenseRate = targetBudgetAmout.divide(targetDispatchAmout, 2, BigDecimal.ROUND_HALF_DOWN); |
|
|
|
costCenter.setTargetExpenseRate(targetExpenseRate.toString()); |
|
|
|
costCenter.setYtdTargetExpenseRate(targetExpenseRate.toString()); |
|
|
|
} |
|
|
|
// costCenter.setTargetExpenseRate(targetExpenseRate);
|
|
|
|
costCenter.setYtdTargetBudget(targetBudgetAmout.toString()); |
|
|
|
costCenter.setYtdTargetSales(targetDispatchAmout.toString()); |
|
|
|
// costCenter.setYtdTargetExpenseRate(targetExpenseRate);
|
|
|
|
|
|
|
|
// costCenter.setQtdTargetBudget(BigDecimal.ZERO);
|
|
|
|
// costCenter.setQtdTargetSales(BigDecimal.ZERO);
|
|
|
|
// costCenter.setQtdTargetExpenseRate(BigDecimal.ZERO);
|
|
|
|
// costCenter.setMtdTargetBudget(BigDecimal.ZERO);
|
|
|
|
// costCenter.setMtdTargetSales(BigDecimal.ZERO);
|
|
|
|
// costCenter.setMtdTargetExpenseRate(BigDecimal.ZERO);
|
|
|
|
/* ------------------------------------------------------------------------- */ |
|
|
|
//实际发贷数
|
|
|
|
List<String> supplierCodeList = roiRateService.getSupplierCodesByCenter(costDTO,centerType,Arrays.asList(centerId)); |
|
|
|
List<ErpDispatchSumVo> dispatchSumVos = dispatchDataMapper.querySumCost(startMonthNum,endMonthNum,supplierCodeList); |
|
|
|
List<BirActivityCenterGoods> birCenterCost = birCenterCostMap.containsKey(centerKey)?birCenterCostMap.get(centerKey):new ArrayList<>(); |
|
|
|
|
|
|
|
/* --------------- 实际费用率YTD --------------------------------------------- */ |
|
|
|
BigDecimal ytdRealDipatch = dispatchSumVos.stream().map(a->a.getDispatchSumCost()).reduce(BigDecimal.ZERO,BigDecimal::add); |
|
|
|
BigDecimal ytdRealCost = birCenterCost.stream().map(a->a.getSplitUsedAmount()).reduce(BigDecimal.ZERO,BigDecimal::add); |
|
|
|
costCenter.setYtdRealCost(ytdRealCost.toString()); |
|
|
|
costCenter.setYtdRealSales(ytdRealDipatch.toString()); |
|
|
|
BigDecimal ytdRealExpenseRate = BigDecimal.ZERO; |
|
|
|
if(ytdRealDipatch.compareTo(BigDecimal.ZERO)!=0) { |
|
|
|
ytdRealExpenseRate = ytdRealCost.divide(ytdRealDipatch, 2, BigDecimal.ROUND_HALF_DOWN); |
|
|
|
costCenter.setYtdRealExpenseRate(ytdRealExpenseRate.toString()); |
|
|
|
} |
|
|
|
// costCenter.setYtdRealExpenseRate(ytdRealExpenseRate);
|
|
|
|
/* ------------------------------------------------------------------------- */ |
|
|
|
|
|
|
|
/* --------------- 实际费用率QTD --------------------------------------------- */ |
|
|
|
List<Integer> yearQuarter = QuarterUtil.getQuarterNumbers(year, month); |
|
|
|
BigDecimal qtdRealDipatch = dispatchSumVos.stream().filter(a->yearQuarter.contains(a.getYearMonth())).map(a->a.getDispatchSumCost()).reduce(BigDecimal.ZERO,BigDecimal::add); |
|
|
|
BigDecimal qtdRealCost = birCenterCost.stream().filter(a->yearQuarter.contains(a.getKeyNum())).map(a->a.getSplitUsedAmount()).reduce(BigDecimal.ZERO,BigDecimal::add); |
|
|
|
costCenter.setQtdRealCost(qtdRealCost.toString()); |
|
|
|
costCenter.setQtdRealSales(qtdRealDipatch.toString()); |
|
|
|
BigDecimal qtdRealExpenseRate = BigDecimal.ZERO; |
|
|
|
if(qtdRealDipatch.compareTo(BigDecimal.ZERO)!=0) { |
|
|
|
qtdRealExpenseRate = qtdRealCost.divide(qtdRealDipatch, 2, BigDecimal.ROUND_HALF_DOWN); |
|
|
|
costCenter.setQtdRealExpenseRate(qtdRealExpenseRate.toString()); |
|
|
|
} |
|
|
|
// costCenter.setQtdRealExpenseRate(qtdRealExpenseRate);
|
|
|
|
/* ------------------------------------------------------------------------- */ |
|
|
|
|
|
|
|
/* --------------- 实际费用率MTD --------------------------------------------- */ |
|
|
|
Integer yearMonth = year*100 + month; |
|
|
|
BigDecimal mtdRealDipatch = dispatchSumVos.stream().filter(a->yearMonth.equals(a.getYearMonth())).map(a->a.getDispatchSumCost()).reduce(BigDecimal.ZERO,BigDecimal::add); |
|
|
|
BigDecimal mtdRealCost = birCenterCost.stream().filter(a->yearMonth.equals(a.getKeyNum())).map(a->a.getSplitUsedAmount()).reduce(BigDecimal.ZERO,BigDecimal::add); |
|
|
|
costCenter.setMtdRealCost(mtdRealCost.toString()); |
|
|
|
costCenter.setMtdRealSales(mtdRealDipatch.toString()); |
|
|
|
BigDecimal mtdRealExpenseRate = BigDecimal.ZERO; |
|
|
|
if(mtdRealDipatch.compareTo(BigDecimal.ZERO)!=0) { |
|
|
|
mtdRealExpenseRate = mtdRealCost.divide(mtdRealDipatch, 2, BigDecimal.ROUND_HALF_DOWN); |
|
|
|
costCenter.setMtdRealExpenseRate(mtdRealExpenseRate.toString()); |
|
|
|
} |
|
|
|
// costCenter.setMtdRealExpenseRate(mtdRealExpenseRate);
|
|
|
|
/* ------------------------------------------------------------------------- */ |
|
|
|
|
|
|
|
|
|
|
|
TbsCostSubItem.CostCenterTranStr costCenter = centerRateService.buildCostCenter(center.getCenterType(),center.getCenterId(),center.getCenterName()); |
|
|
|
subList.add(costCenter); |
|
|
|
// String centerType = center.getCenterType();
|
|
|
|
// String centerId = center.getCenterId();
|
|
|
|
// String centerKey = centerType + "-" + centerId;
|
|
|
|
// TbsCostSubItem.CostCenterTranStr costCenter = new TbsCostSubItem.CostCenterTranStr(center.getCenterName(),centerType+"-"+centerId);
|
|
|
|
// /* --------------- 全年目标费用率YTD 目标预计发货,目标预算 --------------------------- */
|
|
|
|
// //通过成本中心TYPE和ID取预算
|
|
|
|
// LambdaQueryWrapper<TbsBudget> budgetLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
// budgetLambdaQueryWrapper.eq(TbsBudget::getCenterId,centerId);
|
|
|
|
// budgetLambdaQueryWrapper.eq(TbsBudget::getCenterType,centerType);
|
|
|
|
// List<TbsBudget> tbsBudgetList = tbsBudgetMapper.selectList(budgetLambdaQueryWrapper);
|
|
|
|
// //通过预算ID取预算的发货和金额
|
|
|
|
// LambdaQueryWrapper<TbsScheduleItemBudget> scheduleItemBudgetLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
// scheduleItemBudgetLambdaQueryWrapper.in(TbsScheduleItemBudget::getBudgetId,tbsBudgetList.stream().map(a->a.getId()).collect(Collectors.toList()));
|
|
|
|
// List<TbsScheduleItemBudget> scheduleItemBudgetList = tbsScheduleItemBudgetMapper.selectList(scheduleItemBudgetLambdaQueryWrapper);
|
|
|
|
// //合计目标发货和金定额
|
|
|
|
// BigDecimal targetBudgetAmout = scheduleItemBudgetList.stream().map(a->a.getBudgetAmount()).reduce(BigDecimal.ZERO,BigDecimal::add);
|
|
|
|
// BigDecimal targetDispatchAmout = scheduleItemBudgetList.stream().map(a->a.getPreDispatchAmount()==null?BigDecimal.ZERO:a.getPreDispatchAmount()).reduce(BigDecimal.ZERO,BigDecimal::add);
|
|
|
|
// costCenter.setTargetSales(targetDispatchAmout.toString());
|
|
|
|
// costCenter.setAreaBudget(targetBudgetAmout.toString());
|
|
|
|
// BigDecimal targetExpenseRate = BigDecimal.ZERO;
|
|
|
|
// if(targetDispatchAmout.compareTo(BigDecimal.ZERO)!=0) {
|
|
|
|
// targetExpenseRate = targetBudgetAmout.divide(targetDispatchAmout, 2, BigDecimal.ROUND_HALF_DOWN);
|
|
|
|
// costCenter.setTargetExpenseRate(targetExpenseRate.toString());
|
|
|
|
// costCenter.setYtdTargetExpenseRate(targetExpenseRate.toString());
|
|
|
|
// }
|
|
|
|
//// costCenter.setTargetExpenseRate(targetExpenseRate);
|
|
|
|
// costCenter.setYtdTargetBudget(targetBudgetAmout.toString());
|
|
|
|
// costCenter.setYtdTargetSales(targetDispatchAmout.toString());
|
|
|
|
//// costCenter.setYtdTargetExpenseRate(targetExpenseRate);
|
|
|
|
//
|
|
|
|
//// costCenter.setQtdTargetBudget(BigDecimal.ZERO);
|
|
|
|
//// costCenter.setQtdTargetSales(BigDecimal.ZERO);
|
|
|
|
//// costCenter.setQtdTargetExpenseRate(BigDecimal.ZERO);
|
|
|
|
//// costCenter.setMtdTargetBudget(BigDecimal.ZERO);
|
|
|
|
//// costCenter.setMtdTargetSales(BigDecimal.ZERO);
|
|
|
|
//// costCenter.setMtdTargetExpenseRate(BigDecimal.ZERO);
|
|
|
|
// /* ------------------------------------------------------------------------- */
|
|
|
|
// //实际发贷数
|
|
|
|
// List<String> supplierCodeList = roiRateService.getSupplierCodesByCenter(costDTO,centerType,Arrays.asList(centerId));
|
|
|
|
// List<ErpDispatchSumVo> dispatchSumVos = dispatchDataMapper.querySumCost(startMonthNum,endMonthNum,supplierCodeList);
|
|
|
|
// List<BirActivityCenterGoods> birCenterCost = birCenterCostMap.containsKey(centerKey)?birCenterCostMap.get(centerKey):new ArrayList<>();
|
|
|
|
//
|
|
|
|
// /* --------------- 实际费用率YTD --------------------------------------------- */
|
|
|
|
// BigDecimal ytdRealDipatch = dispatchSumVos.stream().map(a->a.getDispatchSumCost()).reduce(BigDecimal.ZERO,BigDecimal::add);
|
|
|
|
// BigDecimal ytdRealCost = birCenterCost.stream().map(a->a.getSplitUsedAmount()).reduce(BigDecimal.ZERO,BigDecimal::add);
|
|
|
|
// costCenter.setYtdRealCost(ytdRealCost.toString());
|
|
|
|
// costCenter.setYtdRealSales(ytdRealDipatch.toString());
|
|
|
|
// BigDecimal ytdRealExpenseRate = BigDecimal.ZERO;
|
|
|
|
// if(ytdRealDipatch.compareTo(BigDecimal.ZERO)!=0) {
|
|
|
|
// ytdRealExpenseRate = ytdRealCost.divide(ytdRealDipatch, 2, BigDecimal.ROUND_HALF_DOWN);
|
|
|
|
// costCenter.setYtdRealExpenseRate(ytdRealExpenseRate.toString());
|
|
|
|
// }
|
|
|
|
//// costCenter.setYtdRealExpenseRate(ytdRealExpenseRate);
|
|
|
|
// /* ------------------------------------------------------------------------- */
|
|
|
|
//
|
|
|
|
// /* --------------- 实际费用率QTD --------------------------------------------- */
|
|
|
|
// List<Integer> yearQuarter = QuarterUtil.getQuarterNumbers(year, month);
|
|
|
|
// BigDecimal qtdRealDipatch = dispatchSumVos.stream().filter(a->yearQuarter.contains(a.getYearMonth())).map(a->a.getDispatchSumCost()).reduce(BigDecimal.ZERO,BigDecimal::add);
|
|
|
|
// BigDecimal qtdRealCost = birCenterCost.stream().filter(a->yearQuarter.contains(a.getKeyNum())).map(a->a.getSplitUsedAmount()).reduce(BigDecimal.ZERO,BigDecimal::add);
|
|
|
|
// costCenter.setQtdRealCost(qtdRealCost.toString());
|
|
|
|
// costCenter.setQtdRealSales(qtdRealDipatch.toString());
|
|
|
|
// BigDecimal qtdRealExpenseRate = BigDecimal.ZERO;
|
|
|
|
// if(qtdRealDipatch.compareTo(BigDecimal.ZERO)!=0) {
|
|
|
|
// qtdRealExpenseRate = qtdRealCost.divide(qtdRealDipatch, 2, BigDecimal.ROUND_HALF_DOWN);
|
|
|
|
// costCenter.setQtdRealExpenseRate(qtdRealExpenseRate.toString());
|
|
|
|
// }
|
|
|
|
//// costCenter.setQtdRealExpenseRate(qtdRealExpenseRate);
|
|
|
|
// /* ------------------------------------------------------------------------- */
|
|
|
|
//
|
|
|
|
// /* --------------- 实际费用率MTD --------------------------------------------- */
|
|
|
|
// Integer yearMonth = year*100 + month;
|
|
|
|
// BigDecimal mtdRealDipatch = dispatchSumVos.stream().filter(a->yearMonth.equals(a.getYearMonth())).map(a->a.getDispatchSumCost()).reduce(BigDecimal.ZERO,BigDecimal::add);
|
|
|
|
// BigDecimal mtdRealCost = birCenterCost.stream().filter(a->yearMonth.equals(a.getKeyNum())).map(a->a.getSplitUsedAmount()).reduce(BigDecimal.ZERO,BigDecimal::add);
|
|
|
|
// costCenter.setMtdRealCost(mtdRealCost.toString());
|
|
|
|
// costCenter.setMtdRealSales(mtdRealDipatch.toString());
|
|
|
|
// BigDecimal mtdRealExpenseRate = BigDecimal.ZERO;
|
|
|
|
// if(mtdRealDipatch.compareTo(BigDecimal.ZERO)!=0) {
|
|
|
|
// mtdRealExpenseRate = mtdRealCost.divide(mtdRealDipatch, 2, BigDecimal.ROUND_HALF_DOWN);
|
|
|
|
// costCenter.setMtdRealExpenseRate(mtdRealExpenseRate.toString());
|
|
|
|
// }
|
|
|
|
//// costCenter.setMtdRealExpenseRate(mtdRealExpenseRate);
|
|
|
|
// /* ------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
// 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,2, BigDecimal.ROUND_DOWN)); |
|
|
|
} |
|
|
|
//暂保持目标相关数据一致
|
|
|
|
costCenter.setYtdTargetSales(costCenter.getTargetSales().setScale(2,BigDecimal.ROUND_DOWN)); |
|
|
|
costCenter.setYtdTargetBudget(costCenter.getAreaBudget().setScale(2, RoundingMode.DOWN)); |
|
|
|
costCenter.setYtdTargetExpenseRate(costCenter.getTargetExpenseRate().setScale(2, RoundingMode.DOWN)); |
|
|
|
// costCenter.setQtdTargetSales(costCenter.getTargetSales());
|
|
|
|
// costCenter.setQtdTargetBudget(costCenter.getAreaBudget());
|
|
|
|
// costCenter.setQtdTargetExpenseRate(costCenter.getTargetExpenseRate());
|
|
|
|
// 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
|
|
|
|
// * @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,2, BigDecimal.ROUND_DOWN));
|
|
|
|
// }
|
|
|
|
// //暂保持目标相关数据一致
|
|
|
|
// costCenter.setYtdTargetSales(costCenter.getTargetSales().setScale(2,BigDecimal.ROUND_DOWN));
|
|
|
|
// costCenter.setYtdTargetBudget(costCenter.getAreaBudget().setScale(2, RoundingMode.DOWN));
|
|
|
|
// costCenter.setYtdTargetExpenseRate(costCenter.getTargetExpenseRate().setScale(2, RoundingMode.DOWN));
|
|
|
|
//// costCenter.setQtdTargetSales(costCenter.getTargetSales());
|
|
|
|
//// costCenter.setQtdTargetBudget(costCenter.getAreaBudget());
|
|
|
|
//// costCenter.setQtdTargetExpenseRate(costCenter.getTargetExpenseRate());
|
|
|
|
//// 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;
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|