|
@@ -0,0 +1,113 @@
|
|
|
|
+package cn.com.qmth.examcloud.tool.service.paper_struct;
|
|
|
|
+
|
|
|
|
+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.export_student_answer_and_score_detail.vo.CourseVO;
|
|
|
|
+import cn.com.qmth.examcloud.tool.service.paper_struct.vo.ExamPaperVO;
|
|
|
|
+import cn.com.qmth.examcloud.tool.service.paper_struct.vo.ExtractConfigVO;
|
|
|
|
+import cn.com.qmth.examcloud.tool.utils.HttpHelper;
|
|
|
|
+import cn.com.qmth.examcloud.tool.utils.JsonMapper;
|
|
|
|
+import cn.com.qmth.examcloud.tool.utils.SignUtils;
|
|
|
|
+import cn.com.qmth.examcloud.tool.vo.Pager;
|
|
|
|
+import cn.com.qmth.examcloud.tool.vo.User;
|
|
|
|
+import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
+
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+@Component
|
|
|
|
+public class PaperStructTask {
|
|
|
|
+
|
|
|
|
+ private final static Logger log = LoggerFactory.getLogger(PaperStructTask.class);
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private SysProperty sysProperty;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private CommonService commonService;
|
|
|
|
+
|
|
|
|
+ public void start(TaskEntity task) {
|
|
|
|
+ User user = commonService.login(sysProperty.getServerRootOrgId(), sysProperty.getServerLoginName(), sysProperty.getServerPassword());
|
|
|
|
+ this.execute(user, 51L);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void execute(User user, Long examId) {
|
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
|
+ headers.put("key", user.getKey());
|
|
|
|
+ headers.put("token", user.getToken());
|
|
|
|
+
|
|
|
|
+ List<CourseVO> courses = commonService.getExamCourseList(user.getKey(), user.getToken(), examId);
|
|
|
|
+ log.info("examId:{}, 课程数为:{}", examId, courses.size());
|
|
|
|
+
|
|
|
|
+ for (CourseVO course : courses) {
|
|
|
|
+ List<ExtractConfigVO> extractConfigs = this.getExtractConfig(user, examId, course.getCourseCode());
|
|
|
|
+ if (CollectionUtils.isEmpty(extractConfigs)) {
|
|
|
|
+ log.info("examId:{}, courseCode:{}, 未配置调卷规则!", examId, course.getCourseCode());
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (ExtractConfigVO extractConfig : extractConfigs) {
|
|
|
|
+ for (ExamPaperVO examPaper : extractConfig.getExamPaperList()) {
|
|
|
|
+ String basePaperId = examPaper.getPaper().getId();
|
|
|
|
+ log.info("examId:{}, courseCode:{}, paperType:{}, basePaperId:{}", examId, course.getCourseCode(), examPaper.getGroupCode(), basePaperId);
|
|
|
|
+ this.getPaperStruct(examId, course.getCourseCode(), examPaper.getGroupCode(), basePaperId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询某个考试课程的调卷规则配置
|
|
|
|
+ */
|
|
|
|
+ private List<ExtractConfigVO> getExtractConfig(User user, Long examId, String courseCode) {
|
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
|
+ headers.put("key", user.getKey());
|
|
|
|
+ headers.put("token", user.getToken());
|
|
|
|
+
|
|
|
|
+ Map<String, String> params = new HashMap<>();
|
|
|
|
+ params.put("examId", String.valueOf(examId));
|
|
|
|
+ params.put("courseNo", courseCode);
|
|
|
|
+
|
|
|
|
+ String url = sysProperty.getServerUrl() + "/api/ecs_ques/findPageExtractConfig/1/10";
|
|
|
|
+ String json = HttpHelper.get(url, headers, params);
|
|
|
|
+
|
|
|
|
+ Pager<ExtractConfigVO> page = new JsonMapper().parseJson(json, new TypeReference<Pager<ExtractConfigVO>>() {
|
|
|
|
+ });
|
|
|
|
+ return page.getContent();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取某个考试课程原卷的试卷结构
|
|
|
|
+ */
|
|
|
|
+ private void getPaperStruct(Long examId, String courseCode, String paperType, String basePaperId) {
|
|
|
|
+ long rootOrgId = sysProperty.getServerRootOrgId();
|
|
|
|
+ String appId = sysProperty.getServerAppId();
|
|
|
|
+ String secretKey = sysProperty.getServerSecretKey();
|
|
|
|
+ long timestamp = System.currentTimeMillis();
|
|
|
|
+ String accessToken = SignUtils.accessToken(rootOrgId, appId, secretKey, timestamp);
|
|
|
|
+
|
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
|
+ headers.put("rootOrgId", String.valueOf(rootOrgId));
|
|
|
|
+ headers.put("appId", appId);
|
|
|
|
+ headers.put("access_token", accessToken);
|
|
|
|
+ headers.put("timestamp", String.valueOf(timestamp));
|
|
|
|
+
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
+ params.put("examId", examId);
|
|
|
|
+ params.put("courseCode", courseCode);
|
|
|
|
+ params.put("paperType", paperType);
|
|
|
|
+ params.put("basePaperId", basePaperId);
|
|
|
|
+
|
|
|
|
+ String url = sysProperty.getServerUrl() + "/api/exchange/outer/question/getPaperStruct";
|
|
|
|
+ String json = HttpHelper.post(url, headers, params);
|
|
|
|
+ System.out.println(json);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|