deason 3 days ago
parent
commit
512d699056

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

@@ -5,6 +5,7 @@ import cn.com.qmth.examcloud.tool.config.SysProperty;
 import cn.com.qmth.examcloud.tool.service.batch_create_user.vo.RoleInfo;
 import cn.com.qmth.examcloud.tool.service.batch_create_user.vo.UserInfo;
 import cn.com.qmth.examcloud.tool.service.export_student_answer_and_score_detail.vo.CourseVO;
+import cn.com.qmth.examcloud.tool.service.update_correct_answer_and_re_fix_score.vo.ExamStudentVO;
 import cn.com.qmth.examcloud.tool.utils.HttpHelper;
 import cn.com.qmth.examcloud.tool.utils.JsonMapper;
 import cn.com.qmth.examcloud.tool.vo.Pager;
@@ -232,4 +233,47 @@ public class CommonService {
         return null;
     }
 
+    /**
+     * 获取网考考生列表
+     */
+    public List<ExamStudentVO> getExamStudentList(User loginUser, Long examId, Long courseId, String identityNumber) {
+        Map<String, Object> params = new HashMap<>();
+        params.put("examId", examId);
+        if (courseId != null) {
+            params.put("courseId", courseId);
+        }
+        if (StringUtils.isNotBlank(identityNumber)) {
+            params.put("identityNumber", identityNumber);
+        }
+        params.put("pageSize", 500);
+
+        Map<String, String> headers = new HashMap<>();
+        headers.put("key", loginUser.getKey());
+        headers.put("token", loginUser.getToken());
+
+        String url = loginUser.getServerUrl() + "/api/ecs_oe_admin/exam/student/simple/list";
+        List<ExamStudentVO> all = new ArrayList<>();
+        JsonMapper jsonMapper = new JsonMapper();
+
+        int sum = 0, pageNo = 0;
+        while (true) {
+            params.put("pageNo", ++pageNo);
+            String json = HttpHelper.post(url, headers, params);
+
+            Pager<ExamStudentVO> page = jsonMapper.parseJson(json, new TypeReference<Pager<ExamStudentVO>>() {
+
+            });
+            if (page == null || CollectionUtils.isEmpty(page.getContent())) {
+                break;
+            }
+            all.addAll(page.getContent());
+
+            sum += page.getContent().size();
+            float rate = sum * 100f / page.getTotalElements();
+            log.info("examId:{} courseId:{} 已获取考生数:{} 进度:{}%", examId, courseId, sum, rate);
+        }
+
+        return all;
+    }
+
 }

+ 75 - 0
src/main/java/cn/com/qmth/examcloud/tool/service/batch_delete_exam_student/BatchDeleteExamStudentTask.java

@@ -0,0 +1,75 @@
+package cn.com.qmth.examcloud.tool.service.batch_delete_exam_student;
+
+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.TaskService;
+import cn.com.qmth.examcloud.tool.service.batch_delete_exam_student.vo.ExamStudentExcelVO;
+import cn.com.qmth.examcloud.tool.service.update_correct_answer_and_re_fix_score.vo.ExamStudentVO;
+import cn.com.qmth.examcloud.tool.vo.user.User;
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.context.AnalysisContext;
+import com.alibaba.excel.event.AnalysisEventListener;
+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 BatchDeleteExamStudentTask implements TaskService {
+
+    private final static Logger log = LoggerFactory.getLogger(BatchDeleteExamStudentTask.class);
+
+    @Autowired
+    private SysProperty sysProperty;
+
+    @Autowired
+    private CommonService commonService;
+
+    @Override
+    public void start(TaskEntity task) {
+        // this.execute(loginUser, task);
+    }
+
+    /**
+     * 批量删除某个考试的考生列表
+     */
+    public void deleteExamStudentForExcel(User loginUser) {
+        String dataFilePath = "D:/home/data/delete_exam_students.xlsx";
+
+        long startTime = System.currentTimeMillis();
+        List<ExamStudentExcelVO> list = new ArrayList<>();
+        try {
+            EasyExcel.read(dataFilePath, ExamStudentExcelVO.class, new AnalysisEventListener<ExamStudentExcelVO>() {
+                        @Override
+                        public void invoke(ExamStudentExcelVO data, AnalysisContext analysisContext) {
+                            list.add(data);
+                        }
+
+                        @Override
+                        public void doAfterAllAnalysed(AnalysisContext analysisContext) {
+                            // ignore
+                        }
+                    }
+            ).sheet().doRead();
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            throw new RuntimeException("Excel内容解析错误,请使用标准模板!");
+        }
+
+        log.info("待删除条数:{}", list.size());
+
+        for (ExamStudentExcelVO vo : list) {
+            List<ExamStudentVO> examStudents = commonService.getExamStudentList(loginUser, vo.getExamId(), null, vo.getIdentityNumber());
+            for (ExamStudentVO examStudent : examStudents) {
+                log.info("examId:{} identityNumber:{} examStudentId:{}", examStudent.getExamId(), examStudent.getIdentityNumber(), examStudent.getExamStudentId());
+            }
+        }
+
+        log.info("删除完成,耗时:{}ms", System.currentTimeMillis() - startTime);
+    }
+
+}

