|
@@ -15,7 +15,9 @@ import cn.com.qmth.examcloud.core.oe.admin.service.bean.statistic.ExamStatisticI
|
|
import cn.com.qmth.examcloud.core.oe.admin.service.bean.statistic.ExamStudentScoreInfo;
|
|
import cn.com.qmth.examcloud.core.oe.admin.service.bean.statistic.ExamStudentScoreInfo;
|
|
import cn.com.qmth.examcloud.core.oe.admin.service.bean.statistic.OverviewInfo;
|
|
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.ExamCloudService;
|
|
|
|
+import cn.com.qmth.examcloud.examwork.api.request.GetExamCourseIdsReq;
|
|
import cn.com.qmth.examcloud.examwork.api.request.GetExamCourseReq;
|
|
import cn.com.qmth.examcloud.examwork.api.request.GetExamCourseReq;
|
|
|
|
+import cn.com.qmth.examcloud.examwork.api.response.GetExamCourseIdsResp;
|
|
import cn.com.qmth.examcloud.examwork.api.response.GetExamCourseResp;
|
|
import cn.com.qmth.examcloud.examwork.api.response.GetExamCourseResp;
|
|
import cn.com.qmth.examcloud.support.CacheConstants;
|
|
import cn.com.qmth.examcloud.support.CacheConstants;
|
|
import cn.com.qmth.examcloud.web.redis.RedisClient;
|
|
import cn.com.qmth.examcloud.web.redis.RedisClient;
|
|
@@ -57,83 +59,100 @@ public class ExamStatisticServiceImpl implements ExamStatisticService {
|
|
@Autowired
|
|
@Autowired
|
|
private JdbcTemplate jdbcTemplate;
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
|
|
+ private final static int PASS_SCORE_LINE = 60;// 及格率默认值
|
|
|
|
+
|
|
|
|
+ private final static int GOOD_SCORE_LINE = 90;// 优秀率默认值
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
- public void refresh(Long examId, Long courseId) {
|
|
|
|
- final String cacheKey = CacheConstants.CACHE_OE_SCORE_STATISTIC_STATUS + examId + "_" + courseId;
|
|
|
|
|
|
+ public void refresh(Long examId) {
|
|
|
|
+ final String cacheKey = CacheConstants.CACHE_OE_SCORE_STATISTIC_STATUS + examId;
|
|
Boolean running = redisClient.get(cacheKey, Boolean.class);
|
|
Boolean running = redisClient.get(cacheKey, Boolean.class);
|
|
if (running != null) {
|
|
if (running != null) {
|
|
throw new StatusException("500", "统计计算中,请稍后查询结果!");
|
|
throw new StatusException("500", "统计计算中,请稍后查询结果!");
|
|
}
|
|
}
|
|
|
|
|
|
try {
|
|
try {
|
|
|
|
+ long start = System.currentTimeMillis();
|
|
redisClient.set(cacheKey, true, 600);// 10分钟后自动过期
|
|
redisClient.set(cacheKey, true, 600);// 10分钟后自动过期
|
|
|
|
|
|
- long start = System.currentTimeMillis();
|
|
|
|
|
|
+ // 获取考试相关的课程ID列表
|
|
|
|
+ GetExamCourseIdsReq idsReq = new GetExamCourseIdsReq();
|
|
|
|
+ idsReq.setExamId(examId);
|
|
|
|
+ GetExamCourseIdsResp idsResp = examCloudService.getExamCourseIds(idsReq);
|
|
|
|
+ List<Long> courseIds = idsResp.getCourseIds();
|
|
|
|
+ if (CollectionUtils.isEmpty(courseIds)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
|
|
- GetExamCourseReq req = new GetExamCourseReq();
|
|
|
|
- req.setExamId(examId);
|
|
|
|
- req.setCourseId(courseId);
|
|
|
|
- GetExamCourseResp resp = examCloudService.getExamCourseSetting(req);
|
|
|
|
|
|
+ for (Long courseId : courseIds) {
|
|
|
|
+ long courseStart = System.currentTimeMillis();
|
|
|
|
|
|
- int passScoreLine = 60;// 默认值
|
|
|
|
- int goodScoreLine = 90;// 默认值
|
|
|
|
- if (resp != null && resp.getBean() != null) {
|
|
|
|
- passScoreLine = resp.getBean().getPassScoreLine();
|
|
|
|
- goodScoreLine = resp.getBean().getGoodScoreLine();
|
|
|
|
- }
|
|
|
|
|
|
+ GetExamCourseReq settingReq = new GetExamCourseReq();
|
|
|
|
+ settingReq.setExamId(examId);
|
|
|
|
+ settingReq.setCourseId(courseId);
|
|
|
|
+ GetExamCourseResp settingResp = examCloudService.getExamCourseSetting(settingReq);
|
|
|
|
|
|
- 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;
|
|
|
|
- }
|
|
|
|
|
|
+ int passScoreLine = PASS_SCORE_LINE, goodScoreLine = GOOD_SCORE_LINE;
|
|
|
|
+ if (settingResp != null && settingResp.getBean() != null) {
|
|
|
|
+ passScoreLine = settingResp.getBean().getPassScoreLine();
|
|
|
|
+ goodScoreLine = settingResp.getBean().getGoodScoreLine();
|
|
|
|
+ }
|
|
|
|
|
|
- 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++;
|
|
|
|
|
|
+ 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);
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
|
|
- if (v.getTotalScore() == null) {
|
|
|
|
- // 无成绩,则未完成考试
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
|
|
+ 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++;
|
|
|
|
|
|
- finishCount++;
|
|
|
|
|
|
+ if (v.getTotalScore() == null) {
|
|
|
|
+ // 无成绩,则未完成考试
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
|
|
- if (v.getTotalScore() >= (v.getPaperScore() * passScoreLine) / 100d) {
|
|
|
|
- passScoreCount++;
|
|
|
|
|
|
+ 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() - courseStart);
|
|
}
|
|
}
|
|
|
|
|
|
- log.warn("refresh ok! examId:{} courseId:{} cost:{}ms", examId, courseId, System.currentTimeMillis() - start);
|
|
|
|
|
|
+ log.warn("refresh ok! examId:{} cost:{}ms", examId, System.currentTimeMillis() - start);
|
|
} finally {
|
|
} finally {
|
|
redisClient.delete(cacheKey);
|
|
redisClient.delete(cacheKey);
|
|
}
|
|
}
|