Browse Source

添加医院科室成本分摊汇总表相关代码

JammeyJiang 3 months ago
parent
commit
cb9644df7e

+ 9 - 4
src/main/java/com/kcim/service/StandardReportService.java

@@ -1,9 +1,6 @@
 package com.kcim.service;
 
-import com.kcim.vo.ClinicalDeptFullCostVO;
-import com.kcim.vo.DeptFullDirectCostVO;
-import com.kcim.vo.ClinicalDeptMedicalCostVO;
-import com.kcim.vo.DeptDirectMedicalCostVO;
+import com.kcim.vo.*;
 import com.kcim.web.reponse.ComputeProfitCollectResponse;
 
 import java.util.List;
@@ -42,4 +39,12 @@ public interface StandardReportService {
      * @return 报表数据
      */
     ComputeProfitCollectResponse getClinicalDeptFullCostAnalysis(String computeDate);
+
+    /**
+     * 获取医院科室成本分摊汇总表数据
+     * @param computeDate 核算年月
+     * @return 报表数据
+     */
+    List<HospitalDeptCostAllocationVO> getHospitalDeptCostAllocation(String computeDate) ;
+
 }

+ 154 - 4
src/main/java/com/kcim/service/impl/StandardReportServiceImpl.java

@@ -18,6 +18,7 @@ import com.kcim.service.CenterService;
 import com.kcim.service.IncomeCollectionService;
 import com.kcim.service.StandardReportService;
 import com.kcim.vo.*;
