瀏覽代碼

3.2.3 增加云阅卷机构同步

xiaofei 2 年之前
父節點
當前提交
a445ddae17

+ 1 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/contant/SystemConstant.java

@@ -79,6 +79,7 @@ public class SystemConstant {
     /**
      * 云阅卷api
      */
+    public static final String CLOUD_MARK_SCHOOL_SAVE_API = "/api/school/save";
     public static final String CLOUD_MARK_EXAM_SAVE_API = "/api/exam/save";
     public static final String CLOUD_MARK_EXAM_LIST_API = "/api/exams";
     public static final String CLOUD_MARK_EXAM_STUDENT_SAVE_API = "/api/exam/student/save";

+ 29 - 0
teachcloud-common/src/main/java/com/qmth/teachcloud/common/sync/CloudMarkingTaskUtils.java

@@ -60,6 +60,35 @@ public class CloudMarkingTaskUtils {
     @Resource
     private DictionaryConfig dictionaryConfig;
 
+    /**
+     * 考试创建/更新接口
+     *
+     * @param code     唯一标识
+     * @param name     考试名称
+     * @param examTime 考试时间
+     * @return 考试ID
+     */
+    public Long syncSchool(Long schoolId, String code, String name, String examTime) {
+        SysConfig sysConfig = commonCacheService.addSysConfigCache(schoolId, SystemConstant.CLOUDMARK_HOST_URL);
+        Optional.ofNullable(sysConfig).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未配置云阅卷地址"));
+        String hostUrl = sysConfig.getConfigValue();
+        String examSaveUrl = SystemConstant.CLOUD_MARK_SCHOOL_SAVE_API;
+        validUrl(hostUrl, examSaveUrl);
+        String postUrl = hostUrl.concat(examSaveUrl);
+        //参数
+        Map<String, Object> map = new HashMap<>();
+        map.put("code", validParam(code, null, true, "唯一标识"));
+        map.put("name", validParam(name, null, true, "显示名称"));
+
+        String result = HttpKit.sendPost(postUrl, getHeaders(schoolId, examSaveUrl), map, null, null, null);
+        JSONObject jsonObject = JSONObject.parseObject(result);
+        if (jsonObject.containsKey("id")) {
+            return Long.valueOf(jsonObject.get("id").toString());
+        } else {
+            throw ExceptionResultEnum.ERROR.exception("学校(机构)同步失败");
+        }
+    }
+
     /**
      * 考试创建/更新接口
      *