|
|
@@ -0,0 +1,148 @@
|
|
|
+package cn.iselab.mooctest.site.web.logic.impl;
|
|
|
+
|
|
|
+import cn.iselab.mooctest.site.models.*;
|
|
|
+import cn.iselab.mooctest.site.service.AssignedTaskService;
|
|
|
+import cn.iselab.mooctest.site.service.DetailStatisticsService;
|
|
|
+import cn.iselab.mooctest.site.service.UserService;
|
|
|
+import cn.iselab.mooctest.site.web.data.CaseExtendsVO;
|
|
|
+import cn.iselab.mooctest.site.web.data.ExamVO;
|
|
|
+import cn.iselab.mooctest.site.web.data.PaperVO;
|
|
|
+import cn.iselab.mooctest.site.web.data.wrapper.ExamVOWrapper;
|
|
|
+import cn.iselab.mooctest.site.web.logic.DetailStatisticsLogic;
|
|
|
+import cn.iselab.mooctest.site.web.util.Converter;
|
|
|
+import org.json.JSONObject;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Iterator;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by HenryLee on 2017/9/30.
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class DetailStatisticsLogicImpl implements DetailStatisticsLogic {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ DetailStatisticsService detailStatisticsService;
|
|
|
+ @Autowired
|
|
|
+ UserService userService;
|
|
|
+ @Autowired
|
|
|
+ ExamVOWrapper examVOWrapper;
|
|
|
+ @Autowired
|
|
|
+ AssignedTaskService assignedTaskService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<CaseExtendsVO> findCasesByTargetId(long targetId) {
|
|
|
+ List<CaseExtends> caseExtendsList = detailStatisticsService.findCaseByTargetId(targetId);
|
|
|
+ List<CaseExtendsVO> caseExtendsVOS = new ArrayList<>();
|
|
|
+ caseExtendsList.forEach(caseExtends -> {
|
|
|
+ CaseExtendsVO caseExtendsVO = Converter.convert(CaseExtendsVO.class, caseExtends);
|
|
|
+ caseExtendsVO.setManagerId(caseExtends.getOwnerId());
|
|
|
+ caseExtendsVOS.add(caseExtendsVO);
|
|
|
+ });
|
|
|
+ return caseExtendsVOS;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<PaperVO> findPapersByCaseId(long caseId) {
|
|
|
+ List<Paper> papers = detailStatisticsService.findPaperByCaseId(caseId);
|
|
|
+ List<PaperVO> paperVOS = new ArrayList<>();
|
|
|
+ papers.forEach(paper -> {
|
|
|
+ PaperVO paperVO = Converter.convert(PaperVO.class,paper);
|
|
|
+ User user = userService.findByUserId(paper.getOwnerId());
|
|
|
+ paperVO.setOwnerName(user.getName());
|
|
|
+ paperVOS.add(paperVO);
|
|
|
+ });
|
|
|
+ return paperVOS;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<ExamVO> findExamsByCaseId(long caseId) {
|
|
|
+ List<Task> tasks = detailStatisticsService.findTaskByCaseId(caseId);
|
|
|
+
|
|
|
+ List<ExamVO> examVOS = new ArrayList<>();
|
|
|
+ tasks.forEach(task -> {
|
|
|
+ examVOS.add(examVOWrapper.wrap(task));
|
|
|
+ });
|
|
|
+ return examVOS;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<PaperVO> findPaperByTargetId(long targetId) {
|
|
|
+ List<CaseExtends> caseExtendsList = detailStatisticsService.findCaseByTargetId(targetId);
|
|
|
+ List<PaperVO> paperVOS = new ArrayList<>();
|
|
|
+ caseExtendsList.forEach(caseExtends -> {
|
|
|
+ paperVOS.addAll(this.findPapersByCaseId(caseExtends.getId()));
|
|
|
+ });
|
|
|
+ return paperVOS;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<ExamVO> findExamByTargetId(long targetId) {
|
|
|
+ List<CaseExtends> caseExtendsList = detailStatisticsService.findCaseByTargetId(targetId);
|
|
|
+ List<ExamVO> examVOS = new ArrayList<>();
|
|
|
+ caseExtendsList.forEach(caseExtends -> {
|
|
|
+ examVOS.addAll(this.findExamsByCaseId(caseExtends.getId()));
|
|
|
+ });
|
|
|
+ return examVOS;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HashMap countUserByCase(long caseId) {
|
|
|
+ HashMap<Long,Double> scores = new HashMap();
|
|
|
+ List<Task> tasks = detailStatisticsService.findTaskByCaseId(caseId);
|
|
|
+ tasks.forEach(task -> {
|
|
|
+ List<AssignedTask> assignedTasks = assignedTaskService.getAssignedTasks(task.getId());
|
|
|
+ assignedTasks.forEach(assignedTask -> {
|
|
|
+ String result = assignedTask.getResult();
|
|
|
+ double caseScore = haveDoneThisCase(caseId,result);
|
|
|
+ if(caseScore != -1) {
|
|
|
+ scores.put(assignedTask.getParticipantId(),caseScore);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ return scores;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int countUserByTarget(long targetId) {
|
|
|
+ List<CaseExtends> caseExtendsList = detailStatisticsService.findCaseByTargetId(targetId);
|
|
|
+ int targetUsedNum = 0;
|
|
|
+ for (CaseExtends caseExtends : caseExtendsList) {
|
|
|
+ targetUsedNum += this.countUserByCase(caseExtends.getId()).size();
|
|
|
+ }
|
|
|
+ return targetUsedNum;
|
|
|
+ }
|
|
|
+
|
|
|
+ private double haveDoneThisCase(long caseId,String result){
|
|
|
+ double cannotFindCase = -1;
|
|
|
+ JSONObject resultObj = new JSONObject(result).getJSONObject("results");
|
|
|
+ Iterator it = resultObj.keys();
|
|
|
+ while(it.hasNext()){
|
|
|
+ String key = it.next().toString();
|
|
|
+ JSONObject caseDetail = resultObj.getJSONObject(key);
|
|
|
+ if(caseDetail.getDouble("id") == caseId) {
|
|
|
+ if(caseDetail.has("maxScore"))
|
|
|
+ return caseDetail.getDouble("maxScore");
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return cannotFindCase;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|