This commit is contained in:
zhangzhiqiang
2022-12-19 18:19:01 +08:00
parent 06c385a086
commit da02fba0ae
3 changed files with 27 additions and 24 deletions

View File

@@ -41,5 +41,4 @@ public interface SysDeptMapper extends BaseMapper<SysDept> {
* @return
*/
String findAllChild(String pid);
}

View File

@@ -29,6 +29,9 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
@@ -94,11 +97,13 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
if (query.getPid() == null){
query.setPidIsNull(true);
}
if (StringUtils.isNotEmpty(query.getName()) || query.getIsUsed()!=null){
query.setPidIsNull(null);
}
}
Page page = this.page(pageQuery.build(SysDept.class), query.build());
page.setRecords(CopyUtil.copyList(page.getRecords(), DeptVo.class));
if (StringUtils.isNotEmpty(query.getName())){
if (StringUtils.isNotEmpty(query.getName()) || query.getIsUsed()!=null){
page.getRecords().forEach(a->((DeptVo)a).setHasChildren(false) );
}
return page;
@@ -140,7 +145,10 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
}
verification(deptIds);
Set<String> depts = new HashSet<>();
Set<String> pids = new HashSet<>();
List<SysDept> deptList = sysDeptMapper.selectList(new QueryWrapper<SysDept>().in("dept_id", deptIds));
for (String deptId : deptIds) {
depts.add(deptId);
String allChild = sysDeptMapper.findAllChild(deptId);
if (StringUtils.isNotEmpty(allChild)){
String[] split = allChild.split(",");
@@ -148,9 +156,10 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
}
}
this.remove(new QueryWrapper<SysDept>().in("dept_id", depts));
for (String deptId : deptIds) {
sysDeptMapper.updateSubCount(deptId);
}
deptList.forEach(dept -> {
if (StringUtils.isNotEmpty(dept.getPid())){sysDeptMapper.updateSubCount(dept.getPid());}
});
}
private void verification(Set<String> depeIds) {