Browse Source

添加医院诊次成本构成表相关代码

JammeyJiang 3 tháng trước cách đây
mục cha
commit
1b27380249

+ 26 - 0
src/main/java/com/kcim/dao/mapper/AllocationQueryMapper.java

@@ -30,4 +30,30 @@ public interface AllocationQueryMapper extends BaseMapper<AllocationQuery> {
 
     BigDecimal getTotalByAccountAndRespCode(@Param("hospId") Long hospId, @Param("dateYear") int dateYear, @Param("month") int month, @Param("accountCode") String accountCode, @Param("responsibilityCode") String responsibilityCode);
 
+    /**
+     * 获取医院所有会计科目成本
+     * @param hospId
+     * @param dateYear
+     * @param month
+     * @return
+     */
+    List<AllocationQuery> getAcountAccounts(@Param("hospId") Long hospId, @Param("dateYear") int dateYear, @Param("month") int month);
+
+    /**
+     * 获取医院各责任中心所有会计科目成本
+     * @param hospId
+     * @param dateYear
+     * @param month
+     * @return
+     */
+    List<AllocationQuery> getRespAcountAccounts(@Param("hospId") Long hospId, @Param("dateYear") int dateYear, @Param("month") int month);
+
+    /**
+     * 获取医院各责任中心不同来源类型的会计科目成本
+     * @param hospId
+     * @param dateYear
+     * @param month
+     * @return
+     */
+    List<AllocationQuery> getRespOriginAcountAccounts(@Param("hospId") Long hospId, @Param("dateYear") int dateYear, @Param("month") int month);
 }

+ 9 - 9
src/main/java/com/kcim/dao/model/AllocationQuery.java

@@ -97,14 +97,14 @@ public class AllocationQuery implements Serializable {
 
 	private Integer shareType;
 
-	/**
-	 * 标准科室分类(来自责任中心)
-	 */
-	private String standardShareLevel;
-
-	/**
-	 * 费用类型(来自会计科目字典)
-	 */
-	private String expandOne;
+//	/**
+//	 * 标准科室分类(来自责任中心)
+//	 */
+//	private String standardShareLevel;
+//
+//	/**
+//	 * 费用类型(来自会计科目字典)
+//	 */
+//	private String expandOne;
 
 }

+ 5 - 0
src/main/java/com/kcim/service/AllocationQueryService.java

@@ -53,6 +53,11 @@ public interface AllocationQueryService extends IService<AllocationQuery> {
 
     List<AllocationQuery> getByDateRespn(int year, int month, Long hospId, List<Long> shareLevelId, String responsibilityCode);
 
+    List<AllocationQuery> getAcountAccounts(Long hospId, int dateYear, int month);
+
+    List<AllocationQuery> getRespAcountAccounts(Long hospId, int dateYear, int month);
+
+    List<AllocationQuery> getRespOriginAcountAccounts(Long hospId, int dateYear, int month);
 
 
 }

+ 7 - 0
src/main/java/com/kcim/service/StandardReportService.java

@@ -47,4 +47,11 @@ public interface StandardReportService {
      */
     List<HospitalDeptCostAllocationVO> getHospitalDeptCostAllocation(String computeDate) ;
 
+    /**
+     * 获取医院诊次成本构成表数据
+     * @param computeDate 核算年月
+     * @return 报表数据
+     */
+    List<HospitalVisitCostCompositionVO> getHospitalVisitCostComposition(String computeDate);
+
 }

+ 15 - 0
src/main/java/com/kcim/service/impl/AllocationQueryServiceImpl.java

@@ -58,6 +58,21 @@ public class AllocationQueryServiceImpl extends ServiceImpl<AllocationQueryMappe
         return baseMapper.getTotalByAccountAndRespCode(hospId, dateYear, month, accountCode, responsibilityCode);
     }
 
