|
@@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.io.IoUtil;
|
|
import cn.hutool.core.io.IoUtil;
|
|
-import cn.hutool.core.util.RandomUtil;
|
|
|
|
import cn.hutool.core.util.ReUtil;
|
|
import cn.hutool.core.util.ReUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.poi.excel.ExcelUtil;
|
|
import cn.hutool.poi.excel.ExcelUtil;
|
|
@@ -21,6 +20,7 @@ import com.imed.costaccount.model.vo.HospProfitVO;
|
|
import com.imed.costaccount.model.vo.RelationVO;
|
|
import com.imed.costaccount.model.vo.RelationVO;
|
|
import com.imed.costaccount.model.vo.ReportFormVO;
|
|
import com.imed.costaccount.model.vo.ReportFormVO;
|
|
import com.imed.costaccount.service.*;
|
|
import com.imed.costaccount.service.*;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
|
@@ -37,7 +37,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
-
|
|
|
|
|
|
+@Slf4j
|
|
@Service("hospProfitAndLossService")
|
|
@Service("hospProfitAndLossService")
|
|
public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossMapper, HospProfitAndLoss> implements HospProfitAndLossService {
|
|
public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossMapper, HospProfitAndLoss> implements HospProfitAndLossService {
|
|
|
|
|
|
@@ -50,6 +50,7 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
private final CostShareLevelService shareLevelService;
|
|
private final CostShareLevelService shareLevelService;
|
|
private final CostOtherPaymentsDataService otherPaymentsDataService;
|
|
private final CostOtherPaymentsDataService otherPaymentsDataService;
|
|
private final ResponsibilityService responsibilityService;
|
|
private final ResponsibilityService responsibilityService;
|
|
|
|
+ private final CostAccountShareService accountShareService;
|
|
|
|
|
|
public HospProfitAndLossServiceImpl(ReportFormService reportFormService,
|
|
public HospProfitAndLossServiceImpl(ReportFormService reportFormService,
|
|
IncomeCollectionService collectionService,
|
|
IncomeCollectionService collectionService,
|
|
@@ -57,7 +58,9 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
AllocationService allocationService,
|
|
AllocationService allocationService,
|
|
ReportRelationService reportRelationService,
|
|
ReportRelationService reportRelationService,
|
|
CostShareLevelService shareLevelService,
|
|
CostShareLevelService shareLevelService,
|
|
- CostOtherPaymentsDataService otherPaymentsDataService, ResponsibilityService responsibilityService) {
|
|
|
|
|
|
+ CostOtherPaymentsDataService otherPaymentsDataService,
|
|
|
|
+ ResponsibilityService responsibilityService,
|
|
|
|
+ CostAccountShareService accountShareService) {
|
|
this.reportFormService = reportFormService;
|
|
this.reportFormService = reportFormService;
|
|
this.collectionService = collectionService;
|
|
this.collectionService = collectionService;
|
|
this.allocationQueryService = allocationQueryService;
|
|
this.allocationQueryService = allocationQueryService;
|
|
@@ -66,6 +69,7 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
this.shareLevelService = shareLevelService;
|
|
this.shareLevelService = shareLevelService;
|
|
this.otherPaymentsDataService = otherPaymentsDataService;
|
|
this.otherPaymentsDataService = otherPaymentsDataService;
|
|
this.responsibilityService = responsibilityService;
|
|
this.responsibilityService = responsibilityService;
|
|
|
|
+ this.accountShareService = accountShareService;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -100,52 +104,35 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
throw new CostException("医院未分摊本月数据");
|
|
throw new CostException("医院未分摊本月数据");
|
|
}
|
|
}
|
|
List<HospProfitAndLoss> list = new ArrayList<>();
|
|
List<HospProfitAndLoss> list = new ArrayList<>();
|
|
- reportForms.forEach(i -> {
|
|
|
|
- Integer calcType = i.getCalcType();
|
|
|
|
- if (calcType == CalcTypeEnum.BY_ACCOUNT.getType()) {
|
|
|
|
- // 按会计科目计算
|
|
|
|
- HospProfitAndLoss loss = calcByAccount(hospId, i, incomes, allocationQueries);
|
|
|
|
- if (Objects.isNull(loss)) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- loss.setDateMonth(month);
|
|
|
|
- loss.setDateYear(year);
|
|
|
|
- list.add(loss);
|
|
|
|
- return;
|
|
|
|
- } else if (calcType == CalcTypeEnum.BY_SHARE_LEVEL.getType()) {
|
|
|
|
- // 分摊层级计算
|
|
|
|
- HospProfitAndLoss loss = calcByShareLevel(hospId, i, year, month);
|
|
|
|
- if (Objects.isNull(loss)) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- loss.setDateMonth(month);
|
|
|
|
- loss.setDateYear(year);
|
|
|
|
- list.add(loss);
|
|
|
|
- return;
|
|
|
|
- } else if (calcType == CalcTypeEnum.LITTER_COUNT.getType()) {
|
|
|
|
- return;
|
|
|
|
- } else if (calcType == CalcTypeEnum.CALC_FORMULA.getType()) {
|
|
|
|
- // todo 留在最后加减
|
|
|
|
- return;
|
|
|
|
- } else if (calcType == CalcTypeEnum.BY_RESPONSIBILITY.getType()) {
|
|
|
|
- // 责任中心
|
|
|
|
- HospProfitAndLoss loss = calcByResponsibility(hospId, i, incomes, allocationQueries);
|
|
|
|
- if (loss == null) {
|
|
|
|
- return;
|
|
|
|
|
|
+ List<ReportForm> parentForms = reportForms.stream().filter(i -> i.getParentId().equals(0L)).collect(Collectors.toList());
|
|
|
|
+ for (ReportForm parentForm : parentForms) {
|
|
|
|
+ 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()) {
|
|
|
|
+ // 按会计科目计算单的话
|
|
|
|
+ calcByAccount(hospId, child, incomes, list, allocationQueries, month, year);
|
|
|
|
+ } else if (calcType == CalcTypeEnum.BY_SHARE_LEVEL.getType()) {
|
|
|
|
+ // 分摊层级计算
|
|
|
|
+ calcByShareLevel(hospId, child, list, year, month);
|
|
|
|
+ } else if (calcType == CalcTypeEnum.LITTER_COUNT.getType()) {
|
|
|
|
+ // 处理小计 todo 默认认为 小计都是在同一个下面最后一个
|
|
|
|
+ calcByLitterCount(year, month, child, children, list, hospId);
|
|
|
|
+ } else if (calcType == CalcTypeEnum.CALC_FORMULA.getType()) {
|
|
|
|
+ // 按公式 (要保证总合计放到最后呀)
|
|
|
|
+ calcByFormula(year, month, child, children, list);
|
|
|
|
+ } else if (calcType == CalcTypeEnum.BY_RESPONSIBILITY.getType()) {
|
|
|
|
+ // 责任中心
|
|
|
|
+ calcByResponsibility(hospId, child, allocationQueries, list, year, month);
|
|
|
|
+ } else if (calcType == CalcTypeEnum.NO_CONFIG.getType()) {
|
|
|
|
+ // 不设置不计算
|
|
|
|
+ } else {
|
|
|
|
+
|
|
}
|
|
}
|
|
- loss.setDateMonth(month);
|
|
|
|
- loss.setDateYear(year);
|
|
|
|
- list.add(loss);
|
|
|
|
- } else {
|
|
|
|
- // 不设置不计算
|
|
|
|
- return;
|
|
|
|
}
|
|
}
|
|
- });
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- // 先处理按公式
|
|
|
|
- calcByFormula(year, month, reportForms, list);
|
|
|
|
- // 处理小计
|
|
|
|
- calcByLitterCount(year, month, reportForms, list, hospId);
|
|
|
|
|
|
|
|
// 处理医院其他收支
|
|
// 处理医院其他收支
|
|
List<CostOtherPaymentsData> otherPaymentsDatas = otherPaymentsDataService.getByMonth(year, month, hospId);
|
|
List<CostOtherPaymentsData> otherPaymentsDatas = otherPaymentsDataService.getByMonth(year, month, hospId);
|
|
@@ -164,47 +151,48 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
}
|
|
}
|
|
|
|
|
|
// 计算公式中钱
|
|
// 计算公式中钱
|
|
- private BigDecimal calcAmount(List<HospProfitAndLoss> list, String calcFormula) {
|
|
|
|
|
|
+ private BigDecimal calcAmount(List<HospProfitAndLoss> list, String calcFormula, ReportForm reportForm) {
|
|
|
|
+ // 得到所有的编号
|
|
String replace = calcFormula.replace("[", "").replace("]", "").replace("-", ",").replace("+", ",");
|
|
String replace = calcFormula.replace("[", "").replace("]", "").replace("-", ",").replace("+", ",");
|
|
ArrayList<String> numList = CollUtil.newArrayList(replace.split(","));
|
|
ArrayList<String> numList = CollUtil.newArrayList(replace.split(","));
|
|
- // 得到数字
|
|
|
|
- Map<Integer, Object> numMap = new ConcurrentHashMap<>();
|
|
|
|
|
|
+ // 得到编号的map
|
|
|
|
+ Map<Integer, Integer> numMap = new ConcurrentHashMap<>();
|
|
for (int j = 0; j < numList.size(); j++) {
|
|
for (int j = 0; j < numList.size(); j++) {
|
|
- numMap.put(j, numList.get(j));
|
|
|
|
|
|
+ numMap.put(j, Integer.parseInt(numList.get(j)));
|
|
}
|
|
}
|
|
List<String> expressions = ReUtil.findAll("[^0-9]", "+" + calcFormula.replace("[", "").replace("]", "").trim(), 0)
|
|
List<String> expressions = ReUtil.findAll("[^0-9]", "+" + calcFormula.replace("[", "").replace("]", "").trim(), 0)
|
|
.stream().filter(StrUtil::isNotBlank).collect(Collectors.toList());
|
|
.stream().filter(StrUtil::isNotBlank).collect(Collectors.toList());
|
|
- // 得到预算表达式
|
|
|
|
|
|
+ // 得到预算表达式 得到所有表达式的Map + - 相关的
|
|
Map<Integer, String> expressionMap = new ConcurrentHashMap<>();
|
|
Map<Integer, String> expressionMap = new ConcurrentHashMap<>();
|
|
for (int k = 0; k < expressions.size(); k++) {
|
|
for (int k = 0; k < expressions.size(); k++) {
|
|
expressionMap.put(k, expressions.get(k));
|
|
expressionMap.put(k, expressions.get(k));
|
|
}
|
|
}
|
|
|
|
+ // 数字的索引和表达式的索引累加计算
|
|
Set<Integer> numSet = numMap.keySet();
|
|
Set<Integer> numSet = numMap.keySet();
|
|
List<Integer> nums = new ArrayList<>(numSet);
|
|
List<Integer> nums = new ArrayList<>(numSet);
|
|
- Map<Integer, BigDecimal> map = new HashMap<>();
|
|
|
|
- for (int l = 0; l < nums.size(); l++) {
|
|
|
|
- for (HospProfitAndLoss z : list) {
|
|
|
|
- if (z.getReportNum().equals(nums.get(l))) {
|
|
|
|
- map.put(l, z.getAmount());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- Set<Integer> integers = map.keySet();
|
|
|
|
- List<Integer> mapList = new ArrayList<>(integers);
|
|
|
|
- AtomicReference<BigDecimal> total = new AtomicReference<>();
|
|
|
|
- total.set(BigDecimal.ZERO);
|
|
|
|
- for (int x = 0; x < mapList.size(); x++) {
|
|
|
|
- BigDecimal bigDecimal = map.get(x);
|
|
|
|
- if (Objects.isNull(bigDecimal)) {
|
|
|
|
- bigDecimal = BigDecimal.ZERO;
|
|
|
|
|
|
+ AtomicReference<BigDecimal> totalAmount = new AtomicReference<>();
|
|
|
|
+ totalAmount.set(BigDecimal.ZERO);
|
|
|
|
+ for (int i = 0; i < nums.size(); i++) {
|
|
|
|
+ // 编号
|
|
|
|
+ Integer num = numMap.get(i);
|
|
|
|
+ List<HospProfitAndLoss> losses = list.stream().filter(item -> item.getReportNum().equals(num)).collect(Collectors.toList());
|
|
|
|
+ if (CollUtil.isEmpty(losses)) {
|
|
|
|
+ continue;
|
|
}
|
|
}
|
|
- if ("+".equals(expressionMap.get(x))) {
|
|
|
|
- total.set(total.get().add(bigDecimal));
|
|
|
|
|
|
+// log.info("data={}", reportForm);
|
|
|
|
+// if (losses.size() != 0 && losses.size() != 1) {
|
|
|
|
+// throw new CostException("数据异常");
|
|
|
|
+// }
|
|
|
|
+ HospProfitAndLoss loss = losses.get(0);
|
|
|
|
+ BigDecimal amount = loss.getAmount();
|
|
|
|
+ String str = expressionMap.get(i);
|
|
|
|
+ if (str.equals("+")) {
|
|
|
|
+ totalAmount.set(totalAmount.get().add(amount));
|
|
} else {
|
|
} else {
|
|
- total.set(total.get().subtract(bigDecimal));
|
|
|
|
|
|
+ totalAmount.set(totalAmount.get().subtract(amount));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return total.get();
|
|
|
|
|
|
+ return totalAmount.get();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -212,13 +200,15 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
*
|
|
*
|
|
* @param hospId 医院id
|
|
* @param hospId 医院id
|
|
* @param reportForm 报表
|
|
* @param reportForm 报表
|
|
- * @param incomes 归集收入数据
|
|
|
|
* @param allocationQueries 分摊成本数据
|
|
* @param allocationQueries 分摊成本数据
|
|
|
|
+ * @param list
|
|
|
|
+ * @param year
|
|
|
|
+ * @param month
|
|
*/
|
|
*/
|
|
- private HospProfitAndLoss calcByResponsibility(Long hospId, ReportForm reportForm, List<IncomeCollection> incomes, List<AllocationQuery> allocationQueries) {
|
|
|
|
- List<RelationVO> responsibilities = reportRelationService.getAccountRelation(reportForm.getId(), hospId);
|
|
|
|
|
|
+ private void calcByResponsibility(Long hospId, ReportForm reportForm, List<AllocationQuery> allocationQueries, List<HospProfitAndLoss> list, int year, int month) {
|
|
|
|
+ List<RelationVO> responsibilities = reportRelationService.getResponsibilities(reportForm.getId(), hospId);
|
|
if (responsibilities.isEmpty()) {
|
|
if (responsibilities.isEmpty()) {
|
|
- return null;
|
|
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
List<String> accountCodes = responsibilities.stream().map(RelationVO::getCode).collect(Collectors.toList());
|
|
List<String> accountCodes = responsibilities.stream().map(RelationVO::getCode).collect(Collectors.toList());
|
|
AtomicReference<BigDecimal> calcTotal = new AtomicReference<>();
|
|
AtomicReference<BigDecimal> calcTotal = new AtomicReference<>();
|
|
@@ -229,64 +219,57 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
calcTotal.set(calcTotal.get().add(costAmount));
|
|
calcTotal.set(calcTotal.get().add(costAmount));
|
|
});
|
|
});
|
|
HospProfitAndLoss loss = new HospProfitAndLoss();
|
|
HospProfitAndLoss loss = new HospProfitAndLoss();
|
|
- return loss.setReportName(reportForm.getReportName()).setReportNum(reportForm.getNum())
|
|
|
|
- .setAmount(calcTotal.get()).setCreateTime(System.currentTimeMillis()).setHospId(hospId);
|
|
|
|
|
|
+ loss.setReportName(reportForm.getReportName()).setReportNum(reportForm.getNum())
|
|
|
|
+ .setAmount(calcTotal.get()).setCreateTime(System.currentTimeMillis()).setHospId(hospId).setDateYear(year).setDateMonth(month);
|
|
|
|
+ list.add(loss);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* 按计算公式计算
|
|
* 按计算公式计算
|
|
*/
|
|
*/
|
|
- private void calcByFormula(Integer year, Integer month, List<ReportForm> reportForms, List<HospProfitAndLoss> list) {
|
|
|
|
|
|
+ private void calcByFormula(Integer year, Integer month, ReportForm child, List<ReportForm> reportForms, List<HospProfitAndLoss> list) {
|
|
|
|
+ // 得到当前下按公式计算的
|
|
List<ReportForm> calcFormulas = reportForms.stream().filter(i -> i.getCalcType() == CalcTypeEnum.CALC_FORMULA.getType()).collect(Collectors.toList());
|
|
List<ReportForm> calcFormulas = reportForms.stream().filter(i -> i.getCalcType() == CalcTypeEnum.CALC_FORMULA.getType()).collect(Collectors.toList());
|
|
- calcFormulas.forEach(i -> {
|
|
|
|
|
|
+ calcFormulas = calcFormulas.stream().filter(i -> i.getNum().equals(child.getNum())).collect(Collectors.toList());
|
|
|
|
+ for (ReportForm i : calcFormulas) {
|
|
String calcFormula = i.getCalcFormula();
|
|
String calcFormula = i.getCalcFormula();
|
|
// TODO: 2021/8/27 校验公式合法性
|
|
// TODO: 2021/8/27 校验公式合法性
|
|
if (StrUtil.isBlank(calcFormula)) {
|
|
if (StrUtil.isBlank(calcFormula)) {
|
|
throw new CostException("reportForm名称为" + i.getReportName() + "计算公式不正确");
|
|
throw new CostException("reportForm名称为" + i.getReportName() + "计算公式不正确");
|
|
}
|
|
}
|
|
- BigDecimal bigDecimal = calcAmount(list, calcFormula);
|
|
|
|
|
|
+ BigDecimal bigDecimal = calcAmount(list, calcFormula, i);
|
|
HospProfitAndLoss loss = new HospProfitAndLoss();
|
|
HospProfitAndLoss loss = new HospProfitAndLoss();
|
|
loss.setDateYear(year).setDateMonth(month).setReportNum(i.getNum()).setReportName(i.getReportName())
|
|
loss.setDateYear(year).setDateMonth(month).setReportNum(i.getNum()).setReportName(i.getReportName())
|
|
.setAmount(bigDecimal).setCreateTime(System.currentTimeMillis()).setHospId(i.getHospId());
|
|
.setAmount(bigDecimal).setCreateTime(System.currentTimeMillis()).setHospId(i.getHospId());
|
|
list.add(loss);
|
|
list.add(loss);
|
|
-
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 按小计计算
|
|
* 按小计计算
|
|
*/
|
|
*/
|
|
- private void calcByLitterCount(Integer year, Integer month, List<ReportForm> reportForms, List<HospProfitAndLoss> list, Long hospId) {
|
|
|
|
- List<ReportForm> litterCounts = reportForms.stream().filter(i -> i.getCalcType() == CalcTypeEnum.LITTER_COUNT.getType()).collect(Collectors.toList());
|
|
|
|
- litterCounts.forEach(reportForm -> {
|
|
|
|
- Long parentId = reportForm.getParentId();
|
|
|
|
- List<ReportForm> reportFormByParents = reportFormService.getByParentId(hospId, parentId);
|
|
|
|
- List<Integer> reportNums = new ArrayList<>();
|
|
|
|
- reportFormByParents.forEach(form -> {
|
|
|
|
- // 去掉自己
|
|
|
|
- if (form.getId().equals(reportForm.getId())) {
|
|
|
|
- return;
|
|
|
|
|
|
+ private void calcByLitterCount(Integer year, Integer month, ReportForm child, List<ReportForm> reportForms, List<HospProfitAndLoss> list, Long hospId) {
|
|
|
|
+ // 其他的
|
|
|
|
+ List<ReportForm> calcList = reportForms.stream().filter(i -> !i.getCalcType().equals(CalcTypeEnum.LITTER_COUNT.getType())).collect(Collectors.toList());
|
|
|
|
+ List<HospProfitAndLoss> thisList = new ArrayList<>();
|
|
|
|
+ list.forEach(i -> {
|
|
|
|
+ calcList.forEach(j -> {
|
|
|
|
+ if (i.getReportNum().equals(j.getNum())) {
|
|
|
|
+ thisList.add(i);
|
|
}
|
|
}
|
|
- reportNums.add(form.getNum());
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- AtomicReference<BigDecimal> total = new AtomicReference<>();
|
|
|
|
- total.set(BigDecimal.ZERO);
|
|
|
|
- reportNums.forEach(num -> {
|
|
|
|
- list.forEach(item -> {
|
|
|
|
- if (num.equals(item.getReportNum())) {
|
|
|
|
- total.set(total.get().add(item.getAmount()));
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
});
|
|
});
|
|
- HospProfitAndLoss loss = new HospProfitAndLoss();
|
|
|
|
- loss.setDateYear(year).setDateMonth(month).setReportNum(reportForm.getNum())
|
|
|
|
- .setReportName(reportForm.getReportName()).setAmount(total.get()).setCreateTime(System.currentTimeMillis()).setHospId(hospId);
|
|
|
|
- list.add(loss);
|
|
|
|
});
|
|
});
|
|
|
|
+ if (thisList.isEmpty()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ BigDecimal reduce = thisList.stream().map(HospProfitAndLoss::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
+ HospProfitAndLoss loss = new HospProfitAndLoss();
|
|
|
|
+ loss.setDateYear(year).setDateMonth(month).setAmount(reduce).setCreateTime(System.currentTimeMillis()).setHospId(hospId);
|
|
|
|
+ // 小计只能有一个
|
|
|
|
+ loss.setReportNum(child.getNum()).setReportName(child.getReportName());
|
|
|
|
+ list.add(loss);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -294,31 +277,37 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
*
|
|
*
|
|
* @param hospId 医院id
|
|
* @param hospId 医院id
|
|
* @param reportForm 报表
|
|
* @param reportForm 报表
|
|
|
|
+ * @param list
|
|
* @param year
|
|
* @param year
|
|
* @param month
|
|
* @param month
|
|
*/
|
|
*/
|
|
- private HospProfitAndLoss calcByShareLevel(Long hospId, ReportForm reportForm, int year, int month) {
|
|
|
|
- List<RelationVO> shareLevels = reportRelationService.getAccountRelation(reportForm.getId(), hospId);
|
|
|
|
- List<Long> shareLevelId = shareLevels.stream().map(RelationVO::getCode).map(Long::valueOf).collect(Collectors.toList());
|
|
|
|
|
|
+ private void calcByShareLevel(Long hospId, ReportForm reportForm, List<HospProfitAndLoss> list, int year, int month) {
|
|
|
|
+ List<RelationVO> shareLevels = reportRelationService.getShareLevel(reportForm.getId(), hospId);
|
|
|
|
+ List<Long> shareLevelId = shareLevels.stream().map(RelationVO::getCode).map(Long::valueOf).sorted(Long::compareTo).collect(Collectors.toList());
|
|
if (CollUtil.isEmpty(shareLevelId)) {
|
|
if (CollUtil.isEmpty(shareLevelId)) {
|
|
- return null;
|
|
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
- // 分摊层级计算金额
|
|
|
|
- // TODO: 2021/8/31
|
|
|
|
-
|
|
|
|
List<CostShareLevel> costShareLevels = shareLevelService.listByIds(shareLevelId);
|
|
List<CostShareLevel> costShareLevels = shareLevelService.listByIds(shareLevelId);
|
|
if (costShareLevels.isEmpty()) {
|
|
if (costShareLevels.isEmpty()) {
|
|
throw new CostException("医院分摊层级设置错误," + reportForm.getReportName());
|
|
throw new CostException("医院分摊层级设置错误," + reportForm.getReportName());
|
|
}
|
|
}
|
|
List<Integer> levelSorts = costShareLevels.stream().map(CostShareLevel::getLeverSort).collect(Collectors.toList());
|
|
List<Integer> levelSorts = costShareLevels.stream().map(CostShareLevel::getLeverSort).collect(Collectors.toList());
|
|
- List<AllocationQuery> allocations = allocationQueryService.getByDate(year, month, hospId, levelSorts);
|
|
|
|
|
|
+ List<AllocationQuery> allocations = allocationQueryService.getByDate(year, month, hospId, shareLevelId);
|
|
|
|
+
|
|
if (allocations.isEmpty()) {
|
|
if (allocations.isEmpty()) {
|
|
throw new CostException("医院未分摊本月数据");
|
|
throw new CostException("医院未分摊本月数据");
|
|
}
|
|
}
|
|
|
|
+ List<CostAccountShare> accountShares = accountShareService.getByShareLevelSort(levelSorts, hospId);
|
|
|
|
+ if (accountShares.isEmpty()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+// allocations = allocations.stream().filter(i -> levelSorts.contains(i.getLevelSort())).collect(Collectors.toList());
|
|
BigDecimal reduce = allocations.stream().map(AllocationQuery::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
BigDecimal reduce = allocations.stream().map(AllocationQuery::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
HospProfitAndLoss loss = new HospProfitAndLoss();
|
|
HospProfitAndLoss loss = new HospProfitAndLoss();
|
|
- return loss.setReportName(reportForm.getReportName()).setReportNum(reportForm.getNum())
|
|
|
|
- .setAmount(reduce).setCreateTime(System.currentTimeMillis()).setHospId(hospId);
|
|
|
|
|
|
+ loss.setReportName(reportForm.getReportName()).setReportNum(reportForm.getNum())
|
|
|
|
+ .setAmount(reduce).setCreateTime(System.currentTimeMillis()).setHospId(hospId).setDateYear(year).setDateMonth(month);
|
|
|
|
+ list.add(loss);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -327,12 +316,16 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
* @param hospId 医院id
|
|
* @param hospId 医院id
|
|
* @param reportForm 报表
|
|
* @param reportForm 报表
|
|
* @param incomes 归集收入数据
|
|
* @param incomes 归集收入数据
|
|
|
|
+ * @param list
|
|
* @param allocationQueries 分摊成本数据
|
|
* @param allocationQueries 分摊成本数据
|
|
|
|
+ * @param month
|
|
|
|
+ * @param year
|
|
*/
|
|
*/
|
|
- private HospProfitAndLoss calcByAccount(Long hospId, ReportForm reportForm, List<IncomeCollection> incomes, List<AllocationQuery> allocationQueries) {
|
|
|
|
|
|
+ private void calcByAccount(Long hospId, ReportForm reportForm, List<IncomeCollection> incomes, List<HospProfitAndLoss> list, List<AllocationQuery> allocationQueries, int month, int year) {
|
|
|
|
+ // 报表项目关联的会计科目对象
|
|
List<RelationVO> accountRelations = reportRelationService.getAccountRelation(reportForm.getId(), hospId);
|
|
List<RelationVO> accountRelations = reportRelationService.getAccountRelation(reportForm.getId(), hospId);
|
|
if (accountRelations.isEmpty()) {
|
|
if (accountRelations.isEmpty()) {
|
|
- return null;
|
|
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
List<String> accountCodes = accountRelations.stream().map(RelationVO::getCode).collect(Collectors.toList());
|
|
List<String> accountCodes = accountRelations.stream().map(RelationVO::getCode).collect(Collectors.toList());
|
|
AtomicReference<BigDecimal> calcTotal = new AtomicReference<>();
|
|
AtomicReference<BigDecimal> calcTotal = new AtomicReference<>();
|
|
@@ -346,9 +339,9 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
calcTotal.set(calcTotal.get().add(total));
|
|
calcTotal.set(calcTotal.get().add(total));
|
|
});
|
|
});
|
|
HospProfitAndLoss loss = new HospProfitAndLoss();
|
|
HospProfitAndLoss loss = new HospProfitAndLoss();
|
|
- return loss.setReportName(reportForm.getReportName()).setReportNum(reportForm.getNum())
|
|
|
|
- .setAmount(calcTotal.get()).setCreateTime(System.currentTimeMillis()).setHospId(hospId);
|
|
|
|
-
|
|
|
|
|
|
+ loss.setReportName(reportForm.getReportName()).setReportNum(reportForm.getNum())
|
|
|
|
+ .setAmount(calcTotal.get()).setCreateTime(System.currentTimeMillis()).setHospId(hospId).setDateYear(year).setDateMonth(month);
|
|
|
|
+ list.add(loss);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -412,6 +405,8 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
if (allHospList.isEmpty()) {
|
|
if (allHospList.isEmpty()) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
+ // 查询所有的全院损益数据 内存溢出问题
|
|
|
|
+ List<HospProfitAndLoss> list = getAllDataByDate(year, month, hospId);
|
|
int lastRow = 3;
|
|
int lastRow = 3;
|
|
for (int i = 0; i < allHospList.size(); i++) {
|
|
for (int i = 0; i < allHospList.size(); i++) {
|
|
ReportFormVO parentFormVO = allHospList.get(i);
|
|
ReportFormVO parentFormVO = allHospList.get(i);
|
|
@@ -447,4 +442,253 @@ public class HospProfitAndLossServiceImpl extends ServiceImpl<HospProfitAndLossM
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private List<HospProfitAndLoss> getAllDataByDate(int year, int month, Long hospId) {
|
|
|
|
+ return this.list(
|
|
|
|
+ new LambdaQueryWrapper<HospProfitAndLoss>()
|
|
|
|
+ .eq(HospProfitAndLoss::getHospId, hospId)
|
|
|
|
+ .eq(HospProfitAndLoss::getDateMonth, month)
|
|
|
|
+ .eq(HospProfitAndLoss::getDateYear, year)
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @param date
|
|
|
|
+ * @param hospId
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional
|
|
|
|
+ public void calcByResponsibility(String date, Long hospId) {
|
|
|
|
+ List<Responsibility> leafResp = responsibilityService.getLeafResp(hospId);
|
|
|
|
+ DateTime parse = DateUtil.parse(date);
|
|
|
|
+ int year = DateUtil.year(parse);
|
|
|
|
+ int month = DateUtil.month(parse) + 1;
|
|
|
|
+ this.remove(new LambdaQueryWrapper<HospProfitAndLoss>().eq(HospProfitAndLoss::getDateYear, year).eq(HospProfitAndLoss::getDateMonth, month).eq(HospProfitAndLoss::getHospId, hospId));
|
|
|
|
+ // 得到全院损益计算报表
|
|
|
|
+ List<ReportForm> reportForms = reportFormService.getListByReportType(hospId, ReportTypeEnum.HOSP_PROFIT_LOSS.getType());
|
|
|
|
+ if (CollUtil.isEmpty(reportForms)) {
|
|
|
|
+ throw new CostException("医院未设置全院损益计算报表");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 得到这个月所有收入数据
|
|
|
|
+ List<IncomeCollection> incomes = collectionService.getCollectionsByDate(year, month, hospId);
|
|
|
|
+ if (incomes.isEmpty()) {
|
|
|
|
+ throw new CostException("医院未归集本月收入数据");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 得到这个月的所有成本数据
|
|
|
|
+ List<AllocationQuery> allocationQueries = allocationQueryService.getAllByDate(hospId, year, month);
|
|
|
|
+ if (allocationQueries.isEmpty()) {
|
|
|
|
+ throw new CostException("医院未分摊本月数据");
|
|
|
|
+ }
|
|
|
|
+ List<HospProfitAndLoss> list = new ArrayList<>();
|
|
|
|
+ List<ReportForm> parentForms = reportForms.stream().filter(i -> i.getParentId().equals(0L)).collect(Collectors.toList());
|
|
|
|
+ for (Responsibility responsibility : leafResp) {
|
|
|
|
+ for (ReportForm parentForm : parentForms) {
|
|
|
|
+ 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 {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 处理医院其他收支
|
|
|
|
+ List<CostOtherPaymentsData> otherPaymentsDatas = otherPaymentsDataService.getByMonth(year, month, hospId);
|
|
|
|
+ if (!otherPaymentsDatas.isEmpty()) {
|
|
|
|
+ otherPaymentsDatas.forEach(ele -> {
|
|
|
|
+ HospProfitAndLoss loss = new HospProfitAndLoss();
|
|
|
|
+ loss.setDateYear(year).setDateMonth(month).setReportName(ele.getPaymentsName()).setReportNum(ele.getId().intValue())
|
|
|
|
+ .setCreateTime(System.currentTimeMillis()).setAmount(ele.getTotalAmount()).setHospId(hospId);
|
|
|
|
+// if (ele.getPaymentsType() == 2) {
|
|
|
|
+// loss.setAmount(BigDecimal.ZERO.subtract(ele.getTotalAmount()));
|
|
|
|
+// }
|
|
|
|
+ list.add(loss);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ this.saveBatch(list);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void calcByResponsibilityResp(Long hospId, ReportForm child, List<HospProfitAndLoss> list, int year, int month, Responsibility responsibility) {
|
|
|
|
+
|
|
|
|
+ List<RelationVO> responsibilities = reportRelationService.getResponsibilities(child.getId(), hospId);
|
|
|
|
+ if (responsibilities.isEmpty()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ List<String> responsibilityCodes = responsibilities.stream().map(RelationVO::getCode).collect(Collectors.toList());
|
|
|
|
+ AtomicReference<BigDecimal> calcTotal = new AtomicReference<>();
|
|
|
|
+ calcTotal.set(BigDecimal.ZERO);
|
|
|
|
+ List<AllocationQuery> allocationQueries = allocationQueryService.getByDateAndResp(year, month, hospId, responsibility.getResponsibilityCode());
|
|
|
|
+ responsibilityCodes.forEach(i -> {
|
|
|
|
+ BigDecimal costAmount = allocationQueries.stream().filter(j -> i.equals(j.getResponsibilityCode())).map(AllocationQuery::getAmount)
|
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
+ calcTotal.set(calcTotal.get().add(costAmount));
|
|
|
|
+ });
|
|
|
|
+ HospProfitAndLoss loss = new HospProfitAndLoss();
|
|
|
|
+ loss.setReportName(child.getReportName()).setReportNum(child.getNum()).setResponsibilityCode(responsibility.getResponsibilityCode()).setResponsibilityName(responsibility.getResponsibilityName())
|
|
|
|
+ .setAmount(calcTotal.get()).setCreateTime(System.currentTimeMillis()).setHospId(hospId).setDateYear(year).setDateMonth(month);
|
|
|
|
+ list.add(loss);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void calcByFormulaResp(int year, int month, ReportForm child, List<HospProfitAndLoss> list, Responsibility responsibility) {
|
|
|
|
+ // 得到这个责任中心下所有的已经收集的数据
|
|
|
|
+ List<HospProfitAndLoss> hadCalcLosses = list.stream().filter(i -> i.getResponsibilityCode().equals(responsibility.getResponsibilityCode())).collect(Collectors.toList());
|
|
|
|
+ String calcFormula = child.getCalcFormula();
|
|
|
|
+ // TODO: 2021/8/27 校验公式合法性
|
|
|
|
+ if (StrUtil.isBlank(calcFormula)) {
|
|
|
|
+ throw new CostException("reportForm名称为" + child.getReportName() + "计算公式不正确");
|
|
|
|
+ }
|
|
|
|
+ BigDecimal bigDecimal = calcAmountResp(hadCalcLosses, calcFormula);
|
|
|
|
+
|
|
|
|
+ HospProfitAndLoss loss = new HospProfitAndLoss();
|
|
|
|
+ loss.setDateYear(year).setDateMonth(month).setReportNum(child.getNum()).setReportName(child.getReportName())
|
|
|
|
+ .setAmount(bigDecimal).setCreateTime(System.currentTimeMillis()).setHospId(child.getHospId()).setResponsibilityCode(responsibility.getResponsibilityCode()).setResponsibilityName(responsibility.getResponsibilityName());
|
|
|
|
+ list.add(loss);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private BigDecimal calcAmountResp(List<HospProfitAndLoss> hadCalcLosses, String calcFormula) {
|
|
|
|
+ // 得到所有的编号
|
|
|
|
+ String replace = calcFormula.replace("[", "").replace("]", "").replace("-", ",").replace("+", ",");
|
|
|
|
+ ArrayList<String> numList = CollUtil.newArrayList(replace.split(","));
|
|
|
|
+ // 得到编号的map
|
|
|
|
+ Map<Integer, Integer> numMap = new ConcurrentHashMap<>();
|
|
|
|
+ for (int j = 0; j < numList.size(); j++) {
|
|
|
|
+ numMap.put(j, Integer.parseInt(numList.get(j)));
|
|
|
|
+ }
|
|
|
|
+ List<String> expressions = ReUtil.findAll("[^0-9]", "+" + calcFormula.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> numSet = numMap.keySet();
|
|
|
|
+ List<Integer> nums = new ArrayList<>(numSet);
|
|
|
|
+ AtomicReference<BigDecimal> totalAmount = new AtomicReference<>();
|
|
|
|
+ totalAmount.set(BigDecimal.ZERO);
|
|
|
|
+ for (int i = 0; i < nums.size(); i++) {
|
|
|
|
+ // 编号
|
|
|
|
+ Integer num = numMap.get(i);
|
|
|
|
+ List<HospProfitAndLoss> losses = hadCalcLosses.stream().filter(item -> item.getReportNum().equals(num)).collect(Collectors.toList());
|
|
|
|
+ if (CollUtil.isEmpty(losses)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ HospProfitAndLoss loss = losses.get(0);
|
|
|
|
+ BigDecimal amount = loss.getAmount();
|
|
|
|
+ String str = expressionMap.get(i);
|
|
|
|
+ if (str.equals("+")) {
|
|
|
|
+ totalAmount.set(totalAmount.get().add(amount));
|
|
|
|
+ } else {
|
|
|
|
+ totalAmount.set(totalAmount.get().subtract(amount));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return totalAmount.get();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void calcByLitterCountResp(int year, int month, ReportForm child, List<ReportForm> children,
|
|
|
|
+ List<HospProfitAndLoss> list, Long hospId, Responsibility responsibility) {
|
|
|
|
+ List<HospProfitAndLoss> thisRespCodeList = list.stream().filter(i -> i.getResponsibilityCode().equals(responsibility.getResponsibilityCode())).collect(Collectors.toList());
|
|
|
|
+ List<ReportForm> thisForEachList = children.stream().filter(i -> !i.getCalcType().equals(CalcTypeEnum.LITTER_COUNT.getType())).collect(Collectors.toList());
|
|
|
|
+ List<HospProfitAndLoss> collect = thisRespCodeList.stream().filter(i -> thisForEachList.stream().map(ReportForm::getNum).collect(Collectors.toList()).contains(i.getReportNum())).collect(Collectors.toList());
|
|
|
|
+ if (collect.isEmpty()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ BigDecimal reduce = collect.stream().map(HospProfitAndLoss::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
+ HospProfitAndLoss loss = new HospProfitAndLoss();
|
|
|
|
+ loss.setDateYear(year).setDateMonth(month)
|
|
|
|
+ .setAmount(reduce).setCreateTime(System.currentTimeMillis()).setHospId(hospId);
|
|
|
|
+ // 小计只能有一个
|
|
|
|
+ loss.setReportNum(child.getNum()).setReportName(child.getReportName())
|
|
|
|
+ .setResponsibilityCode(responsibility.getResponsibilityCode())
|
|
|
|
+ .setResponsibilityName(responsibility.getResponsibilityName());
|
|
|
|
+ list.add(loss);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void calcByShareLevelResp(Long hospId, ReportForm child, List<HospProfitAndLoss> list, int year, int month, Responsibility responsibility) {
|
|
|
|
+ List<RelationVO> shareLevels = reportRelationService.getShareLevel(child.getId(), hospId);
|
|
|
|
+ List<Long> shareLevelId = shareLevels.stream().map(RelationVO::getCode).map(Long::valueOf).sorted(Long::compareTo).collect(Collectors.toList());
|
|
|
|
+ if (CollUtil.isEmpty(shareLevelId)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ List<CostShareLevel> costShareLevels = shareLevelService.listByIds(shareLevelId);
|
|
|
|
+ if (costShareLevels.isEmpty()) {
|
|
|
|
+ throw new CostException("医院分摊层级设置错误," + child.getReportName());
|
|
|
|
+ }
|
|
|
|
+ List<Integer> levelSorts = costShareLevels.stream().map(CostShareLevel::getLeverSort).collect(Collectors.toList());
|
|
|
|
+ List<AllocationQuery> allocations = allocationQueryService.getByDateRespn(year, month, hospId, shareLevelId, responsibility.getResponsibilityCode());
|
|
|
|
+
|
|
|
|
+ if (allocations.isEmpty()) {
|
|
|
|
+ throw new CostException("医院未分摊本月数据");
|
|
|
|
+ }
|
|
|
|
+ List<CostAccountShare> accountShares = accountShareService.getByShareLevelSort(levelSorts, hospId);
|
|
|
|
+ if (accountShares.isEmpty()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ BigDecimal reduce = allocations.stream().map(AllocationQuery::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
+ HospProfitAndLoss loss = new HospProfitAndLoss();
|
|
|
|
+ loss.setReportName(child.getReportName()).setReportNum(child.getNum())
|
|
|
|
+ .setAmount(reduce).setCreateTime(System.currentTimeMillis()).setHospId(hospId).setDateYear(year).setDateMonth(month)
|
|
|
|
+ .setResponsibilityCode(responsibility.getResponsibilityCode()).setResponsibilityName(responsibility.getResponsibilityName())
|
|
|
|
+ ;
|
|
|
|
+ list.add(loss);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void calcByAccountByResp(Long hospId, ReportForm child, List<HospProfitAndLoss> list, int month, int year, Responsibility responsibility) {
|
|
|
|
+
|
|
|
|
+ // 报表项目关联的会计科目对象
|
|
|
|
+ List<RelationVO> accountRelations = reportRelationService.getAccountRelation(child.getId(), hospId);
|
|
|
|
+ if (accountRelations.isEmpty()) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ List<String> accountCodes = accountRelations.stream().map(RelationVO::getCode).collect(Collectors.toList());
|
|
|
|
+ AtomicReference<BigDecimal> calcTotal = new AtomicReference<>();
|
|
|
|
+ calcTotal.set(BigDecimal.ZERO);
|
|
|
|
+ List<IncomeCollection> incomes = collectionService.getCollectionsByDateAndResp(year, month, hospId, responsibility.getResponsibilityCode());
|
|
|
|
+ List<AllocationQuery> allocationQueries = allocationQueryService.getByDateAndResp(year, month, hospId, responsibility.getResponsibilityCode());
|
|
|
|
+ accountCodes.forEach(i -> {
|
|
|
|
+ BigDecimal incomeAmount = incomes.stream().filter(j -> i.equals(j.getAccountingCode())).map(IncomeCollection::getAmount)
|
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
+ BigDecimal costAmount = allocationQueries.stream().filter(j -> i.equals(j.getAccountingCode())).map(AllocationQuery::getAmount)
|
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
+ BigDecimal total = incomeAmount.add(costAmount);
|
|
|
|
+ calcTotal.set(calcTotal.get().add(total));
|
|
|
|
+ });
|
|
|
|
+ HospProfitAndLoss loss = new HospProfitAndLoss();
|
|
|
|
+ loss.setReportName(child.getReportName()).setReportNum(child.getNum())
|
|
|
|
+ .setAmount(calcTotal.get()).setCreateTime(System.currentTimeMillis()).setHospId(hospId).setDateYear(year).setDateMonth(month)
|
|
|
|
+ .setResponsibilityCode(responsibility.getResponsibilityCode()).setResponsibilityName(responsibility.getResponsibilityName())
|
|
|
|
+ ;
|
|
|
|
+ list.add(loss);
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|