|
@@ -4,15 +4,28 @@ import cn.com.qmth.examcloud.tool.cache.LoginSessionManager;
|
|
|
import cn.com.qmth.examcloud.tool.config.SysProperty;
|
|
|
import cn.com.qmth.examcloud.tool.entity.TaskEntity;
|
|
|
import cn.com.qmth.examcloud.tool.service.CommonService;
|
|
|
+import cn.com.qmth.examcloud.tool.service.create_random_paper_template.vo.PaperStructVO;
|
|
|
+import cn.com.qmth.examcloud.tool.service.create_random_paper_template.vo.PaperVO;
|
|
|
+import cn.com.qmth.examcloud.tool.service.create_random_paper_template.vo.RandomPaperTemplateVO;
|
|
|
+import cn.com.qmth.examcloud.tool.service.export_student_answer_and_score_detail.vo.CourseVO;
|
|
|
+import cn.com.qmth.examcloud.tool.utils.HttpHelper;
|
|
|
import cn.com.qmth.examcloud.tool.utils.JsonMapper;
|
|
|
import cn.com.qmth.examcloud.tool.utils.StatusException;
|
|
|
+import cn.com.qmth.examcloud.tool.vo.Pager;
|
|
|
import cn.com.qmth.examcloud.tool.vo.user.User;
|
|
|
+import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
@Component
|
|
|
public class CreateRandomPaperTemplateTask {
|
|
|
|
|
@@ -39,7 +52,150 @@ public class CreateRandomPaperTemplateTask {
|
|
|
}
|
|
|
|
|
|
private void execute(User user, JsonNode jsonParams) {
|
|
|
+ Long examId = jsonParams.get("examId").asLong(0L);
|
|
|
+ Integer questionPool = jsonParams.get("questionPool").asInt(1);
|
|
|
+ String structType = jsonParams.get("structType").asInt(1) == 1 ? "EXACT" : "BLUEPRINT";
|
|
|
+ String structName = jsonParams.get("structName").asText("");
|
|
|
+ String paperKeywords = jsonParams.get("paperKeywords").asText("");
|
|
|
+
|
|
|
+ log.info("examId = {}, questionPool = {}, structType = {}, structName = {}, paperKeywords = {}", examId,
|
|
|
+ questionPool, structType, structName, paperKeywords);
|
|
|
+
|
|
|
+ List<CourseVO> courses = commonService.getExamCourseList(user, examId);
|
|
|
+ log.info("examId:{}, 待处理的课程数为:{}", examId, courses.size());
|
|
|
+
|
|
|
+ if (courses.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ int index = 0;
|
|
|
+ for (CourseVO course : courses) {
|
|
|
+ // 按考试课程逐个处理
|
|
|
+ index++;
|
|
|
+
|
|
|
+ if (this.existRandomPaperTemplate(user, course.getCourseId())) {
|
|
|
+ log.warn("examId:{} courseId:{} 已处理课程数:{} 已存在随机抽卷模板!", examId, course.getCourseId(),
|
|
|
+ index);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取试卷结构
|
|
|
+ String paperStructId = this.getPaperStructId(user, course.getCourseCode(), structType, structName);
|
|
|
+ if (paperStructId == null) {
|
|
|
+ log.warn("examId:{} courseId:{} 已处理课程数:{} 未找到试卷结构!", examId, course.getCourseId(), index);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取试卷列表
|
|
|
+ List<String> paperIds = this.getPapers(user, course.getCourseCode(), questionPool, paperKeywords);
|
|
|
+ if (paperIds.isEmpty()) {
|
|
|
+ log.warn("examId:{} courseId:{} 已处理课程数:{} 未找到相关试卷!", examId, course.getCourseId(), index);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存随机抽卷模板
|
|
|
+ this.saveRandomPaperTemplate(user, course.getCourseId(), structType, paperStructId, questionPool, paperIds);
|
|
|
+
|
|
|
+ log.info("examId:{} courseId:{} 已处理课程数:{}", examId, course.getCourseId(), index);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取试卷结构信息
|
|
|
+ */
|
|
|
+ private String getPaperStructId(User user, String courseCode, String structType, String structName) {
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("key", user.getKey());
|
|
|
+ headers.put("token", user.getToken());
|
|
|
+
|
|
|
+ Map<String, String> params = new HashMap<>();
|
|
|
+ params.put("courseNo", courseCode);
|
|
|
+ params.put("type", structType);
|
|
|
+
|
|
|
+ String url = user.getServerUrl() + "/api/ecs_ques/paperStruct";
|
|
|
+ String json = HttpHelper.get(url, headers, params);
|
|
|
+
|
|
|
+ JsonMapper jsonMapper = new JsonMapper();
|
|
|
+ List<PaperStructVO> list = jsonMapper.toList(json, PaperStructVO.class);
|
|
|
+ for (PaperStructVO vo : list) {
|
|
|
+ if (vo.getName().equals(structName)) {
|
|
|
+ return vo.getId();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断课程是否已存在随机抽卷模板
|
|
|
+ */
|
|
|
+ private boolean existRandomPaperTemplate(User user, Long courseId) {
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("key", user.getKey());
|
|
|
+ headers.put("token", user.getToken());
|
|
|
+
|
|
|
+ String url = user.getServerUrl() + "/api/ecs_ques/randompaper/page?pageSize=1&courseId=" + courseId;
|
|
|
+ String json = HttpHelper.post(url, headers, null);
|
|
|
+
|
|
|
+ JsonMapper jsonMapper = new JsonMapper();
|
|
|
+ Pager<RandomPaperTemplateVO> page = jsonMapper.parseJson(json,
|
|
|
+ new TypeReference<Pager<RandomPaperTemplateVO>>() {
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ return !page.getContent().isEmpty();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取试卷列表
|
|
|
+ */
|
|
|
+ private List<String> getPapers(User user, String courseCode, Integer questionPool, String paperKeywords) {
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("key", user.getKey());
|
|
|
+ headers.put("token", user.getToken());
|
|
|
+
|
|
|
+ Map<String, String> params = new HashMap<>();
|
|
|
+ params.put("courseNo", courseCode);
|
|
|
+
|
|
|
+ String paperType = questionPool == 1 ? "importPaper" : "genPaper";
|
|
|
+ String url = user.getServerUrl() + "/api/ecs_ques/" + paperType + "/huoge/1/10";
|
|
|
+
|
|
|
+ String json = HttpHelper.get(url, headers, params);
|
|
|
+
|
|
|
+ JsonMapper jsonMapper = new JsonMapper();
|
|
|
+ Pager<PaperVO> page = jsonMapper.parseJson(json, new TypeReference<Pager<PaperVO>>() {
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+ List<String> paperIds = new ArrayList<>();
|
|
|
+ for (PaperVO vo : page.getContent()) {
|
|
|
+ //todo
|
|
|
+ }
|
|
|
+
|
|
|
+ return paperIds;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存随机抽卷模板
|
|
|
+ */
|
|
|
+ public void saveRandomPaperTemplate(User user, Long courseId, String paperStructType, String paperStructId,
|
|
|
+ Integer questionPool, List<String> paperIds) {
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("key", user.getKey());
|
|
|
+ headers.put("token", user.getToken());
|
|
|
+
|
|
|
+ String paperType = questionPool == 1 ? "IMPORT" : "GENERATE";
|
|
|
+
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ params.put("name", "todo");//todo
|
|
|
+ params.put("courseId", courseId);
|
|
|
+ params.put("paperStructType", paperStructType);
|
|
|
+ params.put("paperStructId", paperStructId);
|
|
|
+ params.put("paperType", paperType);
|
|
|
+ params.put("paperIds", StringUtils.join(paperIds, ","));
|
|
|
|
|
|
+ final String url = user.getServerUrl() + "/api/ecs_ques/randompaper/save";
|
|
|
+ HttpHelper.post(url, headers, params);
|
|
|
}
|
|
|
|
|
|
}
|