|
@@ -0,0 +1,165 @@
|
|
|
+package cn.iselab.mooctest.site.web.logic.asyncProgress.impl;
|
|
|
+
|
|
|
+import cn.iselab.mooctest.site.common.acyncTask.ScriptAnalysisCallBack;
|
|
|
+import cn.iselab.mooctest.site.common.enums.AsyncJobTool;
|
|
|
+import cn.iselab.mooctest.site.data.AsyncJobStatus;
|
|
|
+import cn.iselab.mooctest.site.data.UploadRecordDTO;
|
|
|
+import cn.iselab.mooctest.site.data.UserDTOForMT;
|
|
|
+import cn.iselab.mooctest.site.models.SubmitRecord;
|
|
|
+import cn.iselab.mooctest.site.models.WeightGeneral;
|
|
|
+import cn.iselab.mooctest.site.service.*;
|
|
|
+import cn.iselab.mooctest.site.web.data.ScriptAnalysisJobVO;
|
|
|
+import cn.iselab.mooctest.site.web.data.ScriptAnalysisProgressVO;
|
|
|
+import cn.iselab.mooctest.site.web.data.forMongo.AsyncTaskDTO;
|
|
|
+import cn.iselab.mooctest.site.web.exception.HttpBadRequestException;
|
|
|
+import cn.iselab.mooctest.site.web.logic.BaseLogic;
|
|
|
+import cn.iselab.mooctest.site.web.logic.asyncProgress.ScriptAnalysisProgressLogic;
|
|
|
+import cn.iselab.mooctest.site.web.logic.fromDev.PluginLogic;
|
|
|
+import org.apache.commons.collections.map.HashedMap;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by guochao on 2019/4/8.
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class ScriptAanlysisProgressLogicImpl extends BaseLogic implements ScriptAnalysisProgressLogic {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ SubmitRecordService submitRecordService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ AsyncTaskService asyncTaskService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ AsyncScheduleService asyncScheduleService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ UserService userService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ PluginLogic pluginLogic;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ CaseService caseService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ WeightGeneralService weightGeneralService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ GeneralCalculateScoreService generalCalculateScoreService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ScriptAnalysisProgressVO getScriptAnalysisProgress(Long examId, Long caseId) {
|
|
|
+ AsyncTaskDTO asyncTaskDTO = asyncTaskService.getAsyncTask(AsyncJobTool.SCRIPTANALYSIS, examId, caseId);
|
|
|
+ if (asyncTaskDTO == null) {
|
|
|
+ asyncTaskDTO = triggerScriptAnalysis(examId, caseId);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(asyncTaskDTO == null){
|
|
|
+ return new ScriptAnalysisProgressVO();
|
|
|
+ }
|
|
|
+ Map<String, AsyncJobStatus> jobStatusMap = asyncScheduleService.getStatusMap(asyncTaskDTO.getSessionId());
|
|
|
+ List<Long> userIds = asyncTaskDTO.getJobs().stream().map(asyncJobDTO -> {
|
|
|
+ return Long.parseLong(asyncJobDTO.getContexts().get("userId"));
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ Map<Long, UserDTOForMT> userMap = userService.getUserMap(userIds);
|
|
|
+ List<ScriptAnalysisJobVO> jobs = asyncTaskDTO.getJobs().stream().map(asyncJobDTO -> {
|
|
|
+ ScriptAnalysisJobVO scriptAnalysisJobVO = new ScriptAnalysisJobVO();
|
|
|
+ scriptAnalysisJobVO.setJobId(asyncJobDTO.getJobId());
|
|
|
+ scriptAnalysisJobVO.setStatus(asyncJobDTO.getStatus());
|
|
|
+ scriptAnalysisJobVO.setUserId(Long.parseLong(asyncJobDTO.getContexts().get("userId")));
|
|
|
+ AsyncJobStatus tempStatus = jobStatusMap.get(asyncJobDTO.getJobId());
|
|
|
+ UserDTOForMT tempUser = userMap.get(Long.parseLong(asyncJobDTO.getContexts().get("userId")));
|
|
|
+ scriptAnalysisJobVO.setProgressStatus(tempStatus!=null?tempStatus.getStatus():"");
|
|
|
+ scriptAnalysisJobVO.setUserName(tempUser!=null?tempUser.getName():null);
|
|
|
+ return scriptAnalysisJobVO;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ ScriptAnalysisProgressVO scriptAnalysisProgressVO = new ScriptAnalysisProgressVO();
|
|
|
+ scriptAnalysisProgressVO.setSessionId(asyncTaskDTO.getSessionId());
|
|
|
+ scriptAnalysisProgressVO.setExamId(examId);
|
|
|
+ scriptAnalysisProgressVO.setCaseId(caseId);
|
|
|
+ scriptAnalysisProgressVO.setJobs(jobs);
|
|
|
+ return scriptAnalysisProgressVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ private AsyncTaskDTO triggerScriptAnalysis(Long examId, Long caseId) {
|
|
|
+ List<WeightGeneral> weightGenerals=weightGeneralService.get(examId,caseId);
|
|
|
+ if(weightGenerals==null || weightGenerals.isEmpty()){
|
|
|
+ throw new HttpBadRequestException("unmatched examId and caseId");
|
|
|
+ }
|
|
|
+ List<Map<String, String>> params;
|
|
|
+ List<Map<String, String>> contexts;
|
|
|
+ List<SubmitRecord> submitRecords = submitRecordService.getSubmittedRecordsByExamId(examId);
|
|
|
+ params = submitRecords.stream()
|
|
|
+ .filter(assignedTask -> {
|
|
|
+ UploadRecordDTO uploadRecordDTO = generalCalculateScoreService.getLatestUploadRecord
|
|
|
+ (assignedTask.getParticipantId(),examId,caseId);
|
|
|
+ return uploadRecordDTO!=null && uploadRecordDTO.getOSSUrl()!=null;
|
|
|
+ })
|
|
|
+ .map(assignedTask -> {
|
|
|
+ Map<String, String> param = new HashedMap();
|
|
|
+ UploadRecordDTO uploadRecordDTO = generalCalculateScoreService.getLatestUploadRecord
|
|
|
+ (assignedTask.getParticipantId(),examId,caseId);
|
|
|
+ String downloadUrl = uploadRecordDTO.getOSSUrl();
|
|
|
+ param.put("downloadURL", uploadRecordDTO.getOSSUrl());
|
|
|
+ param.put("extraArgs", generateScriptAnalysisExtraArgs(downloadUrl));
|
|
|
+ return param;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ contexts = submitRecords.stream()
|
|
|
+ .filter(assignedTask -> {
|
|
|
+ UploadRecordDTO uploadRecordDTO = generalCalculateScoreService.getLatestUploadRecord
|
|
|
+ (assignedTask.getParticipantId(),examId,caseId);
|
|
|
+ return uploadRecordDTO!=null && uploadRecordDTO.getOSSUrl()!=null;
|
|
|
+ })
|
|
|
+ .map(assignedTask -> {
|
|
|
+ Map<String, String> param = new HashedMap();
|
|
|
+ param.put("examId", examId.toString());
|
|
|
+ param.put("caseId", caseId.toString());
|
|
|
+ param.put("userId", assignedTask.getParticipantId().toString());
|
|
|
+ UploadRecordDTO uploadRecordDTO = generalCalculateScoreService.getLatestUploadRecord
|
|
|
+ (assignedTask.getParticipantId(),examId,caseId);
|
|
|
+ param.put("uploadId", uploadRecordDTO.getId()+"");
|
|
|
+ return param;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ //return null when no one submits
|
|
|
+ if(params.size()==0&&contexts.size()==0){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ return asyncScheduleService.start(AsyncJobTool.SCRIPTANALYSIS, params,contexts,ScriptAnalysisCallBack.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String generateScriptAnalysisExtraArgs(String downloadUrl){
|
|
|
+ String zipName = downloadUrl.split("/")[downloadUrl.split("/").length - 1];
|
|
|
+ return "-F "+ zipName;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean stopScriptAnalysis(String taskId) {
|
|
|
+ return asyncScheduleService.stop(taskId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean retryJob(String sessionId, String jobId) {
|
|
|
+ asyncScheduleService.retryJob(AsyncJobTool.SCRIPTANALYSIS,sessionId,jobId,ScriptAnalysisCallBack.class);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean reRunSession(String sessionId, Long examId, Long caseId){
|
|
|
+ asyncScheduleService.stop(sessionId);
|
|
|
+ try {
|
|
|
+ triggerScriptAnalysis(examId, caseId);
|
|
|
+ return true;
|
|
|
+ }catch (Exception e){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|