|
@@ -12,15 +12,15 @@ import com.imed.costaccount.model.Responsibility;
|
|
|
import com.imed.costaccount.model.User;
|
|
|
import com.imed.costaccount.model.dto.ResponsibilityEditDTO;
|
|
|
import com.imed.costaccount.model.dto.ResponsibilitySaveDTO;
|
|
|
-import com.imed.costaccount.model.vo.CenterDepartmentVO;
|
|
|
-import com.imed.costaccount.model.vo.CommonVO;
|
|
|
-import com.imed.costaccount.model.vo.CostResponsibilityVO;
|
|
|
+import com.imed.costaccount.model.vo.*;
|
|
|
import com.imed.costaccount.service.ResponsibilityService;
|
|
|
import com.imed.costaccount.utils.BeanUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -30,6 +30,9 @@ import java.util.stream.Collectors;
|
|
|
public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper, Responsibility> implements ResponsibilityService {
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CostShareLevelServiceImpl costShareLevelService;
|
|
|
+
|
|
|
/**
|
|
|
* 责任中心列表不分页
|
|
|
*
|
|
@@ -84,15 +87,7 @@ public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper,
|
|
|
if (Objects.isNull(id)) {
|
|
|
id = 0;
|
|
|
}
|
|
|
- // 校验责任代码唯一性
|
|
|
- Responsibility one = this.getOne(
|
|
|
- new LambdaQueryWrapper<Responsibility>().select(Responsibility::getId)
|
|
|
- .eq(Responsibility::getResponsibilityCode, responsibilitySaveDTO.getResponsibilityCode())
|
|
|
- .eq(Responsibility::getHospId, user.getHospId()).last("limit 1")
|
|
|
- );
|
|
|
- if (Objects.nonNull(one)) {
|
|
|
- throw new CostException(ErrorCodeEnum.RESPONSIBILITY_CODE_EXIST);
|
|
|
- }
|
|
|
+ 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);
|
|
@@ -101,9 +96,22 @@ public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper,
|
|
|
center.setShareLevel(0);
|
|
|
center.setShareName("");
|
|
|
}
|
|
|
+
|
|
|
this.save(center);
|
|
|
}
|
|
|
|
|
|
+ private void checkCode(String code,Integer hospId) {
|
|
|
+ // 校验责任代码唯一性
|
|
|
+ Responsibility one = this.getOne(
|
|
|
+ new LambdaQueryWrapper<Responsibility>().select(Responsibility::getId)
|
|
|
+ .eq(Responsibility::getResponsibilityCode, code)
|
|
|
+ .eq(Responsibility::getHospId, hospId).last("limit 1")
|
|
|
+ );
|
|
|
+ if (Objects.nonNull(one)) {
|
|
|
+ throw new CostException(ErrorCodeEnum.RESPONSIBILITY_CODE_EXIST);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 编辑责任中心
|
|
@@ -121,24 +129,25 @@ public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper,
|
|
|
}
|
|
|
// 如果修改父节点节点(只有两层的情况)
|
|
|
if (center.getResponsibilityLevel() == 1) {
|
|
|
- this.updateParent(responsibilityEditDTO, center);
|
|
|
+ this.updateParent(responsibilityEditDTO, center, user.getHospId());
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- this.updateCurrent(responsibilityEditDTO, center);
|
|
|
+ this.updateCurrent(responsibilityEditDTO, center,user.getHospId());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修的是父节点
|
|
|
- *
|
|
|
- * @param dto
|
|
|
+ * @param dto
|
|
|
* @param responsibility
|
|
|
+ * @param hospId
|
|
|
*/
|
|
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
|
- public void updateParent(ResponsibilityEditDTO dto, Responsibility responsibility) {
|
|
|
+ public void updateParent(ResponsibilityEditDTO dto, Responsibility responsibility, Integer hospId) {
|
|
|
// 删除原有的父节点数据
|
|
|
Integer id = dto.getId();
|
|
|
this.removeById(id);
|
|
|
+ this.checkCode(dto.getResponsibilityCode(),hospId);
|
|
|
// 新增父节点数据
|
|
|
Responsibility newResponsibility = BeanUtil.convertObj(dto, Responsibility.class);
|
|
|
newResponsibility.setId(null).setHospId(responsibility.getHospId()).setCreateTime(new Date().getTime()).setResponsibilityLevel(1);
|
|
@@ -153,14 +162,17 @@ public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper,
|
|
|
/**
|
|
|
* 修改当前的节点
|
|
|
*
|
|
|
- * @param responsibility
|
|
|
* @param dto
|
|
|
+ * @param responsibility
|
|
|
+ * @param hospId
|
|
|
*/
|
|
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
|
- public void updateCurrent(ResponsibilityEditDTO dto, Responsibility responsibility) {
|
|
|
+ public void updateCurrent(ResponsibilityEditDTO dto, Responsibility responsibility, Integer hospId) {
|
|
|
// 删除原有的父节点数据
|
|
|
Integer id = dto.getId();
|
|
|
this.removeById(id);
|
|
|
+
|
|
|
+ this.checkCode(dto.getResponsibilityCode(),hospId);
|
|
|
// 新增父节点数据
|
|
|
Responsibility newResponsibility = BeanUtil.convertObj(dto, Responsibility.class);
|
|
|
newResponsibility.setId(null).setHospId(responsibility.getHospId()).setCreateTime(new Date().getTime()).setResponsibilityLevel(1);
|
|
@@ -260,4 +272,29 @@ public class ResponsibilityServiceImpl extends ServiceImpl<ResponsibilityMapper,
|
|
|
return commonVO;
|
|
|
}).collect(Collectors.toList());
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取第二级别的责任中心的数据
|
|
|
+ *
|
|
|
+ * @param hospId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<CostResponsibilityLevelVO> getLevelTwo(Integer hospId) {
|
|
|
+ List<Responsibility> responsibilities = baseMapper.selectList(new QueryWrapper<Responsibility>().lambda()
|
|
|
+ .eq(Responsibility::getHospId, hospId)
|
|
|
+ .eq(Responsibility::getResponsibilityLevel, NumberConstant.TWO));
|
|
|
+ List<CostResponsibilityLevelVO> costResponsibilityLevelVOS = BeanUtil.convertList(responsibilities, CostResponsibilityLevelVO.class);
|
|
|
+ List<CostShareLevelVO> costShareLevelServiceAll = costShareLevelService.getAll(hospId);
|
|
|
+ Map<Integer, List<CostShareLevelVO>> listMap = costShareLevelServiceAll.stream().collect(Collectors.groupingBy(CostShareLevelVO::getId));
|
|
|
+ // 设置责任中心的计算方式
|
|
|
+ costResponsibilityLevelVOS.forEach(i->{
|
|
|
+ Integer shareLevel = i.getShareLevel();
|
|
|
+ List<CostShareLevelVO> costShareLevelVOList = listMap.get(shareLevel);
|
|
|
+ if (!CollectionUtils.isEmpty(costShareLevelVOList)){
|
|
|
+ i.setCalcType(costShareLevelVOList.get(0).getCalcType());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return costResponsibilityLevelVOS;
|
|
|
+ }
|
|
|
}
|