使用mybatis-flex重构“角色管理”模块代码
This commit is contained in:
parent
39215aaded
commit
50da2f8224
2
pom.xml
2
pom.xml
@ -18,7 +18,7 @@
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>17</java.version>
|
||||
<spring-boot.version>3.1.4</spring-boot.version>
|
||||
<mybatis-flex.version>1.6.7</mybatis-flex.version>
|
||||
<mybatis-flex.version>1.6.8</mybatis-flex.version>
|
||||
<satoken.version>1.36.0</satoken.version>
|
||||
<mysql.version>8.0.33</mysql.version>
|
||||
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
|
||||
|
@ -10,6 +10,7 @@ import com.ruoyi.common.security.utils.LoginHelper;
|
||||
import com.ruoyi.system.domain.SysMenu;
|
||||
import com.ruoyi.system.domain.SysUser;
|
||||
import com.ruoyi.system.service.*;
|
||||
import com.ruoyi.web.domain.vo.LoginVo;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -60,7 +61,7 @@ public class AuthController {
|
||||
* @return 结果
|
||||
*/
|
||||
@PostMapping("/login")
|
||||
public AjaxResult login(@Validated @RequestBody LoginBody loginBody) {
|
||||
public R<LoginVo> login(@Validated @RequestBody LoginBody loginBody) {
|
||||
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
// 授权类型和客户端id
|
||||
@ -71,18 +72,14 @@ public class AuthController {
|
||||
// 查询不到 client 或 client 内不包含 grantType
|
||||
if (ObjectUtil.isNull(client) || !StringUtils.contains(client.getGrantType(), grantType)) {
|
||||
log.info("客户端id: {} 认证类型:{} 异常!.", clientId, grantType);
|
||||
return AjaxResult.error(MessageUtils.message("auth.grant.type.error"));
|
||||
return R.fail(MessageUtils.message("auth.grant.type.error"));
|
||||
}
|
||||
|
||||
// TODO:校验租户
|
||||
//loginService.checkTenant(loginBody.getTenantId());
|
||||
|
||||
// 生成令牌
|
||||
String token =IAuthStrategy.login(loginBody, client);
|
||||
ajax.put(Constants.TOKEN, token);
|
||||
|
||||
// 登录
|
||||
return ajax;
|
||||
return R.ok(IAuthStrategy.login(loginBody, client));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6,6 +6,7 @@ import com.ruoyi.common.core.core.domain.model.LoginBody;
|
||||
import com.ruoyi.common.core.exception.ServiceException;
|
||||
import com.ruoyi.common.core.utils.SpringUtils;
|
||||
import com.ruoyi.system.domain.SysClient;
|
||||
import com.ruoyi.web.domain.vo.LoginVo;
|
||||
|
||||
/**
|
||||
* 授权策略
|
||||
@ -19,7 +20,7 @@ public interface IAuthStrategy {
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
static String login(LoginBody loginBody, SysClient client) {
|
||||
static LoginVo login(LoginBody loginBody, SysClient client) {
|
||||
// 授权类型和客户端id
|
||||
String clientId = loginBody.getClientId();
|
||||
String grantType = loginBody.getGrantType();
|
||||
@ -40,6 +41,6 @@ public interface IAuthStrategy {
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
String login(String clientId, LoginBody loginBody, SysClient client);
|
||||
LoginVo login(String clientId, LoginBody loginBody, SysClient client);
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import cn.dev33.satoken.stp.SaLoginModel;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.ruoyi.common.core.core.domain.AjaxResult;
|
||||
import com.ruoyi.web.domain.vo.LoginVo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.ruoyi.common.core.constant.Constants;
|
||||
@ -46,7 +47,7 @@ public class EmailAuthStrategy implements IAuthStrategy {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String login(String clientId, LoginBody loginBody, SysClient client) {
|
||||
public LoginVo login(String clientId, LoginBody loginBody, SysClient client) {
|
||||
Long tenantId = loginBody.getTenantId();
|
||||
String email = loginBody.getEmail();
|
||||
String emailCode = loginBody.getEmailCode();
|
||||
@ -70,12 +71,12 @@ public class EmailAuthStrategy implements IAuthStrategy {
|
||||
loginService.recordLogininfor(loginUser.getTenantId(), user.getUserName(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"));
|
||||
loginService.recordLoginInfo(user.getUserId());
|
||||
|
||||
// LoginVo loginVo = new LoginVo();
|
||||
// loginVo.setAccessToken(StpUtil.getTokenValue());
|
||||
// loginVo.setExpireIn(StpUtil.getTokenTimeout());
|
||||
// loginVo.setClientId(clientId);
|
||||
// return loginVo;
|
||||
return StpUtil.getTokenValue();
|
||||
LoginVo loginVo = new LoginVo();
|
||||
loginVo.setAccessToken(StpUtil.getTokenValue());
|
||||
loginVo.setExpireIn(StpUtil.getTokenTimeout());
|
||||
loginVo.setClientId(clientId);
|
||||
return loginVo;
|
||||
// return StpUtil.getTokenValue();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,7 +57,7 @@ public class PasswordAuthStrategy implements IAuthStrategy {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String login(String clientId, LoginBody loginBody, SysClient client) {
|
||||
public LoginVo login(String clientId, LoginBody loginBody, SysClient client) {
|
||||
Long tenantId = loginBody.getTenantId();
|
||||
String username = loginBody.getUsername();
|
||||
String password = loginBody.getPassword();
|
||||
@ -87,13 +87,13 @@ public class PasswordAuthStrategy implements IAuthStrategy {
|
||||
loginService.recordLogininfor(loginUser.getTenantId(), username, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"));
|
||||
loginService.recordLoginInfo(user.getUserId());
|
||||
|
||||
// LoginVo loginVo = new LoginVo();
|
||||
// loginVo.setAccessToken(StpUtil.getTokenValue());
|
||||
// loginVo.setExpireIn(StpUtil.getTokenTimeout());
|
||||
// loginVo.setClientId(clientId);
|
||||
// return loginVo;
|
||||
LoginVo loginVo = new LoginVo();
|
||||
loginVo.setAccessToken(StpUtil.getTokenValue());
|
||||
loginVo.setExpireIn(StpUtil.getTokenTimeout());
|
||||
loginVo.setClientId(clientId);
|
||||
return loginVo;
|
||||
|
||||
return StpUtil.getTokenValue();
|
||||
//return StpUtil.getTokenValue();
|
||||
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,6 @@ mybatis-flex:
|
||||
# 默认日志输出 org.apache.ibatis.logging.slf4j.Slf4jImpl
|
||||
logImpl: org.apache.ibatis.logging.slf4j.Slf4jImpl
|
||||
cacheEnabled: true
|
||||
#useGeneratedKeys: true
|
||||
#defaultExecutorType: SIMPLE
|
||||
|
||||
# MyBatis-Flex全局配置
|
||||
global-config:
|
||||
|
@ -25,6 +25,7 @@ mybatis-flex:
|
||||
# 关闭日志记录 (可单纯使用 p6spy 分析) org.apache.ibatis.logging.nologging.NoLoggingImpl
|
||||
# 默认日志输出 org.apache.ibatis.logging.slf4j.Slf4jImpl
|
||||
logImpl: org.apache.ibatis.logging.slf4j.Slf4jImpl
|
||||
cacheEnabled: true
|
||||
|
||||
|
||||
# MyBatis-Flex全局配置
|
||||
|
@ -14,8 +14,20 @@ import java.util.Collection;
|
||||
* @author dataprince数据小王子
|
||||
*/
|
||||
public interface IBaseService<T> extends IService<T> {
|
||||
|
||||
/**
|
||||
* <p>带主键批量保存实体类对象数据,适用于中间表有联合主键场合,例如sys_role_menu。
|
||||
* <p>带主键保存实体类对象数据,适用于中间表有联合主键场合但是不通过主键生成器生成主键值,而是程序自己提供主键值。
|
||||
*
|
||||
* @param entity 实体类对象
|
||||
* @return 受影响的行数
|
||||
* @apiNote 默认调用的是 {@link BaseMapper#insertSelectiveWithPk(Object)} 方法,忽略实体类
|
||||
* {@code null} 属性的数据,使数据库配置的默认值生效。
|
||||
*/
|
||||
default int saveWithPk(T entity) {
|
||||
return getMapper().insertSelectiveWithPk(entity);
|
||||
}
|
||||
/**
|
||||
* <p>带主键批量保存实体类对象数据,适用于中间表有联合主键场合但是不通过主键生成器生成主键值,而是程序自己提供主键值,例如sys_role_menu。
|
||||
*
|
||||
* @param entities 实体类对象
|
||||
* @return {@code true} 保存成功,{@code false} 保存失败。
|
||||
@ -27,7 +39,7 @@ public interface IBaseService<T> extends IService<T> {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>带主键批量保存实体类对象数据,适用于中间表有联合主键场合,例如sys_role_menu。
|
||||
* <p>带主键批量保存实体类对象数据,适用于中间表有联合主键场合但是不通过主键生成器生成主键值,而是程序自己提供主键值,例如sys_role_menu。
|
||||
*
|
||||
* @param entities 实体类对象
|
||||
* @param batchSize 每次保存切分的数量
|
||||
|
@ -3,14 +3,17 @@ package com.ruoyi.system.controller.system;
|
||||
import java.util.List;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.ruoyi.common.core.core.domain.R;
|
||||
import com.ruoyi.common.excel.utils.ExcelUtil;
|
||||
import com.ruoyi.common.log.annotation.Log;
|
||||
import com.ruoyi.common.log.enums.BusinessType;
|
||||
import com.ruoyi.common.orm.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.security.utils.LoginHelper;
|
||||
import com.ruoyi.system.domain.SysDept;
|
||||
import com.ruoyi.system.domain.SysRole;
|
||||
import com.ruoyi.system.domain.SysUser;
|
||||
import com.ruoyi.system.domain.bo.SysDeptBo;
|
||||
import com.ruoyi.system.domain.bo.SysRoleBo;
|
||||
import com.ruoyi.system.domain.vo.DeptTreeSelectVo;
|
||||
import com.ruoyi.system.domain.vo.SysRoleVo;
|
||||
import com.ruoyi.system.service.ISysUserRoleService;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -25,7 +28,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.ruoyi.common.web.core.BaseController;
|
||||
import com.ruoyi.common.core.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.system.domain.SysUserRole;
|
||||
import com.ruoyi.system.service.ISysDeptService;
|
||||
import com.ruoyi.system.service.ISysRoleService;
|
||||
@ -40,34 +42,31 @@ import com.ruoyi.system.service.ISysUserService;
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/system/role")
|
||||
public class SysRoleController extends BaseController
|
||||
{
|
||||
public class SysRoleController extends BaseController {
|
||||
@Resource
|
||||
private ISysRoleService roleService;
|
||||
|
||||
@Resource
|
||||
private ISysUserService userService;
|
||||
|
||||
@Resource
|
||||
private ISysUserRoleService userRoleService;
|
||||
|
||||
@Resource
|
||||
private ISysDeptService deptService;
|
||||
|
||||
@SaCheckPermission("system:role:list")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(SysRole role)
|
||||
{
|
||||
startPage();
|
||||
List<SysRole> list = roleService.selectRoleList(role);
|
||||
return getDataTable(list);
|
||||
public TableDataInfo<SysRoleVo> list(SysRoleBo roleBo) {
|
||||
return roleService.selectPage(roleBo);
|
||||
}
|
||||
|
||||
@Log(title = "角色管理", businessType = BusinessType.EXPORT)
|
||||
@SaCheckPermission("system:role:export")
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, SysRole role)
|
||||
{
|
||||
List<SysRole> list = roleService.selectRoleList(role);
|
||||
ExcelUtil<SysRole> util = new ExcelUtil<>(SysRole.class);
|
||||
util.exportExcel(response, list, "角色数据");
|
||||
public void export(HttpServletResponse response, SysRoleBo roleBo) {
|
||||
List<SysRoleVo> list = roleService.selectRoleList(roleBo);
|
||||
ExcelUtil.exportExcel(list, "角色数据", SysRoleVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -75,10 +74,9 @@ public class SysRoleController extends BaseController
|
||||
*/
|
||||
@SaCheckPermission("system:role:query")
|
||||
@GetMapping(value = "/{roleId}")
|
||||
public AjaxResult getInfo(@PathVariable Long roleId)
|
||||
{
|
||||
public R<SysRoleVo> getInfo(@PathVariable Long roleId) {
|
||||
roleService.checkRoleDataScope(roleId);
|
||||
return success(roleService.selectRoleById(roleId));
|
||||
return R.ok(roleService.selectRoleById(roleId));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -87,19 +85,18 @@ public class SysRoleController extends BaseController
|
||||
@SaCheckPermission("system:role:add")
|
||||
@Log(title = "角色管理", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@Validated @RequestBody SysRole role)
|
||||
{
|
||||
if (!roleService.checkRoleNameUnique(role))
|
||||
{
|
||||
return error("新增角色'" + role.getRoleName() + "'失败,角色名称已存在");
|
||||
public R<Void> add(@Validated @RequestBody SysRoleBo roleBo) {
|
||||
roleService.checkRoleAllowed(roleBo);
|
||||
if (!roleService.checkRoleNameUnique(roleBo)) {
|
||||
return R.fail("新增角色'" + roleBo.getRoleName() + "'失败,角色名称已存在");
|
||||
} else if (!roleService.checkRoleKeyUnique(roleBo)) {
|
||||
return R.fail("新增角色'" + roleBo.getRoleName() + "'失败,角色权限已存在");
|
||||
}
|
||||
else if (!roleService.checkRoleKeyUnique(role))
|
||||
{
|
||||
return error("新增角色'" + role.getRoleName() + "'失败,角色权限已存在");
|
||||
boolean inserted = roleService.insertRole(roleBo);
|
||||
if (!inserted) {
|
||||
return R.fail("新增角色记录失败!");
|
||||
}
|
||||
role.setCreateBy(LoginHelper.getUserId());
|
||||
return toAjax(roleService.insertRole(role));
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -108,26 +105,20 @@ public class SysRoleController extends BaseController
|
||||
@SaCheckPermission("system:role:edit")
|
||||
@Log(title = "角色管理", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@Validated @RequestBody SysRole role)
|
||||
{
|
||||
roleService.checkRoleAllowed(role);
|
||||
roleService.checkRoleDataScope(role.getRoleId());
|
||||
if (!roleService.checkRoleNameUnique(role))
|
||||
{
|
||||
return error("修改角色'" + role.getRoleName() + "'失败,角色名称已存在");
|
||||
public R<Void> edit(@Validated @RequestBody SysRoleBo roleBo) {
|
||||
roleService.checkRoleAllowed(roleBo);
|
||||
roleService.checkRoleDataScope(roleBo.getRoleId());
|
||||
if (!roleService.checkRoleNameUnique(roleBo)) {
|
||||
return R.fail("修改角色'" + roleBo.getRoleName() + "'失败,角色名称已存在");
|
||||
} else if (!roleService.checkRoleKeyUnique(roleBo)) {
|
||||
return R.fail("修改角色'" + roleBo.getRoleName() + "'失败,角色权限已存在");
|
||||
}
|
||||
else if (!roleService.checkRoleKeyUnique(role))
|
||||
{
|
||||
return error("修改角色'" + role.getRoleName() + "'失败,角色权限已存在");
|
||||
boolean updated = roleService.updateRole(roleBo);
|
||||
if (updated) {
|
||||
roleService.cleanOnlineUserByRole(roleBo.getRoleId());
|
||||
return R.ok();
|
||||
}
|
||||
role.setUpdateBy(LoginHelper.getUserId());
|
||||
|
||||
if (roleService.updateRole(role) > 0)
|
||||
{
|
||||
roleService.cleanOnlineUserByRole(role.getRoleId());
|
||||
return success();
|
||||
}
|
||||
return error("修改角色'" + role.getRoleName() + "'失败,请联系管理员");
|
||||
return R.fail("修改角色'" + roleBo.getRoleName() + "'失败,请联系管理员");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -136,11 +127,15 @@ public class SysRoleController extends BaseController
|
||||
@SaCheckPermission("system:role:edit")
|
||||
@Log(title = "角色管理", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/dataScope")
|
||||
public AjaxResult dataScope(@RequestBody SysRole role)
|
||||
{
|
||||
roleService.checkRoleAllowed(role);
|
||||
roleService.checkRoleDataScope(role.getRoleId());
|
||||
return toAjax(roleService.authDataScope(role));
|
||||
public R<Void> dataScope(@RequestBody SysRoleBo roleBo) {
|
||||
roleService.checkRoleAllowed(roleBo);
|
||||
roleService.checkRoleDataScope(roleBo.getRoleId());
|
||||
boolean updated = roleService.authDataScope(roleBo);
|
||||
if (!updated) {
|
||||
return R.fail("修改角色'" + roleBo.getRoleName() + "'数据权限失败,请联系管理员");
|
||||
}
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -149,12 +144,14 @@ public class SysRoleController extends BaseController
|
||||
@SaCheckPermission("system:role:edit")
|
||||
@Log(title = "角色管理", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/changeStatus")
|
||||
public AjaxResult changeStatus(@RequestBody SysRole role)
|
||||
{
|
||||
roleService.checkRoleAllowed(role);
|
||||
roleService.checkRoleDataScope(role.getRoleId());
|
||||
role.setUpdateBy(LoginHelper.getUserId());
|
||||
return toAjax(roleService.updateRoleStatus(role));
|
||||
public R<Void> changeStatus(@RequestBody SysRoleBo roleBo) {
|
||||
roleService.checkRoleAllowed(roleBo);
|
||||
roleService.checkRoleDataScope(roleBo.getRoleId());
|
||||
boolean updated = roleService.updateRoleStatus(roleBo);
|
||||
if (!updated) {
|
||||
return R.fail("修改角色'" + roleBo.getRoleName() + "'的状态失败,请联系管理员");
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -163,9 +160,12 @@ public class SysRoleController extends BaseController
|
||||
@SaCheckPermission("system:role:remove")
|
||||
@Log(title = "角色管理", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{roleIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] roleIds)
|
||||
{
|
||||
return toAjax(roleService.deleteRoleByIds(roleIds));
|
||||
public R<Void> remove(@PathVariable Long[] roleIds) {
|
||||
boolean deleted = roleService.deleteRoleByIds(roleIds);
|
||||
if (!deleted) {
|
||||
return R.fail("批量删除角色失败,请联系管理员");
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -173,9 +173,8 @@ public class SysRoleController extends BaseController
|
||||
*/
|
||||
@SaCheckPermission("system:role:query")
|
||||
@GetMapping("/optionselect")
|
||||
public AjaxResult optionselect()
|
||||
{
|
||||
return success(roleService.selectRoleAll());
|
||||
public R<List<SysRoleVo>> optionSelect() {
|
||||
return R.ok(roleService.selectRoleAll());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -183,8 +182,7 @@ public class SysRoleController extends BaseController
|
||||
*/
|
||||
@SaCheckPermission("system:role:list")
|
||||
@GetMapping("/authUser/allocatedList")
|
||||
public TableDataInfo allocatedList(SysUser user)
|
||||
{
|
||||
public TableDataInfo allocatedList(SysUser user) {
|
||||
startPage();
|
||||
List<SysUser> list = userService.selectAllocatedList(user);
|
||||
return getDataTable(list);
|
||||
@ -195,8 +193,7 @@ public class SysRoleController extends BaseController
|
||||
*/
|
||||
@SaCheckPermission("system:role:list")
|
||||
@GetMapping("/authUser/unallocatedList")
|
||||
public TableDataInfo unallocatedList(SysUser user)
|
||||
{
|
||||
public TableDataInfo unallocatedList(SysUser user) {
|
||||
startPage();
|
||||
List<SysUser> list = userService.selectUnallocatedList(user);
|
||||
return getDataTable(list);
|
||||
@ -208,9 +205,12 @@ public class SysRoleController extends BaseController
|
||||
@SaCheckPermission("system:role:edit")
|
||||
@Log(title = "角色管理", businessType = BusinessType.GRANT)
|
||||
@PutMapping("/authUser/cancel")
|
||||
public AjaxResult cancelAuthUser(@RequestBody SysUserRole userRole)
|
||||
{
|
||||
return toAjax(roleService.deleteAuthUser(userRole));
|
||||
public R<Void> cancelAuthUser(@RequestBody SysUserRole userRole) {
|
||||
boolean deleted = userRoleService.deleteUserRoleInfo(userRole);
|
||||
if (!deleted) {
|
||||
return R.fail("取消授权用户角色失败,请联系管理员");
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -219,9 +219,12 @@ public class SysRoleController extends BaseController
|
||||
@SaCheckPermission("system:role:edit")
|
||||
@Log(title = "角色管理", businessType = BusinessType.GRANT)
|
||||
@PutMapping("/authUser/cancelAll")
|
||||
public AjaxResult cancelAuthUserAll(Long roleId, Long[] userIds)
|
||||
{
|
||||
return toAjax(roleService.deleteAuthUsers(roleId, userIds));
|
||||
public R<Void> cancelAuthUserAll(Long roleId, Long[] userIds) {
|
||||
boolean deleted = userRoleService.deleteUserRoleInfos(roleId,userIds);
|
||||
if (!deleted) {
|
||||
return R.fail("批量取消授权用户角色失败,请联系管理员");
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -230,10 +233,13 @@ public class SysRoleController extends BaseController
|
||||
@SaCheckPermission("system:role:edit")
|
||||
@Log(title = "角色管理", businessType = BusinessType.GRANT)
|
||||
@PutMapping("/authUser/selectAll")
|
||||
public AjaxResult selectAuthUserAll(Long roleId, Long[] userIds)
|
||||
{
|
||||
public R<Void> selectAuthUserAll(Long roleId, Long[] userIds) {
|
||||
roleService.checkRoleDataScope(roleId);
|
||||
return toAjax(roleService.insertAuthUsers(roleId, userIds));
|
||||
boolean inserted = userRoleService.insertAuthUsers(roleId, userIds);
|
||||
if (!inserted) {
|
||||
return R.fail("批量选择用户授权失败,请联系管理员");
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -241,11 +247,10 @@ public class SysRoleController extends BaseController
|
||||
*/
|
||||
@SaCheckPermission("system:role:query")
|
||||
@GetMapping(value = "/deptTree/{roleId}")
|
||||
public AjaxResult deptTree(@PathVariable("roleId") Long roleId)
|
||||
{
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId));
|
||||
ajax.put("depts", deptService.selectDeptTreeList(new SysDeptBo()));
|
||||
return ajax;
|
||||
public R<DeptTreeSelectVo> deptTree(@PathVariable("roleId") Long roleId) {
|
||||
DeptTreeSelectVo selectVo = new DeptTreeSelectVo();
|
||||
selectVo.setCheckedKeys(deptService.selectDeptListByRoleId(roleId));
|
||||
selectVo.setDepts(deptService.selectDeptTreeList(new SysDeptBo()));
|
||||
return R.ok(selectVo);
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,8 @@ import com.ruoyi.system.domain.SysRole;
|
||||
import com.ruoyi.system.domain.SysUser;
|
||||
import com.ruoyi.system.domain.bo.SysDeptBo;
|
||||
import com.ruoyi.system.domain.bo.SysPostBo;
|
||||
import com.ruoyi.system.domain.bo.SysRoleBo;
|
||||
import com.ruoyi.system.domain.vo.SysRoleVo;
|
||||
import com.ruoyi.system.service.*;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
@ -113,9 +115,9 @@ public class SysUserController extends BaseController {
|
||||
@GetMapping(value = {"/", "/{userId}"})
|
||||
public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId) {
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
SysRole sysRole = new SysRole();
|
||||
SysRoleBo sysRole = new SysRoleBo();
|
||||
sysRole.setStatus(UserConstants.ROLE_NORMAL);
|
||||
List<SysRole> roles = roleService.selectRoleList(sysRole);
|
||||
List<SysRoleVo> roles = roleService.selectRoleList(sysRole);
|
||||
SysPostBo sysPost = new SysPostBo();
|
||||
sysPost.setStatus(UserConstants.POST_NORMAL);
|
||||
ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
|
||||
@ -216,7 +218,7 @@ public class SysUserController extends BaseController {
|
||||
public AjaxResult authRole(@PathVariable("userId") Long userId) {
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
SysUser user = userService.selectUserById(userId);
|
||||
List<SysRole> roles = roleService.selectRolesByUserId(userId);
|
||||
List<SysRoleVo> roles = roleService.selectRolesByUserId(userId);
|
||||
ajax.put("user", user);
|
||||
ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
|
||||
return ajax;
|
||||
|
@ -1,21 +1,11 @@
|
||||
package com.ruoyi.system.domain;
|
||||
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.RelationManyToMany;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import com.mybatisflex.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import com.ruoyi.common.core.annotation.Excel.ColumnType;
|
||||
import com.ruoyi.common.orm.core.domain.BaseEntity;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@ -28,40 +18,51 @@ import java.util.Set;
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Table(value = "sys_role")
|
||||
public class SysRole extends BaseEntity
|
||||
{
|
||||
/** 角色ID */
|
||||
@Excel(name = "角色序号", cellType = ColumnType.NUMERIC)
|
||||
@Id(keyType = KeyType.Auto)
|
||||
public class SysRole extends BaseEntity {
|
||||
/**
|
||||
* 角色ID
|
||||
*/
|
||||
@Id
|
||||
private Long roleId;
|
||||
|
||||
/** 角色名称 */
|
||||
@Excel(name = "角色名称")
|
||||
/**
|
||||
* 角色名称
|
||||
*/
|
||||
private String roleName;
|
||||
|
||||
/** 角色权限 */
|
||||
@Excel(name = "角色权限")
|
||||
/**
|
||||
* 角色权限
|
||||
*/
|
||||
private String roleKey;
|
||||
|
||||
/** 角色排序 */
|
||||
@Excel(name = "角色排序")
|
||||
/**
|
||||
* 角色排序
|
||||
*/
|
||||
private String roleSort;
|
||||
|
||||
/** 数据范围(1:所有数据权限;2:自定义数据权限;3:本部门数据权限;4:本部门及以下数据权限;5:仅本人数据权限) */
|
||||
@Excel(name = "数据范围", readConverterExp = "1=所有数据权限,2=自定义数据权限,3=本部门数据权限,4=本部门及以下数据权限,5=仅本人数据权限")
|
||||
/**
|
||||
* 数据范围(1:所有数据权限;2:自定义数据权限;3:本部门数据权限;4:本部门及以下数据权限;5:仅本人数据权限)
|
||||
*/
|
||||
private String dataScope;
|
||||
|
||||
/** 菜单树选择项是否关联显示( 0:父子不互相关联显示 1:父子互相关联显示) */
|
||||
/**
|
||||
* 菜单树选择项是否关联显示( 0:父子不互相关联显示 1:父子互相关联显示)
|
||||
*/
|
||||
private boolean menuCheckStrictly;
|
||||
|
||||
/** 部门树选择项是否关联显示(0:父子不互相关联显示 1:父子互相关联显示 ) */
|
||||
/**
|
||||
* 部门树选择项是否关联显示(0:父子不互相关联显示 1:父子互相关联显示 )
|
||||
*/
|
||||
private boolean deptCheckStrictly;
|
||||
|
||||
/** 角色状态(0正常 1停用) */
|
||||
@Excel(name = "角色状态", readConverterExp = "0=正常,1=停用")
|
||||
/**
|
||||
* 角色状态(0正常 1停用)
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/** 删除标志(0代表存在 2代表删除) */
|
||||
/**
|
||||
* 删除标志(0代表存在 2代表删除)
|
||||
*/
|
||||
private String delFlag;
|
||||
|
||||
/**
|
||||
@ -69,48 +70,60 @@ public class SysRole extends BaseEntity
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
/** 用户是否存在此角色标识 默认不存在 */
|
||||
/**
|
||||
* 用户是否存在此角色标识 默认不存在
|
||||
*/
|
||||
@Column(ignore = true)
|
||||
private boolean flag = false;
|
||||
|
||||
/** 菜单组 */
|
||||
/**
|
||||
* 菜单组
|
||||
*/
|
||||
@Column(ignore = true)
|
||||
private Long[] menuIds;
|
||||
|
||||
@RelationManyToMany(
|
||||
selfField = "roleId",
|
||||
targetField = "menuId",
|
||||
selfField = "roleId", targetField = "menuId",
|
||||
joinTable = "sys_role_menu",
|
||||
joinSelfColumn = "role_id",
|
||||
joinTargetColumn = "menu_id"
|
||||
joinSelfColumn = "role_id", joinTargetColumn = "menu_id"
|
||||
)
|
||||
private List<SysMenu> menuList;
|
||||
|
||||
/** 部门组(数据权限) */
|
||||
/**
|
||||
* 部门组(数据权限)
|
||||
*/
|
||||
@Column(ignore = true)
|
||||
private Long[] deptIds;
|
||||
|
||||
@RelationManyToMany(
|
||||
selfField = "roleId",
|
||||
targetField = "deptId",
|
||||
selfField = "roleId", targetField = "deptId",
|
||||
joinTable = "sys_role_dept",
|
||||
joinSelfColumn = "role_id",
|
||||
joinTargetColumn = "dept_id"
|
||||
joinSelfColumn = "role_id", joinTargetColumn = "dept_id"
|
||||
)
|
||||
private List<SysDept> deptList;
|
||||
|
||||
/** 角色菜单权限 */
|
||||
@RelationManyToMany(
|
||||
selfField = "roleId", targetField = "userId",
|
||||
joinTable = "sys_user_role",
|
||||
joinSelfColumn = "role_id", joinTargetColumn = "user_id"
|
||||
)
|
||||
private List<SysUser> userList;
|
||||
|
||||
/**
|
||||
* 角色菜单权限
|
||||
*/
|
||||
@Column(ignore = true)
|
||||
private Set<String> permissions;
|
||||
|
||||
public SysRole(Long roleId)
|
||||
{
|
||||
public SysRole(Long roleId) {
|
||||
this.roleId = roleId;
|
||||
}
|
||||
|
||||
public boolean isAdmin()
|
||||
{
|
||||
public boolean isAdmin() {
|
||||
return isAdmin(this.roleId);
|
||||
}
|
||||
|
||||
public static boolean isAdmin(Long roleId)
|
||||
{
|
||||
public static boolean isAdmin(Long roleId) {
|
||||
return roleId != null && 1L == roleId;
|
||||
}
|
||||
|
||||
|
@ -1,46 +1,26 @@
|
||||
package com.ruoyi.system.domain;
|
||||
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
/**
|
||||
* 角色和部门关联 sys_role_dept
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Data
|
||||
@Table(value = "sys_role_dept")
|
||||
public class SysRoleDept
|
||||
{
|
||||
/** 角色ID */
|
||||
@Id
|
||||
private Long roleId;
|
||||
|
||||
|
||||
/** 部门ID */
|
||||
@Id
|
||||
private Long deptId;
|
||||
|
||||
public Long getRoleId()
|
||||
{
|
||||
return roleId;
|
||||
}
|
||||
|
||||
public void setRoleId(Long roleId)
|
||||
{
|
||||
this.roleId = roleId;
|
||||
}
|
||||
|
||||
public Long getDeptId()
|
||||
{
|
||||
return deptId;
|
||||
}
|
||||
|
||||
public void setDeptId(Long deptId)
|
||||
{
|
||||
this.deptId = deptId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("roleId", getRoleId())
|
||||
.append("deptId", getDeptId())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
@ -25,32 +25,4 @@ public class SysRoleMenu
|
||||
/** 菜单ID */
|
||||
@Id(keyType = KeyType.None)
|
||||
private Long menuId;
|
||||
|
||||
public Long getRoleId()
|
||||
{
|
||||
return roleId;
|
||||
}
|
||||
|
||||
public void setRoleId(Long roleId)
|
||||
{
|
||||
this.roleId = roleId;
|
||||
}
|
||||
|
||||
public Long getMenuId()
|
||||
{
|
||||
return menuId;
|
||||
}
|
||||
|
||||
public void setMenuId(Long menuId)
|
||||
{
|
||||
this.menuId = menuId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("roleId", getRoleId())
|
||||
.append("menuId", getMenuId())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,7 @@ import java.io.Serial;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import com.mybatisflex.annotation.*;
|
||||
import com.ruoyi.common.core.constant.UserConstants;
|
||||
import com.ruoyi.common.orm.core.domain.BaseEntity;
|
||||
import jakarta.validation.constraints.*;
|
||||
@ -41,6 +39,14 @@ public class SysUser extends BaseEntity
|
||||
@Excel(name = "部门编号", type = Type.IMPORT)
|
||||
private Long deptId;
|
||||
|
||||
/** 部门对象 */
|
||||
@Excels({
|
||||
@Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT),
|
||||
@Excel(name = "部门负责人", targetAttr = "leader", type = Type.EXPORT)
|
||||
})
|
||||
@RelationManyToOne(selfField = "deptId", targetField = "deptId")
|
||||
private SysDept dept;
|
||||
|
||||
/** 用户账号 */
|
||||
@Excel(name = "登录名称")
|
||||
private String userName;
|
||||
@ -90,19 +96,26 @@ public class SysUser extends BaseEntity
|
||||
@Excel(name = "最后登录时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss", type = Type.EXPORT)
|
||||
private Date loginDate;
|
||||
|
||||
/** 部门对象 */
|
||||
@Excels({
|
||||
@Excel(name = "部门名称", targetAttr = "deptName", type = Type.EXPORT),
|
||||
@Excel(name = "部门负责人", targetAttr = "leader", type = Type.EXPORT)
|
||||
})
|
||||
private SysDept dept;
|
||||
|
||||
|
||||
/** 角色对象 */
|
||||
@RelationManyToMany(
|
||||
selfField = "userId", targetField = "roleId",
|
||||
joinTable = "sys_user_role",
|
||||
joinSelfColumn = "user_id", joinTargetColumn = "role_id"
|
||||
)
|
||||
private List<SysRole> roles;
|
||||
|
||||
/** 角色组 */
|
||||
private Long[] roleIds;
|
||||
|
||||
@RelationManyToMany(
|
||||
selfField = "userId", targetField = "postId",
|
||||
joinTable = "sys_user_post",
|
||||
joinSelfColumn = "user_id", joinTargetColumn = "post_id"
|
||||
)
|
||||
private List<SysPost> postList;
|
||||
|
||||
/** 岗位组 */
|
||||
private Long[] postIds;
|
||||
|
||||
|
@ -1,19 +1,25 @@
|
||||
package com.ruoyi.system.domain;
|
||||
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.KeyType;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
/**
|
||||
* 用户和岗位关联 sys_user_post
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Table(value = "sys_user_post")
|
||||
public class SysUserPost
|
||||
{
|
||||
/** 用户ID */
|
||||
@Id(keyType = KeyType.None)
|
||||
private Long userId;
|
||||
|
||||
|
||||
/** 岗位ID */
|
||||
@Id(keyType = KeyType.None)
|
||||
private Long postId;
|
||||
|
||||
public Long getUserId()
|
||||
|
@ -1,46 +1,25 @@
|
||||
package com.ruoyi.system.domain;
|
||||
|
||||
import com.mybatisflex.annotation.Id;
|
||||
import com.mybatisflex.annotation.Table;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
/**
|
||||
* 用户和角色关联 sys_user_role
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Data
|
||||
@Table(value = "sys_user_role")
|
||||
public class SysUserRole
|
||||
{
|
||||
/** 用户ID */
|
||||
@Id
|
||||
private Long userId;
|
||||
|
||||
|
||||
/** 角色ID */
|
||||
@Id
|
||||
private Long roleId;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("userId", getUserId())
|
||||
.append("roleId", getRoleId())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.ruoyi.system.domain.vo;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.mybatisflex.annotation.Column;
|
||||
import com.ruoyi.common.core.constant.UserConstants;
|
||||
import com.ruoyi.common.excel.annotation.ExcelDictFormat;
|
||||
import com.ruoyi.common.excel.convert.ExcelDictConvert;
|
||||
@ -91,10 +92,19 @@ public class SysRoleVo implements Serializable {
|
||||
/**
|
||||
* 用户是否存在此角色标识 默认不存在
|
||||
*/
|
||||
@Column(ignore = true)
|
||||
private boolean flag = false;
|
||||
|
||||
public boolean isSuperAdmin() {
|
||||
return UserConstants.SUPER_ADMIN_ID.equals(this.roleId);
|
||||
}
|
||||
|
||||
public boolean isAdmin() {
|
||||
return isAdmin(this.roleId);
|
||||
}
|
||||
|
||||
public static boolean isAdmin(Long roleId) {
|
||||
return roleId != null && 1L == roleId;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,44 +1,48 @@
|
||||
package com.ruoyi.system.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.ruoyi.system.domain.SysRoleDept;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 角色与部门关联表 数据层
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface SysRoleDeptMapper
|
||||
@Mapper
|
||||
public interface SysRoleDeptMapper extends BaseMapper<SysRoleDept>
|
||||
{
|
||||
/**
|
||||
* 通过角色ID删除角色和部门关联
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRoleDeptByRoleId(Long roleId);
|
||||
// /**
|
||||
// * 通过角色ID删除角色和部门关联
|
||||
// *
|
||||
// * @param roleId 角色ID
|
||||
// * @return 结果
|
||||
// */
|
||||
// public int deleteRoleDeptByRoleId(Long roleId);
|
||||
|
||||
/**
|
||||
* 批量删除角色部门关联信息
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRoleDept(Long[] ids);
|
||||
// /**
|
||||
// * 批量删除角色部门关联信息
|
||||
// *
|
||||
// * @param ids 需要删除的数据ID
|
||||
// * @return 结果
|
||||
// */
|
||||
// public int deleteRoleDept(Long[] ids);
|
||||
|
||||
/**
|
||||
* 查询部门使用数量
|
||||
*
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int selectCountRoleDeptByDeptId(Long deptId);
|
||||
|
||||
/**
|
||||
* 批量新增角色部门信息
|
||||
*
|
||||
* @param roleDeptList 角色部门列表
|
||||
* @return 结果
|
||||
*/
|
||||
public int batchRoleDept(List<SysRoleDept> roleDeptList);
|
||||
// /**
|
||||
// * 批量新增角色部门信息
|
||||
// *
|
||||
// * @param roleDeptList 角色部门列表
|
||||
// * @return 结果
|
||||
// */
|
||||
// public int batchRoleDept(List<SysRoleDept> roleDeptList);
|
||||
}
|
||||
|
@ -1,108 +1,16 @@
|
||||
package com.ruoyi.system.mapper;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.ruoyi.system.domain.SysRole;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 角色表 数据层
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface SysRoleMapper
|
||||
@Mapper
|
||||
public interface SysRoleMapper extends BaseMapper<SysRole>
|
||||
{
|
||||
/**
|
||||
* 根据条件分页查询角色数据
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 角色数据集合信息
|
||||
*/
|
||||
List<SysRole> selectRoleList(SysRole role);
|
||||
|
||||
/**
|
||||
* 根据用户ID查询角色
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 角色列表
|
||||
*/
|
||||
List<SysRole> selectRolePermissionByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 查询所有角色
|
||||
*
|
||||
* @return 角色列表
|
||||
*/
|
||||
List<SysRole> selectRoleAll();
|
||||
|
||||
/**
|
||||
* 根据用户ID获取角色选择框列表
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 选中角色ID列表
|
||||
*/
|
||||
List<Long> selectRoleListByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 通过角色ID查询角色
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 角色对象信息
|
||||
*/
|
||||
SysRole selectRoleById(Long roleId);
|
||||
|
||||
/**
|
||||
* 根据用户ID查询角色
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @return 角色列表
|
||||
*/
|
||||
List<SysRole> selectRolesByUserName(String userName);
|
||||
|
||||
/**
|
||||
* 校验角色名称是否唯一
|
||||
*
|
||||
* @param roleName 角色名称
|
||||
* @return 角色信息
|
||||
*/
|
||||
SysRole checkRoleNameUnique(String roleName);
|
||||
|
||||
/**
|
||||
* 校验角色权限是否唯一
|
||||
*
|
||||
* @param roleKey 角色权限
|
||||
* @return 角色信息
|
||||
*/
|
||||
SysRole checkRoleKeyUnique(String roleKey);
|
||||
|
||||
/**
|
||||
* 修改角色信息
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 结果
|
||||
*/
|
||||
int updateRole(SysRole role);
|
||||
|
||||
/**
|
||||
* 新增角色信息
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 结果
|
||||
*/
|
||||
int insertRole(SysRole role);
|
||||
|
||||
/**
|
||||
* 通过角色ID删除角色
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteRoleById(Long roleId);
|
||||
|
||||
/**
|
||||
* 批量删除角色信息
|
||||
*
|
||||
* @param roleIds 需要删除的角色ID
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteRoleByIds(Long[] roleIds);
|
||||
}
|
||||
|
@ -1,44 +1,48 @@
|
||||
package com.ruoyi.system.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.ruoyi.system.domain.SysRoleMenu;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 角色与菜单关联表 数据层
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface SysRoleMenuMapper
|
||||
@Mapper
|
||||
public interface SysRoleMenuMapper extends BaseMapper<SysRoleMenu>
|
||||
{
|
||||
/**
|
||||
* 查询菜单使用数量
|
||||
*
|
||||
*
|
||||
* @param menuId 菜单ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int checkMenuExistRole(Long menuId);
|
||||
|
||||
/**
|
||||
* 通过角色ID删除角色和菜单关联
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRoleMenuByRoleId(Long roleId);
|
||||
// /**
|
||||
// * 通过角色ID删除角色和菜单关联
|
||||
// *
|
||||
// * @param roleId 角色ID
|
||||
// * @return 结果
|
||||
// */
|
||||
// public int deleteRoleMenuByRoleId(Long roleId);
|
||||
//
|
||||
// /**
|
||||
// * 批量删除角色菜单关联信息
|
||||
// *
|
||||
// * @param ids 需要删除的数据ID
|
||||
// * @return 结果
|
||||
// */
|
||||
// public int deleteRoleMenu(Long[] ids);
|
||||
|
||||
/**
|
||||
* 批量删除角色菜单关联信息
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteRoleMenu(Long[] ids);
|
||||
|
||||
/**
|
||||
* 批量新增角色菜单信息
|
||||
*
|
||||
* @param roleMenuList 角色菜单列表
|
||||
* @return 结果
|
||||
*/
|
||||
public int batchRoleMenu(List<SysRoleMenu> roleMenuList);
|
||||
// /**
|
||||
// * 批量新增角色菜单信息
|
||||
// *
|
||||
// * @param roleMenuList 角色菜单列表
|
||||
// * @return 结果
|
||||
// */
|
||||
// public int batchRoleMenu(List<SysRoleMenu> roleMenuList);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import java.util.List;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.ruoyi.system.domain.SysUser;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
@ -11,6 +12,7 @@ import org.apache.ibatis.annotations.Param;
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysUserMapper extends BaseMapper<SysUser>
|
||||
{
|
||||
/**
|
||||
|
@ -1,18 +1,22 @@
|
||||
package com.ruoyi.system.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import com.ruoyi.system.domain.SysUserPost;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 用户与岗位关联表 数据层
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface SysUserPostMapper
|
||||
@Mapper
|
||||
public interface SysUserPostMapper extends BaseMapper<SysUserPost>
|
||||
{
|
||||
/**
|
||||
* 通过用户ID删除用户和岗位关联
|
||||
*
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 结果
|
||||
*/
|
||||
@ -20,7 +24,7 @@ public interface SysUserPostMapper
|
||||
|
||||
/**
|
||||
* 通过岗位ID查询岗位使用数量
|
||||
*
|
||||
*
|
||||
* @param postId 岗位ID
|
||||
* @return 结果
|
||||
*/
|
||||
@ -28,7 +32,7 @@ public interface SysUserPostMapper
|
||||
|
||||
/**
|
||||
* 批量删除用户和岗位关联
|
||||
*
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
@ -36,7 +40,7 @@ public interface SysUserPostMapper
|
||||
|
||||
/**
|
||||
* 批量新增用户岗位信息
|
||||
*
|
||||
*
|
||||
* @param userPostList 用户角色列表
|
||||
* @return 结果
|
||||
*/
|
||||
|
@ -1,19 +1,23 @@
|
||||
package com.ruoyi.system.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.mybatisflex.core.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import com.ruoyi.system.domain.SysUserRole;
|
||||
|
||||
/**
|
||||
* 用户与角色关联表 数据层
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface SysUserRoleMapper
|
||||
@Mapper
|
||||
public interface SysUserRoleMapper extends BaseMapper<SysUserRole>
|
||||
{
|
||||
/**
|
||||
* 通过用户ID删除用户和角色关联
|
||||
*
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 结果
|
||||
*/
|
||||
@ -21,42 +25,42 @@ public interface SysUserRoleMapper
|
||||
|
||||
/**
|
||||
* 批量删除用户和角色关联
|
||||
*
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteUserRole(Long[] ids);
|
||||
|
||||
/**
|
||||
* 通过角色ID查询角色使用数量
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int countUserRoleByRoleId(Long roleId);
|
||||
// /**
|
||||
// * 通过角色ID查询角色使用数量
|
||||
// *
|
||||
// * @param roleId 角色ID
|
||||
// * @return 结果
|
||||
// */
|
||||
// public int countUserRoleByRoleId(Long roleId);
|
||||
|
||||
/**
|
||||
* 批量新增用户角色信息
|
||||
*
|
||||
* @param userRoleList 用户角色列表
|
||||
* @return 结果
|
||||
*/
|
||||
public int batchUserRole(List<SysUserRole> userRoleList);
|
||||
// /**
|
||||
// * 批量新增用户角色信息
|
||||
// *
|
||||
// * @param userRoleList 用户角色列表
|
||||
// * @return 结果
|
||||
// */
|
||||
// public int batchUserRole(List<SysUserRole> userRoleList);
|
||||
|
||||
/**
|
||||
* 删除用户和角色关联信息
|
||||
*
|
||||
* @param userRole 用户和角色关联信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteUserRoleInfo(SysUserRole userRole);
|
||||
// /**
|
||||
// * 删除用户和角色关联信息
|
||||
// *
|
||||
// * @param userRole 用户和角色关联信息
|
||||
// * @return 结果
|
||||
// */
|
||||
// public int deleteUserRoleInfo(SysUserRole userRole);
|
||||
|
||||
/**
|
||||
* 批量取消授权用户角色
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @param userIds 需要删除的用户数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteUserRoleInfos(@Param("roleId") Long roleId, @Param("userIds") Long[] userIds);
|
||||
// /**
|
||||
// * 批量取消授权用户角色
|
||||
// *
|
||||
// * @param roleId 角色ID
|
||||
// * @param userIds 需要删除的用户数据ID
|
||||
// * @return 结果
|
||||
// */
|
||||
// public int deleteUserRoleInfos(@Param("roleId") Long roleId, @Param("userIds") Long[] userIds);
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
package com.ruoyi.system.service;
|
||||
|
||||
import com.ruoyi.common.orm.core.service.IBaseService;
|
||||
import com.ruoyi.system.domain.SysRoleDept;
|
||||
|
||||
/**
|
||||
* SysRoleDept服务接口
|
||||
*
|
||||
* @author dataprince数据小王子
|
||||
*/
|
||||
public interface ISysRoleDeptService extends IBaseService<SysRoleDept> {
|
||||
|
||||
/**
|
||||
* 通过角色ID删除角色和部门关联
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 结果:true 删除成功,false 删除失败
|
||||
*/
|
||||
boolean deleteRoleDeptByRoleId(Long roleId);
|
||||
|
||||
/**
|
||||
* 批量删除角色部门关联信息
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果:true 删除成功,false 删除失败。
|
||||
*/
|
||||
boolean deleteRoleDept(Long[] ids);
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.ruoyi.system.service;
|
||||
|
||||
import com.ruoyi.common.orm.core.service.IBaseService;
|
||||
import com.ruoyi.system.domain.SysRoleMenu;
|
||||
|
||||
/**
|
||||
* ruoyi-flex
|
||||
*
|
||||
* @author dataprince数据小王子
|
||||
*/
|
||||
public interface ISysRoleMenuService extends IBaseService<SysRoleMenu> {
|
||||
|
||||
/**
|
||||
* 批量删除角色菜单关联信息
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return true 删除成功,false 删除失败。
|
||||
*/
|
||||
boolean deleteRoleMenu(Long[] ids);
|
||||
|
||||
}
|
@ -3,23 +3,37 @@ package com.ruoyi.system.service;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.ruoyi.common.orm.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.orm.core.service.IBaseService;
|
||||
import com.ruoyi.system.domain.SysRole;
|
||||
import com.ruoyi.system.domain.SysUserRole;
|
||||
import com.ruoyi.system.domain.bo.SysNoticeBo;
|
||||
import com.ruoyi.system.domain.bo.SysRoleBo;
|
||||
import com.ruoyi.system.domain.vo.SysNoticeVo;
|
||||
import com.ruoyi.system.domain.vo.SysRoleVo;
|
||||
|
||||
/**
|
||||
* 角色业务层
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface ISysRoleService
|
||||
public interface ISysRoleService extends IBaseService<SysRole>
|
||||
{
|
||||
/**
|
||||
* 分页查询角色列表
|
||||
*
|
||||
* @param roleBo 角色信息
|
||||
* @return 角色集合
|
||||
*/
|
||||
TableDataInfo<SysRoleVo> selectPage(SysRoleBo roleBo);
|
||||
|
||||
/**
|
||||
* 根据条件分页查询角色数据
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @param roleBo 角色信息
|
||||
* @return 角色数据集合信息
|
||||
*/
|
||||
List<SysRole> selectRoleList(SysRole role);
|
||||
List<SysRoleVo> selectRoleList(SysRoleBo roleBo);
|
||||
|
||||
/**
|
||||
* 根据用户ID查询角色列表
|
||||
@ -27,7 +41,7 @@ public interface ISysRoleService
|
||||
* @param userId 用户ID
|
||||
* @return 角色列表
|
||||
*/
|
||||
List<SysRole> selectRolesByUserId(Long userId);
|
||||
List<SysRoleVo> selectRolesByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 根据用户ID查询角色权限
|
||||
@ -42,7 +56,7 @@ public interface ISysRoleService
|
||||
*
|
||||
* @return 角色列表
|
||||
*/
|
||||
List<SysRole> selectRoleAll();
|
||||
List<SysRoleVo> selectRoleAll();
|
||||
|
||||
/**
|
||||
* 根据用户ID获取角色选择框列表
|
||||
@ -58,30 +72,30 @@ public interface ISysRoleService
|
||||
* @param roleId 角色ID
|
||||
* @return 角色对象信息
|
||||
*/
|
||||
SysRole selectRoleById(Long roleId);
|
||||
SysRoleVo selectRoleById(Long roleId);
|
||||
|
||||
/**
|
||||
* 校验角色名称是否唯一
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @param roleBo 角色信息
|
||||
* @return 结果
|
||||
*/
|
||||
boolean checkRoleNameUnique(SysRole role);
|
||||
boolean checkRoleNameUnique(SysRoleBo roleBo);
|
||||
|
||||
/**
|
||||
* 校验角色权限是否唯一
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @param roleBo 角色信息
|
||||
* @return 结果
|
||||
*/
|
||||
boolean checkRoleKeyUnique(SysRole role);
|
||||
boolean checkRoleKeyUnique(SysRoleBo roleBo);
|
||||
|
||||
/**
|
||||
* 校验角色是否允许操作
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @param roleBo 角色信息
|
||||
*/
|
||||
void checkRoleAllowed(SysRole role);
|
||||
void checkRoleAllowed(SysRoleBo roleBo);
|
||||
|
||||
/**
|
||||
* 校验角色是否有数据权限
|
||||
@ -90,53 +104,53 @@ public interface ISysRoleService
|
||||
*/
|
||||
void checkRoleDataScope(Long roleId);
|
||||
|
||||
/**
|
||||
* 通过角色ID查询角色使用数量
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 结果
|
||||
*/
|
||||
int countUserRoleByRoleId(Long roleId);
|
||||
// /**
|
||||
// * 通过角色ID查询角色使用数量
|
||||
// *
|
||||
// * @param roleId 角色ID
|
||||
// * @return 结果
|
||||
// */
|
||||
// int countUserRoleByRoleId(Long roleId);
|
||||
|
||||
/**
|
||||
* 新增保存角色信息
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 结果
|
||||
* @param roleBo 角色信息
|
||||
* @return 结果: true 保存成功,false 保存失败
|
||||
*/
|
||||
int insertRole(SysRole role);
|
||||
boolean insertRole(SysRoleBo roleBo);
|
||||
|
||||
/**
|
||||
* 修改保存角色信息
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 结果
|
||||
* @param roleBo 角色信息
|
||||
* @return true 操作成功,false 操作失败
|
||||
*/
|
||||
int updateRole(SysRole role);
|
||||
boolean updateRole(SysRoleBo roleBo);
|
||||
|
||||
/**
|
||||
* 修改角色状态
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @param roleBo 角色信息
|
||||
* @return 结果
|
||||
*/
|
||||
int updateRoleStatus(SysRole role);
|
||||
boolean updateRoleStatus(SysRoleBo roleBo) ;
|
||||
|
||||
/**
|
||||
* 修改数据权限信息
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 结果
|
||||
* @param roleBo 角色信息
|
||||
* @return 结果:true 成功,false 失败
|
||||
*/
|
||||
int authDataScope(SysRole role);
|
||||
boolean authDataScope(SysRoleBo roleBo);
|
||||
|
||||
/**
|
||||
* 通过角色ID删除角色
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteRoleById(Long roleId);
|
||||
// /**
|
||||
// * 通过角色ID删除角色
|
||||
// *
|
||||
// * @param roleId 角色ID
|
||||
// * @return 结果
|
||||
// */
|
||||
// int deleteRoleById(Long roleId);
|
||||
|
||||
/**
|
||||
* 批量删除角色信息
|
||||
@ -144,37 +158,19 @@ public interface ISysRoleService
|
||||
* @param roleIds 需要删除的角色ID
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteRoleByIds(Long[] roleIds);
|
||||
|
||||
/**
|
||||
* 取消授权用户角色
|
||||
*
|
||||
* @param userRole 用户和角色关联信息
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteAuthUser(SysUserRole userRole);
|
||||
|
||||
/**
|
||||
* 批量取消授权用户角色
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @param userIds 需要取消授权的用户数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
int deleteAuthUsers(Long roleId, Long[] userIds);
|
||||
|
||||
/**
|
||||
* 批量选择授权用户角色
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @param userIds 需要删除的用户数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
int insertAuthUsers(Long roleId, Long[] userIds);
|
||||
boolean deleteRoleByIds(Long[] roleIds);
|
||||
|
||||
/**
|
||||
* 注销该角色的在线用户
|
||||
* @param roleId
|
||||
*/
|
||||
void cleanOnlineUserByRole(Long roleId);
|
||||
|
||||
/**
|
||||
* 根据用户ID查询角色
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @return 角色列表
|
||||
*/
|
||||
List<SysRoleVo> selectRolesByUserName(String userName);
|
||||
}
|
||||
|
@ -0,0 +1,46 @@
|
||||
package com.ruoyi.system.service;
|
||||
|
||||
import com.ruoyi.common.orm.core.service.IBaseService;
|
||||
import com.ruoyi.system.domain.SysUserRole;
|
||||
|
||||
/**
|
||||
* SysUserRole服务接口
|
||||
*
|
||||
* @author dataprince数据小王子
|
||||
*/
|
||||
public interface ISysUserRoleService extends IBaseService<SysUserRole> {
|
||||
|
||||
/**
|
||||
* 通过角色ID查询角色使用数量
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 结果
|
||||
*/
|
||||
int countUserRoleByRoleId(Long roleId);
|
||||
|
||||
/**
|
||||
* 取消授权用户:删除用户和角色关联信息
|
||||
*
|
||||
* @param userRole 用户和角色关联信息
|
||||
* @return 结果:true 删除成功,false 删除失败
|
||||
*/
|
||||
boolean deleteUserRoleInfo(SysUserRole userRole);
|
||||
|
||||
/**
|
||||
* 批量取消授权用户角色
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @param userIds 需要删除的用户数据ID
|
||||
* @return 结果:true 删除成功,false 删除失败
|
||||
*/
|
||||
boolean deleteUserRoleInfos(Long roleId, Long[] userIds);
|
||||
|
||||
/**
|
||||
* 批量选择授权用户角色
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @param userIds 需要新增的用户数据ID
|
||||
* @return 结果:true 保存成功,false 保存失败
|
||||
*/
|
||||
boolean insertAuthUsers(Long roleId, Long[] userIds);
|
||||
}
|
@ -159,6 +159,7 @@ public class SysConfigServiceImpl extends BaseServiceImpl<SysConfigMapper, SysCo
|
||||
//return this.getMapper().insertSelective(sysConfig);
|
||||
//return configMapper.insertSelective(sysConfig);
|
||||
int ret=configMapper.insert(sysConfig,false);
|
||||
//boolean saved = this.save(sysConfig);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,8 @@ import com.ruoyi.common.security.utils.LoginHelper;
|
||||
import com.ruoyi.system.domain.*;
|
||||
import com.ruoyi.system.domain.bo.SysDeptBo;
|
||||
import com.ruoyi.system.domain.vo.SysDeptVo;
|
||||
import com.ruoyi.system.domain.vo.SysRoleVo;
|
||||
import com.ruoyi.system.service.ISysRoleService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
@ -51,9 +53,8 @@ import static com.ruoyi.system.domain.table.SysDeptTableDef.SYS_DEPT;
|
||||
public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptMapper, SysDept> implements ISysDeptService, DeptService {
|
||||
@Resource
|
||||
private SysDeptMapper deptMapper;
|
||||
|
||||
@Resource
|
||||
private SysRoleMapper roleMapper;
|
||||
private ISysRoleService sysRoleService;
|
||||
|
||||
@Override
|
||||
public QueryWrapper query() {
|
||||
@ -141,8 +142,8 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptMapper, SysDept>
|
||||
*/
|
||||
@Override
|
||||
public List<Long> selectDeptListByRoleId(Long roleId) {
|
||||
SysRole role = roleMapper.selectRoleById(roleId);
|
||||
return deptMapper.selectDeptListByRoleId(roleId, role.isDeptCheckStrictly());
|
||||
SysRoleVo role = sysRoleService.selectRoleById(roleId);
|
||||
return deptMapper.selectDeptListByRoleId(roleId, role.getDeptCheckStrictly());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -167,7 +168,6 @@ public class SysDeptServiceImpl extends BaseServiceImpl<SysDeptMapper, SysDept>
|
||||
*/
|
||||
@Override
|
||||
public int selectNormalChildrenDeptById(Long deptId) {
|
||||
// return deptMapper.selectNormalChildrenDeptById(deptId);
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.select(QueryMethods.count(SYS_DEPT.DEPT_ID))
|
||||
.from(SYS_DEPT)
|
||||
|
@ -18,6 +18,8 @@ import com.ruoyi.common.security.utils.LoginHelper;
|
||||
import com.ruoyi.system.domain.*;
|
||||
import com.ruoyi.system.domain.bo.SysMenuBo;
|
||||
import com.ruoyi.system.domain.vo.SysMenuVo;
|
||||
import com.ruoyi.system.domain.vo.SysRoleVo;
|
||||
import com.ruoyi.system.service.ISysRoleService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.common.core.constant.Constants;
|
||||
@ -43,7 +45,7 @@ public class SysMenuServiceImpl extends BaseServiceImpl<SysMenuMapper,SysMenu> i
|
||||
private SysMenuMapper menuMapper;
|
||||
|
||||
@Resource
|
||||
private SysRoleMapper roleMapper;
|
||||
private ISysRoleService sysRoleService;
|
||||
|
||||
@Resource
|
||||
private SysRoleMenuMapper roleMenuMapper;
|
||||
@ -170,8 +172,8 @@ public class SysMenuServiceImpl extends BaseServiceImpl<SysMenuMapper,SysMenu> i
|
||||
*/
|
||||
@Override
|
||||
public List<Long> selectMenuListByRoleId(Long roleId) {
|
||||
SysRole role = roleMapper.selectRoleById(roleId);
|
||||
return menuMapper.selectMenuListByRoleId(roleId, role.isMenuCheckStrictly());
|
||||
SysRoleVo role = sysRoleService.selectRoleById(roleId);
|
||||
return menuMapper.selectMenuListByRoleId(roleId, role.getMenuCheckStrictly());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,50 @@
|
||||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
|
||||
import com.ruoyi.system.domain.SysRoleDept;
|
||||
import com.ruoyi.system.mapper.SysRoleDeptMapper;
|
||||
import com.ruoyi.system.service.ISysRoleDeptService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static com.ruoyi.system.domain.table.SysRoleDeptTableDef.SYS_ROLE_DEPT;
|
||||
|
||||
/**
|
||||
* SysRoleDept服务实现
|
||||
*
|
||||
* @author dataprince数据小王子
|
||||
*/
|
||||
@Service
|
||||
public class SysRoleDeptServiceImpl extends BaseServiceImpl<SysRoleDeptMapper, SysRoleDept> implements ISysRoleDeptService {
|
||||
|
||||
@Override
|
||||
public QueryWrapper query() {
|
||||
return super.query().from(SYS_ROLE_DEPT);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过角色ID删除角色和部门关联
|
||||
* delete from sys_role_dept where role_id=#{roleId}
|
||||
* @param roleId 角色ID
|
||||
* @return 结果:true 删除成功,false 删除失败
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteRoleDeptByRoleId(Long roleId) {
|
||||
QueryWrapper queryWrapper = query().where(SYS_ROLE_DEPT.ROLE_ID.eq(roleId));
|
||||
return this.remove(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除角色部门关联信息
|
||||
* delete from sys_role_dept where role_id in
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果:true 删除成功,false 删除失败。
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteRoleDept(Long[] ids) {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create().from(SYS_ROLE_DEPT).where(SYS_ROLE_DEPT.ROLE_ID.in(Arrays.asList(ids)));
|
||||
return this.remove(queryWrapper);
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
|
||||
import com.ruoyi.system.domain.SysRoleMenu;
|
||||
import com.ruoyi.system.mapper.SysRoleMenuMapper;
|
||||
import com.ruoyi.system.service.ISysRoleMenuService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static com.ruoyi.system.domain.table.SysRoleMenuTableDef.SYS_ROLE_MENU;
|
||||
|
||||
/**
|
||||
* SysRoleMenu服务实现类
|
||||
*
|
||||
* @author dataprince数据小王子
|
||||
*/
|
||||
@Service
|
||||
public class SysRoleMenuServiceImpl extends BaseServiceImpl<SysRoleMenuMapper, SysRoleMenu> implements ISysRoleMenuService {
|
||||
|
||||
/**
|
||||
* 批量删除角色菜单关联信息
|
||||
* delete from sys_role_menu where role_id in
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return true 删除成功,false 删除失败。
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteRoleMenu(Long[] ids) {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create().from(SYS_ROLE_MENU).where(SYS_ROLE_MENU.ROLE_ID.in(Arrays.asList(ids)));
|
||||
return this.remove(queryWrapper);
|
||||
}
|
||||
}
|
@ -1,18 +1,30 @@
|
||||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
import cn.dev33.satoken.exception.NotLoginException;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryMethods;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.core.update.UpdateChain;
|
||||
import com.ruoyi.common.core.constant.TenantConstants;
|
||||
import com.ruoyi.common.core.core.domain.dto.RoleDTO;
|
||||
import com.ruoyi.common.core.core.domain.model.LoginUser;
|
||||
import com.ruoyi.common.core.utils.MapstructUtils;
|
||||
import com.ruoyi.common.orm.core.page.PageQuery;
|
||||
import com.ruoyi.common.orm.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
|
||||
import com.ruoyi.common.security.utils.LoginHelper;
|
||||
import com.ruoyi.system.domain.*;
|
||||
import com.ruoyi.system.domain.bo.SysRoleBo;
|
||||
import com.ruoyi.system.domain.vo.SysRoleVo;
|
||||
import com.ruoyi.system.mapper.*;
|
||||
import com.ruoyi.system.service.ISysRoleDeptService;
|
||||
import com.ruoyi.system.service.ISysRoleMenuService;
|
||||
import com.ruoyi.system.service.ISysUserRoleService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@ -21,41 +33,103 @@ import com.ruoyi.common.core.constant.UserConstants;
|
||||
import com.ruoyi.common.core.exception.ServiceException;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.core.utils.SpringUtils;
|
||||
import com.ruoyi.system.mapper.SysRoleDeptMapper;
|
||||
import com.ruoyi.system.mapper.SysRoleMapper;
|
||||
import com.ruoyi.system.mapper.SysRoleMenuMapper;
|
||||
import com.ruoyi.system.mapper.SysUserRoleMapper;
|
||||
import com.ruoyi.system.service.ISysRoleService;
|
||||
|
||||
import static com.ruoyi.system.domain.table.SysDeptTableDef.SYS_DEPT;
|
||||
import static com.ruoyi.system.domain.table.SysRoleMenuTableDef.SYS_ROLE_MENU;
|
||||
import static com.ruoyi.system.domain.table.SysRoleTableDef.SYS_ROLE;
|
||||
import static com.ruoyi.system.domain.table.SysUserRoleTableDef.SYS_USER_ROLE;
|
||||
import static com.ruoyi.system.domain.table.SysUserTableDef.SYS_USER;
|
||||
|
||||
/**
|
||||
* 角色 业务层处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Service
|
||||
public class SysRoleServiceImpl implements ISysRoleService {
|
||||
public class SysRoleServiceImpl extends BaseServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService {
|
||||
@Resource
|
||||
private SysRoleMapper roleMapper;
|
||||
|
||||
@Resource
|
||||
private SysRoleMenuMapper roleMenuMapper;
|
||||
|
||||
private ISysRoleMenuService roleMenuService;
|
||||
@Resource
|
||||
private SysUserRoleMapper userRoleMapper;
|
||||
|
||||
private ISysRoleDeptService roleDeptService;
|
||||
@Resource
|
||||
private SysRoleDeptMapper roleDeptMapper;
|
||||
private ISysUserRoleService userRoleService;
|
||||
|
||||
|
||||
@Override
|
||||
public QueryWrapper query() {
|
||||
return super.query().from(SYS_ROLE);
|
||||
}
|
||||
|
||||
private QueryWrapper buildQueryWrapper(SysRoleBo roleBo) {
|
||||
/* select distinct r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.menu_check_strictly, r.dept_check_strictly,
|
||||
r.status, r.del_flag, r.create_time, r.remark
|
||||
from sys_role r
|
||||
left join sys_user_role ur on ur.role_id = r.role_id
|
||||
left join sys_user u on u.user_id = ur.user_id
|
||||
left join sys_dept d on u.dept_id = d.dept_id*/
|
||||
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.select(QueryMethods.distinct(SYS_ROLE.ALL_COLUMNS))
|
||||
.from(SYS_ROLE.as("r"))
|
||||
.leftJoin(SYS_USER_ROLE).as("ur").on(SYS_USER_ROLE.ROLE_ID.eq(SYS_ROLE.ROLE_ID))
|
||||
.leftJoin(SYS_USER).as("u").on(SYS_USER.USER_ID.eq(SYS_USER_ROLE.USER_ID))
|
||||
.leftJoin(SYS_DEPT).as("d").on(SYS_DEPT.DEPT_ID.eq(SYS_USER.DEPT_ID));
|
||||
|
||||
queryWrapper.where(SYS_ROLE.DEL_FLAG.eq("0"));
|
||||
if (ObjectUtil.isNotNull(roleBo.getRoleId())) {
|
||||
queryWrapper.and(SYS_ROLE.ROLE_ID.eq(roleBo.getRoleId()));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(roleBo.getRoleName())) {
|
||||
queryWrapper.and(SYS_ROLE.ROLE_NAME.like(roleBo.getRoleName()));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(roleBo.getStatus())) {
|
||||
queryWrapper.and(SYS_ROLE.STATUS.eq(roleBo.getStatus()));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(roleBo.getRoleKey())) {
|
||||
queryWrapper.and(SYS_ROLE.ROLE_KEY.like(roleBo.getRoleKey()));
|
||||
}
|
||||
Map<String, Object> params = roleBo.getParams();
|
||||
if (params.get("beginTime") != null && params.get("endTime") != null) {
|
||||
queryWrapper.and(SYS_ROLE.CREATE_TIME.between(params.get("beginTime"), params.get("endTime")));
|
||||
}
|
||||
|
||||
//TODO:添加 数据权限 过滤条件
|
||||
|
||||
queryWrapper.orderBy(SYS_ROLE.ROLE_SORT.asc());
|
||||
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据条件分页查询角色数据
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @param roleBo 角色信息
|
||||
* @return 角色数据集合信息
|
||||
*/
|
||||
@Override
|
||||
@DataScope(deptAlias = "d")
|
||||
public List<SysRole> selectRoleList(SysRole role) {
|
||||
return roleMapper.selectRoleList(role);
|
||||
//@DataScope(deptAlias = "d")
|
||||
public List<SysRoleVo> selectRoleList(SysRoleBo roleBo) {
|
||||
//return roleMapper.selectRoleList(roleBo);
|
||||
|
||||
QueryWrapper queryWrapper = buildQueryWrapper(roleBo);
|
||||
//List<SysRoleVo> list = roleMapper.selectListByQueryAs(queryWrapper, SysRoleVo.class);
|
||||
return this.listAs(queryWrapper, SysRoleVo.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询角色列表
|
||||
*
|
||||
* @param roleBo 角色信息
|
||||
* @return 角色集合
|
||||
*/
|
||||
@Override
|
||||
public TableDataInfo<SysRoleVo> selectPage(SysRoleBo roleBo) {
|
||||
QueryWrapper queryWrapper = buildQueryWrapper(roleBo);
|
||||
Page<SysRoleVo> page = this.pageAs(PageQuery.build(), queryWrapper, SysRoleVo.class);
|
||||
return TableDataInfo.build(page);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,11 +139,27 @@ public class SysRoleServiceImpl implements ISysRoleService {
|
||||
* @return 角色列表
|
||||
*/
|
||||
@Override
|
||||
public List<SysRole> selectRolesByUserId(Long userId) {
|
||||
List<SysRole> userRoles = roleMapper.selectRolePermissionByUserId(userId);
|
||||
List<SysRole> roles = selectRoleAll();
|
||||
for (SysRole role : roles) {
|
||||
for (SysRole userRole : userRoles) {
|
||||
public List<SysRoleVo> selectRolesByUserId(Long userId) {
|
||||
/*select distinct r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.menu_check_strictly, r.dept_check_strictly,
|
||||
r.status, r.del_flag, r.create_time, r.remark
|
||||
from sys_role r
|
||||
left join sys_user_role ur on ur.role_id = r.role_id
|
||||
left join sys_user u on u.user_id = ur.user_id
|
||||
where r.del_flag = '0' and ur.user_id = #{userId}*/
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.select(QueryMethods.distinct(SYS_ROLE.ALL_COLUMNS))
|
||||
.from(SYS_ROLE.as("r"))
|
||||
.leftJoin(SYS_USER_ROLE).as("ur").on(SYS_USER_ROLE.ROLE_ID.eq(SYS_ROLE.ROLE_ID))
|
||||
.leftJoin(SYS_USER).as("u").on(SYS_USER.USER_ID.eq(SYS_USER_ROLE.USER_ID))
|
||||
.leftJoin(SYS_DEPT).as("d").on(SYS_DEPT.DEPT_ID.eq(SYS_USER.DEPT_ID));
|
||||
queryWrapper.where(SYS_ROLE.DEL_FLAG.eq("0"))
|
||||
.and(SYS_USER_ROLE.USER_ID.eq(userId));
|
||||
|
||||
//List<SysRole> userRoles = roleMapper.selectRolePermissionByUserId(userId);
|
||||
List<SysRoleVo> userRoles = this.listAs(queryWrapper, SysRoleVo.class);
|
||||
List<SysRoleVo> roles = selectRoleAll();
|
||||
for (SysRoleVo role : roles) {
|
||||
for (SysRoleVo userRole : userRoles) {
|
||||
if (role.getRoleId().longValue() == userRole.getRoleId().longValue()) {
|
||||
role.setFlag(true);
|
||||
break;
|
||||
@ -87,9 +177,18 @@ public class SysRoleServiceImpl implements ISysRoleService {
|
||||
*/
|
||||
@Override
|
||||
public Set<String> selectRolePermissionByUserId(Long userId) {
|
||||
List<SysRole> perms = roleMapper.selectRolePermissionByUserId(userId);
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.select(QueryMethods.distinct(SYS_ROLE.ALL_COLUMNS))
|
||||
.from(SYS_ROLE.as("r"))
|
||||
.leftJoin(SYS_USER_ROLE).as("ur").on(SYS_USER_ROLE.ROLE_ID.eq(SYS_ROLE.ROLE_ID))
|
||||
.leftJoin(SYS_USER).as("u").on(SYS_USER.USER_ID.eq(SYS_USER_ROLE.USER_ID))
|
||||
.leftJoin(SYS_DEPT).as("d").on(SYS_DEPT.DEPT_ID.eq(SYS_USER.DEPT_ID));
|
||||
queryWrapper.where(SYS_ROLE.DEL_FLAG.eq("0"))
|
||||
.and(SYS_USER_ROLE.USER_ID.eq(userId));
|
||||
List<SysRoleVo> perms = this.listAs(queryWrapper, SysRoleVo.class);
|
||||
//List<SysRole> perms = roleMapper.selectRolePermissionByUserId(userId);
|
||||
Set<String> permsSet = new HashSet<>();
|
||||
for (SysRole perm : perms) {
|
||||
for (SysRoleVo perm : perms) {
|
||||
if (StringUtils.isNotNull(perm)) {
|
||||
permsSet.addAll(Arrays.asList(perm.getRoleKey().trim().split(",")));
|
||||
}
|
||||
@ -103,8 +202,8 @@ public class SysRoleServiceImpl implements ISysRoleService {
|
||||
* @return 角色列表
|
||||
*/
|
||||
@Override
|
||||
public List<SysRole> selectRoleAll() {
|
||||
return SpringUtils.getAopProxy(this).selectRoleList(new SysRole());
|
||||
public List<SysRoleVo> selectRoleAll() {
|
||||
return SpringUtils.getAopProxy(this).selectRoleList(new SysRoleBo());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -115,7 +214,19 @@ public class SysRoleServiceImpl implements ISysRoleService {
|
||||
*/
|
||||
@Override
|
||||
public List<Long> selectRoleListByUserId(Long userId) {
|
||||
return roleMapper.selectRoleListByUserId(userId);
|
||||
//return roleMapper.selectRoleListByUserId(userId);
|
||||
/*select r.role_id
|
||||
from sys_role r
|
||||
left join sys_user_role ur on ur.role_id = r.role_id
|
||||
left join sys_user u on u.user_id = ur.user_id
|
||||
where u.user_id = #{userId}*/
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.select(SYS_ROLE.ROLE_ID)
|
||||
.from(SYS_ROLE.as("r"))
|
||||
.leftJoin(SYS_USER_ROLE).as("ur").on(SYS_USER_ROLE.ROLE_ID.eq(SYS_ROLE.ROLE_ID))
|
||||
.leftJoin(SYS_USER).as("u").on(SYS_USER.USER_ID.eq(SYS_USER_ROLE.USER_ID))
|
||||
.where(SYS_USER.USER_ID.eq(userId));
|
||||
return roleMapper.selectObjectListByQueryAs(queryWrapper, Long.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -125,21 +236,23 @@ public class SysRoleServiceImpl implements ISysRoleService {
|
||||
* @return 角色对象信息
|
||||
*/
|
||||
@Override
|
||||
public SysRole selectRoleById(Long roleId) {
|
||||
return roleMapper.selectRoleById(roleId);
|
||||
public SysRoleVo selectRoleById(Long roleId) {
|
||||
return this.getOneAs(query().where(SYS_ROLE.ROLE_ID.eq(roleId)), SysRoleVo.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验角色名称是否唯一
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @param roleBo 角色信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public boolean checkRoleNameUnique(SysRole role) {
|
||||
Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId();
|
||||
SysRole info = roleMapper.checkRoleNameUnique(role.getRoleName());
|
||||
if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) {
|
||||
public boolean checkRoleNameUnique(SysRoleBo roleBo) {
|
||||
Long roleId = ObjectUtil.isNull(roleBo.getRoleId()) ? -1L : roleBo.getRoleId();
|
||||
QueryWrapper queryWrapper = query().where(SYS_ROLE.ROLE_NAME.eq(roleBo.getRoleName()))
|
||||
.and(SYS_ROLE.DEL_FLAG.eq("0"));
|
||||
SysRole info = this.getOne(queryWrapper);
|
||||
if (ObjectUtil.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) {
|
||||
return UserConstants.NOT_UNIQUE;
|
||||
}
|
||||
return UserConstants.UNIQUE;
|
||||
@ -148,14 +261,16 @@ public class SysRoleServiceImpl implements ISysRoleService {
|
||||
/**
|
||||
* 校验角色权限是否唯一
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @param roleBo 角色信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public boolean checkRoleKeyUnique(SysRole role) {
|
||||
Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId();
|
||||
SysRole info = roleMapper.checkRoleKeyUnique(role.getRoleKey());
|
||||
if (StringUtils.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) {
|
||||
public boolean checkRoleKeyUnique(SysRoleBo roleBo) {
|
||||
Long roleId = ObjectUtil.isNull(roleBo.getRoleId()) ? -1L : roleBo.getRoleId();
|
||||
QueryWrapper queryWrapper = query().where(SYS_ROLE.ROLE_KEY.eq(roleBo.getRoleKey()))
|
||||
.and(SYS_ROLE.DEL_FLAG.eq("0"));
|
||||
SysRole info = this.getOne(queryWrapper);
|
||||
if (ObjectUtil.isNotNull(info) && info.getRoleId().longValue() != roleId.longValue()) {
|
||||
return UserConstants.NOT_UNIQUE;
|
||||
}
|
||||
return UserConstants.UNIQUE;
|
||||
@ -164,13 +279,29 @@ public class SysRoleServiceImpl implements ISysRoleService {
|
||||
/**
|
||||
* 校验角色是否允许操作
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @param roleBo 角色信息
|
||||
*/
|
||||
@Override
|
||||
public void checkRoleAllowed(SysRole role) {
|
||||
if (StringUtils.isNotNull(role.getRoleId()) && role.isAdmin()) {
|
||||
public void checkRoleAllowed(SysRoleBo roleBo) {
|
||||
if (ObjectUtil.isNotNull(roleBo.getRoleId()) && LoginHelper.isSuperAdmin(roleBo.getRoleId())) {
|
||||
throw new ServiceException("不允许操作超级管理员角色");
|
||||
}
|
||||
// 新增:不允许使用 管理员标识符
|
||||
if (ObjectUtil.isNull(roleBo.getRoleId())
|
||||
&& StringUtils.equalsAny(roleBo.getRoleKey(),
|
||||
TenantConstants.SUPER_ADMIN_ROLE_KEY, TenantConstants.TENANT_ADMIN_ROLE_KEY)) {
|
||||
throw new ServiceException("不允许使用系统内置管理员角色标识符!");
|
||||
}
|
||||
// 修改:不允许修改 管理员标识符
|
||||
if (ObjectUtil.isNotNull(roleBo.getRoleId())) {
|
||||
SysRole sysRole = this.getById(roleBo.getRoleId());
|
||||
// 如果标识符不相等 判断为修改了管理员标识符
|
||||
if (!StringUtils.equals(sysRole.getRoleKey(), roleBo.getRoleKey())
|
||||
&& StringUtils.equalsAny(sysRole.getRoleKey(),
|
||||
TenantConstants.SUPER_ADMIN_ROLE_KEY, TenantConstants.TENANT_ADMIN_ROLE_KEY)) {
|
||||
throw new ServiceException("不允许修改系统内置管理员角色标识符!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -186,95 +317,106 @@ public class SysRoleServiceImpl implements ISysRoleService {
|
||||
if (LoginHelper.isSuperAdmin()) {
|
||||
return;
|
||||
}
|
||||
SysRole role = new SysRole();
|
||||
SysRoleBo role = new SysRoleBo();
|
||||
role.setRoleId(roleId);
|
||||
List<SysRole> roles = SpringUtils.getAopProxy(this).selectRoleList(role);
|
||||
if (StringUtils.isEmpty(roles)) {
|
||||
List<SysRoleVo> roles = SpringUtils.getAopProxy(this).selectRoleList(role);
|
||||
if (CollUtil.isEmpty(roles)) {
|
||||
throw new ServiceException("没有权限访问角色数据!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过角色ID查询角色使用数量
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int countUserRoleByRoleId(Long roleId) {
|
||||
return userRoleMapper.countUserRoleByRoleId(roleId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增保存角色信息
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 结果
|
||||
* @param roleBo 角色信息
|
||||
* @return true 操作成功,false 操作失败
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int insertRole(SysRole role) {
|
||||
public boolean insertRole(SysRoleBo roleBo) {
|
||||
SysRole role = MapstructUtils.convert(roleBo, SysRole.class);
|
||||
role.setDelFlag("0");
|
||||
role.setDataScope("1");//默认1:全部数据权限
|
||||
// 新增角色信息
|
||||
roleMapper.insertRole(role);
|
||||
return insertRoleMenu(role);
|
||||
boolean inserted = this.save(role);//使用全局配置的雪花算法主键生成器生成ID值
|
||||
if (inserted) {
|
||||
return insertRoleMenu(role);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改保存角色信息
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 结果
|
||||
* @param roleBo 角色信息
|
||||
* @return true 操作成功,false 操作失败
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int updateRole(SysRole role) {
|
||||
public boolean updateRole(SysRoleBo roleBo) {
|
||||
SysRole role = MapstructUtils.convert(roleBo, SysRole.class);
|
||||
// 修改角色信息
|
||||
roleMapper.updateRole(role);
|
||||
boolean updated = this.updateById(role);
|
||||
// 删除角色与菜单关联
|
||||
roleMenuMapper.deleteRoleMenuByRoleId(role.getRoleId());
|
||||
return insertRoleMenu(role);
|
||||
if (updated) {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create().from(SYS_ROLE_MENU).where(SYS_ROLE_MENU.ROLE_ID.eq(role.getRoleId()));
|
||||
roleMenuService.remove(queryWrapper);//TODO:这两行封装到 roleMenuService一个方法中
|
||||
|
||||
return insertRoleMenu(role);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改角色状态
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 结果
|
||||
* @param roleBo 角色信息
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public int updateRoleStatus(SysRole role) {
|
||||
Long roleId = role.getRoleId();
|
||||
String status = role.getStatus();
|
||||
if (UserConstants.ROLE_DISABLE.equals(status) && this.countUserRoleByRoleId(roleId) > 0) {
|
||||
public boolean updateRoleStatus(SysRoleBo roleBo) {
|
||||
Long roleId = roleBo.getRoleId();
|
||||
String status = roleBo.getStatus();
|
||||
if (UserConstants.ROLE_DISABLE.equals(status) && userRoleService.countUserRoleByRoleId(roleId) > 0) {
|
||||
throw new ServiceException("角色已分配,不能禁用!");
|
||||
}
|
||||
return roleMapper.updateRole(role);
|
||||
|
||||
return UpdateChain.of(SysRole.class)
|
||||
.set(SysRole::getStatus, status)
|
||||
.where(SysRole::getRoleId).eq(roleId)
|
||||
.update();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改数据权限信息
|
||||
*
|
||||
* @param role 角色信息
|
||||
* @return 结果
|
||||
* @param roleBo 角色信息
|
||||
* @return 结果:true 成功,false 失败
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int authDataScope(SysRole role) {
|
||||
public boolean authDataScope(SysRoleBo roleBo) {
|
||||
// 修改角色信息
|
||||
roleMapper.updateRole(role);
|
||||
SysRole role = MapstructUtils.convert(roleBo, SysRole.class);
|
||||
// 修改角色信息
|
||||
boolean updated = this.updateById(role);
|
||||
// 删除角色与部门关联
|
||||
roleDeptMapper.deleteRoleDeptByRoleId(role.getRoleId());
|
||||
// 新增角色和部门信息(数据权限)
|
||||
return insertRoleDept(role);
|
||||
roleDeptService.deleteRoleDeptByRoleId(role.getRoleId());
|
||||
// 新增角色和部门 信息(数据权限)
|
||||
insertRoleDept(role);
|
||||
|
||||
return updated;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增角色菜单信息
|
||||
*
|
||||
* @param role 角色对象
|
||||
* @return true 保存成功,false 保存失败
|
||||
*/
|
||||
public int insertRoleMenu(SysRole role) {
|
||||
int rows = 1;
|
||||
public boolean insertRoleMenu(SysRole role) {
|
||||
boolean inserted = true;
|
||||
int insertedRows = 0;
|
||||
// 新增用户与角色管理
|
||||
List<SysRoleMenu> list = new ArrayList<>();
|
||||
for (Long menuId : role.getMenuIds()) {
|
||||
@ -284,9 +426,9 @@ public class SysRoleServiceImpl implements ISysRoleService {
|
||||
list.add(rm);
|
||||
}
|
||||
if (list.size() > 0) {
|
||||
rows = roleMenuMapper.batchRoleMenu(list);
|
||||
inserted = roleMenuService.saveBatchWithPk(list, 100);//批量保存
|
||||
}
|
||||
return rows;
|
||||
return inserted;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -294,8 +436,8 @@ public class SysRoleServiceImpl implements ISysRoleService {
|
||||
*
|
||||
* @param role 角色对象
|
||||
*/
|
||||
public int insertRoleDept(SysRole role) {
|
||||
int rows = 1;
|
||||
public boolean insertRoleDept(SysRole role) {
|
||||
boolean inserted = true;
|
||||
// 新增角色与部门(数据权限)管理
|
||||
List<SysRoleDept> list = new ArrayList<>();
|
||||
for (Long deptId : role.getDeptIds()) {
|
||||
@ -305,25 +447,9 @@ public class SysRoleServiceImpl implements ISysRoleService {
|
||||
list.add(rd);
|
||||
}
|
||||
if (list.size() > 0) {
|
||||
rows = roleDeptMapper.batchRoleDept(list);
|
||||
inserted = roleDeptService.saveBatchWithPk(list, 100);//批量保存
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过角色ID删除角色
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int deleteRoleById(Long roleId) {
|
||||
// 删除角色与菜单关联
|
||||
roleMenuMapper.deleteRoleMenuByRoleId(roleId);
|
||||
// 删除角色与部门关联
|
||||
roleDeptMapper.deleteRoleDeptByRoleId(roleId);
|
||||
return roleMapper.deleteRoleById(roleId);
|
||||
return inserted;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -334,73 +460,36 @@ public class SysRoleServiceImpl implements ISysRoleService {
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int deleteRoleByIds(Long[] roleIds) {
|
||||
public boolean deleteRoleByIds(Long[] roleIds) {
|
||||
for (Long roleId : roleIds) {
|
||||
checkRoleAllowed(new SysRole(roleId));
|
||||
checkRoleAllowed(new SysRoleBo(roleId));
|
||||
checkRoleDataScope(roleId);
|
||||
SysRole role = selectRoleById(roleId);
|
||||
if (countUserRoleByRoleId(roleId) > 0) {
|
||||
SysRoleVo role = selectRoleById(roleId);
|
||||
if (userRoleService.countUserRoleByRoleId(roleId) > 0) {
|
||||
throw new ServiceException(String.format("%1$s已分配,不能删除!", role.getRoleName()));
|
||||
}
|
||||
}
|
||||
// 删除角色与菜单关联
|
||||
roleMenuMapper.deleteRoleMenu(roleIds);
|
||||
roleMenuService.deleteRoleMenu(roleIds);
|
||||
// 删除角色与部门关联
|
||||
roleDeptMapper.deleteRoleDept(roleIds);
|
||||
return roleMapper.deleteRoleByIds(roleIds);
|
||||
}
|
||||
roleDeptService.deleteRoleDept(roleIds);
|
||||
|
||||
/**
|
||||
* 取消授权用户角色
|
||||
*
|
||||
* @param userRole 用户和角色关联信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteAuthUser(SysUserRole userRole) {
|
||||
return userRoleMapper.deleteUserRoleInfo(userRole);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量取消授权用户角色
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @param userIds 需要取消授权的用户数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteAuthUsers(Long roleId, Long[] userIds) {
|
||||
return userRoleMapper.deleteUserRoleInfos(roleId, userIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量选择授权用户角色
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @param userIds 需要授权的用户数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertAuthUsers(Long roleId, Long[] userIds) {
|
||||
// 新增用户与角色管理
|
||||
List<SysUserRole> list = new ArrayList<>();
|
||||
for (Long userId : userIds) {
|
||||
SysUserRole ur = new SysUserRole();
|
||||
ur.setUserId(userId);
|
||||
ur.setRoleId(roleId);
|
||||
list.add(ur);
|
||||
}
|
||||
return userRoleMapper.batchUserRole(list);
|
||||
//逻辑删除:update sys_role set del_flag = '1' where role_id in
|
||||
return UpdateChain.of(SysRole.class)
|
||||
.set(SysRole::getDelFlag, "1")
|
||||
.where(SysRole::getRoleId).in(Arrays.asList(roleIds))
|
||||
.update();
|
||||
}
|
||||
|
||||
/**
|
||||
* 注销该角色的在线用户
|
||||
* @param roleId
|
||||
*
|
||||
* @param roleId 主键
|
||||
*/
|
||||
@Override
|
||||
public void cleanOnlineUserByRole(Long roleId) {
|
||||
// 如果角色未绑定用户 直接返回
|
||||
int num = userRoleMapper.countUserRoleByRoleId(roleId);
|
||||
int num = userRoleService.countUserRoleByRoleId(roleId);
|
||||
if (num == 0) {
|
||||
return;
|
||||
}
|
||||
@ -416,12 +505,42 @@ public class SysRoleServiceImpl implements ISysRoleService {
|
||||
return;
|
||||
}
|
||||
LoginUser loginUser = LoginHelper.getLoginUser(token);
|
||||
if (loginUser.getRoles().stream().anyMatch(r -> r.getRoleId().equals(roleId))) {
|
||||
try {
|
||||
StpUtil.logoutByTokenValue(token);
|
||||
} catch (NotLoginException ignored) {
|
||||
for (RoleDTO roleDTO : loginUser.getRoles()) {
|
||||
if (ObjectUtil.isNotNull(roleDTO.getRoleId()) && roleDTO.getRoleId().equals(roleId)) {
|
||||
try {
|
||||
StpUtil.logoutByTokenValue(token);
|
||||
break;
|
||||
} catch (NotLoginException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID查询角色
|
||||
*
|
||||
* @param userName 用户名
|
||||
* @return 角色列表
|
||||
*/
|
||||
@Override
|
||||
public List<SysRoleVo> selectRolesByUserName(String userName) {
|
||||
/* select distinct r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.menu_check_strictly, r.dept_check_strictly,
|
||||
r.status, r.del_flag, r.create_time, r.remark
|
||||
from sys_role r
|
||||
left join sys_user_role ur on ur.role_id = r.role_id
|
||||
left join sys_user u on u.user_id = ur.user_id
|
||||
left join sys_dept d on u.dept_id = d.dept_id
|
||||
WHERE r.del_flag = '0' and u.user_name = #{userName} */
|
||||
//List<SysRole> list = roleMapper.selectRolesByUserName(userName);
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.select(QueryMethods.distinct(SYS_ROLE.ALL_COLUMNS))
|
||||
.from(SYS_ROLE.as("r"))
|
||||
.leftJoin(SYS_USER_ROLE).as("ur").on(SYS_USER_ROLE.ROLE_ID.eq(SYS_ROLE.ROLE_ID))
|
||||
.leftJoin(SYS_USER).as("u").on(SYS_USER.USER_ID.eq(SYS_USER_ROLE.USER_ID))
|
||||
.leftJoin(SYS_DEPT).as("d").on(SYS_DEPT.DEPT_ID.eq(SYS_USER.DEPT_ID))
|
||||
.where(SYS_ROLE.DEL_FLAG.eq("0"))
|
||||
.and(SYS_USER.USER_NAME.eq(userName));
|
||||
return this.listAs(queryWrapper, SysRoleVo.class);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,91 @@
|
||||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import com.mybatisflex.core.query.QueryMethods;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
|
||||
import com.ruoyi.system.domain.SysUserRole;
|
||||
import com.ruoyi.system.mapper.SysUserRoleMapper;
|
||||
import com.ruoyi.system.service.ISysUserRoleService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static com.ruoyi.system.domain.table.SysUserRoleTableDef.SYS_USER_ROLE;
|
||||
|
||||
/**
|
||||
* SysUserRoleService实现类
|
||||
*
|
||||
* @author dataprince数据小王子
|
||||
*/
|
||||
@Service
|
||||
public class SysUserRoleServiceImpl extends BaseServiceImpl<SysUserRoleMapper, SysUserRole> implements ISysUserRoleService {
|
||||
|
||||
@Resource
|
||||
private SysUserRoleMapper userRoleMapper;
|
||||
|
||||
/**
|
||||
* 通过角色ID查询角色使用数量
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int countUserRoleByRoleId(Long roleId) {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.select(QueryMethods.count(SYS_USER_ROLE.ROLE_ID))
|
||||
.from(SYS_USER_ROLE)
|
||||
.where(SYS_USER_ROLE.ROLE_ID.eq(roleId));
|
||||
|
||||
return userRoleMapper.selectObjectByQueryAs(queryWrapper,Integer.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消授权用户:删除用户和角色关联信息
|
||||
* delete from sys_user_role where user_id=#{userId} and role_id=#{roleId}
|
||||
* @param userRole 用户和角色关联信息
|
||||
* @return 结果:true 删除成功,false 删除失败
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteUserRoleInfo(SysUserRole userRole) {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create().from(SYS_USER_ROLE).where(SYS_USER_ROLE.USER_ID.eq(userRole.getUserId()))
|
||||
.and(SYS_USER_ROLE.ROLE_ID.eq(userRole.getRoleId()));
|
||||
return this.remove(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量取消授权用户角色
|
||||
* delete from sys_user_role where role_id=#{roleId} and user_id in
|
||||
* @param roleId 角色ID
|
||||
* @param userIds 需要删除的用户数据ID
|
||||
* @return 结果:true 删除成功,false 删除失败
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteUserRoleInfos(Long roleId, Long[] userIds) {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create().from(SYS_USER_ROLE).where(SYS_USER_ROLE.ROLE_ID.eq(roleId))
|
||||
.and(SYS_USER_ROLE.USER_ID.in(Arrays.asList(userIds)));
|
||||
return this.remove(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量选择授权用户角色
|
||||
* insert into sys_user_role(user_id, role_id) values
|
||||
* @param roleId 角色ID
|
||||
* @param userIds 需要新增的用户数据ID
|
||||
* @return 结果:true 保存成功,false 保存失败
|
||||
*/
|
||||
@Override
|
||||
public boolean insertAuthUsers(Long roleId, Long[] userIds) {
|
||||
// 新增用户与角色管理
|
||||
List<SysUserRole> list = new ArrayList<>();
|
||||
for (Long userId : userIds) {
|
||||
SysUserRole ur = new SysUserRole();
|
||||
ur.setUserId(userId);
|
||||
ur.setRoleId(roleId);
|
||||
list.add(ur);
|
||||
}
|
||||
return this.saveBatchWithPk(list,100);//批量插入
|
||||
}
|
||||
}
|
@ -15,7 +15,10 @@ import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
|
||||
import com.ruoyi.common.security.utils.LoginHelper;
|
||||
import com.ruoyi.system.domain.*;
|
||||
import com.ruoyi.system.domain.bo.SysUserBo;
|
||||
import com.ruoyi.system.domain.vo.SysRoleVo;
|
||||
import com.ruoyi.system.mapper.*;
|
||||
import com.ruoyi.system.service.ISysRoleService;
|
||||
import com.ruoyi.system.service.ISysUserRoleService;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Validator;
|
||||
import org.slf4j.Logger;
|
||||
@ -49,13 +52,15 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
|
||||
private SysUserMapper userMapper;
|
||||
|
||||
@Resource
|
||||
private SysRoleMapper roleMapper;
|
||||
private ISysRoleService roleService;
|
||||
|
||||
@Resource
|
||||
private SysPostMapper postMapper;
|
||||
|
||||
@Resource
|
||||
private SysUserRoleMapper userRoleMapper;
|
||||
@Resource
|
||||
private ISysUserRoleService userRoleService;
|
||||
|
||||
@Resource
|
||||
private SysUserPostMapper userPostMapper;
|
||||
@ -132,11 +137,12 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
|
||||
*/
|
||||
@Override
|
||||
public String selectUserRoleGroup(String userName) {
|
||||
List<SysRole> list = roleMapper.selectRolesByUserName(userName);
|
||||
//List<SysRole> list = roleMapper.selectRolesByUserName(userName);
|
||||
List<SysRoleVo> list = roleService.selectRolesByUserName(userName);
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
return list.stream().map(SysRole::getRoleName).collect(Collectors.joining(","));
|
||||
return list.stream().map(SysRoleVo::getRoleName).collect(Collectors.joining(","));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -414,17 +420,18 @@ public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser>
|
||||
* @param roleIds 角色组
|
||||
*/
|
||||
public void insertUserRole(Long userId, Long[] roleIds) {
|
||||
if (StringUtils.isNotEmpty(roleIds)) {
|
||||
// 新增用户与角色管理
|
||||
List<SysUserRole> list = new ArrayList<>(roleIds.length);
|
||||
for (Long roleId : roleIds) {
|
||||
SysUserRole ur = new SysUserRole();
|
||||
ur.setUserId(userId);
|
||||
ur.setRoleId(roleId);
|
||||
list.add(ur);
|
||||
}
|
||||
userRoleMapper.batchUserRole(list);
|
||||
}
|
||||
userRoleService.insertAuthUsers(userId,roleIds);
|
||||
// if (StringUtils.isNotEmpty(roleIds)) {
|
||||
// // 新增用户与角色管理
|
||||
// List<SysUserRole> list = new ArrayList<>(roleIds.length);
|
||||
// for (Long roleId : roleIds) {
|
||||
// SysUserRole ur = new SysUserRole();
|
||||
// ur.setUserId(userId);
|
||||
// ur.setRoleId(roleId);
|
||||
// list.add(ur);
|
||||
// }
|
||||
// userRoleMapper.batchUserRole(list);
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -9,26 +9,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="deptId" column="dept_id" />
|
||||
</resultMap>
|
||||
|
||||
<delete id="deleteRoleDeptByRoleId" parameterType="Long">
|
||||
delete from sys_role_dept where role_id=#{roleId}
|
||||
</delete>
|
||||
|
||||
<!-- <delete id="deleteRoleDeptByRoleId" parameterType="Long">-->
|
||||
<!-- delete from sys_role_dept where role_id=#{roleId}-->
|
||||
<!-- </delete>-->
|
||||
|
||||
<select id="selectCountRoleDeptByDeptId" resultType="Integer">
|
||||
select count(1) from sys_role_dept where dept_id=#{deptId}
|
||||
</select>
|
||||
|
||||
<delete id="deleteRoleDept" parameterType="Long">
|
||||
delete from sys_role_dept where role_id in
|
||||
<foreach collection="array" item="roleId" open="(" separator="," close=")">
|
||||
#{roleId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<insert id="batchRoleDept">
|
||||
insert into sys_role_dept(role_id, dept_id) values
|
||||
<foreach item="item" index="index" collection="list" separator=",">
|
||||
(#{item.roleId},#{item.deptId})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
|
||||
<!-- <delete id="deleteRoleDept" parameterType="Long">-->
|
||||
<!-- delete from sys_role_dept where role_id in-->
|
||||
<!-- <foreach collection="array" item="roleId" open="(" separator="," close=")">-->
|
||||
<!-- #{roleId}-->
|
||||
<!-- </foreach>-->
|
||||
<!-- </delete>-->
|
||||
|
||||
<!-- <insert id="batchRoleDept">-->
|
||||
<!-- insert into sys_role_dept(role_id, dept_id) values-->
|
||||
<!-- <foreach item="item" index="index" collection="list" separator=",">-->
|
||||
<!-- (#{item.roleId},#{item.deptId})-->
|
||||
<!-- </foreach>-->
|
||||
<!-- </insert>-->
|
||||
|
||||
</mapper>
|
||||
|
@ -20,133 +20,40 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="remark" column="remark" />
|
||||
</resultMap>
|
||||
|
||||
|
||||
<sql id="selectRoleVo">
|
||||
select distinct r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.menu_check_strictly, r.dept_check_strictly,
|
||||
r.status, r.del_flag, r.create_time, r.remark
|
||||
r.status, r.del_flag, r.create_time, r.remark
|
||||
from sys_role r
|
||||
left join sys_user_role ur on ur.role_id = r.role_id
|
||||
left join sys_user u on u.user_id = ur.user_id
|
||||
left join sys_dept d on u.dept_id = d.dept_id
|
||||
</sql>
|
||||
|
||||
<select id="selectRoleList" parameterType="SysRole" resultMap="SysRoleResult">
|
||||
<include refid="selectRoleVo"/>
|
||||
where r.del_flag = '0'
|
||||
<if test="roleId != null and roleId != 0">
|
||||
AND r.role_id = #{roleId}
|
||||
</if>
|
||||
<if test="roleName != null and roleName != ''">
|
||||
AND r.role_name like concat('%', #{roleName}, '%')
|
||||
</if>
|
||||
<if test="status != null and status != ''">
|
||||
AND r.status = #{status}
|
||||
</if>
|
||||
<if test="roleKey != null and roleKey != ''">
|
||||
AND r.role_key like concat('%', #{roleKey}, '%')
|
||||
</if>
|
||||
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
|
||||
and date_format(r.create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d')
|
||||
</if>
|
||||
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
|
||||
and date_format(r.create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')
|
||||
</if>
|
||||
<!-- 数据范围过滤 -->
|
||||
${params.dataScope}
|
||||
order by r.role_sort
|
||||
</select>
|
||||
|
||||
<select id="selectRolePermissionByUserId" parameterType="Long" resultMap="SysRoleResult">
|
||||
<include refid="selectRoleVo"/>
|
||||
WHERE r.del_flag = '0' and ur.user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<select id="selectRoleAll" resultMap="SysRoleResult">
|
||||
<include refid="selectRoleVo"/>
|
||||
</select>
|
||||
|
||||
<select id="selectRoleListByUserId" parameterType="Long" resultType="Long">
|
||||
select r.role_id
|
||||
from sys_role r
|
||||
left join sys_user_role ur on ur.role_id = r.role_id
|
||||
left join sys_user u on u.user_id = ur.user_id
|
||||
where u.user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<select id="selectRoleById" parameterType="Long" resultMap="SysRoleResult">
|
||||
<include refid="selectRoleVo"/>
|
||||
where r.role_id = #{roleId}
|
||||
</select>
|
||||
|
||||
<select id="selectRolesByUserName" parameterType="String" resultMap="SysRoleResult">
|
||||
<include refid="selectRoleVo"/>
|
||||
WHERE r.del_flag = '0' and u.user_name = #{userName}
|
||||
</select>
|
||||
|
||||
<select id="checkRoleNameUnique" parameterType="String" resultMap="SysRoleResult">
|
||||
<include refid="selectRoleVo"/>
|
||||
where r.role_name=#{roleName} and r.del_flag = '0' limit 1
|
||||
</select>
|
||||
|
||||
<select id="checkRoleKeyUnique" parameterType="String" resultMap="SysRoleResult">
|
||||
<include refid="selectRoleVo"/>
|
||||
where r.role_key=#{roleKey} and r.del_flag = '0' limit 1
|
||||
</select>
|
||||
|
||||
<insert id="insertRole" parameterType="SysRole" useGeneratedKeys="true" keyProperty="roleId">
|
||||
insert into sys_role(
|
||||
<if test="roleId != null and roleId != 0">role_id,</if>
|
||||
<if test="roleName != null and roleName != ''">role_name,</if>
|
||||
<if test="roleKey != null and roleKey != ''">role_key,</if>
|
||||
<if test="roleSort != null">role_sort,</if>
|
||||
<if test="dataScope != null and dataScope != ''">data_scope,</if>
|
||||
<if test="menuCheckStrictly != null">menu_check_strictly,</if>
|
||||
<if test="deptCheckStrictly != null">dept_check_strictly,</if>
|
||||
<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>
|
||||
create_time
|
||||
)values(
|
||||
<if test="roleId != null and roleId != 0">#{roleId},</if>
|
||||
<if test="roleName != null and roleName != ''">#{roleName},</if>
|
||||
<if test="roleKey != null and roleKey != ''">#{roleKey},</if>
|
||||
<if test="roleSort != null">#{roleSort},</if>
|
||||
<if test="dataScope != null and dataScope != ''">#{dataScope},</if>
|
||||
<if test="menuCheckStrictly != null">#{menuCheckStrictly},</if>
|
||||
<if test="deptCheckStrictly != null">#{deptCheckStrictly},</if>
|
||||
<if test="status != null and status != ''">#{status},</if>
|
||||
<if test="remark != null and remark != ''">#{remark},</if>
|
||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||
sysdate()
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="updateRole" parameterType="SysRole">
|
||||
update sys_role
|
||||
<set>
|
||||
<if test="roleName != null and roleName != ''">role_name = #{roleName},</if>
|
||||
<if test="roleKey != null and roleKey != ''">role_key = #{roleKey},</if>
|
||||
<if test="roleSort != null">role_sort = #{roleSort},</if>
|
||||
<if test="dataScope != null and dataScope != ''">data_scope = #{dataScope},</if>
|
||||
<if test="menuCheckStrictly != null">menu_check_strictly = #{menuCheckStrictly},</if>
|
||||
<if test="deptCheckStrictly != null">dept_check_strictly = #{deptCheckStrictly},</if>
|
||||
<if test="status != null and status != ''">status = #{status},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
||||
update_time = sysdate()
|
||||
</set>
|
||||
where role_id = #{roleId}
|
||||
</update>
|
||||
|
||||
<delete id="deleteRoleById" parameterType="Long">
|
||||
update sys_role set del_flag = '1' where role_id = #{roleId}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteRoleByIds" parameterType="Long">
|
||||
update sys_role set del_flag = '1' where role_id in
|
||||
<foreach collection="array" item="roleId" open="(" separator="," close=")">
|
||||
#{roleId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
|
||||
<!-- <select id="selectRoleList" parameterType="SysRole" resultMap="SysRoleResult">-->
|
||||
<!-- <include refid="selectRoleVo"/>-->
|
||||
<!-- where r.del_flag = '0'-->
|
||||
<!-- <if test="roleId != null and roleId != 0">-->
|
||||
<!-- AND r.role_id = #{roleId}-->
|
||||
<!-- </if>-->
|
||||
<!-- <if test="roleName != null and roleName != ''">-->
|
||||
<!-- AND r.role_name like concat('%', #{roleName}, '%')-->
|
||||
<!-- </if>-->
|
||||
<!-- <if test="status != null and status != ''">-->
|
||||
<!-- AND r.status = #{status}-->
|
||||
<!-- </if>-->
|
||||
<!-- <if test="roleKey != null and roleKey != ''">-->
|
||||
<!-- AND r.role_key like concat('%', #{roleKey}, '%')-->
|
||||
<!-- </if>-->
|
||||
<!-- <if test="params.beginTime != null and params.beginTime != ''"><!– 开始时间检索 –>-->
|
||||
<!-- and date_format(r.create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d')-->
|
||||
<!-- </if>-->
|
||||
<!-- <if test="params.endTime != null and params.endTime != ''"><!– 结束时间检索 –>-->
|
||||
<!-- and date_format(r.create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')-->
|
||||
<!-- </if>-->
|
||||
<!-- <!– 数据范围过滤 –>-->
|
||||
<!-- ${params.dataScope}-->
|
||||
<!-- order by r.role_sort-->
|
||||
<!-- </select>-->
|
||||
|
||||
</mapper>
|
||||
|
@ -8,27 +8,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="roleId" column="role_id" />
|
||||
<result property="menuId" column="menu_id" />
|
||||
</resultMap>
|
||||
|
||||
|
||||
<select id="checkMenuExistRole" resultType="Integer">
|
||||
select count(1) from sys_role_menu where menu_id = #{menuId}
|
||||
</select>
|
||||
|
||||
<delete id="deleteRoleMenuByRoleId" parameterType="Long">
|
||||
delete from sys_role_menu where role_id=#{roleId}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteRoleMenu" parameterType="Long">
|
||||
delete from sys_role_menu where role_id in
|
||||
<foreach collection="array" item="roleId" open="(" separator="," close=")">
|
||||
#{roleId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<insert id="batchRoleMenu">
|
||||
insert into sys_role_menu(role_id, menu_id) values
|
||||
<foreach item="item" index="index" collection="list" separator=",">
|
||||
(#{item.roleId},#{item.menuId})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
<!-- <delete id="deleteRoleMenuByRoleId" parameterType="Long">-->
|
||||
<!-- delete from sys_role_menu where role_id=#{roleId}-->
|
||||
<!-- </delete>-->
|
||||
|
||||
<!-- <delete id="deleteRoleMenu" parameterType="Long">-->
|
||||
<!-- delete from sys_role_menu where role_id in-->
|
||||
<!-- <foreach collection="array" item="roleId" open="(" separator="," close=")">-->
|
||||
<!-- #{roleId}-->
|
||||
<!-- </foreach>-->
|
||||
<!-- </delete>-->
|
||||
|
||||
<!-- <insert id="batchRoleMenu">-->
|
||||
<!-- insert into sys_role_menu(role_id, menu_id) values-->
|
||||
<!-- <foreach item="item" index="index" collection="list" separator=",">-->
|
||||
<!-- (#{item.roleId},#{item.menuId})-->
|
||||
<!-- </foreach>-->
|
||||
<!-- </insert>-->
|
||||
|
||||
</mapper>
|
||||
|
@ -12,33 +12,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<delete id="deleteUserRoleByUserId" parameterType="Long">
|
||||
delete from sys_user_role where user_id=#{userId}
|
||||
</delete>
|
||||
|
||||
<select id="countUserRoleByRoleId" resultType="Integer">
|
||||
select count(1) from sys_user_role where role_id=#{roleId}
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
|
||||
<delete id="deleteUserRole" parameterType="Long">
|
||||
delete from sys_user_role where user_id in
|
||||
<foreach collection="array" item="userId" open="(" separator="," close=")">
|
||||
#{userId}
|
||||
</foreach>
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<insert id="batchUserRole">
|
||||
insert into sys_user_role(user_id, role_id) values
|
||||
<foreach item="item" index="index" collection="list" separator=",">
|
||||
(#{item.userId},#{item.roleId})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<delete id="deleteUserRoleInfo" parameterType="SysUserRole">
|
||||
delete from sys_user_role where user_id=#{userId} and role_id=#{roleId}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteUserRoleInfos">
|
||||
delete from sys_user_role where role_id=#{roleId} and user_id in
|
||||
<foreach collection="userIds" item="userId" open="(" separator="," close=")">
|
||||
#{userId}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
@ -39,8 +39,8 @@ const user = {
|
||||
const uuid = userInfo.uuid
|
||||
return new Promise((resolve, reject) => {
|
||||
login(tenantId,username, password, code, uuid).then(res => {
|
||||
setToken(res.token)
|
||||
commit('SET_TOKEN', res.token)
|
||||
setToken(res.data.access_token)
|
||||
commit('SET_TOKEN', res.data.access_token)
|
||||
resolve()
|
||||
}).catch(error => {
|
||||
reject(error)
|
||||
|
@ -38,7 +38,7 @@
|
||||
<el-date-picker
|
||||
v-model="dateRange"
|
||||
style="width: 240px"
|
||||
value-format="yyyy-MM-dd"
|
||||
value-format="YYYY-MM-DD"
|
||||
type="daterange"
|
||||
range-separator="-"
|
||||
start-placeholder="开始日期"
|
||||
@ -462,15 +462,15 @@ function handleUpdate(row) {
|
||||
/** 根据角色ID查询菜单树结构 */
|
||||
function getRoleMenuTreeselect(roleId) {
|
||||
return roleMenuTreeselect(roleId).then(response => {
|
||||
menuOptions.value = response.menus;
|
||||
return response;
|
||||
menuOptions.value = response.data.menus;
|
||||
return response.data;
|
||||
});
|
||||
}
|
||||
/** 根据角色ID查询部门树结构 */
|
||||
function getRoleDeptTreeselect(roleId) {
|
||||
return deptTreeSelect(roleId).then(response => {
|
||||
deptOptions.value = response.depts;
|
||||
return response;
|
||||
deptOptions.value = response.data.depts;
|
||||
return response.data;
|
||||
});
|
||||
}
|
||||
/** 树权限(展开/折叠)*/
|
||||
|
Loading…
Reference in New Issue
Block a user