ソースを参照

修改部门层级为区域层级

wangwl 4 ヶ月 前
コミット
a87effae39

+ 3 - 0
leromro-admin/src/main/java/com/leromro/web/controller/system/SysUserController.java

@@ -125,7 +125,10 @@ public class SysUserController extends BaseController
             ajax.put("postIds", postService.selectPostListByUserId(userId));
             ajax.put("roleIds", sysUser.getRoles().stream().map(SysRole::getRoleId).collect(Collectors.toList()));
         }
+        //获取当前用户最大的角色id
+        //获取所有的角色id
         List<SysRole> roles = roleService.selectRoleAll();
+        //只能分配等于或小于自己角色的id
         ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
         ajax.put("posts", postService.selectPostAll());
         return ajax;

+ 10 - 0
leromro-common/src/main/java/com/leromro/common/core/domain/entity/SysDept.java

@@ -55,6 +55,16 @@ public class SysDept extends BaseEntity
     /** 子部门 */
     private List<SysDept> children = new ArrayList<SysDept>();
 
+    private List<Long> parentsIds;
+
+    public List<Long> getParentsIds() {
+        return parentsIds;
+    }
+
+    public void setParentsIds(List<Long> parentsIds) {
+        this.parentsIds = parentsIds;
+    }
+
     public Long getDeptId()
     {
         return deptId;

+ 8 - 1
leromro-system/src/main/java/com/leromro/system/service/impl/SysDeptServiceImpl.java

@@ -4,6 +4,9 @@ import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.stream.Collectors;
+
+import cn.hutool.core.convert.Convert;
+import cn.hutool.core.util.StrUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.leromro.common.annotation.DataScope;
@@ -12,7 +15,6 @@ import com.leromro.common.core.domain.TreeSelect;
 import com.leromro.common.core.domain.entity.SysDept;
 import com.leromro.common.core.domain.entity.SysRole;
 import com.leromro.common.core.domain.entity.SysUser;
-import com.leromro.common.core.text.Convert;
 import com.leromro.common.exception.ServiceException;
 import com.leromro.common.utils.SecurityUtils;
 import com.leromro.common.utils.StringUtils;
@@ -57,6 +59,11 @@ public class SysDeptServiceImpl implements ISysDeptService
     @Override
     public List<TreeSelect> selectDeptTreeList(SysDept dept)
     {
+        SysDept sysDept = deptMapper.selectDeptById(SecurityUtils.getDeptId());
+        dept.setDeptId(sysDept.getDeptId());
+//        List<Long> longList = Convert.toList(Long.class, StrUtil.split(sysDept.getAncestors(), ','));
+//        longList.add(sysDept.getDeptId());
+//        dept.setParentsIds(longList);
         List<SysDept> depts = SpringUtils.getAopProxy(this).selectDeptList(dept);
         return buildDeptTreeSelect(depts);
     }

+ 4 - 0
leromro-system/src/main/java/com/leromro/system/service/impl/SysUserServiceImpl.java

@@ -5,6 +5,7 @@ import java.util.List;
 import java.util.stream.Collectors;
 import javax.validation.Validator;
 
+import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -77,6 +78,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
     @DataScope(deptAlias = "d", userAlias = "u")
     public List<SysUser> selectUserList(SysUser user)
     {
+        //如果每传dept则默认为当前,如果传了则判断是否是当前之上,是上面的则默认为当前,因为无法查看当前用户之上部门的用户列表
+        if (ObjectUtil.isEmpty(user.getDeptId()))
+        user.setDeptId(SecurityUtils.getDeptId());
         return userMapper.selectUserList(user);
     }
 

+ 6 - 1
leromro-system/src/main/resources/mapper/system/SysDeptMapper.xml

@@ -31,7 +31,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <include refid="selectDeptVo"/>
         where d.del_flag = '0'
 		<if test="deptId != null and deptId != 0">
-			AND dept_id = #{deptId}
+<!--			AND (ancestors like concat('%', #{deptId}, '%') or d.dept_id in-->
+<!--			<foreach collection="parentsIds" item="deptId" open="(" separator="," close=")">-->
+<!--				#{deptId}-->
+<!--			</foreach>-->
+-- 			)
+			AND (find_in_set(#{deptId}, d.ancestors) or d.dept_id = #{deptId})
 		</if>
         <if test="parentId != null and parentId != 0">
 			AND parent_id = #{parentId}