Ver código fonte

科室损益计算

ljx 4 anos atrás
pai
commit
9a08d3a9e1

+ 10 - 2
src/main/java/com/imed/costaccount/model/CostDepartmentProfit.java

@@ -43,18 +43,26 @@ public class CostDepartmentProfit implements Serializable {
 	 * 报表项目父层级Id
 	 * 报表项目父层级Id
 	 */
 	 */
 	private Long reportParentId;
 	private Long reportParentId;
+	/**
+	 * 报表Id
+	 */
+	private Long reportId;
 	/**
 	/**
 	 * 报表项目编号
 	 * 报表项目编号
 	 */
 	 */
-	private String reportNum;
+	private Integer reportNum;
 	/**
 	/**
 	 * 报表项目名称
 	 * 报表项目名称
 	 */
 	 */
 	private String reportName;
 	private String reportName;
 	/**
 	/**
-	 * 计算
+	 * 计算
 	 */
 	 */
 	private String calcFormula;
 	private String calcFormula;
+	/**
+	 * 计算方式
+	 */
+	private Integer calcType;
 	/**
 	/**
 	 * 责任中心代码
 	 * 责任中心代码
 	 */
 	 */

+ 6 - 0
src/main/java/com/imed/costaccount/model/vo/CostDepartmentProfitVO.java

@@ -27,6 +27,9 @@ public class CostDepartmentProfitVO {
     @ApiModelProperty(name = "reportParentId",value = "报表父级Id")
     @ApiModelProperty(name = "reportParentId",value = "报表父级Id")
     private Long reportParentId;
     private Long reportParentId;
 
 
+    @ApiModelProperty(name = "reportId",value = "报表编号Id")
+    private Long reportId;
+
     @ApiModelProperty(name = "levelSort",value = "分摊层级Id")
     @ApiModelProperty(name = "levelSort",value = "分摊层级Id")
     private Integer levelSort;
     private Integer levelSort;
 
 
@@ -39,6 +42,9 @@ public class CostDepartmentProfitVO {
     @ApiModelProperty(name = "calcFormula",value = "计算公式")
     @ApiModelProperty(name = "calcFormula",value = "计算公式")
     private String calcFormula;
     private String calcFormula;
 
 
+    @ApiModelProperty(name = "calcType",value = "计算方式 ")
+    private Integer calcType;
+
     @ApiModelProperty(name = "responsibilityCode",value = "责任中心的代码")
     @ApiModelProperty(name = "responsibilityCode",value = "责任中心的代码")
     private String responsibilityCode;
     private String responsibilityCode;
 
 

+ 88 - 72
src/main/java/com/imed/costaccount/service/impl/CostDepartmentProfitServiceImpl.java

@@ -78,7 +78,7 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
                 .eq(CostDepartmentProfit::getHospId, hospId)
                 .eq(CostDepartmentProfit::getHospId, hospId)
                 .eq(StrUtil.isNotBlank(responsibilityCode), CostDepartmentProfit::getResponsibilityCode, responsibilityCode)
                 .eq(StrUtil.isNotBlank(responsibilityCode), CostDepartmentProfit::getResponsibilityCode, responsibilityCode)
                 .eq(StrUtil.isNotBlank(date), CostDepartmentProfit::getYear, year)
                 .eq(StrUtil.isNotBlank(date), CostDepartmentProfit::getYear, year)
-                .eq(StrUtil.isNotBlank(date), CostDepartmentProfit::getMonth, month).ne(CostDepartmentProfit::getCalcFormula,NumberConstant.ZERO));
+                .eq(StrUtil.isNotBlank(date), CostDepartmentProfit::getMonth, month).ne(CostDepartmentProfit::getCalcType,NumberConstant.ZERO));
         List<CostDepartmentProfit> records = pages.getRecords();
         List<CostDepartmentProfit> records = pages.getRecords();
         List<CostDepartmentProfitVO> costDepartmentProfitVOList = BeanUtil.convertList(records, CostDepartmentProfitVO.class);
         List<CostDepartmentProfitVO> costDepartmentProfitVOList = BeanUtil.convertList(records, CostDepartmentProfitVO.class);
         PageUtils pageUtils = new PageUtils(pages);
         PageUtils pageUtils = new PageUtils(pages);
@@ -114,7 +114,7 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
         Long id = costShareLevelList.get(0).getId();
         Long id = costShareLevelList.get(0).getId();
         // 查询责任中心里面是这个层级的所有的收益中心
         // 查询责任中心里面是这个层级的所有的收益中心
         List<Responsibility> responsibilityList = responsibilityService.list(new QueryWrapper<Responsibility>().lambda()
         List<Responsibility> responsibilityList = responsibilityService.list(new QueryWrapper<Responsibility>().lambda()
-                .eq(Responsibility::getHospId, hospId).eq(Responsibility::getResponsibilityType, NumberConstant.ONE).eq(Responsibility::getShareId,id));
+                .eq(Responsibility::getHospId, hospId).eq(Responsibility::getResponsibilityType, NumberConstant.ONE).eq(Responsibility::getShareId, id));
         // 归集后
         // 归集后
         List<IncomeCollection> incomeList = incomeCollectionService.list(new QueryWrapper<IncomeCollection>().lambda()
         List<IncomeCollection> incomeList = incomeCollectionService.list(new QueryWrapper<IncomeCollection>().lambda()
                 .eq(IncomeCollection::getHospId, hospId)
                 .eq(IncomeCollection::getHospId, hospId)
@@ -125,10 +125,10 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
         List<AllocationQuery> allocationQueryList = allocationQueryService.list(new QueryWrapper<AllocationQuery>().lambda().eq(AllocationQuery::getHospId, hospId)
         List<AllocationQuery> allocationQueryList = allocationQueryService.list(new QueryWrapper<AllocationQuery>().lambda().eq(AllocationQuery::getHospId, hospId)
                 .eq(year > 0, AllocationQuery::getDateYear, year)
                 .eq(year > 0, AllocationQuery::getDateYear, year)
                 .eq(month > 0, AllocationQuery::getDateMonth, month)
                 .eq(month > 0, AllocationQuery::getDateMonth, month)
-                .eq(AllocationQuery::getOriginType,NumberConstant.TWO));
+                .eq(AllocationQuery::getOriginType, NumberConstant.TWO));
         // 封装数据
         // 封装数据
         List<AllocationQueryReportVO> allocationQueryReportVOList = BeanUtil.convertList(allocationQueryList, AllocationQueryReportVO.class);
         List<AllocationQueryReportVO> allocationQueryReportVOList = BeanUtil.convertList(allocationQueryList, AllocationQueryReportVO.class);
-        allocationQueryReportVOList.forEach(i->{
+        allocationQueryReportVOList.forEach(i -> {
             i.setAccountingCodes(Arrays.asList(i.getAccountingCode().split(StrUtil.COMMA)));
             i.setAccountingCodes(Arrays.asList(i.getAccountingCode().split(StrUtil.COMMA)));
             i.setAccountingNames(Arrays.asList(i.getAccountingName().split(StrUtil.COMMA)));
             i.setAccountingNames(Arrays.asList(i.getAccountingName().split(StrUtil.COMMA)));
         });
         });
@@ -148,20 +148,21 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
                 CostDepartmentProfitVO costDepartmentProfitVO = new CostDepartmentProfitVO();
                 CostDepartmentProfitVO costDepartmentProfitVO = new CostDepartmentProfitVO();
                 costDepartmentProfitVO.setYear(finalYear);
                 costDepartmentProfitVO.setYear(finalYear);
                 costDepartmentProfitVO.setMonth(finalMonth);
                 costDepartmentProfitVO.setMonth(finalMonth);
+                costDepartmentProfitVO.setReportId(j.getId());
                 costDepartmentProfitVO.setReportNum(j.getNum());
                 costDepartmentProfitVO.setReportNum(j.getNum());
-                costDepartmentProfitVO.setCostType(j.getCalcType());
+                costDepartmentProfitVO.setCalcType(j.getCalcType());
                 costDepartmentProfitVO.setReportName(j.getReportName());
                 costDepartmentProfitVO.setReportName(j.getReportName());
                 costDepartmentProfitVO.setCalcFormula(j.getCalcFormula());
                 costDepartmentProfitVO.setCalcFormula(j.getCalcFormula());
+                costDepartmentProfitVO.setReportParentId(j.getParentId());
                 costDepartmentProfitVO.setResponsibilityCode(i.getResponsibilityCode());
                 costDepartmentProfitVO.setResponsibilityCode(i.getResponsibilityCode());
                 costDepartmentProfitVO.setResponsibilityName(i.getResponsibilityName());
                 costDepartmentProfitVO.setResponsibilityName(i.getResponsibilityName());
-                costDepartmentProfitVO.setReportParentId(i.getParentId());
                 costDepartmentProfitVO.setCostType(NumberConstant.ONE);
                 costDepartmentProfitVO.setCostType(NumberConstant.ONE);
                 costDepartmentProfitVO.setIncomeType(NumberConstant.ONE);
                 costDepartmentProfitVO.setIncomeType(NumberConstant.ONE);
                 costDepartmentProfitVO.setHospId(hospId);
                 costDepartmentProfitVO.setHospId(hospId);
                 list.add(costDepartmentProfitVO);
                 list.add(costDepartmentProfitVO);
             });
             });
         });
         });
