deason 6 years ago
parent
commit
b32afebf4d

+ 37 - 2
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/bean/coursestatistic/CourseStatisticConvert.java

@@ -9,6 +9,14 @@ package cn.com.qmth.examcloud.core.print.service.bean.coursestatistic;
 
 import cn.com.qmth.examcloud.core.print.entity.CoursePaper;
 import cn.com.qmth.examcloud.core.print.entity.CourseStatistic;
+import com.google.common.collect.Lists;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageImpl;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
+
+import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * @author: fengdesheng
@@ -16,10 +24,37 @@ import cn.com.qmth.examcloud.core.print.entity.CourseStatistic;
  */
 public class CourseStatisticConvert {
 
-    public static CourseStatisticInfo of(CourseStatistic statistic, CoursePaper paper) {
+    public static CourseStatisticInfo of(CourseStatistic statistic) {
         CourseStatisticInfo info = new CourseStatisticInfo();
-        //todo
+        info.setId(statistic.getId());
+        info.setOrgId(statistic.getOrgId());
+        info.setExamId(statistic.getExamId());
+        info.setCourseId(statistic.getCourseId());
+        info.setCourseCode(statistic.getCourseCode());
+        info.setCourseName(statistic.getCourseName());
+        info.setPaperType(statistic.getPaperType());
+        info.setPaperBindingStatus(statistic.getPaperBindingStatus());
+        info.setTotalStudent(statistic.getTotalStudent());
+
+        CoursePaper paper = statistic.getCoursePaper();
+        if (paper != null) {
+            info.setPaperId(paper.getPaperId());
+            info.setPaperName(paper.getPaperName());
+            info.setPaperFileUrl(paper.getPaperFileUrl());
+            info.setAnswerFileUrl(paper.getAnswerFileUrl());
+            info.setPaperP(paper.getPaperP());
+        }
         return info;
     }
 
+    public static Page<CourseStatisticInfo> ofPage(Page<CourseStatistic> page) {
+        Pageable pageable = new PageRequest(page.getNumber(), page.getSize());
+        List<CourseStatistic> entities = page.getContent();
+        if (entities == null || entities.isEmpty()) {
+            return new PageImpl<>(Lists.newArrayList(), pageable, page.getTotalElements());
+        }
+        List<CourseStatisticInfo> list = entities.stream().map(entity -> of(entity)).collect(Collectors.toList());
+        return new PageImpl<>(list, pageable, page.getTotalElements());
+    }
+
 }

+ 30 - 30
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/bean/coursestatistic/CourseStatisticInfo.java

@@ -41,22 +41,22 @@ public class CourseStatisticInfo implements Serializable {
      */
     private String courseName;
     /**
-     * 试卷ID
-     */
-    private Long paperId;
-    /**
-     * 试卷名称
+     * @See PaperBindingStatus.java
+     * 试卷绑定状态
      */
-    private String paperName;
+    private Integer paperBindingStatus;
     /**
      * 试卷类型
      */
     private String paperType;
     /**
-     * @See PaperBindingStatus.java
-     * 试卷绑定状态
+     * 试卷ID
      */
-    private Integer paperBindingStatus;
+    private String paperId;
+    /**
+     * 试卷名称
+     */
+    private String paperName;
     /**
      * 试卷文件URL
      */
@@ -68,7 +68,7 @@ public class CourseStatisticInfo implements Serializable {
     /**
      * 试卷P数
      */
-    private Integer totalP;
+    private Integer paperP;
     /**
      * 考生人数
      */
@@ -126,20 +126,12 @@ public class CourseStatisticInfo implements Serializable {
         this.courseName = courseName;
     }
 
-    public Long getPaperId() {
-        return paperId;
-    }
-
-    public void setPaperId(Long paperId) {
-        this.paperId = paperId;
-    }
-
-    public String getPaperName() {
-        return paperName;
+    public Integer getPaperBindingStatus() {
+        return paperBindingStatus;
     }
 
-    public void setPaperName(String paperName) {
-        this.paperName = paperName;
+    public void setPaperBindingStatus(Integer paperBindingStatus) {
+        this.paperBindingStatus = paperBindingStatus;
     }
 
     public String getPaperType() {
@@ -150,12 +142,20 @@ public class CourseStatisticInfo implements Serializable {
         this.paperType = paperType;
     }
 
-    public Integer getPaperBindingStatus() {
-        return paperBindingStatus;
+    public String getPaperId() {
+        return paperId;
     }
 
-    public void setPaperBindingStatus(Integer paperBindingStatus) {
-        this.paperBindingStatus = paperBindingStatus;
+    public void setPaperId(String paperId) {
+        this.paperId = paperId;
+    }
+
+    public String getPaperName() {
+        return paperName;
+    }
+
+    public void setPaperName(String paperName) {
+        this.paperName = paperName;
     }
 
     public String getPaperFileUrl() {
@@ -174,12 +174,12 @@ public class CourseStatisticInfo implements Serializable {
         this.answerFileUrl = answerFileUrl;
     }
 
-    public Integer getTotalP() {
-        return totalP != null ? totalP : 0;
+    public Integer getPaperP() {
+        return paperP != null ? paperP : 0;
     }
 
-    public void setTotalP(Integer totalP) {
-        this.totalP = totalP;
+    public void setPaperP(Integer paperP) {
+        this.paperP = paperP;
     }
 
     public Integer getTotalStudent() {

+ 16 - 5
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/impl/CourseStatisticServiceImpl.java

@@ -7,14 +7,20 @@
 
 package cn.com.qmth.examcloud.core.print.service.impl;
 
+import cn.com.qmth.examcloud.core.print.common.jpa.OrderBuilder;
 import cn.com.qmth.examcloud.core.print.common.jpa.SearchBuilder;
+import cn.com.qmth.examcloud.core.print.common.jpa.SpecUtils;
 import cn.com.qmth.examcloud.core.print.common.utils.Check;
+import cn.com.qmth.examcloud.core.print.entity.CourseStatistic;
 import cn.com.qmth.examcloud.core.print.repository.CourseStatisticRepository;
 import cn.com.qmth.examcloud.core.print.service.CourseStatisticService;
+import cn.com.qmth.examcloud.core.print.service.bean.coursestatistic.CourseStatisticConvert;
 import cn.com.qmth.examcloud.core.print.service.bean.coursestatistic.CourseStatisticInfo;
 import cn.com.qmth.examcloud.core.print.service.bean.coursestatistic.CourseStatisticQuery;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.jpa.domain.Specification;
 import org.springframework.stereotype.Service;
 
 /**
@@ -40,14 +46,19 @@ public class CourseStatisticServiceImpl implements CourseStatisticService {
         if (query.getCourseId() != null) {
             searches.eq("courseId", query.getCourseId());
         }
-        if (query.getPaperId() != null) {
-            searches.eq("paperId", query.getPaperId());
-        }
         if (query.getPaperBindingStatus() != null) {
             searches.eq("paperBindingStatus", query.getPaperBindingStatus());
         }
-        //todo
-        return null;
+        if (query.getPaperId() != null) {
+            searches.eq("coursePaper.id", query.getPaperId());
+        }
+        Specification<CourseStatistic> spec = SpecUtils.buildSearchers(CourseStatistic.class, searches.build());
+        //排序条件
+        OrderBuilder orders = new OrderBuilder().desc("id");
+        //分页条件
+        Pageable pageable = SpecUtils.buildPageable(query.getPageNo(), query.getPageSize(), orders.build());
+        Page<CourseStatistic> page = courseStatisticsRepository.findAll(spec, pageable);
+        return CourseStatisticConvert.ofPage(page);
     }
 
     @Override

+ 7 - 4
examcloud-core-print-starter/src/test/java/cn/com/qmth/examcloud/core/print/test/CourseStatisticServiceTest.java

@@ -8,9 +8,11 @@
 package cn.com.qmth.examcloud.core.print.test;
 
 import cn.com.qmth.examcloud.core.print.service.CourseStatisticService;
+import cn.com.qmth.examcloud.core.print.service.bean.coursestatistic.CourseStatisticInfo;
 import cn.com.qmth.examcloud.core.print.service.bean.coursestatistic.CourseStatisticQuery;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
 
 /**
  * @author: fengdesheng
@@ -25,10 +27,11 @@ public class CourseStatisticServiceTest extends BaseTest {
         CourseStatisticQuery query = new CourseStatisticQuery();
         query.setOrgId(1L);
         query.setExamId(1L);
-//        query.setCourseId(1L);
-//        query.setPaperId(1L);
-//        query.setPaperBindingStatus(1);
-        courseStatisticService.getCourseStatisticList(query);
+        query.setCourseId(1L);
+        query.setPaperBindingStatus(0);
+        //query.setPaperId(1L);
+        Page<CourseStatisticInfo> page = courseStatisticService.getCourseStatisticList(query);
+        System.out.println(jsonMapper.toJson(page));
     }
 
     @Test