|
|
@@ -1,10 +1,18 @@
|
|
|
package cn.iselab.mooctest.site.rpc.Oauth2.impl;
|
|
|
|
|
|
+import cn.iselab.mooctest.site.common.constant.Constants;
|
|
|
import cn.iselab.mooctest.site.common.constant.SubsiteConstants;
|
|
|
-import cn.iselab.mooctest.site.models.Task;
|
|
|
+import cn.iselab.mooctest.site.dao.Exam2CaseDao;
|
|
|
+import cn.iselab.mooctest.site.dao.OpenId2UserIdDao;
|
|
|
+import cn.iselab.mooctest.site.dao.Task2CaseDao;
|
|
|
+import cn.iselab.mooctest.site.models.*;
|
|
|
import cn.iselab.mooctest.site.models.instancePermission.TaskPermission;
|
|
|
import cn.iselab.mooctest.site.rpc.oauth2.api.ExamService;
|
|
|
import cn.iselab.mooctest.site.rpc.oauth2.data.*;
|
|
|
+import cn.iselab.mooctest.site.service.AssignedTaskService;
|
|
|
+import cn.iselab.mooctest.site.service.ExamStatusService;
|
|
|
+import cn.iselab.mooctest.site.service.PaperService;
|
|
|
+import cn.iselab.mooctest.site.service.TaskService;
|
|
|
import cn.iselab.mooctest.site.web.data.fromDev.PluginResultVO;
|
|
|
import cn.iselab.mooctest.site.web.data.fromKibug.ReportScriptResultVO;
|
|
|
import cn.iselab.mooctest.site.web.data.fromKibug.ReportVO;
|
|
|
@@ -14,16 +22,19 @@ import cn.iselab.mooctest.site.web.logic.fromDev.PluginLogic;
|
|
|
import cn.iselab.mooctest.site.web.util.Converter;
|
|
|
import com.alibaba.dubbo.config.annotation.Service;
|
|
|
import org.apache.shiro.authz.UnauthorizedException;
|
|
|
+import org.json.JSONArray;
|
|
|
+import org.json.JSONObject;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* Created by shanshan on 2017/8/14.
|
|
|
*/
|
|
|
-@Service(version = "1.0.7")
|
|
|
+@Service(version = Constants.OAUTH2APIVERSION, timeout = 12000 )
|
|
|
@Component
|
|
|
public class ExamServiceImpl2 implements ExamService {
|
|
|
@Autowired
|
|
|
@@ -32,6 +43,24 @@ public class ExamServiceImpl2 implements ExamService {
|
|
|
private PluginLogic pluginLogic;
|
|
|
@Autowired
|
|
|
private ExamLogic examLogic;
|
|
|
+ @Autowired
|
|
|
+ private AssignedTaskService assignedTaskService;
|
|
|
+ @Autowired
|
|
|
+ private OpenId2UserIdDao openId2UserIdDao;
|
|
|
+ @Autowired
|
|
|
+ private cn.iselab.mooctest.site.service.ExamService examService;
|
|
|
+ @Autowired
|
|
|
+ private PaperService paperService;
|
|
|
+ @Autowired
|
|
|
+ private Task2CaseDao task2CaseDao;
|
|
|
+ @Autowired
|
|
|
+ private Exam2CaseDao exam2CaseDao;
|
|
|
+ @Autowired
|
|
|
+ private TaskService taskService;
|
|
|
+ @Autowired
|
|
|
+ private ExamStatusService examStatusService;
|
|
|
+
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public TaskVO getCaseList(Long userId, Long taskId, Long subsiteId) throws Exception {
|
|
|
@@ -83,4 +112,96 @@ public class ExamServiceImpl2 implements ExamService {
|
|
|
ReportScriptResultVO reportScriptResultVO = Converter.convert(ReportScriptResultVO.class, vo);
|
|
|
reportLogic.recordReportScript(reportId, reportScriptResultVO);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean saveTaskResult(TaskResultDTO taskResultDTO) {
|
|
|
+ long taskId = taskResultDTO.getTask_id();
|
|
|
+
|
|
|
+ HashMap<Long, String> caseNameMap = taskResultDTO.getTask_case_list();
|
|
|
+ Task task = null;
|
|
|
+ long participantId;
|
|
|
+ for(ScoreDetails scoreDetails: taskResultDTO.getScoreDetails()) {
|
|
|
+ OpenId2UserId openId2UserId = openId2UserIdDao.findByOpenId(scoreDetails.getOpen_id());
|
|
|
+ participantId = openId2UserId.getUserId();
|
|
|
+ task = examService.getExamByIdAndParticipantIdIfPermited(taskId, openId2UserId.getUserId());
|
|
|
+ this.saveAssignedTask(participantId, scoreDetails, task, caseNameMap);
|
|
|
+ }
|
|
|
+ if(task != null) {
|
|
|
+ Paper paper = this.savePaperAndPaper2Case(task.getName(), caseNameMap);
|
|
|
+ this.saveExam2PaperAndExam2Case(paper, taskId, caseNameMap);
|
|
|
+ this.updateTaskStatus(taskId);
|
|
|
+ }
|
|
|
+
|
|
|
+ // insert data into assignedtask
|
|
|
+ // new paper for the task (paper and paper2case)
|
|
|
+ // copy cases to exam (savetask2exam)
|
|
|
+ // update status of task
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private AssignedTask saveAssignedTask(long participantId, ScoreDetails scoreDetails, Task task, HashMap<Long, String> caseNameMap) {
|
|
|
+ AssignedTask assignedTask = new AssignedTask();
|
|
|
+ assignedTask.setWorkerId(participantId);
|
|
|
+ assignedTask.setName(task.getName());
|
|
|
+ assignedTask.setTaskId(task.getId());
|
|
|
+ assignedTask.setManagerId(task.getManagerId());
|
|
|
+ assignedTask.setContent("");
|
|
|
+ assignedTask.setScore(0.0);
|
|
|
+ assignedTask.setOwnerId(task.getOwnerId());
|
|
|
+ assignedTask.setParticipantId(participantId);
|
|
|
+
|
|
|
+ JSONObject assignedResults = new JSONObject();
|
|
|
+ JSONObject assignedResultObj = new JSONObject();
|
|
|
+
|
|
|
+ for(CaseDetailDTO caseDetailDTO: scoreDetails.getDetail()) {
|
|
|
+ JSONObject caseDetail = new JSONObject();
|
|
|
+ caseDetail.put("id", caseDetailDTO.getCase_id());
|
|
|
+ caseDetail.put("maxScore", caseDetailDTO.getScore());
|
|
|
+ JSONArray scores = new JSONArray();
|
|
|
+ scores.put(caseDetailDTO.getScore());
|
|
|
+ caseDetail.put("scores", scores);
|
|
|
+ caseDetail.put("name", caseNameMap.get(caseDetailDTO.getCase_id()));
|
|
|
+ caseDetail.put("resultUrls", new JSONArray());
|
|
|
+ assignedResults.put(String.valueOf(caseDetailDTO.getCase_id()), caseDetail);
|
|
|
+ }
|
|
|
+ assignedResultObj.put("results", assignedResults);
|
|
|
+ assignedTask.setResult(assignedResultObj.toString());
|
|
|
+ return assignedTaskService.saveOrUpdateAssignedTask(assignedTask);
|
|
|
+ }
|
|
|
+
|
|
|
+ private Paper savePaperAndPaper2Case(String paperName, HashMap<Long, String> caseNameMap) {
|
|
|
+ Paper paper = new Paper();
|
|
|
+ paper.setName(paperName+"试卷");
|
|
|
+ paper = paperService.createOrUpdate(paper);
|
|
|
+ for(Long id: caseNameMap.keySet()) {
|
|
|
+ Task2Case task2Case = new Task2Case();
|
|
|
+ task2Case.setTaskId(paper.getId());
|
|
|
+ task2Case.setAutoSelect(true);
|
|
|
+ task2Case.setCaseId(id);
|
|
|
+ task2Case.setCaseIndex(0);
|
|
|
+ task2Case.setCount(1);
|
|
|
+ task2Case.setWeight(0.0);
|
|
|
+ task2CaseDao.save(task2Case);
|
|
|
+ }
|
|
|
+ return paper;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveExam2PaperAndExam2Case(Paper paper, long taskId, HashMap<Long, String> nameCaseMap) {
|
|
|
+ examService.saveExam2Paper(taskId, paper.getId());
|
|
|
+ for(Long id: nameCaseMap.keySet()) {
|
|
|
+ Exam2Case exam2Case = new Exam2Case();
|
|
|
+ exam2Case.setCaseId(id);
|
|
|
+ exam2Case.setExamId(taskId);
|
|
|
+ exam2Case.setPaperId(paper.getId());
|
|
|
+ exam2CaseDao.save(exam2Case);
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void updateTaskStatus(long taskId) {
|
|
|
+ Task task = taskService.getTask(taskId);
|
|
|
+ examStatusService.updateStatus(task);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
}
|