Browse Source

权限管理-角色新增和查询

jichaobo 3 years ago
parent
commit
64c4b1b990

+ 8 - 8
fiveep-controller/src/main/java/com/bizmatics/controller/web/system/SysRoleController.java

@@ -70,14 +70,14 @@ public class SysRoleController extends BaseController
     @PostMapping
     public ApiResult add(@Validated @RequestBody SysRole role)
     {
-        if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role)))
-        {
-            return ApiResult.error(BusinessErrorCode.BIZ_BUSINESS_ERROR.getCode(), "新增角色'" + role.getRoleName() + "'失败,角色名称已存在");
-        }
-        else if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role)))
-        {
-            return ApiResult.error(BusinessErrorCode.BIZ_BUSINESS_ERROR.getCode(), "新增角色'" + role.getRoleName() + "'失败,角色权限已存在");
-        }
+//        if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleNameUnique(role)))
+//        {
+//            return ApiResult.error(BusinessErrorCode.BIZ_BUSINESS_ERROR.getCode(), "新增角色'" + role.getRoleName() + "'失败,角色名称已存在");
+//        }
+//        else if (UserConstants.NOT_UNIQUE.equals(roleService.checkRoleKeyUnique(role)))
+//        {
+//            return ApiResult.error(BusinessErrorCode.BIZ_BUSINESS_ERROR.getCode(), "新增角色'" + role.getRoleName() + "'失败,角色权限已存在");
+//        }
         role.setCreateBy(SecurityUtils.getUsername());
         return toAjax(roleService.insertRole(role));
 

+ 15 - 0
fiveep-model/src/main/java/com/bizmatics/model/system/SysRole.java

@@ -54,6 +54,11 @@ public class SysRole extends BaseEntity
     /** 创建用户 */
     private String createByOne;
 
+    /**
+     * 租户ID
+     */
+    private Integer tenantId;
+
     public SysRole()
     {
 
@@ -208,6 +213,16 @@ public class SysRole extends BaseEntity
     {
         return createByOne;
     }
+
+    public void setTenantId(Integer tenantId)
+    {
+        this.tenantId = tenantId;
+    }
+
+    public Integer getTenantId()
+    {
+        return tenantId;
+    }
     
     @Override
     public String toString() {

+ 5 - 2
fiveep-persistence/src/main/resources/mapper/mysql/system/SysRoleMapper.xml

@@ -19,6 +19,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		<result property="updateBy"           column="update_by"             />
 		<result property="updateTime"         column="update_time"           />
 		<result property="remark"             column="remark"                />
+		<result property="tenantId"             column="tenant_id"                />
 	</resultMap>
 	
 	<sql id="selectRoleVo">
@@ -36,8 +37,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		<if test="roleName != null and roleName != ''">
 			AND r.role_name like concat('%', #{roleName}, '%')
 		</if>
-		<if test="createByOne != null and createByOne != ''">
-			AND r.create_by = #{createByOne}
+		<if test="tenantId != null and tenantId != ''and tenantId != 0">
+			AND r.tenant_id = #{tenantId}
 		</if>
 		<if test="status != null and status != ''">
 			AND r.status = #{status}
@@ -105,6 +106,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  			<if test="status != null and status != ''">status,</if>
  			<if test="remark != null and remark != ''">remark,</if>
  			<if test="createBy != null and createBy != ''">create_by,</if>
+			<if test="tenantId != null and tenantId != ''">tenant_id,</if>
  			create_time
  		)values(
  			<if test="roleId != null and roleId != 0">#{roleId},</if>
@@ -117,6 +119,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  			<if test="status != null and status != ''">#{status},</if>
  			<if test="remark != null and remark != ''">#{remark},</if>
  			<if test="createBy != null and createBy != ''">#{createBy},</if>
+			<if test="tenantId != null and tenantId != ''">#{tenantId},</if>
  			sysdate()
  		)
 	</insert>

+ 12 - 6
fiveep-service/src/main/java/com/bizmatics/service/system/impl/SysRoleServiceImpl.java

@@ -4,10 +4,7 @@ import com.bizmatics.common.core.exception.BusinessException;
 import com.bizmatics.common.spring.util.SpringContextUtils;
 import com.bizmatics.model.constants.UserConstants;
 import com.bizmatics.model.system.*;
-import com.bizmatics.persistence.mapper.system.SysRoleDeptMapper;
-import com.bizmatics.persistence.mapper.system.SysRoleMapper;
-import com.bizmatics.persistence.mapper.system.SysRoleMenuMapper;
-import com.bizmatics.persistence.mapper.system.SysUserRoleMapper;
+import com.bizmatics.persistence.mapper.system.*;
 import com.bizmatics.service.aop.DataScope;
 import com.bizmatics.service.system.ISysRoleService;
 import com.bizmatics.service.util.SecurityUtils;
@@ -36,6 +33,9 @@ public class SysRoleServiceImpl implements ISysRoleService
     @Autowired
     private SysRoleDeptMapper roleDeptMapper;
 
+    @Autowired
+    private SysUserMapper userMapper;
+
     /**
      * 根据条件分页查询角色数据
      * 
@@ -46,8 +46,11 @@ public class SysRoleServiceImpl implements ISysRoleService
     @DataScope(deptAlias = "d")
     public List<SysRole> selectRoleList(SysRole role)
     {
-        String createByOne = SecurityUtils.getLoginUser().getUser().getUserName();
-        role.setCreateByOne(createByOne);
+//        String createByOne = SecurityUtils.getLoginUser().getUser().getUserName();
+//        role.setCreateByOne(createByOne);
+        Long userId = SecurityUtils.getLoginUser().getUser().getUserId();
+        List<SysUser> sysMenuList = userMapper.getTenantId(userId);
+        role.setTenantId(sysMenuList.get(0).getTenantId());
         return roleMapper.selectRoleList(role);
     }
 
@@ -204,6 +207,9 @@ public class SysRoleServiceImpl implements ISysRoleService
     @Transactional
     public int insertRole(SysRole role)
     {
+        Long userId = SecurityUtils.getLoginUser().getUser().getUserId();
+        List<SysUser> sysMenuList = userMapper.getTenantId(userId);
+        role.setTenantId(sysMenuList.get(0).getTenantId());
         // 新增角色信息
         roleMapper.insertRole(role);
         return insertRoleMenu(role);