Parcourir la source

ConfigExamPaperTask

deason il y a 1 an
Parent
commit
64a122fd0d

+ 34 - 0
src/main/java/cn/com/qmth/examcloud/tool/controller/IndexController.java

@@ -5,6 +5,7 @@ import cn.com.qmth.examcloud.tool.service.CommonService;
 import cn.com.qmth.examcloud.tool.vo.user.User;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestParam;
@@ -47,4 +48,37 @@ public class IndexController extends BaseController {
         return "admin/workspace";
     }
 
+    /**
+     * 任务列表
+     */
+    @GetMapping(value = "/admin/taskList")
+    public String taskList(Model model) {
+        model.addAttribute("menuIndex", 2);
+        return "admin/taskList";
+    }
+
+    /**
+     * 导出考生试题作答和得分明细
+     */
+    @GetMapping(value = "/admin/exportStudentAnswerAndScoreDetail")
+    public String exportStudentAnswerAndScoreDetail() {
+        return "admin/exportStudentAnswerAndScoreDetail";
+    }
+
+    /**
+     * 更新正确答案并重新算分
+     */
+    @GetMapping(value = "/admin/updateCorrectAnswerAndReFixScore")
+    public String updateCorrectAnswerAndReFixScore() {
+        return "admin/updateCorrectAnswerAndReFixScore";
+    }
+
+    /**
+     * 配置考试调卷规则
+     */
+    @GetMapping(value = "/admin/configExamPaper")
+    public String configExamPaper() {
+        return "admin/configExamPaper";
+    }
+
 }

+ 0 - 17
src/main/java/cn/com/qmth/examcloud/tool/controller/TaskController.java

