소스 검색

添加考试进度导出功能

lideyin 5 년 전
부모
커밋
88c1e55f43

+ 99 - 72
examcloud-core-oe-admin-api-provider/src/main/java/cn/com/qmth/examcloud/core/oe/admin/api/controller/ExamStudentController.java

@@ -17,6 +17,7 @@ import java.util.concurrent.ConcurrentHashMap;
 import javax.servlet.http.HttpServletResponse;
 
 import cn.com.qmth.examcloud.core.oe.admin.service.ExamCacheTransferHelper;
+import cn.com.qmth.examcloud.core.oe.admin.service.bean.examstudent.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -28,14 +29,6 @@ import org.springframework.web.bind.annotation.RestController;
 
 import cn.com.qmth.examcloud.core.basic.api.bean.CourseBean;
 import cn.com.qmth.examcloud.core.oe.admin.service.ExamStudentService;
-import cn.com.qmth.examcloud.core.oe.admin.service.bean.examstudent.CourseProgressInfo;
-import cn.com.qmth.examcloud.core.oe.admin.service.bean.examstudent.ExamStudentEntityConvert;
-import cn.com.qmth.examcloud.core.oe.admin.service.bean.examstudent.ExamStudentExcel;
-import cn.com.qmth.examcloud.core.oe.admin.service.bean.examstudent.ExamStudentFinishedStatistic;
-import cn.com.qmth.examcloud.core.oe.admin.service.bean.examstudent.ExamStudentInfo;
-import cn.com.qmth.examcloud.core.oe.admin.service.bean.examstudent.ExamStudentOrgStatistic;
-import cn.com.qmth.examcloud.core.oe.admin.service.bean.examstudent.ExamStudentQuery;
-import cn.com.qmth.examcloud.core.oe.admin.service.bean.examstudent.ExamStudentUnFinishedExcel;
 import cn.com.qmth.examcloud.core.oe.common.base.utils.Check;
 import cn.com.qmth.examcloud.core.oe.common.base.utils.JsonMapper;
 import cn.com.qmth.examcloud.core.oe.common.base.utils.excel.ExportUtils;
