|
@@ -15,6 +15,7 @@ import com.kcim.dao.model.dto.PatientItemDepartmentGroupVo;
|
|
|
import com.kcim.dao.repository.*;
|
|
|
import com.kcim.service.CenterService;
|
|
|
import com.kcim.service.ProjectCostService;
|
|
|
+import com.kcim.service.ResponsibilityDepartmentService;
|
|
|
import com.kcim.service.SqlService;
|
|
|
import com.kcim.vo.*;
|
|
|
import com.kcim.web.reponse.ProjectCostResponse;
|
|
@@ -101,7 +102,9 @@ public class ProjectCostServiceImpl implements ProjectCostService {
|
|
|
|
|
|
SqlService sqlService;
|
|
|
|
|
|
- public ProjectCostServiceImpl(SqlService sqlService,ResponsibilityRepository responsibilityRepository, ComputeProjectCostRepository repository, ComputeProjectCostDetailRepository detailRepository, ComputeProjectGroupCostDetailRepository groupDetailRepository, ImportPatientItemRepository importPatientItemRepository, ShareParamCostRepository shareParamCostRepository, ShareParamCostDetailRepository shareParamCostDetailRepository, CostDepartmentProfitRepository costDepartmentProfitRepository, ShareParamTypeMapRepository shareParamTypeMapRepository, ComputeShareParamRepository computeShareParamRepository, ItemRepository itemRepository, ResponsibilityDepartmentRepository responsibilityDepartmentRepository, CenterService centerService, ComputePatientProjectCostRepository computePatientProjectCostRepository, ComputePatientProjectCostDetailRepository computePatientProjectCostDetailRepository, ComputePatientProjectGroupCostDetailRepository computePatientProjectGroupCostDetailRepository, ComputeStandShareParamRepository computeStandShareParamRepository, ComputeStandProjectCostRepository standProjectCostRepository, ComputeStandProjectCostDetailRepository standProjectCostDetailRepository, ComputeStandProjectGroupCostDetailRepository standProjectGroupCostDetailRepository, ComputeStandPatientProjectCostRepository computeStandPatientProjectCostRepository, ComputeStandPatientProjectCostDetailRepository computeStandPatientProjectCostDetailRepository, ComputeStandPatientProjectGroupCostDetailRepository computeStandPatientProjectGroupCostDetailRepository) {
|
|
|
+ ResponsibilityDepartmentService responsibilityDepartmentService;
|
|
|
+
|
|
|
+ public ProjectCostServiceImpl(ResponsibilityDepartmentService responsibilityDepartmentService,SqlService sqlService,ResponsibilityRepository responsibilityRepository, ComputeProjectCostRepository repository, ComputeProjectCostDetailRepository detailRepository, ComputeProjectGroupCostDetailRepository groupDetailRepository, ImportPatientItemRepository importPatientItemRepository, ShareParamCostRepository shareParamCostRepository, ShareParamCostDetailRepository shareParamCostDetailRepository, CostDepartmentProfitRepository costDepartmentProfitRepository, ShareParamTypeMapRepository shareParamTypeMapRepository, ComputeShareParamRepository computeShareParamRepository, ItemRepository itemRepository, ResponsibilityDepartmentRepository responsibilityDepartmentRepository, CenterService centerService, ComputePatientProjectCostRepository computePatientProjectCostRepository, ComputePatientProjectCostDetailRepository computePatientProjectCostDetailRepository, ComputePatientProjectGroupCostDetailRepository computePatientProjectGroupCostDetailRepository, ComputeStandShareParamRepository computeStandShareParamRepository, ComputeStandProjectCostRepository standProjectCostRepository, ComputeStandProjectCostDetailRepository standProjectCostDetailRepository, ComputeStandProjectGroupCostDetailRepository standProjectGroupCostDetailRepository, ComputeStandPatientProjectCostRepository computeStandPatientProjectCostRepository, ComputeStandPatientProjectCostDetailRepository computeStandPatientProjectCostDetailRepository, ComputeStandPatientProjectGroupCostDetailRepository computeStandPatientProjectGroupCostDetailRepository) {
|
|
|
this.responsibilityRepository = responsibilityRepository;
|
|
|
this.repository = repository;
|
|
|
this.sqlService = sqlService;
|
|
@@ -127,6 +130,7 @@ public class ProjectCostServiceImpl implements ProjectCostService {
|
|
|
this.computeStandPatientProjectCostRepository = computeStandPatientProjectCostRepository;
|
|
|
this.computeStandPatientProjectCostDetailRepository = computeStandPatientProjectCostDetailRepository;
|
|
|
this.computeStandPatientProjectGroupCostDetailRepository = computeStandPatientProjectGroupCostDetailRepository;
|
|
|
+ this.responsibilityDepartmentService=responsibilityDepartmentService;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -254,7 +258,7 @@ public class ProjectCostServiceImpl implements ProjectCostService {
|
|
|
@Override
|
|
|
public void computeItemCost(String computeDate){
|
|
|
//项目成本分摊计算
|
|
|
- computeItemCostACtion(computeDate);
|
|
|
+ calcItemCostAllocation(computeDate);
|
|
|
log.info("项目成本分摊计算完成开始执行后续处理脚本");
|
|
|
//执行后续处理脚本
|
|
|
execItemCostSQL(computeDate);
|
|
@@ -425,6 +429,294 @@ public class ProjectCostServiceImpl implements ProjectCostService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 项目成本分摊计算
|
|
|
+ * @param computeDate
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Throwable.class, propagation = Propagation.REQUIRED)
|
|
|
+ public void calcItemCostAllocation(String computeDate) {
|
|
|
+ SessionUserVO currentUser = UserContext.getCurrentUser();
|
|
|
+ //获取收费项目数据(项目)
|
|
|
+ checkImportItem(computeDate, currentUser);
|
|
|
+ //判断是否进行过分摊参数计算
|
|
|
+ long shareCount = computeShareParamRepository.getComputeShareParamCount(computeDate);
|
|
|
+ if (shareCount == 0) {
|
|
|
+ throw new CostException("未进行项目分摊参数计算,请先进行项目分摊参数计算,当前计算中止");
|
|
|
+ }
|
|
|
+ //医疗服务项目字典
|
|
|
+ List<Item> itemList = itemRepository.getList();
|
|
|
+ if (CollectionUtils.isEmpty(itemList)) {
|
|
|
+ throw new CostException("医疗服务项目未维护,请先添加医疗服务项目再进行计算,当前计算中止");
|
|
|
+ }
|
|
|
+ //月度患者收费项目信息
|
|
|
+ List<PatientItemDepartmentGroupVo> ptChargeItems = importPatientItemRepository.getByDepartGroupComputeDateItem(computeDate, currentUser);
|
|
|
+ if (CollectionUtils.isEmpty(ptChargeItems)){
|
|
|
+ throw new CostException("没有可计算的收费项目");
|
|
|
+ }
|
|
|
+
|
|
|
+ //项目成本分摊配置
|
|
|
+ List<ShareParamCostVo> shareParamCostVos = shareParamCostRepository.getParamCost();
|
|
|
+ if (CollectionUtils.isEmpty(shareParamCostVos)){
|
|
|
+ throw new CostException("没有项目分摊配置信息无法分摊,请联系管理员");
|
|
|
+ }
|
|
|
+
|
|
|
+ //作废上次计算记录
|
|
|
+ repository.removeByComputeDate(computeDate, currentUser);
|
|
|
+ detailRepository.removeByComputeDate(computeDate, currentUser);
|
|
|
+ groupDetailRepository.removeByComputeDate(computeDate, currentUser);
|
|
|
+
|
|
|
+ //项目成本分摊配置主表信息(项目成本列配置)
|
|
|
+ List<ShareParamCost> ShareParamCosts = shareParamCostRepository.getList(null);
|
|
|
+ //科室责任中心对照信息
|
|
|
+ List<ResponsibilityDepartIdVO> responsibilityDeptMaps = responsibilityDepartmentService.getResponsibilityDepart();
|
|
|
+ //分摊参数信息
|
|
|
+ List<ComputeShareParamDetailVo> computeShareParamDetails = computeShareParamRepository.getComputeShareParamDetail(computeDate);
|
|
|
+ //分摊参数按责任中心汇总信息
|
|
|
+ List<ComputeShareParamDetailVo> computeShareParamDetailGroup = computeShareParamRepository.getComputeShareParamDetailGroup(computeDate);
|
|
|
+ //要计算的科室收费项目
|
|
|
+ List<ComputeShareParamDetailVo> computeResponsibilityItems = computeShareParamRepository.getComputeResponsibilityItem(computeDate);
|
|
|
+ //获取科室损益报表数据
|
|
|
+ List<CostDepartmentProfit> costDepartmentProfits = costDepartmentProfitRepository.getDepartmentProfit(computeDate);
|
|
|
+
|
|
|
+ //开始项目成本分摊计算
|
|
|
+ List<ComputeProjectCost> computeProjectCosts=new ArrayList<>();
|
|
|
+ List<ComputeProjectCostDetail> computeProjectCostDetails=new ArrayList<>();
|
|
|
+ List<ComputeProjectGroupCostDetail> computeProjectGroupCostDetails=new ArrayList<>();
|
|
|
+ //获取项目收入对应的分摊参数配置
|
|
|
+ ShareParamTypeMap incomeShareParam = getIncomeShareParamTypeMap();
|
|
|
+ //按项目类别+责任中心代码+项目代码逐个计算项目分摊金额
|
|
|
+ computeResponsibilityItems.stream().forEach(responsibilityItem->{
|
|
|
+ //创建项目成本主表对象
|
|
|
+ ComputeProjectCost projectCost = createComputeProjectCost(computeDate, currentUser, responsibilityItem);
|
|
|
+ computeProjectCosts.add(projectCost);
|
|
|
+ //获取项目对应分摊参数数值
|
|
|
+ List<ComputeShareParamDetailVo> itemShareParams = computeShareParamDetails.stream().filter(shareParamGroup -> shareParamGroup.getResponsibilityCode().equals(projectCost.getResponsibilityCode())
|
|
|
+ && shareParamGroup.getCode().equals(projectCost.getCode()) && shareParamGroup.getItemType().equals(projectCost.getItemType())).collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isEmpty(itemShareParams)){
|
|
|
+ throw new CostException(String.format("找不到项目的[%s-%s]对应的分摊分摊参数,请重新计算分摊参数",projectCost.getItemType(),projectCost.getName()));
|
|
|
+ }
|
|
|
+ //取项目对应的分摊配置
|
|
|
+ List<ShareParamCost> itemShareParamCost = ShareParamCosts.stream().filter(shareParamCost -> shareParamCost.getItemType().equals(projectCost.getItemType())).collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isEmpty(itemShareParamCost)){
|
|
|
+ throw new CostException(String.format("类型[%s]没有对应分摊配置,请联系管理员",projectCost.getItemType()));
|
|
|
+ }
|
|
|
+ List<ComputeProjectCostDetail> computeProjectCostDetailChilds=new ArrayList<>();
|
|
|
+ //按项目分摊配置计算项目的所有项目成本列的分摊金额
|
|
|
+ itemShareParamCost.stream().forEach(shareParamCost->{
|
|
|
+ ComputeProjectCostDetail cmputeProjectCostDetail=createComputeProjectCostDetail(computeDate, currentUser,incomeShareParam,responsibilityItem,projectCost,
|
|
|
+ shareParamCost,shareParamCostVos,itemShareParams,computeShareParamDetailGroup,costDepartmentProfits);
|
|
|
+ computeProjectCostDetailChilds.add(cmputeProjectCostDetail);
|
|
|
+ });
|
|
|
+ computeProjectCostDetails.addAll(computeProjectCostDetailChilds);
|
|
|
+
|
|
|
+ //按项目成本列类型汇总数据
|
|
|
+ Map<String, BigDecimal> columnTypeGroup = computeProjectCostDetailChilds.stream().collect(Collectors.groupingBy(ComputeProjectCostDetail::getCostColumnType,
|
|
|
+ Collectors.mapping(ComputeProjectCostDetail::getComputeResult, Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))));
|
|
|
+ columnTypeGroup.forEach((columnType, computeResult) -> {
|
|
|
+ //创建项目成本汇总表对象
|
|
|
+ ComputeProjectGroupCostDetail computeProjectGroupCostDetail = createComputeProjectGroupCostDetail(computeDate, currentUser, responsibilityItem, projectCost, columnType, computeResult);
|
|
|
+ computeProjectGroupCostDetails.add(computeProjectGroupCostDetail);
|
|
|
+ });
|
|
|
+ //所有成本列汇总的金额就是项目成本
|
|
|
+ BigDecimal itemCost = computeProjectCostDetailChilds.stream().map(ComputeProjectCostDetail::getComputeResult).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ //创建项目成本列的汇总表对象
|
|
|
+ ComputeProjectGroupCostDetail itemCostGroupDetail = createComputeProjectGroupCostDetail(computeDate, currentUser, responsibilityItem, projectCost, ITEM_COST.getCode(), itemCost);
|
|
|
+ computeProjectGroupCostDetails.add(itemCostGroupDetail);
|
|
|
+ });
|
|
|
+
|
|
|
+ //没有任何可保存的数据
|
|
|
+ if (CollectionUtils.isEmpty(computeProjectCosts)) {
|
|
|
+ throw new CostException("没有任何可保存的数据");
|
|
|
+ }
|
|
|
+ //保存项目分摊主表对象数据
|
|
|
+ repository.saveBatch(computeProjectCosts, 500);
|
|
|
+ if (!CollectionUtils.isEmpty(computeProjectCostDetails)) {
|
|
|
+ //保存项目分摊明细表对象数据
|
|
|
+ computeProjectCostDetails.stream().forEach(projectCostDetail->projectCostDetail.setProjectCostId(projectCostDetail.getComputeProjectCost().getId()));
|
|
|
+ detailRepository.saveBatch(computeProjectCostDetails, 500);
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(computeProjectGroupCostDetails)) {
|
|
|
+ //保存项目分摊汇总表对象数据
|
|
|
+ computeProjectGroupCostDetails.stream().forEach(projectCostDetail->projectCostDetail.setProjectCostId(projectCostDetail.getComputeProjectCost().getId()));
|
|
|
+ groupDetailRepository.saveBatch(computeProjectGroupCostDetails, 500);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取项目收入对应的分摊参数配置
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ShareParamTypeMap getIncomeShareParamTypeMap(){
|
|
|
+ //分摊参数设置信息
|
|
|
+ List<ShareParamTypeMap> shareParamTypeMaps = shareParamTypeMapRepository.getList();
|
|
|
+ if(CollectionUtils.isEmpty(shareParamTypeMaps)){
|
|
|
+ throw new CostException("没有分摊参数配置信息无法进行项目分摊计算");
|
|
|
+ }
|
|
|
+ Optional<ShareParamTypeMap> firstShareParamTypeMap = shareParamTypeMaps.stream().filter(shareParam -> shareParam.getSourceCode().equals(ITEM_INCOME.getCode())).findFirst();
|
|
|
+ if(!firstShareParamTypeMap.isPresent()){
|
|
|
+ throw new CostException("没有配置项目收入的分摊参数无法进行项目分摊计算");
|
|
|
+ }
|
|
|
+ return firstShareParamTypeMap.get();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建项目成本主表对象
|
|
|
+ * @param computeDate
|
|
|
+ * @param currentUser
|
|
|
+ * @param responsibilityItem
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ComputeProjectCost createComputeProjectCost(String computeDate,SessionUserVO currentUser,ComputeShareParamDetailVo responsibilityItem){
|
|
|
+ //主表公共对象
|
|
|
+ ComputeProjectCost computeProjectCost = new ComputeProjectCost();
|
|
|
+ computeProjectCost.setComputeDate(computeDate);
|
|
|
+ computeProjectCost.setHospId(currentUser.getHospId());
|
|
|
+ computeProjectCost.setCreateUser(String.valueOf(currentUser.getId()));
|
|
|
+ computeProjectCost.setCreateTime(new Date());
|
|
|
+ computeProjectCost.setCode(responsibilityItem.getCode());
|
|
|
+ computeProjectCost.setName(responsibilityItem.getName());
|
|
|
+ computeProjectCost.setItemType(responsibilityItem.getItemType());
|
|
|
+ computeProjectCost.setResponsibilityCode(responsibilityItem.getResponsibilityCode());
|
|
|
+ computeProjectCost.setResponsibilityName(responsibilityItem.getResponsibilityName());
|
|
|
+ return computeProjectCost;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建项目成本明细表对象
|
|
|
+ * @param computeDate 核算年月
|
|
|
+ * @param currentUser 登录人信息
|
|
|
+ * @param responsibilityItem 责任中心的项目汇总数据
|
|
|
+ * @param computeProjectCost 主表对象
|
|
|
+ * @param shareParamCost 分摊配置主表
|
|
|
+ * @param shareParamCostVos 分摊配置明细
|
|
|
+ * @param computeShareParamDetails 分摊参数计算明细
|
|
|
+ * @param computeShareParamDetailGroup 分摊参数计算明细汇总
|
|
|
+ * @param costDepartmentProfits 科室损益数据
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ComputeProjectCostDetail createComputeProjectCostDetail(String computeDate,SessionUserVO currentUser,ShareParamTypeMap incomeShareParam,ComputeShareParamDetailVo responsibilityItem,ComputeProjectCost computeProjectCost,ShareParamCost shareParamCost,
|
|
|
+ List<ShareParamCostVo> shareParamCostVos,List<ComputeShareParamDetailVo> computeShareParamDetails ,
|
|
|
+ List<ComputeShareParamDetailVo> computeShareParamDetailGroup,List<CostDepartmentProfit> costDepartmentProfits){
|
|
|
+ //明细表公共对象
|
|
|
+ ComputeProjectCostDetail costDetail = new ComputeProjectCostDetail();
|
|
|
+ costDetail.setComputeDate(computeDate);
|
|
|
+ costDetail.setHospId(currentUser.getHospId());
|
|
|
+ costDetail.setCreateUser(String.valueOf(currentUser.getId()));
|
|
|
+ costDetail.setCreateTime(new Date());
|
|
|
+ costDetail.setComputeProjectCost(computeProjectCost);
|
|
|
+ costDetail.setCostColumnCode(shareParamCost.getColumnCode());
|
|
|
+ costDetail.setCostColumnType(shareParamCost.getColumnType());
|
|
|
+ //获取对应分摊配置明细
|
|
|
+ List<ShareParamCostVo> shareParamDetails = shareParamCostVos.stream().filter(shareParamDetail -> shareParamDetail.getColumnCode().equals(shareParamCost.getColumnCode())).collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isEmpty(shareParamDetails)){
|
|
|
+ throw new CostException(String.format("[%s]没有对应分摊配置,请联系管理员",shareParamCost.getColumnName()));
|
|
|
+ }
|
|
|
+ //根据主表配置找到对应的科室损益数据
|
|
|
+ Optional<CostDepartmentProfit> firstDepartmentProfit = costDepartmentProfits.stream().filter(departmentProfit -> String.valueOf(departmentProfit.getShareType()).equals(shareParamCost.getReportType()) &&
|
|
|
+ String.valueOf(departmentProfit.getReportNum()).equals(shareParamCost.getProfitNum()) &&
|
|
|
+ departmentProfit.getResponsibilityCode().equals(computeProjectCost.getResponsibilityCode())).findFirst();
|
|
|
+ //没有对应的损益项目数据或者损益项目金额为0
|
|
|
+ if(!firstDepartmentProfit.isPresent()||firstDepartmentProfit.get().getAmount().equals(BigDecimal.ZERO)){
|
|
|
+ costDetail.setComputeResult(BigDecimal.ZERO);
|
|
|
+ costDetail.setComputeSingleResult(BigDecimal.ZERO);
|
|
|
+ return costDetail;
|
|
|
+ }
|
|
|
+ //按项目分摊配置计算项目的一个项目成本列的分摊金额
|
|
|
+ BigDecimal itemAllocationAmount=calcItemAllocationAmount(incomeShareParam,computeProjectCost,firstDepartmentProfit.get(),
|
|
|
+ shareParamDetails,computeShareParamDetailGroup,computeShareParamDetails);
|
|
|
+ costDetail.setComputeResult(itemAllocationAmount);
|
|
|
+ //项目没有数量时,单个项目的分摊金额为0
|
|
|
+ if(responsibilityItem.getNum().compareTo(BigDecimal.ZERO)==NumberConstant.ZERO){
|
|
|
+ costDetail.setComputeSingleResult(BigDecimal.ZERO);
|
|
|
+ }else{
|
|
|
+ //有数量数,单个项目的分摊金额=总分摊金额/数量
|
|
|
+ costDetail.setComputeSingleResult(itemAllocationAmount.divide(responsibilityItem.getNum(),NumberConstant.FOUR,RoundingMode.HALF_UP));
|
|
|
+ }
|
|
|
+ return costDetail;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算项目的分摊金额
|
|
|
+ * @param computeProjectCost 主表对象
|
|
|
+ * @param costDepartmentProfit 科室损益数据
|
|
|
+ * @param shareParamCostVos 分摊配置明细
|
|
|
+ * @param computeShareParamDetailGroup 分摊参数计算明细汇总
|
|
|
+ * @param computeShareParamDetails 分摊参数计算明细
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public BigDecimal calcItemAllocationAmount(ShareParamTypeMap incomeShareParam,ComputeProjectCost computeProjectCost,CostDepartmentProfit costDepartmentProfit,List<ShareParamCostVo> shareParamCostVos,
|
|
|
+ List<ComputeShareParamDetailVo> computeShareParamDetailGroup,List<ComputeShareParamDetailVo> computeShareParamDetails){
|
|
|
+ BigDecimal itemAllocationAmount=BigDecimal.ZERO;
|
|
|
+ //按配置计算每个参数分摊金额
|
|
|
+ for (ShareParamCostVo shareParamCostVo : shareParamCostVos) {//获取参数对应的责任中心汇总数据
|
|
|
+ Optional<ComputeShareParamDetailVo> firstShareParamGroup = computeShareParamDetailGroup.stream().filter(shareParamGroup -> shareParamGroup.getItemType().equals(computeProjectCost.getItemType()) &&
|
|
|
+ shareParamGroup.getResponsibilityCode().equals(computeProjectCost.getResponsibilityCode()) && shareParamGroup.getShareParamCode().equals(shareParamCostVo.getShareParamCode())).findFirst();
|
|
|
+ //责任中心的汇总数据为0时,按项目收入分摊
|
|
|
+ if (!firstShareParamGroup.isPresent() || firstShareParamGroup.get().getComputeResult().compareTo(BigDecimal.ZERO) == NumberConstant.ZERO) {
|
|
|
+ //获取项目对应的收入数据
|
|
|
+ Optional<ComputeShareParamDetailVo> firstComputeShareParamDetail = computeShareParamDetails.stream().filter(computeShareParamDetailVo ->
|
|
|
+ computeShareParamDetailVo.getShareParamCode().equals(incomeShareParam.getShareParamCode())).findFirst();
|
|
|
+ if (!firstComputeShareParamDetail.isPresent()) {
|
|
|
+ throw new CostException(String.format("[%s-%s]没有收入数据无法分摊,请检查对应的收费项目数据及分摊参数计算结果数据", computeProjectCost.getResponsibilityName(), computeProjectCost.getName()));
|
|
|
+ }
|
|
|
+ //找到项目收入的责任中心汇总数据
|
|
|
+ ComputeShareParamDetailVo incomeShareParamGroup = computeShareParamDetailGroup.stream().filter(shareParamGroup -> shareParamGroup.getItemType().equals(computeProjectCost.getItemType()) &&
|
|
|
+ shareParamGroup.getResponsibilityCode().equals(computeProjectCost.getResponsibilityCode()) && shareParamGroup.getShareParamCode().equals(incomeShareParam.getShareParamCode())).findFirst().get();
|
|
|
+ //分摊金额=损益项目金额*分摊参数占比*收入/责任中心总收入
|
|
|
+ BigDecimal paramAllocationAmount = costDepartmentProfit.getAmount().multiply(shareParamCostVo.getPercent()).multiply(firstComputeShareParamDetail.get().getComputeResult())
|
|
|
+ .divide(incomeShareParamGroup.getComputeResult(), NumberConstant.FOUR, RoundingMode.HALF_UP);
|
|
|
+ itemAllocationAmount = itemAllocationAmount.add(paramAllocationAmount);
|
|
|
+ } else {
|
|
|
+ //获取项目对应的分摊参数数据
|
|
|
+ Optional<ComputeShareParamDetailVo> firstComputeShareParamDetail = computeShareParamDetails.stream().filter(computeShareParamDetailVo ->
|
|
|
+ computeShareParamDetailVo.getShareParamCode().equals(shareParamCostVo.getShareParamCode())).findFirst();
|
|
|
+ if (!firstComputeShareParamDetail.isPresent()) {
|
|
|
+ throw new CostException(String.format("[%s-%s]没有收入数据无法分摊,请检查对应的收费项目数据", computeProjectCost.getResponsibilityName(), computeProjectCost.getName()));
|
|
|
+ }
|
|
|
+ //分摊金额=损益项目金额*分摊参数占比*分摊参数数值/责任中心总分摊参数数值
|
|
|
+ BigDecimal paramAllocationAmount = costDepartmentProfit.getAmount().multiply(shareParamCostVo.getPercent()).multiply(firstComputeShareParamDetail.get().getComputeResult())
|
|
|
+ .divide(firstShareParamGroup.get().getComputeResult(), NumberConstant.FOUR, RoundingMode.HALF_UP);
|
|
|
+ itemAllocationAmount = itemAllocationAmount.add(paramAllocationAmount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return itemAllocationAmount;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建项目成本汇总表对象
|
|
|
+ * @param computeDate
|
|
|
+ * @param currentUser
|
|
|
+ * @param responsibilityItem
|
|
|
+ * @param computeProjectCost
|
|
|
+ * @param columnType
|
|
|
+ * @param computeResultGroup
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ComputeProjectGroupCostDetail createComputeProjectGroupCostDetail(String computeDate,SessionUserVO currentUser,
|
|
|
+ ComputeShareParamDetailVo responsibilityItem,ComputeProjectCost computeProjectCost,
|
|
|
+ String columnType,BigDecimal computeResultGroup){
|
|
|
+ //汇总明细表对象
|
|
|
+ ComputeProjectGroupCostDetail groupCostDetail = new ComputeProjectGroupCostDetail();
|
|
|
+ groupCostDetail.setComputeDate(computeDate);
|
|
|
+ groupCostDetail.setHospId(currentUser.getHospId());
|
|
|
+ groupCostDetail.setCreateUser(String.valueOf(currentUser.getId()));
|
|
|
+ groupCostDetail.setCreateTime(new Date());
|
|
|
+ groupCostDetail.setComputeProjectCost(computeProjectCost);
|
|
|
+ groupCostDetail.setType(columnType);
|
|
|
+ groupCostDetail.setComputeResult(computeResultGroup);
|
|
|
+ //项目没有数量时,单个项目的分摊金额为0
|
|
|
+ if(responsibilityItem.getNum().compareTo(BigDecimal.ZERO)==NumberConstant.ZERO){
|
|
|
+ groupCostDetail.setComputeSingleResult(BigDecimal.ZERO);
|
|
|
+ }else{
|
|
|
+ //有数量时,单个项目的金额=总金额/数量
|
|
|
+ groupCostDetail.setComputeSingleResult(computeResultGroup.divide(responsibilityItem.getNum(),NumberConstant.FOUR,RoundingMode.HALF_UP));
|
|
|
+ }
|
|
|
+ return groupCostDetail;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 执行项目成本计算后续处理SQL
|
|
|
* @param computeDate
|