add
This commit is contained in:
@ -0,0 +1,38 @@
|
||||
package com.qiaoba.api.system.entity;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* 角色和部门关联 sys_role_dept
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2022-09-22 04:20:28
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
public class SysRoleDept {
|
||||
|
||||
/**
|
||||
* 角色ID
|
||||
*/
|
||||
private String roleId;
|
||||
|
||||
/**
|
||||
* 部门ID
|
||||
*/
|
||||
private String deptId;
|
||||
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
private String tenantId;
|
||||
|
||||
public SysRoleDept(String roleId, String deptId) {
|
||||
this.roleId = roleId;
|
||||
this.deptId = deptId;
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.qiaoba.api.system.entity.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 角色数据权限
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/5/8 15:54
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class DataScopeDto implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 角色ID
|
||||
*/
|
||||
private String roleId;
|
||||
|
||||
/**
|
||||
* 数据权限
|
||||
*/
|
||||
private String dataScope;
|
||||
|
||||
/**
|
||||
* 部门组(数据权限)
|
||||
*/
|
||||
private Set<String> deptIds;
|
||||
|
||||
|
||||
}
|
@ -20,5 +20,12 @@ public class SysRoleParam implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String roleName;
|
||||
|
||||
private String roleKey;
|
||||
|
||||
private String status;
|
||||
|
||||
private String beginTime;
|
||||
|
||||
private String endTime;
|
||||
}
|
||||
|
@ -26,6 +26,8 @@ public class SysUserParam implements Serializable {
|
||||
|
||||
private String deptId;
|
||||
|
||||
private String roleId;
|
||||
|
||||
private String status;
|
||||
|
||||
private String isDelete;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.qiaoba.api.system.service;
|
||||
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import com.qiaoba.api.system.entity.SysDept;
|
||||
import com.qiaoba.api.system.entity.param.SysDeptParam;
|
||||
|
||||
@ -53,4 +54,19 @@ public interface SysDeptApiService {
|
||||
* @return > 0 = success
|
||||
*/
|
||||
int deleteById(Long deptId);
|
||||
|
||||
/**
|
||||
* 构建前端部门树
|
||||
*
|
||||
* @return tree
|
||||
*/
|
||||
List<Tree<String>> selectDeptTree();
|
||||
|
||||
/**
|
||||
* 根据角色ID查询部门树信息
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 选中部门列表
|
||||
*/
|
||||
List<String> selectDeptIdsByRoleId(String roleId);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.qiaoba.api.system.service;
|
||||
|
||||
import com.qiaoba.api.system.entity.SysRole;
|
||||
import com.qiaoba.api.system.entity.dto.DataScopeDto;
|
||||
import com.qiaoba.api.system.entity.dto.SysRoleDto;
|
||||
import com.qiaoba.api.system.entity.param.SysRoleParam;
|
||||
|
||||
@ -62,4 +63,12 @@ public interface SysRoleApiService {
|
||||
* @return > 0 = success
|
||||
*/
|
||||
int deleteByIds(List<String> ids);
|
||||
|
||||
/**
|
||||
* 修改数据权限信息
|
||||
*
|
||||
* @param dto 角色ID + deptIds
|
||||
* @return 结果
|
||||
*/
|
||||
int authDataScope(DataScopeDto dto);
|
||||
}
|
||||
|
@ -78,4 +78,5 @@ public interface SysUserApiService {
|
||||
* @return list
|
||||
*/
|
||||
List<SysUserVo> selectVoList(SysUserParam param);
|
||||
|
||||
}
|
||||
|
@ -2,16 +2,16 @@ qiaoba:
|
||||
datasource:
|
||||
master:
|
||||
driver: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://121.5.136.69:3306/qiaoba-boot-1?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&allowMultiQueries=true
|
||||
url: jdbc:mysql://localhost:3306/qiaoba-boot?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&allowMultiQueries=true
|
||||
username: root
|
||||
password: LpYN7LUoL?l0OSpR2
|
||||
password: root
|
||||
pool:
|
||||
init: 5 #连接池初始化大小
|
||||
min: 10 #最小空闲连接数
|
||||
max: 20 #最大连接数
|
||||
slaves:
|
||||
- driver: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://121.5.136.69:3306/qiaoba-boot?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&allowMultiQueries=true
|
||||
url: jdbc:mysql://121.5.136.69:3306/qiaoba-boot-1?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true&allowMultiQueries=true
|
||||
username: root
|
||||
password: LpYN7LUoL?l0OSpR2
|
||||
pool:
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.qiaoba.module.system.controller;
|
||||
|
||||
import com.qiaoba.common.base.result.AjaxResult;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@ -28,4 +29,9 @@ public class SysLoginController {
|
||||
public String getRouters() {
|
||||
return "{\"msg\":\"操作成功\",\"code\":200,\"data\":[{\"name\":\"System\",\"path\":\"/system\",\"hidden\":false,\"redirect\":\"noRedirect\",\"component\":\"Layout\",\"alwaysShow\":true,\"meta\":{\"title\":\"系统管理\",\"icon\":\"system\",\"noCache\":false,\"link\":null},\"children\":[{\"name\":\"User\",\"path\":\"user\",\"hidden\":false,\"component\":\"system/user/index\",\"meta\":{\"title\":\"用户管理\",\"icon\":\"user\",\"noCache\":false,\"link\":null}},{\"name\":\"Role\",\"path\":\"role\",\"hidden\":false,\"component\":\"system/role/index\",\"meta\":{\"title\":\"角色管理\",\"icon\":\"peoples\",\"noCache\":false,\"link\":null}},{\"name\":\"Menu\",\"path\":\"menu\",\"hidden\":false,\"component\":\"system/menu/index\",\"meta\":{\"title\":\"菜单管理\",\"icon\":\"tree-table\",\"noCache\":false,\"link\":null}},{\"name\":\"Dept\",\"path\":\"dept\",\"hidden\":false,\"component\":\"system/dept/index\",\"meta\":{\"title\":\"部门管理\",\"icon\":\"tree\",\"noCache\":false,\"link\":null}},{\"name\":\"Post\",\"path\":\"post\",\"hidden\":false,\"component\":\"system/post/index\",\"meta\":{\"title\":\"岗位管理\",\"icon\":\"post\",\"noCache\":false,\"link\":null}},{\"name\":\"Dict\",\"path\":\"dict\",\"hidden\":false,\"component\":\"system/dict/index\",\"meta\":{\"title\":\"字典管理\",\"icon\":\"dict\",\"noCache\":false,\"link\":null}},{\"name\":\"Config\",\"path\":\"config\",\"hidden\":false,\"component\":\"system/config/index\",\"meta\":{\"title\":\"参数设置\",\"icon\":\"edit\",\"noCache\":false,\"link\":null}},{\"name\":\"Notice\",\"path\":\"notice\",\"hidden\":false,\"component\":\"system/notice/index\",\"meta\":{\"title\":\"通知公告\",\"icon\":\"message\",\"noCache\":false,\"link\":null}},{\"name\":\"Log\",\"path\":\"log\",\"hidden\":false,\"redirect\":\"noRedirect\",\"component\":\"ParentView\",\"alwaysShow\":true,\"meta\":{\"title\":\"日志管理\",\"icon\":\"log\",\"noCache\":false,\"link\":null},\"children\":[{\"name\":\"Operlog\",\"path\":\"operlog\",\"hidden\":false,\"component\":\"monitor/operlog/index\",\"meta\":{\"title\":\"操作日志\",\"icon\":\"form\",\"noCache\":false,\"link\":null}},{\"name\":\"Logininfor\",\"path\":\"logininfor\",\"hidden\":false,\"component\":\"monitor/logininfor/index\",\"meta\":{\"title\":\"登录日志\",\"icon\":\"logininfor\",\"noCache\":false,\"link\":null}}]}]},{\"name\":\"Monitor\",\"path\":\"/monitor\",\"hidden\":false,\"redirect\":\"noRedirect\",\"component\":\"Layout\",\"alwaysShow\":true,\"meta\":{\"title\":\"系统监控\",\"icon\":\"monitor\",\"noCache\":false,\"link\":null},\"children\":[{\"name\":\"Online\",\"path\":\"online\",\"hidden\":false,\"component\":\"monitor/online/index\",\"meta\":{\"title\":\"在线用户\",\"icon\":\"online\",\"noCache\":false,\"link\":null}},{\"name\":\"Job\",\"path\":\"job\",\"hidden\":false,\"component\":\"monitor/job/index\",\"meta\":{\"title\":\"定时任务\",\"icon\":\"job\",\"noCache\":false,\"link\":null}},{\"name\":\"Druid\",\"path\":\"druid\",\"hidden\":false,\"component\":\"monitor/druid/index\",\"meta\":{\"title\":\"数据监控\",\"icon\":\"druid\",\"noCache\":false,\"link\":null}},{\"name\":\"Server\",\"path\":\"server\",\"hidden\":false,\"component\":\"monitor/server/index\",\"meta\":{\"title\":\"服务监控\",\"icon\":\"server\",\"noCache\":false,\"link\":null}},{\"name\":\"Cache\",\"path\":\"cache\",\"hidden\":false,\"component\":\"monitor/cache/index\",\"meta\":{\"title\":\"缓存监控\",\"icon\":\"redis\",\"noCache\":false,\"link\":null}},{\"name\":\"CacheList\",\"path\":\"cacheList\",\"hidden\":false,\"component\":\"monitor/cache/list\",\"meta\":{\"title\":\"缓存列表\",\"icon\":\"redis-list\",\"noCache\":false,\"link\":null}}]},{\"name\":\"Tool\",\"path\":\"/tool\",\"hidden\":false,\"redirect\":\"noRedirect\",\"component\":\"Layout\",\"alwaysShow\":true,\"meta\":{\"title\":\"系统工具\",\"icon\":\"tool\",\"noCache\":false,\"link\":null},\"children\":[{\"name\":\"Build\",\"path\":\"build\",\"hidden\":false,\"component\":\"tool/build/index\",\"meta\":{\"title\":\"表单构建\",\"icon\":\"build\",\"noCache\":false,\"link\":null}},{\"name\":\"Gen\",\"path\":\"gen\",\"hidden\":false,\"component\":\"tool/gen/index\",\"meta\":{\"title\":\"代码生成\",\"icon\":\"code\",\"noCache\":false,\"link\":null}},{\"name\":\"Swagger\",\"path\":\"swagger\",\"hidden\":false,\"component\":\"tool/swagger/index\",\"meta\":{\"title\":\"系统接口\",\"icon\":\"swagger\",\"noCache\":false,\"link\":null}}]},{\"name\":\"Http://ruoyi.vip\",\"path\":\"http://ruoyi.vip\",\"hidden\":false,\"component\":\"Layout\",\"meta\":{\"title\":\"若依官网\",\"icon\":\"guide\",\"noCache\":false,\"link\":\"http://ruoyi.vip\"}}]}";
|
||||
}
|
||||
|
||||
@PostMapping("/logout")
|
||||
public AjaxResult logout() {
|
||||
return AjaxResult.success();
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,17 @@
|
||||
package com.qiaoba.module.system.controller;
|
||||
|
||||
import com.qiaoba.api.system.entity.SysRole;
|
||||
import com.qiaoba.api.system.entity.dto.DataScopeDto;
|
||||
import com.qiaoba.api.system.entity.dto.SysRoleDto;
|
||||
import com.qiaoba.api.system.entity.param.SysRoleParam;
|
||||
import com.qiaoba.api.system.entity.param.SysUserParam;
|
||||
import com.qiaoba.common.base.result.AjaxResult;
|
||||
import com.qiaoba.common.database.entity.PageQuery;
|
||||
import com.qiaoba.common.database.entity.TableDataInfo;
|
||||
import com.qiaoba.module.system.service.SysDeptService;
|
||||
import com.qiaoba.module.system.service.SysRoleService;
|
||||
import com.qiaoba.module.system.service.SysUserRoleService;
|
||||
import com.qiaoba.module.system.service.SysUserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@ -26,6 +31,9 @@ import java.util.List;
|
||||
public class SysRoleController {
|
||||
|
||||
private final SysRoleService sysRoleService;
|
||||
private final SysDeptService sysDeptService;
|
||||
private final SysUserService sysUserService;
|
||||
private final SysUserRoleService sysUserRoleService;
|
||||
|
||||
//@PreAuthorize("hasAuthority('system:role:list')")
|
||||
@GetMapping("/list")
|
||||
@ -52,6 +60,7 @@ public class SysRoleController {
|
||||
return AjaxResult.toAjax(sysRoleService.updateById(roleDto));
|
||||
|
||||
}
|
||||
|
||||
//@PreAuthorize("hasAuthority('system:role:edit')")
|
||||
@PutMapping("/changeStatus")
|
||||
public AjaxResult changeStatus(@RequestBody SysRoleDto dto) {
|
||||
@ -63,4 +72,52 @@ public class SysRoleController {
|
||||
public AjaxResult remove(@PathVariable List<String> roleIds) {
|
||||
return AjaxResult.toAjax(sysRoleService.deleteByIds(roleIds));
|
||||
}
|
||||
|
||||
//@PreAuthorize("hasAuthority('system:role:query')")
|
||||
@GetMapping(value = "/deptTree/{roleId}")
|
||||
public AjaxResult deptTree(@PathVariable("roleId") String roleId) {
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
ajax.put("checkedKeys", sysDeptService.selectDeptIdsByRoleId(roleId));
|
||||
ajax.put("depts", sysDeptService.selectDeptTree());
|
||||
return ajax;
|
||||
}
|
||||
|
||||
//@PreAuthorize("hasAuthority('system:role:edit')")
|
||||
@PutMapping("/dataScope")
|
||||
public AjaxResult dataScope(@RequestBody DataScopeDto dto) {
|
||||
return AjaxResult.toAjax(sysRoleService.authDataScope(dto));
|
||||
}
|
||||
|
||||
//@PreAuthorize("hasAuthority('system:role:list')")
|
||||
@GetMapping("/authUser/allocatedList")
|
||||
public TableDataInfo allocatedList(SysUserParam param, PageQuery pageQuery) {
|
||||
return sysUserService.selectAllocatedList(param, pageQuery);
|
||||
}
|
||||
|
||||
//@PreAuthorize("hasAuthority('system:role:edit')")
|
||||
@PutMapping("/authUser/cancel")
|
||||
public AjaxResult cancelAuthUser(@RequestParam("roleId") String roleId, @RequestParam("userIds") List<String> userIds) {
|
||||
sysUserRoleService.deleteByRoleIdAndUserIds(roleId, userIds);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询未分配用户角色列表
|
||||
*/
|
||||
//@PreAuthorize("hasAuthority('system:role:list')")
|
||||
@GetMapping("/authUser/unallocatedList")
|
||||
public TableDataInfo unallocatedList(SysUserParam param, PageQuery pageQuery) {
|
||||
return sysUserService.selectUnAllocatedList(param, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量选择用户授权
|
||||
*/
|
||||
//@PreAuthorize("hasAuthority('system:role:edit')")
|
||||
@PutMapping("/authUser/insert")
|
||||
public AjaxResult insertAuthUsers(@RequestParam("roleId") String roleId, @RequestParam("userIds") List<String> userIds) {
|
||||
sysUserRoleService.insertAuthUsers(roleId, userIds);
|
||||
return AjaxResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,4 +22,12 @@ public interface SysDeptMapper extends BaseMapper<SysDept> {
|
||||
*/
|
||||
int checkDeptNameUnique(SysDept dept);
|
||||
|
||||
/**
|
||||
* 根据角色ID查询部门树信息
|
||||
*
|
||||
* @param roleId 角色ID
|
||||
* @return 选中部门列表
|
||||
*/
|
||||
List<String> selectDeptIdsByRoleId(String roleId);
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
package com.qiaoba.module.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.qiaoba.api.system.entity.SysRoleDept;
|
||||
|
||||
/**
|
||||
* 角色部门关联 数据层
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/5/9 9:50
|
||||
*/
|
||||
public interface SysRoleDeptMapper extends BaseMapper<SysRoleDept> {
|
||||
|
||||
/**
|
||||
* 通过角色ID批量删除角色和部门的绑定关系
|
||||
*
|
||||
* @param roleId 角色id
|
||||
*/
|
||||
void deleteByRoleId(String roleId);
|
||||
|
||||
}
|
@ -67,4 +67,22 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
|
||||
* @return list
|
||||
*/
|
||||
List<SysUserVo> selectVoList(@Param("param") SysUserParam param);
|
||||
|
||||
/**
|
||||
* 分页查询角色已绑定的用户列表
|
||||
*
|
||||
* @param page 分页信息
|
||||
* @param param 查询条件
|
||||
* @return list
|
||||
*/
|
||||
Page<SysUserVo> selectAllocatedList(Page page, @Param("param") SysUserParam param);
|
||||
|
||||
/**
|
||||
* 分页查询角色未绑定的用户列表
|
||||
*
|
||||
* @param page 分页信息
|
||||
* @param param 查询条件
|
||||
* @return list
|
||||
*/
|
||||
Page<SysUserVo> selectUnAllocatedList(Page page, @Param("param") SysUserParam param);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.qiaoba.module.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.qiaoba.api.system.entity.SysUserRole;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -21,4 +22,12 @@ public interface SysUserRoleMapper extends BaseMapper<SysUserRole> {
|
||||
* @return roleIds
|
||||
*/
|
||||
List<String> selectRoleIdsByUserId(String userId);
|
||||
|
||||
/**
|
||||
* 批量取消角色所绑定的用户
|
||||
*
|
||||
* @param roleId roleId
|
||||
* @param userIds userIds
|
||||
*/
|
||||
void deleteByRoleIdAndUserIds(@Param("roleId") String roleId, @Param("list") List<String> userIds);
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
package com.qiaoba.module.system.service;
|
||||
|
||||
import com.qiaoba.api.system.entity.SysRoleDept;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 角色部门关联 服务层
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/5/9 9:50
|
||||
*/
|
||||
public interface SysRoleDeptService {
|
||||
|
||||
/**
|
||||
* 批量新增
|
||||
*
|
||||
* @param list list
|
||||
*/
|
||||
void insertBatch(List<SysRoleDept> list);
|
||||
|
||||
/**
|
||||
* 通过角色ID批量删除角色和部门的绑定关系
|
||||
*
|
||||
* @param roleId 角色id
|
||||
*/
|
||||
void deleteByRoleId(String roleId);
|
||||
}
|
@ -27,6 +27,14 @@ public interface SysUserRoleService {
|
||||
*/
|
||||
void deleteByUserId(String userId);
|
||||
|
||||
/**
|
||||
* 批量取消角色所绑定的用户
|
||||
*
|
||||
* @param roleId roleId
|
||||
* @param userIds userIds
|
||||
*/
|
||||
void deleteByRoleIdAndUserIds(String roleId, List<String> userIds);
|
||||
|
||||
/**
|
||||
* 通过userId查询所绑定的角色ID列表
|
||||
*
|
||||
@ -34,4 +42,12 @@ public interface SysUserRoleService {
|
||||
* @return roleIds
|
||||
*/
|
||||
List<String> selectRoleIdsByUserId(String userId);
|
||||
|
||||
/**
|
||||
* 批量选择用户授权
|
||||
*
|
||||
* @param roleId roleId
|
||||
* @param userIds userIds
|
||||
*/
|
||||
void insertAuthUsers(String roleId, List<String> userIds);
|
||||
}
|
||||
|
@ -45,4 +45,21 @@ public interface SysUserService extends SysUserApiService {
|
||||
*/
|
||||
TableDataInfo<SysUserVo> selectVoPageList(SysUserParam param, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 分页查询角色已绑定的用户列表
|
||||
*
|
||||
* @param pageQuery 分页信息
|
||||
* @param param 查询条件
|
||||
* @return list
|
||||
*/
|
||||
TableDataInfo<SysUserVo> selectAllocatedList(SysUserParam param, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 分页查询角色未绑定的用户列表
|
||||
*
|
||||
* @param pageQuery 分页信息
|
||||
* @param param 查询条件
|
||||
* @return list
|
||||
*/
|
||||
TableDataInfo selectUnAllocatedList(SysUserParam param, PageQuery pageQuery);
|
||||
}
|
||||
|
@ -92,6 +92,22 @@ public class SysDeptServiceImpl implements SysDeptService {
|
||||
return sysDeptMapper.deleteById(deptId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Tree<String>> selectDeptTree() {
|
||||
List<SysDept> deptList = selectList(new SysDeptParam());
|
||||
TreeNodeConfig config = TreeNodeConfig.DEFAULT_CONFIG.setNameKey(BaseConstant.TREE_KEY_NAME);
|
||||
return TreeUtil.build(deptList, BaseConstant.DEFAULT_PARENT_ID_VALUE, config, (dept, tree) ->
|
||||
tree.setId(dept.getDeptId())
|
||||
.setParentId(dept.getParentId())
|
||||
.setName(dept.getDeptName())
|
||||
.setWeight(dept.getOrderNum()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> selectDeptIdsByRoleId(String roleId) {
|
||||
return sysDeptMapper.selectDeptIdsByRoleId(roleId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysDept> excludeChild(String deptId) {
|
||||
List<SysDept> deptList = selectList(new SysDeptParam());
|
||||
|
@ -0,0 +1,35 @@
|
||||
package com.qiaoba.module.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.toolkit.Db;
|
||||
import com.qiaoba.api.system.entity.SysRoleDept;
|
||||
import com.qiaoba.module.system.mapper.SysRoleDeptMapper;
|
||||
import com.qiaoba.module.system.service.SysRoleDeptService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 角色菜单关联 服务层实现
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/5/9 10:08
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SysRoleDeptServiceImpl implements SysRoleDeptService {
|
||||
|
||||
private final SysRoleDeptMapper sysRoleDeptMapper;
|
||||
|
||||
@Override
|
||||
public void insertBatch(List<SysRoleDept> list) {
|
||||
Db.saveBatch(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByRoleId(String roleId) {
|
||||
sysRoleDeptMapper.deleteByRoleId(roleId);
|
||||
}
|
||||
|
||||
}
|
@ -5,7 +5,9 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.qiaoba.api.system.entity.SysRole;
|
||||
import com.qiaoba.api.system.entity.SysRoleDept;
|
||||
import com.qiaoba.api.system.entity.SysRoleMenu;
|
||||
import com.qiaoba.api.system.entity.dto.DataScopeDto;
|
||||
import com.qiaoba.api.system.entity.dto.SysRoleDto;
|
||||
import com.qiaoba.api.system.entity.param.SysRoleParam;
|
||||
import com.qiaoba.common.base.exceptions.ServiceException;
|
||||
@ -13,6 +15,7 @@ import com.qiaoba.common.database.entity.PageQuery;
|
||||
import com.qiaoba.common.database.entity.TableDataInfo;
|
||||
import com.qiaoba.common.security.utils.SecurityUtil;
|
||||
import com.qiaoba.module.system.mapper.SysRoleMapper;
|
||||
import com.qiaoba.module.system.service.SysRoleDeptService;
|
||||
import com.qiaoba.module.system.service.SysRoleMenuService;
|
||||
import com.qiaoba.module.system.service.SysRoleService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -37,6 +40,7 @@ public class SysRoleServiceImpl implements SysRoleService {
|
||||
|
||||
private final SysRoleMapper sysRoleMapper;
|
||||
private final SysRoleMenuService sysRoleMenuService;
|
||||
private final SysRoleDeptService sysRoleDeptService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@ -82,11 +86,34 @@ public class SysRoleServiceImpl implements SysRoleService {
|
||||
return sysRoleMapper.deleteBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int authDataScope(DataScopeDto dto) {
|
||||
// 更新信息
|
||||
SysRole sysRole = BeanUtil.copyProperties(dto, SysRole.class);
|
||||
int row = sysRoleMapper.updateById(sysRole);
|
||||
// 删除绑定
|
||||
sysRoleDeptService.deleteByRoleId(sysRole.getRoleId());
|
||||
// 新增绑定
|
||||
if (CollUtil.isNotEmpty(dto.getDeptIds())) {
|
||||
List<SysRoleDept> list = new ArrayList<>();
|
||||
for (String deptId : dto.getDeptIds()) {
|
||||
list.add(new SysRoleDept(dto.getRoleId(), deptId));
|
||||
}
|
||||
sysRoleDeptService.insertBatch(list);
|
||||
}
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
private QueryWrapper<SysRole> param2Wrapper(SysRoleParam param) {
|
||||
QueryWrapper<SysRole> wrapper = new QueryWrapper<>();
|
||||
wrapper.lambda()
|
||||
.orderByAsc(SysRole::getRoleSort)
|
||||
.like(StrUtil.isNotBlank(param.getRoleName()), SysRole::getRoleName, param.getRoleName());
|
||||
.eq(StrUtil.isNotBlank(param.getStatus()), SysRole::getStatus, param.getStatus())
|
||||
.ge(StrUtil.isNotBlank(param.getBeginTime()), SysRole::getCreateTime, param.getBeginTime())
|
||||
.le(StrUtil.isNotBlank(param.getEndTime()), SysRole::getCreateTime, param.getEndTime())
|
||||
.like(StrUtil.isNotBlank(param.getRoleName()), SysRole::getRoleName, param.getRoleName())
|
||||
.like(StrUtil.isNotBlank(param.getRoleKey()), SysRole::getRoleKey, param.getRoleKey());
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import com.qiaoba.module.system.service.SysUserRoleService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -33,11 +34,25 @@ public class SysUserRoleServiceImpl implements SysUserRoleService {
|
||||
sysUserRoleMapper.delete(createWrapper(userId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByRoleIdAndUserIds(String roleId, List<String> userIds) {
|
||||
sysUserRoleMapper.deleteByRoleIdAndUserIds(roleId, userIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> selectRoleIdsByUserId(String userId) {
|
||||
return sysUserRoleMapper.selectRoleIdsByUserId(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertAuthUsers(String roleId, List<String> userIds) {
|
||||
List<SysUserRole> list = new ArrayList<>();
|
||||
for (String userId : userIds) {
|
||||
list.add(new SysUserRole(userId, roleId));
|
||||
}
|
||||
Db.saveBatch(list);
|
||||
}
|
||||
|
||||
private QueryWrapper<SysUserRole> createWrapper(String userId) {
|
||||
QueryWrapper<SysUserRole> wrapper = new QueryWrapper<>();
|
||||
wrapper.lambda()
|
||||
|
@ -109,6 +109,18 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
return TableDataInfo.build(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableDataInfo<SysUserVo> selectAllocatedList(SysUserParam param, PageQuery pageQuery) {
|
||||
Page<SysUserVo> page = sysUserMapper.selectAllocatedList(pageQuery.build(), param);
|
||||
return TableDataInfo.build(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableDataInfo selectUnAllocatedList(SysUserParam param, PageQuery pageQuery) {
|
||||
Page<SysUserVo> page = sysUserMapper.selectUnAllocatedList(pageQuery.build(), param);
|
||||
return TableDataInfo.build(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleUserRole(String userId, Set<String> roleIds, boolean isUpdate) {
|
||||
if (isUpdate) {
|
||||
|
@ -11,5 +11,12 @@
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
<select id="selectDeptIdsByRoleId" resultType="string">
|
||||
select d.dept_id
|
||||
from sys_dept d
|
||||
left join sys_role_dept rd on d.dept_id = rd.dept_id
|
||||
where rd.role_id = #{roleId}
|
||||
order by d.parent_id, d.order_num
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.qiaoba.module.system.mapper.SysRoleDeptMapper">
|
||||
|
||||
<delete id="deleteByRoleId">
|
||||
delete from sys_role_dept where role_id = #{roleId}
|
||||
</delete>
|
||||
</mapper>
|
@ -49,6 +49,41 @@
|
||||
<include refid="selectUserVo"/>
|
||||
</select>
|
||||
|
||||
<select id="selectAllocatedList" resultMap="SysUserVoResult">
|
||||
select distinct t1.user_id, t2.dept_name, t1.username, t1.nickname, t1.email, t1.phone, t1.status,t1.create_time
|
||||
from sys_user t1
|
||||
left join sys_dept t2
|
||||
on t1.dept_id = t2.dept_id
|
||||
left join sys_user_role t3
|
||||
on t1.user_id = t3.user_id
|
||||
left join sys_role t4
|
||||
on t4.role_id = t3.role_id
|
||||
where t1.is_delete = #{param.isDelete} and t4.role_id = #{param.roleId}
|
||||
<if test="param.username != null and param.username != ''">
|
||||
AND t1.username like concat('%', #{param.username}, '%')
|
||||
</if>
|
||||
<if test="param.phone != null and param.phone != ''">
|
||||
AND t1.phone like concat('%', #{param.phone}, '%')
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="selectUnAllocatedList" resultMap="SysUserVoResult">
|
||||
select distinct t1.user_id, t2.dept_name, t1.username, t1.nickname, t1.email, t1.phone, t1.status, t1.create_time
|
||||
from sys_user t1
|
||||
left join sys_dept t2 on t1.dept_id = t2.dept_id
|
||||
left join sys_user_role t3 on t1.user_id = t3.user_id
|
||||
left join sys_role t4 on t4.role_id = t3.role_id
|
||||
where t1.is_delete = #{param.isDelete} and (t4.role_id != #{param.roleId} or t4.role_id IS NULL)
|
||||
and t1.user_id not in (select t1.user_id from sys_user t1 inner join sys_user_role t3 on t1.user_id = t3.user_id and
|
||||
t3.role_id = #{param.roleId})
|
||||
<if test="param.username != null and param.username != ''">
|
||||
AND t1.username like concat('%', #{param.username}, '%')
|
||||
</if>
|
||||
<if test="param.phone != null and param.phone != ''">
|
||||
AND t1.phone like concat('%', #{param.phone}, '%')
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="selectVoList" resultMap="SysUserVoResult">
|
||||
<include refid="selectUserVo"/>
|
||||
</select>
|
||||
|
@ -8,4 +8,10 @@
|
||||
select role_id from sys_user_role where user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<delete id="deleteByRoleIdAndUserIds">
|
||||
delete from sys_user_role where role_id = #{roleId} and user_id in
|
||||
<foreach collection="list" item="userId" open="(" separator="," close=")">
|
||||
#{userId}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
|
Reference in New Issue
Block a user