重构分页查询代码
This commit is contained in:
parent
d413baeb98
commit
891ef9bb09
@ -1,6 +1,9 @@
|
|||||||
package com.ruoyi.common.orm.core.page;
|
package com.ruoyi.common.orm.core.page;
|
||||||
|
|
||||||
|
import com.mybatisflex.core.paginate.Page;
|
||||||
import cn.hutool.http.HttpStatus;
|
import cn.hutool.http.HttpStatus;
|
||||||
|
import com.ruoyi.common.core.core.text.Convert;
|
||||||
|
import com.ruoyi.common.core.utils.ServletUtils;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
@ -20,6 +23,16 @@ public class PageQuery implements Serializable {
|
|||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前记录起始索引
|
||||||
|
*/
|
||||||
|
public static final String PAGE_NUM = "pageNum";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每页显示记录数
|
||||||
|
*/
|
||||||
|
public static final String PAGE_SIZE = "pageSize";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页大小
|
* 分页大小
|
||||||
*/
|
*/
|
||||||
@ -50,59 +63,19 @@ public class PageQuery implements Serializable {
|
|||||||
*/
|
*/
|
||||||
public static final int DEFAULT_PAGE_SIZE = Integer.MAX_VALUE;
|
public static final int DEFAULT_PAGE_SIZE = Integer.MAX_VALUE;
|
||||||
|
|
||||||
// public <T> Page<T> build() {
|
|
||||||
// Integer pageNum = ObjectUtil.defaultIfNull(getPageNum(), DEFAULT_PAGE_NUM);
|
|
||||||
// Integer pageSize = ObjectUtil.defaultIfNull(getPageSize(), DEFAULT_PAGE_SIZE);
|
|
||||||
// if (pageNum <= 0) {
|
|
||||||
// pageNum = DEFAULT_PAGE_NUM;
|
|
||||||
// }
|
|
||||||
// Page<T> page = new Page<>(pageNum, pageSize);
|
|
||||||
// List<OrderItem> orderItems = buildOrderItem();
|
|
||||||
// if (CollUtil.isNotEmpty(orderItems)) {
|
|
||||||
// page.addOrder(orderItems);
|
|
||||||
// }
|
|
||||||
// return page;
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建排序
|
* 构造分页查询参数
|
||||||
*
|
* @return
|
||||||
* 支持的用法如下:
|
* @param <T>
|
||||||
* {isAsc:"asc",orderByColumn:"id"} order by id asc
|
|
||||||
* {isAsc:"asc",orderByColumn:"id,createTime"} order by id asc,create_time asc
|
|
||||||
* {isAsc:"desc",orderByColumn:"id,createTime"} order by id desc,create_time desc
|
|
||||||
* {isAsc:"asc,desc",orderByColumn:"id,createTime"} order by id asc,create_time desc
|
|
||||||
*/
|
*/
|
||||||
// private List<OrderItem> buildOrderItem() {
|
public static <T> Page<T> build() {
|
||||||
// if (StringUtils.isBlank(orderByColumn) || StringUtils.isBlank(isAsc)) {
|
Integer pageNum = Convert.toInt(ServletUtils.getParameter(PAGE_NUM), DEFAULT_PAGE_NUM);
|
||||||
// return null;
|
Integer pageSize = Convert.toInt(ServletUtils.getParameter(PAGE_SIZE), DEFAULT_PAGE_SIZE);
|
||||||
// }
|
if (pageNum <= 0) {
|
||||||
// String orderBy = SqlUtil.escapeOrderBySql(orderByColumn);
|
pageNum = DEFAULT_PAGE_NUM;
|
||||||
// orderBy = StringUtils.toUnderScoreCase(orderBy);
|
}
|
||||||
//
|
Page<T> page = new Page<>(pageNum, pageSize);
|
||||||
// // 兼容前端排序类型
|
return page;
|
||||||
// isAsc = StringUtils.replaceEach(isAsc, new String[]{"ascending", "descending"}, new String[]{"asc", "desc"});
|
}
|
||||||
//
|
|
||||||
// String[] orderByArr = orderBy.split(StringUtils.SEPARATOR);
|
|
||||||
// String[] isAscArr = isAsc.split(StringUtils.SEPARATOR);
|
|
||||||
// if (isAscArr.length != 1 && isAscArr.length != orderByArr.length) {
|
|
||||||
// throw new ServiceException("排序参数有误");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// List<OrderItem> list = new ArrayList<>();
|
|
||||||
// // 每个字段各自排序
|
|
||||||
// for (int i = 0; i < orderByArr.length; i++) {
|
|
||||||
// String orderByStr = orderByArr[i];
|
|
||||||
// String isAscStr = isAscArr.length == 1 ? isAscArr[0] : isAscArr[i];
|
|
||||||
// if ("asc".equals(isAscStr)) {
|
|
||||||
// list.add(OrderItem.asc(orderByStr));
|
|
||||||
// } else if ("desc".equals(isAscStr)) {
|
|
||||||
// list.add(OrderItem.desc(orderByStr));
|
|
||||||
// } else {
|
|
||||||
// throw new ServiceException("排序参数有误");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return list;
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import com.ruoyi.common.core.core.page.TableSupport;
|
|||||||
import com.ruoyi.common.core.service.ConfigService;
|
import com.ruoyi.common.core.service.ConfigService;
|
||||||
import com.ruoyi.common.core.utils.MapstructUtils;
|
import com.ruoyi.common.core.utils.MapstructUtils;
|
||||||
import com.ruoyi.common.core.utils.SpringUtils;
|
import com.ruoyi.common.core.utils.SpringUtils;
|
||||||
|
import com.ruoyi.common.orm.core.page.PageQuery;
|
||||||
import com.ruoyi.common.orm.core.page.TableDataInfo;
|
import com.ruoyi.common.orm.core.page.TableDataInfo;
|
||||||
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
|
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
|
||||||
import com.ruoyi.common.redis.utils.CacheUtils;
|
import com.ruoyi.common.redis.utils.CacheUtils;
|
||||||
@ -139,10 +140,7 @@ public class SysConfigServiceImpl extends BaseServiceImpl<SysConfigMapper, SysCo
|
|||||||
@Override
|
@Override
|
||||||
public TableDataInfo<SysConfigVo> selectConfigPage(SysConfigBo config) {
|
public TableDataInfo<SysConfigVo> selectConfigPage(SysConfigBo config) {
|
||||||
QueryWrapper queryWrapper = buildQueryWrapper(config);
|
QueryWrapper queryWrapper = buildQueryWrapper(config);
|
||||||
|
Page<SysConfigVo> page = this.pageAs(PageQuery.build(), queryWrapper,SysConfigVo.class);
|
||||||
PageDomain pageDomain = TableSupport.buildPageRequest();
|
|
||||||
|
|
||||||
Page<SysConfigVo> page = this.getMapper().paginateAs(pageDomain.getPageNum(), pageDomain.getPageSize(), queryWrapper,SysConfigVo.class);
|
|
||||||
return TableDataInfo.build(page);
|
return TableDataInfo.build(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ import com.ruoyi.common.core.core.page.PageDomain;
|
|||||||
import com.ruoyi.common.core.core.page.TableSupport;
|
import com.ruoyi.common.core.core.page.TableSupport;
|
||||||
import com.ruoyi.common.core.utils.MapstructUtils;
|
import com.ruoyi.common.core.utils.MapstructUtils;
|
||||||
import com.ruoyi.common.core.utils.StringUtils;
|
import com.ruoyi.common.core.utils.StringUtils;
|
||||||
|
import com.ruoyi.common.orm.core.page.PageQuery;
|
||||||
import com.ruoyi.common.orm.core.page.TableDataInfo;
|
import com.ruoyi.common.orm.core.page.TableDataInfo;
|
||||||
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
|
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
|
||||||
import com.ruoyi.common.redis.utils.CacheUtils;
|
import com.ruoyi.common.redis.utils.CacheUtils;
|
||||||
@ -85,10 +86,7 @@ public class SysDictDataServiceImpl extends BaseServiceImpl<SysDictDataMapper, S
|
|||||||
@Override
|
@Override
|
||||||
public TableDataInfo<SysDictDataVo> selectPage(SysDictDataBo dictDataBo) {
|
public TableDataInfo<SysDictDataVo> selectPage(SysDictDataBo dictDataBo) {
|
||||||
QueryWrapper queryWrapper = buildQueryWrapper(dictDataBo);
|
QueryWrapper queryWrapper = buildQueryWrapper(dictDataBo);
|
||||||
|
Page<SysDictDataVo> page = this.pageAs(PageQuery.build(), queryWrapper, SysDictDataVo.class);
|
||||||
PageDomain pageDomain = TableSupport.buildPageRequest();
|
|
||||||
|
|
||||||
Page<SysDictDataVo> page = this.getMapper().paginateAs(pageDomain.getPageNum(), pageDomain.getPageSize(), queryWrapper, SysDictDataVo.class);
|
|
||||||
return TableDataInfo.build(page);
|
return TableDataInfo.build(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ import com.ruoyi.common.core.service.DictService;
|
|||||||
import com.ruoyi.common.core.utils.MapstructUtils;
|
import com.ruoyi.common.core.utils.MapstructUtils;
|
||||||
import com.ruoyi.common.core.utils.SpringUtils;
|
import com.ruoyi.common.core.utils.SpringUtils;
|
||||||
import com.ruoyi.common.core.utils.StreamUtils;
|
import com.ruoyi.common.core.utils.StreamUtils;
|
||||||
|
import com.ruoyi.common.orm.core.page.PageQuery;
|
||||||
import com.ruoyi.common.orm.core.page.TableDataInfo;
|
import com.ruoyi.common.orm.core.page.TableDataInfo;
|
||||||
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
|
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
|
||||||
import com.ruoyi.common.redis.utils.CacheUtils;
|
import com.ruoyi.common.redis.utils.CacheUtils;
|
||||||
@ -105,10 +106,7 @@ public class SysDictTypeServiceImpl extends BaseServiceImpl<SysDictTypeMapper, S
|
|||||||
@Override
|
@Override
|
||||||
public TableDataInfo<SysDictTypeVo> selectPage(SysDictTypeBo dictTypeBo) {
|
public TableDataInfo<SysDictTypeVo> selectPage(SysDictTypeBo dictTypeBo) {
|
||||||
QueryWrapper queryWrapper = buildQueryWrapper(dictTypeBo);
|
QueryWrapper queryWrapper = buildQueryWrapper(dictTypeBo);
|
||||||
|
Page<SysDictTypeVo> page = this.pageAs(PageQuery.build(), queryWrapper, SysDictTypeVo.class);
|
||||||
PageDomain pageDomain = TableSupport.buildPageRequest();
|
|
||||||
|
|
||||||
Page<SysDictTypeVo> page = this.getMapper().paginateAs(pageDomain.getPageNum(), pageDomain.getPageSize(), queryWrapper, SysDictTypeVo.class);
|
|
||||||
return TableDataInfo.build(page);
|
return TableDataInfo.build(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ import com.ruoyi.common.core.core.page.TableSupport;
|
|||||||
import com.ruoyi.common.core.utils.MapstructUtils;
|
import com.ruoyi.common.core.utils.MapstructUtils;
|
||||||
import com.ruoyi.common.core.utils.StringUtils;
|
import com.ruoyi.common.core.utils.StringUtils;
|
||||||
import com.ruoyi.common.core.utils.sql.SqlUtil;
|
import com.ruoyi.common.core.utils.sql.SqlUtil;
|
||||||
|
import com.ruoyi.common.orm.core.page.PageQuery;
|
||||||
import com.ruoyi.common.orm.core.page.TableDataInfo;
|
import com.ruoyi.common.orm.core.page.TableDataInfo;
|
||||||
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
|
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
|
||||||
import com.ruoyi.system.domain.bo.SysNoticeBo;
|
import com.ruoyi.system.domain.bo.SysNoticeBo;
|
||||||
@ -98,10 +99,7 @@ public class SysNoticeServiceImpl extends BaseServiceImpl<SysNoticeMapper, SysNo
|
|||||||
@Override
|
@Override
|
||||||
public TableDataInfo<SysNoticeVo> selectPage(SysNoticeBo noticeBo) {
|
public TableDataInfo<SysNoticeVo> selectPage(SysNoticeBo noticeBo) {
|
||||||
QueryWrapper queryWrapper = buildQueryWrapper(noticeBo);
|
QueryWrapper queryWrapper = buildQueryWrapper(noticeBo);
|
||||||
|
Page<SysNoticeVo> page = this.pageAs(PageQuery.build(), queryWrapper, SysNoticeVo.class);
|
||||||
PageDomain pageDomain = TableSupport.buildPageRequest();
|
|
||||||
|
|
||||||
Page<SysNoticeVo> page = this.getMapper().paginateAs(pageDomain.getPageNum(), pageDomain.getPageSize(), queryWrapper, SysNoticeVo.class);
|
|
||||||
return TableDataInfo.build(page);
|
return TableDataInfo.build(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ import com.ruoyi.common.core.core.page.PageDomain;
|
|||||||
import com.ruoyi.common.core.core.page.TableSupport;
|
import com.ruoyi.common.core.core.page.TableSupport;
|
||||||
import com.ruoyi.common.core.utils.MapstructUtils;
|
import com.ruoyi.common.core.utils.MapstructUtils;
|
||||||
import com.ruoyi.common.core.utils.sql.SqlUtil;
|
import com.ruoyi.common.core.utils.sql.SqlUtil;
|
||||||
|
import com.ruoyi.common.orm.core.page.PageQuery;
|
||||||
import com.ruoyi.common.orm.core.page.TableDataInfo;
|
import com.ruoyi.common.orm.core.page.TableDataInfo;
|
||||||
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
|
import com.ruoyi.common.orm.core.service.impl.BaseServiceImpl;
|
||||||
import com.ruoyi.system.domain.bo.SysPostBo;
|
import com.ruoyi.system.domain.bo.SysPostBo;
|
||||||
@ -92,10 +93,7 @@ public class SysPostServiceImpl extends BaseServiceImpl<SysPostMapper, SysPost>
|
|||||||
@Override
|
@Override
|
||||||
public TableDataInfo<SysPostVo> selectPage(SysPostBo postBo) {
|
public TableDataInfo<SysPostVo> selectPage(SysPostBo postBo) {
|
||||||
QueryWrapper queryWrapper = buildQueryWrapper(postBo);
|
QueryWrapper queryWrapper = buildQueryWrapper(postBo);
|
||||||
|
Page<SysPostVo> page = this.pageAs(PageQuery.build(), queryWrapper, SysPostVo.class);
|
||||||
PageDomain pageDomain = TableSupport.buildPageRequest();
|
|
||||||
|
|
||||||
Page<SysPostVo> page = this.getMapper().paginateAs(pageDomain.getPageNum(), pageDomain.getPageSize(), queryWrapper, SysPostVo.class);
|
|
||||||
return TableDataInfo.build(page);
|
return TableDataInfo.build(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user