@@ -60,36 +53,36 @@ public class ExamStudentController extends ControllerSupport {
     private ExamStudentService examStudentService;
     @Autowired
     private GainBaseDataService gainBaseDataService;
-    
+
     /**
      * 查询课程本地缓存
      */
-    private static Map<Long,CourseBean> courseBeanLocalCache;
-    
+    private static Map<Long, CourseBean> courseBeanLocalCache;
+
     private static Timer timer;
-    
-    static{
-    	courseBeanLocalCache = new ConcurrentHashMap<Long, CourseBean>();
-    	timer = new Timer();
+
+    static {
+        courseBeanLocalCache = new ConcurrentHashMap<Long, CourseBean>();
+        timer = new Timer();
     }
-    
-    class CleanCourseBeanCacheTask extends TimerTask{
-		@Override
-		public void run() {
-			courseBeanLocalCache.clear();
-		}
+
+    class CleanCourseBeanCacheTask extends TimerTask {
+        @Override
+        public void run() {
+            courseBeanLocalCache.clear();
+        }
     }
-    
-    public ExamStudentController(){
-    	long delay = 10*60*1000;//10分钟后开始
-    	long period = 30*60*1000;//30分钟清理一次
-    	timer.schedule(new CleanCourseBeanCacheTask(),delay,period);
+
+    public ExamStudentController() {
+        long delay = 10 * 60 * 1000;//10分钟后开始
+        long period = 30 * 60 * 1000;//30分钟清理一次
+        timer.schedule(new CleanCourseBeanCacheTask(), delay, period);
     }
 
     @PostMapping("/examScheduling/list")
     @ApiOperation(value = "查询“考试进度详情”列表(分页)")
     public Page<ExamStudentInfo> getExamScheduling(@RequestBody ExamStudentQuery query) {
-    	Check.isNull(query, "查询参数不能为空!");
+        Check.isNull(query, "查询参数不能为空!");
         Check.isNull(query.getExamId(), "考试批次不能为空!");
         return examStudentService.getExamStudentListPage(query);
     }
@@ -108,7 +101,7 @@ public class ExamStudentController extends ControllerSupport {
     @PostMapping("/unfinished/list")
     @ApiOperation(value = "查询“缺考登记”列表(分页)")
     public Page<ExamStudentInfo> getExamStudentUnFinishedList(@RequestBody ExamStudentQuery query) {
-    	Check.isNull(query, "查询参数不能为空!");
+        Check.isNull(query, "查询参数不能为空!");
         Check.isNull(query.getExamId(), "考试批次不能为空!");
         query.setFinished(0);
         return examStudentService.getExamStudentListPage(query);
@@ -130,62 +123,76 @@ public class ExamStudentController extends ControllerSupport {
     @PostMapping("/reexamine/list")
     @ApiOperation(value = "查询重考考生列表(分页)")
     public Page<ExamStudentInfo> getReExamineStudentList(@RequestBody ExamStudentQuery query) {
-    	Check.isNull(query, "查询参数不能为空!");
+        Check.isNull(query, "查询参数不能为空!");
         Check.isNull(query.getExamId(), "考试批次不能为空!");
         return examStudentService.getReExamineStudentList(query);
     }
-    
+
     @PostMapping("/reexamine")
     @ApiOperation(value = "设置重考")
-    public void setReexamine(@RequestParam Long examStudentId){
-    	if(examStudentId == null){
-    		return;
-    	}
-    	examStudentService.setReexamine(examStudentId);
+    public void setReexamine(@RequestParam Long examStudentId) {
+        if (examStudentId == null) {
+            return;
+        }
+        examStudentService.setReexamine(examStudentId);
     }
 
     @PostMapping("/statistic/by/finished")
     @ApiOperation(value = "考试概况-按考试完成进度统计")
     public ExamStudentFinishedStatistic getExamStudentStatisticByFinished(@RequestParam Long examId) {
-    	if(examId == null){
-    		return null;
-    	}
+        if (examId == null) {
+            return null;
+        }
         return examStudentService.getExamStudentStatisticByFinished(examId);
     }
 
     @PostMapping("/statistic/by/org")
     @ApiOperation(value = "考试概况-按学习中心统计")
     public List<ExamStudentOrgStatistic> getExamStudentStatisticByOrg(@RequestParam Long examId, @RequestParam(required = false) Long orgId) {
-    	if(examId == null){
-    		return null;
-    	}
+        if (examId == null) {
+            return null;
+        }
         return examStudentService.getExamStudentStatisticByOrg(examId, orgId);
     }
-    
+
+    @GetMapping("/statistic/by/org/export")
+    @ApiOperation(value = "导出“考试概况-按学习中心统计”列表(Excel)")
+    public void exportExamStudentStatisticByOrg(@RequestParam Long examId,
+                                                @RequestParam(required = false) Long orgId,
+                                          HttpServletResponse response) throws Exception {
+        Check.isNull(examId, "请选择考试批次!");
+        List<ExamStudentOrgStatistic> examStudentStatisticByOrgList = examStudentService.getExamStudentStatisticByOrg(examId, orgId);
+        List<OrgCompleteProgressExcel> resultList =
+                ExamStudentEntityConvert.copyFromExamStudentOrgStatistic(examStudentStatisticByOrgList);
+        ExportUtils.exportEXCEL("学习中心完成进度", OrgCompleteProgressExcel.class, resultList, response);
+    }
+
     /**
      * 查询课程
+     *
      * @param examId
      * @param orgId
      * @return
      */
     @GetMapping("/findCoursesByExamIdAndOrgId")
     @ApiOperation(value = "查询课程")
-    public List<CourseBean> findCoursesByExamIdAndOrgId(@RequestParam Long examId, @RequestParam(required=false) Long orgId){
-    	if(examId == null){
-    		return null;
-    	}
-    	User user = getAccessUser();
-    	List<Long> courseIdList = examStudentService.findCoursesFromExamStudent(examId, orgId);
-    	List<CourseBean> courseBeanList = new ArrayList<CourseBean>();
-    	for(Long courseId:courseIdList){
-    		CourseBean courseBean = ExamCacheTransferHelper.getCachedCourse(courseId);
-    		courseBeanList.add(courseBean);
-    	}
-    	return courseBeanList;
+    public List<CourseBean> findCoursesByExamIdAndOrgId(@RequestParam Long examId, @RequestParam(required = false) Long orgId) {
+        if (examId == null) {
+            return null;
+        }
+        User user = getAccessUser();
+        List<Long> courseIdList = examStudentService.findCoursesFromExamStudent(examId, orgId);
+        List<CourseBean> courseBeanList = new ArrayList<CourseBean>();
+        for (Long courseId : courseIdList) {
+            CourseBean courseBean = ExamCacheTransferHelper.getCachedCourse(courseId);
+            courseBeanList.add(courseBean);
+        }
+        return courseBeanList;
     }
-    
+
     /**
      * 课程完成进度
+     *
      * @param examId
      * @param courseId
      * @return
@@ -193,22 +200,42 @@ public class ExamStudentController extends ControllerSupport {
     @GetMapping("/courseProgress/list")
     @ApiOperation(value = "课程完成进度")
     public List<CourseProgressInfo> queryCourseProgressInfos(@RequestParam Long examId,
-    														  @RequestParam(required=false) Long courseId,
-    														  @RequestParam(required=false) String orderColumn){
-    	if(examId == null){
-    		return null;
-    	}
-    	List<CourseProgressInfo> courseProgressInfoList = examStudentService.queryCourseProgressInfos(examId,courseId,orderColumn);
-    	if(courseProgressInfoList!=null && courseProgressInfoList.size()>0){
-    		for(CourseProgressInfo courseProgressInfo:courseProgressInfoList){
-    			long key = courseProgressInfo.getCourseId();
-        		CourseBean courseBean = ExamCacheTransferHelper.getCachedCourse(key);
-        		courseProgressInfo.setCourseCode(courseBean.getCode());
-        		courseProgressInfo.setCourseName(courseBean.getName());
-        	}
-    	}
-    	return courseProgressInfoList;
+                                                             @RequestParam(required = false) Long courseId,
+                                                             @RequestParam(required = false) String orderColumn) {
+        if (examId == null) {
+            return null;
+        }
+        List<CourseProgressInfo> courseProgressInfoList = examStudentService.queryCourseProgressInfos(examId, courseId, orderColumn);
+        if (courseProgressInfoList != null && courseProgressInfoList.size() > 0) {
+            for (CourseProgressInfo courseProgressInfo : courseProgressInfoList) {
+                long key = courseProgressInfo.getCourseId();
+                CourseBean courseBean = ExamCacheTransferHelper.getCachedCourse(key);
+                courseProgressInfo.setCourseCode(courseBean.getCode());
+                courseProgressInfo.setCourseName(courseBean.getName());
+            }
+        }
+        return courseProgressInfoList;
     }
-    
-    
+
+    @GetMapping("/courseProgress/list/export")
+    @ApiOperation(value = "导出“课程完成进度”列表(Excel)")
+    public void exportCourseProgressInfos(@RequestParam Long examId,
+                                          @RequestParam(required = false) Long courseId,
+                                          @RequestParam(required = false) String orderColumn,
+                                          HttpServletResponse response) throws Exception {
+        Check.isNull(examId, "请选择考试批次!");
+        List<CourseProgressInfo> courseProgressInfoList = examStudentService.queryCourseProgressInfos(examId, courseId, orderColumn);
+        if (courseProgressInfoList != null && courseProgressInfoList.size() > 0) {
+            for (CourseProgressInfo courseProgressInfo : courseProgressInfoList) {
+                long key = courseProgressInfo.getCourseId();
+                CourseBean courseBean = ExamCacheTransferHelper.getCachedCourse(key);
+                courseProgressInfo.setCourseCode(courseBean.getCode());
+                courseProgressInfo.setCourseName(courseBean.getName());
+            }
+        }
+        List<CourseCompleteProgressExcel> resultList =
+                ExamStudentEntityConvert.copyFromCourseProgressInfo(courseProgressInfoList);
+        ExportUtils.exportEXCEL("课程完成进度", CourseCompleteProgressExcel.class, resultList, response);
+    }
+
 }

+ 74 - 0
examcloud-core-oe-admin-service/src/main/java/cn/com/qmth/examcloud/core/oe/admin/service/bean/examstudent/CourseCompleteProgressExcel.java

@@ -0,0 +1,74 @@
+/*
+ * *************************************************
+ * Copyright (c) 2018 QMTH. All Rights Reserved.
+ * Created by Deason on 2018-08-30 13:40:36.
+ * *************************************************
+ */
+
+package cn.com.qmth.examcloud.core.oe.admin.service.bean.examstudent;
+
+
+import cn.com.qmth.examcloud.core.oe.common.base.utils.excel.ExcelProperty;
+
+import java.io.Serializable;
+
+/**
+ * @Description 课程完成进度
+ * @Author lideyin
+ * @Date 2019/10/11 15:43
+ * @Version 1.0
+ */
+public class CourseCompleteProgressExcel implements Serializable {
+    private static final long serialVersionUID = -8556362551712685945L;
+
+    @ExcelProperty(name = "课程名称", index = 1)
+    private String courseName;
+    @ExcelProperty(name = "课程代码", index = 2)
+    private String courseCode;
+    @ExcelProperty(name = "报考人数", index = 3)
+    private Integer allNum;
+    @ExcelProperty(name = "实考人数", index = 4)
+    private Integer completedNum;
+    @ExcelProperty(name = "完成比率", index = 5)
+    private Double completedProportion;
+
+    public String getCourseName() {
+        return courseName;
+    }
+
+    public void setCourseName(String courseName) {
+        this.courseName = courseName;
+    }
+
+    public String getCourseCode() {
+        return courseCode;
+    }
+
+    public void setCourseCode(String courseCode) {
+        this.courseCode = courseCode;
+    }
+
+    public Integer getAllNum() {
+        return allNum;
+    }
+
+    public void setAllNum(Integer allNum) {
+        this.allNum = allNum;
+    }
+
+    public Integer getCompletedNum() {
+        return completedNum;
+    }
+
+    public void setCompletedNum(Integer completedNum) {
+        this.completedNum = completedNum;
+    }
+
+    public Double getCompletedProportion() {
+        return completedProportion;
+    }
+
+    public void setCompletedProportion(Double completedProportion) {
+        this.completedProportion = completedProportion;
+    }
+}

+ 42 - 6
examcloud-core-oe-admin-service/src/main/java/cn/com/qmth/examcloud/core/oe/admin/service/bean/examstudent/ExamStudentEntityConvert.java

@@ -90,7 +90,7 @@ public class ExamStudentEntityConvert {
         info.setGrade(entity.getGrade());
         return info;
     }
-    
+
     public static List<ExamStudentExcel> ofExcel(List<ExamStudentInfo> examStudentInfoList) {
         List<ExamStudentExcel> list = new ArrayList<>();
         if (examStudentInfoList == null || examStudentInfoList.size() == 0) {
@@ -137,8 +137,8 @@ public class ExamStudentEntityConvert {
         });
         return list;
     }
-    
-    
+
+
     public static List<ExamStudentUnFinishedExcel> ofUnFinishedExcel(List<ExamStudentInfo> examStudentInfos) {
         List<ExamStudentUnFinishedExcel> list = new ArrayList<>();
         if (examStudentInfos == null || examStudentInfos.size() == 0) {
@@ -163,8 +163,7 @@ public class ExamStudentEntityConvert {
         });
         return list;
     }
-    
-    
+
 
     public static Page<ExamStudentInfo> of(Page<ExamStudentEntity> page) {
         Pageable pageable = new PageRequest(page.getNumber(), page.getSize());
@@ -175,7 +174,7 @@ public class ExamStudentEntityConvert {
         List<ExamStudentInfo> list = entities.stream().map(entity -> of(entity)).collect(Collectors.toList());
         return new PageImpl<>(list, pageable, page.getTotalElements());
     }
-    
+
     public static List<ExamStudentInfo> of(List<HashMap> maps) {
         if (maps == null || maps.size() == 0) {
             return Lists.newArrayList();
@@ -220,4 +219,41 @@ public class ExamStudentEntityConvert {
         return list;
     }
 
+    public static List<CourseCompleteProgressExcel> copyFromCourseProgressInfo(List<CourseProgressInfo> courseProgressInfoList) {
+        List<CourseCompleteProgressExcel> resultList = new ArrayList<>();
+        if (courseProgressInfoList == null || courseProgressInfoList.isEmpty()) {
+            return resultList;
+        }
+
+        courseProgressInfoList.forEach(info -> {
+            CourseCompleteProgressExcel excel = new CourseCompleteProgressExcel();
+            excel.setAllNum(info.getAllNum());
+            excel.setCompletedNum(info.getCompletedNum());
+            excel.setCompletedProportion(info.getCompletedProportion());
+            excel.setCourseCode(info.getCourseCode());
+            excel.setCourseName(info.getCourseName());
+            resultList.add(excel);
+        });
+
+        return resultList;
+    }
+
+    public static List<OrgCompleteProgressExcel> copyFromExamStudentOrgStatistic(List<ExamStudentOrgStatistic> examStudentOrgStatisticList) {
+        List<OrgCompleteProgressExcel> resultList = new ArrayList<>();
+        if (examStudentOrgStatisticList == null || examStudentOrgStatisticList.isEmpty()) {
+            return resultList;
+        }
+
+        examStudentOrgStatisticList.forEach(info -> {
+            OrgCompleteProgressExcel excel = new OrgCompleteProgressExcel();
+            excel.setFinishedCount(info.getFinishedCount());
+            excel.setFinishedPercent(info.getFinishedPercent());
+            excel.setOrgCode(info.getOrgCode());
+            excel.setOrgName(info.getOrgName());
+            excel.setTotalCount(info.getTotalCount());
+            resultList.add(excel);
+        });
+
+        return resultList;
+    }
 }

+ 89 - 0
examcloud-core-oe-admin-service/src/main/java/cn/com/qmth/examcloud/core/oe/admin/service/bean/examstudent/OrgCompleteProgressExcel.java

@@ -0,0 +1,89 @@
+/*
+ * *************************************************
+ * Copyright (c) 2018 QMTH. All Rights Reserved.
+ * Created by Deason on 2018-08-30 13:40:36.
+ * *************************************************
+ */
+
+package cn.com.qmth.examcloud.core.oe.admin.service.bean.examstudent;
+
+
+import cn.com.qmth.examcloud.core.oe.common.base.utils.excel.ExcelProperty;
+
+import java.io.Serializable;
+
+/**
+ * @Description 学习中心完成进度
+ * @Author lideyin
+ * @Date 2019/10/11 15:43
+ * @Version 1.0
+ */
+public class OrgCompleteProgressExcel implements Serializable {
+
+    private static final long serialVersionUID = 122373352029233388L;
+    /**
+     * 学习中心代码
+     */
+    @ExcelProperty(name = "学习中心代码", index = 1)
+    private String orgCode;
+    /**
+     * 学习中心名称
+     */
+    @ExcelProperty(name = "学习中心名称", index = 2)
+    private String orgName;
+    /**
+     * 报考人数(计划数)
+     */
+    @ExcelProperty(name = "报考人数", index = 3)
+    private Integer totalCount;
+    /**
+     * 实考人数(完成数)
+     */
+    @ExcelProperty(name = "实考人数", index = 4)
+    private Integer finishedCount;
+    /**
+     * 完成比率(%)
+     */
+    @ExcelProperty(name = "完成比率(%)", index = 5)
+    private String finishedPercent;
+
+    public String getOrgCode() {
+        return orgCode;
+    }
+
+    public void setOrgCode(String orgCode) {
+        this.orgCode = orgCode;
+    }
+
+    public String getOrgName() {
+        return orgName;
+    }
+
+    public void setOrgName(String orgName) {
+        this.orgName = orgName;
+    }
+
+    public Integer getTotalCount() {
+        return totalCount;
+    }
+
+    public void setTotalCount(Integer totalCount) {
+        this.totalCount = totalCount;
+    }
+
+    public Integer getFinishedCount() {
+        return finishedCount;
+    }
+
+    public void setFinishedCount(Integer finishedCount) {
+        this.finishedCount = finishedCount;
+    }
+
+    public String getFinishedPercent() {
+        return finishedPercent;
+    }
+
+    public void setFinishedPercent(String finishedPercent) {
+        this.finishedPercent = finishedPercent;
+    }
+}