deason 7 anni fa
parent
commit
4292fc6333

+ 2 - 2
src/main/java/cn/com/qmth/examcloud/app/controller/v1/PracticeExamRestController.java

@@ -70,7 +70,7 @@ public class PracticeExamRestController {
     @ApiOperation(value = "获取当前练习的试卷试题列表接口")
     @RequestMapping(value = "/exam/record/paper/question/list", method = {RequestMethod.GET, RequestMethod.POST})
     public Result getExamRecordPaperQuestionList(@RequestHeader String key, @RequestHeader String token, @RequestParam String examRecordId) throws Exception {
-        return netExamService.getExamRecordPaperQuestionList(key, token, examRecordId);//todo
+        return netExamService.getExamRecordPaperQuestionList(key, token, examRecordId);
     }
 
     @ApiOperation(value = "获取考生作答的某个试题的详细信息接口")
@@ -89,7 +89,7 @@ public class PracticeExamRestController {
     @ApiOperation(value = "当前练习的交卷接口")
     @RequestMapping(value = "/exam/record/submit", method = {RequestMethod.GET, RequestMethod.POST})
     public Result submitPracticeExamRecord(@RequestHeader String key, @RequestHeader String token, @RequestParam String examRecordId) throws Exception {
-        return netExamService.submitPracticeExamRecord(key, token, examRecordId);
+        return netExamService.submitPracticeExamRecord(key, token, examRecordId);//todo
     }
 
     @ApiOperation(value = "检查考生当前是否有正在进行的练习记录接口")

+ 20 - 3
src/main/java/cn/com/qmth/examcloud/app/service/NetExamService.java

@@ -8,9 +8,12 @@
 package cn.com.qmth.examcloud.app.service;
 
 import cn.com.qmth.examcloud.app.exception.ApiException;
+import cn.com.qmth.examcloud.app.model.Constants;
 import cn.com.qmth.examcloud.app.model.Result;
 import cn.com.qmth.examcloud.app.utils.DateUtils;
 import cn.com.qmth.examcloud.app.utils.HttpUtils;
+import cn.com.qmth.examcloud.app.utils.JsonMapper;
+import okhttp3.FormBody;
 import okhttp3.MediaType;
 import okhttp3.MultipartBody;
 import okhttp3.RequestBody;
@@ -21,6 +24,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.Assert;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import static cn.com.qmth.examcloud.app.model.Constants.TYPE_PDF;
 import static cn.com.qmth.examcloud.app.model.Constants.TYPE_ZIP;
 
@@ -101,15 +107,26 @@ public class NetExamService {
     }
 
     public Result getExamRecordPaperQuestionList(String key, String token, String examRecordId) throws Exception {
-        return null;
+        //封装请求参数
+        final String requestUrl = String.format("%s/api/exam_question?exam_record_id=%s", propertyService.getNetExamUrl(), examRecordId);
+        return HttpUtils.doGet(requestUrl, key, token);
     }
 
     public Result getExamRecordPaperQuestionDetail(String key, String token, String questionId) throws Exception {
-        return null;
+        //封装请求参数
+        final String requestUrl = String.format("%s/api/exam_question/question?question_id=%s", propertyService.getNetExamUrl(), questionId);
+        return HttpUtils.doGet(requestUrl, key, token);
     }
 
     public Result updateExamRecordPaperQuestionAnswer(String key, String token, String examQuestionId, String studentAnswer) throws Exception {
-        return null;
+        //封装请求参数
+        final String requestUrl = String.format("%s/api/exam_question/%s", propertyService.getNetExamUrl(), examQuestionId);
+        Map<String, String> params = new HashMap<>();
+        params.put("examQuestionId", examQuestionId);
+        params.put("stuAnswer", studentAnswer);
+        String json = new JsonMapper().toJson(params);
+        RequestBody formBody = FormBody.create(MediaType.parse(Constants.CHARSET_JSON_UTF8), json);
+        return HttpUtils.doPut(requestUrl, formBody, key, token);
     }
 
     public Result submitPracticeExamRecord(String key, String token, String examRecordId) throws Exception {

+ 4 - 1
src/main/java/cn/com/qmth/examcloud/app/utils/HttpUtils.java

@@ -31,6 +31,7 @@ public class HttpUtils {
                 .addHeader(PARAM_TOKEN, token)
                 .build();
         //执行请求
+        log.debug("[GET] " + requestUrl);
         return call(request);
     }
 
@@ -43,6 +44,7 @@ public class HttpUtils {
                 .addHeader(PARAM_TOKEN, token)
                 .build();
         //执行请求
+        log.debug("[POST] " + requestUrl);
         return call(request);
     }
 
@@ -55,6 +57,7 @@ public class HttpUtils {
                 .addHeader(PARAM_TOKEN, token)
                 .build();
         //执行请求
+        log.debug("[PUT] " + requestUrl);
         return call(request);
     }
 
@@ -64,7 +67,7 @@ public class HttpUtils {
         if (response.isSuccessful()) {
             return new Result().success(bodyStr);
         } else {
-            log.warn("Http response is " + bodyStr);
+            log.warn("[Response] " + bodyStr);
             ResBody body = new JsonMapper().fromJson(bodyStr, ResBody.class);
             if (body != null && body.getCode() != null) {
                 if (Constants.CODE_403.equals(body.getCode())) {