deason 7 years ago
parent
commit
bd44f8f5da

+ 53 - 0
src/main/java/cn/com/qmth/examcloud/app/controller/v1/OfflineExamController.java

@@ -0,0 +1,53 @@
+/*
+ * *************************************************
+ * Copyright (c) 2018 QMTH. All Rights Reserved.
+ * Created by Deason on 2018-07-18 15:30:38.
+ * *************************************************
+ */
+
+package cn.com.qmth.examcloud.app.controller.v1;
+
+import cn.com.qmth.examcloud.app.service.QuestionPoolService;
+import cn.com.qmth.examcloud.app.service.UpYunService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+
+/**
+ * 离线考试相关接口
+ *
+ * @Version v1.0
+ */
+@Controller
+@RequestMapping("/api/v1/exam/offline")
+@Api(tags = "离线考试相关接口")
+public class OfflineExamController {
+    private static Logger log = LoggerFactory.getLogger(OfflineExamController.class);
+    @Autowired
+    private QuestionPoolService questionPoolService;
+    @Autowired
+    private UpYunService upYunService;
+
+    @ApiOperation(value = "下载考题接口")
+    @RequestMapping(value = "/paper/download", method = {RequestMethod.GET, RequestMethod.POST})
+    public String downloadPaper(@RequestParam String paperId, @RequestParam String orgName) throws Exception {
+        String requestUrl = "redirect:" + questionPoolService.downloadPaper(paperId, orgName);
+        log.debug(requestUrl);
+        return requestUrl;
+    }
+
+    @ApiOperation(value = "下载已上传的“作答文件”接口")
+    @RequestMapping(value = "/paper/answer/download", method = {RequestMethod.GET, RequestMethod.POST})
+    public String downloadPaperAnswer(@RequestParam String filePath) throws Exception {
+        String requestUrl = "redirect:" + upYunService.downloadPaperAnswer(filePath);
+        log.debug(requestUrl);
+        return requestUrl;
+    }
+
+}

+ 3 - 15
src/main/java/cn/com/qmth/examcloud/app/controller/v1/OfflineExamRestController.java

@@ -10,9 +10,10 @@ package cn.com.qmth.examcloud.app.controller.v1;
 import cn.com.qmth.examcloud.app.model.Result;
 import cn.com.qmth.examcloud.app.service.NetExamService;
 import cn.com.qmth.examcloud.app.service.QuestionPoolService;
