|
@@ -0,0 +1,181 @@
|
|
|
+package cn.com.qmth.dp.examcloud.oe.modules.load_question_cache;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.google.common.collect.Maps;
|
|
|
+
|
|
|
+import cn.com.qmth.dp.examcloud.oe.entity.question.ExtractConfig;
|
|
|
+import cn.com.qmth.dp.examcloud.oe.modules.update_correct_answer.util.OKHttpUtil;
|
|
|
+import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
+import cn.com.qmth.examcloud.commons.util.HttpMethod;
|
|
|
+import cn.com.qmth.examcloud.commons.util.JsonUtil;
|
|
|
+import cn.com.qmth.examcloud.question.commons.core.paper.DefaultQuestionGroup;
|
|
|
+import cn.com.qmth.examcloud.question.commons.core.paper.DefaultQuestionStructureWrapper;
|
|
|
+import cn.com.qmth.examcloud.question.commons.core.question.DefaultQuestionUnit;
|
|
|
+import cn.com.qmth.examcloud.question.commons.core.question.QuestionType;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.BasePaperCacheBean;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.ExtractConfigCacheBean;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.ExtractConfigDetailCacheBean;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.ExtractConfigPaperCacheBean;
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.QuestionCacheBean;
|
|
|
+import okhttp3.Response;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 加载题库缓存
|
|
|
+ *
|
|
|
+ * @author chenken
|
|
|
+ *
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class LoadQuestionsCacheService {
|
|
|
+
|
|
|
+ //变动参数
|
|
|
+ private final static String examId="14";
|
|
|
+
|
|
|
+ private final static String key = "U_C_0_6";
|
|
|
+
|
|
|
+ private final static String token = "848cc9362be84796b902f9991a1c6629";
|
|
|
+
|
|
|
+ private final static String domain="https://192.168.10.39/api/ecs_ques/";
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private final static String url1=domain+"cache-load/extract-config-list";
|
|
|
+
|
|
|
+ private final static String url2=domain+"cache-load/extract-config-cache";
|
|
|
+
|
|
|
+ private final static String url3=domain+"cache-load/extract-config-paper-cache";
|
|
|
+
|
|
|
+// private final static String url4=domain+"cache-load/base-paper-cache";
|
|
|
+
|
|
|
+ private final static String url5=domain+"cache-load/question-cache";
|
|
|
+
|
|
|
+ private final static String url6=domain+"cache-load/question-answer-cache";
|
|
|
+
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ start();
|
|
|
+ }
|
|
|
+ public static void start() {
|
|
|
+ Map<String, String> params1 = Maps.newHashMap();
|
|
|
+ params1.put("examId", examId);
|
|
|
+ List<ExtractConfig> ecs=getListData(url1, params1, ExtractConfig.class);
|
|
|
+ if(CollectionUtils.isEmpty(ecs)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ System.out.println("考试名称:"+ecs.get(0).getExamName());
|
|
|
+ System.out.println("--课程数:"+ecs.size());
|
|
|
+ for(ExtractConfig ec:ecs) {
|
|
|
+ Map<String, String> params2 = Maps.newHashMap();
|
|
|
+ params2.put("examId", examId);
|
|
|
+ params2.put("courseCode", ec.getCourseCode());
|
|
|
+ //课程
|
|
|
+ ExtractConfigCacheBean ecCache=getObjectData(url2, params2, ExtractConfigCacheBean.class);
|
|
|
+ System.out.println("----课程code:"+ec.getCourseCode());
|
|
|
+ if(ecCache!=null&&CollectionUtils.isNotEmpty(ecCache.getDetails())) {
|
|
|
+ for(ExtractConfigDetailCacheBean ecdCache:ecCache.getDetails()) {
|
|
|
+ Map<String, String> params3 = Maps.newHashMap();
|
|
|
+ params3.put("examId", examId);
|
|
|
+ params3.put("courseCode", ec.getCourseCode());
|
|
|
+ params3.put("groupCode", ecdCache.getGroupCode());
|
|
|
+ params3.put("paperId", ecdCache.getPaperId());
|
|
|
+ //试卷
|
|
|
+ ExtractConfigPaperCacheBean paper=getObjectData(url3, params3, ExtractConfigPaperCacheBean.class);
|
|
|
+ System.out.println("------试卷名:"+paper.getDefaultPaper().getName());
|
|
|
+ Map<String, String> params4 = Maps.newHashMap();
|
|
|
+ params4.put("paperId", ecdCache.getPaperId());
|
|
|
+ //原卷 阅卷用
|
|
|
+// BasePaperCacheBean bpCache=getObjectData(url4, params4, BasePaperCacheBean.class);
|
|
|
+
|
|
|
+
|
|
|
+ if(paper!=null&&CollectionUtils.isNotEmpty(paper.getDefaultPaper().getQuestionGroupList())) {
|
|
|
+ for(DefaultQuestionGroup dqg:paper.getDefaultPaper().getQuestionGroupList()) {
|
|
|
+ if(CollectionUtils.isNotEmpty(dqg.getQuestionWrapperList())) {
|
|
|
+ for(DefaultQuestionStructureWrapper dqsw:dqg.getQuestionWrapperList()) {
|
|
|
+ Map<String, String> params5 = Maps.newHashMap();
|
|
|
+ params5.put("examId", examId);
|
|
|
+ params5.put("courseCode", ec.getCourseCode());
|
|
|
+ params5.put("groupCode", ecdCache.getGroupCode());
|
|
|
+ params5.put("questionId", dqsw.getQuestionId());
|
|
|
+ //小题
|
|
|
+ QuestionCacheBean qCache=getObjectData(url5, params5, QuestionCacheBean.class);
|
|
|
+ if(isObjective(qCache)) {
|
|
|
+ Map<String, String> params6 = Maps.newHashMap();
|
|
|
+ params6.put("questionId", dqsw.getQuestionId());
|
|
|
+ //答案
|
|
|
+ getObjectData(url6, params6, BasePaperCacheBean.class);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static boolean isObjective(QuestionCacheBean ques) {
|
|
|
+ if(CollectionUtils.isNotEmpty(ques.getDefaultQuestion().getMasterVersion().getQuestionUnitList())){
|
|
|
+ for(DefaultQuestionUnit qu:ques.getDefaultQuestion().getMasterVersion().getQuestionUnitList()) {
|
|
|
+ if(QuestionType.SINGLE_CHOICE.equals(qu.getQuestionType())
|
|
|
+ ||QuestionType.MULTIPLE_CHOICE.equals(qu.getQuestionType())
|
|
|
+ ||QuestionType.TRUE_OR_FALSE.equals(qu.getQuestionType())) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static <T> T getObjectData(String url, Map<String, String> params, Class<T> responseType) {
|
|
|
+ Map<String, String> headers = Maps.newHashMap();
|
|
|
+ headers.put("key", key);
|
|
|
+ headers.put("token", token);
|
|
|
+ Response resp = null;
|
|
|
+ try {
|
|
|
+ resp = OKHttpUtil.call(HttpMethod.POST, url, headers, params);
|
|
|
+ if (resp.code() == 200) {
|
|
|
+ String resultJson = resp.body().string();
|
|
|
+ T res = JsonUtil.fromJson(resultJson, responseType);
|
|
|
+ return res;
|
|
|
+ } else {
|
|
|
+ throw new StatusException("500", resp.body().string());
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new StatusException("500", e.getMessage(), e);
|
|
|
+ } finally {
|
|
|
+ IOUtils.closeQuietly(resp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static <T> List<T> getListData(String url, Map<String, String> params, Class<T> responseType) {
|
|
|
+ Map<String, String> headers = Maps.newHashMap();
|
|
|
+ headers.put("key", key);
|
|
|
+ headers.put("token", token);
|
|
|
+ Response resp = null;
|
|
|
+ try {
|
|
|
+ resp = OKHttpUtil.call(HttpMethod.POST, url, headers, params);
|
|
|
+ if (resp.code() == 200) {
|
|
|
+ String resultJson = resp.body().string();
|
|
|
+ List<T> res = JSON.parseArray(resultJson, responseType);
|
|
|
+ return res;
|
|
|
+ } else {
|
|
|
+ throw new StatusException("500", resp.body().string());
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new StatusException("500", e.getMessage(), e);
|
|
|
+ } finally {
|
|
|
+ IOUtils.closeQuietly(resp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|