deason 2 жил өмнө
parent
commit
86ca90121d

+ 11 - 4
examcloud-core-oe-admin-api-provider/src/main/java/cn/com/qmth/examcloud/core/oe/admin/api/controller/ExamStatisticController.java

@@ -1,5 +1,6 @@
 package cn.com.qmth.examcloud.core.oe.admin.api.controller;
 
+import cn.com.qmth.examcloud.core.oe.admin.base.utils.excel.ExportUtils;
 import cn.com.qmth.examcloud.core.oe.admin.service.ExamStatisticService;
 import cn.com.qmth.examcloud.core.oe.admin.service.bean.statistic.ExamStatisticInfo;
 import cn.com.qmth.examcloud.core.oe.admin.service.bean.statistic.OverviewInfo;
@@ -7,11 +8,9 @@ import cn.com.qmth.examcloud.web.support.ControllerSupport;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletResponse;
 import java.util.List;
 
 @RestController
@@ -34,4 +33,12 @@ public class ExamStatisticController extends ControllerSupport {
         return examStatisticService.overviewForOrg(examId, courseId);
     }
 
+    @GetMapping("/overview/for/org/export")
+    @ApiOperation(value = "统计概况(学习中心)导出Excel")
+    public void overviewForOrgExport(@RequestParam Long examId, @RequestParam Long courseId
+            , HttpServletResponse response) throws Exception {
+        List<ExamStatisticInfo> list = examStatisticService.overviewForOrg(examId, courseId);
+        ExportUtils.exportEXCEL("学习中心统计", ExamStatisticInfo.class, list, response);
+    }
+
 }

+ 6 - 0
examcloud-core-oe-admin-dao/src/main/java/cn/com/qmth/examcloud/core/oe/admin/dao/ExamStatisticRepo.java

@@ -5,7 +5,13 @@ import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.stereotype.Repository;
 
+import java.util.List;
+
 @Repository
 public interface ExamStatisticRepo extends JpaRepository<ExamStatisticEntity, Long>, JpaSpecificationExecutor<ExamStatisticEntity> {
 
+    List<ExamStatisticEntity> findByExamId(Long examId);
+
+    List<ExamStatisticEntity> findByExamIdAndCourseId(Long examId, Long courseId);
+
 }

+ 40 - 9
examcloud-core-oe-admin-service/src/main/java/cn/com/qmth/examcloud/core/oe/admin/service/bean/statistic/ExamStatisticInfo.java

@@ -1,6 +1,7 @@
 package cn.com.qmth.examcloud.core.oe.admin.service.bean.statistic;
 
 import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