-import cn.com.qmth.examcloud.app.service.UpYunService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
@@ -30,12 +31,11 @@ import java.io.File;
 @RequestMapping("/api/v1/exam/offline")
 @Api(tags = "离线考试相关接口")
 public class OfflineExamRestController {
+    private static Logger log = LoggerFactory.getLogger(OfflineExamRestController.class);
     @Autowired
     private QuestionPoolService questionPoolService;
     @Autowired
     private NetExamService netExamService;
-    @Autowired
-    private UpYunService upYunService;
 
     @ApiOperation(value = "获取当前用户参加的离线课程列表接口")
     @RequestMapping(value = "/course/list", method = {RequestMethod.GET, RequestMethod.POST})
@@ -49,12 +49,6 @@ public class OfflineExamRestController {
         return netExamService.startOfflineExamRecord(key, token, examStudentId);
     }
 
-    @ApiOperation(value = "下载考题接口")
-    @RequestMapping(value = "/paper/download", method = {RequestMethod.GET, RequestMethod.POST})
-    public Result downloadPaper(@RequestHeader String key, @RequestHeader String token, @RequestParam String paperId, @RequestParam String orgName) throws Exception {
-        return questionPoolService.downloadPaper(key, token, paperId, orgName);
-    }
-
     @ApiOperation(value = "上传作答文件接口")
     @RequestMapping(value = "/paper/answer/upload", method = {RequestMethod.GET, RequestMethod.POST})
     public Result uploadPaperAnswer(@RequestHeader String key, @RequestHeader String token, @RequestParam String examRecordId, @RequestParam String fileType,
@@ -64,12 +58,6 @@ public class OfflineExamRestController {
         return netExamService.uploadPaperAnswer(key, token, examRecordId, file, fileType, fileMd5);
     }
 
-    @ApiOperation(value = "下载已上传的“作答文件”接口")
-    @RequestMapping(value = "/paper/answer/download", method = {RequestMethod.GET, RequestMethod.POST})
-    public Result downloadPaperAnswer(@RequestHeader String key, @RequestHeader String token, @RequestParam String filePath) throws Exception {
-        return upYunService.downloadPaperAnswer(key, token, filePath);
-    }
-
     @ApiOperation(value = "获取某份试卷的详细信息接口")
     @RequestMapping(value = "/paper/detail", method = {RequestMethod.GET, RequestMethod.POST})
     public Result getPaperDetail(@RequestHeader String key, @RequestHeader String token, @RequestParam String paperId) throws Exception {

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

@@ -49,11 +49,29 @@ public class NetExamService {
     }
 
     public Result getOfflineExamCourseList(String key, String token) throws Exception {
-        return null;
+        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);
     }
 
     public Result startOfflineExamRecord(String key, String token, String examStudentId) throws Exception {
-        return null;
+        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);
     }
 
     public Result uploadPaperAnswer(String key, String token, String examRecordId, File file, String fileType, String fileMd5) throws Exception {

+ 18 - 3
src/main/java/cn/com/qmth/examcloud/app/service/QuestionPoolService.java

@@ -8,11 +8,16 @@
 package cn.com.qmth.examcloud.app.service;
 
 import cn.com.qmth.examcloud.app.model.Result;
+import cn.com.qmth.examcloud.app.utils.HttpUtils;
+import okhttp3.Request;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import static cn.com.qmth.examcloud.app.model.Constants.PARAM_KEY;
+import static cn.com.qmth.examcloud.app.model.Constants.PARAM_TOKEN;
+
 /**
  * 题库业务服务接口
  */
@@ -22,12 +27,22 @@ public class QuestionPoolService {
     @Autowired
     private PropertyService propertyService;
 
-    public Result downloadPaper(String key, String token, String paperId, String orgName) throws Exception {
-        return null;
+    public String downloadPaper(String paperId, String orgName) throws Exception {
+        //封装请求参数
+        return String.format(propertyService.getQuestionPoolUrl() + "/api/ecs_ques/paper/export/%s/PAPER/%s/%s/offLine", paperId, orgName, paperId);
     }
 
     public Result getPaperDetail(String key, String token, String paperId) throws Exception {
-        return null;
+        final String requestUrl = String.format(propertyService.getQuestionPoolUrl() + "/api/ecs_ques/paper/%s", paperId);
+        //封装请求参数
+        Request request = new Request.Builder()
+                .url(requestUrl)
+                .get()
+                .addHeader(PARAM_KEY, key)
+                .addHeader(PARAM_TOKEN, token)
+                .build();
+        //执行请求
+        return HttpUtils.call(request);
     }
 
 }

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

@@ -7,7 +7,6 @@
 
 package cn.com.qmth.examcloud.app.service;
 
-import cn.com.qmth.examcloud.app.model.Result;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -22,8 +21,9 @@ public class UpYunService {
     @Autowired
     private PropertyService propertyService;
 
-    public Result downloadPaperAnswer(String key, String token, String filePath) throws Exception {
-        return null;
+    public String downloadPaperAnswer(String filePath) throws Exception {
+        //封装请求参数
+        return String.format(propertyService.getUpYunUrl() + "/%s", filePath);
     }
 
 }

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

@@ -22,7 +22,6 @@ public class HttpUtils {
         Response response = HttpBuilder.client.getInstance().newCall(request).execute();
         String bodyStr = response.body().string();
         if (response.isSuccessful()) {
-            //todo data
             return new Result().success(bodyStr);
         } else {
             log.warn("Http response is " + bodyStr);