deason 2 年之前
父节点
当前提交
0ff8c821f0

+ 32 - 0
src/main/java/cn/com/qmth/examcloud/tool/service/CommonService.java

@@ -1,15 +1,20 @@
 package cn.com.qmth.examcloud.tool.service;
 
 import cn.com.qmth.examcloud.tool.config.SysProperty;
+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.vo.Pager;
 import cn.com.qmth.examcloud.tool.vo.User;
+import com.fasterxml.jackson.core.type.TypeReference;
 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
@@ -35,4 +40,31 @@ public class CommonService {
         return new JsonMapper().parseJson(result, User.class);
     }
 
+    /**
+     * 获取考试相关的课程列表
+     */
+    public List<CourseVO> getExamCourseList(String key, String token, Long examId) {
+        Map<String, Object> params = new HashMap<>();
+        params.put("examId", examId);
+        params.put("pageNo", 1);
+        params.put("pageSize", 1000);
+
+        Map<String, String> headers = new HashMap<>();
+        headers.put("key", key);
+        headers.put("token", token);
+
+        String url = sysProperty.getServerUrl() + "/api/ecs_exam_work/exam/course/list";
+        String json = HttpHelper.post(url, headers, params);
+
+        JsonMapper jsonMapper = new JsonMapper();
+        Pager<CourseVO> page = jsonMapper.parseJson(json, new TypeReference<Pager<CourseVO>>() {
+        });
+
+        if (page != null && page.getContent() != null) {
+            return page.getContent();
+        }
+
+        return new ArrayList<>();
+    }
+
 }

+ 4 - 31
src/main/java/cn/com/qmth/examcloud/tool/service/export_student_answer_and_score_detail/ExportStudentAnswerAndScoreDetailTask.java

@@ -58,9 +58,9 @@ public class ExportStudentAnswerAndScoreDetailTask {
         Boolean needSubjective = jsonParams.get("needSubjective").asBoolean(false);
         log.info("examId = {}, courseCodes = {}, needSubjective = {}", examId, courseCodes, needSubjective);
 
-        // 待导出的课程列表(未指定课程则按考试的全部课程)
+        // 待处理的课程列表(未指定课程则按考试的全部课程)
         List<CourseVO> todoCourses;
-        List<CourseVO> courses = this.getExamCourseList(user.getKey(), user.getToken(), examId);
+        List<CourseVO> courses = commonService.getExamCourseList(user.getKey(), user.getToken(), examId);
         if (StringUtils.isNotBlank(courseCodes)) {
             todoCourses = new ArrayList<>();
             String[] courseCodeList = StringUtils.split(courseCodes, ",");
@@ -74,10 +74,10 @@ public class ExportStudentAnswerAndScoreDetailTask {
         } else {
             todoCourses = courses;
         }
-        log.info("待导出的课程列表数为:{}", todoCourses.size());
+        log.info("待处理的课程数为:{}", todoCourses.size());
 
         for (CourseVO course : todoCourses) {
-            // 按考试课程逐个导出
+            // 按考试课程逐个处理
             this.export(examId, course, needSubjective, user, tempDir);
         }
     }
@@ -283,33 +283,6 @@ public class ExportStudentAnswerAndScoreDetailTask {
         return all;
     }
 
-    /**
-     * 获取考试相关的课程列表
-     */
-    private List<CourseVO> getExamCourseList(String key, String token, Long examId) {
-        Map<String, Object> params = new HashMap<>();
-        params.put("examId", examId);
-        params.put("pageNo", 1);
-        params.put("pageSize", 1000);
-
-        Map<String, String> headers = new HashMap<>();
-        headers.put("key", key);
-        headers.put("token", token);
-
-        String url = sysProperty.getServerUrl() + "/api/ecs_exam_work/exam/course/list";
-        String json = HttpHelper.post(url, headers, params);
-
-        JsonMapper jsonMapper = new JsonMapper();
-        Pager<CourseVO> page = jsonMapper.parseJson(json, new TypeReference<Pager<CourseVO>>() {
-        });
-
-        if (page != null && page.getContent() != null) {
-            return page.getContent();
-        }
-
-        return new ArrayList<>();
-    }
-
     private String numbersToLetters(String numberStr) {
         if (StringUtils.isEmpty(numberStr)) {
             return "";

+ 57 - 1
src/main/java/cn/com/qmth/examcloud/tool/service/update_correct_answer_and_re_fix_score/UpdateCorrectAnswerAndReFixScoreTask.java

@@ -1,18 +1,74 @@
 package cn.com.qmth.examcloud.tool.service.update_correct_answer_and_re_fix_score;
 
+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.utils.JsonMapper;
 import cn.com.qmth.examcloud.tool.utils.StatusException;
+import cn.com.qmth.examcloud.tool.vo.User;
+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.List;
+
 @Component
 public class UpdateCorrectAnswerAndReFixScoreTask {
 
     private final static Logger log = LoggerFactory.getLogger(UpdateCorrectAnswerAndReFixScoreTask.class);
 
+    @Autowired
+    private CommonService commonService;
+
+    @Autowired
+    private SysProperty sysProperty;
+
     public void start(TaskEntity task) {
-        throw new StatusException("。。。");
+        JsonNode jsonParams = new JsonMapper().getNode(task.getParams());
+        if (jsonParams == null) {
+            throw new StatusException("任务参数解析错误!");
+        }
+
+        User user = commonService.login(sysProperty.getServerDomain(), sysProperty.getServerLoginName(), sysProperty.getServerPassword());
+        this.execute(jsonParams, user);
+    }
+
+    private void execute(JsonNode jsonParams, User user) {
+        Long examId = jsonParams.get("examId").asLong(0L);
+        String courseCodes = jsonParams.get("courseCodes").asText("");
+        log.info("examId = {}, courseCodes = {}", examId, courseCodes);
+
+        // 待处理的课程列表(未指定课程则按考试的全部课程)
+        List<CourseVO> todoCourses;
+        List<CourseVO> courses = commonService.getExamCourseList(user.getKey(), user.getToken(), examId);
+        if (StringUtils.isNotBlank(courseCodes)) {
+            todoCourses = new ArrayList<>();
+            String[] courseCodeList = StringUtils.split(courseCodes, ",");
+            for (String courseCode : courseCodeList) {
+                for (CourseVO vo : courses) {
+                    if (vo.getCourseCode().equals(courseCode)) {
+                        todoCourses.add(vo);
+                    }
+                }
+            }
+        } else {
+            todoCourses = courses;
+        }
+        log.info("待处理的课程数为:{}", todoCourses.size());
+
+        for (CourseVO course : todoCourses) {
+            // 按考试课程逐个处理
+            this.process(examId, course, user);
+        }
+    }
+
+    public void process(Long examId, CourseVO course, User user) {
+        // todo
     }
 
 }