|
@@ -1,14 +1,17 @@
|
|
|
package com.imed.costaccount.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.imed.costaccount.common.exception.CostException;
|
|
|
+import com.imed.costaccount.common.util.BeanUtil;
|
|
|
import com.imed.costaccount.common.util.JsonUtil;
|
|
|
import com.imed.costaccount.common.util.PageUtils;
|
|
|
import com.imed.costaccount.constants.NumberConstant;
|
|
|
import com.imed.costaccount.mapper.CostAccountShareMapper;
|
|
|
import com.imed.costaccount.model.*;
|
|
|
+import com.imed.costaccount.model.dto.AccountShareCopyDto;
|
|
|
import com.imed.costaccount.model.dto.CostAccountShareEditDto;
|
|
|
import com.imed.costaccount.model.dto.CostAccountShareSaveDto;
|
|
|
import com.imed.costaccount.model.dto.ShareParamEditDto;
|
|
@@ -17,7 +20,6 @@ import com.imed.costaccount.model.vo.CostShareParamStatusVO;
|
|
|
import com.imed.costaccount.model.vo.CostShareParamVO;
|
|
|
import com.imed.costaccount.model.vo.ShareParamProportionVO;
|
|
|
import com.imed.costaccount.service.*;
|
|
|
-import com.imed.costaccount.common.util.BeanUtil;
|
|
|
import org.apache.shiro.SecurityUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
@@ -25,10 +27,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -69,40 +68,39 @@ public class CostAccountShareServiceImpl extends ServiceImpl<CostAccountShareMap
|
|
|
List<CostAccountShare> costAccountShareList = pages.getRecords();
|
|
|
|
|
|
List<CostAccountShareVO> costAccountShareVOList = BeanUtil.convertList(costAccountShareList, CostAccountShareVO.class);
|
|
|
- getMessage(hospId, costAccountShareVOList);
|
|
|
- //
|
|
|
+// getMessage(hospId, costAccountShareVOList);
|
|
|
PageUtils pageUtils = new PageUtils(pages);
|
|
|
pageUtils.setList(costAccountShareVOList);
|
|
|
return pageUtils;
|
|
|
}
|
|
|
|
|
|
- private void getMessage(Long hospId, List<CostAccountShareVO> costAccountShareList) {
|
|
|
- // 设置责任中心的数据 与 会计科目的数据从对应的id里面获取
|
|
|
- List<Responsibility> list = responsibilityService.list(new QueryWrapper<Responsibility>().lambda().eq(Responsibility::getHospId, hospId));
|
|
|
- List<Accounting> accountingList = accountingService.list(new QueryWrapper<Accounting>().lambda().eq(Accounting::getHospId, hospId));
|
|
|
- Map<Long, List<Responsibility>> resMap = list.stream().collect(Collectors.groupingBy(Responsibility::getId));
|
|
|
- Map<Long, List<Accounting>> accountMap = accountingList.stream().collect(Collectors.groupingBy(Accounting::getId));
|
|
|
- costAccountShareList.forEach(i->{
|
|
|
- Long id = i.getResponsibilityId();
|
|
|
- List<Responsibility> responsibilities = resMap.get(id);
|
|
|
- if (!CollectionUtils.isEmpty(responsibilities)){
|
|
|
- i.setResponsibilityId(id);
|
|
|
- i.setResponsibilityName(responsibilities.get(0).getResponsibilityName());
|
|
|
- i.setResponsibilityCode(responsibilities.get(0).getResponsibilityCode());
|
|
|
-
|
|
|
- }
|
|
|
- Long accountingId = i.getAccountingId();
|
|
|
- if (accountingId>0){
|
|
|
- List<Accounting> accountingList1 = accountMap.get(accountingId);
|
|
|
- if (!CollectionUtils.isEmpty(accountingList1)){
|
|
|
- i.setAccountingId(accountingId);
|
|
|
- i.setAccountingName(accountingList1.get(0).getAccountingName());
|
|
|
- i.setAccountingCode(accountingList1.get(0).getAccountingCode());
|
|
|
- i.setAllParentIds(accountingList1.get(0).getAllParentIds());
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
+// private void getMessage(Long hospId, List<CostAccountShareVO> costAccountShareList) {
|
|
|
+// // 设置责任中心的数据 与 会计科目的数据从对应的id里面获取
|
|
|
+// List<Responsibility> list = responsibilityService.list(new QueryWrapper<Responsibility>().lambda().eq(Responsibility::getHospId, hospId));
|
|
|
+// List<Accounting> accountingList = accountingService.list(new QueryWrapper<Accounting>().lambda().eq(Accounting::getHospId, hospId));
|
|
|
+// Map<Long, List<Responsibility>> resMap = list.stream().collect(Collectors.groupingBy(Responsibility::getId));
|
|
|
+// Map<Long, List<Accounting>> accountMap = accountingList.stream().collect(Collectors.groupingBy(Accounting::getId));
|
|
|
+// costAccountShareList.forEach(i->{
|
|
|
+// Long id = i.getResponsibilityId();
|
|
|
+// List<Responsibility> responsibilities = resMap.get(id);
|
|
|
+// if (!CollectionUtils.isEmpty(responsibilities)){
|
|
|
+// i.setResponsibilityId(id);
|
|
|
+// i.setResponsibilityName(responsibilities.get(0).getResponsibilityName());
|
|
|
+// i.setResponsibilityCode(responsibilities.get(0).getResponsibilityCode());
|
|
|
+//
|
|
|
+// }
|
|
|
+// Long accountingId = i.getAccountingId();
|
|
|
+// if (accountingId>0){
|
|
|
+// List<Accounting> accountingList1 = accountMap.get(accountingId);
|
|
|
+// if (!CollectionUtils.isEmpty(accountingList1)){
|
|
|
+// i.setAccountingId(accountingId);
|
|
|
+// i.setAccountingName(accountingList1.get(0).getAccountingName());
|
|
|
+// i.setAccountingCode(accountingList1.get(0).getAccountingCode());
|
|
|
+// i.setAllParentIds(accountingList1.get(0).getAllParentIds());
|
|
|
+// }
|
|
|
+// }
|
|
|
+// });
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
|
* 保存成本参数对应成本对照表
|
|
@@ -144,37 +142,43 @@ public class CostAccountShareServiceImpl extends ServiceImpl<CostAccountShareMap
|
|
|
costAccountShareSaveDto.setResponsibilityCode(responsibility.getResponsibilityCode());
|
|
|
costAccountShareSaveDto.setResponsibilityName(responsibility.getResponsibilityName());
|
|
|
costAccountShareSaveDto.setShareLevel(responsibility.getShareLevel());
|
|
|
- if (!StringUtils.isEmpty(costAccountShareSaveDto.getAccountingId()) && costAccountShareSaveDto.getAccountingId() > 0){
|
|
|
- // 如果输入成本科目的情况下
|
|
|
- Accounting accounting = accountingService.getOne(new QueryWrapper<Accounting>().lambda().eq(Accounting::getHospId, hospId).eq(Accounting::getId, costAccountShareSaveDto.getAccountingId()));
|
|
|
- if (Objects.isNull(accounting)){
|
|
|
- throw new CostException(500,"输入的成本科目不存在");
|
|
|
+ if (!StringUtils.isEmpty(costAccountShareSaveDto.getAccountingIds())){
|
|
|
+ // 这个责任中心允许输入会计科目
|
|
|
+ List<String> accountIdList = Arrays.asList(costAccountShareSaveDto.getAccountingIds().split(StrUtil.COMMA));
|
|
|
+ List<Accounting> accountingList = accountingService.list(new QueryWrapper<Accounting>().lambda().eq(Accounting::getHospId, hospId).in(Accounting::getId, accountIdList).orderByDesc(Accounting::getCreateTime));
|
|
|
+ if (CollectionUtils.isEmpty(accountingList)){
|
|
|
+ throw new CostException(500,"输入的会计科目不存在");
|
|
|
}else {
|
|
|
- costAccountShareSaveDto.setAccountingId(accounting.getId());
|
|
|
- costAccountShareSaveDto.setAccountingName(accounting.getAccountingName());
|
|
|
- costAccountShareSaveDto.setAccountingCode(accounting.getAccountingCode());
|
|
|
+ String accountIds = accountingList.stream().map(Accounting::getId).collect(Collectors.toList()).stream().map(String::valueOf).collect(Collectors.joining(StrUtil.COMMA));
|
|
|
+ costAccountShareSaveDto.setAccountingIds(accountIds);
|
|
|
+ String accountNames = accountingList.stream().map(Accounting::getAccountingName).map(String::valueOf).collect(Collectors.joining(StrUtil.COMMA));
|
|
|
+ costAccountShareSaveDto.setAccountingNames(accountNames);
|
|
|
+ String accountCodes = accountingList.stream().map(Accounting::getAccountingCode).map(String::valueOf).collect(Collectors.joining(StrUtil.COMMA));
|
|
|
+ costAccountShareSaveDto.setAccountingCodes(accountCodes);
|
|
|
}
|
|
|
// 检验输入的责任中心与匹配的成本科目是否存在
|
|
|
List<CostAccountShare> costAccountShareList = baseMapper.selectList(new QueryWrapper<CostAccountShare>().lambda().eq(CostAccountShare::getHospId,hospId));
|
|
|
Map<String, List<CostAccountShare>> costAccountMap = costAccountShareList.stream().collect(Collectors.groupingBy(CostAccountShare::getResponsibilityCode));
|
|
|
List<CostAccountShare> list = costAccountMap.get(costAccountShareSaveDto.getResponsibilityCode());
|
|
|
if (!CollectionUtils.isEmpty(list)){
|
|
|
- String accountingCode = list.get(0).getAccountingCode();
|
|
|
- if (accountingCode.equals(costAccountShareSaveDto.getAccountingCode())){
|
|
|
- throw new CostException(500,"输入的责任中心对应的成本科目已存在");
|
|
|
+ String accountingIds = list.get(0).getAccountingIds();
|
|
|
+ List<String> accountIdListRequest = Arrays.asList(accountingIds.split(StrUtil.COMMA));
|
|
|
+ if (!Collections.disjoint(accountIdListRequest,accountIdList)){
|
|
|
+ throw new CostException(500,"存在重复的数据");
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
- // 检验输入的这个责任中心是否允许输入成本科目
|
|
|
+ // 检验输入的这个责任中心是否允许输入会计科目
|
|
|
Long shareId = responsibility.getShareId();
|
|
|
CostShareLevel costShareLevel = costShareLevelService.getOne(new QueryWrapper<CostShareLevel>().lambda()
|
|
|
.eq(CostShareLevel::getHospId, hospId).eq(CostShareLevel::getId, shareId));
|
|
|
if (Objects.nonNull(costShareLevel)){
|
|
|
- if ((!StringUtils.isEmpty(costAccountShareSaveDto.getAccountingId()) && costAccountShareSaveDto.getAccountingId() > 0) && NumberConstant.ZERO.equals(costShareLevel.getCalcType())){
|
|
|
- throw new CostException(500,"合并计算不允许选择成本科目");
|
|
|
+ if ((!StringUtils.isEmpty(costAccountShareSaveDto.getAccountingIds())) && NumberConstant.ZERO.equals(costShareLevel.getCalcType())){
|
|
|
+ throw new CostException(500,"合并计算不允许选择会计科目");
|
|
|
}
|
|
|
- if ((!StringUtils.isEmpty(costAccountShareSaveDto.getAccountingId()) && costAccountShareSaveDto.getAccountingId() <= 0) && NumberConstant.ONE.equals(costShareLevel.getCalcType())){
|
|
|
- throw new CostException(500,"分开计算的责任中心需要选择成本科目");
|
|
|
+ if ((StringUtils.isEmpty(costAccountShareSaveDto.getAccountingIds())) && NumberConstant.ONE.equals(costShareLevel.getCalcType())){
|
|
|
+ throw new CostException(500,"分开计算的责任中心需要选择会计科目");
|
|
|
}
|
|
|
}else {
|
|
|
throw new CostException(500,"对不起该责任中心没有对应分摊层级");
|
|
@@ -315,4 +319,70 @@ public class CostAccountShareServiceImpl extends ServiceImpl<CostAccountShareMap
|
|
|
return costShareParamStatusVOList;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 拷贝
|
|
|
+ *
|
|
|
+ * @param accountShareCopyDto 赋值数据
|
|
|
+ * @param hospId 医院Id
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
|
|
|
+ public void copyAccountShareData(AccountShareCopyDto accountShareCopyDto, Long hospId) {
|
|
|
+ Long id = accountShareCopyDto.getId();
|
|
|
+ CostAccountShare costAccountShare = this.getById(id);
|
|
|
+ if (Objects.isNull(costAccountShare)){
|
|
|
+ throw new CostException(500,"成本分摊参数设置对应数据不存在");
|
|
|
+ }
|
|
|
+ List<CostAccountShare> accountShareList = new ArrayList<>();
|
|
|
+ List<Long> responsibilityIds = accountShareCopyDto.getResponsibilityIds();
|
|
|
+ Map<Long, Responsibility> responsibilityMap = responsibilityService.list(new QueryWrapper<Responsibility>().lambda()
|
|
|
+ .eq(Responsibility::getHospId, hospId)).stream().collect(Collectors.toMap(Responsibility::getId, synOne->synOne));
|
|
|
+ long millis = System.currentTimeMillis();
|
|
|
+ responsibilityIds.forEach(i->{
|
|
|
+ CostAccountShare accountShareRequest = BeanUtil.convertObj(costAccountShare, CostAccountShare.class);
|
|
|
+ accountShareRequest.setId(null);
|
|
|
+ accountShareRequest.setCreateTime(millis);
|
|
|
+ Responsibility responsibility = responsibilityMap.get(i);
|
|
|
+ accountShareRequest.setResponsibilityId(i);
|
|
|
+ accountShareRequest.setResponsibilityCode(responsibility.getResponsibilityCode());
|
|
|
+ accountShareRequest.setResponsibilityName(responsibility.getResponsibilityName());
|
|
|
+ accountShareRequest.setShareLevel(responsibility.getShareLevel());
|
|
|
+ accountShareList.add(accountShareRequest);
|
|
|
+ });
|
|
|
+ this.saveBatch(accountShareList);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取指定类型的责任中心集合 分开计算还是合并计算
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * @param accountShareId
|
|
|
+ * @param hospId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<Responsibility> getResponsibilityCalType(Long accountShareId, Long hospId) {
|
|
|
+ CostAccountShare costAccountShare = this.getById(accountShareId);
|
|
|
+ if (Objects.isNull(costAccountShare)){
|
|
|
+ throw new CostException(500,"成本分摊参数设置对应数据不存在");
|
|
|
+ }
|
|
|
+ Long responsibilityId = costAccountShare.getResponsibilityId();
|
|
|
+ Responsibility responsibility = responsibilityService.getById(responsibilityId);
|
|
|
+ Long shareId = responsibility.getShareId();
|
|
|
+ CostShareLevel costShareLevel = costShareLevelService.getById(shareId);
|
|
|
+ Integer calcType = costShareLevel.getCalcType();
|
|
|
+ List<Long> responsibilityIds = this.list(new QueryWrapper<CostAccountShare>().lambda().eq(CostAccountShare::getHospId, hospId)).stream().map(CostAccountShare::getResponsibilityId).collect(Collectors.toList());
|
|
|
+ // 执行类型的分摊级别的Id的集合
|
|
|
+ List<Long> costShareIds = costShareLevelService.list(new QueryWrapper<CostShareLevel>().lambda()
|
|
|
+ .eq(CostShareLevel::getCalcType, calcType))
|
|
|
+ .stream().map(CostShareLevel::getId).collect(Collectors.toList());
|
|
|
+ // 筛选责任中心里面符合指定类型的责任中心
|
|
|
+ // 筛选指定类型的责任中心 并且当前没有设置的责任中心
|
|
|
+ List<Responsibility> responsibilityList = responsibilityService.list(new QueryWrapper<Responsibility>().lambda()
|
|
|
+ .eq(Responsibility::getHospId, hospId)).stream()
|
|
|
+ .filter(i -> costShareIds.contains(i.getShareId()) && !responsibilityIds.contains(i.getId())).collect(Collectors.toList());
|
|
|
+ return responsibilityList;
|
|
|
+ }
|
|
|
+
|
|
|
}
|