mirror of
https://github.com/FatttSnake/Pinnacle-OA.git
synced 2026-04-05 15:01:23 +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,
|
||||
|
||||
@@ -56,8 +56,10 @@
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-button type="primary" @click="handleQuery">查询</el-button>
|
||||
<el-button @click="handleClear">清空</el-button>
|
||||
<el-col span="-1">
|
||||
<el-button type="primary" @click="handleQuery">查询</el-button>
|
||||
<el-button @click="handleClear">清空</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-table
|
||||
@@ -319,6 +321,7 @@ export default {
|
||||
this.inputInput = ''
|
||||
this.selectedGender = -1
|
||||
this.selectedBirth = []
|
||||
this.currentPage = 1
|
||||
this.handleQuery()
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,19 +1,68 @@
|
||||
<template>
|
||||
<el-button bg style="background-color: white" :loading="tableLoading" @click="loadRoleTable">
|
||||
<template #icon>
|
||||
<el-icon>
|
||||
<icon-pinnacle-refresh />
|
||||
</el-icon>
|
||||
</template>
|
||||
</el-button>
|
||||
<el-button type="primary" @click="handleAddBtn">
|
||||
<template #icon>
|
||||
<el-icon>
|
||||
<icon-pinnacle-plus />
|
||||
</el-icon>
|
||||
</template>
|
||||
<template #default> 添加</template>
|
||||
</el-button>
|
||||
<el-row :gutter="10">
|
||||
<el-col :span="-1">
|
||||
<el-button
|
||||
bg
|
||||
style="background-color: white"
|
||||
:loading="tableLoading"
|
||||
@click="loadRoleTable"
|
||||
>
|
||||
<template #icon>
|
||||
<el-icon>
|
||||
<icon-pinnacle-refresh />
|
||||
</el-icon>
|
||||
</template>
|
||||
</el-button>
|
||||
</el-col>
|
||||
<el-col :span="-1">
|
||||
<el-button type="primary" @click="handleAddBtn">
|
||||
<template #icon>
|
||||
<el-icon>
|
||||
<icon-pinnacle-plus />
|
||||
</el-icon>
|
||||
</template>
|
||||
<template #default> 添加</template>
|
||||
</el-button>
|
||||
</el-col>
|
||||
<el-col :span="5">
|
||||
<el-form-item label="名称" class="fill-with">
|
||||
<el-input
|
||||
v-model="inputName"
|
||||
maxlength="20"
|
||||
show-word-limit
|
||||
placeholder="请输入内容"
|
||||
@keyup.enter="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="9">
|
||||
<el-form-item label="权限" class="fill-with">
|
||||
<el-cascader
|
||||
:options="powerOptions"
|
||||
v-model="selectedPower"
|
||||
:props="powerOptionProps"
|
||||
class="fill-with"
|
||||
clearable
|
||||
collapse-tags
|
||||
collapse-tags-tooltip
|
||||
filterable
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="3">
|
||||
<el-form-item label="状态" class="fill-with">
|
||||
<el-select v-model="selectedEnable" class="fill-with">
|
||||
<el-option label="全部" :value="-1" />
|
||||
<el-option label="启用" :value="1" />
|
||||
<el-option label="禁用" :value="0" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="-1">
|
||||
<el-button type="primary" @click="handleQuery">查询</el-button>
|
||||
<el-button @click="handleClear">清空</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<common-table
|
||||
:table-date="roleTable"
|
||||
:table-loading="tableLoading"
|
||||
@@ -73,12 +122,12 @@
|
||||
<el-tree
|
||||
:data="powerTree"
|
||||
node-key="powerId"
|
||||
:props="powerProps"
|
||||
:props="powerTreeProps"
|
||||
show-checkbox
|
||||
:render-after-expand="false"
|
||||
:default-checked-keys="defaultSelectedPower"
|
||||
style="min-width: 120px"
|
||||
@check-change="handleSelectedPowerChange"
|
||||
@check-change="handleTreeSelectedPowerChange"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
@@ -111,12 +160,27 @@ export default {
|
||||
dialogVisible: false,
|
||||
tableLoading: true,
|
||||
dialogLoading: true,
|
||||
powerOptions: [],
|
||||
searchName: '',
|
||||
searchPower: [],
|
||||
searchEnable: -1,
|
||||
inputName: '',
|
||||
selectedPower: [],
|
||||
selectedEnable: -1,
|
||||
currentPage: 1,
|
||||
pageSize: 50,
|
||||
totalCount: 0,
|
||||
roleTable: [],
|
||||
powerTree: [],
|
||||
powerProps: {
|
||||
powerOptionProps: {
|
||||
expandTrigger: 'hover',
|
||||
multiple: true,
|
||||
label: 'name',
|
||||
value: 'powerId',
|
||||
children: 'children',
|
||||
emitPath: false
|
||||
},
|
||||
powerTreeProps: {
|
||||
label: 'name',
|
||||
children: 'children'
|
||||
},
|
||||
@@ -143,7 +207,13 @@ export default {
|
||||
loadRoleTable() {
|
||||
this.tableLoading = true
|
||||
request
|
||||
.get('/role', { currentPage: this.currentPage, pageSize: this.pageSize })
|
||||
.get('/role', {
|
||||
currentPage: this.currentPage,
|
||||
pageSize: this.pageSize,
|
||||
searchName: this.searchName,
|
||||
searchPower: this.searchPower + '',
|
||||
searchEnable: this.searchEnable
|
||||
})
|
||||
.then((res) => {
|
||||
const response = res.data
|
||||
if (response.code === DATABASE_SELECT_OK) {
|
||||
@@ -238,7 +308,43 @@ export default {
|
||||
}
|
||||
})
|
||||
},
|
||||
handleSelectedPowerChange(data, checked, indeterminate) {
|
||||
getPowerOptions() {
|
||||
request.get('/power').then((res) => {
|
||||
const response = res.data
|
||||
if (response.code === DATABASE_SELECT_OK) {
|
||||
const data = response.data
|
||||
const menuList = data.menuList
|
||||
const elementList = data.elementList
|
||||
const operationList = data.operationList
|
||||
for (const operation of operationList) {
|
||||
const element = _.find(elementList, { id: operation.elementId })
|
||||
if (element.children === undefined) {
|
||||
element.children = []
|
||||
}
|
||||
element.children.push(operation)
|
||||
}
|
||||
for (const element of elementList) {
|
||||
const menu = _.find(menuList, { id: element.menuId })
|
||||
if (menu.children === undefined) {
|
||||
menu.children = []
|
||||
}
|
||||
menu.children.push(element)
|
||||
}
|
||||
for (const menu of menuList) {
|
||||
if (menu.children.length === 1) {
|
||||
menu.children = menu.children[0].children
|
||||
}
|
||||
}
|
||||
this.powerOptions = data.menuList
|
||||
} else {
|
||||
ElMessage.error({
|
||||
dangerouslyUseHTMLString: true,
|
||||
message: '<strong>查询出错</strong>: ' + response.msg
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
handleTreeSelectedPowerChange(data, checked, indeterminate) {
|
||||
if (data.children === undefined) {
|
||||
if (checked || indeterminate) {
|
||||
this.roleForm.selectedPower.add(data.powerId)
|
||||
@@ -357,10 +463,24 @@ export default {
|
||||
handleCurrentChange(currentPage) {
|
||||
this.currentPage = currentPage
|
||||
this.loadRoleTable()
|
||||
},
|
||||
handleQuery() {
|
||||
this.searchName = _.cloneDeep(this.inputName)
|
||||
this.searchPower = _.cloneDeep(this.selectedPower)
|
||||
this.searchEnable = _.cloneDeep(this.selectedEnable)
|
||||
this.loadRoleTable()
|
||||
},
|
||||
handleClear() {
|
||||
this.inputName = ''
|
||||
this.selectedPower = []
|
||||
this.selectedEnable = -1
|
||||
this.currentPage = 1
|
||||
this.handleQuery()
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.loadRoleTable()
|
||||
this.getPowerOptions()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user