+ 23 - 0
src/main/java/cn/com/qmth/examcloud/tool/service/batch_delete_exam_student/vo/ExamStudentExcelVO.java

@@ -0,0 +1,23 @@
+package cn.com.qmth.examcloud.tool.service.batch_delete_exam_student.vo;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.io.Serializable;
+
+@Setter
+@Getter
+public class ExamStudentExcelVO implements Serializable {
+
+    private static final long serialVersionUID = -4647126917276922968L;
+
+    @ExcelProperty(value = "考试ID", index = 0)
+    private Long examId;
+
+    @ExcelProperty(value = "身份证号", index = 1)
+    private String identityNumber;
+
+    private Long examStudentId;
+
+}

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

@@ -10,11 +10,8 @@ import cn.com.qmth.examcloud.tool.service.update_correct_answer_and_re_fix_score
 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.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -96,7 +93,7 @@ public class UpdateCorrectAnswerAndReFixScoreTask implements TaskService {
 
     public void process(User loginUser, Long examId, CourseVO course, String questionIds,
                         Boolean updateObjectiveAnswer, Boolean updateObjectiveScore, Boolean updateSubjectiveScore) {
-        List<ExamStudentVO> examStudents = this.getExamStudentList(loginUser, examId, course.getCourseId());
+        List<ExamStudentVO> examStudents = commonService.getExamStudentList(loginUser, examId, course.getCourseId(), null);
 
         int index = 0, total = examStudents.size();
         for (ExamStudentVO examStudent : examStudents) {
@@ -137,42 +134,4 @@ public class UpdateCorrectAnswerAndReFixScoreTask implements TaskService {
         HttpHelper.post(url, headers, params);
     }
 
-    /**
-     * 获取网考考生列表
-     */
-    private List<ExamStudentVO> getExamStudentList(User loginUser, Long examId, Long courseId) {
-        Map<String, Object> params = new HashMap<>();
-        params.put("examId", examId);
-        params.put("courseId", courseId);
-        params.put("pageSize", 500);
-
-        Map<String, String> headers = new HashMap<>();
-        headers.put("key", loginUser.getKey());
-        headers.put("token", loginUser.getToken());
-
-        String url = loginUser.getServerUrl() + "/api/ecs_oe_admin/exam/student/simple/list";
-        List<ExamStudentVO> all = new ArrayList<>();
-        JsonMapper jsonMapper = new JsonMapper();
-
-        int sum = 0, pageNo = 0;
-        while (true) {
-            params.put("pageNo", ++pageNo);
-            String json = HttpHelper.post(url, headers, params);
-
-            Pager<ExamStudentVO> page = jsonMapper.parseJson(json, new TypeReference<Pager<ExamStudentVO>>() {
-
-            });
-            if (page == null || CollectionUtils.isEmpty(page.getContent())) {
-                break;
-            }
-            all.addAll(page.getContent());
-
-            sum += page.getContent().size();
-            float rate = sum * 100f / page.getTotalElements();
-            log.info("examId:{} courseId:{} 已获取考生数:{} 进度:{}%", examId, courseId, sum, rate);
-        }
-
-        return all;
-    }
-
 }

+ 7 - 2
src/test/java/cn/com/qmth/examcloud/tool/ToolTest.java

@@ -4,6 +4,7 @@ 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.batch_delete_exam_student.BatchDeleteExamStudentTask;
 import cn.com.qmth.examcloud.tool.service.exam_record_data_audit.ExamRecordDataAuditTask;
 import cn.com.qmth.examcloud.tool.service.export_exam_capture.ExportExamCaptureTask;
 import cn.com.qmth.examcloud.tool.service.export_exam_paper_struct.ExportExamPaperStructTask;
@@ -37,6 +38,9 @@ public class ToolTest {
     @Autowired
     private UnbindStudentCodeTask unbindStudentCodeTask;
 
+    @Autowired
+    private BatchDeleteExamStudentTask batchDeleteExamStudentTask;
+
     @Autowired
     private ExportStudentPhotoTask exportStudentPhotoTask;
 
@@ -59,6 +63,7 @@ public class ToolTest {
         // resetStudentPasswordTask.execute(loginUser, 0L);
         // unbindStudentCodeTask.unbindStudentCodeForAll(loginUser);
         // unbindStudentCodeTask.unbindStudentCodeForExcel(loginUser);
+        // batchDeleteExamStudentTask.deleteExamStudentForExcel(loginUser);
         // exportExamPaperStructTask.execute(loginUser, 0L, DATA_DIR);
         // examRecordDataAuditTask.execute(loginUser);
         // exportStudentPhotoTask.execute(null, DATA_DIR);
@@ -87,8 +92,8 @@ public class ToolTest {
     }
 
     private User doLogin() {
-        // String serverUrl = "d0.dev39.qmth.com.cn";
-        String serverUrl = "t0.test41.qmth.com.cn";
+        String serverUrl = "d0.dev39.qmth.com.cn";
+        // String serverUrl = "t0.test41.qmth.com.cn";
         // String serverUrl = "ecs-test.ea100.com.cn";
         // String serverUrl = "exam.exam-cloud.cn";