|
@@ -1,6 +1,8 @@
|
|
|
package com.qmth.themis.business.util;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.qmth.themis.business.bean.cloudmark.*;
|
|
|
import com.qmth.themis.business.constant.SystemConstant;
|
|
|
import com.qmth.themis.business.domain.YunMarkDomain;
|
|
|
import com.qmth.themis.business.entity.TBOrg;
|
|
@@ -35,7 +37,11 @@ public class CloudMarkUtil {
|
|
|
|
|
|
@Bean
|
|
|
public YunMarkDomain yunMarkEnv(YunMarkDomain yunMarkDomain) {
|
|
|
- this.yunMarkDomain = new YunMarkDomain(yunMarkDomain.getUrl(), yunMarkDomain.getStudentScoreApi());
|
|
|
+ this.yunMarkDomain = new YunMarkDomain(yunMarkDomain.getUrl(),
|
|
|
+ yunMarkDomain.getStudentScoreApi(),
|
|
|
+ yunMarkDomain.getExamSaveApi(),
|
|
|
+ yunMarkDomain.getSubjectSaveApi(),
|
|
|
+ yunMarkDomain.getStudentSaveApi());
|
|
|
return this.yunMarkDomain;
|
|
|
}
|
|
|
|
|
@@ -43,34 +49,35 @@ public class CloudMarkUtil {
|
|
|
return yunMarkDomain;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取accessKey和accessSecret
|
|
|
+ *
|
|
|
+ * @param baseParams
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public BaseParams getAccessKeyAndAccessSecret(BaseParams baseParams) {
|
|
|
+ if (Objects.isNull(baseParams.getAccessKey()) && Objects.isNull(baseParams.getAccessSecret())) {
|
|
|
+ TBOrg tbOrg = cacheService.addOrgCache(baseParams.getOrgId());
|
|
|
+ Optional.ofNullable(tbOrg).orElseThrow(() -> new BusinessException(ExceptionResultEnum.ORG_NO));
|
|
|
+ baseParams.setAccessKey(tbOrg.getAccessKey());
|
|
|
+ baseParams.setAccessSecret(tbOrg.getAccessSecret());
|
|
|
+ }
|
|
|
+ return baseParams;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 考试成绩考生查询接口
|
|
|
*
|
|
|
- * @param orgId
|
|
|
- * @param examId
|
|
|
- * @param examCode
|
|
|
- * @param accessKey
|
|
|
- * @param accessSecret
|
|
|
+ * @param studentScoreParams
|
|
|
* @return
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
- public List<Map> callStudentScore(Long orgId, Long examId, String examCode, String accessKey, String accessSecret) throws IOException {
|
|
|
- String url = yunMarkDomain.getUrl() + yunMarkDomain.getStudentScoreApi();
|
|
|
- Map<String, Object> params = new HashMap<>();
|
|
|
- if (Objects.nonNull(examId)) {
|
|
|
- params.put("examId", examId);
|
|
|
- } else if (Objects.nonNull(examCode)) {
|
|
|
- params.put("examCode", examCode);
|
|
|
- }
|
|
|
- TBOrg tbOrg = cacheService.addOrgCache(orgId);
|
|
|
- Optional.ofNullable(tbOrg).orElseThrow(() -> new BusinessException(ExceptionResultEnum.ORG_NO));
|
|
|
+ public List<Map> callStudentScoreApi(StudentScoreParams studentScoreParams) throws IOException {
|
|
|
+ studentScoreParams.vaildParams();
|
|
|
+ this.getAccessKeyAndAccessSecret(studentScoreParams);
|
|
|
+ Map<String, Object> params = JSON.parseObject(JSON.toJSONString(studentScoreParams), Map.class);
|
|
|
|
|
|
- if (Objects.isNull(accessKey) || Objects.equals("", accessKey.trim())) {
|
|
|
- accessKey = tbOrg.getAccessKey();
|
|
|
- }
|
|
|
- if (Objects.isNull(accessSecret) || Objects.equals("", accessSecret.trim())) {
|
|
|
- accessSecret = tbOrg.getAccessSecret();
|
|
|
- }
|
|
|
+ String url = yunMarkDomain.getUrl() + yunMarkDomain.getStudentScoreApi();
|
|
|
int pageNumber = 1;
|
|
|
int pageSize = 100;
|
|
|
List<Map> students = null;
|
|
@@ -78,12 +85,13 @@ public class CloudMarkUtil {
|
|
|
params.put("pageNumber", pageNumber);
|
|
|
params.put("pageSize", pageSize);
|
|
|
Long timestamp = System.currentTimeMillis();
|
|
|
- String accessToken = SignatureInfo.build(SignatureType.SECRET, SystemConstant.METHOD, yunMarkDomain.getStudentScoreApi(), timestamp, accessKey, accessSecret);
|
|
|
+ String accessToken = SignatureInfo.build(SignatureType.SECRET, SystemConstant.METHOD, yunMarkDomain.getStudentScoreApi(), timestamp, studentScoreParams.getAccessKey(), studentScoreParams.getAccessSecret());
|
|
|
String result = HttpUtil.post(url, params, accessToken, timestamp);
|
|
|
result = StringEscapeUtils.unescapeHtml4(result);
|
|
|
if (Objects.nonNull(result)) {
|
|
|
if (result.contains("HTTP")) {
|
|
|
- throw new BusinessException("云阅卷鉴权失败");
|
|
|
+ log.error("callStudentScoreApi result:{}", result);
|
|
|
+ throw new BusinessException("云阅卷拉取学生成绩失败");
|
|
|
}
|
|
|
List<Map> tempList = JSONObject.parseArray(JSONObject.toJSON(result).toString(), Map.class);
|
|
|
if (Objects.nonNull(tempList) && tempList.size() > 0) {
|
|
@@ -101,4 +109,79 @@ public class CloudMarkUtil {
|
|
|
}
|
|
|
return students;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 推送云阅卷考试
|
|
|
+ *
|
|
|
+ * @param saveExamParams
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ public Long callExamSaveApi(SaveExamParams saveExamParams) throws IOException {
|
|
|
+ saveExamParams.vaildParams();
|
|
|
+ this.getAccessKeyAndAccessSecret(saveExamParams);
|
|
|
+ Map<String, Object> params = JSON.parseObject(JSON.toJSONString(saveExamParams), Map.class);
|
|
|
+
|
|
|
+ String url = yunMarkDomain.getUrl() + yunMarkDomain.getExamSaveApi();
|
|
|
+ long timestamp = System.currentTimeMillis();
|
|
|
+ String accessToken = SignatureInfo.build(SignatureType.SECRET, SystemConstant.METHOD, yunMarkDomain.getExamSaveApi(), timestamp, saveExamParams.getAccessKey(), saveExamParams.getAccessSecret());
|
|
|
+ String result = HttpUtil.post(url, params, accessToken, timestamp);
|
|
|
+ result = StringEscapeUtils.unescapeHtml4(result);
|
|
|
+ if (result.contains("HTTP")) {
|
|
|
+ log.error("callExamSaveApi result:{}", result);
|
|
|
+ throw new BusinessException("云阅卷推送考试信息失败");
|
|
|
+ }
|
|
|
+ Map<String, Object> resultMap = (Map<String, Object>) JSON.parse(result);
|
|
|
+ return Long.parseLong(String.valueOf(resultMap.get("id")));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 推送云阅卷科目
|
|
|
+ *
|
|
|
+ * @param saveSubjectParams
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ public String callSubjectSaveApi(SaveSubjectParams saveSubjectParams) throws IOException {
|
|
|
+ saveSubjectParams.vaildParams();
|
|
|
+ this.getAccessKeyAndAccessSecret(saveSubjectParams);
|
|
|
+ Map<String, Object> params = JSON.parseObject(JSON.toJSONString(saveSubjectParams), Map.class);
|
|
|
+
|
|
|
+ String url = yunMarkDomain.getUrl() + yunMarkDomain.getSubjectSaveApi();
|
|
|
+ long timestamp = System.currentTimeMillis();
|
|
|
+ String accessToken = SignatureInfo.build(SignatureType.SECRET, SystemConstant.METHOD, yunMarkDomain.getSubjectSaveApi(), timestamp, saveSubjectParams.getAccessKey(), saveSubjectParams.getAccessSecret());
|
|
|
+ String result = HttpUtil.post(url, params, accessToken, timestamp);
|
|
|
+ result = StringEscapeUtils.unescapeHtml4(result);
|
|
|
+ if (result.contains("HTTP")) {
|
|
|
+ log.error("callSubjectSaveApi result:{}", result);
|
|
|
+ throw new BusinessException("云阅卷推送考试科目信息失败");
|
|
|
+ }
|
|
|
+ Map<String, Object> resultMap = (Map<String, Object>) JSON.parse(result);
|
|
|
+ return String.valueOf(resultMap.get("updateTime"));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 推送云阅卷考生
|
|
|
+ *
|
|
|
+ * @param saveStudentParams
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ public String callStudentSaveApi(SaveStudentParams saveStudentParams) throws IOException {
|
|
|
+ saveStudentParams.vaildParams();
|
|
|
+ this.getAccessKeyAndAccessSecret(saveStudentParams);
|
|
|
+ Map<String, Object> params = JSON.parseObject(JSON.toJSONString(saveStudentParams), Map.class);
|
|
|
+
|
|
|
+ String url = yunMarkDomain.getUrl() + yunMarkDomain.getStudentSaveApi();
|
|
|
+ long timestamp = System.currentTimeMillis();
|
|
|
+ String accessToken = SignatureInfo.build(SignatureType.SECRET, SystemConstant.METHOD, yunMarkDomain.getStudentSaveApi(), timestamp, saveStudentParams.getAccessKey(), saveStudentParams.getAccessSecret());
|
|
|
+ String result = HttpUtil.post(url, params, accessToken, timestamp);
|
|
|
+ result = StringEscapeUtils.unescapeHtml4(result);
|
|
|
+ if (result.contains("HTTP")) {
|
|
|
+ log.error("callStudentSaveApi result:{}", result);
|
|
|
+ throw new BusinessException("云阅卷推送考生信息失败");
|
|
|
+ }
|
|
|
+ Map<String, Object> resultMap = (Map<String, Object>) JSON.parse(result);
|
|
|
+ return String.valueOf(resultMap.get("updateTime"));
|
|
|
+ }
|
|
|
}
|