|
@@ -4,10 +4,15 @@ 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.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.utils.StatusException;
|
|
|
+import cn.com.qmth.examcloud.tool.vo.Pager;
|
|
|
import cn.com.qmth.examcloud.tool.vo.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;
|
|
@@ -15,7 +20,9 @@ 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 UpdateCorrectAnswerAndReFixScoreTask {
|
|
@@ -68,7 +75,65 @@ public class UpdateCorrectAnswerAndReFixScoreTask {
|
|
|
}
|
|
|
|
|
|
public void process(Long examId, CourseVO course, User user) {
|
|
|
- // todo
|
|
|
+ List<ExamStudentVO> examStudents = this.getExamStudentList(user.getKey(), user.getToken(), examId, course.getCourseId());
|
|
|
+
|
|
|
+ for (ExamStudentVO examStudent : examStudents) {
|
|
|
+ // 按考生逐个更新正确答案并重新算分
|
|
|
+ this.fix(user.getKey(), user.getToken(), examId, course.getCourseId(), examStudent.getExamStudentId());
|
|
|
+ }
|
|
|
+
|
|
|
+ examStudents.clear();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void fix(String key, String token, Long examId, Long courseId, Long examStudentId) {
|
|
|
+ Map<String, String> params = new HashMap<>();
|
|
|
+ params.put("examId", String.valueOf(examId));
|
|
|
+ params.put("courseId", String.valueOf(courseId));
|
|
|
+ params.put("examStudentId", String.valueOf(examStudentId));
|
|
|
+
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("key", key);
|
|
|
+ headers.put("token", token);
|
|
|
+
|
|
|
+ String url = sysProperty.getServerUrl() + "/api/ecs_oe_admin/exam/score/updateCorrectAnswerAndReFixScore";
|
|
|
+ HttpHelper.get(url, headers, params);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取网考考生列表
|
|
|
+ */
|
|
|
+ private List<ExamStudentVO> getExamStudentList(String key, String token, 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", key);
|
|
|
+ headers.put("token", token);
|
|
|
+
|
|
|
+ String url = sysProperty.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;
|
|
|
}
|
|
|
|
|
|
}
|