+    @Override
+    public List<AllocationQuery> getAcountAccounts(Long hospId, int dateYear, int month) {
+        return baseMapper.getAcountAccounts(hospId, dateYear, month);
+    }
+
+    @Override
+    public List<AllocationQuery> getRespAcountAccounts(Long hospId, int dateYear, int month) {
+        return baseMapper.getRespAcountAccounts(hospId, dateYear, month);
+    }
+
+    @Override
+    public List<AllocationQuery> getRespOriginAcountAccounts(Long hospId, int dateYear, int month) {
+        return baseMapper.getRespOriginAcountAccounts(hospId, dateYear, month);
+    }
+
     /**
      * 获取这个月的分摊数据
      *

+ 130 - 15
src/main/java/com/kcim/service/impl/StandardReportServiceImpl.java

@@ -459,27 +459,21 @@ public class StandardReportServiceImpl implements StandardReportService {
         //计算科室的床日成本及诊次成本
         if(responsibilityParamValueMap.containsKey(item.getResponsibilityCode())){
             List<ShareParamValue> shareParamValues = responsibilityParamValueMap.get(item.getResponsibilityCode());
-            //获取诊次参数
-            Optional<ShareParamValue> firstVisitParam = shareParamValues.stream().filter(shareParamValue -> shareParamValue.getShareParamCode().equals(visitsBedDaysParamCode[0])).findFirst();
-            if(firstVisitParam.isPresent()){
-                // 计算诊次成本=总成本/诊次数
-                item.setVisitsCost(getPercent(item.getTotal(),firstVisitParam.get().getValueNum()));
-            }else{
-                item.setVisitsCost(BigDecimal.ZERO);
-            }
-            Optional<ShareParamValue> firstBedDayParam = shareParamValues.stream().filter(shareParamValue -> shareParamValue.getShareParamCode().equals(visitsBedDaysParamCode[1])).findFirst();
-            if(firstBedDayParam.isPresent()){
-                // 床日成本=总成本/床日数
-                item.setBedDaysCost(getPercent(item.getTotal(),firstBedDayParam.get().getValueNum()));
-            }else{
-                item.setBedDaysCost(BigDecimal.ZERO);
-            }
+
+            // 诊次分摊参数值
+            BigDecimal visitParamValue = getParamValue(shareParamValues, visitsBedDaysParamCode[NumberConstant.ZERO]);
+            // 床日分摊参数值
+            BigDecimal bedDaysParamValue = getParamValue(shareParamValues, visitsBedDaysParamCode[NumberConstant.ONE]);
+            // 计算诊次成本及床日成本
+            item.setVisitsCost(getPercent(item.getTotal(),visitParamValue));
+            item.setBedDaysCost(getPercent(item.getTotal(),bedDaysParamValue));
         }else{
             item.setBedDaysCost(BigDecimal.ZERO);
             item.setVisitsCost(BigDecimal.ZERO);
         }
     }
 
+
     /**
      * 获取百分比
      * @param amount
@@ -1118,6 +1112,89 @@ public class StandardReportServiceImpl implements StandardReportService {
         return result;
     }
 
+    /**
+     * 获取医院诊次成本构成表数据
+     * @param computeDate 核算年月
+     * @return 报表数据
+     */
+    @Override
+    public List<HospitalVisitCostCompositionVO> getHospitalVisitCostComposition(String computeDate) {
+        DateTime parse = DateUtil.parse(computeDate);
+        int year = DateUtil.year(parse);
+        int month = DateUtil.month(parse) + 1;
+
+        // 获取科室成本
+        List<AllocationQuery> allocationQueryList = allocationQueryService.getAcountAccounts(UserContext.getCurrentLoginHospId(), year, month);
+        if (CollectionUtils.isEmpty(allocationQueryList)) {
+            throw new CostException("医院未分摊本月数据");
+        }
+        //获取分摊参数
+        List<ShareParamValue> shareParamValueList = shareParamValueRepository.getList(computeDate);
+        if (CollectionUtils.isEmpty(shareParamValueList)) {
+            throw new CostException("未获取医院本月分摊参数数据");
+        }
+        // 获取所有的标准字典数据
+        StandCostDictMapVO standCostDictMaps = getStandCostDictMaps();
+        //获取成本会计科目字典
+        List<DictDataVo> accountingTypeDict = standCostDictMaps.getAccountingTypeDict();
+        List<DictDataVo> costAccountingTypeDict = accountingTypeDict.stream().filter(dictDataVo -> NumberConstant.TWO_S.equals(dictDataVo.getValue())).collect(Collectors.toList());
+        // 初始化成本项目映射
+        Map<String, HospitalVisitCostCompositionVO> costItemMap =createHospitalVisitCostCompositionVO(costAccountingTypeDict);
+        // 处理分配查询数据
+        for (AllocationQuery allocationQuery : allocationQueryList) {
+            String accountingCode = allocationQuery.getAccountingCode();
+            Accounting account = standCostDictMaps.getAccountingMap().get(accountingCode);
+            if (account == null) {
+                continue;
+            }
+            DictDataVo costType = standCostDictMaps.getCostTypeMap().get(account.getCostType());
+            HospitalVisitCostCompositionVO vo = costItemMap.get(account.getType());
+            // 医疗成本
+            if ("1".equals(costType.getExpandOne())) {
+                vo.setMedicalCost(vo.getMedicalCost().add(allocationQuery.getAmount()));
+            }
+            // 医疗全成本
+            if (!"3".equals(costType.getExpandOne())) {
+                vo.setMedicalFullCost(vo.getMedicalFullCost().add(allocationQuery.getAmount()));
+            }
+            // 医院全成本
+            vo.setHospitalFullCost(vo.getHospitalFullCost().add(allocationQuery.getAmount()));
+        }
+        //获取诊次床日分摊参数代码
+        String[] visitsBedDaysParamCode = getVisitsBedDaysParamCode();
+
+        // 诊次分摊参数值
+        BigDecimal visitParamValue = getParamValue(shareParamValueList, visitsBedDaysParamCode[NumberConstant.ZERO]);
+//        // 床日分摊参数值
+//        BigDecimal bedDaysParamValue = getParamValue(shareParamValueList, visitsBedDaysParamCode[NumberConstant.ONE]);
+
+        //处理总计和药品小计
+        HospitalVisitCostCompositionVO totalVo = new HospitalVisitCostCompositionVO();
+        totalVo.setCostItem("总计");
+        HospitalVisitCostCompositionVO drugTotalVo = new HospitalVisitCostCompositionVO();
+        totalVo.setCostItem("药品费");
+        // 转成List便于处理
+        List<HospitalVisitCostCompositionVO> reportList = costItemMap.values().stream().collect(Collectors.toList());
+        for (HospitalVisitCostCompositionVO item : reportList) {
+            //计算每诊次的医疗全成本
+            item.setHospitalFullCost(getPercent(visitParamValue,totalVo.getHospitalFullCost()));
+            //计算每诊次的医疗成本
+            item.setMedicalCost(getPercent(visitParamValue,totalVo.getMedicalCost()));
+            //计算每诊次的医院全成本
+            item.setHospitalFullCost(getPercent(visitParamValue,totalVo.getMedicalFullCost()));
+            // 将金额加到总计对象中
+            addBigDecimalFields(item, totalVo);
+            /// 将金额加到药品对象中
+            if(NumberConstant.THREE_S.equals(item.getCostType())){
+                addBigDecimalFields(item, drugTotalVo);
+            }
+        }
+        //添加到列表的指定位置
+        reportList.add(NumberConstant.TWO,drugTotalVo);
+        reportList.add(NumberConstant.ZERO,totalVo);
+        return reportList;
+    }
+
     /**
      * 添加医院科室成本分摊数据
      * @param deptCostAllocationMap 科室成本分摊Map
@@ -1200,4 +1277,42 @@ public class StandardReportServiceImpl implements StandardReportService {
                         .add(allocationQuery.getAmount()));
         deptCostAllocationMap.put(responsibilityCode, costAllocationVO);
     }
+
+
+    /**
+     * 获取指定分摊参数的数值
+     * @param shareParamValues
+     * @param paramCode
+     * @return
+     */
+    public BigDecimal getParamValue(List<ShareParamValue> shareParamValues, String paramCode){
+        BigDecimal sum = shareParamValues.stream()
+                .filter(shareParamValue -> shareParamValue.getShareParamCode().equals(paramCode))
+                .map(ShareParamValue::getValueNum)
+                .reduce(BigDecimal.ZERO, BigDecimal::add);
+        return sum;
+    }
+
+    /**
+     * 创建医院诊次成本构成表数据
+     * @param costAccountingTypeDict
+     * @return
+     */
+    public Map<String, HospitalVisitCostCompositionVO> createHospitalVisitCostCompositionVO(List<DictDataVo> costAccountingTypeDict) {
+        // 初始化成本项目映射
+        Map<String, HospitalVisitCostCompositionVO> costItemMap = new HashMap<>();
+        for (DictDataVo dictDataVo : costAccountingTypeDict) {
+            HospitalVisitCostCompositionVO vo = new HospitalVisitCostCompositionVO();
+            vo.setCostCode(dictDataVo.getCode());
+            vo.setCostItem(dictDataVo.getName());
+            vo.setCostType(dictDataVo.getExpandOne());
+            vo.setMedicalCost(BigDecimal.ZERO);
+            vo.setMedicalFullCost(BigDecimal.ZERO);
+            vo.setHospitalFullCost(BigDecimal.ZERO);
+            costItemMap.put(dictDataVo.getCode(), vo);
+        }
+        return costItemMap;
+    }
+
+
 }

