|
@@ -1,6 +1,5 @@
|
|
|
package com.imed.costaccount.service.impl;
|
|
|
|
|
|
-import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
@@ -12,9 +11,9 @@ import com.imed.costaccount.common.exception.CostException;
|
|
|
import com.imed.costaccount.common.util.*;
|
|
|
import com.imed.costaccount.constants.NumberConstant;
|
|
|
import com.imed.costaccount.enums.DateStyleEnum;
|
|
|
+import com.imed.costaccount.mapper.AllocationMapper;
|
|
|
import com.imed.costaccount.mapper.CostCostingGroupMapper;
|
|
|
import com.imed.costaccount.model.*;
|
|
|
-import com.imed.costaccount.model.dto.StartDTO;
|
|
|
import com.imed.costaccount.model.vo.*;
|
|
|
import com.imed.costaccount.service.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -26,7 +25,6 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
@Service("costCostingGroupService")
|
|
@@ -43,36 +41,20 @@ public class CostCostingGroupServiceImpl extends ServiceImpl<CostCostingGroupMap
|
|
|
|
|
|
private final ResponsibilityService responsibilityService;
|
|
|
|
|
|
- private final CostCostingCollectionService costingCollectionService;
|
|
|
+ private final AllocationMapper allocationMapper;
|
|
|
|
|
|
- private final CostShareLevelService shareLevelService;
|
|
|
-
|
|
|
- private final CostAccountShareService accountShareService;
|
|
|
-
|
|
|
- private final ShareParamValueService shareParamValueService;
|
|
|
-
|
|
|
- private final CostShareParamService shareParamService;
|
|
|
|
|
|
public CostCostingGroupServiceImpl(CostIncomeGroupServiceImpl costIncomeGroupService,
|
|
|
AccountingService accountingService,
|
|
|
AccountingProductService accountingProductService,
|
|
|
CostIncomeFileService costIncomeFileService,
|
|
|
- ResponsibilityService responsibilityService,
|
|
|
- CostCostingCollectionService costingCollectionService,
|
|
|
- CostShareLevelService shareLevelService,
|
|
|
- CostAccountShareService accountShareService,
|
|
|
- ShareParamValueService shareParamValueService,
|
|
|
- CostShareParamService shareParamService) {
|
|
|
+ ResponsibilityService responsibilityService, AllocationMapper allocationMapper) {
|
|
|
this.costIncomeGroupService = costIncomeGroupService;
|
|
|
this.accountingService = accountingService;
|
|
|
this.accountingProductService = accountingProductService;
|
|
|
this.costIncomeFileService = costIncomeFileService;
|
|
|
this.responsibilityService = responsibilityService;
|
|
|
- this.costingCollectionService = costingCollectionService;
|
|
|
- this.shareLevelService = shareLevelService;
|
|
|
- this.accountShareService = accountShareService;
|
|
|
- this.shareParamValueService = shareParamValueService;
|
|
|
- this.shareParamService = shareParamService;
|
|
|
+ this.allocationMapper = allocationMapper;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -130,9 +112,9 @@ public class CostCostingGroupServiceImpl extends ServiceImpl<CostCostingGroupMap
|
|
|
|
|
|
List<AllocationVO> list = baseMapper.queryAllocation(startIndex, pageSize, year, month, hospId);
|
|
|
list.forEach(i -> {
|
|
|
- List<CostCostingCollection> collections = costingCollectionService.list(new LambdaQueryWrapper<CostCostingCollection>().eq(CostCostingCollection::getYear, i.getYear())
|
|
|
- .eq(CostCostingCollection::getMonth, i.getMonth())
|
|
|
- .eq(CostCostingCollection::getHospId, hospId)
|
|
|
+ List<Allocation> collections = allocationMapper.selectList(new LambdaQueryWrapper<Allocation>().eq(Allocation::getDateYear, i.getYear())
|
|
|
+ .eq(Allocation::getDateMonth, i.getMonth())
|
|
|
+ .eq(Allocation::getHospId, hospId)
|
|
|
);
|
|
|
if (!collections.isEmpty()) {
|
|
|
i.setIsAllocation(true);
|
|
@@ -142,182 +124,6 @@ public class CostCostingGroupServiceImpl extends ServiceImpl<CostCostingGroupMap
|
|
|
return new PageUtils(list, count, pageSize, current);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 开始成本分摊
|
|
|
- *
|
|
|
- * @param startDTO {@link StartDTO}
|
|
|
- * @param hospId 医院id
|
|
|
- */
|
|
|
- @Override
|
|
|
- @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
|
|
- public void startAllocation(StartDTO startDTO, Long hospId) {
|
|
|
- // 这个月成本数据数据
|
|
|
- List<CostCostingGroup> list = this.list(
|
|
|
- new LambdaQueryWrapper<CostCostingGroup>()
|
|
|
- .eq(CostCostingGroup::getDateYear, startDTO.getYear())
|
|
|
- .eq(CostCostingGroup::getDateMonth, startDTO.getMonth())
|
|
|
- .eq(CostCostingGroup::getHospId, hospId)
|
|
|
- );
|
|
|
- // 没有重新导入
|
|
|
- if (list.isEmpty()) {
|
|
|
- throw new CostException("本月成本数据暂未导入");
|
|
|
- }
|
|
|
-
|
|
|
- Map<String, List<CostCostingGroup>> responsibilityCodeMap = list.stream().collect(Collectors.groupingBy(CostCostingGroup::getResponsibilityCode));
|
|
|
- Set<String> responsibilityCodes = responsibilityCodeMap.keySet();
|
|
|
- for (String responsibilityCode : responsibilityCodes) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-// // 得到这个月导入的成本分摊参数值数据
|
|
|
-// List<ShareParamValue> shareParamValues = shareParamValueService.list(
|
|
|
-// new LambdaQueryWrapper<ShareParamValue>()
|
|
|
-// .eq(ShareParamValue::getHospId, hospId)
|
|
|
-// .eq(ShareParamValue::getDateYear, startDTO.getYear())
|
|
|
-// .eq(ShareParamValue::getDateMonth, startDTO.getMonth())
|
|
|
-// );
|
|
|
-// // 没有重新导入
|
|
|
-// if (shareParamValues.isEmpty()) {
|
|
|
-// throw new CostException("本月分摊参数值数据未导入");
|
|
|
-// }
|
|
|
-// // 通过会计科目聚合月成本数据
|
|
|
-// Map<String, List<CostCostingGroup>> accountMap = list.stream().collect(Collectors.groupingBy(CostCostingGroup::getAccountCode));
|
|
|
-//
|
|
|
-// // 删除该年月已经过的数据
|
|
|
-// costingCollectionService.remove(
|
|
|
-// new LambdaQueryWrapper<CostCostingCollection>()
|
|
|
-// .eq(CostCostingCollection::getYear, startDTO.getYear())
|
|
|
-// .eq(CostCostingCollection::getMonth, startDTO.getMonth())
|
|
|
-// .eq(CostCostingCollection::getHospId, hospId)
|
|
|
-// );
|
|
|
-// // 得到这个医院所有的分摊层级(通过sort_level正序排序的数据)
|
|
|
-// List<CostShareLevelVO> shareLevelVOs = shareLevelService.getAll(hospId);
|
|
|
-// if (CollUtil.isEmpty(shareLevelVOs)) {
|
|
|
-// throw new CostException("请先设置医院分摊层级");
|
|
|
-// }
|
|
|
-// List<CostCostingCollection> costingCollections = new ArrayList<>();
|
|
|
-// // 遍历这个医院的分摊层级
|
|
|
-// for (int i = 0; i < shareLevelVOs.size(); i++) {
|
|
|
-// // 最后一层不分摊
|
|
|
-// if (i == shareLevelVOs.size() - 1) {
|
|
|
-// break;
|
|
|
-// }
|
|
|
-// // 通过分摊层级id 得到对应的责任中心
|
|
|
-// CostShareLevelVO shareLevelVO = shareLevelVOs.get(i);
|
|
|
-// Responsibility responsibility = responsibilityService.getByLevelId(shareLevelVO.getId(), hospId);
|
|
|
-// // 如果这个分摊层级没有责任中心那么不分摊
|
|
|
-// if (Objects.isNull(responsibility)) {
|
|
|
-// continue;
|
|
|
-// }
|
|
|
-// // 通过责任中心code去得到分摊参数对应信息 并得到对应的会计科目和对应的分摊参数比例等信息
|
|
|
-// List<CostAccountShare> accountShares = accountShareService.getByResponsibility(responsibility.getResponsibilityCode(), hospId);
|
|
|
-// if (accountShares.isEmpty()) {
|
|
|
-// continue;
|
|
|
-// }
|
|
|
-// // 遍历分摊参数对应信息
|
|
|
-// for (CostAccountShare accountShare : accountShares) {
|
|
|
-// // 得到对应的会计中心code
|
|
|
-// String accountingCodes = accountShare.getAccountingCodes();
|
|
|
-// // 没有会计中心,合并计算未设置好分摊参数比例
|
|
|
-// if (StrUtil.isBlank(accountingCodes) && shareLevelVO.getCalcType().equals(1)) {
|
|
|
-// throw new CostException("责任中心:" + accountShare.getResponsibilityName() + ";会计中心为:" + accountShare.getAccountingNames() + ";未设置分摊参数比例");
|
|
|
-// }
|
|
|
-// // 会计科目不存在且是合并计算,这种情况直接分摊下去
|
|
|
-// String paramList = accountShare.getParamList();
|
|
|
-// if (StrUtil.isBlank(paramList)) {
|
|
|
-// throw new CostException("责任中心:" + accountShare.getResponsibilityName() + ";会计中心为:" + accountShare.getAccountingNames() + (";未设置分摊参数比例值"));
|
|
|
-// }
|
|
|
-// // 分摊参数以及比例集合
|
|
|
-// List<AccountShareVO> accountShareVOs = JacksonUtil.str2ObjList(paramList, List.class, AccountShareVO.class);
|
|
|
-// // 没有会计中心直接分摊的情况
|
|
|
-// if (StrUtil.isBlank(accountingCodes) && shareLevelVO.getCalcType().equals(0)) {
|
|
|
-// // 直接分摊到责任中心去 这情况只有一个分摊计划
|
|
|
-// AccountShareVO accountShareVO = accountShareVOs.get(0);
|
|
|
-// Long shareParamId = accountShareVO.getId();
|
|
|
-// CostShareParam shareParam = shareParamService.getByIdAndCalcType(shareParamId);
|
|
|
-// if (Objects.isNull(shareParam)) {
|
|
|
-// continue;
|
|
|
-// }
|
|
|
-// String accountCodeStr = shareParam.getAccountingCodes();
|
|
|
-// if (StrUtil.isBlank(accountCodeStr)) {
|
|
|
-// throw new CostException("成本分摊参数:" + shareParam.getShareParamName() + ";设置会计科目不存在");
|
|
|
-// }
|
|
|
-// ArrayList<String> accountCodes = CollUtil.newArrayList(accountCodeStr.split(StrUtil.COMMA));
|
|
|
-// String shareParamPout = accountShareVO.getShareParamPopout();
|
|
|
-// BigDecimal rate = new BigDecimal("1");
|
|
|
-// if (!"100".equals(shareParamPout)) {
|
|
|
-// rate = new BigDecimal("0." + shareParamPout);
|
|
|
-// }
|
|
|
-// // 计算分摊数值
|
|
|
-// BigDecimal valueNum = shareParamValues.stream().map(ShareParamValue::getValueNum).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
-// for (String accountCode : accountCodes) {
|
|
|
-// Accounting account = this.getAccountByCode(accountCode, hospId);
|
|
|
-// List<CostCostingGroup> costCostingGroups = accountMap.get(accountCode);
|
|
|
-// if (CollUtil.isEmpty(costCostingGroups)) {
|
|
|
-// continue;
|
|
|
-// }
|
|
|
-// BigDecimal accountCodeAmount = costCostingGroups.stream().map(CostCostingGroup::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
-// CostCostingCollection collection = new CostCostingCollection();
|
|
|
-// collection.setYear(startDTO.getYear()).setMonth(startDTO.getMonth()).setResponsibilityCode(accountShare.getResponsibilityCode())
|
|
|
-// .setResponsibilityName(accountShare.getResponsibilityName()).setLeverSort(shareLevelVO.getLeverSort())
|
|
|
-// .setShareLevelName(shareLevelVO.getShareName()).setAccountCode(accountCode).setAccountName(account.getAccountingName())
|
|
|
-// .setIsBaseCost(account.getIsBaseCost()).setAmount(accountCodeAmount).setCreateTime(System.currentTimeMillis())
|
|
|
-// .setHospId(hospId).setShareParam(accountShareVO.getShareParamName()).setShareParamProportion(rate.toString())
|
|
|
-// .setShareValue(valueNum)
|
|
|
-// // 目标分摊层级暂不处理
|
|
|
-// //.setTargetResponsibilityCode().setTargetResponsibilityName()
|
|
|
-// .setShareAmount(rate.multiply(accountCodeAmount));
|
|
|
-// costingCollections.add(collection);
|
|
|
-// }
|
|
|
-// continue;
|
|
|
-// }
|
|
|
-// // 责任中心对应的会计科目代码列表
|
|
|
-// ArrayList<String> accountCodeList = CollUtil.newArrayList(accountingCodes.split(StrUtil.COMMA));
|
|
|
-// for (String accountCode : accountCodeList) {
|
|
|
-// // 分摊前数据 通过会计科目得到
|
|
|
-// List<CostCostingGroup> costCostingGroups = accountMap.get(accountCode);
|
|
|
-//
|
|
|
-// if (CollUtil.isEmpty(costCostingGroups)) {
|
|
|
-// continue;
|
|
|
-// }
|
|
|
-// BigDecimal accountCodeAmount = costCostingGroups.stream().map(CostCostingGroup::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
-// Accounting accounting = this.getAccountByCode(accountCode, hospId);
|
|
|
-// if (StrUtil.isBlank(paramList)) {
|
|
|
-// throw new CostException("未设置分摊参数比例值");
|
|
|
-// }
|
|
|
-// // 分摊比例相关数据
|
|
|
-// if (CollUtil.isEmpty(accountShareVOs)) {
|
|
|
-// throw new CostException("分摊参数对应比例错误");
|
|
|
-// }
|
|
|
-// for (AccountShareVO accountShareVO : accountShareVOs) {
|
|
|
-// CostCostingCollection collection = new CostCostingCollection();
|
|
|
-// String shareParamPout = accountShareVO.getShareParamPopout();
|
|
|
-// BigDecimal rate = new BigDecimal("1");
|
|
|
-// if (!"100".equals(shareParamPout)) {
|
|
|
-// rate = new BigDecimal("0." + shareParamPout);
|
|
|
-// }
|
|
|
-// // 计算分摊数值
|
|
|
-// BigDecimal valueNum = shareParamValues.stream().map(ShareParamValue::getValueNum).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
-// collection.setYear(startDTO.getYear()).setMonth(startDTO.getMonth()).setResponsibilityCode(accountShare.getResponsibilityCode())
|
|
|
-// .setResponsibilityName(accountShare.getResponsibilityName()).setLeverSort(shareLevelVO.getLeverSort())
|
|
|
-// .setShareLevelName(shareLevelVO.getShareName()).setAccountCode(accountCode).setAccountName(accounting.getAccountingName())
|
|
|
-// .setIsBaseCost(accounting.getIsBaseCost()).setAmount(accountCodeAmount).setCreateTime(System.currentTimeMillis())
|
|
|
-// .setHospId(hospId).setShareParam(accountShareVO.getShareParamName()).setShareParamProportion(rate.toString())
|
|
|
-// .setShareValue(valueNum)
|
|
|
-// // 目标分摊层级暂不处理
|
|
|
-// //.setTargetResponsibilityCode().setTargetResponsibilityName()
|
|
|
-// .setShareAmount(rate.multiply(accountCodeAmount));
|
|
|
-// costingCollections.add(collection);
|
|
|
-//// costingCollectionService.save(collection);
|
|
|
-// }
|
|
|
-//
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// log.info("list:{}", costingCollections);
|
|
|
-// costingCollectionService.saveBatch(costingCollections);
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 通过code获取名称
|