Skip to content

Commit

Permalink
role paged query
Browse files Browse the repository at this point in the history
  • Loading branch information
iamKyun committed Sep 27, 2024
1 parent 97c9b80 commit cae05bc
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 11 deletions.
6 changes: 3 additions & 3 deletions web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@

<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.9</version>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.6.0</version>
</dependency>

<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.29</version>
<version>5.8.32</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package cn.wintersoft.dashboard.api.user.controller;

import cn.wintersoft.dashboard.api.user.model.request.AdminUserPageReq;
import cn.wintersoft.dashboard.api.user.model.request.RolePageReq;
import cn.wintersoft.dashboard.api.user.model.response.AdminUserPageItem;
import cn.wintersoft.dashboard.web.model.ApiRes;
import cn.wintersoft.dashboard.web.model.PageRes;
import cn.wintersoft.dashboard.web.model.SelectOption;
import cn.wintersoft.dashboard.web.resolver.JsonParam;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -41,11 +45,11 @@ public ApiRes<List<SelectOption>> getRoleOptions() {
return ApiRes.success(roles);
}

@Operation(summary = "分页查询角色列表")
@GetMapping
@Operation(summary = "查询所有角色")
public ApiRes<List<Role>> getRoles() {
List<Role> roles = roleService.list();
return ApiRes.success(roles);
public ApiRes<PageRes<Role>> getPagingRoles(RolePageReq req) {
PageRes<Role> page = roleService.getRolePagingList(req);
return ApiRes.success(page);
}

@Operation(summary = "获取角色")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package cn.wintersoft.dashboard.api.user.model.request;

import cn.wintersoft.dashboard.web.model.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;

@Schema(description = "角色分页查询参数")
@Getter
@Setter
public class RolePageReq extends PageParam {
@Schema(description = "角色名称")
private String roleName;
@Schema(description = "角色代码")
private String roleCode;
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package cn.wintersoft.dashboard.api.user.service;

import cn.wintersoft.dashboard.api.user.entity.Role;
import cn.wintersoft.dashboard.api.user.mapper.RoleMapper;
import cn.wintersoft.dashboard.api.user.model.request.RolePageReq;
import cn.wintersoft.dashboard.web.model.PageRes;
import cn.wintersoft.dashboard.web.model.SelectOption;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import cn.wintersoft.dashboard.api.user.entity.Role;
import cn.wintersoft.dashboard.api.user.mapper.RoleMapper;

import java.util.List;

Expand All @@ -33,4 +38,12 @@ public void deleteRoles(List<Integer> ids) {
roleMenuService.deleteByRoleIds(ids);
}

public PageRes<Role> getRolePagingList(RolePageReq req) {
Page<Role> page = req.toPage();
LambdaQueryWrapper<Role> qw =
Wrappers.<Role>lambdaQuery()
.like(req.getRoleCode() != null, Role::getCode, req.getRoleCode())
.like(req.getRoleName() != null, Role::getName, req.getRoleName());
return PageRes.of(this.page(page, qw));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public class PageParam implements Serializable {
@Schema(description = "页大小")
private int pageSize = 10;

public Page<?> toPage() {
return new Page<>(page, pageSize);
public<T> Page<T> toPage() {
return new Page<T>(page, pageSize);
}

}
2 changes: 2 additions & 0 deletions web/src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
springdoc:
swagger-ui:
enabled: true
api-docs:
enabled: true
mybatis-plus:
Expand Down

0 comments on commit cae05bc

Please sign in to comment.