xiatian 5 rokov pred
rodič
commit
88c4ba71eb

+ 25 - 8
examcloud-core-reports-service/src/main/java/cn/com/qmth/examcloud/core/reports/service/impl/StudentTotalCountServiceImpl.java

@@ -1,6 +1,8 @@
 package cn.com.qmth.examcloud.core.reports.service.impl;
 
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -10,10 +12,6 @@ import javax.persistence.criteria.Predicate;
 
 import org.apache.commons.collections.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.data.domain.Sort;
-import org.springframework.data.domain.Sort.Direction;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -67,9 +65,7 @@ public class StudentTotalCountServiceImpl implements StudentTotalCountService {
 			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
 		};
 
-		PageRequest pageRequest = PageRequest.of(pageNo - 1, pageSize, new Sort(Direction.DESC, "id"));
-
-		Page<StudentTotalCountEntity> es = studentTotalCountRepo.findAll(specification, pageRequest);
+		List<StudentTotalCountEntity> es = studentTotalCountRepo.findAll(specification);
 
 		List<StudentCountBean> ret = Lists.newArrayList();
 
@@ -84,7 +80,28 @@ public class StudentTotalCountServiceImpl implements StudentTotalCountService {
 		fillOnlineCount(ret);
 		fillOnExamCount(ret);
 		fillRootOrgName(ret);
-		return new PageInfo<StudentCountBean>(es, ret);
+		Collections.sort(ret, new Comparator<StudentCountBean>() {
+
+			@Override
+			public int compare(StudentCountBean o1, StudentCountBean o2) {
+				if (o1.getOnlineCount() > o2.getOnlineCount()) {
+					return -1;
+				} else if (o1.getOnlineCount() < o2.getOnlineCount()) {
+					return 1;
+				} else {
+					return 0;
+				}
+			}
+
+		});
+		int total = ret.size();
+		ret = ret.stream().skip((pageNo - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
+		PageInfo<StudentCountBean> pi=new PageInfo<StudentCountBean>();
+		pi.setLimit(pageSize);
+		pi.setList(ret);
+		pi.setPages(pageNo);
+		pi.setTotal(total);
+		return pi;
 	}
 
 	private void fillOnlineCount(List<StudentCountBean> ret) {