deason 6 жил өмнө
parent
commit
fd1ab73008

+ 5 - 0
examcloud-core-print-dao/src/main/java/cn/com/qmth/examcloud/core/print/repository/CourseStatisticRepository.java

@@ -30,4 +30,9 @@ public interface CourseStatisticRepository extends JpaRepository<CourseStatistic
     int updateTotalStudentByOrgExamCourse(@Param("orgId") Long orgId, @Param("examId") Long examId, @Param("courseId") Long courseId, @Param("paperType") String paperType,
                                           @Param("totalStudent") Integer totalStudent);
 
+    @Transactional
+    @Modifying
+    @Query("UPDATE CourseStatistic SET paperStatus=:paperStatus WHERE orgId=:orgId AND examId=:examId AND courseId=:courseId")
+    int updatePaperStatusByOrgExamCourse(@Param("orgId") Long orgId, @Param("examId") Long examId, @Param("courseId") Long courseId, @Param("paperStatus") Integer paperStatus);
+
 }

+ 3 - 2
examcloud-core-print-provider/src/main/java/cn/com/qmth/examcloud/core/print/api/controller/CourseStatisticController.java

@@ -10,6 +10,7 @@ package cn.com.qmth.examcloud.core.print.api.controller;
 import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
 import cn.com.qmth.examcloud.core.print.common.Result;
 import cn.com.qmth.examcloud.core.print.service.CourseStatisticService;
+import cn.com.qmth.examcloud.core.print.service.bean.coursestatistic.CourseRefreshForm;
 import cn.com.qmth.examcloud.core.print.service.bean.coursestatistic.CourseStatisticInfo;
 import cn.com.qmth.examcloud.core.print.service.bean.coursestatistic.CourseStatisticQuery;
 import io.swagger.annotations.Api;
