mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-09-12 14:57:10 +08:00
refactor(extension/crud): PageDataResp => PageResp
This commit is contained in:
@@ -32,7 +32,7 @@ import top.charles7c.continew.starter.extension.crud.annotation.CrudRequestMappi
|
|||||||
import top.charles7c.continew.starter.extension.crud.enums.Api;
|
import top.charles7c.continew.starter.extension.crud.enums.Api;
|
||||||
import top.charles7c.continew.starter.extension.crud.model.query.PageQuery;
|
import top.charles7c.continew.starter.extension.crud.model.query.PageQuery;
|
||||||
import top.charles7c.continew.starter.extension.crud.model.query.SortQuery;
|
import top.charles7c.continew.starter.extension.crud.model.query.SortQuery;
|
||||||
import top.charles7c.continew.starter.extension.crud.model.resp.PageDataResp;
|
import top.charles7c.continew.starter.extension.crud.model.resp.PageResp;
|
||||||
import top.charles7c.continew.starter.extension.crud.model.resp.R;
|
import top.charles7c.continew.starter.extension.crud.model.resp.R;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -64,10 +64,9 @@ public abstract class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q,
|
|||||||
@Operation(summary = "分页查询列表", description = "分页查询列表")
|
@Operation(summary = "分页查询列表", description = "分页查询列表")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public R<PageDataResp<L>> page(Q query, @Validated PageQuery pageQuery) {
|
public R<PageResp<L>> page(Q query, @Validated PageQuery pageQuery) {
|
||||||
this.checkPermission(Api.LIST);
|
this.checkPermission(Api.LIST);
|
||||||
PageDataResp<L> pageData = baseService.page(query, pageQuery);
|
return R.ok(baseService.page(query, pageQuery));
|
||||||
return R.ok(pageData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -82,8 +81,7 @@ public abstract class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q,
|
|||||||
@GetMapping("/tree")
|
@GetMapping("/tree")
|
||||||
public R<List<Tree<Long>>> tree(Q query, SortQuery sortQuery) {
|
public R<List<Tree<Long>>> tree(Q query, SortQuery sortQuery) {
|
||||||
this.checkPermission(Api.LIST);
|
this.checkPermission(Api.LIST);
|
||||||
List<Tree<Long>> list = baseService.tree(query, sortQuery, false);
|
return R.ok(baseService.tree(query, sortQuery, false));
|
||||||
return R.ok(list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -98,8 +96,7 @@ public abstract class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q,
|
|||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
public R<List<L>> list(Q query, SortQuery sortQuery) {
|
public R<List<L>> list(Q query, SortQuery sortQuery) {
|
||||||
this.checkPermission(Api.LIST);
|
this.checkPermission(Api.LIST);
|
||||||
List<L> list = baseService.list(query, sortQuery);
|
return R.ok(baseService.list(query, sortQuery));
|
||||||
return R.ok(list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -114,8 +111,7 @@ public abstract class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q,
|
|||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
public R<D> get(@PathVariable Long id) {
|
public R<D> get(@PathVariable Long id) {
|
||||||
this.checkPermission(Api.LIST);
|
this.checkPermission(Api.LIST);
|
||||||
D detail = baseService.get(id);
|
return R.ok(baseService.get(id));
|
||||||
return R.ok(detail);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -129,8 +125,7 @@ public abstract class BaseController<S extends BaseService<L, D, Q, C>, L, D, Q,
|
|||||||
@PostMapping
|
@PostMapping
|
||||||
public R<Long> add(@Validated(ValidateGroup.Crud.Add.class) @RequestBody C req) {
|
public R<Long> add(@Validated(ValidateGroup.Crud.Add.class) @RequestBody C req) {
|
||||||
this.checkPermission(Api.ADD);
|
this.checkPermission(Api.ADD);
|
||||||
Long id = baseService.add(req);
|
return R.ok("新增成功", baseService.add(req));
|
||||||
return R.ok("新增成功", id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -20,7 +20,7 @@ import cn.hutool.core.lang.tree.Tree;
|
|||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import top.charles7c.continew.starter.extension.crud.model.query.PageQuery;
|
import top.charles7c.continew.starter.extension.crud.model.query.PageQuery;
|
||||||
import top.charles7c.continew.starter.extension.crud.model.query.SortQuery;
|
import top.charles7c.continew.starter.extension.crud.model.query.SortQuery;
|
||||||
import top.charles7c.continew.starter.extension.crud.model.resp.PageDataResp;
|
import top.charles7c.continew.starter.extension.crud.model.resp.PageResp;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ public interface BaseService<L, D, Q, C extends BaseReq> {
|
|||||||
* @param pageQuery 分页查询条件
|
* @param pageQuery 分页查询条件
|
||||||
* @return 分页列表信息
|
* @return 分页列表信息
|
||||||
*/
|
*/
|
||||||
PageDataResp<L> page(Q query, PageQuery pageQuery);
|
PageResp<L> page(Q query, PageQuery pageQuery);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询树列表
|
* 查询树列表
|
||||||
|
@@ -41,7 +41,7 @@ import top.charles7c.continew.starter.data.mybatis.plus.query.QueryHelper;
|
|||||||
import top.charles7c.continew.starter.extension.crud.annotation.TreeField;
|
import top.charles7c.continew.starter.extension.crud.annotation.TreeField;
|
||||||
import top.charles7c.continew.starter.extension.crud.model.query.PageQuery;
|
import top.charles7c.continew.starter.extension.crud.model.query.PageQuery;
|
||||||
import top.charles7c.continew.starter.extension.crud.model.query.SortQuery;
|
import top.charles7c.continew.starter.extension.crud.model.query.SortQuery;
|
||||||
import top.charles7c.continew.starter.extension.crud.model.resp.PageDataResp;
|
import top.charles7c.continew.starter.extension.crud.model.resp.PageResp;
|
||||||
import top.charles7c.continew.starter.extension.crud.util.TreeUtils;
|
import top.charles7c.continew.starter.extension.crud.util.TreeUtils;
|
||||||
import top.charles7c.continew.starter.file.excel.util.ExcelUtils;
|
import top.charles7c.continew.starter.file.excel.util.ExcelUtils;
|
||||||
|
|
||||||
@@ -78,12 +78,12 @@ public abstract class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseDO,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageDataResp<L> page(Q query, PageQuery pageQuery) {
|
public PageResp<L> page(Q query, PageQuery pageQuery) {
|
||||||
QueryWrapper<T> queryWrapper = QueryHelper.build(query);
|
QueryWrapper<T> queryWrapper = QueryHelper.build(query);
|
||||||
IPage<T> page = baseMapper.selectPage(pageQuery.toPage(), queryWrapper);
|
IPage<T> page = baseMapper.selectPage(pageQuery.toPage(), queryWrapper);
|
||||||
PageDataResp<L> pageDataResp = PageDataResp.build(page, listClass);
|
PageResp<L> pageResp = PageResp.build(page, listClass);
|
||||||
pageDataResp.getList().forEach(this::fill);
|
pageResp.getList().forEach(this::fill);
|
||||||
return pageDataResp;
|
return pageResp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -36,7 +36,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Schema(description = "分页信息")
|
@Schema(description = "分页信息")
|
||||||
public class PageDataResp<L> implements Serializable {
|
public class PageResp<L> implements Serializable {
|
||||||
|
|
||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
@@ -62,14 +62,14 @@ public class PageDataResp<L> implements Serializable {
|
|||||||
* @param <L> 目标列表数据类型
|
* @param <L> 目标列表数据类型
|
||||||
* @return 分页信息
|
* @return 分页信息
|
||||||
*/
|
*/
|
||||||
public static <T, L> PageDataResp<L> build(IPage<T> page, Class<L> targetClass) {
|
public static <T, L> PageResp<L> build(IPage<T> page, Class<L> targetClass) {
|
||||||
if (null == page) {
|
if (null == page) {
|
||||||
return empty();
|
return empty();
|
||||||
}
|
}
|
||||||
PageDataResp<L> pageDataResp = new PageDataResp<>();
|
PageResp<L> pageResp = new PageResp<>();
|
||||||
pageDataResp.setList(BeanUtil.copyToList(page.getRecords(), targetClass));
|
pageResp.setList(BeanUtil.copyToList(page.getRecords(), targetClass));
|
||||||
pageDataResp.setTotal(page.getTotal());
|
pageResp.setTotal(page.getTotal());
|
||||||
return pageDataResp;
|
return pageResp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -79,14 +79,14 @@ public class PageDataResp<L> implements Serializable {
|
|||||||
* @param <L> 列表数据类型
|
* @param <L> 列表数据类型
|
||||||
* @return 分页信息
|
* @return 分页信息
|
||||||
*/
|
*/
|
||||||
public static <L> PageDataResp<L> build(IPage<L> page) {
|
public static <L> PageResp<L> build(IPage<L> page) {
|
||||||
if (null == page) {
|
if (null == page) {
|
||||||
return empty();
|
return empty();
|
||||||
}
|
}
|
||||||
PageDataResp<L> pageDataResp = new PageDataResp<>();
|
PageResp<L> pageResp = new PageResp<>();
|
||||||
pageDataResp.setList(page.getRecords());
|
pageResp.setList(page.getRecords());
|
||||||
pageDataResp.setTotal(page.getTotal());
|
pageResp.setTotal(page.getTotal());
|
||||||
return pageDataResp;
|
return pageResp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -98,23 +98,23 @@ public class PageDataResp<L> implements Serializable {
|
|||||||
* @param <L> 列表数据类型
|
* @param <L> 列表数据类型
|
||||||
* @return 分页信息
|
* @return 分页信息
|
||||||
*/
|
*/
|
||||||
public static <L> PageDataResp<L> build(int page, int size, List<L> list) {
|
public static <L> PageResp<L> build(int page, int size, List<L> list) {
|
||||||
if (CollUtil.isEmpty(list)) {
|
if (CollUtil.isEmpty(list)) {
|
||||||
return empty();
|
return empty();
|
||||||
}
|
}
|
||||||
PageDataResp<L> pageDataResp = new PageDataResp<>();
|
PageResp<L> pageResp = new PageResp<>();
|
||||||
pageDataResp.setTotal(list.size());
|
pageResp.setTotal(list.size());
|
||||||
// 对列表数据进行分页
|
// 对列表数据进行分页
|
||||||
int fromIndex = (page - 1) * size;
|
int fromIndex = (page - 1) * size;
|
||||||
int toIndex = page * size + size;
|
int toIndex = page * size + size;
|
||||||
if (fromIndex > list.size()) {
|
if (fromIndex > list.size()) {
|
||||||
pageDataResp.setList(new ArrayList<>(0));
|
pageResp.setList(new ArrayList<>(0));
|
||||||
} else if (toIndex >= list.size()) {
|
} else if (toIndex >= list.size()) {
|
||||||
pageDataResp.setList(list.subList(fromIndex, list.size()));
|
pageResp.setList(list.subList(fromIndex, list.size()));
|
||||||
} else {
|
} else {
|
||||||
pageDataResp.setList(list.subList(fromIndex, toIndex));
|
pageResp.setList(list.subList(fromIndex, toIndex));
|
||||||
}
|
}
|
||||||
return pageDataResp;
|
return pageResp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -123,9 +123,9 @@ public class PageDataResp<L> implements Serializable {
|
|||||||
* @param <L> 列表数据类型
|
* @param <L> 列表数据类型
|
||||||
* @return 分页信息
|
* @return 分页信息
|
||||||
*/
|
*/
|
||||||
private static <L> PageDataResp<L> empty() {
|
private static <L> PageResp<L> empty() {
|
||||||
PageDataResp<L> pageDataResp = new PageDataResp<>();
|
PageResp<L> pageResp = new PageResp<>();
|
||||||
pageDataResp.setList(new ArrayList<>(0));
|
pageResp.setList(new ArrayList<>(0));
|
||||||
return pageDataResp;
|
return pageResp;
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user