|
@@ -13,7 +13,6 @@ import cn.com.qmth.examcloud.app.utils.DateUtils;
|
|
|
import cn.com.qmth.examcloud.app.utils.HttpUtils;
|
|
|
import okhttp3.MediaType;
|
|
|
import okhttp3.MultipartBody;
|
|
|
-import okhttp3.Request;
|
|
|
import okhttp3.RequestBody;
|
|
|
import org.apache.commons.io.FilenameUtils;
|
|
|
import org.slf4j.Logger;
|
|
@@ -22,7 +21,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.Assert;
|
|
|
|
|
|
-import static cn.com.qmth.examcloud.app.model.Constants.*;
|
|
|
+import static cn.com.qmth.examcloud.app.model.Constants.TYPE_PDF;
|
|
|
+import static cn.com.qmth.examcloud.app.model.Constants.TYPE_ZIP;
|
|
|
|
|
|
/**
|
|
|
* 网考业务服务接口
|
|
@@ -34,16 +34,9 @@ public class NetExamService {
|
|
|
private PropertyService propertyService;
|
|
|
|
|
|
public Result getCurrentTime(String key, String token) throws Exception {
|
|
|
- final String requestUrl = propertyService.getNetExamUrl() + "/api/online_exam_course/currentTime";
|
|
|
//封装请求参数
|
|
|
- Request request = new Request.Builder()
|
|
|
- .url(requestUrl)
|
|
|
- .get()
|
|
|
- .addHeader(PARAM_KEY, key)
|
|
|
- .addHeader(PARAM_TOKEN, token)
|
|
|
- .build();
|
|
|
- //执行请求
|
|
|
- Result<String> result = HttpUtils.call(request);
|
|
|
+ final String requestUrl = propertyService.getNetExamUrl() + "/api/online_exam_course/currentTime";
|
|
|
+ Result<String> result = HttpUtils.doGet(requestUrl, key, token);
|
|
|
if (result.isSuccess()) {
|
|
|
//转换日期格式
|
|
|
result.setData(DateUtils.format(result.getData()));
|
|
@@ -52,29 +45,15 @@ public class NetExamService {
|
|
|
}
|
|
|
|
|
|
public Result getOfflineExamCourseList(String key, String token) throws Exception {
|
|
|
- final String requestUrl = propertyService.getNetExamUrl() + "/api/offline_exam/getOfflineCourse";
|
|
|
//封装请求参数
|
|
|
- Request request = new Request.Builder()
|
|
|
- .url(requestUrl)
|
|
|
- .get()
|
|
|
- .addHeader(PARAM_KEY, key)
|
|
|
- .addHeader(PARAM_TOKEN, token)
|
|
|
- .build();
|
|
|
- //执行请求
|
|
|
- return HttpUtils.call(request);
|
|
|
+ final String requestUrl = propertyService.getNetExamUrl() + "/api/offline_exam/getOfflineCourse";
|
|
|
+ return HttpUtils.doGet(requestUrl, key, token);
|
|
|
}
|
|
|
|
|
|
public Result startOfflineExamRecord(String key, String token, String examStudentId) throws Exception {
|
|
|
- final String requestUrl = String.format(propertyService.getNetExamUrl() + "/api/offline_exam/start?examStudentId=%s", examStudentId);
|
|
|
//封装请求参数
|
|
|
- Request request = new Request.Builder()
|
|
|
- .url(requestUrl)
|
|
|
- .get()
|
|
|
- .addHeader(PARAM_KEY, key)
|
|
|
- .addHeader(PARAM_TOKEN, token)
|
|
|
- .build();
|
|
|
- //执行请求
|
|
|
- return HttpUtils.call(request);
|
|
|
+ final String requestUrl = String.format(propertyService.getNetExamUrl() + "/api/offline_exam/start?examStudentId=%s", examStudentId);
|
|
|
+ return HttpUtils.doGet(requestUrl, key, token);
|
|
|
}
|
|
|
|
|
|
public Result uploadPaperAnswer(String key, String token, String examRecordId, byte[] fileBytes, String fileName, String md5) throws Exception {
|
|
@@ -87,59 +66,32 @@ public class NetExamService {
|
|
|
if (fileBytes.length == 0) {
|
|
|
throw new ApiException("File must be not empty.");
|
|
|
}
|
|
|
+ //封装请求参数
|
|
|
final String requestUrl = String.format(propertyService.getNetExamUrl() + "/api/offline_exam/%s/submit", examRecordId);
|
|
|
- MultipartBody.Builder formBody = new MultipartBody.Builder().setType(MultipartBody.FORM);
|
|
|
+ MultipartBody.Builder form = new MultipartBody.Builder().setType(MultipartBody.FORM);
|
|
|
RequestBody body = RequestBody.create(MediaType.parse("application/octet-stream"), fileBytes);
|
|
|
- formBody.addFormDataPart("file", fileName, body);
|
|
|
- formBody.addFormDataPart("fileType", fileType);
|
|
|
- formBody.addFormDataPart("md5", md5);
|
|
|
- Request request = new Request.Builder()
|
|
|
- .url(requestUrl)
|
|
|
- .post(formBody.build())
|
|
|
- .addHeader(PARAM_KEY, key)
|
|
|
- .addHeader(PARAM_TOKEN, token)
|
|
|
- .build();
|
|
|
- //执行请求
|
|
|
- return HttpUtils.call(request);
|
|
|
+ form.addFormDataPart("file", fileName, body);
|
|
|
+ form.addFormDataPart("fileType", fileType);
|
|
|
+ form.addFormDataPart("md5", md5);
|
|
|
+ return HttpUtils.doPost(requestUrl, form.build(), key, token);
|
|
|
}
|
|
|
|
|
|
public Result getPracticeExamCourseList(String key, String token, String examId) throws Exception {
|
|
|
- final String requestUrl = String.format(propertyService.getNetExamUrl() + "/api/practice_course?examId=%s", examId);
|
|
|
//封装请求参数
|
|
|
- Request request = new Request.Builder()
|
|
|
- .url(requestUrl)
|
|
|
- .get()
|
|
|
- .addHeader(PARAM_KEY, key)
|
|
|
- .addHeader(PARAM_TOKEN, token)
|
|
|
- .build();
|
|
|
- //执行请求
|
|
|
- return HttpUtils.call(request);
|
|
|
+ final String requestUrl = String.format(propertyService.getNetExamUrl() + "/api/practice_course?examId=%s", examId);
|
|
|
+ return HttpUtils.doGet(requestUrl, key, token);
|
|
|
}
|
|
|
|
|
|
public Result getExamRecordHeartbeat(String key, String token, String examRecordId) throws Exception {
|
|
|
- final String requestUrl = String.format(propertyService.getNetExamUrl() + "/api/exam_control/heartbeat?examRecordId=%s", examRecordId);
|
|
|
//封装请求参数
|
|
|
- Request request = new Request.Builder()
|
|
|
- .url(requestUrl)
|
|
|
- .get()
|
|
|
- .addHeader(PARAM_KEY, key)
|
|
|
- .addHeader(PARAM_TOKEN, token)
|
|
|
- .build();
|
|
|
- //执行请求
|
|
|
- return HttpUtils.call(request);
|
|
|
+ final String requestUrl = String.format(propertyService.getNetExamUrl() + "/api/exam_control/heartbeat?examRecordId=%s", examRecordId);
|
|
|
+ return HttpUtils.doGet(requestUrl, key, token);
|
|
|
}
|
|
|
|
|
|
public Result startPracticeExamRecord(String key, String token, String examStudentId) throws Exception {
|
|
|
- final String requestUrl = String.format(propertyService.getNetExamUrl() + "/api/exam_control/start?stu_exam_info_id=%s", examStudentId);
|
|
|
//封装请求参数
|
|
|
- Request request = new Request.Builder()
|
|
|
- .url(requestUrl)
|
|
|
- .get()
|
|
|
- .addHeader(PARAM_KEY, key)
|
|
|
- .addHeader(PARAM_TOKEN, token)
|
|
|
- .build();
|
|
|
- //执行请求
|
|
|
- return HttpUtils.call(request);
|
|
|
+ final String requestUrl = String.format(propertyService.getNetExamUrl() + "/api/exam_control/start?stu_exam_info_id=%s", examStudentId);
|
|
|
+ return HttpUtils.doGet(requestUrl, key, token);
|
|
|
}
|
|
|
|
|
|
public Result getExamRecordPaperStructList(String key, String token, String examRecordId) throws Exception {
|