mirror of
https://github.com/FatttSnake/Pinnacle-OA.git
synced 2026-04-05 23:11:24 +08:00
Added search in GroupManagement. Optimized RoleController.
This commit is contained in:
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|||||||
import com.cfive.pinnacle.entity.permission.Group;
|
import com.cfive.pinnacle.entity.permission.Group;
|
||||||
import com.cfive.pinnacle.entity.common.ResponseCode;
|
import com.cfive.pinnacle.entity.common.ResponseCode;
|
||||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||||
|
import com.cfive.pinnacle.exception.DataValidationFailedException;
|
||||||
import com.cfive.pinnacle.service.permission.IGroupService;
|
import com.cfive.pinnacle.service.permission.IGroupService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
@@ -16,6 +17,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
|||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,8 +42,19 @@ public class GroupController {
|
|||||||
@Operation(summary = "获取所有用户组")
|
@Operation(summary = "获取所有用户组")
|
||||||
@GetMapping
|
@GetMapping
|
||||||
@PreAuthorize("hasAuthority('system:group:get')")
|
@PreAuthorize("hasAuthority('system:group:get')")
|
||||||
public ResponseResult<IPage<Group>> getAllGroup(Long currentPage, Long pageSize) {
|
public ResponseResult<IPage<Group>> getAllGroup(Long currentPage, Long pageSize, String searchName, String searchRole, Integer searchEnable) {
|
||||||
IPage<Group> groups = groupService.getAllGroup(currentPage, pageSize);
|
List<Long> searchRoleList = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
if (searchRole != null && !searchRole.isBlank()) {
|
||||||
|
String[] searchRoleStr = searchRole.split(",");
|
||||||
|
for (String s : searchRoleStr) {
|
||||||
|
searchRoleList.add(Long.parseLong(s));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new DataValidationFailedException();
|
||||||
|
}
|
||||||
|
IPage<Group> groups = groupService.getAllGroup(currentPage, pageSize, searchName, searchRoleList, searchEnable);
|
||||||
return ResponseResult.databaseSelectSuccess(groups);
|
return ResponseResult.databaseSelectSuccess(groups);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,14 +50,10 @@ public class RoleController {
|
|||||||
try {
|
try {
|
||||||
if (searchPower != null && !searchPower.isBlank()) {
|
if (searchPower != null && !searchPower.isBlank()) {
|
||||||
String[] searchPowerStr = searchPower.split(",");
|
String[] searchPowerStr = searchPower.split(",");
|
||||||
if (searchPowerStr.length == 1) {
|
|
||||||
searchPowerList.add(Long.parseLong(searchPowerStr[0]));
|
|
||||||
} else {
|
|
||||||
for (String s : searchPowerStr) {
|
for (String s : searchPowerStr) {
|
||||||
searchPowerList.add(Long.parseLong(s));
|
searchPowerList.add(Long.parseLong(s));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new DataValidationFailedException();
|
throw new DataValidationFailedException();
|
||||||
}
|
}
|
||||||
@@ -68,7 +64,7 @@ public class RoleController {
|
|||||||
|
|
||||||
@Operation(summary = "获取角色列表")
|
@Operation(summary = "获取角色列表")
|
||||||
@GetMapping("list")
|
@GetMapping("list")
|
||||||
@PreAuthorize("hasAnyAuthority('system:group:add', 'system:group:modify', 'system:user:add', 'system:user:modify')")
|
@PreAuthorize("hasAnyAuthority('system:group:get', 'system:group:add', 'system:group:modify', 'system:user:add', 'system:user:modify')")
|
||||||
public ResponseResult<List<Role>> getRoleList() {
|
public ResponseResult<List<Role>> getRoleList() {
|
||||||
List<Role> roles = roleService.list();
|
List<Role> roles = roleService.list();
|
||||||
return ResponseResult.databaseSelectSuccess(roles);
|
return ResponseResult.databaseSelectSuccess(roles);
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface GroupMapper extends BaseMapper<Group> {
|
public interface GroupMapper extends BaseMapper<Group> {
|
||||||
|
List<Long> filterGroupByRoleId(@Param("groupList") List<Long> groupList, @Param("roleId") Long roleId, String searchName, Integer searchEnable);
|
||||||
List<Group> getAll(@Param("groupList") List<Group> groupList);
|
List<Group> getAll(@Param("groupList") List<Group> groupList);
|
||||||
|
|
||||||
Group getOneById(@Param("id") long id);
|
Group getOneById(@Param("id") long id);
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|||||||
import com.cfive.pinnacle.entity.permission.Group;
|
import com.cfive.pinnacle.entity.permission.Group;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* 用户组 服务类
|
* 用户组 服务类
|
||||||
@@ -13,7 +15,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
|||||||
* @since 2023-04-30
|
* @since 2023-04-30
|
||||||
*/
|
*/
|
||||||
public interface IGroupService extends IService<Group> {
|
public interface IGroupService extends IService<Group> {
|
||||||
IPage<Group> getAllGroup(Long currentPage, Long pageSize);
|
IPage<Group> getAllGroup(Long currentPage, Long pageSize, String searchName, List<Long> searchRole, Integer searchEnable);
|
||||||
|
|
||||||
Group getGroup(Long id);
|
Group getGroup(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.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
|
||||||
import com.cfive.pinnacle.entity.permission.Group;
|
import com.cfive.pinnacle.entity.permission.Group;
|
||||||
@@ -16,6 +15,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -41,10 +41,25 @@ public class GroupServiceImpl extends ServiceImpl<GroupMapper, Group> implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IPage<Group> getAllGroup(Long currentPage, Long pageSize) {
|
public IPage<Group> getAllGroup(Long currentPage, Long pageSize, String searchName, List<Long> searchRole, Integer searchEnable) {
|
||||||
Page<Group> groupIPage = PageDTO.of(currentPage, pageSize);
|
Page<Group> groupIPage = PageDTO.of(currentPage, pageSize);
|
||||||
groupIPage = groupMapper.selectPage(groupIPage, Wrappers.emptyWrapper());
|
searchName = searchName.trim();
|
||||||
|
List<Long> groupList = groupMapper.filterGroupByRoleId(null, null, searchName, searchEnable);
|
||||||
|
if (searchRole.size() > 0) {
|
||||||
|
for (Long roleId : searchRole) {
|
||||||
|
groupList = groupMapper.filterGroupByRoleId(groupList, roleId, null, null);
|
||||||
|
if (groupList.size() == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (groupList.size() > 0) {
|
||||||
|
LambdaQueryWrapper<Group> wrapper = new LambdaQueryWrapper<Group>().in(Group::getId, groupList);
|
||||||
|
groupIPage = groupMapper.selectPage(groupIPage, wrapper);
|
||||||
groupIPage.setRecords(groupMapper.getAll(groupIPage.getRecords()));
|
groupIPage.setRecords(groupMapper.getAll(groupIPage.getRecords()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return groupIPage;
|
return groupIPage;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,28 @@
|
|||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
<!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.GroupMapper">
|
<mapper namespace="com.cfive.pinnacle.mapper.permission.GroupMapper">
|
||||||
|
|
||||||
|
<select id="filterGroupByRoleId" resultType="long">
|
||||||
|
select distinct t_group.id as group_id
|
||||||
|
from (select * from t_group where deleted = 0) as t_group
|
||||||
|
left join (select * from t_role_group where deleted = 0) as trg on t_group.id = trg.group_id
|
||||||
|
left join (select * from t_role where deleted = 0) as tr on tr.id = trg.role_id
|
||||||
|
<where>
|
||||||
|
<if test="roleId != null">
|
||||||
|
tr.id = #{roleId}
|
||||||
|
</if>
|
||||||
|
<foreach collection="groupList" item="item" index="index" open="and t_group.id in (" separator="," close=")"
|
||||||
|
nullable="true">
|
||||||
|
#{item}
|
||||||
|
</foreach>
|
||||||
|
<if test="searchName != null and searchName != ''">
|
||||||
|
and instr(t_group.name, #{searchName}) > 0
|
||||||
|
</if>
|
||||||
|
<if test="searchEnable != null and searchEnable != -1">
|
||||||
|
and t_group.enable = #{searchEnable}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
<select id="getAll" resultMap="groupMap">
|
<select id="getAll" resultMap="groupMap">
|
||||||
select distinct t_group.id as group_id,
|
select distinct t_group.id as group_id,
|
||||||
t_group.name as group_name,
|
t_group.name as group_name,
|
||||||
@@ -42,12 +64,15 @@
|
|||||||
and t_group.id = #{id}
|
and t_group.id = #{id}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<resultMap id="groupMap" type="group">
|
<resultMap id="groupBase" type="role">
|
||||||
<id property="id" column="group_id"/>
|
<id property="id" column="group_id"/>
|
||||||
<result property="name" column="group_name"/>
|
<result property="name" column="group_name"/>
|
||||||
<result property="enable" column="group_enable"/>
|
<result property="enable" column="group_enable"/>
|
||||||
<result property="deleted" column="group_deleted"/>
|
<result property="deleted" column="group_deleted"/>
|
||||||
<result property="version" column="group_version"/>
|
<result property="version" column="group_version"/>
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<resultMap id="groupMap" type="group" extends="groupBase">
|
||||||
<collection property="roles" ofType="role">
|
<collection property="roles" ofType="role">
|
||||||
<id property="id" column="role_id"/>
|
<id property="id" column="role_id"/>
|
||||||
<result property="name" column="role_name"/>
|
<result property="name" column="role_name"/>
|
||||||
|
|||||||
@@ -1,19 +1,71 @@
|
|||||||
<template>
|
<template>
|
||||||
<el-button bg style="background-color: white" :loading="tableLoading" @click="loadGroupTable">
|
<el-row :gutter="5">
|
||||||
|
<el-col :span="-1">
|
||||||
|
<el-button
|
||||||
|
bg
|
||||||
|
style="background-color: white"
|
||||||
|
:loading="tableLoading"
|
||||||
|
@click="loadGroupTable"
|
||||||
|
>
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<el-icon>
|
<el-icon>
|
||||||
<icon-pinnacle-refresh />
|
<icon-pinnacle-refresh />
|
||||||
</el-icon>
|
</el-icon>
|
||||||
</template>
|
</template>
|
||||||
</el-button>
|
</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="-1">
|
||||||
<el-button type="primary" @click="handleAddBtn">
|
<el-button type="primary" @click="handleAddBtn">
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<el-icon>
|
<el-icon>
|
||||||
<icon-pinnacle-plus />
|
<icon-pinnacle-plus />
|
||||||
</el-icon>
|
</el-icon>
|
||||||
</template>
|
</template>
|
||||||
<template #default> 添加 </template>
|
|
||||||
</el-button>
|
</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="5">
|
||||||
|
<el-form-item label="名称" class="fill-with">
|
||||||
|
<el-input
|
||||||
|
v-model="inputName"
|
||||||
|
maxlength="30"
|
||||||
|
show-word-limit
|
||||||
|
placeholder="请输入内容"
|
||||||
|
@keyup.enter="handleQuery"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="9">
|
||||||
|
<el-select
|
||||||
|
v-model="selectedRole"
|
||||||
|
class="fill-with"
|
||||||
|
clearable
|
||||||
|
collapse-tags
|
||||||
|
collapse-tags-tooltip
|
||||||
|
multiple
|
||||||
|
filterable
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="item in roleOptions"
|
||||||
|
:key="item.id"
|
||||||
|
:value="item.id"
|
||||||
|
:label="item.name"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</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
|
<common-table
|
||||||
:table-date="groupTable"
|
:table-date="groupTable"
|
||||||
:table-loading="tableLoading"
|
:table-loading="tableLoading"
|
||||||
@@ -106,6 +158,13 @@ export default {
|
|||||||
dialogVisible: false,
|
dialogVisible: false,
|
||||||
tableLoading: true,
|
tableLoading: true,
|
||||||
dialogLoading: true,
|
dialogLoading: true,
|
||||||
|
roleOptions: [],
|
||||||
|
searchName: '',
|
||||||
|
searchRole: [],
|
||||||
|
searchEnable: -1,
|
||||||
|
inputName: '',
|
||||||
|
selectedRole: [],
|
||||||
|
selectedEnable: -1,
|
||||||
currentPage: 1,
|
currentPage: 1,
|
||||||
pageSize: 50,
|
pageSize: 50,
|
||||||
totalCount: 0,
|
totalCount: 0,
|
||||||
@@ -133,7 +192,13 @@ export default {
|
|||||||
loadGroupTable() {
|
loadGroupTable() {
|
||||||
this.tableLoading = true
|
this.tableLoading = true
|
||||||
request
|
request
|
||||||
.get('/group', { currentPage: this.currentPage, pageSize: this.pageSize })
|
.get('/group', {
|
||||||
|
currentPage: this.currentPage,
|
||||||
|
pageSize: this.pageSize,
|
||||||
|
searchName: this.searchName,
|
||||||
|
searchRole: this.searchRole + '',
|
||||||
|
searchEnable: this.searchEnable
|
||||||
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
const response = res.data
|
const response = res.data
|
||||||
if (response.code === DATABASE_SELECT_OK) {
|
if (response.code === DATABASE_SELECT_OK) {
|
||||||
@@ -177,6 +242,7 @@ export default {
|
|||||||
request.get('/role/list').then((res) => {
|
request.get('/role/list').then((res) => {
|
||||||
const response = res.data
|
const response = res.data
|
||||||
if (response.code === DATABASE_SELECT_OK) {
|
if (response.code === DATABASE_SELECT_OK) {
|
||||||
|
this.roleOptions = response.data
|
||||||
this.roles = response.data
|
this.roles = response.data
|
||||||
this.dialogLoading = false
|
this.dialogLoading = false
|
||||||
} else {
|
} else {
|
||||||
@@ -291,10 +357,23 @@ export default {
|
|||||||
handleCurrentChange(currentPage) {
|
handleCurrentChange(currentPage) {
|
||||||
this.currentPage = currentPage
|
this.currentPage = currentPage
|
||||||
this.loadGroupTable()
|
this.loadGroupTable()
|
||||||
|
},
|
||||||
|
handleQuery() {
|
||||||
|
this.searchName = this.inputName
|
||||||
|
this.searchRole = this.selectedRole
|
||||||
|
this.searchEnable = this.selectedEnable
|
||||||
|
this.loadGroupTable()
|
||||||
|
},
|
||||||
|
handleClear() {
|
||||||
|
this.inputName = ''
|
||||||
|
this.selectedRole = []
|
||||||
|
this.selectedEnable = -1
|
||||||
|
this.handleQuery()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.loadGroupTable()
|
this.loadGroupTable()
|
||||||
|
this.getRoles()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -257,7 +257,7 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
handleDialogOpen() {
|
handleDialogOpen() {
|
||||||
this.getPowerTree()
|
this.getPowers()
|
||||||
|
|
||||||
if (this.isAddNew) {
|
if (this.isAddNew) {
|
||||||
this.defaultSelectedPower = []
|
this.defaultSelectedPower = []
|
||||||
@@ -269,7 +269,7 @@ export default {
|
|||||||
this.dialogTitle = '编辑角色'
|
this.dialogTitle = '编辑角色'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getPowerTree() {
|
getPowers() {
|
||||||
this.dialogLoading = true
|
this.dialogLoading = true
|
||||||
request.get('/power').then((res) => {
|
request.get('/power').then((res) => {
|
||||||
const response = res.data
|
const response = res.data
|
||||||
@@ -297,6 +297,7 @@ export default {
|
|||||||
menu.children = menu.children[0].children
|
menu.children = menu.children[0].children
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.powerOptions = data.menuList
|
||||||
this.powerTree = data.menuList
|
this.powerTree = data.menuList
|
||||||
this.dialogLoading = false
|
this.dialogLoading = false
|
||||||
} else {
|
} else {
|
||||||
@@ -307,42 +308,6 @@ export default {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
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) {
|
handleTreeSelectedPowerChange(data, checked, indeterminate) {
|
||||||
if (data.children === undefined) {
|
if (data.children === undefined) {
|
||||||
if (checked || indeterminate) {
|
if (checked || indeterminate) {
|
||||||
@@ -479,7 +444,7 @@ export default {
|
|||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.loadRoleTable()
|
this.loadRoleTable()
|
||||||
this.getPowerOptions()
|
this.getPowers()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user