From 334a5b571f5684bd091e5b87fc3d243534596d90 Mon Sep 17 00:00:00 2001 From: kwdpb <841299007@qq.com> Date: Mon, 16 Mar 2020 18:39:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E6=A0=B8=E9=85=B8=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E5=88=86=E9=A1=B5=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E7=9A=84=E5=88=86=E9=A1=B5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NucleicDetectionInfoServiceImpl.java | 53 +++++++++++++++---- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/gsafety/gemp/wxapplet/infection/service/NucleicDetectionInfoServiceImpl.java b/src/main/java/com/gsafety/gemp/wxapplet/infection/service/NucleicDetectionInfoServiceImpl.java index e4181a6..af294d9 100644 --- a/src/main/java/com/gsafety/gemp/wxapplet/infection/service/NucleicDetectionInfoServiceImpl.java +++ b/src/main/java/com/gsafety/gemp/wxapplet/infection/service/NucleicDetectionInfoServiceImpl.java @@ -1,5 +1,7 @@ package com.gsafety.gemp.wxapplet.infection.service; +import cn.hutool.core.collection.CollectionUtil; +import com.google.common.collect.Lists; import com.gsafety.gemp.wxapplet.infection.contract.dto.*; import com.gsafety.gemp.wxapplet.infection.contract.iface.NucleicDetectionInfoService; import com.gsafety.gemp.wxapplet.infection.dao.NucleicDetectionInfoDao; @@ -9,10 +11,7 @@ import com.gsafety.gemp.wxapplet.infection.wrapper.NucleicDetectionInfoWrapper; import com.gsafety.gemp.wxapplet.infection.wrapper.PointHospitalInfoWrapper; import com.gsafety.gemp.wxapplet.utils.DateUtils; import org.apache.commons.lang3.StringUtils; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageImpl; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Sort; +import org.springframework.data.domain.*; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; @@ -38,22 +37,58 @@ public class NucleicDetectionInfoServiceImpl implements NucleicDetectionInfoServ if(StringUtils.isNotBlank(dto.getDetectionNum())) { Sort sort = Sort.by(Sort.Direction.DESC, "sendSampleTime"); PageRequest pageRequest2= PageRequest.of(dto.getPage(), dto.getSize(),sort); - Page pageDto2= NucleicDetectionInfoWrapper.toPageDTO(detectionInfoDao.findAll(spec, pageRequest2)); - List content = pageDto2.getContent(); - + List content= NucleicDetectionInfoWrapper.toDTOList(detectionInfoDao.findAll(spec,sort)); List list=content.stream().filter(t->StringUtils.isNotBlank(t.getIdNo())).collect(Collectors.collectingAndThen( Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(c->c.getIdNo()))), ArrayList::new)); List list2=content.stream().filter(t->StringUtils.isBlank(t.getIdNo())).collect(Collectors.collectingAndThen( Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(c->c.getSuffererName()))), ArrayList::new)); - list.addAll(list2); - Page pageList=new PageImpl(list,pageRequest2,pageDto2.getTotalElements()); + + List subList = subPageList(list,pageRequest2); + if(CollectionUtil.isEmpty(subList)){ + Page emptyPageList=new PageImpl(new ArrayList<>(),pageRequest2,list.size()); + return emptyPageList; + } + Page pageList=new PageImpl(subList,pageRequest2,list.size()); return pageList; } return PageDto; } + + private List subPageList(List list,PageRequest pageRequest) { + if (CollectionUtil.isEmpty(list)) { + return null; + } + if (list.size() == 0) { + return null; + } + + Integer count = list.size(); + Integer pageCount = 0; + if (count % pageRequest.getPageSize() == 0) { + pageCount = count / pageRequest.getPageSize(); + } else { + pageCount = count / pageRequest.getPageSize() + 1; + } + + int fromIndex = 0; + int toIndex = 0; + + if(pageRequest.getPageNumber()+1!= pageCount) { + fromIndex = (pageRequest.getPageNumber()) * pageRequest.getPageSize(); + toIndex = fromIndex + pageRequest.getPageSize(); + } else { + fromIndex = (pageRequest.getPageNumber()) * pageRequest.getPageSize(); + toIndex = count; + } + + List pageList = list.subList(fromIndex, toIndex); + + return pageList; + } + @Override public NucleicDetectionInfoPO findOne(String id) { Optional optional = detectionInfoDao.findById(id); -- Gitee