|
@@ -1,15 +1,21 @@
|
|
|
package cn.com.qmth.examcloud.core.oe.admin.service.impl;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.commons.util.MathUtils;
|
|
|
import cn.com.qmth.examcloud.core.oe.admin.dao.ExamStatisticRepo;
|
|
|
+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.bean.statistic.ExamStatisticInfo;
|
|
|
import cn.com.qmth.examcloud.core.oe.admin.service.bean.statistic.OverviewInfo;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class ExamStatisticServiceImpl implements ExamStatisticService {
|
|
@@ -21,12 +27,80 @@ public class ExamStatisticServiceImpl implements ExamStatisticService {
|
|
|
|
|
|
@Override
|
|
|
public OverviewInfo overview(Long examId, Long courseId) {
|
|
|
- return null;
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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()));
|
|
|
+ }
|
|
|
+
|
|
|
+ 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()));
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<ExamStatisticInfo> overviewForOrg(Long examId, Long courseId) {
|
|
|
- return null;
|
|
|
+ List<ExamStatisticEntity> list = examStatisticRepo.findByExamIdAndCourseId(examId, courseId);
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ExamStatisticInfo> result = new ArrayList<>();
|
|
|
+
|
|
|
+ Map<Long, List<ExamStatisticEntity>> orgStatisticMaps = list.stream().collect(Collectors.groupingBy(ExamStatisticEntity::getOrgId));
|
|
|
+ for (Map.Entry<Long, List<ExamStatisticEntity>> e : orgStatisticMaps.entrySet()) {
|
|
|
+ ExamStatisticInfo info = new ExamStatisticInfo();
|
|
|
+ info.setOrgId(e.getKey());
|
|
|
+
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+
|
|
|
+ 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()));
|
|
|
+ }
|
|
|
+
|
|
|
+ result.add(info);
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
}
|