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.common.ResponseCode;
|
||||
import com.cfive.pinnacle.entity.common.ResponseResult;
|
||||
import com.cfive.pinnacle.exception.DataValidationFailedException;
|
||||
import com.cfive.pinnacle.service.permission.IGroupService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
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.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -39,9 +41,20 @@ public class GroupController {
|
||||
|
||||
@Operation(summary = "获取所有用户组")
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAuthority('system:group:get' )")
|
||||
public ResponseResult<IPage<Group>> getAllGroup(Long currentPage, Long pageSize) {
|
||||
IPage<Group> groups = groupService.getAllGroup(currentPage, pageSize);
|
||||
@PreAuthorize("hasAuthority('system:group:get')")
|
||||
public ResponseResult<IPage<Group>> getAllGroup(Long currentPage, Long pageSize, String searchName, String searchRole, Integer searchEnable) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -50,12 +50,8 @@ public class RoleController {
|
||||
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));
|
||||
}
|
||||
for (String s : searchPowerStr) {
|
||||
searchPowerList.add(Long.parseLong(s));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -68,7 +64,7 @@ public class RoleController {
|
||||
|
||||
@Operation(summary = "获取角色列表")
|
||||
@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() {
|
||||
List<Role> roles = roleService.list();
|
||||
return ResponseResult.databaseSelectSuccess(roles);
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.util.List;
|
||||
*/
|
||||
@Mapper
|
||||
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);
|
||||
|
||||
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.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 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);
|
||||
|
||||
|
||||
@@ -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.Page;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
|
||||
import com.cfive.pinnacle.entity.permission.Group;
|
||||
@@ -16,6 +15,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -41,10 +41,25 @@ public class GroupServiceImpl extends ServiceImpl<GroupMapper, Group> implements
|
||||
}
|
||||
|
||||
@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);
|
||||
groupIPage = groupMapper.selectPage(groupIPage, Wrappers.emptyWrapper());
|
||||
groupIPage.setRecords(groupMapper.getAll(groupIPage.getRecords()));
|
||||
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()));
|
||||
}
|
||||
|
||||
|
||||
return groupIPage;
|
||||
}
|
||||
|
||||
@@ -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.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 distinct t_group.id as group_id,
|
||||
t_group.name as group_name,
|
||||
@@ -42,12 +64,15 @@
|
||||
and t_group.id = #{id}
|
||||
</select>
|
||||
|
||||
<resultMap id="groupMap" type="group">
|
||||
<resultMap id="groupBase" type="role">
|
||||
<id property="id" column="group_id"/>
|
||||
<result property="name" column="group_name"/>
|
||||
<result property="enable" column="group_enable"/>
|
||||
<result property="deleted" column="group_deleted"/>
|
||||
<result property="version" column="group_version"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="groupMap" type="group" extends="groupBase">
|
||||
<collection property="roles" ofType="role">
|
||||
<id property="id" column="role_id"/>
|
||||
<result property="name" column="role_name"/>
|
||||
|
||||
Reference in New Issue
Block a user