|
@@ -4,6 +4,7 @@ import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
import cn.com.qmth.examcloud.commons.util.MathUtils;
|
|
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.CourseCloudService;
|
|
import cn.com.qmth.examcloud.core.basic.api.OrgCloudService;
|
|
import cn.com.qmth.examcloud.core.basic.api.OrgCloudService;
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.bean.CourseBean;
|
|
import cn.com.qmth.examcloud.core.basic.api.bean.OrgBean;
|
|
import cn.com.qmth.examcloud.core.basic.api.bean.OrgBean;
|
|
import cn.com.qmth.examcloud.core.basic.api.request.GetCoursesByIdListReq;
|
|
import cn.com.qmth.examcloud.core.basic.api.request.GetCoursesByIdListReq;
|
|
import cn.com.qmth.examcloud.core.basic.api.request.GetOrgMapsReq;
|
|
import cn.com.qmth.examcloud.core.basic.api.request.GetOrgMapsReq;
|
|
@@ -13,7 +14,6 @@ import cn.com.qmth.examcloud.core.oe.admin.dao.entity.ExamStatisticEntity;
|
|
import cn.com.qmth.examcloud.core.oe.admin.service.ExamStatisticService;
|
|
import cn.com.qmth.examcloud.core.oe.admin.service.ExamStatisticService;
|
|
import cn.com.qmth.examcloud.core.oe.admin.service.bean.statistic.ExamStatisticInfo;
|
|
import cn.com.qmth.examcloud.core.oe.admin.service.bean.statistic.ExamStatisticInfo;
|
|
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.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.GetExamCourseIdsReq;
|
|
import cn.com.qmth.examcloud.examwork.api.request.GetExamCourseReq;
|
|
import cn.com.qmth.examcloud.examwork.api.request.GetExamCourseReq;
|
|
@@ -21,7 +21,6 @@ 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;
|
|
-import com.google.common.collect.Lists;
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -30,10 +29,7 @@ import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.Date;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -167,97 +163,127 @@ public class ExamStatisticServiceImpl implements ExamStatisticService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public OverviewInfo overview(Long examId, Long courseId) {
|
|
|
|
- OverviewInfo result = new OverviewInfo();
|
|
|
|
-
|
|
|
|
- ExamStatisticInfo examResult = new ExamStatisticInfo();
|
|
|
|
- ExamStatisticInfo courseResult = new ExamStatisticInfo();
|
|
|
|
- result.setExamResult(examResult);
|
|
|
|
- result.setCourseResult(courseResult);
|
|
|
|
-
|
|
|
|
- List<ExamStatisticEntity> list = examStatisticRepo.findByExamId(examId);
|
|
|
|
- if (CollectionUtils.isEmpty(list)) {
|
|
|
|
- return result;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- GetCoursesByIdListReq req = new GetCoursesByIdListReq();
|
|
|
|
- req.setCourseIdList(Lists.newArrayList(courseId));
|
|
|
|
- GetCoursesByIdListResp resp = courseCloudService.getCoursesByIdList(req);
|
|
|
|
- courseResult.setCourseName(resp.getCourseList().get(0).getName());
|
|
|
|
-
|
|
|
|
- for (ExamStatisticEntity v : list) {
|
|
|
|
- examResult.setAllCount(examResult.getAllCount() + v.getAllCount());
|
|
|
|
- examResult.setFinishCount(examResult.getFinishCount() + v.getFinishCount());
|
|
|
|
- examResult.setPassScoreCount(examResult.getPassScoreCount() + v.getPassScoreCount());
|
|
|
|
- examResult.setGoodScoreCount(examResult.getGoodScoreCount() + v.getGoodScoreCount());
|
|
|
|
- if (v.getCourseId().equals(courseId)) {
|
|
|
|
- courseResult.setAllCount(courseResult.getAllCount() + v.getAllCount());
|
|
|
|
- courseResult.setFinishCount(courseResult.getFinishCount() + v.getFinishCount());
|
|
|
|
- courseResult.setPassScoreCount(courseResult.getPassScoreCount() + v.getPassScoreCount());
|
|
|
|
- courseResult.setGoodScoreCount(courseResult.getGoodScoreCount() + v.getGoodScoreCount());
|
|
|
|
- }
|
|
|
|
|
|
+ public ExamStatisticInfo overviewForExam(Long examId) {
|
|
|
|
+ StringBuffer sql = new StringBuffer();
|
|
|
|
+ sql.append(" select");
|
|
|
|
+ sql.append(" exam_id,");
|
|
|
|
+ sql.append(" sum(all_count) as allCount,");
|
|
|
|
+ sql.append(" sum(finish_count) as finishCount,");
|
|
|
|
+ sql.append(" sum(pass_score_count) as passScoreCount,");
|
|
|
|
+ sql.append(" sum(good_score_count) as goodScoreCount");
|
|
|
|
+ sql.append(" from ec_oe_exam_statistic");
|
|
|
|
+ sql.append(" where exam_id = ").append(examId);
|
|
|
|
+
|
|
|
|
+ List<ExamStatisticInfo> list = jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper(ExamStatisticInfo.class));
|
|
|
|
+ if (list.isEmpty()) {
|
|
|
|
+ return new ExamStatisticInfo();
|
|
}
|
|
}
|
|
|
|
|
|
- examResult.setUnFinishCount(examResult.getAllCount() - examResult.getFinishCount());
|
|
|
|
- if (examResult.getAllCount() > 0) {
|
|
|
|
- examResult.setUnFinishRate(MathUtils.percentage(examResult.getUnFinishCount(), examResult.getAllCount()));
|
|
|
|
- examResult.setPassScoreRate(MathUtils.percentage(examResult.getPassScoreCount(), examResult.getAllCount()));
|
|
|
|
- examResult.setGoodScoreRate(MathUtils.percentage(examResult.getGoodScoreCount(), examResult.getAllCount()));
|
|
|
|
|
|
+ ExamStatisticInfo info = list.get(0);
|
|
|
|
+ if (info.getExamId() == null) {
|
|
|
|
+ return new ExamStatisticInfo();
|
|
}
|
|
}
|
|
|
|
|
|
- courseResult.setUnFinishCount(courseResult.getAllCount() - courseResult.getFinishCount());
|
|
|
|
- if (courseResult.getAllCount() > 0) {
|
|
|
|
- courseResult.setUnFinishRate(MathUtils.percentage(courseResult.getUnFinishCount(), courseResult.getAllCount()));
|
|
|
|
- courseResult.setPassScoreRate(MathUtils.percentage(courseResult.getPassScoreCount(), courseResult.getAllCount()));
|
|
|
|
- courseResult.setGoodScoreRate(MathUtils.percentage(courseResult.getGoodScoreCount(), courseResult.getAllCount()));
|
|
|
|
|
|
+ info.setUnFinishCount(info.getAllCount() - info.getFinishCount());
|
|
|
|
+ if (info.getAllCount() > 0) {
|
|
|
|
+ info.setUnFinishRate(MathUtils.percentage(info.getUnFinishCount(), info.getAllCount()));
|
|
|
|
+ info.setPassScoreRate(MathUtils.percentage(info.getPassScoreCount(), info.getAllCount()));
|
|
|
|
+ info.setGoodScoreRate(MathUtils.percentage(info.getGoodScoreCount(), info.getAllCount()));
|
|
|
|
+ info.setIllegalityRate(MathUtils.percentage(info.getIllegalityCount(), info.getAllCount()));
|
|
}
|
|
}
|
|
|
|
|
|
- return result;
|
|
|
|
|
|
+ return info;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public List<ExamStatisticInfo> overviewForOrg(Long examId, Long courseId) {
|
|
|
|
- List<ExamStatisticEntity> list = examStatisticRepo.findByExamIdAndCourseId(examId, courseId);
|
|
|
|
- if (CollectionUtils.isEmpty(list)) {
|
|
|
|
- return new ArrayList<>();
|
|
|
|
|
|
+ public List<ExamStatisticInfo> overviewForCourse(Long examId, Long courseId) {
|
|
|
|
+ StringBuffer sql = new StringBuffer();
|
|
|
|
+ sql.append(" select");
|
|
|
|
+ sql.append(" course_id,");
|
|
|
|
+ sql.append(" sum(all_count) as allCount,");
|
|
|
|
+ sql.append(" sum(finish_count) as finishCount,");
|
|
|
|
+ sql.append(" sum(pass_score_count) as passScoreCount,");
|
|
|
|
+ sql.append(" sum(good_score_count) as goodScoreCount");
|
|
|
|
+ sql.append(" from ec_oe_exam_statistic");
|
|
|
|
+ sql.append(" where exam_id = ").append(examId);
|
|
|
|
+ if (courseId != null) {
|
|
|
|
+ sql.append(" and course_id = ").append(courseId);
|
|
}
|
|
}
|
|
|
|
+ sql.append(" group by course_id");
|
|
|
|
|
|
- List<ExamStatisticInfo> result = new ArrayList<>();
|
|
|
|
-
|
|
|
|
- Map<Long, List<ExamStatisticEntity>> orgStatisticMaps = list.stream().collect(Collectors.groupingBy(ExamStatisticEntity::getOrgId));
|
|
|
|
|
|
+ Set<Long> courseIds = new HashSet<>();
|
|
|
|
+ List<ExamStatisticInfo> list = jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper(ExamStatisticInfo.class));
|
|
|
|
+ for (ExamStatisticInfo info : list) {
|
|
|
|
+ courseIds.add(info.getCourseId());
|
|
|
|
|
|
- // 获取机构信息列表
|
|
|
|
- GetOrgMapsReq orgMapsReq = new GetOrgMapsReq();
|
|
|
|
- orgMapsReq.setOrgIds(orgStatisticMaps.keySet());
|
|
|
|
- Map<Long, OrgBean> orgMaps = orgCloudService.getOrgMaps(orgMapsReq).getOrgMaps();
|
|
|
|
|
|
+ info.setUnFinishCount(info.getAllCount() - info.getFinishCount());
|
|
|
|
+ if (info.getAllCount() > 0) {
|
|
|
|
+ info.setUnFinishRate(MathUtils.percentage(info.getUnFinishCount(), info.getAllCount()));
|
|
|
|
+ info.setPassScoreRate(MathUtils.percentage(info.getPassScoreCount(), info.getAllCount()));
|
|
|
|
+ info.setGoodScoreRate(MathUtils.percentage(info.getGoodScoreCount(), info.getAllCount()));
|
|
|
|
+ info.setIllegalityRate(MathUtils.percentage(info.getIllegalityCount(), info.getAllCount()));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- for (Map.Entry<Long, List<ExamStatisticEntity>> e : orgStatisticMaps.entrySet()) {
|
|
|
|
- ExamStatisticInfo info = new ExamStatisticInfo();
|
|
|
|
- info.setOrgId(e.getKey());
|
|
|
|
|
|
+ // 获取课程信息列表
|
|
|
|
+ GetCoursesByIdListReq req = new GetCoursesByIdListReq();
|
|
|
|
+ req.setCourseIdList(new ArrayList<>(courseIds));
|
|
|
|
+ GetCoursesByIdListResp resp = courseCloudService.getCoursesByIdList(req);
|
|
|
|
+ Map<Long, CourseBean> courseMaps = resp.getCourseList().stream().collect(Collectors.toMap(CourseBean::getId, v -> v));
|
|
|
|
|
|
- OrgBean org = orgMaps.get(e.getKey());
|
|
|
|
- if (org != null) {
|
|
|
|
- info.setOrgName(org.getName());
|
|
|
|
|
|
+ for (ExamStatisticInfo info : list) {
|
|
|
|
+ CourseBean course = courseMaps.get(info.getCourseId());
|
|
|
|
+ if (course != null) {
|
|
|
|
+ info.setCourseName(course.getName());
|
|
|
|
+ info.setCourseCode(course.getCode());
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
- for (ExamStatisticEntity v : e.getValue()) {
|
|
|
|
- info.setAllCount(info.getAllCount() + v.getAllCount());
|
|
|
|
- info.setFinishCount(info.getFinishCount() + v.getFinishCount());
|
|
|
|
- info.setPassScoreCount(info.getPassScoreCount() + v.getPassScoreCount());
|
|
|
|
- info.setGoodScoreCount(info.getGoodScoreCount() + v.getGoodScoreCount());
|
|
|
|
- }
|
|
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<ExamStatisticInfo> overviewForOrg(Long examId, Long orgId) {
|
|
|
|
+ StringBuffer sql = new StringBuffer();
|
|
|
|
+ sql.append(" select");
|
|
|
|
+ sql.append(" org_id,");
|
|
|
|
+ sql.append(" sum(all_count) as allCount,");
|
|
|
|
+ sql.append(" sum(finish_count) as finishCount,");
|
|
|
|
+ sql.append(" sum(pass_score_count) as passScoreCount,");
|
|
|
|
+ sql.append(" sum(good_score_count) as goodScoreCount");
|
|
|
|
+ sql.append(" from ec_oe_exam_statistic");
|
|
|
|
+ sql.append(" where exam_id = ").append(examId);
|
|
|
|
+ if (orgId != null) {
|
|
|
|
+ sql.append(" and org_id = ").append(orgId);
|
|
|
|
+ }
|
|
|
|
+ sql.append(" group by org_id");
|
|
|
|
+
|
|
|
|
+ Set<Long> orgIds = new HashSet<>();
|
|
|
|
+ List<ExamStatisticInfo> list = jdbcTemplate.query(sql.toString(), new BeanPropertyRowMapper(ExamStatisticInfo.class));
|
|
|
|
+ for (ExamStatisticInfo info : list) {
|
|
|
|
+ orgIds.add(info.getOrgId());
|
|
|
|
|
|
info.setUnFinishCount(info.getAllCount() - info.getFinishCount());
|
|
info.setUnFinishCount(info.getAllCount() - info.getFinishCount());
|
|
if (info.getAllCount() > 0) {
|
|
if (info.getAllCount() > 0) {
|
|
info.setUnFinishRate(MathUtils.percentage(info.getUnFinishCount(), info.getAllCount()));
|
|
info.setUnFinishRate(MathUtils.percentage(info.getUnFinishCount(), info.getAllCount()));
|
|
info.setPassScoreRate(MathUtils.percentage(info.getPassScoreCount(), info.getAllCount()));
|
|
info.setPassScoreRate(MathUtils.percentage(info.getPassScoreCount(), info.getAllCount()));
|
|
info.setGoodScoreRate(MathUtils.percentage(info.getGoodScoreCount(), info.getAllCount()));
|
|
info.setGoodScoreRate(MathUtils.percentage(info.getGoodScoreCount(), info.getAllCount()));
|
|
|
|
+ info.setIllegalityRate(MathUtils.percentage(info.getIllegalityCount(), info.getAllCount()));
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
- result.add(info);
|
|
|
|
|
|
+ // 获取机构信息列表
|
|
|
|
+ GetOrgMapsReq req = new GetOrgMapsReq();
|
|
|
|
+ req.setOrgIds(orgIds);
|
|
|
|
+ Map<Long, OrgBean> orgMaps = orgCloudService.getOrgMaps(req).getOrgMaps();
|
|
|
|
+ for (ExamStatisticInfo info : list) {
|
|
|
|
+ OrgBean org = orgMaps.get(info.getOrgId());
|
|
|
|
+ if (org != null) {
|
|
|
|
+ info.setOrgName(org.getName());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- return result;
|
|
|
|
|
|
+ return list;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|