Parcourir la source

添加计算指定报表类型全院损益的功能

JammeyJiang il y a 8 mois
Parent
commit
63bf2de05a

+ 9 - 0
src/main/java/com/kcim/service/HospProfitAndLossService.java

@@ -21,6 +21,15 @@ public interface HospProfitAndLossService extends IService<HospProfitAndLoss> {
      */
     void calc(String date, Long hospId);
 
+    /**
+     * 计算全院损益
+     *
+     * @param date   yyyy-MM-dd 时间
+     * @param hospId 医院id
+     * @param reportType 报表类型
+     */
+    void calcHospProfit(String date, Long hospId, Integer reportType);
+
     /**
      * 全院损益列表
      *

+ 8 - 1
src/main/java/com/kcim/service/ReportFormService.java

@@ -1,11 +1,11 @@
 package com.kcim.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.kcim.dao.model.ReportForm;
 import com.kcim.dao.model.dto.CopyReportDTO;
 import com.kcim.dao.model.dto.ReportFormEditDTO;
 import com.kcim.dao.model.dto.ReportFormSaveDTO;
 import com.kcim.vo.ReportFormVO;
-import com.kcim.dao.model.ReportForm;
 import com.kcim.vo.SessionUserVO;
 
 import java.util.List;
@@ -75,6 +75,13 @@ public interface ReportFormService extends IService<ReportForm> {
      */
     public void checkExistLoss(Long hospId);
 
+    /**
+     * 校验指定类型的全院损益报表是否存在默认损益
+     * @param hospId
+     * @param reportType
+     */
+    public void checkExistLoss(Long hospId, Integer reportType);
+
     Object getResponsibilities(String reportType, Long reportId);
 
     ReportForm getByReportId(Long hospId, String reportType, Long reportId);

+ 205 - 193
src/main/java/com/kcim/service/impl/HospProfitAndLossServiceImpl.java

@@ -185,6 +185,210 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
         this.saveBatch(list);
     }
 
