| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | 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); |
| | |
| | | int result = count(new LambdaQueryWrapper<SysDept>() |
| | | .eq(SysDept::getParentId, deptId) |
| | | .last("limit 1")); |
| | | return result > 0 ? true : false; |
| | | return result > 0; |
| | | } |
| | | |
| | | /** |
| | |
| | | public boolean checkDeptExistUser(Long deptId) { |
| | | int result = userMapper.selectCount(new LambdaQueryWrapper<SysUser>() |
| | | .eq(SysUser::getDeptId, deptId)); |
| | | return result > 0 ? true : false; |
| | | return result > 0; |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * @param dept 当前部门 |
| | | */ |
| | | private void updateParentDeptStatus(SysDept dept) { |
| | | String updateBy = dept.getUpdateBy(); |
| | | dept = getById(dept.getDeptId()); |
| | | dept.setUpdateBy(updateBy); |
| | | private void updateParentDeptStatusNormal(SysDept dept) { |
| | | String ancestors = dept.getAncestors(); |
| | | Long[] deptIds = Convert.toLongArray(ancestors); |
| | | update(null,new LambdaUpdateWrapper<SysDept>() |
| | | .set(StrUtil.isNotBlank(dept.getStatus()), |
| | | SysDept::getStatus,dept.getStatus()) |
| | | .set(StrUtil.isNotBlank(dept.getUpdateBy()), |
| | | SysDept::getUpdateBy,dept.getUpdateBy()) |
| | | .in(SysDept::getDeptId, Arrays.asList(dept.getAncestors().split(",")))); |
| | | .set(SysDept::getStatus, "0") |
| | | .in(SysDept::getDeptId, Arrays.asList(deptIds))); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | 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(); |
| | | for (SysDept n : list) { |
| | | if (Validator.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue()) { |
| | | tlist.add(n); |
| | | } |
| | |
| | | * 判断是否有子节点 |
| | | */ |
| | | private boolean hasChild(List<SysDept> list, SysDept t) { |
| | | return getChildList(list, t).size() > 0 ? true : false; |
| | | return getChildList(list, t).size() > 0; |
| | | } |
| | | } |