update 分页查询
This commit is contained in:
parent
a174cb255f
commit
211bdd47a6
|
|
@ -8,6 +8,9 @@ public class CommonConstant {
|
|||
// 删除状态
|
||||
public static final Integer DEL_FLAG_NORMAL = 0;
|
||||
public static final Integer DEL_FLAG_DELETED = 1;
|
||||
// 分页
|
||||
public static final Integer PAGE_NUM = 1;
|
||||
public static final Integer PAGE_SIZE = 10;
|
||||
|
||||
// JWT相关常量
|
||||
public static final String JWT_HEADER = "Authorization";
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.tacit.common.entity;
|
|||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import lombok.Data;
|
||||
|
||||
|
|
@ -14,4 +15,8 @@ public class Base implements Serializable {
|
|||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
private Integer delFlag;
|
||||
@TableField(exist = false)
|
||||
private Integer pageNum;
|
||||
@TableField(exist = false)
|
||||
private Integer pageSize;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.tacit.admin.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.tacit.admin.entity.Role;
|
||||
import com.tacit.admin.service.RoleService;
|
||||
import com.tacit.common.entity.ResponseResult;
|
||||
|
|
@ -16,6 +17,13 @@ import java.util.List;
|
|||
public class RoleController {
|
||||
@Resource
|
||||
private RoleService roleService;
|
||||
|
||||
@Operation(summary = "角色分页", description = "角色分页")
|
||||
@GetMapping("/page")
|
||||
public ResponseResult<Page<Role>> getRolePage(@RequestBody Role role) {
|
||||
Page<Role> page = roleService.getRolePage(role);
|
||||
return ResponseResult.success(page);
|
||||
}
|
||||
//新增角色
|
||||
@Operation(summary = "创建角色", description = "创建角色")
|
||||
@PostMapping("/create")
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import com.tacit.common.entity.ResponseResult;
|
|||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.*;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
|
@ -19,6 +19,13 @@ public class UserController {
|
|||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
@Operation(summary = "分页查询用户列表", description = "分页查询用户列表")
|
||||
@GetMapping("/page")
|
||||
public ResponseResult<Page<User>> getUserList(@RequestBody User user) {
|
||||
Page<User> page = userService.getUserPage(user);
|
||||
return ResponseResult.success(page);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取所有用户", description = "获取系统中所有用户列表")
|
||||
@GetMapping("/list")
|
||||
public ResponseResult<List<User>> getAllUsers() {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.tacit.admin.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.tacit.admin.entity.Role;
|
||||
|
||||
|
|
@ -18,6 +19,8 @@ public interface RoleService extends IService<Role> {
|
|||
boolean deleteRole(Long id);
|
||||
|
||||
List<Role> getRoleList(Role role);
|
||||
|
||||
Page<Role> getRolePage(Role role);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.tacit.admin.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.tacit.admin.entity.User;
|
||||
import com.tacit.admin.entity.dto.LoginRequest;
|
||||
|
|
@ -29,6 +30,13 @@ public interface UserService extends IService<User> {
|
|||
*/
|
||||
List<User> getAllUsers();
|
||||
|
||||
/**
|
||||
* 分页查询用户列表
|
||||
* @param user 查询条件
|
||||
* @return 分页查询结果
|
||||
*/
|
||||
Page<User> getUserPage(User user);
|
||||
|
||||
/**
|
||||
* 创建用户
|
||||
* @param user 用户信息
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import com.tacit.admin.mapper.RoleMenuMapper;
|
|||
import com.tacit.admin.mapper.UserRoleMapper;
|
||||
import com.tacit.admin.service.MenuService;
|
||||
import com.tacit.admin.service.RoleService;
|
||||
import com.tacit.common.constant.CommonConstant;
|
||||
import com.tacit.common.exception.BusinessException;
|
||||
import com.tacit.common.redis.utils.RedisUtils;
|
||||
import com.tacit.common.utils.ResCode;
|
||||
|
|
@ -43,7 +44,7 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
|||
List<Long> menuIdList = roleMenuList.stream().map(RoleMenu::getMenuId).collect(Collectors.toList());
|
||||
// 根据菜单ids获取没删除的菜单列表
|
||||
QueryWrapper<Menu> menuQueryWrapper = new QueryWrapper<>();
|
||||
menuQueryWrapper.eq("del_flag", 0);
|
||||
menuQueryWrapper.eq("del_flag", CommonConstant.DEL_FLAG_NORMAL);
|
||||
menuQueryWrapper.in("menu_id", menuIdList);
|
||||
List<Menu> menuList = menuMapper.selectList(menuQueryWrapper);
|
||||
// 需要将MenuList转换成树形结构
|
||||
|
|
@ -56,7 +57,7 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
|||
@Override
|
||||
public List<Menu> getListTree() {
|
||||
QueryWrapper<Menu> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("del_flag", 0);
|
||||
queryWrapper.eq("del_flag", CommonConstant.DEL_FLAG_NORMAL);
|
||||
List<Menu> menuList = menuMapper.selectList(queryWrapper);
|
||||
// 需要将MenuList转换成树形结构
|
||||
menuList = TreeUtils.buildTree(menuList);
|
||||
|
|
@ -66,7 +67,7 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
|||
@Override
|
||||
public List<Menu> getAllMenus(Menu menu) {
|
||||
QueryWrapper<Menu> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("del_flag", 0);
|
||||
queryWrapper.eq("del_flag", CommonConstant.DEL_FLAG_NORMAL);
|
||||
if (menu != null) {
|
||||
queryWrapper.like(menu.getMenuName() != null, "menu_name", menu.getMenuName());
|
||||
}
|
||||
|
|
@ -79,7 +80,7 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
|||
// 每个参数都要进行非空校验
|
||||
this.checkData(menu);
|
||||
|
||||
menu.setDelFlag(0);
|
||||
menu.setDelFlag(CommonConstant.DEL_FLAG_NORMAL);
|
||||
return this.save(menu);
|
||||
|
||||
}
|
||||
|
|
@ -123,7 +124,7 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements Me
|
|||
if (menu == null) {
|
||||
throw new BusinessException(ResCode.DATA_NOT_EXIST.getResultCode(), "菜单不存在");
|
||||
}
|
||||
menu.setDelFlag(1);
|
||||
menu.setDelFlag( CommonConstant.DEL_FLAG_DELETED);
|
||||
return updateById(menu);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.tacit.admin.service.impl;
|
|||
|
||||
import ch.qos.logback.classic.spi.EventArgUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.tacit.admin.entity.Menu;
|
||||
import com.tacit.admin.entity.Role;
|
||||
|
|
@ -11,6 +12,7 @@ import com.tacit.admin.mapper.RoleMapper;
|
|||
import com.tacit.admin.mapper.UserRoleMapper;
|
||||
import com.tacit.admin.service.MenuService;
|
||||
import com.tacit.admin.service.RoleService;
|
||||
import com.tacit.common.constant.CommonConstant;
|
||||
import com.tacit.common.exception.BusinessException;
|
||||
import com.tacit.common.redis.utils.RedisUtils;
|
||||
import com.tacit.common.utils.ResCode;
|
||||
|
|
@ -59,7 +61,7 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
|||
public boolean createRole(Role role) {
|
||||
// 参数校验
|
||||
this.checkData(role);
|
||||
role.setDelFlag(0);
|
||||
role.setDelFlag( CommonConstant.DEL_FLAG_NORMAL);
|
||||
return save(role);
|
||||
}
|
||||
|
||||
|
|
@ -92,14 +94,14 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
|||
if (role == null) {
|
||||
throw new BusinessException(ResCode.DATA_NOT_EXIST.getResultCode(), "角色不存在");
|
||||
}
|
||||
role.setDelFlag(1);
|
||||
role.setDelFlag( CommonConstant.DEL_FLAG_DELETED);
|
||||
return updateById(role);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Role> getRoleList(Role role) {
|
||||
QueryWrapper<Role> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("del_flag", 0);
|
||||
queryWrapper.eq("del_flag", CommonConstant.DEL_FLAG_NORMAL);
|
||||
if (role != null) {
|
||||
queryWrapper.like(role.getRoleName() != null, "role_name", role.getRoleName());
|
||||
}
|
||||
|
|
@ -107,6 +109,25 @@ public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements Ro
|
|||
return roleList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<Role> getRolePage(Role role) {
|
||||
Integer pageNum = role.getPageNum();
|
||||
if (pageNum == null || pageNum < 1){
|
||||
pageNum = CommonConstant.PAGE_NUM;
|
||||
}
|
||||
Integer pageSize = role.getPageSize();
|
||||
if (pageSize == null || pageSize < 1){
|
||||
pageSize = CommonConstant.PAGE_SIZE;
|
||||
}
|
||||
Page<Role> page = new Page<>(pageNum, pageSize);
|
||||
QueryWrapper<Role> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("del_flag", CommonConstant.DEL_FLAG_NORMAL);
|
||||
if (StringUtils.isNotEmpty(role.getRoleName())) {
|
||||
queryWrapper.like(role.getRoleName() != null, "role_name", role.getRoleName());
|
||||
}
|
||||
return page(page, queryWrapper);
|
||||
}
|
||||
|
||||
private void checkData(Role role) {
|
||||
// 角色名称不能为空
|
||||
String roleName = role.getRoleName();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.tacit.admin.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.tacit.admin.entity.Role;
|
||||
import com.tacit.admin.entity.User;
|
||||
|
|
@ -61,9 +62,52 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|||
return userMapper.selectList(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<User> getUserPage(User user) {
|
||||
Integer pageNum = user.getPageNum();
|
||||
if (pageNum == null || pageNum < 1){
|
||||
pageNum = CommonConstant.PAGE_NUM;
|
||||
}
|
||||
Integer pageSize = user.getPageSize();
|
||||
if (pageSize == null || pageSize < 1){
|
||||
pageSize = CommonConstant.PAGE_SIZE;
|
||||
}
|
||||
// 创建分页对象
|
||||
Page<User> page = new Page<>(pageNum, pageSize);
|
||||
// 创建查询条件
|
||||
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("del_flag", 0);
|
||||
|
||||
// 根据条件查询
|
||||
if (user.getUsername() != null && !user.getUsername().isEmpty()) {
|
||||
queryWrapper.like("username", user.getUsername());
|
||||
}
|
||||
if (user.getNickname() != null && !user.getNickname().isEmpty()) {
|
||||
queryWrapper.like("nickname", user.getNickname());
|
||||
}
|
||||
if (user.getEmail() != null && !user.getEmail().isEmpty()) {
|
||||
queryWrapper.like("email", user.getEmail());
|
||||
}
|
||||
if (user.getPhone() != null && !user.getPhone().isEmpty()) {
|
||||
queryWrapper.like("phone", user.getPhone());
|
||||
}
|
||||
if (user.getRole() != null && !user.getRole().isEmpty()) {
|
||||
queryWrapper.eq("role", user.getRole());
|
||||
}
|
||||
if (user.getStatus() != null) {
|
||||
queryWrapper.eq("status", user.getStatus());
|
||||
}
|
||||
|
||||
// 按创建时间降序排序
|
||||
queryWrapper.orderByDesc("create_time");
|
||||
|
||||
// 执行分页查询
|
||||
return page(page, queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createUser(User user) {
|
||||
user.setDelFlag(0);
|
||||
user.setDelFlag(CommonConstant.DEL_FLAG_NORMAL);
|
||||
return save(user);
|
||||
}
|
||||
|
||||
|
|
@ -76,7 +120,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|||
public boolean deleteUser(Long id) {
|
||||
User user = new User();
|
||||
user.setId(id);
|
||||
user.setDelFlag(1);
|
||||
user.setDelFlag(CommonConstant.DEL_FLAG_DELETED);
|
||||
return updateById(user);
|
||||
}
|
||||
|
||||
|
|
@ -153,7 +197,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|||
user.setEmail(registerRequest.getEmail());
|
||||
user.setPhone(registerRequest.getPhone());
|
||||
user.setRole("USER");
|
||||
user.setDelFlag(0);
|
||||
user.setDelFlag(CommonConstant.DEL_FLAG_NORMAL);
|
||||
|
||||
save(user);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue