|
@@ -1,5 +1,6 @@
|
|
|
package cn.com.qmth.examcloud.core.oe.admin.service.impl;
|
|
|
|
|
|
+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;
|
|
@@ -16,6 +17,8 @@ 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.GetExamCourseReq;
|
|
|
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;
|
|
@@ -48,77 +51,92 @@ public class ExamStatisticServiceImpl implements ExamStatisticService {
|
|
|
@Autowired
|
|
|
private ExamCloudService examCloudService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RedisClient redisClient;
|
|
|
+
|
|
|
@Autowired
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
@Override
|
|
|
public void refresh(Long examId, Long courseId) {
|
|
|
- long start = System.currentTimeMillis();
|
|
|
-
|
|
|
- GetExamCourseReq req = new GetExamCourseReq();
|
|
|
- req.setExamId(examId);
|
|
|
- req.setCourseId(courseId);
|
|
|
- GetExamCourseResp resp = examCloudService.getExamCourseSetting(req);
|
|
|
-
|
|
|
- int passScoreLine = 60;// 默认值
|
|
|
- int goodScoreLine = 90;// 默认值
|
|
|
- if (resp != null && resp.getBean() != null) {
|
|
|
- passScoreLine = resp.getBean().getPassScoreLine();
|
|
|
- goodScoreLine = resp.getBean().getGoodScoreLine();
|
|
|
+ final String cacheKey = String.format(CacheConstants.CACHE_OE_SCORE_STATISTIC, examId, courseId);
|
|
|
+ Boolean running = redisClient.get(cacheKey, Boolean.class);
|
|
|
+ if (running != null) {
|
|
|
+ throw new StatusException("500", "统计计算中,请稍后查询结果!");
|
|
|
}
|
|
|
|
|
|
- StringBuffer sql = new StringBuffer();
|
|
|
- sql.append(" select es.exam_id,es.course_id,es.org_id,es.exam_student_id,sc.total_score,d.paper_score");
|
|
|
- sql.append(" from ec_oe_exam_student es");
|
|
|
- sql.append(" left join ec_oe_exam_student_final_score sc on sc.exam_student_id = es.exam_student_id");
|
|
|
- sql.append(" left join ec_oe_exam_record_data d on d.id = sc.exam_record_data_id");
|
|
|
- sql.append(" where es.exam_id = ").append(examId);
|
|
|
- sql.append(" and es.course_id = ").append(courseId);
|
|
|
+ try {
|
|
|
+ redisClient.set(cacheKey, true, 600);// 10分钟后自动过期
|
|
|
|
|
|
- List<ExamStudentScoreInfo> list = jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper(ExamStudentScoreInfo.class));
|
|
|
- if (CollectionUtils.isEmpty(list)) {
|
|
|
- log.warn("ExamStudent is empty! examId:{} courseId:{}", examId, courseId);
|
|
|
- return;
|
|
|
- }
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
|
|
|
- Map<Long, List<ExamStudentScoreInfo>> orgStatisticMaps = list.stream().collect(Collectors.groupingBy(ExamStudentScoreInfo::getOrgId));
|
|
|
- for (Map.Entry<Long, List<ExamStudentScoreInfo>> e : orgStatisticMaps.entrySet()) {
|
|
|
- int allCount = 0, finishCount = 0, passScoreCount = 0, goodScoreCount = 0;
|
|
|
- for (ExamStudentScoreInfo v : e.getValue()) {
|
|
|
- allCount++;
|
|
|
+ GetExamCourseReq req = new GetExamCourseReq();
|
|
|
+ req.setExamId(examId);
|
|
|
+ req.setCourseId(courseId);
|
|
|
+ GetExamCourseResp resp = examCloudService.getExamCourseSetting(req);
|
|
|
|
|
|
- if (v.getTotalScore() == null) {
|
|
|
- // 无成绩,则未完成考试
|
|
|
- continue;
|
|
|
- }
|
|
|
+ int passScoreLine = 60;// 默认值
|
|
|
+ int goodScoreLine = 90;// 默认值
|
|
|
+ if (resp != null && resp.getBean() != null) {
|
|
|
+ passScoreLine = resp.getBean().getPassScoreLine();
|
|
|
+ goodScoreLine = resp.getBean().getGoodScoreLine();
|
|
|
+ }
|
|
|
|
|
|
- finishCount++;
|
|
|
+ StringBuffer sql = new StringBuffer();
|
|
|
+ sql.append(" select es.exam_id,es.course_id,es.org_id,es.exam_student_id,sc.total_score,d.paper_score");
|
|
|
+ sql.append(" from ec_oe_exam_student es");
|
|
|
+ sql.append(" left join ec_oe_exam_student_final_score sc on sc.exam_student_id = es.exam_student_id");
|
|
|
+ sql.append(" left join ec_oe_exam_record_data d on d.id = sc.exam_record_data_id");
|
|
|
+ sql.append(" where es.exam_id = ").append(examId);
|
|
|
+ sql.append(" and es.course_id = ").append(courseId);
|
|
|
+
|
|
|
+ List<ExamStudentScoreInfo> list = jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper(ExamStudentScoreInfo.class));
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
+ log.warn("ExamStudent is empty! examId:{} courseId:{}", examId, courseId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if (v.getTotalScore() >= (v.getPaperScore() * passScoreLine) / 100d) {
|
|
|
- passScoreCount++;
|
|
|
+ Map<Long, List<ExamStudentScoreInfo>> orgStatisticMaps = list.stream().collect(Collectors.groupingBy(ExamStudentScoreInfo::getOrgId));
|
|
|
+ for (Map.Entry<Long, List<ExamStudentScoreInfo>> e : orgStatisticMaps.entrySet()) {
|
|
|
+ int allCount = 0, finishCount = 0, passScoreCount = 0, goodScoreCount = 0;
|
|
|
+ for (ExamStudentScoreInfo v : e.getValue()) {
|
|
|
+ allCount++;
|
|
|
+
|
|
|
+ if (v.getTotalScore() == null) {
|
|
|
+ // 无成绩,则未完成考试
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ finishCount++;
|
|
|
+
|
|
|
+ if (v.getTotalScore() >= (v.getPaperScore() * passScoreLine) / 100d) {
|
|
|
+ passScoreCount++;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (v.getTotalScore() >= (v.getPaperScore() * goodScoreLine) / 100d) {
|
|
|
+ goodScoreCount++;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- if (v.getTotalScore() >= (v.getPaperScore() * goodScoreLine) / 100d) {
|
|
|
- goodScoreCount++;
|
|
|
+ ExamStatisticEntity result = examStatisticRepo.findByExamIdAndCourseIdAndOrgId(examId, courseId, e.getKey());
|
|
|
+ if (result == null) {
|
|
|
+ result = new ExamStatisticEntity();
|
|
|
+ result.setExamId(examId);
|
|
|
+ result.setCourseId(courseId);
|
|
|
+ result.setOrgId(e.getKey());
|
|
|
}
|
|
|
+ result.setAllCount(allCount);
|
|
|
+ result.setFinishCount(finishCount);
|
|
|
+ result.setPassScoreCount(passScoreCount);
|
|
|
+ result.setGoodScoreCount(goodScoreCount);
|
|
|
+ result.setUpdateTime(new Date());
|
|
|
+ examStatisticRepo.save(result);
|
|
|
}
|
|
|
|
|
|
- ExamStatisticEntity result = examStatisticRepo.findByExamIdAndCourseIdAndOrgId(examId, courseId, e.getKey());
|
|
|
- if (result == null) {
|
|
|
- result = new ExamStatisticEntity();
|
|
|
- result.setExamId(examId);
|
|
|
- result.setCourseId(courseId);
|
|
|
- result.setOrgId(e.getKey());
|
|
|
- }
|
|
|
- result.setAllCount(allCount);
|
|
|
- result.setFinishCount(finishCount);
|
|
|
- result.setPassScoreCount(passScoreCount);
|
|
|
- result.setGoodScoreCount(goodScoreCount);
|
|
|
- result.setUpdateTime(new Date());
|
|
|
- examStatisticRepo.save(result);
|
|
|
+ log.warn("refresh ok! examId:{} courseId:{} cost:{}ms", examId, courseId, System.currentTimeMillis() - start);
|
|
|
+ } finally {
|
|
|
+ redisClient.delete(cacheKey);
|
|
|
}
|
|
|
-
|
|
|
- log.warn("refresh ok! examId:{} courseId:{} cost:{}ms", examId, courseId, System.currentTimeMillis() - start);
|
|
|
}
|
|
|
|
|
|
@Override
|