-        Map<Integer, List<CostDepartmentProfitVO>> listMap = list.stream().collect(Collectors.groupingBy(CostDepartmentProfitVO::getReportNum));
+        Map<Long, List<CostDepartmentProfitVO>> listMap = list.stream().collect(Collectors.groupingBy(CostDepartmentProfitVO::getReportId));
         // 记录每一次计算的钱
         // 记录每一次计算的钱
         list.forEach(i -> {
         list.forEach(i -> {
             Integer calcType = i.getCostType();
             Integer calcType = i.getCostType();
@@ -172,19 +173,19 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
                     break;
                     break;
                 case 2:
                 case 2:
                     // TODO 按照分摊层级进行计算
                     // TODO 按照分摊层级进行计算
-                    i.setAmount(setShareLevelReportData(i,costShareLevelList,reportRelationMap,allocationList));
+                    i.setAmount(setShareLevelReportData(i, costShareLevelList, reportRelationMap, allocationList));
                     break;
                     break;
                 case 3:
                 case 3:
                     // TODO 按照小计进行计算
                     // TODO 按照小计进行计算
-                    i.setAmount(setSubtotal(i,costShareLevelList,listMap,list,incomeList,allocationQueryReportVOList,reportRelationMap,allocationList));
+                    i.setAmount(setSubtotal(i, costShareLevelList, listMap, list, incomeList, allocationQueryReportVOList, reportRelationMap, allocationList));
                     break;
                     break;
                 case 4:
                 case 4:
                     // TODO 按照计算公式进行计算
                     // TODO 按照计算公式进行计算
-                    i.setAmount(setCalculation(i,costShareLevelList,listMap,incomeList,allocationQueryReportVOList,reportRelationMap,allocationList));
+                    i.setAmount(setCalculation(i,list, costShareLevelList, listMap, incomeList, allocationQueryReportVOList, reportRelationMap, allocationList));
                     break;
                     break;
                 case 5:
                 case 5:
                     // TODO  按照责任中心进行计算
                     // TODO  按照责任中心进行计算
-                    i.setAmount(setResponsibilityCode(i,reportRelationMap,allocationList));
+                    i.setAmount(setResponsibilityCode(i, reportRelationMap, allocationList));
                     break;
                     break;
                 default:
                 default:
                     i.setAmount(new BigDecimal("0.0000"));
                     i.setAmount(new BigDecimal("0.0000"));
@@ -194,11 +195,13 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
         // 删除这个年月的数据
         // 删除这个年月的数据
         List<CostDepartmentProfit> list1 = this.list(new QueryWrapper<CostDepartmentProfit>().lambda().eq(CostDepartmentProfit::getHospId, hospId)
         List<CostDepartmentProfit> list1 = this.list(new QueryWrapper<CostDepartmentProfit>().lambda().eq(CostDepartmentProfit::getHospId, hospId)
                 .eq(CostDepartmentProfit::getYear, year).eq(CostDepartmentProfit::getMonth, month));
                 .eq(CostDepartmentProfit::getYear, year).eq(CostDepartmentProfit::getMonth, month));
-        this.removeByIds(list1);
+        if (CollUtil.isNotEmpty(list1)){
+            this.removeByIds(list1);
+        }
         // 添加数据
         // 添加数据
         List<CostDepartmentProfit> costDepartmentProfits = BeanUtil.convertList(list, CostDepartmentProfit.class);
         List<CostDepartmentProfit> costDepartmentProfits = BeanUtil.convertList(list, CostDepartmentProfit.class);
         long l = System.currentTimeMillis();
         long l = System.currentTimeMillis();
-        costDepartmentProfits.forEach(i->{
+        costDepartmentProfits.forEach(i -> {
             i.setCreateTime(l);
             i.setCreateTime(l);
         });
         });
         this.saveBatch(costDepartmentProfits);
         this.saveBatch(costDepartmentProfits);
@@ -209,9 +212,9 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
      *
      *
      * @param i
      * @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<ReportRelation> reportRelationList = reportRelationMap.get(i.getId());
+        List<ReportRelation> reportRelationList = reportRelationMap.get(i.getReportId());
         AtomicReference<BigDecimal> sum = new AtomicReference<>(new BigDecimal("0.000"));
         AtomicReference<BigDecimal> sum = new AtomicReference<>(new BigDecimal("0.000"));
         if (CollUtil.isNotEmpty(reportRelationList)) {
         if (CollUtil.isNotEmpty(reportRelationList)) {
             // 获取对应的会计科目信息  筛选会计科目的Code
             // 获取对应的会计科目信息  筛选会计科目的Code
@@ -219,44 +222,48 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
             // 查找在归集数据里面当前责任中心对应的这些会计科目的金额
             // 查找在归集数据里面当前责任中心对应的这些会计科目的金额
             List<IncomeCollection> incomeCollectionList = list.stream().filter(income -> income.getResponsibilityCode().equals(i.getResponsibilityCode()) && accountList.contains(income.getAccountingCode())).collect(Collectors.toList());
             List<IncomeCollection> incomeCollectionList = list.stream().filter(income -> income.getResponsibilityCode().equals(i.getResponsibilityCode()) && accountList.contains(income.getAccountingCode())).collect(Collectors.toList());
             // 需要查询分摊后的表
             // 需要查询分摊后的表
+            // 归集加
             List<AllocationQueryReportVO> reportVOList = allocationQueryReportVOList.stream().filter(m -> m.getResponsibilityCode().equals(i.getResponsibilityCode()) && !Collections.disjoint(accountList, m.getAccountingCodes())).collect(Collectors.toList());
             List<AllocationQueryReportVO> reportVOList = allocationQueryReportVOList.stream().filter(m -> m.getResponsibilityCode().equals(i.getResponsibilityCode()) && !Collections.disjoint(accountList, m.getAccountingCodes())).collect(Collectors.toList());
             if (CollUtil.isNotEmpty(incomeCollectionList)) {
             if (CollUtil.isNotEmpty(incomeCollectionList)) {
                 incomeCollectionList.forEach(m -> {
                 incomeCollectionList.forEach(m -> {
                     sum.updateAndGet(v -> v.add(m.getAmount()));
                     sum.updateAndGet(v -> v.add(m.getAmount()));
                 });
                 });
             }
             }
-            if (CollUtil.isNotEmpty(reportVOList)){
-                reportVOList.forEach(m->{
-                    sum.updateAndGet(v->v.add(m.getAmount()));
+            // 成本减
+            if (CollUtil.isNotEmpty(reportVOList)) {
+                reportVOList.forEach(m -> {
+                    sum.updateAndGet(v -> v.subtract(m.getAmount()));
                 });
                 });
             }
             }
         }
         }
         i.setAmount(new BigDecimal(sum.toString()));
         i.setAmount(new BigDecimal(sum.toString()));
 //        numMap.put(i.getReportNum()+i.getResponsibilityCode(),new BigDecimal(sum.toString()));
 //        numMap.put(i.getReportNum()+i.getResponsibilityCode(),new BigDecimal(sum.toString()));
-        return new BigDecimal(sum.toString());
+        return sum.get();
     }
     }
 
 
     /**
     /**
      * 按照分摊层级进行计算
      * 按照分摊层级进行计算
      * 按照分摊层级计算  报表分摊层级是当前的层级  并且目标责任中心失败当前责任中心
      * 按照分摊层级计算  报表分摊层级是当前的层级  并且目标责任中心失败当前责任中心
      */
      */
-    private BigDecimal setShareLevelReportData(CostDepartmentProfitVO i,List<CostShareLevel> costShareLevelList, Map<Long, List<ReportRelation>> reportRelationMap, List<Allocation> allocationList) {
-        List<ReportRelation> reportRelationList = reportRelationMap.get(i.getId());
-        // 找到对应的分摊层级的Id  但是分摊报表里面存的是分摊层级的序号
-        List<Long> shareLevelIds = reportRelationList.stream().map(ReportRelation::getRelationCode).map(Long::valueOf).collect(Collectors.toList());
-        List<Integer> levelShortList = costShareLevelList.stream().filter(m -> shareLevelIds.contains(m.getId())).map(CostShareLevel::getLeverSort).collect(Collectors.toList());
+    private BigDecimal setShareLevelReportData(CostDepartmentProfitVO i, List<CostShareLevel> costShareLevelList, Map<Long, List<ReportRelation>> reportRelationMap, List<Allocation> allocationList) {
+        List<ReportRelation> reportRelationList = reportRelationMap.get(i.getReportId());
         AtomicReference<BigDecimal> sum = new AtomicReference<>(new BigDecimal("0.000"));
         AtomicReference<BigDecimal> sum = new AtomicReference<>(new BigDecimal("0.000"));
-        if (CollUtil.isNotEmpty(shareLevelIds)) {
-            // 查询报表里面是当前分摊层级的数据
-            List<Allocation> allocations = allocationList.stream().filter(m -> levelShortList.contains(m.getLevelSort()) && m.getTargetResponsibilityCode().equals(i.getResponsibilityCode())).collect(Collectors.toList());
-            if (CollUtil.isNotEmpty(allocations)) {
-                allocations.forEach(m -> {
-                    sum.updateAndGet(v -> v.add(m.getAmount()));
-                });
+        if (CollUtil.isNotEmpty(reportRelationList)) {
+            // 找到对应的分摊层级的Id  但是分摊报表里面存的是分摊层级的序号
+            List<Long> shareLevelIds = reportRelationList.stream().map(ReportRelation::getRelationCode).map(Long::valueOf).collect(Collectors.toList());
+            List<Integer> levelShortList = costShareLevelList.stream().filter(m -> shareLevelIds.contains(m.getId())).map(CostShareLevel::getLeverSort).collect(Collectors.toList());
+            if (CollUtil.isNotEmpty(levelShortList)) {
+                // 查询报表里面是当前分摊层级的数据
+                List<Allocation> allocations = allocationList.stream().filter(m -> levelShortList.contains(m.getLevelSort()) && m.getTargetResponsibilityCode().equals(i.getResponsibilityCode())).collect(Collectors.toList());
+                if (CollUtil.isNotEmpty(allocations)) {
+                    allocations.forEach(m -> {
+                        sum.updateAndGet(v -> v.add(m.getAmount()));
+                    });
+                }
             }
             }
         }
         }
         i.setAmount(new BigDecimal(sum.toString()));
         i.setAmount(new BigDecimal(sum.toString()));
-        return new BigDecimal(sum.toString());
+        return sum.get();
     }
     }
 
 
     /**
     /**
@@ -266,21 +273,23 @@ 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<ReportRelation> reportRelationList = reportRelationMap.get(costDepartmentProfitVO.getId());
-        // 获取对应的责任中心的Code集合  这个是设置的责任中心
-        List<String> responsibilityCodes = reportRelationList.stream().map(ReportRelation::getRelationCode).collect(Collectors.toList());
+        List<ReportRelation> reportRelationList = reportRelationMap.get(costDepartmentProfitVO.getReportId());
         AtomicReference<BigDecimal> sum = new AtomicReference<>(new BigDecimal("0.000"));
         AtomicReference<BigDecimal> sum = new AtomicReference<>(new BigDecimal("0.000"));
-        if (CollUtil.isNotEmpty(responsibilityCodes)) {
-            // 查询报表里面是当前分摊层级的数据
-            List<Allocation> allocations = allocationList.stream().filter(i -> i.getTargetResponsibilityCode().equals(costDepartmentProfitVO.getResponsibilityCode()) && responsibilityCodes.contains(i.getResponsibilityCode())).collect(Collectors.toList());
-            if (CollUtil.isNotEmpty(allocations)) {
-                allocations.forEach(m -> {
-                    sum.updateAndGet(v -> v.add(m.getAmount()));
-                });
+        if (CollUtil.isNotEmpty(reportRelationList)) {
+            // 获取对应的责任中心的Code集合  这个是设置的责任中心
+            List<String> responsibilityCodes = reportRelationList.stream().map(ReportRelation::getRelationCode).collect(Collectors.toList());
+            if (CollUtil.isNotEmpty(responsibilityCodes)) {
+                // 查询报表里面是当前分摊层级的数据
+                List<Allocation> allocations = allocationList.stream().filter(i -> i.getTargetResponsibilityCode().equals(costDepartmentProfitVO.getResponsibilityCode()) && responsibilityCodes.contains(i.getResponsibilityCode())).collect(Collectors.toList());
+                if (CollUtil.isNotEmpty(allocations)) {
+                    allocations.forEach(m -> {
+                        sum.updateAndGet(v -> v.add(m.getAmount()));
+                    });
+                }
             }
             }
         }
         }
         costDepartmentProfitVO.setAmount(new BigDecimal(sum.toString()));
         costDepartmentProfitVO.setAmount(new BigDecimal(sum.toString()));
-        return new BigDecimal(sum.toString());
+        return sum.get();
     }
     }
 
 
     /**
     /**
@@ -289,76 +298,83 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
      */
      */
     public BigDecimal setSubtotal(CostDepartmentProfitVO costDepartmentProfitVO,
     public BigDecimal setSubtotal(CostDepartmentProfitVO costDepartmentProfitVO,
                                   List<CostShareLevel> costShareLevelList,
                                   List<CostShareLevel> costShareLevelList,
-                                  Map<Integer, List<CostDepartmentProfitVO>> listMap,
+                                  Map<Long, List<CostDepartmentProfitVO>> listMap,
                                   List<CostDepartmentProfitVO> profitVOS,
                                   List<CostDepartmentProfitVO> profitVOS,
                                   List<IncomeCollection> list,
                                   List<IncomeCollection> list,
-                                  List<AllocationQueryReportVO> allocationQueryReportVOList ,
+                                  List<AllocationQueryReportVO> allocationQueryReportVOList,
                                   Map<Long, List<ReportRelation>> reportRelationMap, List<Allocation> allocationList) {
                                   Map<Long, List<ReportRelation>> reportRelationMap, List<Allocation> allocationList) {
         // 因为报表是按照报表项目的升序进行排序的  前面的报表是已经进行计算了的
         // 因为报表是按照报表项目的升序进行排序的  前面的报表是已经进行计算了的
         // 查询当前报表的父层级id
         // 查询当前报表的父层级id
         Long reportParentId = costDepartmentProfitVO.getReportParentId();
         Long reportParentId = costDepartmentProfitVO.getReportParentId();
         String responsibilityCode = costDepartmentProfitVO.getResponsibilityCode();
         String responsibilityCode = costDepartmentProfitVO.getResponsibilityCode();
         // 查询报表里面在当前父层级下的并且不是自己的报表项目
         // 查询报表里面在当前父层级下的并且不是自己的报表项目
-        List<CostDepartmentProfitVO> costDepartmentProfitVOS = profitVOS.stream().filter(i -> i.getReportParentId().equals(reportParentId) && i.getResponsibilityCode().equals(costDepartmentProfitVO.getResponsibilityCode()) && !NumberConstant.THREE.equals(i.getCostType())).collect(Collectors.toList());
-        BigDecimal sum = new BigDecimal("0.0000");
+        List<CostDepartmentProfitVO> costDepartmentProfitVOS = profitVOS.stream().filter(i -> i.getReportParentId().equals(reportParentId) && i.getResponsibilityCode().equals(responsibilityCode) && !NumberConstant.THREE.equals(i.getCostType())).collect(Collectors.toList());
+        AtomicReference<BigDecimal> sum = new AtomicReference<>(new BigDecimal("0.0000"));
         // 遍历数据 之前的已经经过了计算
         // 遍历数据 之前的已经经过了计算
-        costDepartmentProfitVOS.forEach(i->{
-            Integer num = i.getReportNum();
-            List<CostDepartmentProfitVO> costDepartmentProfitVOS1 = listMap.get(num);
-            if (CollUtil.isEmpty(costDepartmentProfitVOS1)){
-                throw new CostException(500,"报表未找到");
+        costDepartmentProfitVOS.forEach(i -> {
+            Long reportId = i.getReportId();
+            List<CostDepartmentProfitVO> costDepartmentProfitVOS1 = listMap.get(reportId);
+            if (CollUtil.isEmpty(costDepartmentProfitVOS1)) {
+                throw new CostException(500, "报表未找到");
             }
             }
-            sum.add(getAmount(profitVOS,costShareLevelList,responsibilityCode,list,allocationQueryReportVOList,reportRelationMap,allocationList,listMap));
+            BigDecimal amount = getAmount(profitVOS, costShareLevelList, responsibilityCode, list, allocationQueryReportVOList, reportRelationMap, allocationList, listMap);
+            sum.updateAndGet(v -> v.add(amount));
         });
         });
         costDepartmentProfitVO.setAmount(new BigDecimal(sum.toString()));
         costDepartmentProfitVO.setAmount(new BigDecimal(sum.toString()));
-        return new BigDecimal(sum.toString());
+        return sum.get();
     }
     }
+
     /***
     /***
      * 按照计算方式进行计算
      * 按照计算方式进行计算
      */
      */
-    public BigDecimal setCalculation(CostDepartmentProfitVO costDepartmentProfitVO,List<CostShareLevel> costShareLevelList,Map<Integer, 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) {
         // 获取当前报表的计算方式  [1]+[2]类型
         // 获取当前报表的计算方式  [1]+[2]类型
         String calcFormula = costDepartmentProfitVO.getCalcFormula();
         String calcFormula = costDepartmentProfitVO.getCalcFormula();
         String responsibilityCode = costDepartmentProfitVO.getResponsibilityCode();
         String responsibilityCode = costDepartmentProfitVO.getResponsibilityCode();
         String replace = calcFormula.replace("[", "").replace("]", "").replace("+", ",");
         String replace = calcFormula.replace("[", "").replace("]", "").replace("+", ",");
         List<Integer> calcFormulaList = Arrays.stream(replace.split(StrUtil.COMMA)).map(Integer::valueOf).collect(Collectors.toList());
         List<Integer> calcFormulaList = Arrays.stream(replace.split(StrUtil.COMMA)).map(Integer::valueOf).collect(Collectors.toList());
-        BigDecimal bigDecimal = new BigDecimal("0.0000");
-        calcFormulaList.forEach(i->{
+        // 查询这个编号集合的报表
+        List<Long> reportIdList = costDepartmentProfitVOList.stream().filter(i -> i.getResponsibilityCode().equals(responsibilityCode) && calcFormulaList.contains(i.getReportNum())).map(CostDepartmentProfitVO::getReportParentId).collect(Collectors.toList());
+
+        AtomicReference<BigDecimal> bigDecimal = new AtomicReference<>(new BigDecimal("0.0000"));
+        reportIdList.forEach(i -> {
             List<CostDepartmentProfitVO> profitVOS = listMap.get(i);
             List<CostDepartmentProfitVO> profitVOS = listMap.get(i);
-            if (CollUtil.isEmpty(profitVOS)){
-                throw new CostException(500,"报表未找到");
+            if (CollUtil.isEmpty(profitVOS)) {
+                throw new CostException(500, "报表未找到");
             }
             }
-            bigDecimal.add(getAmount(profitVOS,costShareLevelList,responsibilityCode,list,allocationQueryReportVOList,reportRelationMap,allocationList,listMap));
+            BigDecimal amount = getAmount(profitVOS, costShareLevelList, responsibilityCode, list, allocationQueryReportVOList, reportRelationMap, allocationList, listMap);
+            bigDecimal.updateAndGet(v -> v.add(amount));
         });
         });
-        return bigDecimal;
+        return bigDecimal.get();
     }
     }
+
     /**
     /**
      * 判断是那种计算方式 调用方法进行计算
      * 判断是那种计算方式 调用方法进行计算
      */
      */
     public BigDecimal getAmount(List<CostDepartmentProfitVO> profitVOS,
     public BigDecimal getAmount(List<CostDepartmentProfitVO> profitVOS,
                                 List<CostShareLevel> costShareLevelList,
                                 List<CostShareLevel> costShareLevelList,
-                                String responsibilityCode,List<IncomeCollection> list,
-                                List<AllocationQueryReportVO> allocationQueryReportVOList ,
+                                String responsibilityCode, List<IncomeCollection> list,
+                                List<AllocationQueryReportVO> allocationQueryReportVOList,
                                 Map<Long, List<ReportRelation>> reportRelationMap, List<Allocation> allocationList,
                                 Map<Long, List<ReportRelation>> reportRelationMap, List<Allocation> allocationList,
-                                Map<Integer, List<CostDepartmentProfitVO>> listMap){
+                                Map<Long, List<CostDepartmentProfitVO>> listMap) {
         BigDecimal bigDecimal = new BigDecimal("0.0000");
         BigDecimal bigDecimal = new BigDecimal("0.0000");
         // 在对这个报表进行过滤
         // 在对这个报表进行过滤
         List<CostDepartmentProfitVO> costDepartmentProfitVOS = profitVOS.stream().filter(i -> i.getResponsibilityCode().equals(responsibilityCode)).collect(Collectors.toList());
         List<CostDepartmentProfitVO> costDepartmentProfitVOS = profitVOS.stream().filter(i -> i.getResponsibilityCode().equals(responsibilityCode)).collect(Collectors.toList());
         // 都一个就是
         // 都一个就是
         CostDepartmentProfitVO costDepartmentProfitVO = costDepartmentProfitVOS.get(0);
         CostDepartmentProfitVO costDepartmentProfitVO = costDepartmentProfitVOS.get(0);
         Integer costType = costDepartmentProfitVO.getCostType();
         Integer costType = costDepartmentProfitVO.getCostType();
-        if (NumberConstant.ONE.equals(costType)){
+        if (NumberConstant.ONE.equals(costType)) {
             // 调用计算的方法 按照会计科目
             // 调用计算的方法 按照会计科目
-            bigDecimal=setAccountReportData(costDepartmentProfitVO,list,allocationQueryReportVOList,reportRelationMap);
-        }else if (NumberConstant.TWO.equals(costType)){
+            bigDecimal = setAccountReportData(costDepartmentProfitVO, list, allocationQueryReportVOList, reportRelationMap);
+        } else if (NumberConstant.TWO.equals(costType)) {
             // 按照分摊层级
             // 按照分摊层级
-            bigDecimal=setShareLevelReportData(costDepartmentProfitVO,costShareLevelList,reportRelationMap,allocationList);
-        }else if (NumberConstant.THREE.equals(costType)){
+            bigDecimal = setShareLevelReportData(costDepartmentProfitVO, costShareLevelList, reportRelationMap, allocationList);
+        } else if (NumberConstant.THREE.equals(costType)) {
             // 小计
             // 小计
-            bigDecimal=setSubtotal(costDepartmentProfitVO,costShareLevelList,listMap,profitVOS,list,allocationQueryReportVOList,reportRelationMap,allocationList);
-        }else if (NumberConstant.FIVE.equals(costType)){
+            bigDecimal = setSubtotal(costDepartmentProfitVO, costShareLevelList, listMap, profitVOS, list, allocationQueryReportVOList, reportRelationMap, allocationList);
+        } else if (NumberConstant.FIVE.equals(costType)) {
             // 按照责任中心
             // 按照责任中心
-            bigDecimal=setResponsibilityCode(costDepartmentProfitVO,reportRelationMap,allocationList);
+            bigDecimal = setResponsibilityCode(costDepartmentProfitVO, reportRelationMap, allocationList);
         }
         }
         return bigDecimal;
         return bigDecimal;
     }
     }

+ 2 - 0
src/main/resources/mapper/CostDepartmentProfitMapper.xml

@@ -9,9 +9,11 @@
         <result property="year" column="year"/>
         <result property="year" column="year"/>
         <result property="month" column="month"/>
         <result property="month" column="month"/>
         <result property="reportParentId" column="report_parent_id"/>
         <result property="reportParentId" column="report_parent_id"/>
+        <result property="reportId" column="report_id"/>
         <result property="reportNum" column="report_num"/>
         <result property="reportNum" column="report_num"/>
         <result property="reportName" column="report_name"/>
         <result property="reportName" column="report_name"/>
         <result property="calcFormula" column="calc_formula"/>
         <result property="calcFormula" column="calc_formula"/>
+        <result property="calcType" column="calc_type"/>
         <result property="responsibilityCode" column="responsibility_code"/>
         <result property="responsibilityCode" column="responsibility_code"/>
         <result property="responsibilityName" column="responsibility_name"/>
         <result property="responsibilityName" column="responsibility_name"/>
         <result property="costType" column="cost_type"/>
         <result property="costType" column="cost_type"/>