提交 8aba91c0 authored 作者: 李秋林's avatar 李秋林

修改时间管理;分页管理

上级 15543a7e
...@@ -119,6 +119,11 @@ ...@@ -119,6 +119,11 @@
<artifactId>mybatis-plus-core</artifactId> <artifactId>mybatis-plus-core</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-extension</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>
...@@ -8,6 +8,7 @@ import java.time.LocalDateTime; ...@@ -8,6 +8,7 @@ import java.time.LocalDateTime;
import java.time.LocalTime; import java.time.LocalTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.commons.lang3.time.DateFormatUtils;
...@@ -18,6 +19,7 @@ import org.apache.commons.lang3.time.DateFormatUtils; ...@@ -18,6 +19,7 @@ import org.apache.commons.lang3.time.DateFormatUtils;
*/ */
public class DateUtils extends org.apache.commons.lang3.time.DateUtils public class DateUtils extends org.apache.commons.lang3.time.DateUtils
{ {
public static String HH_MM_SS_0 = "yyyy-MM-dd 00:00:00";
public static String YYYY = "yyyy"; public static String YYYY = "yyyy";
public static String YYYY_MM = "yyyy-MM"; public static String YYYY_MM = "yyyy-MM";
...@@ -180,4 +182,27 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils ...@@ -180,4 +182,27 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
ZonedDateTime zdt = localDateTime.atZone(ZoneId.systemDefault()); ZonedDateTime zdt = localDateTime.atZone(ZoneId.systemDefault());
return Date.from(zdt.toInstant()); return Date.from(zdt.toInstant());
} }
/**
* 获取今天开始时间00:00:00
* @return
*/
public static Date dateStart(Date date){
Calendar start = Calendar.getInstance();
start.setTime(date);
start.set( Calendar.HOUR_OF_DAY,0);
start.set( Calendar.MINUTE, 0);
start.set( Calendar.SECOND,0);
start.set( Calendar.MILLISECOND,0);
return start.getTime();
}
/**
* 获取今天增加天数后的结束时间23:59:59
* @return
*/
public static Date dateStart(int day){
Date date=dateStart(new Date());
return DateUtils.addMilliseconds(DateUtils.addDays(date,day),-1000);
}
} }
package com.sfa.common.core.web.controller; package com.sfa.common.core.web.controller;
import java.beans.PropertyEditorSupport;
import java.util.Date;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.sfa.common.core.constant.HttpStatus;
import com.sfa.common.core.utils.DateUtils; import com.sfa.common.core.utils.DateUtils;
import com.sfa.common.core.utils.PageUtils; import com.sfa.common.core.utils.PageUtils;
import com.sfa.common.core.web.domain.AjaxResult; import com.sfa.common.core.web.domain.AjaxResult;
import com.sfa.common.core.web.page.TableDataInfo; import com.sfa.common.core.web.page.TableDataInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import java.beans.PropertyEditorSupport;
import java.util.Date;
import java.util.List;
/** /**
* web层通用数据处理 * web层通用数据处理
......
...@@ -22,12 +22,12 @@ public class PageInfo<T> implements Serializable { ...@@ -22,12 +22,12 @@ public class PageInfo<T> implements Serializable {
/** /**
* 当前页数,第1页开始 * 当前页数,第1页开始
*/ */
private int pageNum = 1; private int pageNum;
/** /**
* 每页条数 * 每页条数
*/ */
private int pageSize = 1; private int pageSize;
/** /**
* 总条数 * 总条数
...@@ -41,10 +41,9 @@ public class PageInfo<T> implements Serializable { ...@@ -41,10 +41,9 @@ public class PageInfo<T> implements Serializable {
private List<T> rows; private List<T> rows;
private Map<String,Object> queryParams; private Map<String, Object> queryParams;
/** /**
*
* current:当前页数,必须大于等于 1,默认值为 1。 * current:当前页数,必须大于等于 1,默认值为 1。
* size:每页条数,默认值为 10。 * size:每页条数,默认值为 10。
* total:总条数,默认值为 0。 * total:总条数,默认值为 0。
...@@ -55,9 +54,10 @@ public class PageInfo<T> implements Serializable { ...@@ -55,9 +54,10 @@ public class PageInfo<T> implements Serializable {
* hitCount:是否对 count 进行 limit 优化,默认值为 false。 * hitCount:是否对 count 进行 limit 优化,默认值为 false。
* countId:count 查询的列名,默认为 null,表示所有列。 * countId:count 查询的列名,默认为 null,表示所有列。
* maxLimit:设置最大的 limit 查询限制,默认值为 -1,表示不限制。 * maxLimit:设置最大的 limit 查询限制,默认值为 -1,表示不限制。
*
* @param iPage 查询出的分页对象 * @param iPage 查询出的分页对象
* @param t 需要转换的对象(用于返回前端,不能直接返回DO) * @param t 需要转换的对象(用于返回前端,不能直接返回DO)
* @param <P> 分页对象中的类型 * @param <P> 分页对象中的类型
*/ */
public <P> void pageCovert(IPage<P> iPage, Class<T> t) { public <P> void pageCovert(IPage<P> iPage, Class<T> t) {
this.total = (int) iPage.getTotal(); this.total = (int) iPage.getTotal();
...@@ -83,12 +83,20 @@ public class PageInfo<T> implements Serializable { ...@@ -83,12 +83,20 @@ public class PageInfo<T> implements Serializable {
} }
} }
public <P> void pageCovert(IPage<P> iPage) { /**
* 当前方法直接返回DO数据,在Service层无需再次处理DO数据时使用
* @param iPage DB中的DO数据
* PS:如需在Service层对DO数据二次处理时,请使用IPage<P> iPage, Class<T> t,返回DTO数据,将DO数据与业务隔离
*/
public PageInfo(IPage<T> iPage) {
this.pageNum = (int) iPage.getCurrent();
this.pageSize = (int) iPage.getSize();
this.total = (int) iPage.getTotal(); this.total = (int) iPage.getTotal();
this.totalPage = (int) iPage.getPages(); this.totalPage = (int) iPage.getPages();
this.rows = iPage.getRecords();
} }
public int getSkipNum(){ public int getSkipNum() {
return this.pageSize * (this.pageNum - 1); return this.pageSize * (this.pageNum - 1);
} }
...@@ -139,4 +147,7 @@ public class PageInfo<T> implements Serializable { ...@@ -139,4 +147,7 @@ public class PageInfo<T> implements Serializable {
public void setTotal(int total) { public void setTotal(int total) {
this.total = total; this.total = total;
} }
public PageInfo() {
}
} }
package com.sfa.common.core.web.page; package com.sfa.common.core.web.page;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sfa.common.core.text.Convert; import com.sfa.common.core.text.Convert;
import com.sfa.common.core.utils.ServletUtils; import com.sfa.common.core.utils.ServletUtils;
import com.sfa.common.core.web.domain.PageInfo;
/** /**
* 表格数据处理 * 表格数据处理
* *
* @author ruoyi * @author ruoyi
*/ */
public class TableSupport public class TableSupport {
{
/** /**
* 当前记录起始索引 * 当前记录起始索引
*/ */
...@@ -38,8 +39,7 @@ public class TableSupport ...@@ -38,8 +39,7 @@ public class TableSupport
/** /**
* 封装分页对象 * 封装分页对象
*/ */
public static PageDomain getPageDomain() public static PageDomain getPageDomain() {
{
PageDomain pageDomain = new PageDomain(); PageDomain pageDomain = new PageDomain();
pageDomain.setPageNum(Convert.toInt(ServletUtils.getParameter(PAGE_NUM), 1)); pageDomain.setPageNum(Convert.toInt(ServletUtils.getParameter(PAGE_NUM), 1));
pageDomain.setPageSize(Convert.toInt(ServletUtils.getParameter(PAGE_SIZE), 10)); pageDomain.setPageSize(Convert.toInt(ServletUtils.getParameter(PAGE_SIZE), 10));
...@@ -49,8 +49,19 @@ public class TableSupport ...@@ -49,8 +49,19 @@ public class TableSupport
return pageDomain; return pageDomain;
} }
public static PageDomain buildPageRequest() public static PageDomain buildPageRequest() {
{
return getPageDomain(); return getPageDomain();
} }
public static <T> Page<T> pageI() {
Page<T> page = new Page<T>(Convert.toInt(ServletUtils.getParameter(PAGE_NUM), 1), Convert.toInt(ServletUtils.getParameter(PAGE_SIZE), 10));
return page;
}
public static <T> PageInfo<T> pageInfo() {
PageInfo<T> pageInfo = new PageInfo<>();
pageInfo.setPageNum(Convert.toInt(ServletUtils.getParameter(PAGE_NUM), 1));
pageInfo.setPageSize(Convert.toInt(ServletUtils.getParameter(PAGE_SIZE), 10));
return pageInfo;
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论