|
@@ -1,26 +1,43 @@
|
|
|
package cn.iselab.mooctest.site.web.ctrl;
|
|
|
|
|
|
import cn.iselab.mooctest.site.common.constant.UrlConstants;
|
|
|
+import cn.iselab.mooctest.site.configure.EvaluationConfiguration;
|
|
|
import cn.iselab.mooctest.site.web.data.CommunityStatisticVO;
|
|
|
import cn.iselab.mooctest.site.web.data.response.ResponseVO;
|
|
|
import cn.iselab.mooctest.site.web.data.response.ServerCode;
|
|
|
+import cn.iselab.mooctest.site.web.logic.ExamLogic;
|
|
|
+import cn.iselab.mooctest.site.web.logic.OSSLogic;
|
|
|
import cn.iselab.mooctest.site.web.logic.UserEvaluationLogic;
|
|
|
import javax.annotation.Resource;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.shiro.SecurityUtils;
|
|
|
+import org.springframework.http.*;
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.InputStream;
|
|
|
|
|
|
/**
|
|
|
* Created on 2019/3/19
|
|
|
*/
|
|
|
@RestController
|
|
|
+@Slf4j
|
|
|
public class EvaluationController {
|
|
|
|
|
|
@Resource
|
|
|
+ private EvaluationConfiguration evaluationConfiguration;
|
|
|
+ @Resource
|
|
|
private UserEvaluationLogic userEvaluationLogic;
|
|
|
+ @Resource
|
|
|
+ private OSSLogic ossLogic;
|
|
|
+ @Resource
|
|
|
+ private ExamLogic examLogic;
|
|
|
|
|
|
@RequestMapping(value = UrlConstants.API+"/evaluation/{examId}", method = RequestMethod.POST)
|
|
|
public ResponseVO triggerExamEvaluation(@PathVariable("examId")long examId){
|
|
@@ -35,4 +52,100 @@ public class EvaluationController {
|
|
|
CommunityStatisticVO vo = userEvaluationLogic.getCommunityStatistic(userId);
|
|
|
return new ResponseVO<>(ServerCode.SUCCESS, vo);
|
|
|
}
|
|
|
+
|
|
|
+ @RequestMapping(value = UrlConstants.API + "/evaluation/trigger/{examId}", method = RequestMethod.POST)
|
|
|
+ public ResponseVO<String> triggerEvaluation(@PathVariable("examId") long examId) {
|
|
|
+ if (examLogic.getExamById(examId) == null) {
|
|
|
+ return new ResponseVO<>(500, "无当前考试记录", null);
|
|
|
+ }
|
|
|
+ String url = evaluationConfiguration.getBackEndUrl() + "jobProgress";
|
|
|
+ log.info("getTriggerResponse开始...");
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ ResponseEntity<JSONObject> response = getTriggerResponse(url, examId);
|
|
|
+ log.info("用时:[{}]ms.", System.currentTimeMillis() - start);
|
|
|
+ log.info(String.valueOf(response.getBody()));
|
|
|
+ if (response.getBody().getInteger("code") == 200) {
|
|
|
+ return new ResponseVO<>(ServerCode.SUCCESS, "触发考试评估");
|
|
|
+ } else {
|
|
|
+ return new ResponseVO<>(500, "触发考试失败,请稍后重试", null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = UrlConstants.API + "/evaluation/getProgress/{examId}", method = RequestMethod.GET)
|
|
|
+ public ResponseVO<JSONObject> checkEvaluationProgress(@PathVariable("examId") long examId) {
|
|
|
+ if (examLogic.getExamById(examId) == null) {
|
|
|
+ return new ResponseVO<>(500, "无当前考试记录", null);
|
|
|
+ }
|
|
|
+ RestTemplate rt = new RestTemplate();
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ json.put("examId", examId);
|
|
|
+ HttpEntity<JSONObject> httpEntity = new HttpEntity<>(json, headers);
|
|
|
+ String url = evaluationConfiguration.getBackEndUrl() + "jobProgress";
|
|
|
+ log.info("方法开始...");
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ ResponseEntity<JSONObject> response = rt.exchange(url, HttpMethod.POST, httpEntity, JSONObject.class);
|
|
|
+ log.info("用时:[{}]ms.", System.currentTimeMillis() - start);
|
|
|
+ log.info(String.valueOf(response.getBody()));
|
|
|
+ if (response.getBody().getInteger("code") == 200) {
|
|
|
+ return new ResponseVO<>(ServerCode.SUCCESS, response.getBody().getJSONObject("data"));
|
|
|
+ } else {
|
|
|
+ return new ResponseVO<>(500, "获取评估进度失败", null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = UrlConstants.API + "/evaluation/retry/{examId}", method = RequestMethod.POST)
|
|
|
+ public ResponseVO<String> retryEvaluation(@PathVariable("examId") long examId) {
|
|
|
+ if (examLogic.getExamById(examId) == null) {
|
|
|
+ return new ResponseVO<>(500, "无当前考试记录", null);
|
|
|
+ }
|
|
|
+ String url = evaluationConfiguration.getBackEndUrl() + "retryJob";
|
|
|
+ ResponseEntity<JSONObject> response = getTriggerResponse(url, examId);
|
|
|
+ log.info(String.valueOf(response.getBody()));
|
|
|
+ if (response.getBody().getInteger("code") == 200) {
|
|
|
+ return new ResponseVO<>(ServerCode.SUCCESS, "重试触发考试评估");
|
|
|
+ } else {
|
|
|
+ return new ResponseVO<>(500, "重试触发考试失败,请稍后重试", null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private ResponseEntity<JSONObject> getTriggerResponse(String requestUrl, Long examId) {
|
|
|
+ String fileName = "exam_result.json";
|
|
|
+ log.info("generateExamData方法开始...");
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ InputStream inputStream = userEvaluationLogic.generateExamData(fileName, examId);
|
|
|
+ log.info("generateExamData方法用时:[{}]ms.", System.currentTimeMillis() - start);
|
|
|
+ String uploadUrl = "evaluation/exam_" + examId + ".json";
|
|
|
+ String ossUrl = ossLogic.uploadByUrl(uploadUrl, inputStream);
|
|
|
+ log.info("ossUrl: " + ossUrl);
|
|
|
+ // 删除本地json文件
|
|
|
+ File tmpFile = new File(fileName);
|
|
|
+ if (tmpFile.exists()) {
|
|
|
+ tmpFile.delete();
|
|
|
+ }
|
|
|
+ RestTemplate rt = new RestTemplate();
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ json.put("examId", examId);
|
|
|
+ json.put("ossUrl", ossUrl);
|
|
|
+ HttpEntity<JSONObject> httpEntity = new HttpEntity<>(json, headers);
|
|
|
+ return rt.exchange(requestUrl, HttpMethod.POST, httpEntity, JSONObject.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = UrlConstants.API + "/evaluation/getRadarUrl", method = RequestMethod.GET)
|
|
|
+ public ResponseVO<String> getRadarUrl() {
|
|
|
+ String url = evaluationConfiguration.getFrontEndUrl() + evaluationConfiguration.getRadarUrl();
|
|
|
+ return new ResponseVO<>(ServerCode.SUCCESS, url);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = UrlConstants.API + "/evaluation/checkPermission/{examId}", method = RequestMethod.GET)
|
|
|
+ public ResponseVO<Boolean> checkEvaluationPermission(@PathVariable("examId") long examId) {
|
|
|
+ if (examLogic.getExamById(examId) == null) {
|
|
|
+ return new ResponseVO<>(500, "无当前考试记录", false);
|
|
|
+ }
|
|
|
+ boolean res = userEvaluationLogic.checkEvaluationPermission(examId);
|
|
|
+ return new ResponseVO<>(ServerCode.SUCCESS, res);
|
|
|
+ }
|
|
|
}
|