From e96a638d089338e07cf6cbaebd1b2a7ba86ded05 Mon Sep 17 00:00:00 2001 From: "rong.liu" Date: Wed, 17 Mar 2021 14:57:04 +0800 Subject: [PATCH] =?UTF-8?q?=E8=80=83=E6=A0=B8=E3=80=81=E7=BB=83=E4=B9=A0?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=94=B9=E6=88=90=E5=88=86=E9=A1=B5=E5=88=97?= =?UTF-8?q?=E8=A1=A8=EF=BC=8C=E6=B7=BB=E5=8A=A0=E5=88=86=E9=A1=B5=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AchievementManagementController.java | 16 ++- .../java/com/msdw/tms/util/ListPageUtil.java | 129 ++++++++++++++++++ .../java/com/msdw/tms/util/PageUtils.java | 113 +++++++++++++++ .../mapper/tms/AchievementManagementDao.xml | 2 +- 4 files changed, 256 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/msdw/tms/util/ListPageUtil.java create mode 100644 src/main/java/com/msdw/tms/util/PageUtils.java diff --git a/src/main/java/com/msdw/tms/controller/AchievementManagementController.java b/src/main/java/com/msdw/tms/controller/AchievementManagementController.java index 37a20d5..db82573 100644 --- a/src/main/java/com/msdw/tms/controller/AchievementManagementController.java +++ b/src/main/java/com/msdw/tms/controller/AchievementManagementController.java @@ -7,6 +7,8 @@ import com.msdw.tms.entity.vo.AchievementManagementVO; import com.msdw.tms.entity.vo.ResultsVo; import com.msdw.tms.service.AchievementManagementService; import com.msdw.tms.service.ProjectRecordService; +import com.msdw.tms.util.ListPageUtil; +import com.msdw.tms.util.PageUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; @@ -90,7 +92,11 @@ public class AchievementManagementController implements AchievementManagementApi vo.setEndTime(endTime); } List result = service.list(vo, page, size); - return R.ok().put("data", result); + + ListPageUtil listPageUtil = new ListPageUtil(result, page, size); + List pagedList = listPageUtil.getPagedList(); + PageUtils pageUtils = new PageUtils(pagedList, result.size(), page, size); + return R.ok().put("data", pageUtils); } /** @@ -121,7 +127,11 @@ public class AchievementManagementController implements AchievementManagementApi vo.setEndTime(endTime); } List result = service.newList(vo, page, size); - return R.ok().put("data", result); + /*return R.ok().put("data", result);*/ + ListPageUtil listPageUtil = new ListPageUtil(result, page, size); + List pagedList = listPageUtil.getPagedList(); + PageUtils pageUtils = new PageUtils(pagedList, result.size(), page, size); + return R.ok().put("data", pageUtils); } /** @@ -230,7 +240,7 @@ public class AchievementManagementController implements AchievementManagementApi @Override @GetMapping("/exportAchievement") public void exportAchievement(HttpServletResponse response, @RequestParam String ids, @RequestParam Integer source) throws Exception { - service.exportAchievement(response, ids,source);//SearchAchievementVo vo + service.exportAchievement(response, ids, source);//SearchAchievementVo vo } //成绩管理列表 diff --git a/src/main/java/com/msdw/tms/util/ListPageUtil.java b/src/main/java/com/msdw/tms/util/ListPageUtil.java new file mode 100644 index 0000000..f04f73a --- /dev/null +++ b/src/main/java/com/msdw/tms/util/ListPageUtil.java @@ -0,0 +1,129 @@ +package com.msdw.tms.util; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * @ProjectName: gzedu + * @Package: com.huoran.edu.utils + * @ClassName: ListSub + * @Description: 集合分页 + * @Author: Maureen.Rong + * @CreateDate: 2020/12/3 18:48 + * @UpdateDate: 2020/12/3 18:48 + * @Version: 1.0 + */ +public class ListPageUtil { + /** + * 原集合 + */ + private List data; + + /** + * 上一页 + */ + private int lastPage; + + /** + * 当前页 + */ + private int nowPage; + + /** + * 下一页 + */ + private int nextPage; + + /** + * 每页条数 + */ + private int pageSize; + + /** + * 总页数 + */ + private int totalPage; + + /** + * 总数据条数 + */ + private int totalCount; + + public ListPageUtil(List data, int nowPage, int pageSize) { + if (data == null || data.isEmpty()) { + //throw new IllegalArgumentException("暂无数据"); + this.data = null; +// this.pageSize = pageSize; +// this.nowPage = nowPage; +// this.totalCount = data.size(); + } + + this.data = data; + this.pageSize = pageSize; + this.nowPage = nowPage; + this.totalCount = data.size(); + this.totalPage = (totalCount + pageSize - 1) / pageSize; + this.lastPage = nowPage - 1 > 1 ? nowPage - 1 : 1; + this.nextPage = nowPage >= totalPage ? totalPage : nowPage + 1; + + } + + /** + * 得到分页后的数据 + * + * @return 分页后结果 + */ + public List getPagedList() { + int fromIndex = (nowPage - 1) * pageSize; + if (fromIndex >= data.size()) { + return Collections.emptyList();//空数组 + } + if (fromIndex < 0) { + return Collections.emptyList();//空数组 + } + int toIndex = nowPage * pageSize; + if (toIndex >= data.size()) { + toIndex = data.size(); + } + return data.subList(fromIndex, toIndex); + } + + public int getPageSize() { + return pageSize; + } + + public List getData() { + return data; + } + + public int getLastPage() { + return lastPage; + } + + public int getNowPage() { + return nowPage; + } + + public int getNextPage() { + return nextPage; + } + + public int getTotalPage() { + return totalPage; + } + + public int getTotalCount() { + return totalCount; + } + + public static void main(String[] args) { + Integer[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; + List list = Arrays.asList(array); + + ListPageUtil listPageUtil = new ListPageUtil(list, 1, 4); + List pagedList = listPageUtil.getPagedList(); + System.out.println(pagedList); + } + +} diff --git a/src/main/java/com/msdw/tms/util/PageUtils.java b/src/main/java/com/msdw/tms/util/PageUtils.java new file mode 100644 index 0000000..a17ead7 --- /dev/null +++ b/src/main/java/com/msdw/tms/util/PageUtils.java @@ -0,0 +1,113 @@ +/** + * Copyright (c) 2016-2019 人人开源 All rights reserved. + *

+ * https://www.renren.io + *

+ * 版权所有,侵权必究! + */ + +package com.msdw.tms.util; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +/** + * 分页工具类 + * + * @author Mark sunlightcs@gmail.com + */ +@Data +public class PageUtils implements Serializable { + private static final long serialVersionUID = 1L; + /** + * 总记录数 + */ + private int totalCount; + /** + * 每页记录数 + */ + private int pageSize; + /** + * 总页数 + */ + private int totalPage; + /** + * 当前页数 + */ + private int currPage; + /** + * 列表数据 + */ + private List list; + + /** + * 分页 + * + * @param list 列表数据 + * @param totalCount 总记录数 + * @param pageSize 每页记录数 + * @param currPage 当前页数 + */ + public PageUtils(List list, int totalCount, int pageSize, int currPage) { + this.list = list; + this.totalCount = totalCount; + this.pageSize = pageSize; + this.currPage = currPage; + this.totalPage = (int) Math.ceil((double) totalCount / pageSize); + } + + /** + * 分页 + */ + public PageUtils(IPage page) { + this.list = page.getRecords(); + this.totalCount = (int) page.getTotal(); + this.pageSize = (int) page.getSize(); + this.currPage = (int) page.getCurrent(); + this.totalPage = (int) page.getPages(); + } + + public int getTotalCount() { + return totalCount; + } + + public void setTotalCount(int totalCount) { + this.totalCount = totalCount; + } + + public int getPageSize() { + return pageSize; + } + + public void setPageSize(int pageSize) { + this.pageSize = pageSize; + } + + public int getTotalPage() { + return totalPage; + } + + public void setTotalPage(int totalPage) { + this.totalPage = totalPage; + } + + public int getCurrPage() { + return currPage; + } + + public void setCurrPage(int currPage) { + this.currPage = currPage; + } + + public List getList() { + return list; + } + + public void setList(List list) { + this.list = list; + } + +} diff --git a/src/main/resources/mapper/tms/AchievementManagementDao.xml b/src/main/resources/mapper/tms/AchievementManagementDao.xml index 621e937..bb2f4b6 100644 --- a/src/main/resources/mapper/tms/AchievementManagementDao.xml +++ b/src/main/resources/mapper/tms/AchievementManagementDao.xml @@ -502,7 +502,7 @@ hr_project_management pm on et.project_id = pm.projectId WHERE user_id = #{userId} - AND pm.isdel = 0 + /*AND pm.isdel = 0*/ and et.experimental_class_name like concat('%',#{searchContant},'%') or et.experimental_name like concat('%',#{searchContant},'%') or pm.projectName like concat('%',#{searchContant},'%')