|
|
@@ -15,10 +15,8 @@ import com.railway.system.mapper.SysDeptMapper;
|
|
|
import com.railway.system.mapper.SysRoleMapper;
|
|
|
import com.railway.system.service.ISysDeptService;
|
|
|
import java.util.ArrayList;
|
|
|
-import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
/**
|
|
|
@@ -29,11 +27,14 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
|
|
|
- @Autowired
|
|
|
- private SysDeptMapper deptMapper;
|
|
|
+ private final SysDeptMapper deptMapper;
|
|
|
+ private final SysRoleMapper roleMapper;
|
|
|
|
|
|
- @Autowired
|
|
|
- private SysRoleMapper roleMapper;
|
|
|
+ public SysDeptServiceImpl(SysDeptMapper deptMapper,
|
|
|
+ SysRoleMapper roleMapper) {
|
|
|
+ this.deptMapper = deptMapper;
|
|
|
+ this.roleMapper = roleMapper;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 查询部门管理数据
|
|
|
@@ -55,13 +56,12 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
*/
|
|
|
@Override
|
|
|
public List<SysDept> buildDeptTree(List<SysDept> depts) {
|
|
|
- List<SysDept> returnList = new ArrayList<SysDept>();
|
|
|
- List<Long> tempList = new ArrayList<Long>();
|
|
|
+ List<SysDept> returnList = new ArrayList<>();
|
|
|
+ List<Long> tempList = new ArrayList<>();
|
|
|
for (SysDept dept : depts) {
|
|
|
tempList.add(dept.getDeptId());
|
|
|
}
|
|
|
- for (Iterator<SysDept> iterator = depts.iterator(); iterator.hasNext(); ) {
|
|
|
- SysDept dept = (SysDept) iterator.next();
|
|
|
+ for (SysDept dept : depts) {
|
|
|
// 如果是顶级节点, 遍历该父节点的所有子节点
|
|
|
if (!tempList.contains(dept.getParentId())) {
|
|
|
recursionFn(depts, dept);
|
|
|
@@ -129,7 +129,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
@Override
|
|
|
public boolean hasChildByDeptId(Long deptId) {
|
|
|
int result = deptMapper.hasChildByDeptId(deptId);
|
|
|
- return result > 0 ? true : false;
|
|
|
+ return result > 0;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -141,7 +141,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
@Override
|
|
|
public boolean checkDeptExistUser(Long deptId) {
|
|
|
int result = deptMapper.checkDeptExistUser(deptId);
|
|
|
- return result > 0 ? true : false;
|
|
|
+ return result > 0;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -152,9 +152,9 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
*/
|
|
|
@Override
|
|
|
public String checkDeptNameUnique(SysDept dept) {
|
|
|
- Long deptId = StringUtils.isNull(dept.getDeptId()) ? -1L : dept.getDeptId();
|
|
|
+ long deptId = StringUtils.isNull(dept.getDeptId()) ? -1L : dept.getDeptId();
|
|
|
SysDept info = deptMapper.checkDeptNameUnique(dept.getDeptName(), dept.getParentId());
|
|
|
- if (StringUtils.isNotNull(info) && info.getDeptId().longValue() != deptId.longValue()) {
|
|
|
+ if (StringUtils.isNotNull(info) && info.getDeptId() != deptId) {
|
|
|
return UserConstants.NOT_UNIQUE;
|
|
|
}
|
|
|
return UserConstants.UNIQUE;
|
|
|
@@ -277,10 +277,8 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
* 得到子节点列表
|
|
|
*/
|
|
|
private List<SysDept> getChildList(List<SysDept> list, SysDept t) {
|
|
|
- List<SysDept> tlist = new ArrayList<SysDept>();
|
|
|
- Iterator<SysDept> it = list.iterator();
|
|
|
- while (it.hasNext()) {
|
|
|
- SysDept n = (SysDept) it.next();
|
|
|
+ List<SysDept> tlist = new ArrayList<>();
|
|
|
+ for (SysDept n : list) {
|
|
|
if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId()
|
|
|
.longValue()) {
|
|
|
tlist.add(n);
|
|
|
@@ -293,6 +291,6 @@ public class SysDeptServiceImpl implements ISysDeptService {
|
|
|
* 判断是否有子节点
|
|
|
*/
|
|
|
private boolean hasChild(List<SysDept> list, SysDept t) {
|
|
|
- return getChildList(list, t).size() > 0 ? true : false;
|
|
|
+ return getChildList(list, t).size() > 0;
|
|
|
}
|
|
|
}
|