Ver código fonte

添加多月份的全院其他收支的填充逻辑

JammeyJiang 3 meses atrás
pai
commit
94da3e696b

+ 1 - 0
src/main/java/com/kcim/service/impl/ComputeMedicalDepartmentProfitServiceImpl.java

@@ -380,6 +380,7 @@ public class ComputeMedicalDepartmentProfitServiceImpl implements ComputeMedical
         //通过查询的最下层责任中心 找到其所有父类责任中心
         List<MedicalResponsibilityVo> parentResponseList = new ArrayList<>();
         for (MedicalResponsibilityVo responsibility : computeResponsibityList) {
+            log.info(String.format("查询责任中心{%s}的父级ID{%s}", responsibility.getResponsibilityCode(),responsibility.getParentId()));
             if (responsibility.getParentId().equals(NumberConstant.ZERO_L)) {
                 parentResponseList.add(responsibility);
             } else {

+ 56 - 6
src/main/java/com/kcim/service/impl/HospProfitAndLossServiceImpl.java

@@ -1582,9 +1582,7 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
         for (Map.Entry<String, List<HospProfitAndLoss>> entry : groupedByYearMonth.entrySet()){
             List<HospProfitAndLoss> hospProfitAndLossList = entry.getValue();
             //转换成成本损益数据
-            List<CostProfitVo> costProfitVos = convertToCostProfitVoList(hospProfitAndLossList, reportFormList);
-            //记录所有月份的损益数据
-            allCostProfitVo.addAll(costProfitVos);
+            List<CostProfitVo> costProfitVos = convertToCostProfitVoList(hospProfitAndLossList, reportFormList,allCostProfitVo);
             //生成出参样式
             BatchCostProfitResponse response = new BatchCostProfitResponse();
             //第13月为审计月份
@@ -1606,6 +1604,8 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
         if(!beginComputeDate.equals(endComputeDate)){
             //获取月度汇总数据
             List<CostProfitVo> costProfitVos = generateSummaryForMultipleMonths(allCostProfitVo);
+            //填充全院其他收支
+            fillHopsOhterProfit(costProfitVos,responses);
             if(!CollectionUtils.isEmpty(costProfitVos)){
                 BatchCostProfitResponse response = new BatchCostProfitResponse();
                 response.setComputeDate(String.format("%s至%s", beginComputeDate, endComputeDate));
@@ -1620,6 +1620,48 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
         return responses;
     }
 
+    /**
+     * 填充全院其他收支
+     * @param multipleMonthsProfitVos
+     * @param responses
+     */
+    public void fillHopsOhterProfit(List<CostProfitVo> multipleMonthsProfitVos,List<BatchCostProfitResponse> responses) {
+        //获取累计月全院其他收支节点
+        Optional<CostProfitVo> firstHopsOhterProfit = multipleMonthsProfitVos.stream().filter(costProfitVo -> costProfitVo.getReportId().equals(-1L)).findFirst();
+        if(!firstHopsOhterProfit.isPresent()||CollectionUtils.isEmpty(firstHopsOhterProfit.get().getChildren())){
+            return;
+        }
+        CostProfitVo standCostProfitVo = firstHopsOhterProfit.get();
+        for (BatchCostProfitResponse response : responses) {
+            //获取月度的全院其他收支节点
+            Optional<CostProfitVo> firstOhterProfit = response.getProfitVoList().stream().filter(costProfitVo -> costProfitVo.getReportId().equals(-1L)).findFirst();
+            //没有全院其他收支的添加一个空数据的全院其他收支
+            if(!firstOhterProfit.isPresent()||CollectionUtils.isEmpty(firstOhterProfit.get().getChildren())){
+                CostProfitVo costProfitVo = BeanUtil.convertObj(standCostProfitVo, CostProfitVo.class);
+                costProfitVo.setChildren(new ArrayList<>());
+                //添加缺失的全院其他收支项目到月度数据中
+                for (CostProfitVo missChildCostProfitVo : standCostProfitVo.getChildren()) {
+                    CostProfitVo newCostProfitVo = BeanUtil.convertObj(missChildCostProfitVo, CostProfitVo.class);
+                    combineReportAndProfitAmount(newCostProfitVo,null);
+                    costProfitVo.getChildren().add(newCostProfitVo);
+                }
+                response.getProfitVoList().add(costProfitVo);
+                continue;
+            }
+            //找出月度缺失的全院其他收支
+            List<CostProfitVo> missChilds = standCostProfitVo.getChildren().stream().filter(standChildCostProfitVo -> !firstOhterProfit.get().getChildren().stream().anyMatch(childCostProfitVo -> standChildCostProfitVo.getReportId().equals(childCostProfitVo.getReportId()))).collect(Collectors.toList());
+            if(CollectionUtils.isEmpty(missChilds)){
+                continue;
+            }
+            //添加缺失的全院其他收支项目到月度数据中
+            for (CostProfitVo missChildCostProfitVo : missChilds) {
+                CostProfitVo costProfitVo = BeanUtil.convertObj(missChildCostProfitVo, CostProfitVo.class);
+                combineReportAndProfitAmount(costProfitVo,null);
+                firstOhterProfit.get().getChildren().add(costProfitVo);
+            }
+        }
+    }
+
     /**
      * 生成多月份汇总的科室损益数据
      *
@@ -1648,6 +1690,7 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
                     .reduce(BigDecimal.ZERO, BigDecimal::add);
             BigDecimal totalSamePeriodAmount = profitVos.stream().map(vo -> Optional.ofNullable(vo.getSamePeriodAmount()).orElse(BigDecimal.ZERO))
                     .reduce(BigDecimal.ZERO, BigDecimal::add);
+            costProfitVo.setChildren(null);
             costProfitVo.setAmount(totalAmount);
             costProfitVo.setBudgetAmount(totalBudgetAmount);
             costProfitVo.setPrevPeriodAmount(totalPrevPeriodAmount);
@@ -1668,7 +1711,7 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
      * @param reportFormList
      * @return
      */
-    public  List<CostProfitVo> convertToCostProfitVoList(List<HospProfitAndLoss> hospProfitAndLossList,List<ReportForm> reportFormList ){
+    public  List<CostProfitVo> convertToCostProfitVoList(List<HospProfitAndLoss> hospProfitAndLossList,List<ReportForm> reportFormList,List<CostProfitVo> allCostProfitVo ){
         //全院其他收支项目
         List<HospProfitAndLoss> otherHospProfitAndLoss = hospProfitAndLossList.stream().filter(i -> NumberConstant.ONE.equals(i.getOriginType())).collect(Collectors.toList());
         //按报表项目编号map
@@ -1709,12 +1752,18 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
                 costProfitVo.setMonth(hospProfitAndLoss.getDateMonth());
                 //全院其他收支项目放在虚拟的全院其他收支下
                 costProfitVo.setSort(i);
-                costProfitVo.setReportNum(hospProfitAndLoss.getReportNum());
-                costProfitVo.setReportId(hospProfitAndLoss.getReportNum().longValue());
+                //添加一个负数作为虚拟的报表项目编号
+                Integer reportNum =hospProfitAndLoss.getReportNum();
+                costProfitVo.setReportNum(reportNum);
+                costProfitVo.setId(reportNum.longValue());
+                costProfitVo.setReportId(reportNum.longValue());
+                costProfitVo.setReportName(hospProfitAndLoss.getReportName());
                 costProfitVo.setReportParentId(otherProfit.getReportId());
                 costProfitVos.add(costProfitVo);
             }
         }
+        //记录所有月份的损益数据
+        allCostProfitVo.addAll(costProfitVos);
         //转成树状结构的损益数据
         List<CostProfitVo> costProfitVoTree = converToCostProfitVoTree(costProfitVos);
         return costProfitVoTree;
@@ -1744,6 +1793,7 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
      */
     public CostProfitVo reportFormToProfitVo(ReportForm reportForm){
         CostProfitVo profitVo = new CostProfitVo();
+        profitVo.setId(reportForm.getId());
         profitVo.setReportId(reportForm.getId());
         profitVo.setReportName(reportForm.getReportName());
         profitVo.setReportParentId(reportForm.getParentId());