deason 6 years ago
parent
commit
e997a5e1f5

+ 5 - 0
examcloud-core-print-service/src/main/java/cn/com/qmth/examcloud/core/print/service/CourseStatisticService.java

@@ -32,4 +32,9 @@ public interface CourseStatisticService {
      */
     void initAllCourseStatistic();
 
+    /**
+     * 同步更新课程名称信息
+     */
+    void syncCourseStatisticForCourseName(Long courseId, String courseName);
+
 }

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

@@ -81,6 +81,7 @@ 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);
     }
 
@@ -106,7 +107,7 @@ public class CourseStatisticServiceImpl implements CourseStatisticService {
             }
             boolean isExist = this.isExistCourseStatistic(info);
             if (isExist) {
-                this.updateCourseStatistic(info);
+                this.syncCourseStatisticForTotalStudent(info);
             } else {
                 this.addCourseStatistic(info);
             }
@@ -140,13 +141,11 @@ public class CourseStatisticServiceImpl implements CourseStatisticService {
         courseStatisticsRepository.save(statistic);
     }
 
-    private void updateCourseStatistic(ExamCourseInfo info) {
-        //仅更新total_student、course_name字段
+    private void syncCourseStatisticForTotalStudent(ExamCourseInfo info) {
+        //仅更新total_student字段
         SqlWrapper sql = new SqlWrapper()
                 .update("ec_prt_course_statistic")
-                .set()
-                .append("total_student = '").append(info.getTotalStudent()).append("'")
-                .append(",course_name = '").append(info.getCourseName()).append("'")
+                .set().append("total_student = ").append(info.getTotalStudent())
                 .where()
                 .eq("org_id", info.getOrgId())
                 .and().eq("exam_id", info.getExamId())
@@ -155,4 +154,17 @@ public class CourseStatisticServiceImpl implements CourseStatisticService {
         jdbcTemplate.update(sql.build());
     }
 
+    @Override
+    public void syncCourseStatisticForCourseName(Long courseId, String courseName) {
+        if (courseId == null || StringUtils.isBlank(courseName)) {
+            return;
+        }
+        SqlWrapper sql = new SqlWrapper()
+                .update("ec_prt_course_statistic")
+                .set().append("course_name = '").append(courseName).append("'")
+                .where()
+                .eq("course_id", courseId);
+        jdbcTemplate.update(sql.build());
+    }
+
 }

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

@@ -41,6 +41,10 @@ public class CourseStatisticServiceTest extends BaseTest {
         Long[] courseIds = {1L};
         courseStatisticService.initCourseStatistic(orgId, examId, courseIds);
         //courseStatisticService.initAllCourseStatistic();
+
+        Long courseId = 1L;
+        String courseName = "测试课程";
+        courseStatisticService.syncCourseStatisticForCourseName(courseId, courseName);
     }
 
 }