mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-07-19 06:09:33 +08:00
代码优化
This commit is contained in:
parent
b3e2c2c37e
commit
0dc02ffad7
@ -14,6 +14,7 @@ import xyz.playedu.api.request.backend.AdminUserRequest;
|
||||
import xyz.playedu.api.service.AdminRoleService;
|
||||
import xyz.playedu.api.service.AdminUserRoleService;
|
||||
import xyz.playedu.api.service.AdminUserService;
|
||||
import xyz.playedu.api.types.paginate.AdminUserPaginateFilter;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
import xyz.playedu.api.types.JsonResponse;
|
||||
import xyz.playedu.api.util.HelperUtil;
|
||||
@ -39,8 +40,17 @@ public class AdminUserController {
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.ADMIN_USER_INDEX)
|
||||
@GetMapping("/index")
|
||||
public JsonResponse Index(@RequestParam(name = "page", defaultValue = "1") Integer page, @RequestParam(name = "size", defaultValue = "10") Integer size) {
|
||||
PaginationResult<AdminUser> result = adminUserService.paginate(page, size, null);
|
||||
public JsonResponse Index(
|
||||
@RequestParam(name = "page", defaultValue = "1") Integer page,
|
||||
@RequestParam(name = "size", defaultValue = "10") Integer size,
|
||||
@RequestParam(name = "name", required = false) String name
|
||||
) {
|
||||
AdminUserPaginateFilter filter = new AdminUserPaginateFilter();
|
||||
if (name != null && name.length() > 0) {
|
||||
filter.setName(name);
|
||||
}
|
||||
|
||||
PaginationResult<AdminUser> result = adminUserService.paginate(page, size, filter);
|
||||
|
||||
ArrayList<AdminUser> data = new ArrayList<>();
|
||||
for (AdminUser adminUser : result.getData()) {
|
||||
@ -60,7 +70,6 @@ public class AdminUserController {
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
data.put("roles", roles);
|
||||
return JsonResponse.data(data);
|
||||
|
||||
}
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.ADMIN_USER_STORE)
|
||||
|
@ -34,7 +34,11 @@ public class ResourceController {
|
||||
private ResourceCategoryService categoryService;
|
||||
|
||||
@GetMapping("/index")
|
||||
public JsonResponse index(@RequestParam(name = "page", defaultValue = "1") Integer page, @RequestParam(name = "size", defaultValue = "10") Integer size, @RequestParam(name = "name", defaultValue = "") String name) {
|
||||
public JsonResponse index(
|
||||
@RequestParam(name = "page", defaultValue = "1") Integer page,
|
||||
@RequestParam(name = "size", defaultValue = "10") Integer size,
|
||||
@RequestParam(name = "name", defaultValue = "") String name
|
||||
) {
|
||||
ResourcePaginateFilter filter = new ResourcePaginateFilter();
|
||||
if (name != null && name.length() > 0) {
|
||||
filter.setName(name);
|
||||
|
@ -1,36 +0,0 @@
|
||||
package xyz.playedu.api.request.backend;
|
||||
|
||||
import jakarta.validation.constraints.Max;
|
||||
import jakarta.validation.constraints.Min;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class PaginationRequest implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Min(value = 1, message = "page参数值不能少于1")
|
||||
public Integer page = 1;
|
||||
|
||||
@Min(value = 1, message = "size参数值不能少于1")
|
||||
@Max(value = 1000, message = "size参数值不能超过1000")
|
||||
public Integer size = 10;
|
||||
|
||||
public Integer getPage() {
|
||||
return page;
|
||||
}
|
||||
|
||||
public void setPage(Integer page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
public Integer getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(Integer size) {
|
||||
this.size = size;
|
||||
}
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
package xyz.playedu.api.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import xyz.playedu.api.domain.AdminUser;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import xyz.playedu.api.types.paginate.AdminUserPaginateFilter;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
|
||||
/**
|
||||
@ -11,7 +11,7 @@ import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
* @createDate 2023-02-11 10:58:52
|
||||
*/
|
||||
public interface AdminUserService extends IService<AdminUser> {
|
||||
PaginationResult<AdminUser> paginate(int page, int size, Wrapper<AdminUser> queryWrapper);
|
||||
PaginationResult<AdminUser> paginate(int page, int size, AdminUserPaginateFilter filter);
|
||||
|
||||
AdminUser findByEmail(String email);
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package xyz.playedu.api.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
@ -8,14 +8,22 @@ import xyz.playedu.api.domain.AdminUser;
|
||||
import xyz.playedu.api.service.AdminUserService;
|
||||
import xyz.playedu.api.mapper.AdminUserMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import xyz.playedu.api.types.paginate.AdminUserPaginateFilter;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
|
||||
@Service
|
||||
public class AdminUserServiceImpl extends ServiceImpl<AdminUserMapper, AdminUser> implements AdminUserService {
|
||||
|
||||
public PaginationResult<AdminUser> paginate(int page, int size, Wrapper<AdminUser> queryWrapper) {
|
||||
public PaginationResult<AdminUser> paginate(int page, int size, AdminUserPaginateFilter filter) {
|
||||
QueryWrapper<AdminUser> wrapper = query().getWrapper().eq("1", "1");
|
||||
if (filter != null) {
|
||||
if (filter.getName() != null) {
|
||||
wrapper.like("name", "%" + filter.getName() + "%");
|
||||
}
|
||||
}
|
||||
|
||||
IPage<AdminUser> userPage = new Page<>(page, size);
|
||||
userPage = this.getBaseMapper().selectPage(userPage, queryWrapper);
|
||||
userPage = this.getBaseMapper().selectPage(userPage, wrapper);
|
||||
|
||||
PaginationResult<AdminUser> pageResult = new PaginationResult<>();
|
||||
pageResult.setData(userPage.getRecords());
|
||||
|
@ -0,0 +1,14 @@
|
||||
package xyz.playedu.api.types.paginate;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
* @create 2023/2/23 11:34
|
||||
*/
|
||||
@Data
|
||||
public class AdminUserPaginateFilter {
|
||||
|
||||
private String name;
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user