|
@@ -392,13 +392,28 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
|
// 处理医院其他收支
|
|
|
List<CostOtherPaymentsData> otherPaymentsDatas = otherPaymentsDataService.getByMonth(year, month, hospId);
|
|
|
if (!otherPaymentsDatas.isEmpty()) {
|
|
|
- otherPaymentsDatas.forEach(ele -> {
|
|
|
+ Optional<ReportForm> firstLossReport = reportForms.stream().filter(f -> NumberConstant.ONE.equals(f.getIsLoss())).findFirst();
|
|
|
+ if(!firstLossReport.isPresent()){
|
|
|
+ throw new CostException("全院损益报表配置有误,未设置损益项目");
|
|
|
+ }
|
|
|
+ Optional<HospProfitAndLoss> firstHospProfitAndLoss = list.stream().filter(f -> firstLossReport.get().getNum().equals(f.getReportNum())).findFirst();
|
|
|
+ if(!firstHospProfitAndLoss.isPresent()){
|
|
|
+ throw new CostException("全院损益报表配置有误,未找到配置的损益项目");
|
|
|
+ }
|
|
|
+ for (CostOtherPaymentsData ele : otherPaymentsDatas) {
|
|
|
HospProfitAndLoss loss = new HospProfitAndLoss();
|
|
|
loss.setDateYear(year).setDateMonth(month).setReportName(ele.getPaymentsName()).setReportNum((int) (-ele.getId()))
|
|
|
.setCreateTime(System.currentTimeMillis()).setAmount(ele.getTotalAmount()).setHospId(hospId)
|
|
|
- .setResponsibilityName("全院").setResponsibilityCode("-1").setPercent(null);
|
|
|
+ .setResponsibilityName("全院").setResponsibilityCode("-1").setPercent(null).setOriginType(NumberConstant.ONE);
|
|
|
+ if( NumberConstant.ONE.equals(ele.getPaymentsType()) ) {
|
|
|
+ //全院损益项目加上收入
|
|
|
+ firstHospProfitAndLoss.get().setAmount(firstHospProfitAndLoss.get().getAmount().add(ele.getTotalAmount()));
|
|
|
+ }else{
|
|
|
+ //全院损益项目减去支出
|
|
|
+ firstHospProfitAndLoss.get().setAmount(firstHospProfitAndLoss.get().getAmount().subtract(ele.getTotalAmount()));
|
|
|
+ }
|
|
|
list.add(loss);
|
|
|
- });
|
|
|
+ }
|
|
|
}
|
|
|
long l = System.currentTimeMillis();
|
|
|
list.forEach(i -> {
|
|
@@ -1542,7 +1557,7 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
|
|
|
|
@Override
|
|
|
public Object getBatchHospProfitList(String beginComputeDate, String endComputeDate, Long hospId, Integer reportType) {
|
|
|
- List<HospProfitAndLoss> hospProfitAndLossByDateRange = getHospProfitAndLossByDateRange(beginComputeDate, endComputeDate);
|
|
|
+ List<HospProfitAndLoss> hospProfitAndLossByDateRange = getHospProfitAndLossByDateRange(beginComputeDate, endComputeDate,reportType);
|
|
|
if (CollectionUtils.isEmpty(hospProfitAndLossByDateRange)) {
|
|
|
throw new CostException(500, "未进行全院损益计算");
|
|
|
}
|
|
@@ -1561,6 +1576,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);
|
|
@@ -1644,7 +1660,8 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
|
List<HospProfitAndLoss> otherHospProfitAndLoss = hospProfitAndLossList.stream().filter(i -> NumberConstant.ONE.equals(i.getOriginType())).collect(Collectors.toList());
|
|
|
//按报表项目编号map
|
|
|
Map<Integer, HospProfitAndLoss> hospProfitAndLossMap = hospProfitAndLossList.stream().collect(Collectors.toMap(HospProfitAndLoss::getReportNum, b -> b));
|
|
|
- List<CostProfitVo> costProfitVos = BeanUtil.convertList(reportFormList, CostProfitVo.class);
|
|
|
+ //报表项目转换成多层级损益对象
|
|
|
+ List<CostProfitVo> costProfitVos =reportFormList.stream().map(reportForm -> reportFormToProfitVo(reportForm)).collect(Collectors.toList());
|
|
|
//组装全院损益及报表项目信息
|
|
|
for (CostProfitVo profitVo : costProfitVos) {
|
|
|
//处理年月数据
|
|
@@ -1652,46 +1669,36 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
|
profitVo.setMonth(hospProfitAndLossList.get(0).getDateMonth());
|
|
|
//添加损益数据
|
|
|
HospProfitAndLoss hospProfitAndLoss = hospProfitAndLossMap.get(profitVo.getReportNum());
|
|
|
- if (ObjectUtils.isEmpty(hospProfitAndLoss)) {
|
|
|
- profitVo.setAmount(BigDecimal.ZERO);
|
|
|
- profitVo.setSamePeriodAmount(BigDecimal.ZERO);
|
|
|
- profitVo.setPrevPeriodAmount(BigDecimal.ZERO);
|
|
|
- profitVo.setBudgetAmount(BigDecimal.ZERO);
|
|
|
- profitVo.setYoyRate(BigDecimal.ZERO);
|
|
|
- profitVo.setMomRate(BigDecimal.ZERO);
|
|
|
- profitVo.setCompletionRate(BigDecimal.ZERO);
|
|
|
- } else {
|
|
|
- profitVo.setAmount(hospProfitAndLoss.getAmount());
|
|
|
- profitVo.setSamePeriodAmount(hospProfitAndLoss.getSamePeriodAmount());
|
|
|
- profitVo.setPrevPeriodAmount(hospProfitAndLoss.getPrevPeriodAmount());
|
|
|
- profitVo.setBudgetAmount(hospProfitAndLoss.getBudgetAmount());
|
|
|
- profitVo.setYoyRate(hospProfitAndLoss.getYoyRate());
|
|
|
- profitVo.setMomRate(hospProfitAndLoss.getMomRate());
|
|
|
- profitVo.setCompletionRate(hospProfitAndLoss.getCompletionRate());
|
|
|
- }
|
|
|
+ //组装全院损益及报表项目金额信息
|
|
|
+ combineReportAndProfitAmount(profitVo,hospProfitAndLoss);
|
|
|
}
|
|
|
//有全院其他收支时添加全院其他收支
|
|
|
- if(CollectionUtils.isEmpty(otherHospProfitAndLoss)){
|
|
|
+ if(!CollectionUtils.isEmpty(otherHospProfitAndLoss)){
|
|
|
//找到配置的损益项目
|
|
|
Optional<ReportForm> firstLossReport = reportFormList.stream().filter(i -> NumberConstant.ONE.equals(i.getIsLoss())).findFirst();
|
|
|
if(!firstLossReport.isPresent()){
|
|
|
throw new CostException(500, "全院损益报表配置有误,未设置损益项目");
|
|
|
}
|
|
|
+ //生成一个虚拟的全院其他收支
|
|
|
+ CostProfitVo otherProfit = getOtherProfit(reportFormList);
|
|
|
+ //处理年月数据
|
|
|
+ otherProfit.setYear(otherHospProfitAndLoss.get(NumberConstant.ZERO).getDateYear());
|
|
|
+ otherProfit.setMonth(otherHospProfitAndLoss.get(NumberConstant.ZERO).getDateMonth());
|
|
|
+ costProfitVos.add(otherProfit);
|
|
|
ReportForm reportForm = firstLossReport.get();
|
|
|
- for (HospProfitAndLoss hospProfitAndLoss : otherHospProfitAndLoss) {
|
|
|
- CostProfitVo costProfitVo = BeanUtil.convertObj(reportForm, CostProfitVo.class);
|
|
|
+ for (int i = 0; i < otherHospProfitAndLoss.size(); i++) {
|
|
|
+ HospProfitAndLoss hospProfitAndLoss = otherHospProfitAndLoss.get(i);
|
|
|
+ CostProfitVo costProfitVo =reportFormToProfitVo(reportForm);
|
|
|
+ //组装全院损益及报表项目金额信息
|
|
|
+ combineReportAndProfitAmount(costProfitVo,hospProfitAndLoss);
|
|
|
//处理年月数据
|
|
|
costProfitVo.setYear(hospProfitAndLoss.getDateYear());
|
|
|
costProfitVo.setMonth(hospProfitAndLoss.getDateMonth());
|
|
|
- costProfitVo.setAmount(hospProfitAndLoss.getAmount());
|
|
|
- costProfitVo.setSamePeriodAmount(hospProfitAndLoss.getSamePeriodAmount());
|
|
|
- costProfitVo.setPrevPeriodAmount(hospProfitAndLoss.getPrevPeriodAmount());
|
|
|
- costProfitVo.setBudgetAmount(hospProfitAndLoss.getBudgetAmount());
|
|
|
- costProfitVo.setYoyRate(hospProfitAndLoss.getYoyRate());
|
|
|
- costProfitVo.setMomRate(hospProfitAndLoss.getMomRate());
|
|
|
- costProfitVo.setCompletionRate(hospProfitAndLoss.getCompletionRate());
|
|
|
- //全院其他收支项目排在损益项目后面
|
|
|
- costProfitVo.setSort(reportForm.getSort()+1);
|
|
|
+ //全院其他收支项目放在虚拟的全院其他收支下
|
|
|
+ costProfitVo.setSort(i);
|
|
|
+ costProfitVo.setReportNum(hospProfitAndLoss.getReportNum());
|
|
|
+ costProfitVo.setReportId(hospProfitAndLoss.getReportNum().longValue());
|
|
|
+ costProfitVo.setReportParentId(otherProfit.getReportId());
|
|
|
costProfitVos.add(costProfitVo);
|
|
|
}
|
|
|
}
|
|
@@ -1700,6 +1707,71 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
|
return costProfitVoTree;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 生成一个虚拟的全院其他收支
|
|
|
+ * @param reportFormList
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public CostProfitVo getOtherProfit(List<ReportForm> reportFormList) {
|
|
|
+ //全院其他收支
|
|
|
+ CostProfitVo hospProfitVO = reportFormToProfitVo(reportFormList.get(NumberConstant.ZERO));
|
|
|
+ hospProfitVO.setId(-1L);
|
|
|
+ hospProfitVO.setReportId(-1L);
|
|
|
+ hospProfitVO.setReportNum(-1);
|
|
|
+ hospProfitVO.setReportParentId(0L);
|
|
|
+ hospProfitVO.setReportName("全院其他收支");
|
|
|
+ hospProfitVO.setSort(reportFormList.size());
|
|
|
+ return hospProfitVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 报表项目转换成多层级损益对象
|
|
|
+ * @param reportForm
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public CostProfitVo reportFormToProfitVo(ReportForm reportForm){
|
|
|
+ CostProfitVo profitVo = new CostProfitVo();
|
|
|
+ profitVo.setReportId(reportForm.getId());
|
|
|
+ profitVo.setReportName(reportForm.getReportName());
|
|
|
+ profitVo.setReportParentId(reportForm.getParentId());
|
|
|
+ profitVo.setReportNum(reportForm.getNum());
|
|
|
+ profitVo.setCalcType(reportForm.getCalcType());
|
|
|
+ profitVo.setCalcFormula(reportForm.getCalcFormula());
|
|
|
+ profitVo.setCostType(reportForm.getCostType());
|
|
|
+ profitVo.setShareType(reportForm.getReportType());
|
|
|
+ profitVo.setSort(reportForm.getSort());
|
|
|
+ profitVo.setDescription(reportForm.getDescription());
|
|
|
+ profitVo.setDataType(reportForm.getDataType());
|
|
|
+ profitVo.setDecimalPlace(reportForm.getDecimalPlace());
|
|
|
+ profitVo.setPermil(reportForm.getPermil());
|
|
|
+ return profitVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 组装全院损益及报表项目的金额信息
|
|
|
+ * @param profitVo
|
|
|
+ * @param hospProfitAndLoss
|
|
|
+ */
|
|
|
+ public void combineReportAndProfitAmount(CostProfitVo profitVo, HospProfitAndLoss hospProfitAndLoss) {
|
|
|
+ if (ObjectUtils.isEmpty(hospProfitAndLoss)) {
|
|
|
+ profitVo.setAmount(BigDecimal.ZERO);
|
|
|
+ profitVo.setSamePeriodAmount(BigDecimal.ZERO);
|
|
|
+ profitVo.setPrevPeriodAmount(BigDecimal.ZERO);
|
|
|
+ profitVo.setBudgetAmount(BigDecimal.ZERO);
|
|
|
+ profitVo.setYoyRate(BigDecimal.ZERO);
|
|
|
+ profitVo.setMomRate(BigDecimal.ZERO);
|
|
|
+ profitVo.setCompletionRate(BigDecimal.ZERO);
|
|
|
+ } else {
|
|
|
+ profitVo.setAmount(hospProfitAndLoss.getAmount());
|
|
|
+ profitVo.setSamePeriodAmount(hospProfitAndLoss.getSamePeriodAmount());
|
|
|
+ profitVo.setPrevPeriodAmount(hospProfitAndLoss.getPrevPeriodAmount());
|
|
|
+ profitVo.setBudgetAmount(hospProfitAndLoss.getBudgetAmount());
|
|
|
+ profitVo.setYoyRate(hospProfitAndLoss.getYoyRate());
|
|
|
+ profitVo.setMomRate(hospProfitAndLoss.getMomRate());
|
|
|
+ profitVo.setCompletionRate(hospProfitAndLoss.getCompletionRate());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 转成树状结构的损益数据
|
|
|
* @param costProfitVos
|
|
@@ -1759,7 +1831,7 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
|
* @param endComputeDate
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<HospProfitAndLoss> getHospProfitAndLossByDateRange(String beginComputeDate, String endComputeDate) {
|
|
|
+ public List<HospProfitAndLoss> getHospProfitAndLossByDateRange(String beginComputeDate, String endComputeDate, Integer reportType) {
|
|
|
// 解析开始和结束时间
|
|
|
int startYear = Integer.parseInt(beginComputeDate.split("-")[0]);
|
|
|
int startMonth = Integer.parseInt(beginComputeDate.split("-")[1]);
|
|
@@ -1775,12 +1847,11 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
|
endMonth=13;
|
|
|
}
|
|
|
List<HospProfitAndLoss> list = this.list(new QueryWrapper<HospProfitAndLoss>().lambda()
|
|
|
- .eq(HospProfitAndLoss::getDeleteTime, NumberConstant.ZERO)
|
|
|
- .eq(HospProfitAndLoss::getHospId, UserContext.getHospId())
|
|
|
- .apply("({0} * 100 + {1}) >= {2}",
|
|
|
- "date_year", "date_month", startYear * 100 + startMonth)
|
|
|
- .apply("({0} * 100 + {1}) <= {2}",
|
|
|
- "date_year", "date_month", endYear * 100 + endMonth));
|
|
|
+ .eq(HospProfitAndLoss::getDeleteTime, NumberConstant.ZERO)
|
|
|
+ .eq(HospProfitAndLoss::getHospId, UserContext.getHospId())
|
|
|
+ .eq(HospProfitAndLoss::getReportType, reportType)
|
|
|
+ .apply("(date_year * 100 + date_month) >= {0}", startYear * 100 + startMonth)
|
|
|
+ .apply("(date_year * 100 + date_month) <= {0}", endYear * 100 + endMonth));
|
|
|
return list;
|
|
|
}
|
|
|
|