diff --git a/ruoyi-common/ruoyi-common-orm/src/main/java/com/ruoyi/common/orm/core/page/PageQuery.java b/ruoyi-common/ruoyi-common-orm/src/main/java/com/ruoyi/common/orm/core/page/PageQuery.java index 8eb85e3..e4c2330 100644 --- a/ruoyi-common/ruoyi-common-orm/src/main/java/com/ruoyi/common/orm/core/page/PageQuery.java +++ b/ruoyi-common/ruoyi-common-orm/src/main/java/com/ruoyi/common/orm/core/page/PageQuery.java @@ -1,6 +1,9 @@ package com.ruoyi.common.orm.core.page; +import com.mybatisflex.core.paginate.Page; 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.NoArgsConstructor; @@ -20,6 +23,16 @@ public class PageQuery implements Serializable { @Serial 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 Page 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 page = new Page<>(pageNum, pageSize); -// List orderItems = buildOrderItem(); -// if (CollUtil.isNotEmpty(orderItems)) { -// page.addOrder(orderItems); -// } -// return page; -// } - /** - * 构建排序 - * - * 支持的用法如下: - * {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 + * 构造分页查询参数 + * @return + * @param */ -// private List buildOrderItem() { -// if (StringUtils.isBlank(orderByColumn) || StringUtils.isBlank(isAsc)) { -// return null; -// } -// String orderBy = SqlUtil.escapeOrderBySql(orderByColumn); -// orderBy = StringUtils.toUnderScoreCase(orderBy); -// -// // 兼容前端排序类型 -// 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 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; -// } + public static Page build() { + Integer pageNum = Convert.toInt(ServletUtils.getParameter(PAGE_NUM), DEFAULT_PAGE_NUM); + Integer pageSize = Convert.toInt(ServletUtils.getParameter(PAGE_SIZE), DEFAULT_PAGE_SIZE); + if (pageNum <= 0) { + pageNum = DEFAULT_PAGE_NUM; + } + Page page = new Page<>(pageNum, pageSize); + return page; + } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java index 4bd912d..1de18d0 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java @@ -10,6 +10,7 @@ import com.ruoyi.common.core.core.page.TableSupport; import com.ruoyi.common.core.service.ConfigService; import com.ruoyi.common.core.utils.MapstructUtils; 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.service.impl.BaseServiceImpl; import com.ruoyi.common.redis.utils.CacheUtils; @@ -139,10 +140,7 @@ public class SysConfigServiceImpl extends BaseServiceImpl selectConfigPage(SysConfigBo config) { QueryWrapper queryWrapper = buildQueryWrapper(config); - - PageDomain pageDomain = TableSupport.buildPageRequest(); - - Page page = this.getMapper().paginateAs(pageDomain.getPageNum(), pageDomain.getPageSize(), queryWrapper,SysConfigVo.class); + Page page = this.pageAs(PageQuery.build(), queryWrapper,SysConfigVo.class); return TableDataInfo.build(page); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictDataServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictDataServiceImpl.java index 13e4c9f..defeabf 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictDataServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictDataServiceImpl.java @@ -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.utils.MapstructUtils; 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.service.impl.BaseServiceImpl; import com.ruoyi.common.redis.utils.CacheUtils; @@ -85,10 +86,7 @@ public class SysDictDataServiceImpl extends BaseServiceImpl selectPage(SysDictDataBo dictDataBo) { QueryWrapper queryWrapper = buildQueryWrapper(dictDataBo); - - PageDomain pageDomain = TableSupport.buildPageRequest(); - - Page page = this.getMapper().paginateAs(pageDomain.getPageNum(), pageDomain.getPageSize(), queryWrapper, SysDictDataVo.class); + Page page = this.pageAs(PageQuery.build(), queryWrapper, SysDictDataVo.class); return TableDataInfo.build(page); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java index fe89bc5..4c0e2c5 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java @@ -18,6 +18,7 @@ import com.ruoyi.common.core.service.DictService; import com.ruoyi.common.core.utils.MapstructUtils; import com.ruoyi.common.core.utils.SpringUtils; 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.service.impl.BaseServiceImpl; import com.ruoyi.common.redis.utils.CacheUtils; @@ -105,10 +106,7 @@ public class SysDictTypeServiceImpl extends BaseServiceImpl selectPage(SysDictTypeBo dictTypeBo) { QueryWrapper queryWrapper = buildQueryWrapper(dictTypeBo); - - PageDomain pageDomain = TableSupport.buildPageRequest(); - - Page page = this.getMapper().paginateAs(pageDomain.getPageNum(), pageDomain.getPageSize(), queryWrapper, SysDictTypeVo.class); + Page page = this.pageAs(PageQuery.build(), queryWrapper, SysDictTypeVo.class); return TableDataInfo.build(page); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysNoticeServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysNoticeServiceImpl.java index 45ac7f0..0d74c65 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysNoticeServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysNoticeServiceImpl.java @@ -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.StringUtils; 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.service.impl.BaseServiceImpl; import com.ruoyi.system.domain.bo.SysNoticeBo; @@ -98,10 +99,7 @@ public class SysNoticeServiceImpl extends BaseServiceImpl selectPage(SysNoticeBo noticeBo) { QueryWrapper queryWrapper = buildQueryWrapper(noticeBo); - - PageDomain pageDomain = TableSupport.buildPageRequest(); - - Page page = this.getMapper().paginateAs(pageDomain.getPageNum(), pageDomain.getPageSize(), queryWrapper, SysNoticeVo.class); + Page page = this.pageAs(PageQuery.build(), queryWrapper, SysNoticeVo.class); return TableDataInfo.build(page); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java index b466236..e4821bd 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java @@ -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.utils.MapstructUtils; 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.service.impl.BaseServiceImpl; import com.ruoyi.system.domain.bo.SysPostBo; @@ -92,10 +93,7 @@ public class SysPostServiceImpl extends BaseServiceImpl @Override public TableDataInfo selectPage(SysPostBo postBo) { QueryWrapper queryWrapper = buildQueryWrapper(postBo); - - PageDomain pageDomain = TableSupport.buildPageRequest(); - - Page page = this.getMapper().paginateAs(pageDomain.getPageNum(), pageDomain.getPageSize(), queryWrapper, SysPostVo.class); + Page page = this.pageAs(PageQuery.build(), queryWrapper, SysPostVo.class); return TableDataInfo.build(page); }