|
@@ -145,14 +145,18 @@ public class DeptServiceImpl implements DeptService {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@Cacheable(key = "'id:' + #p0")
|
|
@Cacheable(key = "'id:' + #p0")
|
|
- public DeptDto findById(Long id) {
|
|
|
|
- Dept dept = deptRepository.findById(id).orElseGet(Dept::new);
|
|
|
|
- ValidationUtil.isNull(dept.getId(),"Dept","id",id);
|
|
|
|
- return deptMapper.toDto(dept);
|
|
|
|
|
|
+ public DeptDto findById(String id) {
|
|
|
|
+ Optional<Dept> dept = deptRepository.findById(id);
|
|
|
|
+ if (!dept.isPresent()) {
|
|
|
|
+ return null;
|
|
|
|
+ } else {
|
|
|
|
+ ValidationUtil.isNull(dept.get().getId(), "Dept", "id", id);
|
|
|
|
+ return deptMapper.toDto(dept.get());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public List<Dept> findByPid(long pid) {
|
|
|
|
|
|
+ public List<Dept> findByPid(String pid) {
|
|
return deptRepository.findByPid(pid);
|
|
return deptRepository.findByPid(pid);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -175,8 +179,8 @@ public class DeptServiceImpl implements DeptService {
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public void update(Dept resources) {
|
|
public void update(Dept resources) {
|
|
// 旧的部门
|
|
// 旧的部门
|
|
- Long oldPid = findById(resources.getId()).getPid();
|
|
|
|
- Long newPid = resources.getPid();
|
|
|
|
|
|
+ String oldPid = findById(resources.getId()).getPid();
|
|
|
|
+ String newPid = resources.getPid();
|
|
if(resources.getPid() != null && resources.getId().equals(resources.getPid())) {
|
|
if(resources.getPid() != null && resources.getId().equals(resources.getPid())) {
|
|
throw new BadRequestException("上级不能为自己");
|
|
throw new BadRequestException("上级不能为自己");
|
|
}
|
|
}
|
|
@@ -228,8 +232,8 @@ public class DeptServiceImpl implements DeptService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public List<Long> getDeptChildren(List<Dept> deptList) {
|
|
|
|
- List<Long> list = new ArrayList<>();
|
|
|
|
|
|
+ public List<String> getDeptChildren(List<Dept> deptList) {
|
|
|
|
+ List<String> list = new ArrayList<>();
|
|
deptList.forEach(dept -> {
|
|
deptList.forEach(dept -> {
|
|
if (dept!=null && dept.getEnabled()) {
|
|
if (dept!=null && dept.getEnabled()) {
|
|
List<Dept> depts = deptRepository.findByPid(dept.getId());
|
|
List<Dept> depts = deptRepository.findByPid(dept.getId());
|
|
@@ -291,7 +295,7 @@ public class DeptServiceImpl implements DeptService {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void verification(Set<DeptDto> deptDtos) {
|
|
public void verification(Set<DeptDto> deptDtos) {
|
|
- Set<Long> deptIds = deptDtos.stream().map(DeptDto::getId).collect(Collectors.toSet());
|
|
|
|
|
|
+ Set<String> deptIds = deptDtos.stream().map(DeptDto::getId).collect(Collectors.toSet());
|
|
if(userRepository.countByDepts(deptIds) > 0){
|
|
if(userRepository.countByDepts(deptIds) > 0){
|
|
throw new BadRequestException("所选部门存在用户关联,请解除后再试!");
|
|
throw new BadRequestException("所选部门存在用户关联,请解除后再试!");
|
|
}
|
|
}
|
|
@@ -300,7 +304,7 @@ public class DeptServiceImpl implements DeptService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void updateSubCnt(Long deptId){
|
|
|
|
|
|
+ private void updateSubCnt(String deptId){
|
|
if(deptId != null){
|
|
if(deptId != null){
|
|
int count = deptRepository.countByPid(deptId);
|
|
int count = deptRepository.countByPid(deptId);
|
|
deptRepository.updateSubCntById(count, deptId);
|
|
deptRepository.updateSubCntById(count, deptId);
|
|
@@ -328,7 +332,7 @@ public class DeptServiceImpl implements DeptService {
|
|
* 清理缓存
|
|
* 清理缓存
|
|
* @param id /
|
|
* @param id /
|
|
*/
|
|
*/
|
|
- public void delCaches(Long id){
|
|
|
|
|
|
+ public void delCaches(String id){
|
|
List<User> users = userRepository.findByRoleDeptId(id);
|
|
List<User> users = userRepository.findByRoleDeptId(id);
|
|
// 删除数据权限
|
|
// 删除数据权限
|
|
redisUtils.delByKeys(CacheKey.DATA_USER, users.stream().map(User::getId).collect(Collectors.toSet()));
|
|
redisUtils.delByKeys(CacheKey.DATA_USER, users.stream().map(User::getId).collect(Collectors.toSet()));
|