+import com.kcim.vo.HospitalDeptCostAllocationVO;
 import com.kcim.web.reponse.ComputeProfitCollectResponse;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -535,7 +536,7 @@ public class StandardReportServiceImpl implements StandardReportService {
      * @param standCostDictMaps
      */
     private void addClinicalDeptFullCostVO(Map<String, ClinicalDeptFullCostVO> reportMap, AllocationQuery allocationQuery, StandCostDictMapVO standCostDictMaps) {
-        String responsibilityCode = allocationQuery.getResponsibilityCode();
+        String responsibilityCode = allocationQuery.getTargetResponsibilityCode();
         Responsibility responsibility = standCostDictMaps.getResponsibilityMap().get(responsibilityCode);
         if (responsibility == null) {
             return; // 添加 null 检查
@@ -636,7 +637,7 @@ public class StandardReportServiceImpl implements StandardReportService {
      * @param standCostDictMaps
      */
     private void addDeptCostDetailVO(Map<String, ClinicalDeptMedicalCostVO> reportMap, AllocationQuery allocationQuery, StandCostDictMapVO standCostDictMaps) {
-        String responsibilityCode = allocationQuery.getResponsibilityCode();
+        String responsibilityCode = allocationQuery.getTargetResponsibilityCode();
         Responsibility responsibility = standCostDictMaps.getResponsibilityMap().get(responsibilityCode);
         if (responsibility == null) {
             return; // 添加 null 检查
@@ -843,7 +844,7 @@ public class StandardReportServiceImpl implements StandardReportService {
     public void addDeptDirectMedicalCostVO(Map<String ,DeptDirectMedicalCostVO> deptDirectMedicalCostMap,
                                            AllocationQuery allocationQuery,
                                            StandCostDictMapVO standCostDictMaps) {
-        String responsibilityCode = allocationQuery.getResponsibilityCode();
+        String responsibilityCode = allocationQuery.getTargetResponsibilityCode();
         Responsibility responsibility = standCostDictMaps.getResponsibilityMap().get(responsibilityCode);
         if (responsibility == null) {
             return; // 添加 null 检查
@@ -910,7 +911,7 @@ public class StandardReportServiceImpl implements StandardReportService {
      * @param standCostDictMaps
      */
     private void addDeptDirectAllCostVO(Map<String, DeptFullDirectCostVO> reportMap, AllocationQuery allocationQuery, StandCostDictMapVO standCostDictMaps) {
-        String responsibilityCode = allocationQuery.getResponsibilityCode();
+        String responsibilityCode = allocationQuery.getTargetResponsibilityCode();
         Responsibility responsibility = standCostDictMaps.getResponsibilityMap().get(responsibilityCode);
         if (responsibility == null) {
             return; // 添加 null 检查
@@ -1050,4 +1051,153 @@ public class StandardReportServiceImpl implements StandardReportService {
         return split;
     }
 
+    /**
+     * 获取医院科室成本分摊汇总表数据
+     * @param computeDate 核算年月
+     * @return 报表数据
+     */
+    @Override
+    public List<HospitalDeptCostAllocationVO> getHospitalDeptCostAllocation(String computeDate) {
+        DateTime parse = DateUtil.parse(computeDate);
+        int year = DateUtil.year(parse);
+        int month = DateUtil.month(parse) + 1;
+
+        // 获取科室成本
+        List<AllocationQuery> allocationQueryList = allocationQueryService.getAllByDate(UserContext.getCurrentLoginHospId(), year, month);
+        if (CollectionUtils.isEmpty(allocationQueryList)) {
+            throw new CostException("医院未分摊本月数据");
+        }
+
+        // 获取所有的标准字典数据
+        StandCostDictMapVO standCostDictMaps = getStandCostDictMaps();
+
+        // 处理 allocationQueryList 数据
+        Map<String, HospitalDeptCostAllocationVO> deptCostAllocationMap = new HashMap<>();
+
+        // 转换为HospitalDeptCostAllocationVO(一个责任中心只一条记录)
+        for (AllocationQuery allocationQuery : allocationQueryList) {
+            addHospitalDeptCostAllocationVO(deptCostAllocationMap, allocationQuery, standCostDictMaps);
+        }
+
+        // 转成List便于处理
+        List<HospitalDeptCostAllocationVO> reportList = new ArrayList<>(deptCostAllocationMap.values());
+        //创建总计
+        HospitalDeptCostAllocationVO grandTotal = createSubtotalVo(reportList.get(NumberConstant.ZERO), "总计", HospitalDeptCostAllocationVO.class);
+        // 按responsibilitySort正序排序
+        reportList.sort(Comparator.comparing(HospitalDeptCostAllocationVO::getResponsibilitySort,
+                Comparator.nullsLast(Comparator.naturalOrder())));
+
+        // 按标准分级分组
+        Map<String, List<HospitalDeptCostAllocationVO>> shareLevelGroup = reportList.stream()
+                .collect(Collectors.groupingBy(HospitalDeptCostAllocationVO::getStandardShareLevel));
+
+        // 科室标准分级按顺序号倒序排序
+        List<DictDataVo> standardShareLevelList = standCostDictMaps.getStandardShareLevelDict();
+        standardShareLevelList.sort(Comparator.comparing(DictDataVo::getSort, Comparator.nullsLast(Comparator.reverseOrder())));
+
+        // 创建各层级小计并按正确顺序插入
+        List<HospitalDeptCostAllocationVO> result = new ArrayList<>();
+        for (DictDataVo shareLevel : standardShareLevelList) {
+            List<HospitalDeptCostAllocationVO> deptCostAllocationVOS = shareLevelGroup.get(shareLevel.getCode());
+            if (CollectionUtils.isEmpty(deptCostAllocationVOS)) {
+                continue;
+            }
+            // 添加该分类下的所有记录
+            result.addAll(deptCostAllocationVOS);
+            // 创建小计对象
+            HospitalDeptCostAllocationVO subtotalVo = createSubtotalVo(deptCostAllocationVOS.get(NumberConstant.ZERO), String.format("%s小计", shareLevel.getName()), HospitalDeptCostAllocationVO.class);
+            //将科室的金额加到小计对象中
+            deptCostAllocationVOS.forEach(item -> addBigDecimalFields(item, subtotalVo));
+            // 小计的金额加到总计
+            addBigDecimalFields(subtotalVo, grandTotal);
+            // 添加小计行
+            result.add(subtotalVo);
+        }
+        // 总计加到列表最后面
+        result.add(grandTotal);
+        return result;
+    }
+
+    /**
+     * 添加医院科室成本分摊数据
+     * @param deptCostAllocationMap 科室成本分摊Map
+     * @param allocationQuery 分摊查询对象
+     * @param standCostDictMaps 标准字典数据
+     */
+    private void addHospitalDeptCostAllocationVO(Map<String, HospitalDeptCostAllocationVO> deptCostAllocationMap,
+                                                 AllocationQuery allocationQuery,
+                                                 StandCostDictMapVO standCostDictMaps) {
+        String responsibilityCode = allocationQuery.getTargetResponsibilityCode();
+        String sourceResponsibilityCode = allocationQuery.getResponsibilityCode();
+        Responsibility responsibility = standCostDictMaps.getResponsibilityMap().get(responsibilityCode);
+        if (responsibility == null) {
+            return;
+        }
+
+        Responsibility sourceResponsibility = standCostDictMaps.getResponsibilityMap().get(sourceResponsibilityCode);
+        if (sourceResponsibility == null) {
+            return;
+        }
+
+        String accountingCode = allocationQuery.getAccountingCode();
+        Accounting account = standCostDictMaps.getAccountingMap().get(accountingCode);
+        if (account == null) {
+            return;
+        }
+
+        DictDataVo accountType = standCostDictMaps.getAccountingTypeMap().get(account.getType());
+        if (accountType == null) {
+            return;
+        }
+
+        HospitalDeptCostAllocationVO costAllocationVO = new HospitalDeptCostAllocationVO();
+        if (deptCostAllocationMap.containsKey(responsibilityCode)) {
+            costAllocationVO = deptCostAllocationMap.get(responsibilityCode);
+        } else {
+            // 初始化VO对象
+            costAllocationVO.setResponsibilityName(responsibility.getResponsibilityName());
+            costAllocationVO.setResponsibilityCode(responsibility.getResponsibilityCode());
+            costAllocationVO.setResponsibilitySort(responsibility.getSort());
+            costAllocationVO.setStandardShareLevel(responsibility.getStandardShareLevel());
+
+            // 初始化所有费用字段为0
+            BeanUtil.initBigDecimalFieldsToZero(costAllocationVO);
+        }
+
+        // 直接成本
+        if (NumberConstant.ONE.equals(allocationQuery.getOriginType().intValue())) {
+            costAllocationVO.setDirectCost(
+                    (costAllocationVO.getDirectCost() == null ? BigDecimal.ZERO : costAllocationVO.getDirectCost())
+                            .add(allocationQuery.getAmount()));
+        }else{
+            switch (sourceResponsibility.getStandardShareLevel())
+            {
+                case "1":
+                    // 行政后勤类科室成本
+                    costAllocationVO.setAllocatedAdminCost(
+                            (costAllocationVO.getAllocatedAdminCost() == null ? BigDecimal.ZERO : costAllocationVO.getAllocatedAdminCost())
+                                    .add(allocationQuery.getAmount()));
+                case "2":
+                    // 辅助支持类科室成本
+                    costAllocationVO.setAllocatedSupportCost(
+                            (costAllocationVO.getAllocatedSupportCost() == null ? BigDecimal.ZERO : costAllocationVO.getAllocatedSupportCost())
+                                    .add(allocationQuery.getAmount()));
+                case "3":
+                    // 技术类科室成本
+                    costAllocationVO.setAllocatedTechCost(
+                            (costAllocationVO.getAllocatedTechCost() == null ? BigDecimal.ZERO : costAllocationVO.getAllocatedTechCost())
+                                    .add(allocationQuery.getAmount()));
+                break;
+            }
+            //小计
+            costAllocationVO.setSubtotal(
+                    (costAllocationVO.getSubtotal() == null ? BigDecimal.ZERO : costAllocationVO.getSubtotal())
+                            .add(allocationQuery.getAmount()));
+        }
+        // 医疗类科室成本
+        costAllocationVO.setMedicalCost(
+                (costAllocationVO.getMedicalCost() == null ? BigDecimal.ZERO : costAllocationVO.getMedicalCost())
+                        .add(allocationQuery.getAmount()));
+        deptCostAllocationMap.put(responsibilityCode, costAllocationVO);
+    }
 }

+ 42 - 0
src/main/java/com/kcim/vo/HospitalDeptCostAllocationVO.java

@@ -0,0 +1,42 @@
+package com.kcim.vo;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+/**
+ * 医院科室成本分摊汇总表VO
+ */
+@Data
+public class HospitalDeptCostAllocationVO extends BaseDeptCostReportVO {
+
+    /**
+     * 医疗成本
+     */
+    private BigDecimal medicalCost;
+
+    /**
+     * 直接成本
+     */
+    private BigDecimal directCost;
+
+    /**
+     * 小计
+     */
+    private BigDecimal subtotal;
+
+    /**
+     * 分摊行政后勤类科室成本
+     */
+    private BigDecimal allocatedAdminCost;
+
+    /**
+     * 分摊医疗辅助类科室成本
+     */
+    private BigDecimal allocatedSupportCost;
+
+    /**
+     * 分摊医疗技术类科室成本
+     */
+    private BigDecimal allocatedTechCost;
+}

+ 6 - 0
src/main/java/com/kcim/web/StandardReportController.java

@@ -51,4 +51,10 @@ public class StandardReportController extends AbstractController {
     public Result getClinicalDeptFullCostAnalysis(@RequestParam String computeDate) {
         return Result.ok(standardReportService.getClinicalDeptFullCostAnalysis(computeDate));
     }
+
+    @ApiOperation("获取医院科室成本分摊汇总表")
+    @GetMapping("/getHospitalDeptCostAllocation")
+    public Result getHospitalDeptCostAllocation(@RequestParam String computeDate) {
+        return Result.ok(standardReportService.getHospitalDeptCostAllocation(computeDate));
+    }
 }