+ 43 - 0
src/main/java/com/kcim/vo/HospitalVisitCostCompositionVO.java

@@ -0,0 +1,43 @@
+package com.kcim.vo;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+/**
+ * 医院科室成本分摊汇总表VO
+ * @author Administrator
+ */
+@Data
+public class HospitalVisitCostCompositionVO{
+
+    /**
+     * 成本项目代码
+     */
+    private String costCode;
+
+    /**
+     * 成本项目名称
+     */
+    private String costItem;
+
+    /**
+     * 成本项目类型
+     */
+    private String costType;
+
+    /**
+     * 每诊次医疗成本金额
+     */
+    private BigDecimal medicalCost;
+
+    /**
+     * 每诊次医疗全成本金额
+     */
+    private BigDecimal medicalFullCost;
+
+    /**
+     * 每诊次医院全成本金额
+     */
+    private BigDecimal hospitalFullCost;
+}

+ 17 - 0
src/main/java/com/kcim/vo/StandCostDictMapVO.java

@@ -16,10 +16,27 @@ import java.util.Map;
 @Data
 public class StandCostDictMapVO {
 
+    /**
+     * 责任中心字典
+     */
     private List<Responsibility> responsibilityDict;
+
+    /**
+     * 会计科目字典
+     */
     private List<Accounting> costAccountingDict ;
+
+    /**
+     * 会计科目类型字典
+     */
     private List<DictDataVo> accountingTypeDict;
+    /**
+     * 成本类型字典
+     */
     private List<DictDataVo> costTypeDict;
+    /**
+     * 标准分摊级别字典
+     */
     private List<DictDataVo> standardShareLevelDict;
 
     private Map<String, Responsibility> responsibilityMap;

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

@@ -57,4 +57,12 @@ public class StandardReportController extends AbstractController {
     public Result getHospitalDeptCostAllocation(@RequestParam String computeDate) {
         return Result.ok(standardReportService.getHospitalDeptCostAllocation(computeDate));
     }
+
+    @ApiOperation("获取医院诊次成本构成表")
+    @GetMapping("/getHospitalVisitCostComposition")
+    public Result getHospitalVisitCostComposition(@RequestParam String computeDate) {
+        return Result.ok(standardReportService.getHospitalVisitCostComposition(computeDate));
+    }
+
+
 }

+ 48 - 1
src/main/resources/mapper/AllocationQueryMapper.xml

@@ -86,5 +86,52 @@
           and delete_time = 0
     </select>
 
-
+    <select id="getAcountAccounts" resultType="com.kcim.dao.model.AllocationQuery">
+        SELECT
+            accounting_code,
+            IFNULL( sum( amount ), 0 ) AS amount
+        FROM
+            cost_allocation_query
+        WHERE
+            date_year = #{dateYear}
+          AND date_month = #{month}
+          AND hosp_id = #{hospId}
+          AND delete_time = 0
+        GROUP BY
+            accounting_code
+    </select>
+    <select id="getRespAcountAccounts" resultType="com.kcim.dao.model.AllocationQuery">
+        SELECT
+            responsibility_code,
+            accounting_code,
+            IFNULL( sum( amount ), 0 ) AS amount
+        FROM
+            cost_allocation_query
+        WHERE
+            date_year = #{dateYear}
+          AND date_month = #{month}
+          AND hosp_id = #{hospId}
+          AND delete_time = 0
+        GROUP BY
+            responsibility_code,
+            accounting_code
+    </select>
+    <select id="getRespOriginAcountAccounts" resultType="com.kcim.dao.model.AllocationQuery">
+        SELECT
+            responsibility_code,
+            origin_type,
+            accounting_code,
+            IFNULL( sum( amount ), 0 ) AS amount
+        FROM
+            cost_allocation_query
+        WHERE
+            date_year = #{dateYear}
+          AND date_month = #{month}
+          AND hosp_id = #{hospId}
+          AND delete_time = 0
+        GROUP BY
+            responsibility_code,
+            origin_type,
+            accounting_code
+    </select>
 </mapper>