Răsfoiți Sursa

解决admin不能创建角色bug

xuezizhuo 1 an în urmă
părinte
comite
3d5c8e41ef

+ 22 - 0
zkqy-common/src/main/java/com/zkqy/common/utils/SecurityUtils.java

@@ -115,10 +115,20 @@ public class SecurityUtils {
         return userId != null && 1L == userId;
     }
 
+    /**
+     * 是否为租户管理员
+     * @param userType 用户类型
+     * @param tenantId 租户ID
+     * @return
+     */
     public static boolean isTenantAdmin(String userType, Long tenantId) {
         return tenantId != null && "01".equals(userType);
     }
 
+    /**
+     * 是否登录用户租户管理员
+     * @return
+     */
     public static boolean isLoginUserTenantAdmin() {
         LoginUser loginUser = SecurityUtils.getLoginUser();
         if (loginUser == null) {
@@ -137,4 +147,16 @@ public class SecurityUtils {
         LoginUser loginUser = SecurityUtils.getLoginUser();
         return loginUser.getUser().getTenant().getDataSource();
     }
+
+    /**
+     * 是否租户
+     */
+    public static boolean isTenant(){
+        LoginUser loginUser = SecurityUtils.getLoginUser();
+        if(loginUser == null || loginUser.getTenantId() == null){
+            return false;
+        }else {
+            return true;
+        }
+    }
 }

+ 2 - 2
zkqy-system/src/main/java/com/zkqy/system/mapper/SysRoleMapper.java

@@ -64,7 +64,7 @@ public interface SysRoleMapper {
      * @param roleName 角色名称
      * @return 角色信息
      */
-    public SysRole checkRoleNameUnique(@Param("roleName") String roleName, @Param("tenantId") String tenantId);
+    public SysRole checkRoleNameUnique(@Param("roleName") String roleName, @Param("tenantId") Long tenantId);
 
     /**
      * 校验角色权限是否唯一
@@ -72,7 +72,7 @@ public interface SysRoleMapper {
      * @param roleKey 角色权限
      * @return 角色信息
      */
-    public SysRole checkRoleKeyUnique(@Param("roleKey") String roleKey, @Param("tenantId") String tenantId);
+    public SysRole checkRoleKeyUnique(@Param("roleKey") String roleKey, @Param("tenantId") Long tenantId);
 
     /**
      * 修改角色信息

+ 13 - 2
zkqy-system/src/main/java/com/zkqy/system/service/impl/SysRoleServiceImpl.java

@@ -149,7 +149,12 @@ public class SysRoleServiceImpl implements ISysRoleService {
     @Override
     public boolean checkRoleNameUnique(SysRole role) {
         Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId();
-        SysRole info = roleMapper.checkRoleNameUnique(role.getRoleName(), role.getTenantId().toString());
+        SysRole info = new SysRole();
+        if(SecurityUtils.isTenant()){
+            info = roleMapper.checkRoleNameUnique(role.getRoleName(), role.getTenantId());
+        }else {
+            info = roleMapper.checkRoleNameUnique(role.getRoleName(), 0L);
+        }
         if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) {
             return UserConstants.NOT_UNIQUE;
         }
@@ -165,7 +170,13 @@ public class SysRoleServiceImpl implements ISysRoleService {
     @Override
     public boolean checkRoleKeyUnique(SysRole role) {
         Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId();
-        SysRole info = roleMapper.checkRoleKeyUnique(role.getRoleKey(), role.getTenantId().toString());
+        SysRole info = new SysRole();
+        if(SecurityUtils.isTenant()){
+            info = roleMapper.checkRoleKeyUnique(role.getRoleKey(), role.getTenantId());
+        }else {
+            info = roleMapper.checkRoleKeyUnique(role.getRoleKey(), 0L);
+        }
+
         if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) {
             return UserConstants.NOT_UNIQUE;
         }

+ 1 - 1
zkqy-system/src/main/resources/mapper/system/SysBpmNodeScriptMapper.xml

@@ -104,7 +104,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 
     <select id="selectSysBpmNodeScriptByScriptKey" parameterType="String" resultMap="SysBpmNodeScriptResult">
         <include refid="selectSysBpmNodeScriptVo"/>
-        where script_key = #{scriptKey}
+        where script_key = #{scriptKey} and del_flag = '0'
     </select>
 
     <select id="selectSysBpmNodeScriptByScriptKeys"  resultMap="SysBpmNodeScriptResult">

+ 16 - 2
zkqy-system/src/main/resources/mapper/system/SysRoleMapper.xml

@@ -97,12 +97,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	
 	<select id="checkRoleNameUnique" parameterType="String" resultMap="SysRoleResult">
 		<include refid="selectRoleVo"/>
-		 where r.role_name=#{roleName} and r.del_flag = '0' and r.tenant_id = #{tenantId} limit 1
+		 where r.role_name=#{roleName} and r.del_flag = '0'
+		 <if test="tenantId != 0">
+			 and r.tenant_id = #{tenantId}
+		 </if>
+		<if test="tenantId == 0">
+			and r.tenant_id is null
+		</if>
+		limit 1
 	</select>
 	
 	<select id="checkRoleKeyUnique" parameterType="String" resultMap="SysRoleResult">
 		<include refid="selectRoleVo"/>
-		 where r.role_key=#{roleKey} and r.del_flag = '0' and r.tenant_id = #{tenantId} limit 1
+		 where r.role_key=#{roleKey} and r.del_flag = '0'
+		<if test="tenantId != 0">
+			and r.tenant_id = #{tenantId}
+		</if>
+		<if test="tenantId == 0">
+			and r.tenant_id is null
+		</if>
+		limit 1
 	</select>
 
 	<select id="selectUserRoleKeyByUserId" parameterType="long" resultType="string">