|
@@ -6,12 +6,14 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
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.bean.tiku.TikuCourseProperty;
|
|
import com.qmth.teachcloud.common.bean.tiku.TikuPaperInfo;
|
|
import com.qmth.teachcloud.common.bean.tiku.TikuPaperInfo;
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
import com.qmth.teachcloud.common.entity.BasicSchool;
|
|
import com.qmth.teachcloud.common.entity.BasicSchool;
|
|
import com.qmth.teachcloud.common.entity.SysConfig;
|
|
import com.qmth.teachcloud.common.entity.SysConfig;
|
|
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.FileUtil;
|
|
import com.qmth.teachcloud.common.util.HttpUtil;
|
|
import com.qmth.teachcloud.common.util.HttpUtil;
|
|
import com.qmth.teachcloud.common.util.JacksonUtil;
|
|
import com.qmth.teachcloud.common.util.JacksonUtil;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -20,11 +22,9 @@ import org.slf4j.LoggerFactory;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.Map;
|
|
|
|
-import java.util.Objects;
|
|
|
|
-import java.util.Optional;
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 题库工具类
|
|
* 题库工具类
|
|
@@ -52,11 +52,7 @@ public class TikuUtils {
|
|
* @param pageSize 每页条数
|
|
* @param pageSize 每页条数
|
|
*/
|
|
*/
|
|
public IPage<TikuPaperInfo> pagePaperInfo(Long schoolId, String courseCode, String paperName, String account, int pageNumber, int pageSize) {
|
|
public IPage<TikuPaperInfo> pagePaperInfo(Long schoolId, String courseCode, String paperName, String account, int pageNumber, int pageSize) {
|
|
- SysConfig sysConfig = commonCacheService.addSysConfigCache(schoolId, SystemConstant.QUESTION_HOST_URL);
|
|
|
|
- Optional.ofNullable(sysConfig).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未配置题库地址"));
|
|
|
|
- BasicSchool basicSchool = commonCacheService.schoolCache(schoolId);
|
|
|
|
- String hostUrl = SystemConstant.getHost(sysConfig.getConfigValue(), basicSchool.getCode());
|
|
|
|
-
|
|
|
|
|
|
+ String hostUrl = getHostUrl(schoolId);
|
|
String url = SystemConstant.TIKU_PAPER_LIST_API;
|
|
String url = SystemConstant.TIKU_PAPER_LIST_API;
|
|
validUrl(hostUrl, url);
|
|
validUrl(hostUrl, url);
|
|
String postUrl = hostUrl.concat(url);
|
|
String postUrl = hostUrl.concat(url);
|
|
@@ -101,38 +97,76 @@ public class TikuUtils {
|
|
* @param paperId 题库试卷ID
|
|
* @param paperId 题库试卷ID
|
|
*/
|
|
*/
|
|
public boolean getTikuPaperData(Long schoolId, Long paperId) {
|
|
public boolean getTikuPaperData(Long schoolId, Long paperId) {
|
|
- SysConfig sysConfig = commonCacheService.addSysConfigCache(schoolId, SystemConstant.TEACHCLOUD_REPORT_HOST_URL);
|
|
|
|
- Optional.ofNullable(sysConfig).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未配置教研分析地址"));
|
|
|
|
- BasicSchool basicSchool = commonCacheService.schoolCache(schoolId);
|
|
|
|
- String hostUrl = SystemConstant.getHost(sysConfig.getConfigValue(), basicSchool.getCode());
|
|
|
|
-
|
|
|
|
|
|
+ String hostUrl = getHostUrl(schoolId);
|
|
String url = SystemConstant.TIKU_PAPER_DATA_API;
|
|
String url = SystemConstant.TIKU_PAPER_DATA_API;
|
|
validUrl(hostUrl, url);
|
|
validUrl(hostUrl, url);
|
|
String postUrl = hostUrl.concat(url);
|
|
String postUrl = hostUrl.concat(url);
|
|
long timestamp = System.currentTimeMillis();
|
|
long timestamp = System.currentTimeMillis();
|
|
|
|
+ File file = null;
|
|
try {
|
|
try {
|
|
//参数
|
|
//参数
|
|
Map<String, Object> map = new HashMap<>();
|
|
Map<String, Object> map = new HashMap<>();
|
|
map.put("paperId", validParam(paperId, null, true, "试卷ID"));
|
|
map.put("paperId", validParam(paperId, null, true, "试卷ID"));
|
|
|
|
|
|
- String result = HttpUtil.post(postUrl, map, createSign(schoolId, timestamp, url), timestamp);
|
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
|
-// if (jsonObject.containsKey("code")) {
|
|
|
|
-// String code = jsonObject.getString("code");
|
|
|
|
-// if ("200".equals(code)) {
|
|
|
|
-// return jsonObject.getLong("data");
|
|
|
|
-// } else {
|
|
|
|
-// throw ExceptionResultEnum.ERROR.exception(jsonObject.getString("error"));
|
|
|
|
-// }
|
|
|
|
-// } else {
|
|
|
|
-// throw ExceptionResultEnum.ERROR.exception("考试同步失败");
|
|
|
|
-// }
|
|
|
|
|
|
+ File filePath = SystemConstant.getFileTempDirVar(SystemConstant.ZIP_PREFIX);
|
|
|
|
+ file = HttpUtil.postDownload(postUrl, map, createSign(schoolId, timestamp, url), timestamp, filePath.getPath());
|
|
|
|
+ if (file.exists()) {
|
|
|
|
+ System.out.println(filePath.getPath());
|
|
|
|
+ System.out.println(1);
|
|
|
|
+ } else {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("试卷结构包获取失败");
|
|
|
|
+ }
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
throw ExceptionResultEnum.ERROR.exception(e.getMessage());
|
|
throw ExceptionResultEnum.ERROR.exception(e.getMessage());
|
|
|
|
+ } finally {
|
|
|
|
+ if (file.exists()) {
|
|
|
|
+ FileUtil.deleteFile(file);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 获取试卷知识点
|
|
|
|
+ *
|
|
|
|
+ * @param schoolId 学校ID
|
|
|
|
+ * @param courseCode 课程代码
|
|
|
|
+ */
|
|
|
|
+ public List<TikuCourseProperty> listCourseProperty(Long schoolId, String courseCode) {
|
|
|
|
+ String hostUrl = getHostUrl(schoolId);
|
|
|
|
+ String url = SystemConstant.TIKU_PAPER_PROPERTY_API;
|
|
|
|
+ validUrl(hostUrl, url);
|
|
|
|
+ String postUrl = hostUrl.concat(url);
|
|
|
|
+ long timestamp = System.currentTimeMillis();
|
|
|
|
+ //参数
|
|
|
|
+ try {
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
+ map.put("courseCode", validParam(courseCode, null, true, "科目代码"));
|
|
|
|
+
|
|
|
|
+ String result = HttpUtil.post(postUrl, map, createSign(schoolId, timestamp, url), timestamp);
|
|
|
|
+ if (result.contains("\"code\":500000")) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("课程知识点获取失败");
|
|
|
|
+ }
|
|
|
|
+ return JSON.parseArray(result, TikuCourseProperty.class);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ log.error(SystemConstant.LOG_ERROR, e);
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询题库服务器接口访问地址
|
|
|
|
+ *
|
|
|
|
+ * @param schoolId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private String getHostUrl(Long schoolId) {
|
|
|
|
+ SysConfig sysConfig = commonCacheService.addSysConfigCache(schoolId, SystemConstant.QUESTION_HOST_URL);
|
|
|
|
+ Optional.ofNullable(sysConfig).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未配置题库地址"));
|
|
|
|
+ BasicSchool basicSchool = commonCacheService.schoolCache(schoolId);
|
|
|
|
+ return SystemConstant.getHost(sysConfig.getConfigValue(), basicSchool.getCode());
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 签名
|
|
* 签名
|
|
*
|
|
*
|