瀏覽代碼

update 成绩统计

deason 1 年之前
父節點
當前提交
a77e8bf3b4

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

@@ -3,7 +3,6 @@ package cn.com.qmth.examcloud.core.oe.admin.api.controller;
 import cn.com.qmth.examcloud.commons.helpers.poi.ExcelWriter;
 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 cn.com.qmth.examcloud.web.config.SystemProperties;
 import cn.com.qmth.examcloud.web.support.ControllerSupport;
 import cn.com.qmth.examcloud.web.support.Naked;
@@ -34,23 +33,55 @@ public class ExamStatisticController extends ControllerSupport {
         examStatisticService.refresh(examId);
     }
 
-    @PostMapping("/overview")
-    @ApiOperation(value = "统计概况")
-    public OverviewInfo overview(@RequestParam Long examId, @RequestParam Long courseId) {
-        return examStatisticService.overview(examId, courseId);
+    @PostMapping("/overview/for/exam")
+    @ApiOperation(value = "统计概况(考试)")
+    public ExamStatisticInfo overviewForExam(@RequestParam Long examId) {
+        return examStatisticService.overviewForExam(examId);
+    }
+
+    @PostMapping("/overview/for/course")
+    @ApiOperation(value = "统计概况(课程)")
+    public List<ExamStatisticInfo> overviewForCourse(@RequestParam Long examId, @RequestParam(required = false) Long courseId) {
+        return examStatisticService.overviewForCourse(examId, courseId);
     }
 
     @PostMapping("/overview/for/org")
     @ApiOperation(value = "统计概况(学习中心)")
-    public List<ExamStatisticInfo> overviewForOrg(@RequestParam Long examId, @RequestParam Long courseId) {
-        return examStatisticService.overviewForOrg(examId, courseId);
+    public List<ExamStatisticInfo> overviewForOrg(@RequestParam Long examId, @RequestParam(required = false) Long orgId) {
+        return examStatisticService.overviewForOrg(examId, orgId);
+    }
+
+    @Naked
+    @GetMapping("/overview/for/course/export")
+    @ApiOperation(value = "统计概况(课程)导出Excel")
+    public void overviewForCourseExport(@RequestParam Long examId, @RequestParam(required = false) Long courseId) throws Exception {
+        List<ExamStatisticInfo> list = examStatisticService.overviewForCourse(examId, courseId);
+
+        List<Object[]> lines = new ArrayList<>();
+        for (ExamStatisticInfo info : list) {
+            lines.add(new Object[]{info.getCourseName(), info.getCourseCode(), info.getAllCount(), info.getFinishCount()
+                    , info.getUnFinishCount(), info.getUnFinishRate(), info.getPassScoreCount()
+                    , info.getPassScoreRate(), info.getGoodScoreCount(), info.getGoodScoreRate(),
+                    info.getIllegalityCount(), info.getIllegalityRate()});
+        }
+
+        String filePath = systemConfig.getTempDataDir() + File.separator + System.currentTimeMillis() + ".xlsx";
+        File file = new File(filePath);
+
+        ExcelWriter.write(new String[]{"课程名称", "课程代码", "应考人数", "实考人数", "缺考人数", "缺考率", "及格人数", "及格率", "优秀人数", "优秀率", "违纪人数", "违纪率"},
+                new Class[]{String.class, String.class, Integer.class, Integer.class, Integer.class, Double.class,
+                        Integer.class, Double.class, Integer.class, Double.class, Integer.class, Double.class},
+                lines, new File(filePath));
+
+        exportFile("课程统计.xlsx", file);
+        FileUtils.deleteQuietly(file);
     }
 
     @Naked
     @GetMapping("/overview/for/org/export")
     @ApiOperation(value = "统计概况(学习中心)导出Excel")
-    public void overviewForOrgExport(@RequestParam Long examId, @RequestParam Long courseId) throws Exception {
-        List<ExamStatisticInfo> list = examStatisticService.overviewForOrg(examId, courseId);
+    public void overviewForOrgExport(@RequestParam Long examId, @RequestParam(required = false) Long orgId) throws Exception {
+        List<ExamStatisticInfo> list = examStatisticService.overviewForOrg(examId, orgId);
 
         List<Object[]> lines = new ArrayList<>();
         for (ExamStatisticInfo info : list) {
@@ -62,8 +93,9 @@ public class ExamStatisticController extends ControllerSupport {
         String filePath = systemConfig.getTempDataDir() + File.separator + System.currentTimeMillis() + ".xlsx";
         File file = new File(filePath);
 
-        ExcelWriter.write(new String[]{"学习中心", "应考人数", "实考人数", "缺考人数", "缺考率", "及格人数", "及格率", "优秀人数", "优秀率"},
-                new Class[]{String.class, Integer.class, Integer.class, Integer.class, Double.class, Integer.class, Double.class, Integer.class, Double.class},
+        ExcelWriter.write(new String[]{"学习中心", "应考人数", "实考人数", "缺考人数", "缺考率", "及格人数", "及格率", "优秀人数", "优秀率", "违纪人数", "违纪率"},
+                new Class[]{String.class, Integer.class, Integer.class, Integer.class, Double.class,
+                        Integer.class, Double.class, Integer.class, Double.class, Integer.class, Double.class},
                 lines, new File(filePath));
 
         exportFile("学习中心统计.xlsx", file);

+ 5 - 0
examcloud-core-oe-admin-dao/src/main/java/cn/com/qmth/examcloud/core/oe/admin/dao/entity/ExamStatisticEntity.java

@@ -61,6 +61,11 @@ public class ExamStatisticEntity extends JpaEntity {
     @Column(nullable = false)
     private Integer goodScoreCount;
 
+    /**
+     * 违纪人数
+     */
+    //@Column(nullable = false)
+    //private Integer illegalityCount;
     public Long getId() {
         return id;
     }

+ 4 - 3
examcloud-core-oe-admin-service/src/main/java/cn/com/qmth/examcloud/core/oe/admin/service/ExamStatisticService.java

@@ -1,7 +1,6 @@
 package cn.com.qmth.examcloud.core.oe.admin.service;
 
 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 java.util.List;
 
@@ -9,8 +8,10 @@ public interface ExamStatisticService {
 
     void refresh(Long examId);
 
-    OverviewInfo overview(Long examId, Long courseId);
+    ExamStatisticInfo overviewForExam(Long examId);
 
-    List<ExamStatisticInfo> overviewForOrg(Long examId, Long courseId);
+    List<ExamStatisticInfo> overviewForCourse(Long examId, Long courseId);
+
+    List<ExamStatisticInfo> overviewForOrg(Long examId, Long orgId);
 
 }

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

@@ -1,7 +1,6 @@
 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 {
 
@@ -11,61 +10,64 @@ public class ExamStatisticInfo implements JsonSerializable {
 
     private Long courseId;
 
+    private String courseCode;
+
     private String courseName;
 
     private Long orgId;
 
-    @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;
 
+    /**
+     * 违纪人数
+     */
+    private Integer illegalityCount;
+
+    /**
+     * 违纪率
+     */
+    private Double illegalityRate;
+
     public ExamStatisticInfo() {
         this.allCount = 0;
         this.finishCount = 0;
@@ -75,6 +77,8 @@ public class ExamStatisticInfo implements JsonSerializable {
         this.passScoreRate = 0d;
         this.goodScoreCount = 0;
         this.goodScoreRate = 0d;
+        this.illegalityCount = 0;
+        this.illegalityRate = 0d;
     }
 
     public Long getExamId() {
@@ -93,6 +97,14 @@ public class ExamStatisticInfo implements JsonSerializable {
         this.courseId = courseId;
     }
 
+    public String getCourseCode() {
+        return courseCode;
+    }
+
+    public void setCourseCode(String courseCode) {
+        this.courseCode = courseCode;
+    }
+
     public String getCourseName() {
         return courseName;
     }
@@ -181,4 +193,19 @@ public class ExamStatisticInfo implements JsonSerializable {
         this.goodScoreRate = goodScoreRate;
     }
 
+    public Integer getIllegalityCount() {
+        return illegalityCount;
+    }
+
+    public void setIllegalityCount(Integer illegalityCount) {
+        this.illegalityCount = illegalityCount;
+    }
+
+    public Double getIllegalityRate() {
+        return illegalityRate;
+    }
+
+    public void setIllegalityRate(Double illegalityRate) {
+        this.illegalityRate = illegalityRate;
+    }
 }

+ 0 - 29
examcloud-core-oe-admin-service/src/main/java/cn/com/qmth/examcloud/core/oe/admin/service/bean/statistic/OverviewInfo.java

@@ -1,29 +0,0 @@
-package cn.com.qmth.examcloud.core.oe.admin.service.bean.statistic;
-
-import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
-
-public class OverviewInfo implements JsonSerializable {
-
-    private static final long serialVersionUID = 5667104330981650606L;
-
-    private ExamStatisticInfo examResult;
-
-    private ExamStatisticInfo courseResult;
-
-    public ExamStatisticInfo getExamResult() {
-        return examResult;
-    }
-
-    public void setExamResult(ExamStatisticInfo examResult) {
-        this.examResult = examResult;
-    }
-
-    public ExamStatisticInfo getCourseResult() {
-        return courseResult;
-    }
-
-    public void setCourseResult(ExamStatisticInfo courseResult) {
-        this.courseResult = courseResult;
-    }
-
-}

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

@@ -4,6 +4,7 @@ import cn.com.qmth.examcloud.commons.exception.StatusException;
 import cn.com.qmth.examcloud.commons.util.MathUtils;
 import cn.com.qmth.examcloud.core.basic.api.CourseCloudService;
 import cn.com.qmth.examcloud.core.basic.api.OrgCloudService;
+import cn.com.qmth.examcloud.core.basic.api.bean.CourseBean;
 import cn.com.qmth.examcloud.core.basic.api.bean.OrgBean;
 import cn.com.qmth.examcloud.core.basic.api.request.GetCoursesByIdListReq;
 import cn.com.qmth.examcloud.core.basic.api.request.GetOrgMapsReq;
@@ -13,7 +14,6 @@ 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.ExamStudentScoreInfo;
-import cn.com.qmth.examcloud.core.oe.admin.service.bean.statistic.OverviewInfo;
 import cn.com.qmth.examcloud.examwork.api.ExamCloudService;
 import cn.com.qmth.examcloud.examwork.api.request.GetExamCourseIdsReq;
 import cn.com.qmth.examcloud.examwork.api.request.GetExamCourseReq;
@@ -21,7 +21,6 @@ import cn.com.qmth.examcloud.examwork.api.response.GetExamCourseIdsResp;
 import cn.com.qmth.examcloud.examwork.api.response.GetExamCourseResp;
 import cn.com.qmth.examcloud.support.CacheConstants;
 import cn.com.qmth.examcloud.web.redis.RedisClient;
-import com.google.common.collect.Lists;
 import org.apache.commons.collections4.CollectionUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -30,10 +29,7 @@ import org.springframework.jdbc.core.BeanPropertyRowMapper;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @Service
@@ -167,97 +163,127 @@ public class ExamStatisticServiceImpl implements ExamStatisticService {
     }
 
     @Override
-    public OverviewInfo overview(Long examId, Long courseId) {
-        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;
-        }
-
-        GetCoursesByIdListReq req = new GetCoursesByIdListReq();
-        req.setCourseIdList(Lists.newArrayList(courseId));
-        GetCoursesByIdListResp resp = courseCloudService.getCoursesByIdList(req);
-        courseResult.setCourseName(resp.getCourseList().get(0).getName());
-
-        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());
-            }
+    public ExamStatisticInfo overviewForExam(Long examId) {
+        StringBuffer sql = new StringBuffer();
+        sql.append(" select");
+        sql.append(" exam_id,");
+        sql.append(" sum(all_count) as allCount,");
+        sql.append(" sum(finish_count) as finishCount,");
+        sql.append(" sum(pass_score_count) as passScoreCount,");
+        sql.append(" sum(good_score_count) as goodScoreCount");
+        sql.append(" from ec_oe_exam_statistic");
+        sql.append(" where exam_id = ").append(examId);
+
+        List<ExamStatisticInfo> list = jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper(ExamStatisticInfo.class));
+        if (list.isEmpty()) {
+            return new ExamStatisticInfo();
         }
 
-        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()));
+        ExamStatisticInfo info = list.get(0);
+        if (info.getExamId() == null) {
+            return new ExamStatisticInfo();
         }
 
-        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()));
+        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()));
+            info.setIllegalityRate(MathUtils.percentage(info.getIllegalityCount(), info.getAllCount()));
         }
 
-        return result;
+        return info;
     }
 
     @Override
-    public List<ExamStatisticInfo> overviewForOrg(Long examId, Long courseId) {
-        List<ExamStatisticEntity> list = examStatisticRepo.findByExamIdAndCourseId(examId, courseId);
-        if (CollectionUtils.isEmpty(list)) {
-            return new ArrayList<>();
+    public List<ExamStatisticInfo> overviewForCourse(Long examId, Long courseId) {
+        StringBuffer sql = new StringBuffer();
+        sql.append(" select");
+        sql.append(" course_id,");
+        sql.append(" sum(all_count) as allCount,");
+        sql.append(" sum(finish_count) as finishCount,");
+        sql.append(" sum(pass_score_count) as passScoreCount,");
+        sql.append(" sum(good_score_count) as goodScoreCount");
+        sql.append(" from ec_oe_exam_statistic");
+        sql.append(" where exam_id = ").append(examId);
+        if (courseId != null) {
+            sql.append(" and course_id = ").append(courseId);
         }
+        sql.append(" group by course_id");
 
-        List<ExamStatisticInfo> result = new ArrayList<>();
-
-        Map<Long, List<ExamStatisticEntity>> orgStatisticMaps = list.stream().collect(Collectors.groupingBy(ExamStatisticEntity::getOrgId));
+        Set<Long> courseIds = new HashSet<>();
+        List<ExamStatisticInfo> list = jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper(ExamStatisticInfo.class));
+        for (ExamStatisticInfo info : list) {
+            courseIds.add(info.getCourseId());
 
-        // 获取机构信息列表
-        GetOrgMapsReq orgMapsReq = new GetOrgMapsReq();
-        orgMapsReq.setOrgIds(orgStatisticMaps.keySet());
-        Map<Long, OrgBean> orgMaps = orgCloudService.getOrgMaps(orgMapsReq).getOrgMaps();
+            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()));
+                info.setIllegalityRate(MathUtils.percentage(info.getIllegalityCount(), info.getAllCount()));
+            }
+        }
 