@@ -41,8 +42,8 @@ public class CourseStatisticController extends ControllerSupport {
 
     @PostMapping("/init")
     @ApiOperation(value = "刷新某些课程的统计信息")
-    public Result init(@RequestParam Long orgId, @RequestParam Long examId, @RequestParam Long[] courseIds) {
-        courseStatisticService.initCourseStatistic(orgId, examId, courseIds);
+    public Result init(@RequestBody CourseRefreshForm form) {
+        courseStatisticService.initCourseStatistic(form);
         return success();
     }
 

+ 13 - 4
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/CommonService.java

@@ -50,16 +50,25 @@ public class CommonService {
      * 获取考试所有的开考课程列表
      * 含试卷类型、考生数量
      */
-    public List<ExamCourseInfo> getExamCourseList(Long orgId, Long examId) {
+    public List<ExamCourseInfo> getExamCourseList(Long orgId, Long examId, Long courseId, String paperType) {
         SqlWrapper sql = new SqlWrapper()
                 .select("root_org_id orgId,exam_id,course_id,course_code,course_name,paper_type,count(course_code) totalStudent")
                 .from("ecs_exam_student")//todo ec_e_exam_student
                 .where()
                 .eq("root_org_id", orgId)
-                .and().eq("exam_id", examId)
-                .groupBy("course_id,paper_type");
-        //log.debug(sql.build());
+                .and().eq("exam_id", examId);
+        if (courseId != null) {
+            sql.and().eq("course_id", courseId);
+        }
+        if (StringUtils.isNotBlank(paperType)) {
+            sql.and().eq("paper_type", paperType);
+        }
+        sql.groupBy("course_id,paper_type");
         return jdbcTemplate.query(sql.build(), new BeanPropertyRowMapper(ExamCourseInfo.class));
     }
 
+    public List<ExamCourseInfo> getExamCourseList(Long orgId, Long examId) {
+        return this.getExamCourseList(orgId, examId, null, null);
+    }
+
 }

+ 4 - 1
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/CourseStatisticService.java

@@ -7,6 +7,7 @@
 
 package cn.com.qmth.examcloud.core.print.service;
 
+import cn.com.qmth.examcloud.core.print.service.bean.coursestatistic.CourseRefreshForm;
 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.data.domain.Page;
@@ -24,8 +25,10 @@ public interface CourseStatisticService {
 
     /**
      * 刷新某些课程的统计信息
+     *
+     * @param form 请求表单
      */
-    void initCourseStatistic(Long orgId, Long examId, Long[] courseIds);
+    void initCourseStatistic(CourseRefreshForm form);
 
     /**
      * 初始所有课程的统计信息

+ 95 - 0
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/bean/coursestatistic/CourseRefreshForm.java

@@ -0,0 +1,95 @@
+/*
+ * *************************************************
+ * Copyright (c) 2018 QMTH. All Rights Reserved.
+ * Created by Deason on 2018-11-08 14:10:53.
+ * *************************************************
+ */
+
+package cn.com.qmth.examcloud.core.print.service.bean.coursestatistic;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * 待刷新统计的课程表单
+ *
+ * @author: fengdesheng
+ * @since: 2018/11/08
+ */
+public class CourseRefreshForm implements Serializable {
+    private static final long serialVersionUID = 1L;
+    /**
+     * 学校机构ID
+     */
+    private Long orgId;
+    /**
+     * 考试ID
+     */
+    private Long examId;
+    /**
+     * 格式:
+     * [{"courseId":1,"paperType":"A"},{"courseId":2,"paperType":"B"}]
+     */
+    private List<Course> courses;
+
+    public Long getOrgId() {
+        return orgId;
+    }
+
+    public void setOrgId(Long orgId) {
+        this.orgId = orgId;
+    }
+
+    public Long getExamId() {
+        return examId;
+    }
+
+    public void setExamId(Long examId) {
+        this.examId = examId;
+    }
+
+    public List<Course> getCourses() {
+        return courses;
+    }
+
+    public void setCourses(List<Course> courses) {
+        this.courses = courses;
+    }
+
+    public static class Course {
+        /**
+         * 课程ID
+         */
+        private Long courseId;
+        /**
+         * 试卷类型
+         */
+        private String paperType;
+
+        public Course(Long courseId, String paperType) {
+            this.courseId = courseId;
+            this.paperType = paperType;
+        }
+
+        public Course() {
+
+        }
+
+        public Long getCourseId() {
+            return courseId;
+        }
+
+        public void setCourseId(Long courseId) {
+            this.courseId = courseId;
+        }
+
+        public String getPaperType() {
+            return paperType;
+        }
+
+        public void setPaperType(String paperType) {
+            this.paperType = paperType;
+        }
+    }
+
+}

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

@@ -19,6 +19,7 @@ import cn.com.qmth.examcloud.core.print.service.CommonService;
 import cn.com.qmth.examcloud.core.print.service.CourseStatisticService;
 import cn.com.qmth.examcloud.core.print.service.bean.common.ExamCourseInfo;
 import cn.com.qmth.examcloud.core.print.service.bean.common.ExamInfo;
+import cn.com.qmth.examcloud.core.print.service.bean.coursestatistic.CourseRefreshForm;
 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;
@@ -75,10 +76,22 @@ public class CourseStatisticServiceImpl implements CourseStatisticService {
     }
 
     @Override
-    public void initCourseStatistic(Long orgId, Long examId, Long[] courseIds) {
-        List<ExamCourseInfo> examCourses = commonService.getExamCourseList(orgId, examId);
-        //courseIds paperType todo
-        this.syncCourseStatisticList(examCourses);
+    public void initCourseStatistic(CourseRefreshForm form) {
+        Check.isNull(form, "请求参数不能为空!");
+        Check.isNull(form.getOrgId(), "学校ID不能为空!");
+        Check.isNull(form.getExamId(), "考试ID不能为空!");
+        List<CourseRefreshForm.Course> courses = form.getCourses();
+        if (courses == null || courses.size() == 0) {
+            //课程ID和试卷类型未指定时,则不统计
+            return;
+        }
+        for (CourseRefreshForm.Course course : courses) {
+            if (course.getCourseId() == null || StringUtils.isBlank(course.getPaperType())) {
+                continue;
+            }
+            List<ExamCourseInfo> examCourses = commonService.getExamCourseList(form.getOrgId(), form.getExamId(), course.getCourseId(), course.getPaperType());
+            this.syncCourseStatisticList(examCourses);
+        }
     }
 
     @Override

+ 14 - 6
examcloud-core-print-starter/src/test/java/cn/com/qmth/examcloud/core/print/test/CourseStatisticServiceTest.java

@@ -8,12 +8,16 @@
 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.CourseRefreshForm;
 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;
 
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * @author: fengdesheng
  * @since: 2018/10/17
@@ -36,13 +40,17 @@ public class CourseStatisticServiceTest extends BaseTest {
 
     @Test
     public void initCourseStatisticTest() throws Exception {
-        Long orgId = 1L;
-        Long examId = 1L;
-        Long[] courseIds = {1L};
-        //courseStatisticService.initCourseStatistic(orgId, examId, courseIds);
-        //courseStatisticService.initAllCourseStatistic();
+        CourseRefreshForm form = new CourseRefreshForm();
+        form.setOrgId(109L);
+        form.setExamId(178L);
+        List<CourseRefreshForm.Course> courses = new ArrayList<>();
+        courses.add(new CourseRefreshForm.Course(262L, "O"));
+        courses.add(new CourseRefreshForm.Course(263L, "O"));
+        form.setCourses(courses);
+        courseStatisticService.initCourseStatistic(form);
 
-        courseStatisticService.syncCourseNameByCourseId(262L, "测试课程");
+        //courseStatisticService.initAllCourseStatistic();
+        //courseStatisticService.syncCourseNameByCourseId(262L, "测试课程");
     }
 
 }