|
@@ -30,17 +30,18 @@ import com.kcim.dao.model.*;
|
|
|
import com.kcim.service.*;
|
|
|
import com.kcim.vo.AllocationQueryReportVO;
|
|
|
import com.kcim.vo.HospProfitAndLossVo;
|
|
|
+import com.kcim.vo.HospProfitVO;
|
|
|
import com.kcim.vo.RelationVO;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.fileupload.FileItem;
|
|
|
import org.apache.commons.fileupload.FileItemFactory;
|
|
|
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
-import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
|
|
|
@@ -53,6 +54,7 @@ import java.text.DecimalFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
+import java.util.function.UnaryOperator;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
@@ -357,7 +359,6 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
|
private void calcByAccount(Long hospId, ReportForm reportForm, List<IncomeCollection> incomes, List<HospProfitAndLoss> list, List<AllocationQuery> allocationQueries, int month, int year) {
|
|
|
// check 这个医院是否有对应的损益标识
|
|
|
reportFormService.checkExistLoss(hospId);
|
|
|
-
|
|
|
// 报表项目关联的会计科目对象
|
|
|
List<RelationVO> accountRelations = reportRelationService.getAccountRelation(reportForm.getId(), hospId);
|
|
|
if (accountRelations.isEmpty()) {
|
|
@@ -393,7 +394,6 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
|
@Override
|
|
|
public PageUtils getHospProfits(Integer current, Integer pageSize, String date, Long hospId) {
|
|
|
reportFormService.checkExistLoss(hospId);
|
|
|
-
|
|
|
DateTime parse = DateUtil.parse(date);
|
|
|
int year = DateUtil.year(parse);
|
|
|
int month = DateUtil.month(parse) + 1;
|
|
@@ -557,7 +557,8 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
|
setHospRowList(hospAllList, titleEntities, rowList);
|
|
|
|
|
|
try {
|
|
|
- ExcelPoiUtil excelTool = new ExcelPoiUtil("全院损益");
|
|
|
+ ExcelPoiUtil excelTool = new ExcelPoiUtil();
|
|
|
+ excelTool.setTitle("全院损益");
|
|
|
Map<String, String> param = ImmutableMap.<String, String>builder().put("id", "id").put("pid", "pid")
|
|
|
.put("content", "content").put("fieldName", "fieldName").put("width", "width").build();
|
|
|
|
|
@@ -732,43 +733,43 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
|
}
|
|
|
//相 同key 的数值 进行汇总
|
|
|
// for (int i = 0; i < 2; i++) {
|
|
|
- Map<String, String> hospMap = new HashMap<>();
|
|
|
- for (TitleEntity titleEntity : titleEntities) {
|
|
|
- AtomicReference<BigDecimal> total = new AtomicReference<>(new BigDecimal("0.00"));
|
|
|
- for (Map<String, String> map : amountRowList) {
|
|
|
- String s = map.get(titleEntity.getFieldName());
|
|
|
- if (!titleEntity.getFieldName().equals("child") && !titleEntity.getFieldName().equals("parent") && !titleEntity.getFieldName().equals("itemType")) {
|
|
|
+ Map<String, String> hospMap = new HashMap<>();
|
|
|
+ for (TitleEntity titleEntity : titleEntities) {
|
|
|
+ AtomicReference<BigDecimal> total = new AtomicReference<>(new BigDecimal("0.00"));
|
|
|
+ for (Map<String, String> map : amountRowList) {
|
|
|
+ String s = map.get(titleEntity.getFieldName());
|
|
|
+ if (!titleEntity.getFieldName().equals("child") && !titleEntity.getFieldName().equals("parent") && !titleEntity.getFieldName().equals("itemType")) {
|
|
|
// if(StringUtils.isEmpty(s)){
|
|
|
// total.updateAndGet(v -> v.add(BigDecimal.ZERO));
|
|
|
// }else {
|
|
|
- total.updateAndGet(v -> v.add(new BigDecimal(s)));
|
|
|
+ total.updateAndGet(v -> v.add(new BigDecimal(s)));
|
|
|
// }
|
|
|
- }
|
|
|
}
|
|
|
- if (titleEntity.getFieldName().equals("parent")) {
|
|
|
- hospMap.put("parent", "全院");
|
|
|
- } else if (titleEntity.getFieldName().equals("child")) {
|
|
|
- hospMap.put("child", "全院");
|
|
|
- } else if (titleEntity.getFieldName().equals("itemType")) {
|
|
|
+ }
|
|
|
+ if (titleEntity.getFieldName().equals("parent")) {
|
|
|
+ hospMap.put("parent", "全院");
|
|
|
+ } else if (titleEntity.getFieldName().equals("child")) {
|
|
|
+ hospMap.put("child", "全院");
|
|
|
+ } else if (titleEntity.getFieldName().equals("itemType")) {
|
|
|
// if (i == 0) {
|
|
|
- hospMap.put("itemType", "金额");
|
|
|
+ hospMap.put("itemType", "金额");
|
|
|
// } else {
|
|
|
// hospMap.put("itemType", "占比");
|
|
|
// }
|
|
|
- } else {
|
|
|
+ } else {
|
|
|
// if (i == 0) {
|
|
|
- hospMap.put(titleEntity.getFieldName(), total.get().toString());
|
|
|
- if(!CollectionUtils.isEmpty(hospAllList)){
|
|
|
- for (HospProfitAndLoss data : hospAllList) {
|
|
|
- hospMap.put(data.getReportNum().toString(), data.getAmount().setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
- }
|
|
|
- }
|
|
|
+ hospMap.put(titleEntity.getFieldName(), total.get().toString());
|
|
|
+ if (!CollectionUtils.isEmpty(hospAllList)) {
|
|
|
+ for (HospProfitAndLoss data : hospAllList) {
|
|
|
+ hospMap.put(data.getReportNum().toString(), data.getAmount().setScale(2, RoundingMode.HALF_UP).toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
// } else {
|
|
|
// hospMap.put(titleEntity.getFieldName(), "");
|
|
|
// }
|
|
|
- }
|
|
|
}
|
|
|
- rowList.add(hospMap);
|
|
|
+ }
|
|
|
+ rowList.add(hospMap);
|
|
|
// }
|
|
|
}
|
|
|
|
|
@@ -923,6 +924,177 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
|
return new PageUtils(pageUtils);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Object getHospProfitResponsibilities(String responsibilityName) {
|
|
|
+ List<Responsibility> responsibilityList = responsibilityService.list(new QueryWrapper<Responsibility>().lambda()
|
|
|
+ .eq(Responsibility::getHospId, UserContext.getHospId())
|
|
|
+ .and(q -> q.eq(Responsibility::getStatus, NumberConstant.ONE).or().eq(Responsibility::getStatus, null))
|
|
|
+ .like(StrUtil.isNotBlank(responsibilityName), Responsibility::getResponsibilityName, responsibilityName));
|
|
|
+ List<Responsibility> responsibilityAllList = responsibilityService.list(new QueryWrapper<Responsibility>().lambda()
|
|
|
+ .eq(Responsibility::getHospId, UserContext.getHospId()));
|
|
|
+ Map<Long, Responsibility> map = responsibilityAllList.stream().collect(Collectors.toMap(Responsibility::getId, responsibility -> responsibility, (a, b) -> b));
|
|
|
+ List<Responsibility> addList = new ArrayList<>();
|
|
|
+ for (Responsibility responsibility : responsibilityList) {
|
|
|
+ Responsibility responsibility1 = map.get(responsibility.getParentId());
|
|
|
+ if (Objects.nonNull(responsibility1)) {
|
|
|
+ addList.add(responsibility1);
|
|
|
+ if (!responsibility1.getParentId().equals(NumberConstant.ZERO_L)) {
|
|
|
+ getResponsibilityParent(responsibility1, map, addList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(addList)) {
|
|
|
+ //去重
|
|
|
+ List<Responsibility> collect = addList.stream().distinct().collect(Collectors.toList());
|
|
|
+ responsibilityList.addAll(collect);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Map<Long, List<Responsibility>> collect = responsibilityList.stream().collect(Collectors.groupingBy(Responsibility::getParentId));
|
|
|
+ List<Responsibility> responsibilities = collect.get(NumberConstant.ZERO_L);
|
|
|
+ collect.remove(NumberConstant.ZERO_L);
|
|
|
+ for (Responsibility responsibility : responsibilities) {
|
|
|
+ List<Responsibility> responsibilities1 = collect.get(responsibility.getId());
|
|
|
+ if (!CollectionUtils.isEmpty(responsibilities1)) {
|
|
|
+ responsibility.setChildren(setResponsibilityChildren(responsibilities1, collect));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ responsibilitySort(responsibilities);
|
|
|
+ return responsibilities;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object getHospProfitList(String computeDate, Long hospId, String reportType) {
|
|
|
+ DateTime parse = DateUtil.parse(computeDate);
|
|
|
+ int year = DateUtil.year(parse);
|
|
|
+ int month = DateUtil.month(parse) + 1;
|
|
|
+// Integer year = ComputeDateUtils.getComputeYear(computeDate);
|
|
|
+// Integer month = ComputeDateUtils.getComputeMonth(computeDate);
|
|
|
+ // 查询所有的全院损益数据 内存溢出问题
|
|
|
+ List<HospProfitAndLoss> hospProfitAndLosses = getAllDataByDate(year, month, hospId);
|
|
|
+ if (CollectionUtils.isEmpty(hospProfitAndLosses)) {
|
|
|
+ throw new CostException(500, "未进行全院损益计算");
|
|
|
+ }
|
|
|
+ //判断是否有全院的数据 有单独取出另算
|
|
|
+ List<HospProfitAndLoss> hospAllList = hospProfitAndLosses.stream().filter(f -> f.getResponsibilityCode().equals("-1")).collect(Collectors.toList());
|
|
|
+ if (!CollectionUtils.isEmpty(hospAllList)) {
|
|
|
+ hospProfitAndLosses.removeAll(hospAllList);
|
|
|
+ }
|
|
|
+ //查询全院损益报表配置
|
|
|
+ Integer integerReportType = Integer.valueOf(reportType);
|
|
|
+ List<ReportForm> reportFormList = reportFormService.list(new QueryWrapper<ReportForm>().lambda()
|
|
|
+ .eq(ReportForm::getHospId, hospId)
|
|
|
+ .eq(ReportForm::getReportType, integerReportType).eq(ReportForm::getHide, NumberConstant.ONE));
|
|
|
+ if (CollUtil.isEmpty(reportFormList)) {
|
|
|
+ throw new CostException(500, "未找到全院损益表配置");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<HospProfitVO> costProfitVos = BeanUtil.convertList(reportFormList, HospProfitVO.class);
|
|
|
+ //把所有数据按报表项目汇总
|
|
|
+ Map<Integer, List<HospProfitAndLoss>> reportNumGroup = hospProfitAndLosses.stream().collect(Collectors.groupingBy(HospProfitAndLoss::getReportNum));
|
|
|
+ Map<Integer, BigDecimal> reportNumSumMap = new HashMap<>();
|
|
|
+ reportNumGroup.forEach((reportNum, hospProfitAndLossList) -> {
|
|
|
+ AtomicReference<BigDecimal> sum = new AtomicReference<>(new BigDecimal("0.000000"));
|
|
|
+ hospProfitAndLossList.stream().<UnaryOperator<BigDecimal>>map(hospProfitAndLoss -> f -> f.add(hospProfitAndLoss.getAmount())).forEach(sum::updateAndGet);
|
|
|
+ reportNumSumMap.put(reportNum, sum.get());
|
|
|
+ });
|
|
|
+
|
|
|
+ for (HospProfitVO costProfitVo : costProfitVos) {
|
|
|
+ BigDecimal bigDecimal = reportNumSumMap.get(costProfitVo.getNum());
|
|
|
+ if (bigDecimal != null) {
|
|
|
+ costProfitVo.setAmount(bigDecimal);
|
|
|
+ } else {
|
|
|
+ costProfitVo.setAmount(BigDecimal.ZERO.setScale(6, RoundingMode.HALF_UP));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断有无其他全院数据 有组装进去
|
|
|
+ if (!CollectionUtils.isEmpty(hospAllList)) {
|
|
|
+ //全院其他收支
|
|
|
+ HospProfitVO hospProfitVO = new HospProfitVO();
|
|
|
+ hospProfitVO.setId(-1L);
|
|
|
+ hospProfitVO.setNum(-1);
|
|
|
+ hospProfitVO.setParentId(0L);
|
|
|
+ hospProfitVO.setReportName("全院其他收支");
|
|
|
+ hospProfitVO.setSort(costProfitVos.size());
|
|
|
+ hospProfitVO.setReportType(3);
|
|
|
+ hospProfitVO.setFraction(3);
|
|
|
+ costProfitVos.add(hospProfitVO);
|
|
|
+ for (int i = 0, hospAllListSize = hospAllList.size(); i < hospAllListSize; i++) {
|
|
|
+ costProfitVos.add(getHospProfitVO(hospAllList, i));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //取出所有成本项目
|
|
|
+ List<HospProfitVO> costFractionList = costProfitVos.stream().filter(f -> f.getCostType() != null && f.getCostType().equals(NumberConstant.TWO) && f.getFraction().equals(NumberConstant.TWO)).collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isEmpty(costFractionList)) {
|
|
|
+ throw new CostException("全院损益未配置成本占比计算分母");
|
|
|
+ } else {
|
|
|
+ if (costFractionList.size() > 1) {
|
|
|
+ throw new CostException("全院损益成本占比计算分母有且只能有一个");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<HospProfitVO> inComeFractionList = costProfitVos.stream().filter(f -> f.getCostType() != null && f.getCostType().equals(NumberConstant.ONE) && f.getFraction().equals(NumberConstant.TWO)).collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isEmpty(inComeFractionList)) {
|
|
|
+ throw new CostException("全院损益未配置收入占比计算分母");
|
|
|
+ } else {
|
|
|
+ if (inComeFractionList.size() > 1) {
|
|
|
+ throw new CostException("全院损益收入占比计算分母有且只能有一个");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ HospProfitVO inComeFraction = inComeFractionList.get(0);
|
|
|
+ HospProfitVO costFraction = costFractionList.get(0);
|
|
|
+ for (HospProfitVO costProfitVo : costProfitVos) {
|
|
|
+ if (costProfitVo.getCostType() != null) {
|
|
|
+ if (costProfitVo.getCostType().equals(NumberConstant.ONE) && costProfitVo.getFraction().equals(NumberConstant.ONE)) {
|
|
|
+ //收入
|
|
|
+ BigDecimal denominator = inComeFraction.getAmount();
|
|
|
+ //收入分子
|
|
|
+ if (denominator.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ costProfitVo.setPercent(BigDecimal.ZERO.setScale(4, RoundingMode.HALF_UP));
|
|
|
+ } else {
|
|
|
+ costProfitVo.setPercent(costProfitVo.getAmount().divide(denominator, 4, RoundingMode.HALF_UP));
|
|
|
+ }
|
|
|
+ } else if (costProfitVo.getCostType().equals(NumberConstant.TWO) && costProfitVo.getFraction().equals(NumberConstant.ONE)) {
|
|
|
+ //成本
|
|
|
+ BigDecimal denominator = costFraction.getAmount();
|
|
|
+ if (denominator.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ costProfitVo.setPercent(BigDecimal.ZERO.setScale(4, RoundingMode.HALF_UP));
|
|
|
+ } else {
|
|
|
+ costProfitVo.setPercent(costProfitVo.getAmount().divide(denominator, 4, RoundingMode.HALF_UP));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Map<Long, List<HospProfitVO>> collect = costProfitVos.stream().collect(Collectors.groupingBy(HospProfitVO::getParentId));
|
|
|
+ List<HospProfitVO> costProfitParentVos = collect.get(NumberConstant.ZERO_L);
|
|
|
+ collect.remove(NumberConstant.ZERO_L);
|
|
|
+ for (HospProfitVO costProfitVo : costProfitParentVos) {
|
|
|
+ List<HospProfitVO> costProfitVo1 = collect.get(costProfitVo.getId());
|
|
|
+ if (!CollectionUtils.isEmpty(costProfitVo1)) {
|
|
|
+ costProfitVo.setChild(setChildren(costProfitVo1, collect));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(costProfitParentVos)) {
|
|
|
+ costProfitParentVos.sort(Comparator.comparing(HospProfitVO::getSort, Comparator.nullsLast(Integer::compareTo)));
|
|
|
+ }
|
|
|
+ return costProfitParentVos;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private static @NotNull HospProfitVO getHospProfitVO(List<HospProfitAndLoss> hospAllList, int i) {
|
|
|
+ HospProfitAndLoss hospProfitAndLoss = hospAllList.get(i);
|
|
|
+ HospProfitVO hospProfitVO1 = new HospProfitVO();
|
|
|
+ hospProfitVO1.setId(Long.valueOf(hospProfitAndLoss.getReportNum()));
|
|
|
+ hospProfitVO1.setNum(hospProfitAndLoss.getReportNum());
|
|
|
+ hospProfitVO1.setParentId(-1L);
|
|
|
+ hospProfitVO1.setReportName(hospProfitAndLoss.getReportName());
|
|
|
+ hospProfitVO1.setSort(i);
|
|
|
+ hospProfitVO1.setReportType(3);
|
|
|
+ hospProfitVO1.setAmount(hospProfitAndLoss.getAmount());
|
|
|
+ hospProfitVO1.setFraction(3);
|
|
|
+ return hospProfitVO1;
|
|
|
+ }
|
|
|
+
|
|
|
private List<HospProfitAndLoss> getAllDataByDate(int year, int month, Long hospId) {
|
|
|
return this.list(
|
|
|
new LambdaQueryWrapper<HospProfitAndLoss>()
|
|
@@ -1029,85 +1201,74 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
|
i.setAmount(setSubtotal(i, costShareLevelList, listMap, listVo, incomes, allocationQueryReportVOList, reportRelationMap, allocationList, allList));
|
|
|
} else if (NumberConstant.FOUR.equals(calcType)) {
|
|
|
// TODO 按照计算公式进行计算
|
|
|
- i.setAmount(setCalculation(i, listVo, costShareLevelList, listMap, incomes, allocationQueryReportVOList, reportRelationMap, allocationList, allList));
|
|
|
+// i.setAmount(setCalculation(i, listVo, costShareLevelList, listMap, incomes, allocationQueryReportVOList, reportRelationMap, allocationList, allList));
|
|
|
} else if (NumberConstant.FIVE.equals(calcType)) {
|
|
|
// TODO 按照责任中心进行计算
|
|
|
i.setAmount(setResponsibilityCode(i, reportRelationMap, allocationList, allList));
|
|
|
} else {
|
|
|
- i.setAmount(new BigDecimal("0.0000"));
|
|
|
+ i.setAmount(new BigDecimal("0.000000"));
|
|
|
}
|
|
|
});
|
|
|
-//
|
|
|
-//
|
|
|
-//
|
|
|
-// listVo.forEach(i -> {
|
|
|
-// Integer calcType = i.getCalcType();
|
|
|
-// if (calcType == CalcTypeEnum.BY_ACCOUNT.getType()) {
|
|
|
-// // 按会计科目计算单的话
|
|
|
-// calcByAccountByResp(hospId, i);
|
|
|
-// } else if (calcType == CalcTypeEnum.BY_SHARE_LEVEL.getType()) {
|
|
|
-// // 分摊层级计算
|
|
|
-// calcByShareLevelResp(hospId, i);
|
|
|
-// } else if (calcType == CalcTypeEnum.LITTER_COUNT.getType()) {
|
|
|
-// // 处理小计 todo 默认认为 小计都是在同一个下面最后一个
|
|
|
-// calcByLitterCountResp(i,listParentMap, listVo,hospId);
|
|
|
-// } else if (calcType == CalcTypeEnum.CALC_FORMULA.getType()) {
|
|
|
-// // 按公式 (要保证总合计放到最后呀)
|
|
|
-// calcByFormulaResp(i,listVo);
|
|
|
-// } else if (calcType == CalcTypeEnum.BY_RESPONSIBILITY.getType()) {
|
|
|
-// // 责任中心
|
|
|
-// calcByResponsibilityResp(hospId, i);
|
|
|
-// } else if (calcType == CalcTypeEnum.NO_CONFIG.getType()) {
|
|
|
-// // 不设置不计算
|
|
|
-// i.setAmount(new BigDecimal("0.0000"));
|
|
|
-// } else {
|
|
|
-// i.setAmount(new BigDecimal("0.0000"));
|
|
|
-// }
|
|
|
-// });
|
|
|
-// for (Responsibility responsibility : leafResp) {
|
|
|
-// for (ReportForm parentForm : reportForms) {
|
|
|
-// Long parentId = parentForm.getId();
|
|
|
-// List<ReportForm> children = reportForms.stream().filter(i -> i.getParentId().equals(parentId)).collect(Collectors.toList());
|
|
|
-// for (ReportForm child : children) {
|
|
|
-// Integer calcType = child.getCalcType();
|
|
|
-// if (calcType == CalcTypeEnum.BY_ACCOUNT.getType()) {
|
|
|
-// // 按会计科目计算单的话
|
|
|
-// calcByAccountByResp(hospId, child, list, month, year, responsibility);
|
|
|
-// } else if (calcType == CalcTypeEnum.BY_SHARE_LEVEL.getType()) {
|
|
|
-// // 分摊层级计算
|
|
|
-// calcByShareLevelResp(hospId, child, list, year, month, responsibility);
|
|
|
-// } else if (calcType == CalcTypeEnum.LITTER_COUNT.getType()) {
|
|
|
-// // 处理小计 todo 默认认为 小计都是在同一个下面最后一个
|
|
|
-// calcByLitterCountResp(year, month, child, children, list, hospId, responsibility);
|
|
|
-// } else if (calcType == CalcTypeEnum.CALC_FORMULA.getType()) {
|
|
|
-// // 按公式 (要保证总合计放到最后呀)
|
|
|
-// calcByFormulaResp(year, month, child, list, responsibility);
|
|
|
-// } else if (calcType == CalcTypeEnum.BY_RESPONSIBILITY.getType()) {
|
|
|
-// // 责任中心
|
|
|
-// calcByResponsibilityResp(hospId, child, list, year, month, responsibility);
|
|
|
-// } else if (calcType == CalcTypeEnum.NO_CONFIG.getType()) {
|
|
|
-// // 不设置不计算
|
|
|
-// } else {
|
|
|
-//
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
//计算占比
|
|
|
if (CollectionUtils.isEmpty(listVo)) {
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
+ List<HospProfitAndLossVo> listSum = new ArrayList<>();
|
|
|
+
|
|
|
+ //把所有数据按报表项目汇总
|
|
|
+ for (ReportForm j : reportForms) {
|
|
|
+ HospProfitAndLossVo hospProfitAndLossVo = new HospProfitAndLossVo();
|
|
|
+ hospProfitAndLossVo.setDateYear(finalYear);
|
|
|
+ hospProfitAndLossVo.setDateMonth(finalMonth);
|
|
|
+ hospProfitAndLossVo.setReportNum(j.getNum());
|
|
|
+ hospProfitAndLossVo.setReportName(j.getReportName());
|
|
|
+ hospProfitAndLossVo.setCostType(NumberConstant.ZERO);
|
|
|
+ hospProfitAndLossVo.setIncomeType(NumberConstant.ZERO);
|
|
|
+ hospProfitAndLossVo.setHospId(hospId);
|
|
|
+ hospProfitAndLossVo.setType(j.getCostType());
|
|
|
+ hospProfitAndLossVo.setFraction(j.getFraction());
|
|
|
+ hospProfitAndLossVo.setReportId(j.getId());
|
|
|
+ hospProfitAndLossVo.setReportNum(j.getNum());
|
|
|
+ hospProfitAndLossVo.setCalcType(j.getCalcType());
|
|
|
+ hospProfitAndLossVo.setReportName(j.getReportName());
|
|
|
+ hospProfitAndLossVo.setCalcFormula(j.getCalcFormula());
|
|
|
+ hospProfitAndLossVo.setReportParentId(j.getParentId());
|
|
|
+ listSum.add(hospProfitAndLossVo);
|
|
|
+ }
|
|
|
+ Map<Integer, List<HospProfitAndLossVo>> reportNumGroup = listVo.stream().collect(Collectors.groupingBy(HospProfitAndLossVo::getReportNum));
|
|
|
+ Map<Integer, BigDecimal> reportNumSumMap = new HashMap<>();
|
|
|
+ reportNumGroup.forEach((reportNum, hospProfitAndLossList) -> {
|
|
|
+ AtomicReference<BigDecimal> sum = new AtomicReference<>(new BigDecimal("0.000000"));
|
|
|
+ for (HospProfitAndLossVo hospProfitAndLoss : hospProfitAndLossList) {
|
|
|
+ if (hospProfitAndLoss.getAmount() != null) {
|
|
|
+ sum.updateAndGet(f -> f.add(hospProfitAndLoss.getAmount()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ reportNumSumMap.put(reportNum, sum.get());
|
|
|
+ });
|
|
|
+
|
|
|
+ for (HospProfitAndLossVo costProfitVo : listSum) {
|
|
|
+ BigDecimal bigDecimal = reportNumSumMap.get(costProfitVo.getReportNum());
|
|
|
+ if (bigDecimal != null) {
|
|
|
+ costProfitVo.setAmount(bigDecimal);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ costProfitVo.setAmount(BigDecimal.ZERO.setScale(6, RoundingMode.HALF_UP));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //单独计算计算公式数据
|
|
|
+ setCalculationAmount(listSum);
|
|
|
//收入
|
|
|
- List<HospProfitAndLossVo> profitIncomeList = listVo.stream().filter(f -> f.getType().equals(NumberConstant.ONE)).collect(Collectors.toList());
|
|
|
+ List<HospProfitAndLossVo> profitIncomeList = listSum.stream().filter(f -> f.getType().equals(NumberConstant.ONE)).collect(Collectors.toList());
|
|
|
List<HospProfitAndLossVo> profitIncome = costPercent(profitIncomeList);
|
|
|
//成本
|
|
|
- List<HospProfitAndLossVo> profitCostList = listVo.stream().filter(f -> f.getType().equals(NumberConstant.TWO)).collect(Collectors.toList());
|
|
|
+ List<HospProfitAndLossVo> profitCostList = listSum.stream().filter(f -> f.getType().equals(NumberConstant.TWO)).collect(Collectors.toList());
|
|
|
|
|
|
List<HospProfitAndLossVo> profitCost = costPercent(profitCostList);
|
|
|
|
|
|
//不计算项目
|
|
|
- List<HospProfitAndLossVo> noCompute = listVo.stream().filter(f -> f.getFraction().equals(NumberConstant.THREE)).collect(Collectors.toList());
|
|
|
+ List<HospProfitAndLossVo> noCompute = listSum.stream().filter(f -> f.getFraction().equals(NumberConstant.THREE)).collect(Collectors.toList());
|
|
|
noCompute.forEach(profitVO -> profitVO.setPercent(null));
|
|
|
|
|
|
List<HospProfitAndLossVo> listAllVo = new ArrayList<>();
|
|
@@ -1135,18 +1296,81 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
|
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);
|
|
|
list.add(loss);
|
|
|
});
|
|
|
}
|
|
|
-
|
|
|
long l = System.currentTimeMillis();
|
|
|
list.forEach(i -> {
|
|
|
i.setCreateTime(l);
|
|
|
});
|
|
|
-
|
|
|
this.saveBatch(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setCalculationAmount(List<HospProfitAndLossVo> listVo) {
|
|
|
+ Map<Integer, List<HospProfitAndLossVo>> collect = listVo.stream().collect(Collectors.groupingBy(HospProfitAndLossVo::getCalcType));
|
|
|
+ //取出所有计算公式数据
|
|
|
+ List<HospProfitAndLossVo> costDepartmentProfitVOS = collect.get(NumberConstant.FOUR);
|
|
|
+
|
|
|
+ costDepartmentProfitVOS.sort(Comparator.comparing(HospProfitAndLossVo::getReportNum, Comparator.nullsLast(Integer::compareTo)));
|
|
|
+ for (HospProfitAndLossVo profitVO : costDepartmentProfitVOS) {
|
|
|
+ // 获取当前报表的计算方式 [1]+[2]类型/ [1]-[2] [1]*[2] [1]/[2]
|
|
|
+ String formula = profitVO.getCalcFormula();
|
|
|
+ //找出公式当中所有代码
|
|
|
+ String replace = formula.replace("[", "")
|
|
|
+ .replace("]", "")
|
|
|
+ .replace("-", ",")
|
|
|
+ .replace("+", ",")
|
|
|
+ .replace("*", ",")
|
|
|
+ .replace("/", ",");
|
|
|
+ ArrayList<String> codeList = CollUtil.newArrayList(replace.split(","));
|
|
|
+ Map<Integer, String> codeMap = new ConcurrentHashMap<>();
|
|
|
+ for (int j = 0; j < codeList.size(); j++) {
|
|
|
+ codeMap.put(j, codeList.get(j));
|
|
|
+ }
|
|
|
+ List<String> expressions = ReUtil.findAll("[^0-9]", "+" + formula.replace("[", "")
|
|
|
+ .replace("]", "").trim(), 0)
|
|
|
+ .stream().filter(StrUtil::isNotBlank).collect(Collectors.toList());
|
|
|
+ // 得到预算表达式 得到所有表达式的Map + - 相关的
|
|
|
+ Map<Integer, String> expressionMap = new ConcurrentHashMap<>();
|
|
|
+ for (int k = 0; k < expressions.size(); k++) {
|
|
|
+ expressionMap.put(k, expressions.get(k));
|
|
|
+ }
|
|
|
+ // 数字的索引和表达式的索引累加计算
|
|
|
+ Set<Integer> codeSet = codeMap.keySet();
|
|
|
+ List<Integer> codes = new ArrayList<>(codeSet);
|
|
|
+ AtomicReference<BigDecimal> totalAmount = new AtomicReference<>(new BigDecimal("0.000000"));
|
|
|
+ for (int i = 0; i < codes.size(); i++) {
|
|
|
+ // 编号
|
|
|
+ String code = codeMap.get(i);
|
|
|
+ BigDecimal amount = null;
|
|
|
+ for (HospProfitAndLossVo costDepartmentProfitVO : listVo) {
|
|
|
+ if (costDepartmentProfitVO.getReportNum().equals(Integer.valueOf(code))) {
|
|
|
+ amount = costDepartmentProfitVO.getAmount();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (amount == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+// BigDecimal amount = new BigDecimal(o.toString());
|
|
|
+ String str = expressionMap.get(i);
|
|
|
+ if (str.equals("+")) {
|
|
|
+ totalAmount.set(totalAmount.get().add(amount));
|
|
|
+ } else if (str.contains("-")) {
|
|
|
+ totalAmount.set(totalAmount.get().subtract(amount));
|
|
|
+ } else if (str.contains("*")) {
|
|
|
+ totalAmount.set(totalAmount.get().multiply(amount));
|
|
|
+ } else if (str.contains("/")) {
|
|
|
+ if (amount.compareTo(BigDecimal.ZERO.setScale(6, RoundingMode.HALF_UP)) == 0) {
|
|
|
+ totalAmount.set(BigDecimal.ZERO);
|
|
|
+ break;
|
|
|
+ } else {
|
|
|
+ totalAmount.set(totalAmount.get().divide(amount, 6, RoundingMode.HALF_UP));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ profitVO.setAmount(totalAmount.get());
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -1358,35 +1582,31 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
|
|
|
|
private List<HospProfitAndLossVo> costPercent(List<HospProfitAndLossVo> profitIncomeList) {
|
|
|
List<HospProfitAndLossVo> list = new ArrayList<>();
|
|
|
- Map<String, List<HospProfitAndLossVo>> responsibilityGroup = profitIncomeList.stream().collect(Collectors.groupingBy(HospProfitAndLossVo::getResponsibilityCode));
|
|
|
-
|
|
|
- for (String s : responsibilityGroup.keySet()) {
|
|
|
- List<HospProfitAndLossVo> costDepartmentProfitVOS = responsibilityGroup.get(s);
|
|
|
- Map<Integer, List<HospProfitAndLossVo>> collect = costDepartmentProfitVOS.stream().collect(Collectors.groupingBy(HospProfitAndLossVo::getFraction));
|
|
|
- //分母只有一个
|
|
|
- List<HospProfitAndLossVo> denominatorList = collect.get(NumberConstant.TWO);
|
|
|
- if (denominatorList.size() > 1) {
|
|
|
- throw new CostException("收入项目分母大于一个,请查证后再计算科室损益");
|
|
|
+ Map<Integer, List<HospProfitAndLossVo>> collect = profitIncomeList.stream().collect(Collectors.groupingBy(HospProfitAndLossVo::getFraction));
|
|
|
+ //分母只有一个
|
|
|
+ List<HospProfitAndLossVo> denominatorList = collect.get(NumberConstant.TWO);
|
|
|
+ if (denominatorList.size() > 1) {
|
|
|
+ throw new CostException("收入项目分母大于一个,请查证后再计算科室损益");
|
|
|
+ }
|
|
|
+ BigDecimal denominator = denominatorList.get(0).getAmount();
|
|
|
+ //收入分子
|
|
|
+ List<HospProfitAndLossVo> numeratorList = collect.get(NumberConstant.ONE);
|
|
|
+ if (denominator.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ for (HospProfitAndLossVo profitVO : numeratorList) {
|
|
|
+ profitVO.setPercent(BigDecimal.ZERO.setScale(4, RoundingMode.HALF_UP));
|
|
|
}
|
|
|
- BigDecimal denominator = denominatorList.get(0).getAmount();
|
|
|
- //收入分子
|
|
|
- List<HospProfitAndLossVo> numeratorList = collect.get(NumberConstant.ONE);
|
|
|
- if (denominator.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
- for (HospProfitAndLossVo profitVO : numeratorList) {
|
|
|
- profitVO.setPercent(BigDecimal.ZERO.setScale(4, RoundingMode.HALF_UP));
|
|
|
- }
|
|
|
- denominatorList.get(0).setPercent(BigDecimal.ZERO.setScale(4, RoundingMode.HALF_UP));
|
|
|
+ denominatorList.get(0).setPercent(BigDecimal.ZERO.setScale(4, RoundingMode.HALF_UP));
|
|
|
|
|
|
- } else {
|
|
|
- for (HospProfitAndLossVo profitVO : numeratorList) {
|
|
|
- profitVO.setPercent(profitVO.getAmount().divide(denominator, 4, RoundingMode.HALF_UP));
|
|
|
- }
|
|
|
- denominatorList.get(0).setPercent(BigDecimal.ONE.setScale(4, RoundingMode.HALF_UP));
|
|
|
+ } else {
|
|
|
+ for (HospProfitAndLossVo profitVO : numeratorList) {
|
|
|
+ profitVO.setPercent(profitVO.getAmount().divide(denominator, 4, RoundingMode.HALF_UP));
|
|
|
}
|
|
|
- list.add(denominatorList.get(0));
|
|
|
- list.addAll(numeratorList);
|
|
|
-
|
|
|
+ denominatorList.get(0).setPercent(BigDecimal.ONE.setScale(4, RoundingMode.HALF_UP));
|
|
|
}
|
|
|
+ list.add(denominatorList.get(0));
|
|
|
+ list.addAll(numeratorList);
|
|
|
+
|
|
|
+
|
|
|
|
|
|
return list;
|
|
|
|
|
@@ -1687,4 +1907,45 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
|
;
|
|
|
list.add(loss);
|
|
|
}
|
|
|
+
|
|
|
+ private void responsibilitySort(List<Responsibility> responsibilityList) {
|
|
|
+ for (Responsibility responsibility : responsibilityList) {
|
|
|
+ if (!CollectionUtils.isEmpty(responsibility.getChildren())) {
|
|
|
+ responsibilitySort(responsibility.getChildren());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ responsibilityList.sort(Comparator.comparing(Responsibility::getSort, Comparator.nullsLast(Integer::compareTo)));
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Responsibility> setResponsibilityChildren(List<Responsibility> child, Map<Long, List<Responsibility>> collect) {
|
|
|
+ for (Responsibility responsibility : child) {
|
|
|
+ if (!CollectionUtils.isEmpty(collect.get(responsibility.getId()))) {
|
|
|
+ responsibility.setChildren(setResponsibilityChildren(collect.get(responsibility.getId()), collect));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return child;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getResponsibilityParent(Responsibility responsibility, Map<Long, Responsibility> collect, List<Responsibility> addList) {
|
|
|
+ Responsibility responsibility1 = collect.get(responsibility.getParentId());
|
|
|
+ if (Objects.nonNull(responsibility1)) {
|
|
|
+ addList.add(responsibility1);
|
|
|
+ if (!responsibility1.getParentId().equals(NumberConstant.ZERO_L)) {
|
|
|
+ getResponsibilityParent(responsibility1, collect, addList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<HospProfitVO> setChildren(List<HospProfitVO> child, Map<Long, List<HospProfitVO>> collect) {
|
|
|
+ for (HospProfitVO costProfitVo : child) {
|
|
|
+ if (!CollectionUtils.isEmpty(collect.get(costProfitVo.getId()))) {
|
|
|
+ costProfitVo.setChild(setChildren(collect.get(costProfitVo.getId()), collect));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(child)) {
|
|
|
+ child.sort(Comparator.comparing(HospProfitVO::getSort, Comparator.nullsLast(Integer::compareTo)));
|
|
|
+ }
|
|
|
+ return child;
|
|
|
+ }
|
|
|
+
|
|
|
}
|