-        for (Map.Entry<Long, List<ExamStatisticEntity>> e : orgStatisticMaps.entrySet()) {
-            ExamStatisticInfo info = new ExamStatisticInfo();
-            info.setOrgId(e.getKey());
+        // 获取课程信息列表
+        GetCoursesByIdListReq req = new GetCoursesByIdListReq();
+        req.setCourseIdList(new ArrayList<>(courseIds));
+        GetCoursesByIdListResp resp = courseCloudService.getCoursesByIdList(req);
+        Map<Long, CourseBean> courseMaps = resp.getCourseList().stream().collect(Collectors.toMap(CourseBean::getId, v -> v));
 
-            OrgBean org = orgMaps.get(e.getKey());
-            if (org != null) {
-                info.setOrgName(org.getName());
+        for (ExamStatisticInfo info : list) {
+            CourseBean course = courseMaps.get(info.getCourseId());
+            if (course != null) {
+                info.setCourseName(course.getName());
+                info.setCourseCode(course.getCode());
             }
+        }
 
-            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());
-            }
+        return list;
+    }
+
+    @Override
+    public List<ExamStatisticInfo> overviewForOrg(Long examId, Long orgId) {
+        StringBuffer sql = new StringBuffer();
+        sql.append(" select");
+        sql.append(" org_id,");
+        sql.append(" sum(all_count) as allCount,");
+        sql.append(" sum(finish_count) as finishCount,");
+        sql.append(" sum(pass_score_count) as passScoreCount,");
+        sql.append(" sum(good_score_count) as goodScoreCount");
+        sql.append(" from ec_oe_exam_statistic");
+        sql.append(" where exam_id = ").append(examId);
+        if (orgId != null) {
+            sql.append(" and org_id = ").append(orgId);
+        }
+        sql.append(" group by org_id");
+
+        Set<Long> orgIds = new HashSet<>();
+        List<ExamStatisticInfo> list = jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper(ExamStatisticInfo.class));
+        for (ExamStatisticInfo info : list) {
+            orgIds.add(info.getOrgId());
 
             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()));
+                info.setIllegalityRate(MathUtils.percentage(info.getIllegalityCount(), info.getAllCount()));
             }
+        }
 
-            result.add(info);
+        // 获取机构信息列表
+        GetOrgMapsReq req = new GetOrgMapsReq();
+        req.setOrgIds(orgIds);
+        Map<Long, OrgBean> orgMaps = orgCloudService.getOrgMaps(req).getOrgMaps();
+        for (ExamStatisticInfo info : list) {
+            OrgBean org = orgMaps.get(info.getOrgId());
+            if (org != null) {
+                info.setOrgName(org.getName());
+            }
         }
 
-        return result;
+        return list;
     }
 
 }