|
|
@@ -9,9 +9,7 @@ import com.kcim.common.util.BeanUtil;
|
|
|
import com.kcim.common.util.ComputeDateUtils;
|
|
|
import com.kcim.common.util.UserContext;
|
|
|
import com.kcim.dao.model.*;
|
|
|
-import com.kcim.dao.repository.AccountingRepository;
|
|
|
-import com.kcim.dao.repository.ResponsibilityRepository;
|
|
|
-import com.kcim.dao.repository.ShareParamValueRepository;
|
|
|
+import com.kcim.dao.repository.*;
|
|
|
import com.kcim.service.AllocationQueryService;
|
|
|
import com.kcim.service.CenterService;
|
|
|
import com.kcim.service.IncomeCollectionService;
|
|
|
@@ -22,6 +20,7 @@ import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
@@ -54,6 +53,11 @@ public class StandardReportServiceImpl implements StandardReportService {
|
|
|
IncomeCollectionService incomeCollectionService;
|
|
|
|
|
|
ShareParamValueRepository shareParamValueRepository;
|
|
|
+
|
|
|
+ StandItemRepository standItemRepository;
|
|
|
+ ItemRepository itemRepository;
|
|
|
+
|
|
|
+ ComputeProjectCostAccountRepository computeProjectCostAccountRepository;
|
|
|
|
|
|
/**
|
|
|
* 科室直接成本表(医疗成本)
|
|
|
@@ -793,6 +797,196 @@ public class StandardReportServiceImpl implements StandardReportService {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取医院医疗服务项目成本汇总表数据
|
|
|
+ * @param computeDate 核算年月
|
|
|
+ * @return 报表数据
|
|
|
+ */
|
|
|
+// @Override
|
|
|
+ public List<HospitalServiceProjectCostVO> getHospitalServiceProjectCost(String computeDate) {
|
|
|
+ Integer year = ComputeDateUtils.getComputeYear(computeDate);
|
|
|
+ Integer month = ComputeDateUtils.getComputeMonth(computeDate);
|
|
|
+
|
|
|
+ List<StandItem> standItemList = standItemRepository.getList();
|
|
|
+ if(CollectionUtils.isEmpty(standItemList)){
|
|
|
+ throw new CostException("标准医疗服务项目未维护,请先添加标准医疗服务项目");
|
|
|
+ }
|
|
|
+ List<Item> itemList = itemRepository.getList();
|
|
|
+ if(CollectionUtils.isEmpty(itemList)){
|
|
|
+ throw new CostException("医疗服务项目未维护,请先添加医疗服务项目");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ComputeProjectCostAccount> projectCostAccountList = computeProjectCostAccountRepository.getList(computeDate);
|
|
|
+ if(CollectionUtils.isEmpty(projectCostAccountList)){
|
|
|
+ throw new CostException("医疗服务项目未维护,请先添加医疗服务项目");
|
|
|
+ }
|
|
|
+ // 获取所有的标准字典数据
|
|
|
+ StandCostDictMapVO standCostDictMaps = getStandCostDictMaps();
|
|
|
+
|
|
|
+ List<Map<String, StandItem>> standItemMapDict = getStandItemMapDict(standItemList);
|
|
|
+ // 记录项目类别对象
|
|
|
+ Map<String, HospitalServiceProjectCostVO> projectCostMap = new HashMap<>();
|
|
|
+ for (ComputeProjectCostAccount projectCostAccount : projectCostAccountList) {
|
|
|
+ // 获取项目归属的项目类型
|
|
|
+ StandItem projectItemType = getProjectItemType(projectCostAccount.getStandItemCode(),standItemMapDict);
|
|
|
+ if(ObjectUtils.isEmpty(projectItemType)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //按项目类型累加数据
|
|
|
+ DictDataVo costType = standCostDictMaps.getCostTypeMap().get(projectCostAccount.getCostType());
|
|
|
+ HospitalServiceProjectCostVO vo = new HospitalServiceProjectCostVO();
|
|
|
+ //已有的项目类别
|
|
|
+ if (projectCostMap.containsKey(projectItemType.getCode())) {
|
|
|
+ vo = projectCostMap.get(projectItemType.getCode());
|
|
|
+ } else {
|
|
|
+ //新建一个项目类别对象
|
|
|
+ convertToHospitalServiceProjectCostVO(projectItemType);
|
|
|
+ }
|
|
|
+ // 医疗成本
|
|
|
+ if ("1".equals(costType.getExpandOne())) {
|
|
|
+ vo.setMedicalCost(vo.getMedicalCost().add(projectCostAccount.getComputeResult()));
|
|
|
+ }
|
|
|
+ // 医疗全成本
|
|
|
+ if (!"3".equals(costType.getExpandOne())) {
|
|
|
+ vo.setMedicalFullCost(vo.getMedicalFullCost().add(projectCostAccount.getComputeResult()));
|
|
|
+ }
|
|
|
+ // 医院全成本
|
|
|
+ vo.setHospitalFullCost(vo.getHospitalFullCost().add(projectCostAccount.getComputeResult()));
|
|
|
+ }
|
|
|
+ // 创建项目类别对象并组装层级
|
|
|
+ List<HospitalServiceProjectCostVO> reportList = createProjectCategory(standItemMapDict,projectCostMap);
|
|
|
+ return reportList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取项目归属的项目类型
|
|
|
+ * @param standItemCode
|
|
|
+ * @param standItemMapDict
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public StandItem getProjectItemType(String standItemCode,List<Map<String, StandItem>> standItemMapDict) {
|
|
|
+ //不在完整字典里 返回null
|
|
|
+ if(!standItemMapDict.get(NumberConstant.ZERO).containsKey(standItemCode)){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ //第一层的项目
|
|
|
+ if(standItemMapDict.get(NumberConstant.ONE).containsKey(standItemCode)){
|
|
|
+ return standItemMapDict.get(NumberConstant.ONE).get(standItemCode);
|
|
|
+ }
|
|
|
+ //第二层的项目
|
|
|
+ if(standItemMapDict.get(NumberConstant.TWO).containsKey(standItemCode)){
|
|
|
+ return standItemMapDict.get(NumberConstant.TWO).get(standItemCode);
|
|
|
+ }
|
|
|
+ //其他层的项目需要递归找到所属的第二层
|
|
|
+ StandItem standItem = standItemMapDict.get(NumberConstant.ZERO).get(standItemCode);
|
|
|
+ return getProjectItemType(standItem.getParentCode(),standItemMapDict);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成完整字典、第一层、第二层的code映射字典
|
|
|
+ * @param standItemList
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<Map<String,StandItem>> getStandItemMapDict(List<StandItem> standItemList) {
|
|
|
+ List<Map<String,StandItem>> mapList=new ArrayList<>();
|
|
|
+ if(CollectionUtils.isEmpty(standItemList)){
|
|
|
+ Map<String,StandItem> map = new HashMap<>();
|
|
|
+ Map<String,StandItem> firstMap = new HashMap<>();
|
|
|
+ Map<String,StandItem> secondMap = new HashMap<>();
|
|
|
+ mapList.add(map);
|
|
|
+ mapList.add(firstMap);
|
|
|
+ mapList.add(secondMap);
|
|
|
+ return mapList;
|
|
|
+ }
|
|
|
+ // 构建完整字典code到StandItem的映射
|
|
|
+ Map<String, StandItem> standItemMap = standItemList.stream()
|
|
|
+ .collect(Collectors.toMap(StandItem::getCode, item -> item));
|
|
|
+ mapList.add(standItemMap);
|
|
|
+ List<StandItem> firstLevel = standItemList.stream().filter(item -> NumberConstant.ZERO_S.equals(item.getParentCode())).collect(Collectors.toList());
|
|
|
+ if(CollectionUtils.isEmpty(firstLevel)){
|
|
|
+ Map<String,StandItem> firstMap = new HashMap<>();
|
|
|
+ Map<String,StandItem> secondMap = new HashMap<>();
|
|
|
+ mapList.add(firstMap);
|
|
|
+ mapList.add(secondMap);
|
|
|
+ return mapList;
|
|
|
+ }
|
|
|
+ // 构建第一层code到StandItem的映射
|
|
|
+ Map<String, StandItem> firstLevelMap = firstLevel.stream()
|
|
|
+ .collect(Collectors.toMap(StandItem::getCode, item -> item));
|
|
|
+ mapList.add(firstLevelMap);
|
|
|
+ List<StandItem> secondLevel= standItemList.stream().filter(item -> firstLevelMap.containsKey(item.getParentCode())).collect(Collectors.toList());
|
|
|
+ if(CollectionUtils.isEmpty(secondLevel)){
|
|
|
+ Map<String,StandItem> secondMap = new HashMap<>();
|
|
|
+ mapList.add(secondMap);
|
|
|
+ return mapList;
|
|
|
+ }
|
|
|
+ // 构建第二层code到StandItem的映射
|
|
|
+ Map<String, StandItem> secondLevelMap = secondLevel.stream()
|
|
|
+ .collect(Collectors.toMap(StandItem::getCode, item -> item));
|
|
|
+ mapList.add(secondLevelMap);
|
|
|
+ return mapList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据标准项目字典创建项目类别
|
|
|
+ * @param standItemMapDict 标准项目字典
|
|
|
+ * @return 项目类别
|
|
|
+ */
|
|
|
+ private List<HospitalServiceProjectCostVO> createProjectCategory(List<Map<String, StandItem>> standItemMapDict,Map<String, HospitalServiceProjectCostVO> projectCostMap ) {
|
|
|
+ if(CollectionUtils.isEmpty(standItemMapDict.get(NumberConstant.ONE))){
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ List<StandItem> sencodLevel=new ArrayList<>(standItemMapDict.get(NumberConstant.TWO).values());
|
|
|
+ List<StandItem> firstLevel =new ArrayList<>(standItemMapDict.get(NumberConstant.ONE).values());
|
|
|
+ //按序号排序
|
|
|
+ firstLevel.sort(Comparator.comparing(StandItem::getSort));
|
|
|
+ List<HospitalServiceProjectCostVO> hospitalServiceProjectCostVOS =firstLevel.stream().map( item->convertToHospitalServiceProjectCostVO(item)).collect(Collectors.toList());
|
|
|
+ for (HospitalServiceProjectCostVO item : hospitalServiceProjectCostVOS) {
|
|
|
+ //先加自己的
|
|
|
+ if(projectCostMap.containsKey(item.getCostCode())){
|
|
|
+ addBigDecimalFields(projectCostMap.get(item.getCostCode()), item);
|
|
|
+ }
|
|
|
+ if(CollectionUtils.isEmpty(sencodLevel)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //第一层对应的第二层数据
|
|
|
+ List<StandItem> children = sencodLevel.stream().filter(child -> item.getCostCode().equals(child.getParentCode())).collect(Collectors.toList());
|
|
|
+ if(CollectionUtils.isEmpty( children)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //按序号排序
|
|
|
+ children.sort(Comparator.comparing(StandItem::getSort));
|
|
|
+ item.setChildren(new ArrayList<>());
|
|
|
+ for (StandItem child : children) {
|
|
|
+ HospitalServiceProjectCostVO childProject ;
|
|
|
+ //优先取已有的数据
|
|
|
+ if(projectCostMap.containsKey(child.getCode())){
|
|
|
+ childProject=projectCostMap.get(child.getCode());
|
|
|
+ }else{
|
|
|
+ childProject = convertToHospitalServiceProjectCostVO(child);
|
|
|
+ }
|
|
|
+ //加给第一层
|
|
|
+ addBigDecimalFields(childProject, item);
|
|
|
+ item.getChildren().add(childProject);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return hospitalServiceProjectCostVOS;
|
|
|
+ }
|
|
|
+
|
|
|
+ public HospitalServiceProjectCostVO convertToHospitalServiceProjectCostVO(StandItem standItem){
|
|
|
+ HospitalServiceProjectCostVO vo = new HospitalServiceProjectCostVO();
|
|
|
+ vo.setCostCode(standItem.getCode());
|
|
|
+ vo.setCostItem(standItem.getName());
|
|
|
+ // 初始化所有费用字段为0
|
|
|
+ BeanUtil.initBigDecimalFieldsToZero(vo);
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取可是指定项目的金额
|
|
|
* @param dept
|