+    /**
+     * 计算全院损益
+     * @param date   yyyy-MM-dd 时间
+     * @param hospId 医院id
+     * @param reportType 报表类型
+     */
+    @Override
+    public void calcHospProfit(String date, Long hospId, Integer reportType) {
+        List<Responsibility> leafResp = responsibilityService.getLeafResp(hospId);
+        DateTime parse = DateUtil.parse(date);
+        int year = DateUtil.year(parse);
+        int month = DateUtil.month(parse) + 1;
+        this.remove(
+                new LambdaQueryWrapper<HospProfitAndLoss>()
+                        .eq(HospProfitAndLoss::getDateYear, year)
+                        .eq(HospProfitAndLoss::getDateMonth, month)
+                        .eq(HospProfitAndLoss::getHospId, hospId)
+        );
+        // 得到全院损益计算报表
+        List<ReportForm> reportForms = reportFormService.getListByReportType(hospId, reportType);
+        if (CollUtil.isEmpty(reportForms)) {
+            throw new CostException("医院未设置全院损益计算报表");
+        }
+        reportFormService.checkExistLoss(hospId,reportType);
+        // 得到这个月所有收入数据
+        List<IncomeCollection> incomes = collectionService.getCollectionsByDate(year, month, hospId);
+        if (incomes.isEmpty()) {
+            throw new CostException("医院未归集本月收入数据");
+        }
+        Map<Long, List<ReportRelation>> reportRelationMap = reportRelationService.list(new QueryWrapper<ReportRelation>().lambda().eq(ReportRelation::getHospId, hospId)).stream().collect(Collectors.groupingBy(ReportRelation::getReportId));
+
+        // 得到这个月的所有成本数据
+        List<AllocationQuery> allocationQueries = allocationQueryService.getAllByDate(hospId, year, month);
+        if (allocationQueries.isEmpty()) {
+            throw new CostException("医院未分摊本月数据");
+        }
+        List<AllocationQueryReportVO> allocationQueryReportVOList = BeanUtil.convertList(allocationQueries, AllocationQueryReportVO.class);
+        allocationQueryReportVOList.forEach(i -> {
+            i.setAccountingCodes(Arrays.asList(i.getAccountingCode().split(StrUtil.COMMA)));
+            i.setAccountingNames(Arrays.asList(i.getAccountingName().split(StrUtil.COMMA)));
+        });
+        // 查询分摊的报表数据 后面的计算方式需要使用 小计等需要使用
+        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, "分摊报表数据不存在");
+        }
+        // 查询最后一个层级的责任中心
+        List<CostShareLevel> costShareLevelList = shareLevelService.list(new QueryWrapper<CostShareLevel>().lambda()
+                .eq(CostShareLevel::getHospId, hospId).orderByDesc(CostShareLevel::getLeverSort));
+        if (CollUtil.isEmpty(costShareLevelList)) {
+            throw new CostException(500, "分摊层级未设置");
+        }
+        List<HospProfitAndLossVo> listVo = new ArrayList<>();
+//        List<ReportForm> parentForms = reportForms.stream().filter(i -> i.getParentId().equals(0L)).collect(Collectors.toList());
+        int finalYear = year;
+        int finalMonth = month;
+        leafResp.forEach(i -> {
+            reportForms.forEach(j -> {
+                HospProfitAndLossVo hospProfitAndLossVo = new HospProfitAndLossVo();
+                hospProfitAndLossVo.setDateYear(finalYear);
+                hospProfitAndLossVo.setDateMonth(finalMonth);
+                hospProfitAndLossVo.setReportNum(j.getNum());
+                hospProfitAndLossVo.setReportName(j.getReportName());
+                hospProfitAndLossVo.setResponsibilityCode(i.getResponsibilityCode());
+                hospProfitAndLossVo.setResponsibilityName(i.getResponsibilityName());
+                hospProfitAndLossVo.setCostType(NumberConstant.ZERO);
+                hospProfitAndLossVo.setIncomeType(NumberConstant.ZERO);
+                hospProfitAndLossVo.setHospId(hospId);
+                hospProfitAndLossVo.setType(j.getCostType());
+                hospProfitAndLossVo.setFraction(j.getFraction());
+                hospProfitAndLossVo.setReportId(j.getId());
+                hospProfitAndLossVo.setReportNum(j.getNum());
+                hospProfitAndLossVo.setCalcType(j.getCalcType());
+                hospProfitAndLossVo.setReportName(j.getReportName());
+                hospProfitAndLossVo.setCalcFormula(j.getCalcFormula());
+                hospProfitAndLossVo.setReportParentId(j.getParentId());
+                listVo.add(hospProfitAndLossVo);
+            });
+        });
+
+        Map<Long, List<HospProfitAndLossVo>> listMap = listVo.stream().collect(Collectors.groupingBy(HospProfitAndLossVo::getReportId));
+        List<HospProfitAndLossVo> allList = BeanUtil.convertList(listVo, HospProfitAndLossVo.class);
+        // 记录每一次计算的钱
+        //所有小计 总计单独处理
+        listVo.forEach(i -> {
+            Integer calcType = i.getCalcType();
+            if (NumberConstant.ONE.equals(calcType)) {
+                // TODO 按照会计科目进行计算
+                i.setAmount(setAccountReportData(i, incomes, allocationQueryReportVOList, reportRelationMap));
+            } else if (NumberConstant.TWO.equals(calcType)) {
+                // TODO 按照分摊层级进行计算
+                i.setAmount(setShareLevelReportData(i, reportRelationMap, allocationList));
+            } else if (NumberConstant.THREE.equals(calcType)) {
+                // TODO 按照小计进行计算
+                i.setAmount(setSubtotal(i, costShareLevelList, listMap, listVo, incomes, allocationQueryReportVOList, reportRelationMap, allocationList, allList));
+            } else if (NumberConstant.FOUR.equals(calcType)) {
+                // TODO 按照计算公式进行计算
+//                i.setAmount(setCalculation(i, listVo, costShareLevelList, listMap, incomes, allocationQueryReportVOList, reportRelationMap, allocationList, allList));
+            } else if (NumberConstant.FIVE.equals(calcType)) {
+                // TODO  按照责任中心进行计算
+                i.setAmount(setResponsibilityCode(i, reportRelationMap, allocationList, allList));
+            } else {
+                i.setAmount(new BigDecimal("0.000000"));
+            }
+        });
+        //计算占比
+        if (CollectionUtils.isEmpty(listVo)) {
+            return;
+        }
+
+        List<HospProfitAndLossVo> listSum = new ArrayList<>();
+
+        //把所有数据按报表项目汇总
+        for (ReportForm j : reportForms) {
+            HospProfitAndLossVo hospProfitAndLossVo = new HospProfitAndLossVo();
+            hospProfitAndLossVo.setDateYear(finalYear);
+            hospProfitAndLossVo.setDateMonth(finalMonth);
+            hospProfitAndLossVo.setReportNum(j.getNum());
+            hospProfitAndLossVo.setReportName(j.getReportName());
+            hospProfitAndLossVo.setCostType(NumberConstant.ZERO);
+            hospProfitAndLossVo.setIncomeType(NumberConstant.ZERO);
+            hospProfitAndLossVo.setHospId(hospId);
+            hospProfitAndLossVo.setType(j.getCostType());
+            hospProfitAndLossVo.setFraction(j.getFraction());
+            hospProfitAndLossVo.setReportId(j.getId());
+            hospProfitAndLossVo.setReportNum(j.getNum());
+            hospProfitAndLossVo.setCalcType(j.getCalcType());
+            hospProfitAndLossVo.setReportName(j.getReportName());
+            hospProfitAndLossVo.setCalcFormula(j.getCalcFormula());
+            hospProfitAndLossVo.setReportParentId(j.getParentId());
+            listSum.add(hospProfitAndLossVo);
+        }
+        Map<Integer, List<HospProfitAndLossVo>> reportNumGroup = listVo.stream().collect(Collectors.groupingBy(HospProfitAndLossVo::getReportNum));
+        Map<Integer, BigDecimal> reportNumSumMap = new HashMap<>();
+        reportNumGroup.forEach((reportNum, hospProfitAndLossList) -> {
+            AtomicReference<BigDecimal> sum = new AtomicReference<>(new BigDecimal("0.000000"));
+            for (HospProfitAndLossVo hospProfitAndLoss : hospProfitAndLossList) {
+                if (hospProfitAndLoss.getAmount() != null) {
+                    sum.updateAndGet(f -> f.add(hospProfitAndLoss.getAmount()));
+                }
+            }
+            reportNumSumMap.put(reportNum, sum.get());
+        });
+
+        for (HospProfitAndLossVo costProfitVo : listSum) {
+            BigDecimal bigDecimal = reportNumSumMap.get(costProfitVo.getReportNum());
+            if (bigDecimal != null) {
+                costProfitVo.setAmount(bigDecimal);
+
+            } else {
+                costProfitVo.setAmount(BigDecimal.ZERO.setScale(6, RoundingMode.HALF_UP));
+            }
+        }
+        //单独计算计算公式数据
+        setCalculationAmount(listSum);
+        //收入
+        List<HospProfitAndLossVo> profitIncomeList = listSum.stream().filter(f -> f.getType().equals(NumberConstant.ONE)).collect(Collectors.toList());
+        List<HospProfitAndLossVo> profitIncome = costPercent(profitIncomeList);
+        //成本
+        List<HospProfitAndLossVo> profitCostList = listSum.stream().filter(f -> f.getType().equals(NumberConstant.TWO)).collect(Collectors.toList());
+
+        List<HospProfitAndLossVo> profitCost = costPercent(profitCostList);
+
+        //不计算项目
+        List<HospProfitAndLossVo> noCompute = listSum.stream().filter(f -> f.getFraction().equals(NumberConstant.THREE)).collect(Collectors.toList());
+        noCompute.forEach(profitVO -> profitVO.setPercent(null));
+
+        List<HospProfitAndLossVo> listAllVo = new ArrayList<>();
+
+        if (!CollectionUtils.isEmpty(profitIncome) && !CollectionUtils.isEmpty(profitCost) && !CollectionUtils.isEmpty(noCompute)) {
+            listAllVo.addAll(profitIncome);
+            listAllVo.addAll(profitCost);
+            listAllVo.addAll(noCompute);
+        } else if (!CollectionUtils.isEmpty(profitIncome) && !CollectionUtils.isEmpty(noCompute)) {
+            listAllVo.addAll(noCompute);
+            listAllVo.addAll(profitIncome);
+
+        } else if (!CollectionUtils.isEmpty(profitCost) && !CollectionUtils.isEmpty(noCompute)) {
+            listAllVo.addAll(noCompute);
+            listAllVo.addAll(profitCost);
+        } else if (!CollectionUtils.isEmpty(noCompute)) {
+            listAllVo.addAll(noCompute);
+        }
+
+        List<HospProfitAndLoss> list = BeanUtil.convertList(listAllVo, HospProfitAndLoss.class);
+        // 处理医院其他收支
+        List<CostOtherPaymentsData> otherPaymentsDatas = otherPaymentsDataService.getByMonth(year, month, hospId);
+        if (!otherPaymentsDatas.isEmpty()) {
+            otherPaymentsDatas.forEach(ele -> {
+                HospProfitAndLoss loss = new HospProfitAndLoss();
+                loss.setDateYear(year).setDateMonth(month).setReportName(ele.getPaymentsName()).setReportNum((int) (-ele.getId()))
+                        .setCreateTime(System.currentTimeMillis()).setAmount(ele.getTotalAmount()).setHospId(hospId)
+                        .setResponsibilityName("全院").setResponsibilityCode("-1").setPercent(null);
+                list.add(loss);
+            });
+        }
+        long l = System.currentTimeMillis();
+        list.forEach(i -> {
+            i.setCreateTime(l);
+        });
+        this.saveBatch(list);
+    }
+
     // 计算公式中钱
     private BigDecimal calcAmount(List<HospProfitAndLoss> list, String calcFormula, ReportForm reportForm) {
         // 得到所有的编号
@@ -1112,199 +1316,7 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
     @Override
     @Transactional(rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
     public void calcByResponsibility(String date, Long hospId) {
-        List<Responsibility> leafResp = responsibilityService.getLeafResp(hospId);
-        DateTime parse = DateUtil.parse(date);
-        int year = DateUtil.year(parse);
-        int month = DateUtil.month(parse) + 1;
-        this.remove(
-                new LambdaQueryWrapper<HospProfitAndLoss>()
-                        .eq(HospProfitAndLoss::getDateYear, year)
-                        .eq(HospProfitAndLoss::getDateMonth, month)
-                        .eq(HospProfitAndLoss::getHospId, hospId)
-        );
-        // 得到全院损益计算报表
-        List<ReportForm> reportForms = reportFormService.getListByReportType(hospId, ReportTypeEnum.HOSP_PROFIT_LOSS.getType());
-        if (CollUtil.isEmpty(reportForms)) {
-            throw new CostException("医院未设置全院损益计算报表");
-        }
-        // 得到这个月所有收入数据
-        List<IncomeCollection> incomes = collectionService.getCollectionsByDate(year, month, hospId);
-        if (incomes.isEmpty()) {
-            throw new CostException("医院未归集本月收入数据");
-        }
-        Map<Long, List<ReportRelation>> reportRelationMap = reportRelationService.list(new QueryWrapper<ReportRelation>().lambda().eq(ReportRelation::getHospId, hospId)).stream().collect(Collectors.groupingBy(ReportRelation::getReportId));
-
-        // 得到这个月的所有成本数据
-        List<AllocationQuery> allocationQueries = allocationQueryService.getAllByDate(hospId, year, month);
-        if (allocationQueries.isEmpty()) {
-            throw new CostException("医院未分摊本月数据");
-        }
-        List<AllocationQueryReportVO> allocationQueryReportVOList = BeanUtil.convertList(allocationQueries, AllocationQueryReportVO.class);
-        allocationQueryReportVOList.forEach(i -> {
-            i.setAccountingCodes(Arrays.asList(i.getAccountingCode().split(StrUtil.COMMA)));
-            i.setAccountingNames(Arrays.asList(i.getAccountingName().split(StrUtil.COMMA)));
-        });
-        // 查询分摊的报表数据 后面的计算方式需要使用 小计等需要使用
-        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, "分摊报表数据不存在");
-        }
-        // 查询最后一个层级的责任中心
-        List<CostShareLevel> costShareLevelList = shareLevelService.list(new QueryWrapper<CostShareLevel>().lambda()
-                .eq(CostShareLevel::getHospId, hospId).orderByDesc(CostShareLevel::getLeverSort));
-        if (CollUtil.isEmpty(costShareLevelList)) {
-            throw new CostException(500, "分摊层级未设置");
-        }
-        List<HospProfitAndLossVo> listVo = new ArrayList<>();
-//        List<ReportForm> parentForms = reportForms.stream().filter(i -> i.getParentId().equals(0L)).collect(Collectors.toList());
-        int finalYear = year;
-        int finalMonth = month;
-        leafResp.forEach(i -> {
-            reportForms.forEach(j -> {
-                HospProfitAndLossVo hospProfitAndLossVo = new HospProfitAndLossVo();
-                hospProfitAndLossVo.setDateYear(finalYear);
-                hospProfitAndLossVo.setDateMonth(finalMonth);
-                hospProfitAndLossVo.setReportNum(j.getNum());
-                hospProfitAndLossVo.setReportName(j.getReportName());
-                hospProfitAndLossVo.setResponsibilityCode(i.getResponsibilityCode());
-                hospProfitAndLossVo.setResponsibilityName(i.getResponsibilityName());
-                hospProfitAndLossVo.setCostType(NumberConstant.ZERO);
-                hospProfitAndLossVo.setIncomeType(NumberConstant.ZERO);
-                hospProfitAndLossVo.setHospId(hospId);
-                hospProfitAndLossVo.setType(j.getCostType());
-                hospProfitAndLossVo.setFraction(j.getFraction());
-                hospProfitAndLossVo.setReportId(j.getId());
-                hospProfitAndLossVo.setReportNum(j.getNum());
-                hospProfitAndLossVo.setCalcType(j.getCalcType());
-                hospProfitAndLossVo.setReportName(j.getReportName());
-                hospProfitAndLossVo.setCalcFormula(j.getCalcFormula());
-                hospProfitAndLossVo.setReportParentId(j.getParentId());
-                listVo.add(hospProfitAndLossVo);
-            });
-        });
-
-        Map<Long, List<HospProfitAndLossVo>> listMap = listVo.stream().collect(Collectors.groupingBy(HospProfitAndLossVo::getReportId));
-        List<HospProfitAndLossVo> allList = BeanUtil.convertList(listVo, HospProfitAndLossVo.class);
-        // 记录每一次计算的钱
-        //所有小计 总计单独处理
-        listVo.forEach(i -> {
-            Integer calcType = i.getCalcType();
-            if (NumberConstant.ONE.equals(calcType)) {
-                // TODO 按照会计科目进行计算
-                i.setAmount(setAccountReportData(i, incomes, allocationQueryReportVOList, reportRelationMap));
-            } else if (NumberConstant.TWO.equals(calcType)) {
-                // TODO 按照分摊层级进行计算
-                i.setAmount(setShareLevelReportData(i, reportRelationMap, allocationList));
-            } else if (NumberConstant.THREE.equals(calcType)) {
-                // TODO 按照小计进行计算
-                i.setAmount(setSubtotal(i, costShareLevelList, listMap, listVo, incomes, allocationQueryReportVOList, reportRelationMap, allocationList, allList));
-            } else if (NumberConstant.FOUR.equals(calcType)) {
-                // TODO 按照计算公式进行计算
-//                i.setAmount(setCalculation(i, listVo, costShareLevelList, listMap, incomes, allocationQueryReportVOList, reportRelationMap, allocationList, allList));
-            } else if (NumberConstant.FIVE.equals(calcType)) {
-                // TODO  按照责任中心进行计算
-                i.setAmount(setResponsibilityCode(i, reportRelationMap, allocationList, allList));
-            } else {
-                i.setAmount(new BigDecimal("0.000000"));
-            }
-        });
-        //计算占比
-        if (CollectionUtils.isEmpty(listVo)) {
-            return;
-        }
-
-        List<HospProfitAndLossVo> listSum = new ArrayList<>();
-
-        //把所有数据按报表项目汇总
-        for (ReportForm j : reportForms) {
-            HospProfitAndLossVo hospProfitAndLossVo = new HospProfitAndLossVo();
-            hospProfitAndLossVo.setDateYear(finalYear);
-            hospProfitAndLossVo.setDateMonth(finalMonth);
-            hospProfitAndLossVo.setReportNum(j.getNum());
-            hospProfitAndLossVo.setReportName(j.getReportName());
-            hospProfitAndLossVo.setCostType(NumberConstant.ZERO);
-            hospProfitAndLossVo.setIncomeType(NumberConstant.ZERO);
-            hospProfitAndLossVo.setHospId(hospId);
-            hospProfitAndLossVo.setType(j.getCostType());
-            hospProfitAndLossVo.setFraction(j.getFraction());
-            hospProfitAndLossVo.setReportId(j.getId());
-            hospProfitAndLossVo.setReportNum(j.getNum());
-            hospProfitAndLossVo.setCalcType(j.getCalcType());
-            hospProfitAndLossVo.setReportName(j.getReportName());
-            hospProfitAndLossVo.setCalcFormula(j.getCalcFormula());
-            hospProfitAndLossVo.setReportParentId(j.getParentId());
-            listSum.add(hospProfitAndLossVo);
-        }
-        Map<Integer, List<HospProfitAndLossVo>> reportNumGroup = listVo.stream().collect(Collectors.groupingBy(HospProfitAndLossVo::getReportNum));
-        Map<Integer, BigDecimal> reportNumSumMap = new HashMap<>();
-        reportNumGroup.forEach((reportNum, hospProfitAndLossList) -> {
-            AtomicReference<BigDecimal> sum = new AtomicReference<>(new BigDecimal("0.000000"));
-            for (HospProfitAndLossVo hospProfitAndLoss : hospProfitAndLossList) {
-                if (hospProfitAndLoss.getAmount() != null) {
-                    sum.updateAndGet(f -> f.add(hospProfitAndLoss.getAmount()));
-                }
-            }
-            reportNumSumMap.put(reportNum, sum.get());
-        });
-
-        for (HospProfitAndLossVo costProfitVo : listSum) {
-            BigDecimal bigDecimal = reportNumSumMap.get(costProfitVo.getReportNum());
-            if (bigDecimal != null) {
-                costProfitVo.setAmount(bigDecimal);
-
-            } else {
-                costProfitVo.setAmount(BigDecimal.ZERO.setScale(6, RoundingMode.HALF_UP));
-            }
-        }
-        //单独计算计算公式数据
-        setCalculationAmount(listSum);
-        //收入
-        List<HospProfitAndLossVo> profitIncomeList = listSum.stream().filter(f -> f.getType().equals(NumberConstant.ONE)).collect(Collectors.toList());
-        List<HospProfitAndLossVo> profitIncome = costPercent(profitIncomeList);
-        //成本
-        List<HospProfitAndLossVo> profitCostList = listSum.stream().filter(f -> f.getType().equals(NumberConstant.TWO)).collect(Collectors.toList());
-
-        List<HospProfitAndLossVo> profitCost = costPercent(profitCostList);
-
-        //不计算项目
-        List<HospProfitAndLossVo> noCompute = listSum.stream().filter(f -> f.getFraction().equals(NumberConstant.THREE)).collect(Collectors.toList());
-        noCompute.forEach(profitVO -> profitVO.setPercent(null));
-
-        List<HospProfitAndLossVo> listAllVo = new ArrayList<>();
-
-        if (!CollectionUtils.isEmpty(profitIncome) && !CollectionUtils.isEmpty(profitCost) && !CollectionUtils.isEmpty(noCompute)) {
-            listAllVo.addAll(profitIncome);
-            listAllVo.addAll(profitCost);
-            listAllVo.addAll(noCompute);
-        } else if (!CollectionUtils.isEmpty(profitIncome) && !CollectionUtils.isEmpty(noCompute)) {
-            listAllVo.addAll(noCompute);
-            listAllVo.addAll(profitIncome);
-
-        } else if (!CollectionUtils.isEmpty(profitCost) && !CollectionUtils.isEmpty(noCompute)) {
-            listAllVo.addAll(noCompute);
-            listAllVo.addAll(profitCost);
-        } else if (!CollectionUtils.isEmpty(noCompute)) {
-            listAllVo.addAll(noCompute);
-        }
-
-        List<HospProfitAndLoss> list = BeanUtil.convertList(listAllVo, HospProfitAndLoss.class);
-        // 处理医院其他收支
-        List<CostOtherPaymentsData> otherPaymentsDatas = otherPaymentsDataService.getByMonth(year, month, hospId);
-        if (!otherPaymentsDatas.isEmpty()) {
-            otherPaymentsDatas.forEach(ele -> {
-                HospProfitAndLoss loss = new HospProfitAndLoss();
-                loss.setDateYear(year).setDateMonth(month).setReportName(ele.getPaymentsName()).setReportNum((int) (-ele.getId()))
-                        .setCreateTime(System.currentTimeMillis()).setAmount(ele.getTotalAmount()).setHospId(hospId)
-                        .setResponsibilityName("全院").setResponsibilityCode("-1").setPercent(null);
-                list.add(loss);
-            });
-        }
-        long l = System.currentTimeMillis();
-        list.forEach(i -> {
-            i.setCreateTime(l);
-        });
-        this.saveBatch(list);
+        calcHospProfit(date,hospId,ReportTypeEnum.HOSP_PROFIT_LOSS.getType());
     }
 
     private void setCalculationAmount(List<HospProfitAndLossVo> listVo) {

+ 11 - 1
src/main/java/com/kcim/service/impl/ReportFormServiceImpl.java

@@ -517,9 +517,19 @@ public class ReportFormServiceImpl extends ServiceImpl<ReportFormMapper, ReportF
     @Override
     @Transactional(rollbackFor = Throwable.class,propagation = Propagation.REQUIRED)
     public void checkExistLoss(Long hospId) {
+        checkExistLoss(hospId,ReportTypeEnum.HOSP_PROFIT_LOSS.getType());
+    }
+
+    /**
+     * 校验指定类型的全院损益报表是否存在默认损益
+     * @param hospId
+     * @param reportType
+     */
+    @Override
+    public void checkExistLoss(Long hospId, Integer reportType) {
         List<ReportForm> list = this.list(
                 new LambdaQueryWrapper<ReportForm>()
-                        .eq(ReportForm::getReportType, ReportTypeEnum.HOSP_PROFIT_LOSS.getType())
+                        .eq(ReportForm::getReportType, reportType)
                         .eq(ReportForm::getHospId, hospId)
                         .eq(ReportForm::getIsLoss, 1)
         );

+ 8 - 0
src/main/java/com/kcim/web/HospProfitAndLossController.java

@@ -29,6 +29,14 @@ public class HospProfitAndLossController extends AbstractController {
         return Result.ok();
     }
 
+    @ApiOperation("计算指定类型报表的全院损益")
+    @PostMapping("/calcHospProfit")
+    public Result calcHospProfit(@RequestParam @ApiParam(name = "date", value = "yyyy-MM-dd") String date,@RequestParam Integer reportType) {
+//        hospProfitAndLossService.calc(date, getHospId());
+        hospProfitAndLossService.calcHospProfit(date, getHospId(),reportType);
+        return Result.ok();
+    }
+
     @ApiOperation("全院损益列表")
     @GetMapping("/getHospProfits")
     public Result getHospProfits(@RequestParam(value = "current", defaultValue = "1") Integer current,