疯狂的狮子li
2021-12-24 5ca038d888922e93bf45c7bd37f3c6dce849dcff
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java
@@ -1,10 +1,10 @@
package com.ruoyi.system.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.tree.Tree;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysRole;
@@ -46,8 +46,9 @@
     * @return 部门信息集合
     */
    @Override
    @DataScope(deptAlias = "d")
    public List<SysDept> selectDeptList(SysDept dept) {
//        return baseMapper.selectList();
//        return baseMapper.selectList(new LambdaQueryWrapper<>());
        return baseMapper.selectDeptList(dept);
    }
@@ -59,7 +60,11 @@
     */
    @Override
    public List<Tree<Long>> buildDeptTreeSelect(List<SysDept> depts) {
        return TreeBuildUtils.build(depts, (dept, tree) ->
        if (CollUtil.isEmpty(depts)) {
            return CollUtil.newArrayList();
        }
        Long parentId = depts.get(0).getParentId();
        return TreeBuildUtils.build(depts, parentId, (dept, tree) ->
            tree.setId(dept.getDeptId())
                .setParentId(dept.getParentId())
                .setName(dept.getDeptName())
@@ -73,7 +78,7 @@
     * @return 选中部门列表
     */
    @Override
    public List<Integer> selectDeptListByRoleId(Long roleId) {
    public List<Long> selectDeptListByRoleId(Long roleId) {
        SysRole role = roleMapper.selectById(roleId);
        return baseMapper.selectDeptListByRoleId(roleId, role.isDeptCheckStrictly());
    }
@@ -111,8 +116,7 @@
    @Override
    public boolean hasChildByDeptId(Long deptId) {
        long result = count(new LambdaQueryWrapper<SysDept>()
            .eq(SysDept::getParentId, deptId)
            .last("limit 1"));
            .eq(SysDept::getParentId, deptId));
        return result > 0;
    }
@@ -138,11 +142,11 @@
    @Override
    public String checkDeptNameUnique(SysDept dept) {
        Long deptId = StringUtils.isNull(dept.getDeptId()) ? -1L : dept.getDeptId();
        SysDept info = getOne(new LambdaQueryWrapper<SysDept>()
        long count = count(new LambdaQueryWrapper<SysDept>()
            .eq(SysDept::getDeptName, dept.getDeptName())
            .eq(SysDept::getParentId, dept.getParentId())
            .last("limit 1"));
        if (StringUtils.isNotNull(info) && info.getDeptId().longValue() != deptId.longValue()) {
            .ne(SysDept::getDeptId, deptId));
        if (count > 0) {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;