diff --git a/src/main/java/club/joylink/rtss/services/paper/PaperUserFindPageService.java b/src/main/java/club/joylink/rtss/services/paper/PaperUserFindPageService.java index 9cfae3285..2b5d894cc 100644 --- a/src/main/java/club/joylink/rtss/services/paper/PaperUserFindPageService.java +++ b/src/main/java/club/joylink/rtss/services/paper/PaperUserFindPageService.java @@ -19,6 +19,8 @@ import club.joylink.rtss.vo.paper.FindPaperUserForClassReqVo; import club.joylink.rtss.vo.paper.FindPaperUserForCompositionReqVo; import club.joylink.rtss.vo.paper.PaperUserInfoVo; import club.joylink.rtss.vo.paper.convertor.PaperUserConvertor; +import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -66,7 +68,6 @@ public class PaperUserFindPageService { */ @Transactional(readOnly = true) public PageVO findPaperUserByPageForClass(FindPaperUserForClassReqVo req){ - PageVO page = new PageVO<>(); PaperComposition pc = paperCompositionDAO.selectByPrimaryKey(req.getPcId()); PaperExceptionAssert.PcExisted.assertNotNull(pc,"试卷定义不存在"); // @@ -83,38 +84,24 @@ public class PaperUserFindPageService { case Complete:c.andScoreIsNotNull();break; case All:break; } - long sum = paperUserDAO.countByExample(example); - page.setTotal(sum); - page.setPageNum(req.getPageNum()); - page.setPageSize(req.getPageSize()); - page.setList(new ArrayList<>()); - if (sum > 0) { - // - String orderBy = req.getOrderBy().with(); - long startIndex = (req.getPageNum() - 1) * req.getPageSize(); - // - if (req.getDesc()) { - example.setOrderByClause(String.format("%s desc limit %s,%s", orderBy, startIndex, req.getPageSize())); - } else { - example.setOrderByClause(String.format("%s limit %s,%s", orderBy, startIndex, req.getPageSize())); - } - List pContent = this.paperUserDAO.selectByExample(example); - if (null != pContent) { - pContent.forEach(t -> { - page.getList().add(PaperUserConvertor.convert(pc,t)); - }); - } + // + String orderBy = req.getOrderBy().with()+(req.getDesc()?" desc":""); + PageHelper.startPage(req.getPageNum(),req.getPageSize(),orderBy); + Page sqlPage = (Page) this.paperUserDAO.selectByExample(example); + // + List rtContent= new ArrayList<>(); + if(!CollectionUtils.isEmpty(sqlPage.getResult())){ + sqlPage.getResult().forEach(t -> { + rtContent.add(PaperUserConvertor.convert(pc,t)); + }); } - - - return page; + return PageVO.convert(sqlPage,rtContent); } /** * 分页查询某个试卷蓝图的所有用户试卷基本信息 */ @Transactional(readOnly = true) public PageVO findPaperUserByPage(FindPaperUserForCompositionReqVo req) { - PageVO page = new PageVO<>(); // PaperComposition pc = paperCompositionDAO.selectByPrimaryKey(req.getPcId()); PaperExceptionAssert.PcExisted.assertNotNull(pc,"试卷定义不存在"); @@ -127,30 +114,18 @@ public class PaperUserFindPageService { case Complete:c.andScoreIsNotNull();break; case All:break; } - long sum = paperUserDAO.countByExample(example); - page.setTotal(sum); - page.setPageNum(req.getPageNum()); - page.setPageSize(req.getPageSize()); - page.setList(new ArrayList<>()); - if (sum > 0) { - // - String orderBy = req.getOrderBy().with(); - long startIndex = (req.getPageNum() - 1) * req.getPageSize(); - // - if (req.getDesc()) { - example.setOrderByClause(String.format("%s desc limit %s,%s", orderBy, startIndex, req.getPageSize())); - } else { - example.setOrderByClause(String.format("%s limit %s,%s", orderBy, startIndex, req.getPageSize())); - } - List pContent = this.paperUserDAO.selectByExample(example); - if (null != pContent) { - pContent.forEach(t -> { - page.getList().add(PaperUserConvertor.convert(pc,t)); - }); - } - } // - return page; + String orderBy = req.getOrderBy().with()+(req.getDesc()?" desc":""); + PageHelper.startPage(req.getPageNum(),req.getPageSize(),orderBy); + Page sqlPage = (Page) this.paperUserDAO.selectByExample(example); + // + List rtContent= new ArrayList<>(); + if(!CollectionUtils.isEmpty(sqlPage.getResult())){ + sqlPage.getResult().forEach(t -> { + rtContent.add(PaperUserConvertor.convert(pc,t)); + }); + } + return PageVO.convert(sqlPage,rtContent); } /** * 查询某个班级的所有学生的userId