|
@@ -24,6 +24,8 @@ import org.springframework.util.CollectionUtils;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import static com.imed.costaccount.common.constants.Constant.LIMIT;
|
|
|
+
|
|
|
@Slf4j
|
|
|
@Service("responsibilityService")
|
|
|
public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper, Responsibility> implements ResponsibilityService {
|
|
@@ -44,6 +46,20 @@ public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper,
|
|
|
@Override
|
|
|
public List<CostResponsibilityVO> getList(User user) {
|
|
|
// 1. 获取所有的列表然后组装
|
|
|
+ List<CostResponsibilityVO> costResponsibilityVOS = this.getCostResponsibilityVO(user);
|
|
|
+ List<CostResponsibilityVO> parentCostResponsibility = costResponsibilityVOS.stream()
|
|
|
+ .filter(i -> i.getParentId() == 0).collect(Collectors.toList());
|
|
|
+ // 多层结构
|
|
|
+ List<CostResponsibilityVO> all = new ArrayList<>();
|
|
|
+ // todo 试试多线程实现方式
|
|
|
+ for (CostResponsibilityVO parent : parentCostResponsibility) {
|
|
|
+ List<CostResponsibilityVO> children = this.getResponsibilityChildren(parent, costResponsibilityVOS);
|
|
|
+ all.addAll(children);
|
|
|
+ }
|
|
|
+ return all;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<CostResponsibilityVO> getCostResponsibilityVO(User user) {
|
|
|
List<Responsibility> list = this.list(
|
|
|
new LambdaQueryWrapper<Responsibility>()
|
|
|
.eq(Responsibility::getHospId, user.getHospId())
|
|
@@ -54,23 +70,31 @@ public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper,
|
|
|
}
|
|
|
// 拷贝组合
|
|
|
List<CostResponsibilityVO> costResponsibilityVOS = BeanUtil.convertList(list, CostResponsibilityVO.class);
|
|
|
- List<CostResponsibilityVO> parentCostResponsibility = costResponsibilityVOS.stream()
|
|
|
- .filter(i -> i.getResponsibilityLevel().equals(1)).collect(Collectors.toList());
|
|
|
+ return costResponsibilityVOS;
|
|
|
+ }
|
|
|
|
|
|
- parentCostResponsibility.forEach(i -> costResponsibilityVOS.forEach(j -> {
|
|
|
- if (j.getParentId().equals(i.getId())) {
|
|
|
- if (i.getResponsibilityLevel() == 1) {
|
|
|
- i.setShareLevel(null);
|
|
|
- }
|
|
|
- List<CostResponsibilityVO> child = i.getChild();
|
|
|
+ /**
|
|
|
+ * 获取子层级
|
|
|
+ *
|
|
|
+ * @param parent 当前的
|
|
|
+ * @param costResponsibilityVOS 所有的
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<CostResponsibilityVO> getResponsibilityChildren(CostResponsibilityVO parent, List<CostResponsibilityVO> costResponsibilityVOS) {
|
|
|
+ List<CostResponsibilityVO> list = new LinkedList<>();
|
|
|
+ list.add(parent);
|
|
|
+ for (CostResponsibilityVO costResponsibilityVO : costResponsibilityVOS) {
|
|
|
+ if (parent.getId().equals(costResponsibilityVO.getParentId())) {
|
|
|
+ List<CostResponsibilityVO> child = parent.getChild();
|
|
|
if (CollUtil.isEmpty(child)) {
|
|
|
child = new ArrayList<>();
|
|
|
}
|
|
|
- child.add(j);
|
|
|
- i.setChild(child);
|
|
|
+ child.add(costResponsibilityVO);
|
|
|
+ parent.setChild(child);
|
|
|
+ this.getResponsibilityChildren(costResponsibilityVO, costResponsibilityVOS);
|
|
|
}
|
|
|
- }));
|
|
|
- return parentCostResponsibility;
|
|
|
+ }
|
|
|
+ return list;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -88,13 +112,11 @@ public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper,
|
|
|
if (Objects.isNull(id)) {
|
|
|
id = 0L;
|
|
|
}
|
|
|
+ // 校验责任中心代码code是否唯一
|
|
|
checkCode(responsibilitySaveDTO.getResponsibilityCode(), user.getHospId());
|
|
|
|
|
|
Responsibility center = BeanUtil.convertObj(responsibilitySaveDTO, Responsibility.class);
|
|
|
- center.setCreateTime(System.currentTimeMillis()).setId(null).setParentId(id).setHospId(user.getHospId()).setResponsibilityLevel(2);
|
|
|
- if (id == 0) {
|
|
|
- center.setResponsibilityLevel(1);
|
|
|
- }
|
|
|
+ center.setCreateTime(System.currentTimeMillis()).setId(null).setParentId(id).setHospId(user.getHospId());
|
|
|
|
|
|
// 如果是汇总中心,那么不存在分摊级别
|
|
|
Integer isGatherCenter = responsibilitySaveDTO.getIsGatherCenter();
|
|
@@ -105,15 +127,32 @@ public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper,
|
|
|
// 父节点不允许为非汇总中心
|
|
|
Responsibility byId = this.getById(id);
|
|
|
if (Objects.nonNull(byId) && (byId.getIsGatherCenter() == 2)) {
|
|
|
- throw new CostException(500, "非汇总中心不允许添加");
|
|
|
+ throw new CostException(500, "非汇总中心不允许添加下属层级");
|
|
|
}
|
|
|
|
|
|
if (responsibilitySaveDTO.getIsGatherCenter() == 1) {
|
|
|
throw new CostException(500, "子层级暂不允许为非汇总中心");
|
|
|
}
|
|
|
+
|
|
|
+ // 只允许存在一个汇总中心
|
|
|
+ if (responsibilitySaveDTO.getIsDefault() == 1) {
|
|
|
+ this.checkIsDefault(user.getHospId());
|
|
|
+ }
|
|
|
this.save(center);
|
|
|
}
|
|
|
|
|
|
+ private void checkIsDefault(Long hospId) {
|
|
|
+ Responsibility one = this.getOne(
|
|
|
+ new LambdaQueryWrapper<Responsibility>()
|
|
|
+ .eq(Responsibility::getHospId, hospId)
|
|
|
+ .eq(Responsibility::getIsDefault, 1)
|
|
|
+ .last(LIMIT)
|
|
|
+ );
|
|
|
+ if (Objects.nonNull(one)) {
|
|
|
+ throw new CostException("责任中心只能拥有一个默认责任中心");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void checkCode(String code, Long hospId) {
|
|
|
// 校验责任代码唯一性
|
|
|
Responsibility one = this.getOne(
|
|
@@ -151,55 +190,14 @@ public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper,
|
|
|
// 如果不存在子节点 ,修改它本身
|
|
|
if (list.isEmpty()) {
|
|
|
this.updateCurResp(center, responsibilityEditDTO, user);
|
|
|
- return ;
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
this.updateParent(responsibilityEditDTO, center, user.getHospId());
|
|
|
-// // 不管是哪个绑定到父级目录下
|
|
|
-//// if (responsibilityEditDTO.getParentId() == 0) {
|
|
|
-////
|
|
|
-//// }
|
|
|
-////
|
|
|
-////
|
|
|
-//// // 如果修改父节点节点(只有两层的情况)
|
|
|
-// if (center.getResponsibilityLevel() == 1) {
|
|
|
-// this.updateParent(responsibilityEditDTO, center, user.getHospId());
|
|
|
-// return;
|
|
|
-// }
|
|
|
-
|
|
|
-// this.updateCurrent(responsibilityEditDTO, center, user.getHospId());
|
|
|
}
|
|
|
|
|
|
- @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
|
|
|
- public void updateAllResp(Responsibility center, ResponsibilityEditDTO dto, User user, List<Responsibility> list) {
|
|
|
- // 删除原有的父节点数据
|
|
|
- Long id = dto.getId();
|
|
|
- this.removeById(id);
|
|
|
- this.checkCode(dto.getResponsibilityCode(), user.getHospId());
|
|
|
- // 新增父节点数据
|
|
|
- Responsibility newResponsibility = BeanUtil.convertObj(dto, Responsibility.class);
|
|
|
- newResponsibility.setId(null).setHospId(user.getHospId()).setCreateTime(new Date().getTime()).setResponsibilityLevel(2);
|
|
|
- // 相关校验
|
|
|
- if (dto.getParentId() == 0) {
|
|
|
- newResponsibility.setResponsibilityLevel(1);
|
|
|
- }
|
|
|
-
|
|
|
- // 如果是汇总中心,那么不存在分摊级别
|
|
|
- Integer isGatherCenter = newResponsibility.getIsGatherCenter();
|
|
|
- if (isGatherCenter == 1) {
|
|
|
- newResponsibility.setShareId(null);
|
|
|
- newResponsibility.setShareLevel(0);
|
|
|
- newResponsibility.setShareName("");
|
|
|
- }
|
|
|
-
|
|
|
- if (Objects.nonNull(center) && (center.getIsGatherCenter() == 2)) {
|
|
|
- throw new CostException(500, "非汇总中心不允许添加");
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
- @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
|
|
|
+ @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
|
|
|
public void updateCurResp(Responsibility center, ResponsibilityEditDTO dto, User user) {
|
|
|
// 删除
|
|
|
Long id = dto.getId();
|
|
@@ -211,21 +209,23 @@ public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper,
|
|
|
newResponsibility.setId(null)
|
|
|
.setHospId(user.getHospId())
|
|
|
.setCreateTime(System.currentTimeMillis())
|
|
|
- .setParentId(dto.getParentId())
|
|
|
- .setResponsibilityLevel(2);
|
|
|
+ .setParentId(dto.getParentId());
|
|
|
// 如果变成了汇总中心,那么变成第一层
|
|
|
if (dto.getIsGatherCenter() == 1) {
|
|
|
newResponsibility.setShareId(null)
|
|
|
.setShareLevel(0)
|
|
|
.setShareName(null)
|
|
|
- .setParentId(0L)
|
|
|
- .setResponsibilityLevel(1);
|
|
|
+ .setParentId(0L);
|
|
|
}
|
|
|
if (dto.getParentId() == 0) {
|
|
|
- newResponsibility.setResponsibilityLevel(1);
|
|
|
// 永远为2的情况
|
|
|
newResponsibility.setIsGatherCenter(2);
|
|
|
}
|
|
|
+ // 校验默认
|
|
|
+ if (dto.getIsDefault() == 1) {
|
|
|
+ this.checkIsDefault(user.getHospId());
|
|
|
+ }
|
|
|
+
|
|
|
this.save(newResponsibility);
|
|
|
}
|
|
|
|
|
@@ -252,11 +252,7 @@ public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper,
|
|
|
this.checkCode(dto.getResponsibilityCode(), hospId);
|
|
|
// 新增父节点数据
|
|
|
Responsibility newResponsibility = BeanUtil.convertObj(dto, Responsibility.class);
|
|
|
- newResponsibility.setId(null).setHospId(responsibility.getHospId()).setCreateTime(new Date().getTime()).setResponsibilityLevel(2);
|
|
|
- // 相关校验
|
|
|
- if (dto.getParentId() == 0) {
|
|
|
- newResponsibility.setResponsibilityLevel(1);
|
|
|
- }
|
|
|
+ newResponsibility.setId(null).setHospId(responsibility.getHospId()).setCreateTime(new Date().getTime());
|
|
|
|
|
|
// 如果是汇总中心,那么不存在分摊级别
|
|
|
Integer isGatherCenter = newResponsibility.getIsGatherCenter();
|
|
@@ -270,6 +266,9 @@ public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper,
|
|
|
if (Objects.nonNull(byId) && (byId.getIsGatherCenter() == 2)) {
|
|
|
throw new CostException(500, "非汇总中心不允许添加");
|
|
|
}
|
|
|
+ if (dto.getIsDefault() == 1) {
|
|
|
+ this.checkIsDefault(hospId);
|
|
|
+ }
|
|
|
|
|
|
this.save(newResponsibility);
|
|
|
|
|
@@ -301,15 +300,13 @@ public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper,
|
|
|
newResponsibility.setId(null)
|
|
|
.setHospId(responsibility.getHospId())
|
|
|
.setCreateTime(System.currentTimeMillis())
|
|
|
- .setParentId(dto.getParentId())
|
|
|
- .setResponsibilityLevel(2);
|
|
|
+ .setParentId(dto.getParentId());
|
|
|
// 暂时先这样处理
|
|
|
if (dto.getIsGatherCenter() == 1) {
|
|
|
newResponsibility.setShareId(null)
|
|
|
.setShareLevel(0)
|
|
|
.setShareName(null)
|
|
|
- .setParentId(0L)
|
|
|
- .setResponsibilityLevel(1);
|
|
|
+ .setParentId(0L);
|
|
|
}
|
|
|
this.save(newResponsibility);
|
|
|
}
|
|
@@ -359,7 +356,7 @@ public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper,
|
|
|
new LambdaQueryWrapper<Responsibility>()
|
|
|
.eq(Responsibility::getHospId, user.getHospId())
|
|
|
.eq(Responsibility::getParentId, 0)
|
|
|
- .orderByDesc(Responsibility::getCreateTime)
|
|
|
+ .orderByDesc(Responsibility::getCreateTime)
|
|
|
);
|
|
|
if (CollUtil.isEmpty(parentList)) {
|
|
|
return Collections.emptyList();
|
|
@@ -402,7 +399,7 @@ public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper,
|
|
|
public List<CommonVO> getParentList(User user) {
|
|
|
List<Responsibility> list = this.list(
|
|
|
new LambdaQueryWrapper<Responsibility>().select(Responsibility::getId, Responsibility::getResponsibilityName)
|
|
|
- .eq(Responsibility::getResponsibilityLevel, 1)
|
|
|
+ .eq(Responsibility::getParentId, 0)
|
|
|
.eq(Responsibility::getHospId, user.getHospId())
|
|
|
);
|
|
|
return list.stream().map(i -> {
|
|
@@ -448,16 +445,7 @@ public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper,
|
|
|
@Override
|
|
|
public List<CostResponsibilityVO> responsibilityList(User user) {
|
|
|
// 1. 获取所有的列表然后组装
|
|
|
- List<Responsibility> list = this.list(
|
|
|
- new LambdaQueryWrapper<Responsibility>()
|
|
|
- .eq(Responsibility::getHospId, user.getHospId())
|
|
|
- .orderByDesc(Responsibility::getCreateTime)
|
|
|
- );
|
|
|
- if (CollUtil.isEmpty(list)) {
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
- // 拷贝组合
|
|
|
- List<CostResponsibilityVO> costResponsibilityVOS = BeanUtil.convertList(list, CostResponsibilityVO.class);
|
|
|
+ List<CostResponsibilityVO> costResponsibilityVOS = this.getCostResponsibilityVO(user);
|
|
|
List<CostResponsibilityVO> parentCostResponsibility = costResponsibilityVOS.stream()
|
|
|
.filter(i -> i.getResponsibilityLevel().equals(1)).collect(Collectors.toList());
|
|
|
|
|
@@ -470,7 +458,7 @@ public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper,
|
|
|
if (CollUtil.isEmpty(child)) {
|
|
|
child = new ArrayList<>();
|
|
|
}
|
|
|
- j.setResponsibilityName(i.getResponsibilityName()+"/"+j.getResponsibilityName());
|
|
|
+ j.setResponsibilityName(i.getResponsibilityName() + "/" + j.getResponsibilityName());
|
|
|
child.add(j);
|
|
|
i.setChild(child);
|
|
|
}
|