From 196dffff222c9247eae4860059645be4f8ade80d Mon Sep 17 00:00:00 2001 From: "15989082884@163.com" <15989082884@163.com> Date: Thu, 27 Jul 2023 09:04:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DSUBLIST=E6=88=90=E6=9C=AC?= =?UTF-8?q?=E4=B8=AD=E5=BF=83=E8=B4=B9=E7=94=A8=E7=8E=87=E5=90=88=E5=B9=B6?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/TbsCostApplyServiceImpl.java | 179 +----------------- 1 file changed, 7 insertions(+), 172 deletions(-) diff --git a/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsCostApplyServiceImpl.java b/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsCostApplyServiceImpl.java index 6285c05d..ff2dafe6 100644 --- a/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsCostApplyServiceImpl.java +++ b/src/main/java/com/qs/serve/modules/tbs/service/impl/TbsCostApplyServiceImpl.java @@ -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> centerMapList = tbsActivityCenters.stream().collect(Collectors.groupingBy(a->a.getCenterType()+"-"+a.getCenterId())); + List centerList = centerMapList.values().stream().map(a->a.get(0)).collect(Collectors.toList()); - //目标费率和成本中心统计 - List tbsBudgetCostItems = result.getBudgetMatchList(); - List scheduleItemBudgetIds = tbsBudgetCostItems.stream().map(a->a.getScheduleItemBudgetId()).distinct().collect(Collectors.toList()); - List 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> supplierCodeMapWithCenterType = new HashMap<>(); - Map> centerMapList = tbsActivityCenters.stream().collect(Collectors.groupingBy(TbsActivityCenter::getCenterType)); - for (String centerType : centerMapList.keySet()) { - List centerIds =centerMapList.get(centerType).stream().map(TbsActivityCenter::getCenterId).collect(Collectors.toList()); - List supplierCodeList = roiRateService.getSupplierCodesByCenter(costDTO,centerType,centerIds); - //发货单 - List 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 centerGoodDTOS = new ArrayList<>(); - List birActivityCenterGoodsList = new ArrayList<>(); - //按成本中心维度分组 - Map> 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 tbsScheduleItemBudgets, int year, int month, Map> supplierCodeMapWithCenterType, Map> 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 erpDispatchSumVoList = supplierCodeMapWithCenterType.get(centerKey); - - //所有相关费率记录 - List 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 yearMonthList =QuarterUtil.getQuarterNumbers(year, month); - List 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 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 centerGoods,List 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