diff --git a/pom.xml b/pom.xml index 3cabbe2..163cbea 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,7 @@ UTF-8 17 3.1.4 - 1.6.7 + 1.6.8 1.36.0 8.0.33 3.1.1 diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/AuthController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/AuthController.java index aa67a82..506adf2 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/AuthController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/AuthController.java @@ -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 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)); } /** diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/service/IAuthStrategy.java b/ruoyi-admin/src/main/java/com/ruoyi/web/service/IAuthStrategy.java index 8e0c020..8835ced 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/service/IAuthStrategy.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/service/IAuthStrategy.java @@ -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); } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/service/impl/EmailAuthStrategy.java b/ruoyi-admin/src/main/java/com/ruoyi/web/service/impl/EmailAuthStrategy.java index fceba2f..3913d0c 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/service/impl/EmailAuthStrategy.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/service/impl/EmailAuthStrategy.java @@ -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(); } /** diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/service/impl/PasswordAuthStrategy.java b/ruoyi-admin/src/main/java/com/ruoyi/web/service/impl/PasswordAuthStrategy.java index 924d7ee..53867cb 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/service/impl/PasswordAuthStrategy.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/service/impl/PasswordAuthStrategy.java @@ -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(); } diff --git a/ruoyi-admin/src/main/resources/application-dev.yml b/ruoyi-admin/src/main/resources/application-dev.yml index 134ad74..b55bd50 100644 --- a/ruoyi-admin/src/main/resources/application-dev.yml +++ b/ruoyi-admin/src/main/resources/application-dev.yml @@ -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: diff --git a/ruoyi-admin/src/main/resources/application-prod.yml b/ruoyi-admin/src/main/resources/application-prod.yml index 2e74cd2..1d7bf75 100644 --- a/ruoyi-admin/src/main/resources/application-prod.yml +++ b/ruoyi-admin/src/main/resources/application-prod.yml @@ -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全局配置 diff --git a/ruoyi-common/ruoyi-common-orm/src/main/java/com/ruoyi/common/orm/core/service/IBaseService.java b/ruoyi-common/ruoyi-common-orm/src/main/java/com/ruoyi/common/orm/core/service/IBaseService.java index 0d012e8..cf01d31 100644 --- a/ruoyi-common/ruoyi-common-orm/src/main/java/com/ruoyi/common/orm/core/service/IBaseService.java +++ b/ruoyi-common/ruoyi-common-orm/src/main/java/com/ruoyi/common/orm/core/service/IBaseService.java @@ -14,8 +14,20 @@ import java.util.Collection; * @author dataprince数据小王子 */ public interface IBaseService extends IService { + /** - *

带主键批量保存实体类对象数据,适用于中间表有联合主键场合,例如sys_role_menu。 + *

带主键保存实体类对象数据,适用于中间表有联合主键场合但是不通过主键生成器生成主键值,而是程序自己提供主键值。 + * + * @param entity 实体类对象 + * @return 受影响的行数 + * @apiNote 默认调用的是 {@link BaseMapper#insertSelectiveWithPk(Object)} 方法,忽略实体类 + * {@code null} 属性的数据,使数据库配置的默认值生效。 + */ + default int saveWithPk(T entity) { + return getMapper().insertSelectiveWithPk(entity); + } + /** + *

带主键批量保存实体类对象数据,适用于中间表有联合主键场合但是不通过主键生成器生成主键值,而是程序自己提供主键值,例如sys_role_menu。 * * @param entities 实体类对象 * @return {@code true} 保存成功,{@code false} 保存失败。 @@ -27,7 +39,7 @@ public interface IBaseService extends IService { } /** - *

带主键批量保存实体类对象数据,适用于中间表有联合主键场合,例如sys_role_menu。 + *

带主键批量保存实体类对象数据,适用于中间表有联合主键场合但是不通过主键生成器生成主键值,而是程序自己提供主键值,例如sys_role_menu。 * * @param entities 实体类对象 * @param batchSize 每次保存切分的数量 diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysRoleController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysRoleController.java index 8dee70b..26e18b1 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysRoleController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysRoleController.java @@ -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 list = roleService.selectRoleList(role); - return getDataTable(list); + public TableDataInfo 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 list = roleService.selectRoleList(role); - ExcelUtil util = new ExcelUtil<>(SysRole.class); - util.exportExcel(response, list, "角色数据"); + public void export(HttpServletResponse response, SysRoleBo roleBo) { + List 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 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 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 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 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 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 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> 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 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 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 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 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 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 deptTree(@PathVariable("roleId") Long roleId) { + DeptTreeSelectVo selectVo = new DeptTreeSelectVo(); + selectVo.setCheckedKeys(deptService.selectDeptListByRoleId(roleId)); + selectVo.setDepts(deptService.selectDeptTreeList(new SysDeptBo())); + return R.ok(selectVo); } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysUserController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysUserController.java index f40cadc..160f862 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysUserController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/system/SysUserController.java @@ -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 roles = roleService.selectRoleList(sysRole); + List 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 roles = roleService.selectRolesByUserId(userId); + List 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; diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRole.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRole.java index 4aee36d..56e2a97 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRole.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRole.java @@ -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 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 deptList; - /** 角色菜单权限 */ + @RelationManyToMany( + selfField = "roleId", targetField = "userId", + joinTable = "sys_user_role", + joinSelfColumn = "role_id", joinTargetColumn = "user_id" + ) + private List userList; + + /** + * 角色菜单权限 + */ + @Column(ignore = true) private Set 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; } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRoleDept.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRoleDept.java index 47b21bf..8d13a59 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRoleDept.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRoleDept.java @@ -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(); - } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRoleMenu.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRoleMenu.java index 52aa10d..0ef959d 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRoleMenu.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysRoleMenu.java @@ -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(); - } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysUser.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysUser.java index f6674c6..e42e3ff 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysUser.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysUser.java @@ -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 roles; /** 角色组 */ private Long[] roleIds; + @RelationManyToMany( + selfField = "userId", targetField = "postId", + joinTable = "sys_user_post", + joinSelfColumn = "user_id", joinTargetColumn = "post_id" + ) + private List postList; + /** 岗位组 */ private Long[] postIds; diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysUserPost.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysUserPost.java index 6e8c416..44792c7 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysUserPost.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysUserPost.java @@ -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() diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysUserRole.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysUserRole.java index 4d15810..cc644e3 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysUserRole.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysUserRole.java @@ -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(); - } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysRoleVo.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysRoleVo.java index 06f97a4..592db93 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysRoleVo.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/SysRoleVo.java @@ -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; + } + } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleDeptMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleDeptMapper.java index f9d3a2f..c110fff 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleDeptMapper.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleDeptMapper.java @@ -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 { - /** - * 通过角色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 roleDeptList); +// /** +// * 批量新增角色部门信息 +// * +// * @param roleDeptList 角色部门列表 +// * @return 结果 +// */ +// public int batchRoleDept(List roleDeptList); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMapper.java index 323cf21..e2aed6c 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMapper.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMapper.java @@ -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 { - /** - * 根据条件分页查询角色数据 - * - * @param role 角色信息 - * @return 角色数据集合信息 - */ - List selectRoleList(SysRole role); - /** - * 根据用户ID查询角色 - * - * @param userId 用户ID - * @return 角色列表 - */ - List selectRolePermissionByUserId(Long userId); - - /** - * 查询所有角色 - * - * @return 角色列表 - */ - List selectRoleAll(); - - /** - * 根据用户ID获取角色选择框列表 - * - * @param userId 用户ID - * @return 选中角色ID列表 - */ - List selectRoleListByUserId(Long userId); - - /** - * 通过角色ID查询角色 - * - * @param roleId 角色ID - * @return 角色对象信息 - */ - SysRole selectRoleById(Long roleId); - - /** - * 根据用户ID查询角色 - * - * @param userName 用户名 - * @return 角色列表 - */ - List 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); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMenuMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMenuMapper.java index 6602bee..db44fb2 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMenuMapper.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMenuMapper.java @@ -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 { /** * 查询菜单使用数量 - * + * * @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 roleMenuList); +// /** +// * 批量新增角色菜单信息 +// * +// * @param roleMenuList 角色菜单列表 +// * @return 结果 +// */ +// public int batchRoleMenu(List roleMenuList); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java index 2aec5fb..13f8a8f 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java @@ -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 { /** diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserPostMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserPostMapper.java index e08991d..a5d583f 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserPostMapper.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserPostMapper.java @@ -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 { /** * 通过用户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 结果 */ diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserRoleMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserRoleMapper.java index 3143ec8..f5beeb0 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserRoleMapper.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserRoleMapper.java @@ -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 { /** * 通过用户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 userRoleList); +// /** +// * 批量新增用户角色信息 +// * +// * @param userRoleList 用户角色列表 +// * @return 结果 +// */ +// public int batchUserRole(List 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); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysRoleDeptService.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysRoleDeptService.java new file mode 100644 index 0000000..c35a864 --- /dev/null +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysRoleDeptService.java @@ -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 { + + /** + * 通过角色ID删除角色和部门关联 + * + * @param roleId 角色ID + * @return 结果:true 删除成功,false 删除失败 + */ + boolean deleteRoleDeptByRoleId(Long roleId); + + /** + * 批量删除角色部门关联信息 + * + * @param ids 需要删除的数据ID + * @return 结果:true 删除成功,false 删除失败。 + */ + boolean deleteRoleDept(Long[] ids); + +} diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysRoleMenuService.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysRoleMenuService.java new file mode 100644 index 0000000..b0617a2 --- /dev/null +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysRoleMenuService.java @@ -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 { + + /** + * 批量删除角色菜单关联信息 + * + * @param ids 需要删除的数据ID + * @return true 删除成功,false 删除失败。 + */ + boolean deleteRoleMenu(Long[] ids); + +} diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysRoleService.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysRoleService.java index 1f89b14..4b31c0e 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysRoleService.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysRoleService.java @@ -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 { + /** + * 分页查询角色列表 + * + * @param roleBo 角色信息 + * @return 角色集合 + */ + TableDataInfo selectPage(SysRoleBo roleBo); + /** * 根据条件分页查询角色数据 * - * @param role 角色信息 + * @param roleBo 角色信息 * @return 角色数据集合信息 */ - List selectRoleList(SysRole role); + List selectRoleList(SysRoleBo roleBo); /** * 根据用户ID查询角色列表 @@ -27,7 +41,7 @@ public interface ISysRoleService * @param userId 用户ID * @return 角色列表 */ - List selectRolesByUserId(Long userId); + List selectRolesByUserId(Long userId); /** * 根据用户ID查询角色权限 @@ -42,7 +56,7 @@ public interface ISysRoleService * * @return 角色列表 */ - List selectRoleAll(); + List 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 selectRolesByUserName(String userName); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserRoleService.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserRoleService.java new file mode 100644 index 0000000..9d78960 --- /dev/null +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserRoleService.java @@ -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 { + + /** + * 通过角色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); +} diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java index 1de18d0..7f90659 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java @@ -159,6 +159,7 @@ public class SysConfigServiceImpl extends BaseServiceImpl 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 */ @Override public List 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 */ @Override public int selectNormalChildrenDeptById(Long deptId) { -// return deptMapper.selectNormalChildrenDeptById(deptId); QueryWrapper queryWrapper = QueryWrapper.create() .select(QueryMethods.count(SYS_DEPT.DEPT_ID)) .from(SYS_DEPT) diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java index 1925a60..4fe964e 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java @@ -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 i private SysMenuMapper menuMapper; @Resource - private SysRoleMapper roleMapper; + private ISysRoleService sysRoleService; @Resource private SysRoleMenuMapper roleMenuMapper; @@ -170,8 +172,8 @@ public class SysMenuServiceImpl extends BaseServiceImpl i */ @Override public List 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()); } /** diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleDeptServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleDeptServiceImpl.java new file mode 100644 index 0000000..f84fcbd --- /dev/null +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleDeptServiceImpl.java @@ -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 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); + } +} diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleMenuServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleMenuServiceImpl.java new file mode 100644 index 0000000..c9f8a47 --- /dev/null +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleMenuServiceImpl.java @@ -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 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); + } +} diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java index 776da39..9db1cf8 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java @@ -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 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 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 selectRoleList(SysRole role) { - return roleMapper.selectRoleList(role); + //@DataScope(deptAlias = "d") + public List selectRoleList(SysRoleBo roleBo) { + //return roleMapper.selectRoleList(roleBo); + + QueryWrapper queryWrapper = buildQueryWrapper(roleBo); + //List list = roleMapper.selectListByQueryAs(queryWrapper, SysRoleVo.class); + return this.listAs(queryWrapper, SysRoleVo.class); + } + + /** + * 分页查询角色列表 + * + * @param roleBo 角色信息 + * @return 角色集合 + */ + @Override + public TableDataInfo selectPage(SysRoleBo roleBo) { + QueryWrapper queryWrapper = buildQueryWrapper(roleBo); + Page 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 selectRolesByUserId(Long userId) { - List userRoles = roleMapper.selectRolePermissionByUserId(userId); - List roles = selectRoleAll(); - for (SysRole role : roles) { - for (SysRole userRole : userRoles) { + public List 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 userRoles = roleMapper.selectRolePermissionByUserId(userId); + List userRoles = this.listAs(queryWrapper, SysRoleVo.class); + List 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 selectRolePermissionByUserId(Long userId) { - List 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 perms = this.listAs(queryWrapper, SysRoleVo.class); + //List perms = roleMapper.selectRolePermissionByUserId(userId); Set 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 selectRoleAll() { - return SpringUtils.getAopProxy(this).selectRoleList(new SysRole()); + public List selectRoleAll() { + return SpringUtils.getAopProxy(this).selectRoleList(new SysRoleBo()); } /** @@ -115,7 +214,19 @@ public class SysRoleServiceImpl implements ISysRoleService { */ @Override public List 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 roles = SpringUtils.getAopProxy(this).selectRoleList(role); - if (StringUtils.isEmpty(roles)) { + List 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 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 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 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 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 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); + } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserRoleServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserRoleServiceImpl.java new file mode 100644 index 0000000..12f6b25 --- /dev/null +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserRoleServiceImpl.java @@ -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 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 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);//批量插入 + } +} diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java index 3ea3415..1be48b4 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java @@ -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 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 */ @Override public String selectUserRoleGroup(String userName) { - List list = roleMapper.selectRolesByUserName(userName); + //List list = roleMapper.selectRolesByUserName(userName); + List 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 * @param roleIds 角色组 */ public void insertUserRole(Long userId, Long[] roleIds) { - if (StringUtils.isNotEmpty(roleIds)) { - // 新增用户与角色管理 - List 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 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); +// } } /** diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysRoleDeptMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysRoleDeptMapper.xml index 7c4139b..44b7ba7 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysRoleDeptMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysRoleDeptMapper.xml @@ -9,26 +9,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - - delete from sys_role_dept where role_id=#{roleId} - - + + + + - - - delete from sys_role_dept where role_id in - - #{roleId} - - - - - insert into sys_role_dept(role_id, dept_id) values - - (#{item.roleId},#{item.deptId}) - - - - \ No newline at end of file + + + + + + + + + + + + + + + + diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml index a4e550b..0484f04 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml @@ -20,133 +20,40 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + 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 - - - - - - - - - - - - - - - - - - - insert into sys_role( - role_id, - role_name, - role_key, - role_sort, - data_scope, - menu_check_strictly, - dept_check_strictly, - status, - remark, - create_by, - create_time - )values( - #{roleId}, - #{roleName}, - #{roleKey}, - #{roleSort}, - #{dataScope}, - #{menuCheckStrictly}, - #{deptCheckStrictly}, - #{status}, - #{remark}, - #{createBy}, - sysdate() - ) - - - - update sys_role - - role_name = #{roleName}, - role_key = #{roleKey}, - role_sort = #{roleSort}, - data_scope = #{dataScope}, - menu_check_strictly = #{menuCheckStrictly}, - dept_check_strictly = #{deptCheckStrictly}, - status = #{status}, - remark = #{remark}, - update_by = #{updateBy}, - update_time = sysdate() - - where role_id = #{roleId} - - - - update sys_role set del_flag = '1' where role_id = #{roleId} - - - - update sys_role set del_flag = '1' where role_id in - - #{roleId} - - - - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysRoleMenuMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysRoleMenuMapper.xml index cb60a85..7114d3d 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysRoleMenuMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysRoleMenuMapper.xml @@ -8,27 +8,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + - - delete from sys_role_menu where role_id=#{roleId} - - - - delete from sys_role_menu where role_id in - - #{roleId} - - - - - insert into sys_role_menu(role_id, menu_id) values - - (#{item.roleId},#{item.menuId}) - - - - \ No newline at end of file + + + + + + + + + + + + + + + + + + + diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysUserRoleMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysUserRoleMapper.xml index dd72689..5f2bdc8 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysUserRoleMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysUserRoleMapper.xml @@ -12,33 +12,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" delete from sys_user_role where user_id=#{userId} - - - + + + delete from sys_user_role where user_id in #{userId} - + - - - insert into sys_user_role(user_id, role_id) values - - (#{item.userId},#{item.roleId}) - - - - - delete from sys_user_role where user_id=#{userId} and role_id=#{roleId} - - - - delete from sys_user_role where role_id=#{roleId} and user_id in - - #{userId} - - - \ No newline at end of file + + + diff --git a/ruoyi-ui/src/store/modules/user.js b/ruoyi-ui/src/store/modules/user.js index d74ae18..ca6598e 100644 --- a/ruoyi-ui/src/store/modules/user.js +++ b/ruoyi-ui/src/store/modules/user.js @@ -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) diff --git a/ruoyi-ui/src/views/system/role/index.vue b/ruoyi-ui/src/views/system/role/index.vue index 690b4dd..1841c2c 100644 --- a/ruoyi-ui/src/views/system/role/index.vue +++ b/ruoyi-ui/src/views/system/role/index.vue @@ -38,7 +38,7 @@ { - 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; }); } /** 树权限(展开/折叠)*/