|
@@ -1,185 +1,59 @@
|
|
|
/*
|
|
|
* *************************************************
|
|
|
* Copyright (c) 2018 QMTH. All Rights Reserved.
|
|
|
- * Created by Deason on 2018-07-16 17:49:59.
|
|
|
+ * Created by Deason on 2018-07-31 17:31:34.
|
|
|
* *************************************************
|
|
|
*/
|
|
|
|
|
|
package cn.com.qmth.examcloud.app.service;
|
|
|
|
|
|
-import cn.com.qmth.examcloud.app.core.exception.ApiException;
|
|
|
-import cn.com.qmth.examcloud.app.core.utils.DateUtils;
|
|
|
-import cn.com.qmth.examcloud.app.core.utils.HttpUtils;
|
|
|
-import cn.com.qmth.examcloud.app.core.utils.JsonMapper;
|
|
|
-import cn.com.qmth.examcloud.app.model.Constants;
|
|
|
import cn.com.qmth.examcloud.app.model.Result;
|
|
|
-import okhttp3.FormBody;
|
|
|
-import okhttp3.MediaType;
|
|
|
-import okhttp3.MultipartBody;
|
|
|
-import okhttp3.RequestBody;
|
|
|
-import org.apache.commons.io.FilenameUtils;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-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.FILE_TYPE_PDF;
|
|
|
-import static cn.com.qmth.examcloud.app.model.Constants.FILE_TYPE_ZIP;
|
|
|
|
|
|
/**
|
|
|
* 网考业务服务接口
|
|
|
+ *
|
|
|
+ * @author: fengdesheng
|
|
|
+ * @since: 2018/7/31
|
|
|
*/
|
|
|
-@Service
|
|
|
-public class NetExamService {
|
|
|
- private static Logger log = LoggerFactory.getLogger(NetExamService.class);
|
|
|
- @Autowired
|
|
|
- private PropertyService propertyService;
|
|
|
-
|
|
|
- public Result getCurrentTime(String key, String token) throws Exception {
|
|
|
- //封装请求参数
|
|
|
- final String requestUrl = String.format("%s/api/online_exam_course/currentTime", propertyService.getNetExamUrl());
|
|
|
- Result<String> result = HttpUtils.doGet(requestUrl, key, token);
|
|
|
- if (result.isSuccess()) {
|
|
|
- //转换日期格式
|
|
|
- result.setData(DateUtils.formatLongDate(result.getData()));
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
- public Result getOfflineExamCourseList(String key, String token) throws Exception {
|
|
|
- //封装请求参数
|
|
|
- final String requestUrl = String.format("%s/api/offline_exam/getOfflineCourse", propertyService.getNetExamUrl());
|
|
|
- return HttpUtils.doGet(requestUrl, key, token);
|
|
|
- }
|
|
|
-
|
|
|
- public Result startOfflineExamRecord(String key, String token, String examStudentId) throws Exception {
|
|
|
- //封装请求参数
|
|
|
- final String requestUrl = String.format("%s/api/offline_exam/start?examStudentId=%s", propertyService.getNetExamUrl(), examStudentId);
|
|
|
- return HttpUtils.doGet(requestUrl, key, token);
|
|
|
- }
|
|
|
-
|
|
|
- public Result uploadPaperAnswer(String key, String token, String examRecordId, byte[] fileBytes, String fileName, String md5) throws Exception {
|
|
|
- Assert.notNull(examRecordId, "FileName must not be null.");
|
|
|
- Assert.notNull(fileName, "ExamRecordId must not be null.");
|
|
|
- String fileType = FilenameUtils.getExtension(fileName.toLowerCase());
|
|
|
- if (!FILE_TYPE_ZIP.equals(fileType) && !FILE_TYPE_PDF.equals(fileType)) {
|
|
|
- throw new ApiException("FileType must be zip or pdf.");
|
|
|
- }
|
|
|
- if (fileBytes.length == 0) {
|
|
|
- throw new ApiException("File must be not empty.");
|
|
|
- }
|
|
|
- //封装请求参数
|
|
|
- final String requestUrl = String.format("%s/api/offline_exam/%s/submit", propertyService.getNetExamUrl(), examRecordId);
|
|
|
- MultipartBody.Builder form = new MultipartBody.Builder().setType(MultipartBody.FORM);
|
|
|
- RequestBody body = RequestBody.create(MediaType.parse("application/octet-stream"), fileBytes);
|
|
|
- form.addFormDataPart("file", fileName, body);
|
|
|
- form.addFormDataPart("fileType", fileType);
|
|
|
- form.addFormDataPart("md5", md5 != null ? 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("%s/api/practice_course?examId=%s", propertyService.getNetExamUrl(), examId);
|
|
|
- return HttpUtils.doGet(requestUrl, key, token);
|
|
|
- }
|
|
|
-
|
|
|
- public Result getExamRecordHeartbeat(String key, String token, String examRecordId) throws Exception {
|
|
|
- //封装请求参数
|
|
|
- final String requestUrl = String.format("%s/api/exam_control/heartbeat?examRecordId=%s", propertyService.getNetExamUrl(), examRecordId);
|
|
|
- return HttpUtils.doGet(requestUrl, key, token);
|
|
|
- }
|
|
|
-
|
|
|
- public Result startPracticeExamRecord(String key, String token, String examStudentId) throws Exception {
|
|
|
- //封装请求参数
|
|
|
- final String requestUrl = String.format("%s/api/exam_control/start?stu_exam_info_id=%s", propertyService.getNetExamUrl(), examStudentId);
|
|
|
- return HttpUtils.doGet(requestUrl, key, token);
|
|
|
- }
|
|
|
-
|
|
|
- public Result getExamRecordPaperStructList(String key, String token, String examRecordId) throws Exception {
|
|
|
- //封装请求参数
|
|
|
- final String requestUrl = String.format("%s/api/exam_question/paper_struct?exam_record_id=%s", propertyService.getNetExamUrl(), examRecordId);
|
|
|
- return HttpUtils.doGet(requestUrl, key, token);
|
|
|
- }
|
|
|
-
|
|
|
- public Result getExamRecordPaperQuestionList(String key, String token, String examRecordId) throws Exception {
|
|
|
- //封装请求参数
|
|
|
- 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 {
|
|
|
- //封装请求参数
|
|
|
- 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 {
|
|
|
- //封装请求参数
|
|
|
- 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 {
|
|
|
- //封装请求参数
|
|
|
- final String requestUrl = String.format("%s/api/exam_control/submit?examRecordId=%s", propertyService.getNetExamUrl(), examRecordId);
|
|
|
- return HttpUtils.doGet(requestUrl, key, token);
|
|
|
- }
|
|
|
-
|
|
|
- public Result checkOnlineExamRecord(String key, String token) throws Exception {
|
|
|
- //封装请求参数
|
|
|
- final String requestUrl = String.format("%s/api/exam_record/checkExam", propertyService.getNetExamUrl());
|
|
|
- return HttpUtils.doGet(requestUrl, key, token);
|
|
|
- }
|
|
|
+public interface NetExamService {
|
|
|
+
|
|
|
+ Result getCurrentTime(String key, String token) throws Exception;
|
|
|
+
|
|
|
+ Result getOfflineExamCourseList(String key, String token) throws Exception;
|
|
|
+
|
|
|
+ Result startOfflineExamRecord(String key, String token, String examStudentId) throws Exception;
|
|
|
+
|
|
|
+ Result uploadPaperAnswer(String key, String token, String examRecordId, byte[] fileBytes, String fileName, String md5) throws Exception;
|
|
|
+
|
|
|
+ Result getPracticeExamCourseList(String key, String token, String examId) throws Exception;
|
|
|
+
|
|
|
+ Result getExamRecordHeartbeat(String key, String token, String examRecordId) throws Exception;
|
|
|
+
|
|
|
+ Result startPracticeExamRecord(String key, String token, String examStudentId) throws Exception;
|
|
|
+
|
|
|
+ Result getExamRecordPaperStructList(String key, String token, String examRecordId) throws Exception;
|
|
|
+
|
|
|
+ Result getExamRecordPaperQuestionList(String key, String token, String examRecordId) throws Exception;
|
|
|
+
|
|
|
+ Result getExamRecordPaperQuestionDetail(String key, String token, String questionId) throws Exception;
|
|
|
+
|
|
|
+ Result updateExamRecordPaperQuestionAnswer(String key, String token, String examQuestionId, String studentAnswer) throws Exception;
|
|
|
+
|
|
|
+ Result submitPracticeExamRecord(String key, String token, String examRecordId) throws Exception;
|
|
|
+
|
|
|
+ Result checkOnlineExamRecord(String key, String token) throws Exception;
|
|
|
|
|
|
@Deprecated
|
|
|
- public Result getExamRecordPracticeTotalInfo(String key, String token, String examStudentId) throws Exception {
|
|
|
- //封装请求参数
|
|
|
- final String requestUrl = String.format("%s/api/practice_course/%s", propertyService.getNetExamUrl(), examStudentId);
|
|
|
- return HttpUtils.doGet(requestUrl, key, token);
|
|
|
- }
|
|
|
-
|
|
|
- public Result getExamRecordPracticeHistoryList(String key, String token, String examStudentId) throws Exception {
|
|
|
- //封装请求参数
|
|
|
- final String requestUrl = String.format("%s/api/practice_record?examStudentId=%s", propertyService.getNetExamUrl(), examStudentId);
|
|
|
- return HttpUtils.doGet(requestUrl, key, token);
|
|
|
- }
|
|
|
-
|
|
|
- public Result getExamRecordTotalInfo(String key, String token, String examRecordId) throws Exception {
|
|
|
- //封装请求参数
|
|
|
- final String requestUrl = String.format("%s/api/practice_detail?examRecordId=%s", propertyService.getNetExamUrl(), examRecordId);
|
|
|
- return HttpUtils.doGet(requestUrl, key, token);
|
|
|
- }
|
|
|
-
|
|
|
- public Result getExamRecordQuestionDetailList(String key, String token, String examRecordId) throws Exception {
|
|
|
- //封装请求参数
|
|
|
- final String requestUrl = String.format("%s/api/ecs_oe/report/exam_detail_report/paper_question?exam_record_id=%s", propertyService.getNetExamUrl(), examRecordId);
|
|
|
- return HttpUtils.doGet(requestUrl, key, token);
|
|
|
- }
|
|
|
-
|
|
|
- public Result getExamRecordQuestionAudioPlayTimes(String key, String token, String questionId) throws Exception {
|
|
|
- //封装请求参数
|
|
|
- final String requestUrl = String.format("%s/api/exam_question_playtimes?questionId=%s", propertyService.getNetExamUrl(), questionId);
|
|
|
- return HttpUtils.doGet(requestUrl, key, token);
|
|
|
- }
|
|
|
-
|
|
|
- public Result updateExamRecordQuestionAudioPlayTimes(String key, String token, String questionId, String mediaName) throws Exception {
|
|
|
- //封装请求参数
|
|
|
- final String requestUrl = String.format("%s/api/exam_question_playtimes", propertyService.getNetExamUrl());
|
|
|
- RequestBody formBody = new FormBody.Builder()
|
|
|
- .add("questionId", questionId)
|
|
|
- .add("mediaName", mediaName)
|
|
|
- .build();
|
|
|
- return HttpUtils.doPost(requestUrl, formBody, key, token);
|
|
|
- }
|
|
|
+ Result getExamRecordPracticeTotalInfo(String key, String token, String examStudentId) throws Exception;
|
|
|
+
|
|
|
+ Result getExamRecordPracticeHistoryList(String key, String token, String examStudentId) throws Exception;
|
|
|
+
|
|
|
+ Result getExamRecordTotalInfo(String key, String token, String examRecordId) throws Exception;
|
|
|
+
|
|
|
+ Result getExamRecordQuestionDetailList(String key, String token, String examRecordId) throws Exception;
|
|
|
+
|
|
|
+ Result getExamRecordQuestionAudioPlayTimes(String key, String token, String questionId) throws Exception;
|
|
|
+
|
|
|
+ Result updateExamRecordQuestionAudioPlayTimes(String key, String token, String questionId, String mediaName) throws Exception;
|
|
|
|
|
|
}
|