|
@@ -15,7 +15,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.google.common.collect.ImmutableMap;
|
|
|
import com.kcim.common.constants.NumberConstant;
|
|
|
+import com.kcim.common.constants.ParameterConstant;
|
|
|
import com.kcim.common.constants.SQLParameter;
|
|
|
+import com.kcim.common.constants.SplitConstant;
|
|
|
import com.kcim.common.enums.CustomSqlTypeEnum;
|
|
|
import com.kcim.common.enums.DateStyleEnum;
|
|
|
import com.kcim.common.enums.ErrorCodeEnum;
|
|
@@ -111,7 +113,7 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
|
|
|
private final CostAccountShareService costAccountShareService;
|
|
|
|
|
|
- private final UserResponsibilityRightService userResponsibilityRightService ;
|
|
|
+ private final UserResponsibilityRightService userResponsibilityRightService;
|
|
|
|
|
|
|
|
|
private final SqlService sqlService;
|
|
@@ -123,7 +125,7 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
|
|
|
private final String PERCENT_FIELD = "percent";
|
|
|
|
|
|
- public CostDepartmentProfitServiceImpl(ReportFormService reportFormService, IncomeCollectionService incomeCollectionService, CostShareLevelService costShareLevelService, ResponsibilityService responsibilityService, ReportRelationService reportRelationService, AllocationService allocationService, AllocationQueryService allocationQueryService, FileRecordService fileRecordService, MinioConfig minioConfig, MinioFileUtil minioFileUtil, CenterService centerService, CostDepartmentProfitRepository costDepartmentProfitRepository, ComputeLastProfitDateRepository computeLastProfitDateRepository, AccountingService accountingService, CostAccountShareService costAccountShareService, SqlService sqlService,UserResponsibilityRightService userResponsibilityRightService) {
|
|
|
+ public CostDepartmentProfitServiceImpl(ReportFormService reportFormService, IncomeCollectionService incomeCollectionService, CostShareLevelService costShareLevelService, ResponsibilityService responsibilityService, ReportRelationService reportRelationService, AllocationService allocationService, AllocationQueryService allocationQueryService, FileRecordService fileRecordService, MinioConfig minioConfig, MinioFileUtil minioFileUtil, CenterService centerService, CostDepartmentProfitRepository costDepartmentProfitRepository, ComputeLastProfitDateRepository computeLastProfitDateRepository, AccountingService accountingService, CostAccountShareService costAccountShareService, SqlService sqlService, UserResponsibilityRightService userResponsibilityRightService) {
|
|
|
this.reportFormService = reportFormService;
|
|
|
this.incomeCollectionService = incomeCollectionService;
|
|
|
this.costShareLevelService = costShareLevelService;
|
|
@@ -140,7 +142,7 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
this.accountingService = accountingService;
|
|
|
this.costAccountShareService = costAccountShareService;
|
|
|
this.sqlService = sqlService;
|
|
|
- this.userResponsibilityRightService=userResponsibilityRightService;
|
|
|
+ this.userResponsibilityRightService = userResponsibilityRightService;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -1112,8 +1114,19 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
|
public void computeProfit(String computeDate, Long hospId, String reportType) {
|
|
|
+ //需要用代码计算时
|
|
|
+ if(IsNeedCalc(reportType)){
|
|
|
+ //计算科室损益
|
|
|
+ computeProfitAction(computeDate, hospId, reportType);
|
|
|
+ //计算同环比
|
|
|
+ handleSpecificMonthsCalculation(hospId, computeDate, reportType);
|
|
|
+ }
|
|
|
+ execDeptProfitSql(computeDate, reportType);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
|
+ public void computeProfitAction(String computeDate, Long hospId, String reportType) {
|
|
|
// DateTime parse = DateUtil.parse(computeDate);
|
|
|
// int year = DateUtil.year(parse);
|
|
|
// int month = DateUtil.month(parse) + 1;
|
|
@@ -1201,13 +1214,237 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
this.saveBatch(costDepartmentProfits);
|
|
|
//记录最后一次 损益计算日期
|
|
|
computeLastProfitDateRepository.saveLastComputeDate(hospId, computeDate);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理指定月份及关联月份的计算(当前月、下个月、明年同月)
|
|
|
+ *
|
|
|
+ * @param hospId 院区ID
|
|
|
+ * @param computeDate 日期字符串,格式:YYYY-MM
|
|
|
+ * @param shareType 报表类型
|
|
|
+ */
|
|
|
+ public void handleSpecificMonthsCalculation(Long hospId, String computeDate, String shareType) {
|
|
|
+ // 解析输入的年月
|
|
|
+ Integer currentYear = ComputeDateUtils.getComputeYear(computeDate);
|
|
|
+ Integer currentMonth = ComputeDateUtils.getComputeMonth(computeDate);
|
|
|
+ // 计算需要处理的期间信息
|
|
|
+ List<PeriodInfoVO> periods = calculateAllRelatedPeriods(currentYear, currentMonth);
|
|
|
+
|
|
|
+ // 获取所有相关的期间数据
|
|
|
+ Map<String, List<CostDepartmentProfit>> allDataMap = loadAllPeriodData(hospId, shareType, periods);
|
|
|
+
|
|
|
+ // 对每个期间执行计算
|
|
|
+ for (PeriodInfoVO period : periods) {
|
|
|
+ String currentKey = buildPeriodKey(period.getYear(), period.getMonth());
|
|
|
+ if (allDataMap.containsKey(currentKey) && !CollectionUtils.isEmpty(allDataMap.get(currentKey))) {
|
|
|
+ List<CostDepartmentProfit> currentRecords = allDataMap.get(currentKey);
|
|
|
+ List<CostDepartmentProfit> prevRecords = getPeriodData(allDataMap, period.getPrevYear(), period.getPrevMonth());
|
|
|
+ List<CostDepartmentProfit> lastYearRecords = getPeriodData(allDataMap, period.getLastYear(), period.getLastMonth());
|
|
|
+
|
|
|
+ // 执行批量计算
|
|
|
+ calculatePeriodComparisonWithPreloadedData(currentRecords, prevRecords, lastYearRecords);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建所有需要处理的期间信息
|
|
|
+ */
|
|
|
+ private List<PeriodInfoVO> calculateAllRelatedPeriods(int baseYear, int baseMonth) {
|
|
|
+ List<PeriodInfoVO> result = new ArrayList<>();
|
|
|
+
|
|
|
+ // 添加当前期间
|
|
|
+ result.add(calculatePeriodInfo(baseYear, baseMonth));
|
|
|
+
|
|
|
+ // 下个月
|
|
|
+ int nextMonth = baseMonth + 1;
|
|
|
+ int nextMonthYear = baseYear;
|
|
|
+ if (baseMonth == 12) {
|
|
|
+ nextMonth = 1;
|
|
|
+ nextMonthYear += 1;
|
|
|
+ }
|
|
|
+ result.add(calculatePeriodInfo(nextMonthYear, nextMonth));
|
|
|
+
|
|
|
+ // 明年同月
|
|
|
+ result.add(calculatePeriodInfo(baseYear + 1, baseMonth));
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建单个期间的信息(当前月、上月、去年同期)
|
|
|
+ */
|
|
|
+ private PeriodInfoVO calculatePeriodInfo(int year, int month) {
|
|
|
+ PeriodInfoVO info = new PeriodInfoVO();
|
|
|
+
|
|
|
+ info.setYear( year);
|
|
|
+ info.setMonth( month);
|
|
|
+
|
|
|
+ // 上期
|
|
|
+ if (month == 1) {
|
|
|
+ info.setPrevYear(year - 1);
|
|
|
+ info.setPrevMonth(12);
|
|
|
+ } else {
|
|
|
+ info.setPrevYear( year);
|
|
|
+ info.setPrevMonth(month - 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 同期
|
|
|
+ info.setLastYear(year - 1);
|
|
|
+ info.setLastMonth( month);
|
|
|
+
|
|
|
+ return info;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 加载所有相关期间的数据(去重处理)
|
|
|
+ */
|
|
|
+ private Map<String, List<CostDepartmentProfit>> loadAllPeriodData(Long hospId, String shareType, List<PeriodInfoVO> periods) {
|
|
|
+ Set<String> allPeriodKeys = new HashSet<>();
|
|
|
+
|
|
|
+ // 收集所有需要查询的年月组合
|
|
|
+ for (PeriodInfoVO period : periods) {
|
|
|
+ allPeriodKeys.add(buildPeriodKey(period.getYear(), period.getMonth()));
|
|
|
+ allPeriodKeys.add(buildPeriodKey(period.getPrevYear(), period.getPrevMonth()));
|
|
|
+ allPeriodKeys.add(buildPeriodKey(period.getLastYear(), period.getLastMonth()));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 去重后查询
|
|
|
+ Map<String, List<CostDepartmentProfit>> result = new HashMap<>();
|
|
|
+ Set<String> processedKeys = new HashSet<>(); // 已处理的键集合
|
|
|
+
|
|
|
+ for (String key : allPeriodKeys) {
|
|
|
+ if (!processedKeys.contains(key)) {
|
|
|
+ int[] ym = parsePeriodKey(key);
|
|
|
+ List<CostDepartmentProfit> records = getPeriodRecords(hospId, shareType, ym[0], ym[1]);
|
|
|
+ result.put(key, records);
|
|
|
+ processedKeys.add(key); // 标记为已处理
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取指定期间的数据
|
|
|
+ *
|
|
|
+ * @param hospId 院区ID
|
|
|
+ * @param shareType 报表类型
|
|
|
+ * @param year 年份
|
|
|
+ * @param month 月份
|
|
|
+ * @return 符合条件的数据列表
|
|
|
+ */
|
|
|
+ private List<CostDepartmentProfit> getPeriodRecords(Long hospId, String shareType, int year, int month) {
|
|
|
+ return this.list(new QueryWrapper<CostDepartmentProfit>().lambda()
|
|
|
+ .eq(CostDepartmentProfit::getHospId, hospId)
|
|
|
+ .eq(CostDepartmentProfit::getShareType, shareType)
|
|
|
+ .eq(CostDepartmentProfit::getYear, year)
|
|
|
+ .eq(CostDepartmentProfit::getMonth, month)
|
|
|
+ .eq(CostDepartmentProfit::getDeleteTime, 0));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据年月获取对应的数据(从内存中查找)
|
|
|
+ */
|
|
|
+ private List<CostDepartmentProfit> getPeriodData(Map<String, List<CostDepartmentProfit>> dataMap, int year, int month) {
|
|
|
+ String key = buildPeriodKey(year, month);
|
|
|
+ return dataMap.getOrDefault(key, Collections.emptyList());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量计算同环比及同期金额(使用预加载数据)
|
|
|
+ */
|
|
|
+ public void calculatePeriodComparisonWithPreloadedData(
|
|
|
+ List<CostDepartmentProfit> currentRecords,
|
|
|
+ List<CostDepartmentProfit> prevRecords,
|
|
|
+ List<CostDepartmentProfit> lastYearRecords) {
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(currentRecords)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建责任码+报表编号到记录的映射
|
|
|
+ Map<String, CostDepartmentProfit> prevMap = new HashMap<>();
|
|
|
+ for (CostDepartmentProfit record : prevRecords) {
|
|
|
+ String key = buildRecordKey(record);
|
|
|
+ prevMap.put(key, record);
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, CostDepartmentProfit> lastYearMap = new HashMap<>();
|
|
|
+ for (CostDepartmentProfit record : lastYearRecords) {
|
|
|
+ String key = buildRecordKey(record);
|
|
|
+ lastYearMap.put(key, record);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 批量更新数据
|
|
|
+ for (CostDepartmentProfit record : currentRecords) {
|
|
|
+ String key = buildRecordKey(record);
|
|
|
+ CostDepartmentProfit prevRecord = prevMap.get(key);
|
|
|
+ CostDepartmentProfit lastYearRecord = lastYearMap.get(key);
|
|
|
+
|
|
|
+ // 设置上期和同期金额
|
|
|
+ record.setPrevPeriodAmount(prevRecord != null ? prevRecord.getAmount() : BigDecimal.ZERO);
|
|
|
+ record.setSamePeriodAmount(lastYearRecord != null ? lastYearRecord.getAmount() : BigDecimal.ZERO);
|
|
|
+
|
|
|
+ // 计算环比和同比
|
|
|
+ record.setMomRate(calculateProfitRate(record.getAmount().subtract(record.getSamePeriodAmount()), record.getPrevPeriodAmount()));
|
|
|
+ record.setYoyRate(calculateProfitRate(record.getAmount().subtract(record.getSamePeriodAmount()), record.getSamePeriodAmount()));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 批量更新数据库
|
|
|
+ this.updateBatchById(currentRecords);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建期间键(用于存储和检索数据)
|
|
|
+ */
|
|
|
+ private String buildPeriodKey(int year, int month) {
|
|
|
+ return year + "_" + month;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析期间键为年月数组
|
|
|
+ */
|
|
|
+ private int[] parsePeriodKey(String key) {
|
|
|
+ String[] parts = key.split("_");
|
|
|
+ return new int[]{Integer.parseInt(parts[0]), Integer.parseInt(parts[1])};
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建记录的唯一标识键(责任码 + 报表编号)
|
|
|
+ */
|
|
|
+ private String buildRecordKey(CostDepartmentProfit record) {
|
|
|
+ return record.getResponsibilityCode() + "_" + record.getReportNum();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 安全地计算百分比:避免除零错误
|
|
|
+ */
|
|
|
+ private BigDecimal calculateProfitRate(BigDecimal current, BigDecimal base) {
|
|
|
+ if (base == null || base.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ BigDecimal bigDecimal = current.divide(base, 4, RoundingMode.HALF_UP).setScale(4, RoundingMode.HALF_UP);
|
|
|
+ return bigDecimal;
|
|
|
+ }
|
|
|
|
|
|
- Map<String,String> sqlParameter = new HashMap<>();
|
|
|
- sqlParameter.put(SQLParameter.COMPUTE_DATE_CODE,computeDate);
|
|
|
- sqlParameter.put(SQLParameter.REPORT_TYPE_CODE,reportType);
|
|
|
- sqlService.autoExecuteSql(CustomSqlTypeEnum.DEPT_PROFIT_CALC.getCode(),sqlParameter);
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 执行科室损益后续脚本
|
|
|
+ *
|
|
|
+ * @param computeDate
|
|
|
+ * @param reportType
|
|
|
+ */
|
|
|
+ public void execDeptProfitSql(String computeDate, String reportType) {
|
|
|
+ Map<String, String> sqlParameter = new HashMap<>();
|
|
|
+ sqlParameter.put(SQLParameter.COMPUTE_DATE_CODE, computeDate);
|
|
|
+ sqlParameter.put(SQLParameter.REPORT_TYPE_CODE, reportType);
|
|
|
+ sqlService.autoExecuteSql(CustomSqlTypeEnum.DEPT_PROFIT_CALC.getCode(), sqlParameter);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private DictDataVo getDictDataVo(String reportType) {
|
|
|
DictDataVo dict = centerService.getDict(PROFIT_REPORT_TYPE);
|
|
|
if (Objects.isNull(dict)) {
|
|
@@ -1246,8 +1483,14 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
if (CollUtil.isEmpty(reportFormList)) {
|
|
|
throw new CostException(500, "损益表未找到");
|
|
|
}
|
|
|
- List<CommonTitleReportVo> commonTitleReportVos = reportFormList.stream().map(reportForm -> new CommonTitleReportVo(reportForm.getId(), reportForm.getParentId(), reportForm.getReportName(), reportForm.getSort())).collect(Collectors.toList());
|
|
|
-
|
|
|
+ List<CommonTitleReportVo> commonTitleReportVos = reportFormList.stream().map(reportForm -> {
|
|
|
+ CommonTitleReportVo commonTitleReportVo = new CommonTitleReportVo(reportForm.getId(), reportForm.getParentId(), reportForm.getReportName(), reportForm.getSort());
|
|
|
+ commonTitleReportVo.setDataType(reportForm.getDataType());
|
|
|
+ commonTitleReportVo.setDecimalPlace(reportForm.getDecimalPlace());
|
|
|
+ commonTitleReportVo.setPermil(reportForm.getPermil());
|
|
|
+ return commonTitleReportVo;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+// List<CommonTitleReportVo> commonTitleReportVos = BeanUtil.convertList(reportFormList,CommonTitleReportVo.class);
|
|
|
Map<Long, List<CommonTitleReportVo>> collect = commonTitleReportVos.stream().collect(Collectors.groupingBy(CommonTitleReportVo::getParentReportId));
|
|
|
List<CommonTitleReportVo> titleReportVoList = collect.get(NumberConstant.ZERO_L);
|
|
|
for (CommonTitleReportVo reportVo : titleReportVoList) {
|
|
@@ -1278,9 +1521,9 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
Map<Long, List<CostDepartmentProfit>> collectGroup = departmentProfits.stream().collect(Collectors.groupingBy(CostDepartmentProfit::getReportId));
|
|
|
for (ReportForm reportForm : reportFormList) {
|
|
|
Integer hide = reportForm.getHide();
|
|
|
- if(hide.equals(NumberConstant.ONE)){
|
|
|
+ if (hide.equals(NumberConstant.ONE)) {
|
|
|
List<CostDepartmentProfit> costDepartmentProfits = collectGroup.get(reportForm.getId());
|
|
|
- if(!CollectionUtils.isEmpty(costDepartmentProfits)) {
|
|
|
+ if (!CollectionUtils.isEmpty(costDepartmentProfits)) {
|
|
|
filterProfit.addAll(costDepartmentProfits);
|
|
|
}
|
|
|
}
|
|
@@ -1305,7 +1548,7 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
throw new CostException("未找到对应分摊层级责任中心");
|
|
|
}
|
|
|
//获取授权的责任中心
|
|
|
- responsibilityList=userResponsibilityRightService.getAuthorizedResponsibility(responsibilityList);
|
|
|
+ responsibilityList = userResponsibilityRightService.getAuthorizedResponsibility(responsibilityList);
|
|
|
//获取当前院区所有的责任中心
|
|
|
List<Responsibility> responsibilityAllList = responsibilityService.list(new QueryWrapper<Responsibility>().lambda()
|
|
|
.eq(Responsibility::getHospId, hospId));
|
|
@@ -1619,7 +1862,7 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
throw new CostException("未找到对应分摊层级责任中心");
|
|
|
}
|
|
|
//获取授权的责任中心
|
|
|
- responsibilityList=userResponsibilityRightService.getAuthorizedResponsibility(responsibilityList);
|
|
|
+ responsibilityList = userResponsibilityRightService.getAuthorizedResponsibility(responsibilityList);
|
|
|
List<Responsibility> responsibilityAllList = responsibilityService.list(new QueryWrapper<Responsibility>().lambda()
|
|
|
.eq(Responsibility::getHospId, hospId));
|
|
|
Map<Long, Responsibility> map = responsibilityAllList.stream().collect(Collectors.toMap(Responsibility::getId, responsibility -> responsibility, (a, b) -> b));
|
|
@@ -1703,10 +1946,10 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
Map<Long, List<CostDepartmentProfit>> collect1 = departmentProfits.stream().collect(Collectors.groupingBy(CostDepartmentProfit::getReportId));
|
|
|
for (ReportForm reportForm : reportFormList) {
|
|
|
Integer hide = reportForm.getHide();
|
|
|
- if(hide.equals(NumberConstant.ONE)){
|
|
|
+ if (hide.equals(NumberConstant.ONE)) {
|
|
|
// filterProfit.addAll(collect1.get(reportForm.getId()));
|
|
|
List<CostDepartmentProfit> costDepartmentProfits = collect1.get(reportForm.getId());
|
|
|
- if(!CollectionUtils.isEmpty(costDepartmentProfits)) {
|
|
|
+ if (!CollectionUtils.isEmpty(costDepartmentProfits)) {
|
|
|
filterProfit.addAll(costDepartmentProfits);
|
|
|
}
|
|
|
}
|
|
@@ -1715,11 +1958,22 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
|
|
|
Map<Long, Integer> sortMap = reportFormList.stream().collect(Collectors.toMap(ReportForm::getId, ReportForm::getSort, (a, b) -> b));
|
|
|
Map<Long, String> descriptionMap = reportFormList.stream().collect(Collectors.toMap(ReportForm::getId, reportForm -> !StringUtils.isEmpty(reportForm.getDescription()) ? reportForm.getDescription() : "", (a, b) -> b));
|
|
|
+ Map<Long, List<ReportForm>> reportIdMap = reportFormList.stream().collect(Collectors.groupingBy(ReportForm::getId));
|
|
|
|
|
|
List<CostProfitVo> costProfitVos = BeanUtil.convertList(filterProfit, CostProfitVo.class);
|
|
|
costProfitVos.forEach(profitVo -> {
|
|
|
profitVo.setDescription(descriptionMap.get(profitVo.getReportId()));
|
|
|
profitVo.setSort(sortMap.get(profitVo.getReportId()));
|
|
|
+ List<ReportForm> profitReportFormList = reportIdMap.get(profitVo.getReportId());
|
|
|
+ if (!CollectionUtils.isEmpty(profitReportFormList)) {
|
|
|
+ profitVo.setDataType(profitReportFormList.get(NumberConstant.ZERO).getDataType());
|
|
|
+ profitVo.setDecimalPlace(profitReportFormList.get(NumberConstant.ZERO).getDecimalPlace());
|
|
|
+ profitVo.setPermil(profitReportFormList.get(NumberConstant.ZERO).getPermil());
|
|
|
+ } else {
|
|
|
+ profitVo.setDataType(NumberConstant.ONE);
|
|
|
+ profitVo.setDecimalPlace(NumberConstant.TWO);
|
|
|
+ profitVo.setPermil(NumberConstant.ONE);
|
|
|
+ }
|
|
|
});
|
|
|
Map<Long, List<CostProfitVo>> collect = costProfitVos.stream().collect(Collectors.groupingBy(CostProfitVo::getReportParentId));
|
|
|
List<CostProfitVo> costProfitParentVos = collect.get(NumberConstant.ZERO_L);
|
|
@@ -1773,15 +2027,16 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
if (CollUtil.isEmpty(reportFormList)) {
|
|
|
throw new CostException(500, "损益表未找到");
|
|
|
}
|
|
|
+ Map<Long, List<ReportForm>> reportIdMap = reportFormList.stream().collect(Collectors.groupingBy(ReportForm::getId));
|
|
|
List<CostDepartmentProfit> filterProfit = new ArrayList<>();
|
|
|
|
|
|
Map<Long, List<CostDepartmentProfit>> collect1 = departmentProfits.stream().collect(Collectors.groupingBy(CostDepartmentProfit::getReportId));
|
|
|
for (ReportForm reportForm : reportFormList) {
|
|
|
Integer hide = reportForm.getHide();
|
|
|
- if(hide.equals(NumberConstant.ONE)){
|
|
|
+ if (hide.equals(NumberConstant.ONE)) {
|
|
|
// filterProfit.addAll(collect1.get(reportForm.getId()));
|
|
|
List<CostDepartmentProfit> costDepartmentProfits = collect1.get(reportForm.getId());
|
|
|
- if(!CollectionUtils.isEmpty(costDepartmentProfits)) {
|
|
|
+ if (!CollectionUtils.isEmpty(costDepartmentProfits)) {
|
|
|
filterProfit.addAll(costDepartmentProfits);
|
|
|
}
|
|
|
}
|
|
@@ -1794,6 +2049,16 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
costProfitVos.forEach(profitVo -> {
|
|
|
profitVo.setDescription(descriptionMap.get(profitVo.getReportId()));
|
|
|
profitVo.setSort(sortMap.get(profitVo.getReportId()));
|
|
|
+ List<ReportForm> profitReportFormList = reportIdMap.get(profitVo.getReportId());
|
|
|
+ if (!CollectionUtils.isEmpty(profitReportFormList)) {
|
|
|
+ profitVo.setDataType(profitReportFormList.get(NumberConstant.ZERO).getDataType());
|
|
|
+ profitVo.setDecimalPlace(profitReportFormList.get(NumberConstant.ZERO).getDecimalPlace());
|
|
|
+ profitVo.setPermil(profitReportFormList.get(NumberConstant.ZERO).getPermil());
|
|
|
+ } else {
|
|
|
+ profitVo.setDataType(NumberConstant.ONE);
|
|
|
+ profitVo.setDecimalPlace(NumberConstant.TWO);
|
|
|
+ profitVo.setPermil(NumberConstant.ONE);
|
|
|
+ }
|
|
|
});
|
|
|
Map<Long, List<CostProfitVo>> collect = costProfitVos.stream().collect(Collectors.groupingBy(CostProfitVo::getReportParentId));
|
|
|
List<CostProfitVo> costProfitParentVos = collect.get(NumberConstant.ZERO_L);
|
|
@@ -1810,6 +2075,7 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
BatchCostProfitResponse response = new BatchCostProfitResponse();
|
|
|
response.setComputeDate(beginComputeDate);
|
|
|
response.setProfitVoList(costProfitParentVos);
|
|
|
+ response.setAllowDrillDown(true);
|
|
|
responses.add(response);
|
|
|
return responses;
|
|
|
} else {
|
|
@@ -1819,6 +2085,7 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
throw new CostException("开始日期不能大于结束日期");
|
|
|
}
|
|
|
List<String> intervalMonthList = DateUtils.getIntervalMonthList(date, endDate);
|
|
|
+ List<CostProfitVo> allCostProfitVo=new ArrayList<>();
|
|
|
if (!CollectionUtils.isEmpty(intervalMonthList)) {
|
|
|
for (String computeDates : intervalMonthList) {
|
|
|
Integer year = ComputeDateUtils.getComputeYear(computeDates);
|
|
@@ -1835,15 +2102,16 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
if (CollUtil.isEmpty(reportFormList)) {
|
|
|
throw new CostException(500, "损益表未找到");
|
|
|
}
|
|
|
+ Map<Long, List<ReportForm>> reportIdMap = reportFormList.stream().collect(Collectors.groupingBy(ReportForm::getId));
|
|
|
List<CostDepartmentProfit> filterProfit = new ArrayList<>();
|
|
|
|
|
|
Map<Long, List<CostDepartmentProfit>> collect1 = departmentProfits.stream().collect(Collectors.groupingBy(CostDepartmentProfit::getReportId));
|
|
|
for (ReportForm reportForm : reportFormList) {
|
|
|
Integer hide = reportForm.getHide();
|
|
|
- if(hide.equals(NumberConstant.ONE)){
|
|
|
+ if (hide.equals(NumberConstant.ONE)) {
|
|
|
// filterProfit.addAll(collect1.get(reportForm.getId()));
|
|
|
List<CostDepartmentProfit> costDepartmentProfits = collect1.get(reportForm.getId());
|
|
|
- if(!CollectionUtils.isEmpty(costDepartmentProfits)) {
|
|
|
+ if (!CollectionUtils.isEmpty(costDepartmentProfits)) {
|
|
|
filterProfit.addAll(costDepartmentProfits);
|
|
|
}
|
|
|
}
|
|
@@ -1855,7 +2123,19 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
costProfitVos.forEach(profitVo -> {
|
|
|
profitVo.setDescription(descriptionMap.get(profitVo.getReportId()));
|
|
|
profitVo.setSort(sortMap.get(profitVo.getReportId()));
|
|
|
+ List<ReportForm> profitReportFormList = reportIdMap.get(profitVo.getReportId());
|
|
|
+ if (!CollectionUtils.isEmpty(profitReportFormList)) {
|
|
|
+ profitVo.setDataType(profitReportFormList.get(NumberConstant.ZERO).getDataType());
|
|
|
+ profitVo.setDecimalPlace(profitReportFormList.get(NumberConstant.ZERO).getDecimalPlace());
|
|
|
+ profitVo.setPermil(profitReportFormList.get(NumberConstant.ZERO).getPermil());
|
|
|
+ } else {
|
|
|
+ profitVo.setDataType(NumberConstant.ONE);
|
|
|
+ profitVo.setDecimalPlace(NumberConstant.TWO);
|
|
|
+ profitVo.setPermil(NumberConstant.ONE);
|
|
|
+ }
|
|
|
});
|
|
|
+ //记录所有月份的科室损益数据
|
|
|
+ allCostProfitVo.addAll(costProfitVos);
|
|
|
Map<Long, List<CostProfitVo>> collect = costProfitVos.stream().collect(Collectors.groupingBy(CostProfitVo::getReportParentId));
|
|
|
List<CostProfitVo> costProfitParentVos = collect.get(NumberConstant.ZERO_L);
|
|
|
collect.remove(NumberConstant.ZERO_L);
|
|
@@ -1871,8 +2151,19 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
BatchCostProfitResponse response = new BatchCostProfitResponse();
|
|
|
response.setComputeDate(computeDates);
|
|
|
response.setProfitVoList(costProfitParentVos);
|
|
|
+ response.setAllowDrillDown(true);
|
|
|
responses.add(response);
|
|
|
}
|
|
|
+ //获取月度汇总数据
|
|
|
+ List<CostProfitVo> costProfitVos = generateSummaryForMultipleMonths(allCostProfitVo);
|
|
|
+ if(!CollectionUtils.isEmpty(costProfitVos)){
|
|
|
+ BatchCostProfitResponse response = new BatchCostProfitResponse();
|
|
|
+ response.setComputeDate(String.format("%s至%s", beginComputeDate, endComputeDate));
|
|
|
+ response.setProfitVoList(costProfitVos);
|
|
|
+ response.setAllowDrillDown(false);
|
|
|
+ response.setMonthlyAccumulation(true);
|
|
|
+ responses.add(NumberConstant.ZERO,response);
|
|
|
+ }
|
|
|
return responses;
|
|
|
|
|
|
} else {
|
|
@@ -1881,6 +2172,69 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取树状结构的科室损益数据
|
|
|
+ * @param costProfitVos
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<CostProfitVo> getCostProfitVoTree(List<CostProfitVo> costProfitVos){
|
|
|
+ // 参数校验
|
|
|
+ if (CollectionUtils.isEmpty(costProfitVos)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ Map<Long, List<CostProfitVo>> collect = costProfitVos.stream().collect(Collectors.groupingBy(CostProfitVo::getReportParentId));
|
|
|
+ List<CostProfitVo> costProfitParentVos = collect.get(NumberConstant.ZERO_L);
|
|
|
+ collect.remove(NumberConstant.ZERO_L);
|
|
|
+ for (CostProfitVo costProfitVo : costProfitParentVos) {
|
|
|
+ List<CostProfitVo> costProfitVo1 = collect.get(costProfitVo.getReportId());
|
|
|
+ if (!CollectionUtils.isEmpty(costProfitVo1)) {
|
|
|
+ costProfitVo.setChildren(setChildren(costProfitVo1, collect));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(costProfitParentVos)) {
|
|
|
+ costProfitParentVos.sort(Comparator.comparing(CostProfitVo::getSort, Comparator.nullsLast(Integer::compareTo)));
|
|
|
+ }
|
|
|
+ return costProfitParentVos;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成多月份汇总的科室损益数据
|
|
|
+ *
|
|
|
+ * @param allCostProfitVo 原始数据列表
|
|
|
+ * @return 汇总后的科室损益数据
|
|
|
+ */
|
|
|
+ private List<CostProfitVo> generateSummaryForMultipleMonths(List<CostProfitVo> allCostProfitVo){
|
|
|
+ // 参数校验
|
|
|
+ if (CollectionUtils.isEmpty(allCostProfitVo)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ List<CostProfitVo> profitVoList=new ArrayList<>() ;
|
|
|
+ Map<Long, List<CostProfitVo>> reportGroup = allCostProfitVo.stream().collect(Collectors.groupingBy(CostProfitVo::getReportId));
|
|
|
+ reportGroup.forEach((reportId, profitVos) -> {
|
|
|
+ CostProfitVo costProfitVo = BeanUtil.convertObj(profitVos.get(NumberConstant.ZERO), CostProfitVo.class);
|
|
|
+ BigDecimal totalAmount = profitVos.stream().map(vo -> Optional.ofNullable(vo.getAmount()).orElse(BigDecimal.ZERO))
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal totalBudgetAmount = profitVos.stream().map(vo -> Optional.ofNullable(vo.getBudgetAmount()).orElse(BigDecimal.ZERO))
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal totalPrevPeriodAmount = profitVos.stream().map(vo -> Optional.ofNullable(vo.getPrevPeriodAmount()).orElse(BigDecimal.ZERO))
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal totalSamePeriodAmount = profitVos.stream().map(vo -> Optional.ofNullable(vo.getSamePeriodAmount()).orElse(BigDecimal.ZERO))
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ costProfitVo.setAmount(totalAmount);
|
|
|
+ costProfitVo.setBudgetAmount(totalBudgetAmount);
|
|
|
+ costProfitVo.setPrevPeriodAmount(totalPrevPeriodAmount);
|
|
|
+ costProfitVo.setSamePeriodAmount(totalSamePeriodAmount);
|
|
|
+ costProfitVo.setCompletionRate(calculateRate(costProfitVo.getAmount(), costProfitVo.getBudgetAmount()));
|
|
|
+ costProfitVo.setMomRate(calculateRate(costProfitVo.getAmount().subtract(costProfitVo.getPrevPeriodAmount()), costProfitVo.getPrevPeriodAmount()));
|
|
|
+ costProfitVo.setYoyRate(calculateRate(costProfitVo.getAmount().subtract(costProfitVo.getSamePeriodAmount()), costProfitVo.getSamePeriodAmount()));
|
|
|
+ profitVoList.add(costProfitVo);
|
|
|
+ });
|
|
|
+ //转成树状结构
|
|
|
+ List<CostProfitVo> costProfitVoTree = getCostProfitVoTree(profitVoList);
|
|
|
+ return costProfitVoTree;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public Object getRedirectData(String computeDate, Long reportId, Long hospId, String reportType, String responsibilityCode) {
|
|
|
//查询报表项目
|
|
@@ -2167,7 +2521,7 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
throw new CostException("未找到对应分摊层级责任中心");
|
|
|
}
|
|
|
//获取授权的责任中心
|
|
|
- responsibilityList=userResponsibilityRightService.getAuthorizedResponsibility(responsibilityList);
|
|
|
+ responsibilityList = userResponsibilityRightService.getAuthorizedResponsibility(responsibilityList);
|
|
|
List<Responsibility> responsibilityAllList = responsibilityService.list(new QueryWrapper<Responsibility>().lambda()
|
|
|
.eq(Responsibility::getHospId, hospId));
|
|
|
Map<Long, Responsibility> map = responsibilityAllList.stream().collect(Collectors.toMap(Responsibility::getId, responsibility -> responsibility, (a, b) -> b));
|
|
@@ -2201,7 +2555,14 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
if (!CollectionUtils.isEmpty(responsibilities)) {
|
|
|
commonResponsibilityReportVo.setChild(getChildTitle(responsibilities, responsibilityGroup));
|
|
|
} else {
|
|
|
- commonResponsibilityReportVo.setChild(setDefalutChildList(responsibility));
|
|
|
+ //要显示占比时自动生成默认金额占比层
|
|
|
+ if (IsShowPercent()) {
|
|
|
+ commonResponsibilityReportVo.setChild(setDefalutChildList(responsibility));
|
|
|
+ } else {
|
|
|
+ //不显示占比时,直接责任中心作为金额层
|
|
|
+ commonResponsibilityReportVo.setResponsibilityCode(commonResponsibilityReportVo.getResponsibilityCode() + AMOUNT_FIELD);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
list.add(commonResponsibilityReportVo);
|
|
|
}
|
|
@@ -2531,6 +2892,30 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 是否显示占比
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public boolean IsShowPercent() {
|
|
|
+ String parameterValue = centerService.getParameterValue(ParameterConstant.SHOW_PERCENT);
|
|
|
+ return NumberConstant.ONE_S.equals(parameterValue);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否需要代码计算
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public boolean IsNeedCalc(String reportType) {
|
|
|
+ String parameterValue = centerService.getParameterValue(ParameterConstant.SQL_CALC_REPORT_TYPE);
|
|
|
+ if(StringUtils.isEmpty(parameterValue)){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ //不需计算的报表类型列表
|
|
|
+ List<String> nonCalcReportTypeList = Arrays.stream(parameterValue.split(SplitConstant.SEPARATOR_VERTICALLINE)).collect(Collectors.toList());
|
|
|
+ return !nonCalcReportTypeList.contains(reportType);
|
|
|
+ }
|
|
|
+
|
|
|
private List<CommonResponsibilityReportVo> getChildTitle(List<Responsibility> responsibilities, Map<Long, List<Responsibility>> responsibilityGroup) {
|
|
|
List<CommonResponsibilityReportVo> list = new ArrayList<>();
|
|
|
for (Responsibility responsibility : responsibilities) {
|
|
@@ -2542,8 +2927,15 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
if (!CollectionUtils.isEmpty(responsibilityChild)) {
|
|
|
commonResponsibilityReportVo.setChild(getChildTitle(responsibilityChild, responsibilityGroup));
|
|
|
} else {
|
|
|
- //添加金额占比
|
|
|
- commonResponsibilityReportVo.setChild(setDefalutChildList(responsibility));
|
|
|
+// //添加金额占比
|
|
|
+// commonResponsibilityReportVo.setChild(setDefalutChildList(responsibility));
|
|
|
+ //要显示占比时自动生成默认金额占比层
|
|
|
+ if (IsShowPercent()) {
|
|
|
+ commonResponsibilityReportVo.setChild(setDefalutChildList(responsibility));
|
|
|
+ } else {
|
|
|
+ //不显示占比时,直接责任中心作为金额层
|
|
|
+ commonResponsibilityReportVo.setResponsibilityCode(commonResponsibilityReportVo.getResponsibilityCode() + AMOUNT_FIELD);
|
|
|
+ }
|
|
|
}
|
|
|
list.add(commonResponsibilityReportVo);
|
|
|
}
|
|
@@ -3136,4 +3528,137 @@ public class CostDepartmentProfitServiceImpl extends ServiceImpl<CostDepartmentP
|
|
|
}
|
|
|
T.sort(Comparator.comparing(CostResponsibilityProfitVo::getSort, Comparator.nullsLast(Integer::compareTo)));
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object getBatchComputeProfitListByYear(String startYear, String endYear, String reportType, String responsibilityCode) {
|
|
|
+ Integer integerReportType = Integer.valueOf(reportType);
|
|
|
+ Long hospId = UserContext.getHospId();
|
|
|
+ List<BatchCostProfitResponse> responses = new ArrayList<>();
|
|
|
+ // 解析起止年份
|
|
|
+ int startY = Integer.parseInt(startYear);
|
|
|
+ int endY = Integer.parseInt(endYear);
|
|
|
+
|
|
|
+ if (startY > endY) {
|
|
|
+ throw new CostException(500, "起始年份不能大于结束年份");
|
|
|
+ }
|
|
|
+ // 获取报表配置
|
|
|
+ List<ReportForm> reportFormList = reportFormService.list(new QueryWrapper<ReportForm>().lambda()
|
|
|
+ .eq(ReportForm::getHospId, hospId)
|
|
|
+ .eq(ReportForm::getDeleteTime, NumberConstant.ZERO)
|
|
|
+ .eq(ReportForm::getReportType, integerReportType));
|
|
|
+ if (CollUtil.isEmpty(reportFormList)) {
|
|
|
+ throw new CostException(500, "损益表未找到");
|
|
|
+ }
|
|
|
+ Map<Long, ReportForm> reportMap = reportFormList.stream()
|
|
|
+ .collect(Collectors.toMap(ReportForm::getId, report -> report));
|
|
|
+ // 取非隐藏的报表项目ID
|
|
|
+ List<Long> activeReportIdList = reportFormList.stream()
|
|
|
+ .filter(report -> NumberConstant.ONE.equals(report.getHide()))
|
|
|
+ .map(ReportForm::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 获取当前年份和上一年度的汇总数据(一次性查询)
|
|
|
+ List<CostProfitVo> summaryList = this.baseMapper.getAnnualSummaryByYearRange(startY, endY, hospId, integerReportType, responsibilityCode);
|
|
|
+ List<CostProfitVo> preYearSummaryList = this.baseMapper.getAnnualSummaryByYearRange(startY - 1, endY - 1, hospId, integerReportType, responsibilityCode);
|
|
|
+
|
|
|
+ // 按年份分组处理数据
|
|
|
+ Map<Integer, List<CostProfitVo>> currentYearMap = new HashMap<>();
|
|
|
+ Map<Integer, List<CostProfitVo>> preYearMap = new HashMap<>();
|
|
|
+
|
|
|
+ // 将结果按年份分组
|
|
|
+ if (!CollectionUtils.isEmpty(summaryList)) {
|
|
|
+ currentYearMap = summaryList.stream()
|
|
|
+ .collect(Collectors.groupingBy(CostProfitVo::getYear));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!CollectionUtils.isEmpty(preYearSummaryList)) {
|
|
|
+ preYearMap = preYearSummaryList.stream()
|
|
|
+ .collect(Collectors.groupingBy(CostProfitVo::getYear));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 遍历每个年份进行数据处理
|
|
|
+ for (int year = startY; year <= endY; year++) {
|
|
|
+ int previousYear = year - 1;
|
|
|
+
|
|
|
+ List<CostProfitVo> currentYearList = currentYearMap.get(year);
|
|
|
+ List<CostProfitVo> previousYearList = preYearMap.get(previousYear);
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(currentYearList)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 只处理非隐藏的项目
|
|
|
+ List<CostProfitVo> activeCostProfitVo = currentYearList.stream()
|
|
|
+ .filter(vo -> activeReportIdList.contains(vo.getReportId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isEmpty(activeCostProfitVo)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建映射以便快速查找上一年的数据
|
|
|
+ Map<Long, CostProfitVo> preYearCostProfitMap = new HashMap<>();
|
|
|
+ if (!CollectionUtils.isEmpty(previousYearList)) {
|
|
|
+ preYearCostProfitMap = previousYearList.stream()
|
|
|
+ .collect(Collectors.toMap(CostProfitVo::getReportId, costProfitVo -> costProfitVo));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 计算完成率、环比、同比
|
|
|
+ for (CostProfitVo vo : currentYearList) {
|
|
|
+ // 设置同期数据
|
|
|
+ if (preYearCostProfitMap.containsKey(vo.getReportId())) {
|
|
|
+ vo.setSamePeriodAmount(preYearCostProfitMap.get(vo.getReportId()).getAmount());
|
|
|
+ } else {
|
|
|
+ vo.setSamePeriodAmount(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+
|
|
|
+ vo.setCompletionRate(calculateRate(vo.getAmount(), vo.getBudgetAmount()));
|
|
|
+ vo.setMomRate(calculateRate(vo.getAmount().subtract(vo.getPrevPeriodAmount()), vo.getPrevPeriodAmount()));
|
|
|
+ vo.setYoyRate(calculateRate(vo.getAmount().subtract(vo.getSamePeriodAmount()), vo.getSamePeriodAmount()));
|
|
|
+
|
|
|
+ // 设置报表相关属性
|
|
|
+ ReportForm reportForm = reportMap.get(vo.getReportId());
|
|
|
+ if (reportForm != null) {
|
|
|
+ vo.setDescription(reportForm.getDescription());
|
|
|
+ vo.setSort(reportForm.getSort());
|
|
|
+ vo.setPermil(reportForm.getPermil());
|
|
|
+ vo.setDataType(reportForm.getDataType());
|
|
|
+ vo.setDecimalPlace(reportForm.getDecimalPlace());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建树状结构
|
|
|
+ Map<Long, List<CostProfitVo>> collect = currentYearList.stream()
|
|
|
+ .collect(Collectors.groupingBy(CostProfitVo::getReportParentId));
|
|
|
+ List<CostProfitVo> costProfitParentVos = collect.get(NumberConstant.ZERO_L);
|
|
|
+ collect.remove(NumberConstant.ZERO_L);
|
|
|
+
|
|
|
+ if (!CollectionUtils.isEmpty(costProfitParentVos)) {
|
|
|
+ costProfitParentVos.forEach(parentVo -> {
|
|
|
+ parentVo.setChildren(collect.get(parentVo.getReportId()));
|
|
|
+ });
|
|
|
+ costProfitParentVos.sort(Comparator.comparing(CostProfitVo::getSort, Comparator.nullsLast(Integer::compareTo)));
|
|
|
+ }
|
|
|
+
|
|
|
+ BatchCostProfitResponse response = new BatchCostProfitResponse();
|
|
|
+ response.setComputeDate(String.valueOf(year));
|
|
|
+ response.setProfitVoList(costProfitParentVos);
|
|
|
+ response.setAllowDrillDown(false);
|
|
|
+ responses.add(response);
|
|
|
+ }
|
|
|
+
|
|
|
+ return responses;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 安全地计算百分比:避免除零错误
|
|
|
+ */
|
|
|
+ private BigDecimal calculateRate(BigDecimal current, BigDecimal base) {
|
|
|
+ if (base == null || base.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ BigDecimal rate = current.divide(base, 4, RoundingMode.HALF_UP);
|
|
|
+ return rate.setScale(4, RoundingMode.HALF_UP);
|
|
|
+ }
|
|
|
+
|
|
|
}
|