Browse Source

修复多媒体接口问题

ting.yin 4 years ago
parent
commit
0c178f882e

+ 2 - 0
stmms-web/src/main/java/cn/com/qmth/stmms/admin/thread/DataSyncThread.java

@@ -239,10 +239,12 @@ public class DataSyncThread implements Runnable {
         subject.setCode(subjectCode);
         subject.setName(subjectName);
         subject.setPaperFileType(FormatType.JSON);
+        subject.setAnswerFileType(FormatType.JSON);
         subject.setObjectiveScore(0d);
         subject.setSubjectiveScore(0d);
         subject.setTotalScore(0d);
         subject.setUploadCount(0);
+        subjectService.save(subject);
     }
 
 }

+ 30 - 11
stmms-web/src/main/java/cn/com/qmth/stmms/admin/utils/HttpUtil.java

@@ -1,12 +1,17 @@
 package cn.com.qmth.stmms.admin.utils;
 
 import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.net.HttpURLConnection;
 import java.net.URL;
+import java.nio.charset.StandardCharsets;
 import java.security.cert.CertificateException;
 import java.security.cert.X509Certificate;
 import java.util.Map;
@@ -19,6 +24,8 @@ import javax.net.ssl.X509TrustManager;
 
 import net.sf.json.JSONObject;
 
+import org.apache.commons.io.IOUtils;
+
 public class HttpUtil {
 
     // private static Logger log = LoggerFactory.getLogger(HttpUtil.class);
@@ -139,6 +146,9 @@ public class HttpUtil {
             }
 
             result = getResult(conn);
+            JSONObject message = JSONObject.fromObject(result);
+            message.accumulate("code", "");
+            result = message.toString();
         } catch (Exception e) {
             // 操作失败
             // log.error("Http connection error!", e);
@@ -220,16 +230,27 @@ public class HttpUtil {
         return text.toString();
     }
 
-    public static void main(String[] args) {
+    public static void main(String[] args) throws IOException {
         JSONObject json = new JSONObject();
-        json.accumulate("examId", 5);
+        json.accumulate("examId", 240);
+        json.accumulate("subjectCode", "CJFX17");
         String test = "https://ecs-test.ea100.com.cn/api/exchange/outer/question/getSubjectivePaperStruct";
-        String dev = "https://dev.ea100.com.cn/api/exchange/outer/question/getSubjectivePaperStruct";
-        HttpUtil subjectHttp = new HttpUtil(dev, "123456", "11", "0");
+        // String dev =
+        // "https://dev.ea100.com.cn/api/exchange/outer/question/getSubjectivePaperStruct";
+        long start = System.currentTimeMillis();
+        HttpUtil subjectHttp = new HttpUtil(test, "123456", "11", "17128");
         String subjectJson = subjectHttp.httpAction(null, json.toString());
         System.out.println(subjectJson);
-
-        // json.accumulate("subjectCode", "ldyCos001");
+        // ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+        // IOUtils.copy(new
+        // ByteArrayInputStream(subjectJson.getBytes(StandardCharsets.UTF_8)),
+        // buffer);
+        // byte[] data = buffer.toByteArray();
+        // File target = new File("/Users/ting.yin/Desktop/test123.json");
+        // target.getParentFile().mkdirs();
+        // FileOutputStream ous = new FileOutputStream(target);
+        // ous.write(data);
+        // IOUtils.closeQuietly(ous);
         // HttpUtil subjectHttp = new HttpUtil(
         // "http://iepcc-ps.ecs.qmth.com.cn:80/api/exchange/outer/question/getSubjectivePaperStruct",
         // "Fu234234CK!fsd9f0", "EPCC", "16923");
@@ -237,19 +258,17 @@ public class HttpUtil {
         // System.out.println(subjectJson);
 
         // HttpUtil paperHttp = new
-        // HttpUtil("http://192.168.10.39:8007/api/exchange/outer/question/getSubjectivePaper",
-        // "123456", "11", "0");
+        // HttpUtil();
         // String paper = paperHttp.httpAction(null, json.toString());
         // System.out.println(paper);
 
-        // long start = System.currentTimeMillis();
         // HttpUtil studentHttp = new HttpUtil(
         // "https://192.168.10.39:8007/api/exchange/outer/question/getSubjectiveQuestion",
         // "123456", "11", "0");
         // json.accumulate("startId", 0);
         // json.accumulate("size", 10);
         // String studentJson = studentHttp.httpAction(null, json.toString());
-        // long end = System.currentTimeMillis();
-        // System.out.println(end - start + ":" + studentJson);
+        long end = System.currentTimeMillis();
+        System.out.println(end - start);
     }
 }

+ 3 - 0
stmms-web/src/main/java/cn/com/qmth/stmms/api/controller/CoreController.java

@@ -259,6 +259,9 @@ public class CoreController extends BaseApiController {
         if (examCode != null) {
             exam = examService.findBySchoolAndCode(user.getSchoolId(), examCode);
         }
+        if (exam == null) {
+            throw ApiException.QUERY_PARAM_ERROR.replaceMessage("exam unexists");
+        }
         if (!exam.getSchoolId().equals(user.getSchoolId())) {
             throw ApiException.EXAM_NOT_ACCESSIBLED;
         }