mirror of
https://github.com/FatttSnake/Pinnacle-OA.git
synced 2026-04-05 23:11:24 +08:00
Added search in RoleManagement
This commit is contained in:
@@ -32,7 +32,7 @@ public class PowerController {
|
||||
|
||||
@Operation(summary = "获取所有权限")
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAnyAuthority('system:role:add', 'system:role:modify')")
|
||||
@PreAuthorize("hasAnyAuthority('system:role:get','system:role:add', 'system:role:modify')")
|
||||
public ResponseResult<PowerSet> getAllPower() {
|
||||
PowerSet powerSet = powerService.getAllPower();
|
||||
|
||||
|
||||
@@ -5,17 +5,20 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.cfive.pinnacle.entity.permission.Role;
|
||||
import com.cfive.pinnacle.entity.common.ResponseCode;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.exception.DataValidationFailedException;
|
||||
import com.cfive.pinnacle.service.permission.IRoleService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -26,6 +29,7 @@ import java.util.List;
|
||||
* @author FatttSnake
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/role")
|
||||
@Tag(name = "角色", description = "角色相关接口")
|
||||
@@ -41,8 +45,24 @@ public class RoleController {
|
||||
@Operation(summary = "获取所有角色")
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAuthority('system:role:get')")
|
||||
public ResponseResult<IPage<Role>> getAllRole(Long currentPage, Long pageSize) {
|
||||
IPage<Role> roles = roleService.getAllRole(currentPage, pageSize);
|
||||
public ResponseResult<IPage<Role>> getAllRole(Long currentPage, Long pageSize, String searchName, String searchPower, Integer searchEnable) {
|
||||
List<Long> searchPowerList = new ArrayList<>();
|
||||
try {
|
||||
if (searchPower != null && !searchPower.isBlank()) {
|
||||
String[] searchPowerStr = searchPower.split(",");
|
||||
if (searchPowerStr.length == 1) {
|
||||
searchPowerList.add(Long.parseLong(searchPowerStr[0]));
|
||||
} else {
|
||||
for (String s : searchPowerStr) {
|
||||
searchPowerList.add(Long.parseLong(s));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new DataValidationFailedException();
|
||||
}
|
||||
|
||||
IPage<Role> roles = roleService.getAllRole(currentPage, pageSize, searchName, searchPowerList, searchEnable);
|
||||
return ResponseResult.databaseSelectSuccess(roles);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ import java.util.List;
|
||||
*/
|
||||
@Mapper
|
||||
public interface RoleMapper extends BaseMapper<Role> {
|
||||
List<Long> filterRoleByPowerId(@Param("roleList") List<Long> roleList, @Param("powerId") Long powerId, String searchName, Integer searchEnable);
|
||||
|
||||
List<Role> getAll(@Param("roleList") List<Role> roleList);
|
||||
|
||||
Role getOneById(@Param("id") long id);
|
||||
|
||||
@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.cfive.pinnacle.entity.permission.Role;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 角色 服务类
|
||||
@@ -13,7 +15,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
public interface IRoleService extends IService<Role> {
|
||||
IPage<Role> getAllRole(Long currentPage, Long pageSize);
|
||||
IPage<Role> getAllRole(Long currentPage, Long pageSize, String searchName, List<Long> searchPower, Integer searchEnable);
|
||||
|
||||
Role getRole(long id);
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.cfive.pinnacle.service.permission.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
|
||||
import com.cfive.pinnacle.entity.permission.*;
|
||||
import com.cfive.pinnacle.exception.DataValidationFailedException;
|
||||
@@ -10,6 +9,7 @@ import com.cfive.pinnacle.mapper.permission.RoleMapper;
|
||||
import com.cfive.pinnacle.mapper.permission.PowerRoleMapper;
|
||||
import com.cfive.pinnacle.service.permission.IRoleService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -26,6 +26,7 @@ import java.util.Set;
|
||||
* @author FatttSnake
|
||||
* @since 2023-04-30
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {
|
||||
|
||||
@@ -43,10 +44,24 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IR
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<Role> getAllRole(Long currentPage, Long pageSize) {
|
||||
public IPage<Role> getAllRole(Long currentPage, Long pageSize, String searchName, List<Long> searchPower, Integer searchEnable) {
|
||||
IPage<Role> roleIPage = PageDTO.of(currentPage, pageSize);
|
||||
roleIPage = roleMapper.selectPage(roleIPage, Wrappers.emptyWrapper());
|
||||
roleIPage.setRecords(roleMapper.getAll(roleIPage.getRecords()));
|
||||
searchName = searchName.trim();
|
||||
List<Long> roleList = roleMapper.filterRoleByPowerId(null, null, searchName, searchEnable);
|
||||
if (searchPower.size() > 0) {
|
||||
for (Long powerId : searchPower) {
|
||||
roleList = roleMapper.filterRoleByPowerId(roleList, powerId, null, null);
|
||||
if (roleList.size() == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (roleList.size() > 0) {
|
||||
LambdaQueryWrapper<Role> wrapper = new LambdaQueryWrapper<Role>().in(Role::getId, roleList);
|
||||
roleIPage = roleMapper.selectPage(roleIPage, wrapper);
|
||||
roleIPage.setRecords(roleMapper.getAll(roleIPage.getRecords()));
|
||||
}
|
||||
|
||||
return roleIPage;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,28 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.cfive.pinnacle.mapper.permission.RoleMapper">
|
||||
|
||||
<select id="filterRoleByPowerId" resultType="long">
|
||||
select distinct t_role.id as role_id
|
||||
from (select * from t_role where deleted = 0) as t_role
|
||||
left join (select * from t_power_role where deleted = 0) as tpr on t_role.id = tpr.role_id
|
||||
left join t_power tp on tp.id = tpr.power_id
|
||||
<where>
|
||||
<if test="powerId != null">
|
||||
tp.id = #{powerId}
|
||||
</if>
|
||||
<foreach collection="roleList" item="item" index="index" open="and t_role.id in (" separator="," close=")"
|
||||
nullable="true">
|
||||
#{item}
|
||||
</foreach>
|
||||
<if test="searchName != null and searchName != ''">
|
||||
and instr(t_role.name, #{searchName}) > 0
|
||||
</if>
|
||||
<if test="searchEnable != null and searchEnable != -1">
|
||||
and t_role.enable = #{searchEnable}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="getAll" resultMap="roleMap">
|
||||
select distinct t_role.id as role_id,
|
||||
t_role.name as role_name,
|
||||
|
||||
Reference in New Issue
Block a user