|
@@ -1,6 +1,8 @@
|
|
package com.qmth.teachcloud.common.sync;
|
|
package com.qmth.teachcloud.common.sync;
|
|
|
|
|
|
|
|
+import cn.hutool.http.HttpStatus;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.qmth.boot.api.exception.ApiException;
|
|
import com.qmth.boot.tools.signature.SignatureType;
|
|
import com.qmth.boot.tools.signature.SignatureType;
|
|
import com.qmth.teachcloud.common.SignatureEntityTest;
|
|
import com.qmth.teachcloud.common.SignatureEntityTest;
|
|
import com.qmth.teachcloud.common.config.DictionaryConfig;
|
|
import com.qmth.teachcloud.common.config.DictionaryConfig;
|
|
@@ -9,6 +11,9 @@ import com.qmth.teachcloud.common.entity.BasicSchool;
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
import com.qmth.teachcloud.common.service.CommonCacheService;
|
|
import com.qmth.teachcloud.common.service.CommonCacheService;
|
|
import com.qmth.teachcloud.common.util.HttpKit;
|
|
import com.qmth.teachcloud.common.util.HttpKit;
|
|
|
|
+import com.qmth.teachcloud.common.util.HttpUtil;
|
|
|
|
+import com.qmth.teachcloud.common.util.JacksonUtil;
|
|
|
|
+import com.qmth.teachcloud.common.util.ResultUtil;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -16,6 +21,7 @@ import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
|
|
|
|
@@ -140,6 +146,42 @@ public class TeachCloudReportTaskUtils {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @param schoolId 学校ID
|
|
|
|
+ * @param examId 考试ID
|
|
|
|
+ * @param courseCodes 分析试卷的唯一标识
|
|
|
|
+ */
|
|
|
|
+ public boolean startCalc(Long schoolId, Long examId, List<String> courseCodes) {
|
|
|
|
+ String hostUrl = dictionaryConfig.reportOpenDomain().getHostUrl();
|
|
|
|
+ String saveUrl = dictionaryConfig.reportOpenDomain().getCalculateApi();
|
|
|
|
+ validUrl(hostUrl, saveUrl);
|
|
|
|
+ String postUrl = hostUrl.concat(saveUrl);
|
|
|
|
+ long timestamp = System.currentTimeMillis();
|
|
|
|
+ try {
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
+ map.computeIfAbsent("examId", v -> examId);
|
|
|
|
+ map.computeIfAbsent("courseCode", v -> courseCodes);//试卷编号+卷型
|
|
|
|
+ String accessToken = createSign(schoolId, timestamp, saveUrl);
|
|
|
|
+ String result = HttpUtil.postJson(postUrl, JacksonUtil.parseJson(map), accessToken, timestamp);
|
|
|
|
+ if (Objects.nonNull(result)) {
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
|
+ if (Objects.nonNull(jsonObject.get("code")) && jsonObject.getIntValue("code") != HttpStatus.HTTP_OK) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(jsonObject.getString("error"));
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error(SystemConstant.LOG_ERROR, e);
|
|
|
|
+ if (e instanceof ApiException) {
|
|
|
|
+ ResultUtil.error((ApiException) e, e.getMessage());
|
|
|
|
+ } else {
|
|
|
|
+ ResultUtil.error(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
/**
|
|
/**
|
|
* http请求头
|
|
* http请求头
|