forked from Gitlink/microservices
feat(ruoyi支持用户在多组织中不同角色能力): 增加用户与部门的一对多关系
1、用户与部门及部门对应角色的关联对象移动至公共模块 2、新增Fegin接口:通过用户名查询用户下组织及组织对应角色列表 关联Issue:https://www.gitlink.org.cn/Gitlink/forgeplus/issues/2780
This commit is contained in:
parent
d8788e5cae
commit
a9158d83c1
|
|
@ -4,11 +4,14 @@ import com.ruoyi.common.core.constant.SecurityConstants;
|
|||
import com.ruoyi.common.core.constant.ServiceNameConstants;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.system.api.domain.SysUser;
|
||||
import com.ruoyi.system.api.domain.SysUserDeptRole;
|
||||
import com.ruoyi.system.api.factory.RemoteUserFallbackFactory;
|
||||
import com.ruoyi.system.api.model.LoginUser;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户服务
|
||||
*
|
||||
|
|
@ -31,6 +34,7 @@ public interface RemoteUserService
|
|||
* 通过用户名查询用户信息
|
||||
*
|
||||
* @param username 用户名
|
||||
* @param source 请求来源
|
||||
* @return 结果
|
||||
*/
|
||||
@GetMapping("/user/getSysUserByUserName/{username}")
|
||||
|
|
@ -40,6 +44,7 @@ public interface RemoteUserService
|
|||
* 通过用户Id查询用户信息
|
||||
*
|
||||
* @param userId 用户Id
|
||||
* @param source 请求来源
|
||||
* @return 结果
|
||||
*/
|
||||
@GetMapping("/user/getSysUserByUserId/{userId}")
|
||||
|
|
@ -61,9 +66,19 @@ public interface RemoteUserService
|
|||
* 通过GitLinkToken获取本系统Token
|
||||
*
|
||||
* @param cookie
|
||||
* @param source 请求来源
|
||||
* @return 返回本系统Token
|
||||
*/
|
||||
@PostMapping("/user/getSysUserTokenByGitLinkCookie")
|
||||
public R<String> getSysUserTokenByGitLinkCookie(@RequestHeader("cookie") String cookie, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
/**
|
||||
* 通过用户名查询用户下组织及组织对应角色列表
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @param source 请求来源
|
||||
* @return 用户下组织及组织对应角色列表
|
||||
*/
|
||||
@GetMapping("/userByUserName/{userName}/list")
|
||||
public R<List<SysUserDeptRole>> getSysUserDeptRoleListByUserName(@PathVariable("userName") String userName, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,12 @@
|
|||
package com.ruoyi.system.domain;
|
||||
package com.ruoyi.system.api.domain;
|
||||
|
||||
import com.ruoyi.system.api.domain.SysDept;
|
||||
import com.ruoyi.system.api.domain.SysRole;
|
||||
import com.ruoyi.system.api.domain.SysUser;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 用户与部门及部门内角色关联对象 sys_user_dept_role
|
||||
*
|
||||
* @author otto
|
||||
* @date 2023-04-11
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@ApiModel("用户与部门及部门对应角色的关联对象")
|
||||
public class SysUserDeptRole {
|
||||
|
||||
|
|
@ -73,4 +62,64 @@ public class SysUserDeptRole {
|
|||
public int hashCode() {
|
||||
return Objects.hash(deptId, userId, roleId);
|
||||
}
|
||||
|
||||
public Long getDeptId() {
|
||||
return deptId;
|
||||
}
|
||||
|
||||
public void setDeptId(Long deptId) {
|
||||
this.deptId = deptId;
|
||||
}
|
||||
|
||||
public Long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Long userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public Long getRoleId() {
|
||||
return roleId;
|
||||
}
|
||||
|
||||
public void setRoleId(Long roleId) {
|
||||
this.roleId = roleId;
|
||||
}
|
||||
|
||||
public SysDept getSysDept() {
|
||||
return sysDept;
|
||||
}
|
||||
|
||||
public void setSysDept(SysDept sysDept) {
|
||||
this.sysDept = sysDept;
|
||||
}
|
||||
|
||||
public SysUser getSysUser() {
|
||||
return sysUser;
|
||||
}
|
||||
|
||||
public void setSysUser(SysUser sysUser) {
|
||||
this.sysUser = sysUser;
|
||||
}
|
||||
|
||||
public SysRole getSysRole() {
|
||||
return sysRole;
|
||||
}
|
||||
|
||||
public void setSysRole(SysRole sysRole) {
|
||||
this.sysRole = sysRole;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SysUserDeptRole{" +
|
||||
"deptId=" + deptId +
|
||||
", userId=" + userId +
|
||||
", roleId=" + roleId +
|
||||
", sysDept=" + sysDept +
|
||||
", sysUser=" + sysUser +
|
||||
", sysRole=" + sysRole +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
@ -3,12 +3,15 @@ package com.ruoyi.system.api.factory;
|
|||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.system.api.RemoteUserService;
|
||||
import com.ruoyi.system.api.domain.SysUser;
|
||||
import com.ruoyi.system.api.domain.SysUserDeptRole;
|
||||
import com.ruoyi.system.api.model.LoginUser;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户服务降级处理
|
||||
*
|
||||
|
|
@ -50,6 +53,11 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
|
|||
public R<String> getSysUserTokenByGitLinkCookie(String cookie, String source) {
|
||||
return R.fail("获取用户Token失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<List<SysUserDeptRole>> getSysUserDeptRoleListByUserName(String userName, String source) {
|
||||
return R.fail("查询用户下组织及组织对应角色列表失败:" + throwable.getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
package com.ruoyi.auth.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import com.ruoyi.common.core.constant.CacheConstants;
|
||||
import com.ruoyi.common.core.constant.Constants;
|
||||
import com.ruoyi.common.core.constant.SecurityConstants;
|
||||
|
|
@ -17,6 +15,8 @@ import com.ruoyi.common.security.utils.SecurityUtils;
|
|||
import com.ruoyi.system.api.RemoteUserService;
|
||||
import com.ruoyi.system.api.domain.SysUser;
|
||||
import com.ruoyi.system.api.model.LoginUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 登录校验方法
|
||||
|
|
@ -97,6 +97,7 @@ public class SysLoginService
|
|||
throw new ServiceException("对不起,您的账号:" + username + " 已停用");
|
||||
}
|
||||
passwordService.validate(user, password);
|
||||
|
||||
recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功");
|
||||
return userInfo;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,9 +50,9 @@ public class SortUtils {
|
|||
}
|
||||
|
||||
} catch (NoSuchFieldException e) {
|
||||
throw new ServiceException(String.format("没用指定字段[%s]", param));
|
||||
throw new ServiceException(String.format("指定的排序字段不存在[%s]", param));
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new ServiceException(String.format("访问字段非法,请检查字段[%s]权限", param));
|
||||
throw new ServiceException(String.format("访问排序字段非法,请检查排序字段[%s]权限", param));
|
||||
}
|
||||
return 1;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
package com.ruoyi.system.controller;
|
||||
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.web.controller.BaseController;
|
||||
import com.ruoyi.common.core.web.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.web.page.TableDataInfo;
|
||||
import com.ruoyi.common.log.annotation.Log;
|
||||
import com.ruoyi.common.log.enums.BusinessType;
|
||||
import com.ruoyi.system.domain.SysUserDeptRole;
|
||||
import com.ruoyi.common.security.annotation.InnerAuth;
|
||||
import com.ruoyi.system.api.domain.SysUserDeptRole;
|
||||
import com.ruoyi.system.domain.dto.SysUserDeptRoleByDeptInput;
|
||||
import com.ruoyi.system.domain.dto.SysUserDeptRoleByUserInput;
|
||||
import com.ruoyi.system.service.ISysUserDeptRoleService;
|
||||
|
|
@ -14,6 +16,7 @@ import io.swagger.annotations.ApiOperation;
|
|||
import io.swagger.annotations.ApiParam;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -101,6 +104,18 @@ public class SysUserDeptRoleController extends BaseController {
|
|||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过用户名查询用户下组织及组织对应角色列表
|
||||
*/
|
||||
// @RequiresPermissions("system:SysUserDeptRole:list")
|
||||
@ApiIgnore
|
||||
@InnerAuth
|
||||
@GetMapping("/userByUserName/{userName}/list")
|
||||
public R<List<SysUserDeptRole>> getSysUserDeptRoleListByUserName(@PathVariable("userName") String userName) {
|
||||
List<SysUserDeptRole> list = sysUserDeptRoleService.selectSysUserDeptRoleListByUserName(userName);
|
||||
return R.ok(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户下批量新增组织及在组织中的角色
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.ruoyi.system.domain.dto;
|
||||
|
||||
import com.ruoyi.system.domain.SysUserDeptRole;
|
||||
import com.ruoyi.system.api.domain.SysUserDeptRole;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.ruoyi.system.domain.dto;
|
||||
|
||||
import com.ruoyi.system.domain.SysUserDeptRole;
|
||||
import com.ruoyi.system.api.domain.SysUserDeptRole;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.ruoyi.system.mapper;
|
||||
|
||||
import com.ruoyi.system.domain.SysUserDeptRole;
|
||||
import com.ruoyi.system.api.domain.SysUserDeptRole;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -83,4 +83,6 @@ public interface SysUserDeptRoleMapper {
|
|||
List<SysUserDeptRole> selectSysUserDeptRoleListByUserId(@Param("userId") Long userId, @Param("deptName") String deptName, @Param("roleName") String roleName);
|
||||
|
||||
int deleteSysUserDeptRoleListByUserIdAndDeptIds(@Param("userId") Long userId, @Param("deptIds") Long[] deptIds);
|
||||
|
||||
List<SysUserDeptRole> selectSysUserDeptRoleListByUserName(String userName);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.ruoyi.system.service;
|
||||
|
||||
import com.ruoyi.system.domain.SysUserDeptRole;
|
||||
import com.ruoyi.system.api.domain.SysUserDeptRole;
|
||||
import com.ruoyi.system.domain.dto.SysUserDeptRoleByDeptInput;
|
||||
import com.ruoyi.system.domain.dto.SysUserDeptRoleByUserInput;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
|
@ -82,4 +82,6 @@ public interface ISysUserDeptRoleService {
|
|||
int updateSysUserDeptRoleByUser(Long userId, SysUserDeptRoleByUserInput[] sysUserDeptRoleByUserInputs);
|
||||
|
||||
int deleteSysUserDeptRoleListByUserIdAndDeptIds(Long userId, Long[] deptIds);
|
||||
|
||||
List<SysUserDeptRole> selectSysUserDeptRoleListByUserName(String userName);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import com.ruoyi.common.core.exception.ServiceException;
|
|||
import com.ruoyi.system.api.domain.SysDept;
|
||||
import com.ruoyi.system.api.domain.SysRole;
|
||||
import com.ruoyi.system.api.domain.SysUser;
|
||||
import com.ruoyi.system.domain.SysUserDeptRole;
|
||||
import com.ruoyi.system.api.domain.SysUserDeptRole;
|
||||
import com.ruoyi.system.domain.dto.SysUserDeptRoleByDeptInput;
|
||||
import com.ruoyi.system.domain.dto.SysUserDeptRoleByUserInput;
|
||||
import com.ruoyi.system.mapper.SysDeptMapper;
|
||||
|
|
@ -214,6 +214,11 @@ public class SysUserDeptRoleServiceImpl implements ISysUserDeptRoleService {
|
|||
return sysUserDeptRoleMapper.deleteSysUserDeptRoleListByUserIdAndDeptIds(userId, deptIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysUserDeptRole> selectSysUserDeptRoleListByUserName(String userName) {
|
||||
return sysUserDeptRoleMapper.selectSysUserDeptRoleListByUserName(userName);
|
||||
}
|
||||
|
||||
private SysUser selectSysUserById(Long userId) {
|
||||
SysUser sysUser = sysUserMapper.selectUserById(userId);
|
||||
if (sysUser == null) {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.system.mapper.SysUserDeptRoleMapper">
|
||||
|
||||
<resultMap type="com.ruoyi.system.domain.SysUserDeptRole" id="SysUserDeptRoleResult">
|
||||
<resultMap type="com.ruoyi.system.api.domain.SysUserDeptRole" id="SysUserDeptRoleResult">
|
||||
<result property="deptId" column="dept_id"/>
|
||||
<result property="userId" column="user_id"/>
|
||||
<result property="roleId" column="role_id"/>
|
||||
|
|
@ -82,7 +82,7 @@
|
|||
</sql>
|
||||
|
||||
|
||||
<select id="selectSysUserDeptRoleList" parameterType="com.ruoyi.system.domain.SysUserDeptRole"
|
||||
<select id="selectSysUserDeptRoleList" parameterType="com.ruoyi.system.api.domain.SysUserDeptRole"
|
||||
resultMap="SysUserDeptRoleResult">
|
||||
<include refid="selectSysUserDeptRoleVo"/>
|
||||
<where>
|
||||
|
|
@ -124,8 +124,15 @@
|
|||
</if>
|
||||
</where>
|
||||
</select>
|
||||
<select id="selectSysUserDeptRoleListByUserName" resultType="com.ruoyi.system.api.domain.SysUserDeptRole">
|
||||
<include refid="selectSysUserDeptRoleDetailVo"/>
|
||||
<where>
|
||||
u.user_name = #{userName}
|
||||
and u.del_flag = '0'
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<insert id="insertSysUserDeptRole" parameterType="com.ruoyi.system.domain.SysUserDeptRole">
|
||||
<insert id="insertSysUserDeptRole" parameterType="com.ruoyi.system.api.domain.SysUserDeptRole">
|
||||
insert into sys_user_dept_role
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="deptId != null">dept_id,</if>
|
||||
|
|
@ -139,7 +146,7 @@
|
|||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateSysUserDeptRole" parameterType="com.ruoyi.system.domain.SysUserDeptRole">
|
||||
<update id="updateSysUserDeptRole" parameterType="com.ruoyi.system.api.domain.SysUserDeptRole">
|
||||
update sys_user_dept_role
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="roleId != null">role_id = #{roleId},</if>
|
||||
|
|
|
|||
Loading…
Reference in New Issue