+import cn.com.qmth.examcloud.support.excel.ExcelProperty;
 
 public class ExamStatisticInfo implements JsonSerializable {
 
@@ -10,50 +11,72 @@ public class ExamStatisticInfo implements JsonSerializable {
 
     private Long courseId;
 
+    private String courseName;
+
     private Long orgId;
 
-    private String title;
+    @ExcelProperty(name = "学习中心", index = 1)
+    private String orgName;
 
     /**
      * 应考人数
      */
+    @ExcelProperty(name = "应考人数", index = 2)
     private Integer allCount;
 
     /**
      * 实考人数
      */
+    @ExcelProperty(name = "实考人数", index = 3)
     private Integer finishCount;
 
     /**
      * 缺考人数
      */
+    @ExcelProperty(name = "缺考人数", index = 4)
     private Integer unFinishCount;
 
     /**
      * 缺考率
      */
+    @ExcelProperty(name = "缺考率", index = 5)
     private Double unFinishRate;
 
     /**
      * (成绩)及格人数
      */
+    @ExcelProperty(name = "及格人数", index = 6)
     private Integer passScoreCount;
 
     /**
      * 及格率
      */
+    @ExcelProperty(name = "及格率", index = 7)
     private Double passScoreRate;
 
     /**
      * (成绩)优秀人数
      */
+    @ExcelProperty(name = "优秀人数", index = 8)
     private Integer goodScoreCount;
 
     /**
      * 优秀率
      */
+    @ExcelProperty(name = "优秀率", index = 9)
     private Double goodScoreRate;
 
+    public ExamStatisticInfo() {
+        this.allCount = 0;
+        this.finishCount = 0;
+        this.unFinishCount = 0;
+        this.unFinishRate = 0d;
+        this.passScoreCount = 0;
+        this.passScoreRate = 0d;
+        this.goodScoreCount = 0;
+        this.goodScoreRate = 0d;
+    }
+
     public Long getExamId() {
         return examId;
     }
@@ -70,6 +93,14 @@ public class ExamStatisticInfo implements JsonSerializable {
         this.courseId = courseId;
     }
 
+    public String getCourseName() {
+        return courseName;
+    }
+
+    public void setCourseName(String courseName) {
+        this.courseName = courseName;
+    }
+
     public Long getOrgId() {
         return orgId;
     }
@@ -78,6 +109,14 @@ public class ExamStatisticInfo implements JsonSerializable {
         this.orgId = orgId;
     }
 
+    public String getOrgName() {
+        return orgName;
+    }
+
+    public void setOrgName(String orgName) {
+        this.orgName = orgName;
+    }
+
     public Integer getAllCount() {
         return allCount;
     }
@@ -142,12 +181,4 @@ public class ExamStatisticInfo implements JsonSerializable {
         this.goodScoreRate = goodScoreRate;
     }
 
-    public String getTitle() {
-        return title;
-    }
-
-    public void setTitle(String title) {
-        this.title = title;
-    }
-
 }

+ 76 - 2
examcloud-core-oe-admin-service/src/main/java/cn/com/qmth/examcloud/core/oe/admin/service/impl/ExamStatisticServiceImpl.java

@@ -1,15 +1,21 @@
 package cn.com.qmth.examcloud.core.oe.admin.service.impl;
 
+import cn.com.qmth.examcloud.commons.util.MathUtils;
 import cn.com.qmth.examcloud.core.oe.admin.dao.ExamStatisticRepo;
+import cn.com.qmth.examcloud.core.oe.admin.dao.entity.ExamStatisticEntity;
 import cn.com.qmth.examcloud.core.oe.admin.service.ExamStatisticService;
 import cn.com.qmth.examcloud.core.oe.admin.service.bean.statistic.ExamStatisticInfo;
 import cn.com.qmth.examcloud.core.oe.admin.service.bean.statistic.OverviewInfo;
+import org.apache.commons.collections4.CollectionUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 @Service
 public class ExamStatisticServiceImpl implements ExamStatisticService {
@@ -21,12 +27,80 @@ public class ExamStatisticServiceImpl implements ExamStatisticService {
 
     @Override
     public OverviewInfo overview(Long examId, Long courseId) {
-        return null;
+        OverviewInfo result = new OverviewInfo();
+
+        ExamStatisticInfo examResult = new ExamStatisticInfo();
+        ExamStatisticInfo courseResult = new ExamStatisticInfo();
+        result.setExamResult(examResult);
+        result.setCourseResult(courseResult);
+
+        List<ExamStatisticEntity> list = examStatisticRepo.findByExamId(examId);
+        if (CollectionUtils.isEmpty(list)) {
+            return result;
+        }
+
+        for (ExamStatisticEntity v : list) {
+            examResult.setAllCount(examResult.getAllCount() + v.getAllCount());
+            examResult.setFinishCount(examResult.getFinishCount() + v.getFinishCount());
+            examResult.setPassScoreCount(examResult.getPassScoreCount() + v.getPassScoreCount());
+            examResult.setGoodScoreCount(examResult.getGoodScoreCount() + v.getGoodScoreCount());
+            if (v.getCourseId().equals(courseId)) {
+                courseResult.setAllCount(courseResult.getAllCount() + v.getAllCount());
+                courseResult.setFinishCount(courseResult.getFinishCount() + v.getFinishCount());
+                courseResult.setPassScoreCount(courseResult.getPassScoreCount() + v.getPassScoreCount());
+                courseResult.setGoodScoreCount(courseResult.getGoodScoreCount() + v.getGoodScoreCount());
+            }
+        }
+
+        examResult.setUnFinishCount(examResult.getAllCount() - examResult.getFinishCount());
+        if (examResult.getAllCount() > 0) {
+            examResult.setUnFinishRate(MathUtils.percentage(examResult.getUnFinishCount(), examResult.getAllCount()));
+            examResult.setPassScoreRate(MathUtils.percentage(examResult.getPassScoreCount(), examResult.getAllCount()));
+            examResult.setGoodScoreRate(MathUtils.percentage(examResult.getGoodScoreCount(), examResult.getAllCount()));
+        }
+
+        courseResult.setUnFinishCount(courseResult.getAllCount() - courseResult.getFinishCount());
+        if (courseResult.getAllCount() > 0) {
+            courseResult.setUnFinishRate(MathUtils.percentage(courseResult.getUnFinishCount(), courseResult.getAllCount()));
+            courseResult.setPassScoreRate(MathUtils.percentage(courseResult.getPassScoreCount(), courseResult.getAllCount()));
+            courseResult.setGoodScoreRate(MathUtils.percentage(courseResult.getGoodScoreCount(), courseResult.getAllCount()));
+        }
+
+        return result;
     }
 
     @Override
     public List<ExamStatisticInfo> overviewForOrg(Long examId, Long courseId) {
-        return null;
+        List<ExamStatisticEntity> list = examStatisticRepo.findByExamIdAndCourseId(examId, courseId);
+        if (CollectionUtils.isEmpty(list)) {
+            return new ArrayList<>();
+        }
+
+        List<ExamStatisticInfo> result = new ArrayList<>();
+
+        Map<Long, List<ExamStatisticEntity>> orgStatisticMaps = list.stream().collect(Collectors.groupingBy(ExamStatisticEntity::getOrgId));
+        for (Map.Entry<Long, List<ExamStatisticEntity>> e : orgStatisticMaps.entrySet()) {
+            ExamStatisticInfo info = new ExamStatisticInfo();
+            info.setOrgId(e.getKey());
+
+            for (ExamStatisticEntity v : e.getValue()) {
+                info.setAllCount(info.getAllCount() + v.getAllCount());
+                info.setFinishCount(info.getFinishCount() + v.getFinishCount());
+                info.setPassScoreCount(info.getPassScoreCount() + v.getPassScoreCount());
+                info.setGoodScoreCount(info.getGoodScoreCount() + v.getGoodScoreCount());
+            }
+
+            info.setUnFinishCount(info.getAllCount() - info.getFinishCount());
+            if (info.getAllCount() > 0) {
+                info.setUnFinishRate(MathUtils.percentage(info.getUnFinishCount(), info.getAllCount()));
+                info.setPassScoreRate(MathUtils.percentage(info.getPassScoreCount(), info.getAllCount()));
+                info.setGoodScoreRate(MathUtils.percentage(info.getGoodScoreCount(), info.getAllCount()));
+            }
+
+            result.add(info);
+        }
+
+        return result;
     }
 
 }