Переглянути джерело

Merge branch 'master' of huangrui/CostAccount into dev

lijiaxi 4 роки тому
батько
коміт
c35fd70875

+ 21 - 18
src/main/java/com/imed/costaccount/service/impl/CostDepartmentProfitServiceImpl.java

@@ -180,25 +180,26 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
             });
         });
         Map<Long, List<CostDepartmentProfitVO>> listMap = list.stream().collect(Collectors.groupingBy(CostDepartmentProfitVO::getReportId));
+        List<CostDepartmentProfitVO> allList = BeanUtil.convertList(list, CostDepartmentProfitVO.class);
         // 记录每一次计算的钱
         list.forEach(i -> {
             Long reportId = i.getReportId();
             Integer calcType = i.getCalcType();
             if (NumberConstant.ONE.equals(calcType)){
                 // TODO 按照会计科目进行计算
-                i.setAmount(setAccountReportData(i, incomeList, allocationQueryReportVOList, reportRelationMap));
+                i.setAmount(setAccountReportData(i, incomeList, allocationQueryReportVOList, reportRelationMap,allList));
             }else if (NumberConstant.TWO.equals(calcType)){
                 // TODO 按照分摊层级进行计算
-                i.setAmount(setShareLevelReportData(i, costShareLevelList, reportRelationMap, allocationList));
+                i.setAmount(setShareLevelReportData(i, costShareLevelList, reportRelationMap, allocationList,allList));
             }else if (NumberConstant.THREE.equals(calcType)){
                 // TODO 按照小计进行计算
-                i.setAmount(setSubtotal(i, costShareLevelList, listMap, list, incomeList, allocationQueryReportVOList, reportRelationMap, allocationList));
+                i.setAmount(setSubtotal(i, costShareLevelList, listMap, list, incomeList, allocationQueryReportVOList, reportRelationMap, allocationList,allList));
             }else if (NumberConstant.FOUR.equals(calcType)){
                 // TODO 按照计算公式进行计算
-                i.setAmount(setCalculation(i, list, costShareLevelList, listMap, incomeList, allocationQueryReportVOList, reportRelationMap, allocationList));
+                i.setAmount(setCalculation(i, list, costShareLevelList, listMap, incomeList, allocationQueryReportVOList, reportRelationMap, allocationList,allList));
             }else if (NumberConstant.FIVE.equals(calcType)){
                 // TODO  按照责任中心进行计算
-                i.setAmount(setResponsibilityCode(i, reportRelationMap, allocationList));
+                i.setAmount(setResponsibilityCode(i, reportRelationMap, allocationList,allList));
             }else {
                 i.setAmount(new BigDecimal("0.0000"));
             }
@@ -382,7 +383,7 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
      *
      * @param i
      */
-    private BigDecimal setAccountReportData(CostDepartmentProfitVO i, List<IncomeCollection> list, List<AllocationQueryReportVO> allocationQueryReportVOList, Map<Long, List<ReportRelation>> reportRelationMap) {
+    private BigDecimal setAccountReportData(CostDepartmentProfitVO i, List<IncomeCollection> list, List<AllocationQueryReportVO> allocationQueryReportVOList, Map<Long, List<ReportRelation>> reportRelationMap,List<CostDepartmentProfitVO> allList) {
         // 在报表关联里面查询当前报表关联的
         Long reportId = i.getReportId();
         List<ReportRelation> reportRelationList = reportRelationMap.get(reportId);
@@ -417,7 +418,7 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
      * 按照分摊层级进行计算
      * 按照分摊层级计算  报表分摊层级是当前的层级  并且目标责任中心失败当前责任中心
      */
-    private BigDecimal setShareLevelReportData(CostDepartmentProfitVO i, List<CostShareLevel> costShareLevelList, Map<Long, List<ReportRelation>> reportRelationMap, List<Allocation> allocationList) {
+    private BigDecimal setShareLevelReportData(CostDepartmentProfitVO i, List<CostShareLevel> costShareLevelList, Map<Long, List<ReportRelation>> reportRelationMap, List<Allocation> allocationList,List<CostDepartmentProfitVO> allList) {
         List<ReportRelation> reportRelationList = reportRelationMap.get(i.getReportId());
         AtomicReference<BigDecimal> sum = new AtomicReference<>(new BigDecimal("0.000"));
         if (CollUtil.isNotEmpty(reportRelationList)) {
@@ -443,7 +444,7 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
      * 原始责任中心是设置的责任中心   目标责任中心是报表的责任中心
      * 查询分摊报表里面目标责任中心是当前责任中心  报表责任中心是当前设置的责任中心
      */
-    public BigDecimal setResponsibilityCode(CostDepartmentProfitVO costDepartmentProfitVO, Map<Long, List<ReportRelation>> reportRelationMap, List<Allocation> allocationList) {
+    public BigDecimal setResponsibilityCode(CostDepartmentProfitVO costDepartmentProfitVO, Map<Long, List<ReportRelation>> reportRelationMap, List<Allocation> allocationList,List<CostDepartmentProfitVO> allList) {
         // 获取当前报表对应的责任中心
         List<ReportRelation> reportRelationList = reportRelationMap.get(costDepartmentProfitVO.getReportId());
         AtomicReference<BigDecimal> sum = new AtomicReference<>(new BigDecimal("0.000"));
@@ -474,7 +475,7 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
                                   List<CostDepartmentProfitVO> profitVOS,
                                   List<IncomeCollection> list,
                                   List<AllocationQueryReportVO> allocationQueryReportVOList,
-                                  Map<Long, List<ReportRelation>> reportRelationMap, List<Allocation> allocationList) {
+                                  Map<Long, List<ReportRelation>> reportRelationMap, List<Allocation> allocationList,List<CostDepartmentProfitVO> allList) {
         // 因为报表是按照报表项目的升序进行排序的  前面的报表是已经进行计算了的
         // 查询当前报表的父层级id
         Long reportParentId = costDepartmentProfitVO.getReportParentId();
@@ -489,7 +490,7 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
             if (CollUtil.isEmpty(costDepartmentProfitVOS1)) {
                 throw new CostException(500, "报表未找到");
             }
-            BigDecimal amount = getAmount(costDepartmentProfitVOS1, costShareLevelList, responsibilityCode, list, allocationQueryReportVOList, reportRelationMap, allocationList, listMap);
+            BigDecimal amount = getAmount(costDepartmentProfitVOS1, costShareLevelList, responsibilityCode, list, allocationQueryReportVOList, reportRelationMap, allocationList, listMap,allList);
             sum.updateAndGet(v -> v.add(amount));
         });
 //        costDepartmentProfitVO.setAmount(new BigDecimal(sum.toString()));
@@ -499,7 +500,7 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
     /***
      * 按照计算方式进行计算
      */
-    public BigDecimal setCalculation(CostDepartmentProfitVO costDepartmentProfitVO, List<CostDepartmentProfitVO> costDepartmentProfitVOList, List<CostShareLevel> costShareLevelList, Map<Long, List<CostDepartmentProfitVO>> listMap, List<IncomeCollection> list, List<AllocationQueryReportVO> allocationQueryReportVOList, Map<Long, List<ReportRelation>> reportRelationMap, List<Allocation> allocationList) {
+    public BigDecimal setCalculation(CostDepartmentProfitVO costDepartmentProfitVO, List<CostDepartmentProfitVO> costDepartmentProfitVOList, List<CostShareLevel> costShareLevelList, Map<Long, List<CostDepartmentProfitVO>> listMap, List<IncomeCollection> list, List<AllocationQueryReportVO> allocationQueryReportVOList, Map<Long, List<ReportRelation>> reportRelationMap, List<Allocation> allocationList,List<CostDepartmentProfitVO> allList) {
         // 获取当前报表的计算方式  [1]+[2]类型/ [1]-[2]
         String calcFormula = costDepartmentProfitVO.getCalcFormula();
         String responsibilityCode = costDepartmentProfitVO.getResponsibilityCode();
@@ -509,14 +510,14 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
         AtomicReference<BigDecimal> bigDecimal = new AtomicReference<>(new BigDecimal("0.0000"));
         calcFormulaList.forEach(calc -> {
             Integer calcNum=Math.abs(calc);
-            List<Long> reportIdList = costDepartmentProfitVOList.stream().filter(i -> i.getResponsibilityCode().equals(responsibilityCode) && calcNum.equals(i.getReportNum())).map(CostDepartmentProfitVO::getReportId).collect(Collectors.toList());
+            List<Long> reportIdList = allList.stream().filter(i -> i.getResponsibilityCode().equals(responsibilityCode) && calcNum.equals(i.getReportNum())).map(CostDepartmentProfitVO::getReportId).collect(Collectors.toList());
             if (CollUtil.isNotEmpty(reportIdList)) {
                 reportIdList.forEach(i -> {
                     List<CostDepartmentProfitVO> profitVOS = listMap.get(i);
                     if (CollUtil.isEmpty(profitVOS)) {
                         throw new CostException(500, "报表未找到");
                     }
-                    BigDecimal amount = getAmount(profitVOS, costShareLevelList, responsibilityCode, list, allocationQueryReportVOList, reportRelationMap, allocationList, listMap);
+                    BigDecimal amount = getAmount(profitVOS, costShareLevelList, responsibilityCode, list, allocationQueryReportVOList, reportRelationMap, allocationList, listMap,allList);
                     if (calc>0){
                         bigDecimal.updateAndGet(v -> v.add(amount));
                     }else {
@@ -537,7 +538,7 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
                                 String responsibilityCode, List<IncomeCollection> list,
                                 List<AllocationQueryReportVO> allocationQueryReportVOList,
                                 Map<Long, List<ReportRelation>> reportRelationMap, List<Allocation> allocationList,
-                                Map<Long, List<CostDepartmentProfitVO>> listMap) {
+                                Map<Long, List<CostDepartmentProfitVO>> listMap,List<CostDepartmentProfitVO> allList) {
         BigDecimal bigDecimal = new BigDecimal("0.0000");
         // 在对这个报表进行过滤
         List<CostDepartmentProfitVO> costDepartmentProfitVOS = profitVOS.stream().filter(i -> i.getResponsibilityCode().equals(responsibilityCode)).collect(Collectors.toList());
@@ -546,16 +547,18 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
         Integer calcType = costDepartmentProfitVO.getCalcType();
         if (NumberConstant.ONE.equals(calcType)) {
             // 调用计算的方法 按照会计科目
-            bigDecimal = setAccountReportData(costDepartmentProfitVO, list, allocationQueryReportVOList, reportRelationMap);
+            bigDecimal = setAccountReportData(costDepartmentProfitVO, list, allocationQueryReportVOList, reportRelationMap,allList);
         } else if (NumberConstant.TWO.equals(calcType)) {
             // 按照分摊层级
-            bigDecimal = setShareLevelReportData(costDepartmentProfitVO, costShareLevelList, reportRelationMap, allocationList);
+            bigDecimal = setShareLevelReportData(costDepartmentProfitVO, costShareLevelList, reportRelationMap, allocationList,allList);
         } else if (NumberConstant.THREE.equals(calcType)) {
             // 小计
-            bigDecimal = setSubtotal(costDepartmentProfitVO, costShareLevelList, listMap, profitVOS, list, allocationQueryReportVOList, reportRelationMap, allocationList);
+            bigDecimal = setSubtotal(costDepartmentProfitVO, costShareLevelList, listMap, profitVOS, list, allocationQueryReportVOList, reportRelationMap, allocationList,allList);
         } else if (NumberConstant.FIVE.equals(calcType)) {
             // 按照责任中心
-            bigDecimal = setResponsibilityCode(costDepartmentProfitVO, reportRelationMap, allocationList);
+            bigDecimal = setResponsibilityCode(costDepartmentProfitVO, reportRelationMap, allocationList,allList);
+        }else if (NumberConstant.FOUR.equals(calcType)){
+            bigDecimal=setCalculation(costDepartmentProfitVO,costDepartmentProfitVOS,costShareLevelList,listMap,list,allocationQueryReportVOList,reportRelationMap,allocationList,allList);
         }
         return bigDecimal;
     }