Преглед на файлове

Merge branch 'master' of huangrui/CostAccount into dev

lijiaxi преди 4 години
родител
ревизия
eb1f33e23d
променени са 1 файла, в които са добавени 35 реда и са изтрити 15 реда
  1. 35 15
      src/main/java/com/imed/costaccount/service/impl/CostDepartmentProfitServiceImpl.java

+ 35 - 15
src/main/java/com/imed/costaccount/service/impl/CostDepartmentProfitServiceImpl.java

@@ -108,12 +108,17 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
         List<ReportForm> reportFormList = reportFormService.list(new QueryWrapper<ReportForm>().lambda()
                 .eq(ReportForm::getHospId, hospId)
                 .eq(ReportForm::getReportType, NumberConstant.ZERO));
-
+        if (CollUtil.isEmpty(reportFormList)) {
+            throw new CostException(500, "损益表未找到");
+        }
         // 遍历报表数据根据报表数据计算方式进行计算
 
         // 查询最后一个层级的责任中心
         List<CostShareLevel> costShareLevelList = costShareLevelService.list(new QueryWrapper<CostShareLevel>().lambda()
                 .eq(CostShareLevel::getHospId, hospId).orderByDesc(CostShareLevel::getLeverSort));
+        if (CollUtil.isEmpty(costShareLevelList)) {
+            throw new CostException(500, "分摊层级未设置");
+        }
         Long id = costShareLevelList.get(0).getId();
         // 查询责任中心里面是这个层级的所有的收益中心
         List<Responsibility> responsibilityList = responsibilityService.list(new QueryWrapper<Responsibility>().lambda()
@@ -122,13 +127,18 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
         List<IncomeCollection> incomeList = incomeCollectionService.list(new QueryWrapper<IncomeCollection>().lambda()
                 .eq(IncomeCollection::getHospId, hospId)
                 .eq(year > 0, IncomeCollection::getYear, year).eq(month > 0, IncomeCollection::getMonth, month));
-
+        if (CollUtil.isEmpty(incomeList)) {
+            throw new CostException(500, "归集后数据不存在");
+        }
         Map<Long, List<ReportRelation>> reportRelationMap = reportRelationService.list(new QueryWrapper<ReportRelation>().lambda().eq(ReportRelation::getHospId, hospId)).stream().collect(Collectors.groupingBy(ReportRelation::getReportId));
         // 分摊后的数据getOriginType等于2说明是分摊后的数据
         List<AllocationQuery> allocationQueryList = allocationQueryService.list(new QueryWrapper<AllocationQuery>().lambda().eq(AllocationQuery::getHospId, hospId)
                 .eq(year > 0, AllocationQuery::getDateYear, year)
                 .eq(month > 0, AllocationQuery::getDateMonth, month)
                 .eq(AllocationQuery::getOriginType, NumberConstant.TWO));
+        if (CollUtil.isEmpty(allocationQueryList)) {
+            throw new CostException(500, "分摊后数据不存在");
+        }
         // 封装数据
         List<AllocationQueryReportVO> allocationQueryReportVOList = BeanUtil.convertList(allocationQueryList, AllocationQueryReportVO.class);
         allocationQueryReportVOList.forEach(i -> {
@@ -139,6 +149,9 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
         // 查询分摊的报表数据 后面的计算方式需要使用 小计等需要使用
         List<Allocation> allocationList = allocationService.list(new QueryWrapper<Allocation>().lambda().eq(Allocation::getHospId, hospId)
                 .eq(year > 0, Allocation::getDateYear, year).eq(month > 0, Allocation::getDateMonth, month));
+        if (CollUtil.isEmpty(allocationList)) {
+            throw new CostException(500, "分摊报表数据不存在");
+        }
 
         // 查询所有指定类型的损益表
         // 每个责任中心对应报表都要生成记录
@@ -360,22 +373,29 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
         // 获取当前报表的计算方式  [1]+[2]类型/ [1]-[2]
         String calcFormula = costDepartmentProfitVO.getCalcFormula();
         String responsibilityCode = costDepartmentProfitVO.getResponsibilityCode();
-        String replace = calcFormula.replace("[", "").replace("]", "").replace("+", ",").replace("-", ",");
+        String replace = calcFormula.replace("[", "").replace("]", "").replace("+", ",").replace("-", ",-");
         List<Integer> calcFormulaList = Arrays.stream(replace.split(StrUtil.COMMA)).map(Integer::valueOf).collect(Collectors.toList());
         // 查询这个编号集合的报表
-        List<Long> reportIdList = costDepartmentProfitVOList.stream().filter(i -> i.getResponsibilityCode().equals(responsibilityCode) && calcFormulaList.contains(i.getReportNum())).map(CostDepartmentProfitVO::getReportId).collect(Collectors.toList());
-
         AtomicReference<BigDecimal> bigDecimal = new AtomicReference<>(new BigDecimal("0.0000"));
-        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.updateAndGet(v -> v.add(amount));
-            });
-        }
+        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());
+            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);
+                    if (calc>0){
+                        bigDecimal.updateAndGet(v -> v.add(amount));
+                    }else {
+                        bigDecimal.updateAndGet(v -> v.subtract(amount));
+                    }
+                });
+            }
+
+        });
         return bigDecimal.get();
     }