@@ -11,7 +11,6 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.stereotype.Controller;
-import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
@@ -26,22 +25,6 @@ public class TaskController extends BaseController {
     @Autowired
     private SysProperty sysProperty;
 
-    @GetMapping(value = "/admin/taskList")
-    public String taskList(Model model) {
-        model.addAttribute("menuIndex", 2);
-        return "admin/taskList";
-    }
-
-    @GetMapping(value = "/admin/exportStudentAnswerAndScoreDetail")
-    public String exportStudentAnswerAndScoreDetail() {
-        return "admin/exportStudentAnswerAndScoreDetail";
-    }
-
-    @GetMapping(value = "/admin/updateCorrectAnswerAndReFixScore")
-    public String updateCorrectAnswerAndReFixScore() {
-        return "admin/updateCorrectAnswerAndReFixScore";
-    }
-
     @ResponseBody
     @PostMapping(value = "/api/task/list")
     public Page<TaskEntity> taskList(@RequestBody TaskQuery req) {

+ 3 - 1
src/main/java/cn/com/qmth/examcloud/tool/enums/TaskType.java

@@ -7,7 +7,9 @@ public enum TaskType {
 
     EXPORT_STUDENT_ANSWER_AND_SCORE_DETAIL("导出考生试题作答和得分明细"),
 
-    UPDATE_CORRECT_ANSWER_AND_RE_FIX_SCORE("更新正确答案并重新算分");
+    UPDATE_CORRECT_ANSWER_AND_RE_FIX_SCORE("更新正确答案并重新算分"),
+
+    CONFIG_EXAM_PAPER("配置考试调卷规则");
 
     TaskType(String description) {
         this.description = description;

+ 7 - 0
src/main/java/cn/com/qmth/examcloud/tool/service/TaskService.java

@@ -4,6 +4,7 @@ import cn.com.qmth.examcloud.tool.dao.TaskRepository;
 import cn.com.qmth.examcloud.tool.entity.TaskEntity;
 import cn.com.qmth.examcloud.tool.enums.TaskStatus;
 import cn.com.qmth.examcloud.tool.enums.TaskType;
+import cn.com.qmth.examcloud.tool.service.config_exam_paper.ConfigExamPaperTask;
 import cn.com.qmth.examcloud.tool.service.export_student_answer_and_score_detail.ExportStudentAnswerAndScoreDetailTask;
 import cn.com.qmth.examcloud.tool.service.update_correct_answer_and_re_fix_score.UpdateCorrectAnswerAndReFixScoreTask;
 import cn.com.qmth.examcloud.tool.utils.StatusException;
@@ -41,6 +42,9 @@ public class TaskService {
     @Autowired
     private UpdateCorrectAnswerAndReFixScoreTask updateCorrectAnswerAndReFixScoreTask;
 
+    @Autowired
+    private ConfigExamPaperTask configExamPaperTask;
+
     public Page<TaskEntity> getTaskList(TaskQuery req) {
         if (req.getPageNo() == null || req.getPageNo() < 1) {
             req.setPageNo(1);
@@ -128,9 +132,12 @@ public class TaskService {
                 exportStudentAnswerAndScoreDetailTask.start(task);
             } else if (TaskType.UPDATE_CORRECT_ANSWER_AND_RE_FIX_SCORE == task.getType()) {
                 updateCorrectAnswerAndReFixScoreTask.start(task);
+            } else if (TaskType.CONFIG_EXAM_PAPER == task.getType()) {
+                configExamPaperTask.start(task);
             } else {
                 throw new StatusException("功能暂未实现!");
             }
+
             task.setStatus(TaskStatus.SUCCESS);
         } catch (Exception e) {
             log.error(e.getMessage(), e);

+ 97 - 0
src/main/java/cn/com/qmth/examcloud/tool/service/config_exam_paper/ConfigExamPaperTask.java

@@ -0,0 +1,97 @@
+package cn.com.qmth.examcloud.tool.service.config_exam_paper;
+
+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.HttpHelper;
+import cn.com.qmth.examcloud.tool.utils.JsonMapper;
+import cn.com.qmth.examcloud.tool.utils.StatusException;
+import cn.com.qmth.examcloud.tool.vo.user.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.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Component
+public class ConfigExamPaperTask {
+
+    private final static Logger log = LoggerFactory.getLogger(ConfigExamPaperTask.class);
+
+    @Autowired
+    private CommonService commonService;
+
+    @Autowired
+    private SysProperty sysProperty;
+
+    public void start(TaskEntity task) {
+        JsonNode jsonParams = new JsonMapper().getNode(task.getParams());
+        if (jsonParams == null) {
+            throw new StatusException("任务参数解析错误!");
+        }
+
+        User user = commonService.login(sysProperty.getServerRootOrgId(), 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("examId:{}, 待处理的课程数为:{}", examId, todoCourses.size());
+
+        List<String> errors = new ArrayList<>();
+        for (CourseVO course : todoCourses) {
+            // 按考试课程逐个处理
+            try {
+                this.process(examId, course, user);
+            } catch (Exception e) {
+                errors.add(String.format("课程代码:%s  处理失败:%s", course.getCourseCode(), e.getMessage()));
+            }
+        }
+
+        if (!errors.isEmpty()) {
+            throw new RuntimeException(StringUtils.join(errors, " "));
+        }
+    }
+
+    public void process(Long examId, CourseVO course, User user) {
+        // 按课程逐个配置考试调卷规则
+        Map<String, String> headers = new HashMap<>();
+        headers.put("key", user.getKey());
+        headers.put("token", user.getToken());
+
+        Map<String, Object> params = new HashMap<>();
+        params.put("examId", examId);
+        params.put("courseCode", course.getCourseCode());
+
+        final String url = sysProperty.getServerUrl() + "/api/ecs_ques/extract_config/randompaper/save";
+        HttpHelper.post(url, headers, params);
+        log.info("examId:{} courseId:{} courseCode:{} 已处理!", examId, course.getCourseId(), course.getCourseCode());
+    }
+
+}

+ 84 - 0
src/main/resources/templates/admin/configExamPaper.ftlh

@@ -0,0 +1,84 @@
+<#assign base=request.contextPath>
+<!DOCTYPE html>
+<html lang="zh-cn">
+<head>
+    <#include "../layout/header.ftlh"/>
+</head>
+
+<body>
+<div id="myVue">
+    <el-container>
+        <#include "../layout/topMenu.ftlh"/>
+
+        <el-main>
+            <el-row>
+                <el-col :span="8" :offset="8">
+                    <h3 style="text-align: center">配置考试调卷规则</h3>
+
+                    <el-form label-position="left" label-width="80px" :model="curForm" ref="curForm" :rules="rules">
+                        <el-form-item label="考试ID" prop="examId">
+                            <el-input v-model="curForm.examId"></el-input>
+                        </el-form-item>
+
+                        <el-form-item label="课程代码" prop="courseCodes">
+                            <el-input v-model="curForm.courseCodes" placeholder="多个值逗号分隔"></el-input>
+                        </el-form-item>
+
+                        <el-form-item>
+                            <el-button type="primary" @click="doSubmit" round>确 认</el-button>
+                        </el-form-item>
+                    </el-form>
+                </el-col>
+            </el-row>
+        </el-main>
+    </el-container>
+</div>
+
+<script>
+    new Vue({
+        el: '#myVue',
+        data: {
+            curForm: {
+                examId: null,
+                courseCodes: null,
+            },
+            rules: {
+                examId: [
+                    {required: true, message: '请输入考试ID', trigger: 'blur'}
+                ]
+            }
+        },
+        methods: {
+            doSubmit() {
+                this.$refs.curForm.validate((valid) => {
+                    if (!valid) {
+                        return false;
+                    }
+
+                    let req = {
+                        type: "CONFIG_EXAM_PAPER",
+                        examId: this.curForm.examId,
+                        params: JSON.stringify(this.curForm)
+                    };
+
+                    let url = "${base}/api/task/add";
+                    axios.post(url, req).then((response) => {
+                        this.$notify({
+                            message: "保存成功!",
+                            type: "success",
+                        });
+
+                        window.location.href = '${base}/admin/taskList';
+                    }).catch((error) => {
+                        this.$notify({
+                            message: error.response.data.message,
+                            type: "error",
+                        });
+                    });
+                });
+            }
+        }
+    });
+</script>
+</body>
+</html>

+ 4 - 2
src/main/resources/templates/admin/taskList.ftlh

@@ -29,7 +29,8 @@
                     </el-form-item>
 
                     <el-form-item>
-                        <el-button size="small" type="primary" icon="el-icon-search" @click="doSearch(1)">查询</el-button>
+                        <el-button size="small" type="primary" icon="el-icon-search" @click="doSearch(1)">查询
+                        </el-button>
                     </el-form-item>
                 </el-form>
 
@@ -98,7 +99,8 @@
             totalElements: 0,
             taskTypes: [
                 {label: "导出考生试题作答和得分明细", value: "EXPORT_STUDENT_ANSWER_AND_SCORE_DETAIL"},
-                {label: "更新正确答案并重新算分", value: "UPDATE_CORRECT_ANSWER_AND_RE_FIX_SCORE"}
+                {label: "更新正确答案并重新算分", value: "UPDATE_CORRECT_ANSWER_AND_RE_FIX_SCORE"},
+                {label: "配置考试调卷规则", value: "CONFIG_EXAM_PAPER"}
             ],
             taskStatuses: [
                 {label: "等待处理", value: "WAITING"},

+ 15 - 5
src/main/resources/templates/admin/workspace.ftlh

@@ -11,17 +11,27 @@
         <#include "../layout/topMenu.ftlh"/>
 
         <el-main>
-            <div style="margin: 50px 0px 0px 0px">
+            <div style="margin: 20px 0px 0px 0px">
                 <el-row :gutter="10">
-                    <el-col :span="10">
+                    <el-col :span="8">
                         <el-card shadow="hover">
-                            <el-link href="${base}/admin/exportStudentAnswerAndScoreDetail">导出考生试题作答和得分明细</el-link>
+                            <el-link href="${base}/admin/exportStudentAnswerAndScoreDetail">导出考生试题作答和得分明细
+                            </el-link>
                         </el-card>
                     </el-col>
 
-                    <el-col :span="10">
+                    <el-col :span="8">
                         <el-card shadow="hover">
-                            <el-link href="${base}/admin/updateCorrectAnswerAndReFixScore">更新正确答案并重新算分</el-link>
+                            <el-link href="${base}/admin/updateCorrectAnswerAndReFixScore">更新正确答案并重新算分
+                            </el-link>
+                        </el-card>
+                    </el-col>
+                </el-row>
+
+                <el-row :gutter="10" style="margin-top: 10px">
+                    <el-col :span="8">
+                        <el-card shadow="hover">
+                            <el-link href="${base}/admin/configExamPaper">配置考试调卷规则</el-link>
                         </el-card>
                     </el-col>
                 </el-row>