Эх сурвалжийг харах

feat: 部门管理增加租户ID

yang kai 2 жил өмнө
parent
commit
5d3bfe9451

+ 11 - 0
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysDept.java

@@ -51,6 +51,17 @@ public class SysDept extends BaseEntity
 
     /** 父部门名称 */
     private String parentName;
+
+    public Long getTenantId() {
+        return tenantId;
+    }
+
+    public void setTenantId(Long tenantId) {
+        this.tenantId = tenantId;
+    }
+
+    /** 租户ID */
+    private Long tenantId;
     
     /** 子部门 */
     private List<SysDept> children = new ArrayList<SysDept>();

+ 1 - 1
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysUser.java

@@ -131,7 +131,7 @@ public class SysUser extends BaseEntity
     }
 
     public boolean isTenantAdmin() {
-        return "01".equals(this.userType);
+        return "01".equals(this.userType) && this.tenantId != null;
     }
 
     public Long getDeptId()

+ 6 - 1
ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java

@@ -69,7 +69,7 @@ public class DataScopeAspect
         if (StringUtils.isNotNull(loginUser))
         {
             SysUser currentUser = loginUser.getUser();
-            System.out.println("currentUser: " + currentUser.isTenantAdmin());
+            System.out.println("currentUser isTenantAdmin: " + currentUser.isTenantAdmin());
             // 如果是超级管理员,则不过滤数据
             if (StringUtils.isNotNull(currentUser) && !currentUser.isAdmin())
             {
@@ -149,6 +149,11 @@ public class DataScopeAspect
             sqlString.append(StringUtils.format(" OR {}.dept_id = 0 ", deptAlias));
         }
 
+        // 租户管理员情况下,根据租户ID过滤数据
+        if (user.isTenantAdmin()) {
+            sqlString.append(StringUtils.format(" OR {}.tenant_id = {} ", deptAlias, user.getTenantId()));
+        }
+
         if (StringUtils.isNotBlank(sqlString.toString()))
         {
             Object params = joinPoint.getArgs()[0];

+ 2 - 2
ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysPermissionService.java

@@ -34,7 +34,7 @@ public class SysPermissionService
     {
         Set<String> roles = new HashSet<String>();
         // 管理员拥有所有权限
-        if (user.isAdmin())
+        if (user.isAdmin() || user.isTenantAdmin())
         {
             roles.add("admin");
         }
@@ -55,7 +55,7 @@ public class SysPermissionService
     {
         Set<String> perms = new HashSet<String>();
         // 管理员拥有所有权限
-        if (user.isAdmin())
+        if (user.isAdmin() || user.isTenantAdmin())
         {
             perms.add("*:*:*");
         }

+ 1 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java

@@ -218,6 +218,7 @@ public class SysDeptServiceImpl implements ISysDeptService
             throw new ServiceException("部门停用,不允许新增");
         }
         dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
+        dept.setTenantId(info.getTenantId());
         return deptMapper.insertDept(dept);
     }
 

+ 5 - 2
ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml

@@ -15,6 +15,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		<result property="email"      column="email"       />
 		<result property="status"     column="status"      />
 		<result property="delFlag"    column="del_flag"    />
+		<result property="tenantId"   column="tenant_id"   />
 		<result property="parentName" column="parent_name" />
 		<result property="createBy"   column="create_by"   />
 		<result property="createTime" column="create_time" />
@@ -23,7 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	</resultMap>
 	
 	<sql id="selectDeptVo">
-        select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time 
+        select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.tenant_id, d.create_by, d.create_time
         from sys_dept d
     </sql>
     
@@ -59,7 +60,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	</select>
     
     <select id="selectDeptById" parameterType="Long" resultMap="SysDeptResult">
-		select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status,
+		select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, d.tenant_id,
 			(select dept_name from sys_dept where dept_id = d.parent_id) parent_name
 		from sys_dept d
 		where d.dept_id = #{deptId}
@@ -98,6 +99,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  			<if test="phone != null and phone != ''">phone,</if>
  			<if test="email != null and email != ''">email,</if>
  			<if test="status != null">status,</if>
+		    <if test="tenantId != null">tenant_id,</if>
  			<if test="createBy != null and createBy != ''">create_by,</if>
  			create_time
  		)values(
@@ -110,6 +112,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  			<if test="phone != null and phone != ''">#{phone},</if>
  			<if test="email != null and email != ''">#{email},</if>
  			<if test="status != null">#{status},</if>
+		    <if test="tenantId != null">#{tenantId},</if>
  			<if test="createBy != null and createBy != ''">#{createBy},</if>
  			sysdate()
  		)

+ 1 - 1
ruoyi-ui/vue.config.js

@@ -35,7 +35,7 @@ module.exports = {
     proxy: {
       // detail: https://cli.vuejs.org/config/#devserver-proxy
       [process.env.VUE_APP_BASE_API]: {
-        target: `http://192.168.110.52:8080`,
+        target: `http://localhost:8080`,
         changeOrigin: true,
         pathRewrite: {
           ['^' + process.env.VUE_APP_BASE_API]: ''