|
@@ -10,9 +10,11 @@ package cn.com.qmth.examcloud.core.print.service.impl;
|
|
|
import cn.com.qmth.examcloud.core.print.common.jpa.OrderBuilder;
|
|
|
import cn.com.qmth.examcloud.core.print.common.jpa.SearchBuilder;
|
|
|
import cn.com.qmth.examcloud.core.print.common.jpa.SpecUtils;
|
|
|
+import cn.com.qmth.examcloud.core.print.common.jpa.SqlWrapper;
|
|
|
import cn.com.qmth.examcloud.core.print.common.utils.Check;
|
|
|
import cn.com.qmth.examcloud.core.print.entity.CourseStatistic;
|
|
|
import cn.com.qmth.examcloud.core.print.enums.ExamType;
|
|
|
+import cn.com.qmth.examcloud.core.print.enums.PaperBindingStatus;
|
|
|
import cn.com.qmth.examcloud.core.print.repository.CourseStatisticRepository;
|
|
|
import cn.com.qmth.examcloud.core.print.service.CommonService;
|
|
|
import cn.com.qmth.examcloud.core.print.service.CourseStatisticService;
|
|
@@ -28,6 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.List;
|
|
@@ -43,6 +46,8 @@ public class CourseStatisticServiceImpl implements CourseStatisticService {
|
|
|
private CourseStatisticRepository courseStatisticsRepository;
|
|
|
@Autowired
|
|
|
private CommonService commonService;
|
|
|
+ @Autowired
|
|
|
+ private JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
@Override
|
|
|
public Page<CourseStatisticInfo> getCourseStatisticList(CourseStatisticQuery query) {
|
|
@@ -76,22 +81,78 @@ public class CourseStatisticServiceImpl implements CourseStatisticService {
|
|
|
@Override
|
|
|
public void initCourseStatistic(Long orgId, Long examId, Long[] courseIds) {
|
|
|
List<ExamCourseInfo> examCourses = commonService.getExamCourseList(orgId, examId);
|
|
|
- //todo
|
|
|
- System.out.println(examCourses.size());
|
|
|
+ this.syncCourseStatisticList(examCourses);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void initAllCourseStatistic() {
|
|
|
- //获取所有"传统"考试列表
|
|
|
log.debug("initAllCourseStatistic...");
|
|
|
List<ExamInfo> exams = commonService.getExamList(ExamType.TRADITION.name());
|
|
|
if (exams != null && !exams.isEmpty()) {
|
|
|
for (ExamInfo info : exams) {
|
|
|
List<ExamCourseInfo> examCourses = commonService.getExamCourseList(info.getOrgId(), info.getExamId());
|
|
|
- //todo
|
|
|
- System.out.println(examCourses.size());
|
|
|
+ this.syncCourseStatisticList(examCourses);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void syncCourseStatisticList(List<ExamCourseInfo> examCourses) {
|
|
|
+ if (examCourses == null || examCourses.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (ExamCourseInfo info : examCourses) {
|
|
|
+ if (info.getCourseId() == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ boolean isExist = this.isExistCourseStatistic(info);
|
|
|
+ if (isExist) {
|
|
|
+ this.updateCourseStatistic(info);
|
|
|
+ } else {
|
|
|
+ this.addCourseStatistic(info);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private boolean isExistCourseStatistic(ExamCourseInfo info) {
|
|
|
+ SearchBuilder searches = new SearchBuilder()
|
|
|
+ .eq("orgId", info.getOrgId())
|
|
|
+ .eq("examId", info.getExamId())
|
|
|
+ .eq("courseId", info.getCourseId())
|
|
|
+ .eq("paperType", info.getPaperType());
|
|
|
+ Specification<CourseStatistic> spec = SpecUtils.buildSearchers(CourseStatistic.class, searches.build());
|
|
|
+ long total = courseStatisticsRepository.count(spec);
|
|
|
+ if (total > 0) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addCourseStatistic(ExamCourseInfo info) {
|
|
|
+ CourseStatistic statistic = new CourseStatistic();
|
|
|
+ statistic.setOrgId(info.getOrgId());
|
|
|
+ statistic.setExamId(info.getExamId());
|
|
|
+ statistic.setCourseId(info.getCourseId());
|
|
|
+ statistic.setCourseCode(info.getCourseCode());
|
|
|
+ statistic.setCourseName(info.getCourseName());
|
|
|
+ statistic.setPaperType(info.getPaperType());
|
|
|
+ statistic.setTotalStudent(info.getTotalStudent());
|
|
|
+ statistic.setPaperBindingStatus(PaperBindingStatus.无.getIndex());
|
|
|
+ courseStatisticsRepository.save(statistic);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateCourseStatistic(ExamCourseInfo info) {
|
|
|
+ //仅更新total_student、course_name字段
|
|
|
+ SqlWrapper sql = new SqlWrapper()
|
|
|
+ .update("ec_prt_course_statistic")
|
|
|
+ .set()
|
|
|
+ .append("total_student = '").append(info.getTotalStudent()).append("'")
|
|
|
+ .append(",course_name = '").append(info.getCourseName()).append("'")
|
|
|
+ .where()
|
|
|
+ .eq("org_id", info.getOrgId())
|
|
|
+ .and().eq("exam_id", info.getExamId())
|
|
|
+ .and().eq("course_id", info.getCourseId())
|
|
|
+ .and().eq("paper_type", info.getPaperType());
|
|
|
+ jdbcTemplate.update(sql.build());
|
|
|
+ }
|
|
|
+
|
|
|
}
|