|
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
+import com.ydtech.core.page.HttpResult;
|
|
|
import com.ydtech.core.page.PageRequest;
|
|
import com.ydtech.core.page.PageRequest;
|
|
|
import com.ydtech.core.page.PageResult;
|
|
import com.ydtech.core.page.PageResult;
|
|
|
import com.ydtech.exception.SystemException;
|
|
import com.ydtech.exception.SystemException;
|
|
@@ -20,6 +21,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.ObjectUtils;
|
|
import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
|
+import java.util.Comparator;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -40,11 +42,11 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
|
|
|
LambdaQueryWrapper<SysDept> lqw = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<SysDept> lqw = new LambdaQueryWrapper<>();
|
|
|
lqw.eq(SysDept::getDelFlag, 0);
|
|
lqw.eq(SysDept::getDelFlag, 0);
|
|
|
lqw.likeRight(SysDept::getId, deptId);
|
|
lqw.likeRight(SysDept::getId, deptId);
|
|
|
- lqw.orderByDesc(SysDept::getOrderNum);
|
|
|
|
|
|
|
+ lqw.orderByAsc(SysDept::getOrderNum);
|
|
|
List<SysDept> sysDeptList = list(lqw);
|
|
List<SysDept> sysDeptList = list(lqw);
|
|
|
//判断机构来源条件 进行遍历
|
|
//判断机构来源条件 进行遍历
|
|
|
- if(null != managementSource && !"undefined".equals(managementSource) && !"".equals(managementSource)){
|
|
|
|
|
- lqw.eq(SysDept::getManagementSource,managementSource);
|
|
|
|
|
|
|
+ if (null != managementSource && !"undefined".equals(managementSource) && !"".equals(managementSource)) {
|
|
|
|
|
+ lqw.eq(SysDept::getManagementSource, managementSource);
|
|
|
//条件
|
|
//条件
|
|
|
List<SysDept> conditionList = list(lqw);
|
|
List<SysDept> conditionList = list(lqw);
|
|
|
Map<String, List<SysDept>> conditionMap = conditionList.stream().collect(Collectors.groupingBy(SysDept::getParentId));
|
|
Map<String, List<SysDept>> conditionMap = conditionList.stream().collect(Collectors.groupingBy(SysDept::getParentId));
|
|
@@ -56,11 +58,11 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
|
|
|
List<SysDept> result = new ArrayList<>();
|
|
List<SysDept> result = new ArrayList<>();
|
|
|
//再查前4层
|
|
//再查前4层
|
|
|
int level = 5;
|
|
int level = 5;
|
|
|
- while(level > 0){
|
|
|
|
|
|
|
+ while (level > 0) {
|
|
|
List<SysDept> resultTmp = recursion(sysDeptList, conditionMap);
|
|
List<SysDept> resultTmp = recursion(sysDeptList, conditionMap);
|
|
|
- if(resultTmp.size() == 0){
|
|
|
|
|
|
|
+ if (resultTmp.size() == 0) {
|
|
|
break;
|
|
break;
|
|
|
- }else{
|
|
|
|
|
|
|
+ } else {
|
|
|
result.clear();
|
|
result.clear();
|
|
|
result.addAll(resultTmp);
|
|
result.addAll(resultTmp);
|
|
|
}
|
|
}
|
|
@@ -68,7 +70,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
|
|
|
level--;
|
|
level--;
|
|
|
}
|
|
}
|
|
|
sysDeptList = result;
|
|
sysDeptList = result;
|
|
|
- }else{
|
|
|
|
|
|
|
+ } else {
|
|
|
Map<String, List<SysDept>> map = sysDeptList.stream().collect(Collectors.groupingBy(SysDept::getParentId));
|
|
Map<String, List<SysDept>> map = sysDeptList.stream().collect(Collectors.groupingBy(SysDept::getParentId));
|
|
|
sysDeptList.forEach(i -> i.setChildren(map.getOrDefault(i.getId(), new ArrayList<>())));
|
|
sysDeptList.forEach(i -> i.setChildren(map.getOrDefault(i.getId(), new ArrayList<>())));
|
|
|
sysDeptList = map.get(sysDept.getParentId());
|
|
sysDeptList = map.get(sysDept.getParentId());
|
|
@@ -79,9 +81,9 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
|
|
|
private List<SysDept> recursion(List<SysDept> sysDeptList, Map<String, List<SysDept>> conditionMap) {
|
|
private List<SysDept> recursion(List<SysDept> sysDeptList, Map<String, List<SysDept>> conditionMap) {
|
|
|
List<SysDept> result = new ArrayList<>();
|
|
List<SysDept> result = new ArrayList<>();
|
|
|
sysDeptList.forEach(i ->
|
|
sysDeptList.forEach(i ->
|
|
|
- conditionMap.forEach((key,value) -> {
|
|
|
|
|
|
|
+ conditionMap.forEach((key, value) -> {
|
|
|
if (i.getId().equals(key)) {
|
|
if (i.getId().equals(key)) {
|
|
|
- if(i.getChildren() == null){
|
|
|
|
|
|
|
+ if (i.getChildren() == null) {
|
|
|
i.setChildren(new ArrayList<>());
|
|
i.setChildren(new ArrayList<>());
|
|
|
}
|
|
}
|
|
|
i.getChildren().addAll(value);
|
|
i.getChildren().addAll(value);
|
|
@@ -89,6 +91,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
);
|
|
);
|
|
|
|
|
+ result.sort(Comparator.comparing(SysDept::getOrderNum));
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -154,10 +157,47 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
|
|
|
sysDept.setManagementSource(parentDept.getManagementSource());
|
|
sysDept.setManagementSource(parentDept.getManagementSource());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 查询当前部门序号是否存在
|
|
|
|
|
+ LambdaQueryWrapper<SysDept> qw = new LambdaQueryWrapper<>();
|
|
|
|
|
+ qw.eq(SysDept::getDelFlag, 0); // 删除标志为未删除
|
|
|
|
|
+ qw.eq(SysDept::getParentId, sysDept.getParentId()); // 父级部门ID相同
|
|
|
|
|
+ qw.eq(SysDept::getOrderNum, sysDept.getOrderNum()); // 排序号相同
|
|
|
|
|
+ boolean exists = baseMapper.exists(qw);
|
|
|
|
|
+
|
|
|
|
|
+ if (exists) {
|
|
|
|
|
+ // 如果存在,查询该父级部门下排序号大于当前部门的部门列表
|
|
|
|
|
+ LambdaQueryWrapper<SysDept> lqw = new LambdaQueryWrapper<>();
|
|
|
|
|
+ lqw.eq(SysDept::getDelFlag, 0); // 删除标志为未删除
|
|
|
|
|
+ lqw.eq(SysDept::getParentId, sysDept.getParentId()); // 父级部门ID相同
|
|
|
|
|
+ lqw.ge(SysDept::getOrderNum, sysDept.getOrderNum()); // 排序号大于当前部门
|
|
|
|
|
+ List<SysDept> sysDeptList = list(lqw);
|
|
|
|
|
+ // 更新这些部门的排序号
|
|
|
|
|
+ sysDeptList.forEach(i -> {
|
|
|
|
|
+ i.setOrderNum(i.getOrderNum() + 1);
|
|
|
|
|
+ updateById(i);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
boolean b = save(sysDept);
|
|
boolean b = save(sysDept);
|
|
|
AssertionUtils.isSucceed(b, "删除失败");
|
|
AssertionUtils.isSucceed(b, "删除失败");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public HttpResult updateDept(SysDept record) {
|
|
|
|
|
+ // 查询当前部门序号是否存在
|
|
|
|
|
+ LambdaQueryWrapper<SysDept> qw = new LambdaQueryWrapper<>();
|
|
|
|
|
+ qw.eq(SysDept::getDelFlag, 0); // 删除标志为未删除
|
|
|
|
|
+ qw.eq(SysDept::getParentId, record.getParentId()); // 父级部门ID相同
|
|
|
|
|
+ qw.eq(SysDept::getOrderNum, record.getOrderNum()); // 排序号相同
|
|
|
|
|
+ SysDept sysDept = baseMapper.selectOne(qw);
|
|
|
|
|
+ if (sysDept != null) {
|
|
|
|
|
+ sysDept.setOrderNum(sysDept.getOrderNum() + 1);
|
|
|
|
|
+ baseMapper.updateById(sysDept);
|
|
|
|
|
+ }
|
|
|
|
|
+ baseMapper.updateById(record);
|
|
|
|
|
+ return HttpResult.ok();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void deleteDept(String deptId) {
|
|
public void deleteDept(String deptId) {
|
|
@@ -186,7 +226,6 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public String findMaxDeptId(String deptId) {
|
|
public String findMaxDeptId(String deptId) {
|
|
|
if (deptId == null) return "";
|
|
if (deptId == null) return "";
|
|
|
String result = "00";
|
|
String result = "00";
|