Explorar el Código

Merge remote-tracking branch 'origin/release_v5.0.6'

deason hace 1 semana
padre
commit
e44af9edbe

+ 328 - 310
examcloud-core-oe-admin-api-provider/src/main/java/cn/com/qmth/examcloud/core/oe/admin/api/provider/ExamRecordForMarkingCloudServiceProvider.java

@@ -10,7 +10,6 @@ import java.util.stream.Collectors;
 
 import javax.persistence.criteria.Predicate;
 
-import cn.com.qmth.examcloud.support.fss.FssHelper;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -56,6 +55,7 @@ import cn.com.qmth.examcloud.core.oe.admin.dao.entity.ExamRecordForMarkingEntity
 import cn.com.qmth.examcloud.core.oe.admin.dao.entity.ExamStudentEntity;
 import cn.com.qmth.examcloud.core.oe.admin.service.ExamRecordForMarkingService;
 import cn.com.qmth.examcloud.core.oe.admin.service.ExamRecordQuestionsService;
+import cn.com.qmth.examcloud.support.fss.FssHelper;
 import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
 import cn.com.qmth.examcloud.web.support.ControllerSupport;
 import io.swagger.annotations.Api;
@@ -71,314 +71,332 @@ import io.swagger.annotations.ApiOperation;
 @RestController
 @RequestMapping("${$rmp.cloud.oe}/examRecordForMarking")
 public class ExamRecordForMarkingCloudServiceProvider extends ControllerSupport
-		implements ExamRecordForMarkingCloudService {
-
-	private static final long serialVersionUID = -8343697288418890873L;
-	@Autowired
-	private JdbcTemplate jdbcTemplate;
-	@Autowired
-	private ExamRecordForMarkingService examRecordForMarkingService;
-
-	@Autowired
-	private ExamStudentRepo examStudentRepo;
-
-	@Autowired
-	private ExamRecordDataRepo examRecordDataRepo;
-
-	@Autowired
-	private ExamRecordForMarkingRepo examRecordForMarkingRepo;
-
-	@Autowired
-	private ExamRecordQuestionsService examRecordQuestionsService;
-
-	@Autowired
-	private ExamRecordFileAnswerRepo examRecordFileAnswerRepo;
-
-	@Override
-	@ApiOperation(value = "根据条件查询阅卷需要的信息")
-	@PostMapping("/findExamRecordForMarkingInfo")
-	public FindExamRecordForMarkingInfoResp findExamRecordForMarkingInfo(
-			@RequestBody FindExamRecordForMarkingInfoReq req) {
-		Long id = req.getId();
-		Long examId = req.getExamId();
-		FindExamRecordForMarkingInfoResp resp = new FindExamRecordForMarkingInfoResp();
-		if (id == null && examId == null) {
-			return resp;
-		}
-
-		List<ExamRecordForMarkingEntity> examRecordForMarkingList = examRecordForMarkingService
-				.findExamRecordForMarkingInfo(id, examId, req.getCourseId(), req.getBatchNum());
-		List<ExamRecordForMarkingBean> examRecordForMarkingBeanList = new ArrayList<>();
-		for (ExamRecordForMarkingEntity entity : examRecordForMarkingList) {
-			ExamRecordForMarkingBean examRecordForMarkingBean = new ExamRecordForMarkingBean();
-			examRecordForMarkingBean.setId(entity.getId());
-			examRecordForMarkingBean.setExamId(entity.getExamId());
-			examRecordForMarkingBean.setBasePaperId(entity.getBasePaperId());
-			examRecordForMarkingBean.setPaperType(entity.getPaperType());
-			examRecordForMarkingBean.setCourseId(entity.getCourseId());
-
-			if (entity.getExamRecordDataId() == null) {
-				throw new StatusException("500101", "阅卷信息错误,考试记录ID存在空值!");
-			}
-
-			long examRecordDataId = entity.getExamRecordDataId();
-			List<ExamRecordFileAnswerEntity> fileAnswerList = examRecordFileAnswerRepo
-					.findByExamRecordDataId(examRecordDataId);
-			if (fileAnswerList != null) {
-				examRecordForMarkingBean.setOfflineFiles(getOfflineFilesFrom(fileAnswerList));
-			}
-
-			examRecordForMarkingBean.setBatchNum(entity.getBatchNum());
-			examRecordForMarkingBeanList.add(examRecordForMarkingBean);
-		}
-
-		resp.setExamRecordForMarkingBeanList(examRecordForMarkingBeanList);
-		return resp;
-	}
-
-	private List<ExamRecordFileAnswerBean> getOfflineFilesFrom(List<ExamRecordFileAnswerEntity> fileAnswerList) {
-		List<ExamRecordFileAnswerBean> resultList = new ArrayList<>();
-		for (ExamRecordFileAnswerEntity entity : fileAnswerList) {
-			ExamRecordFileAnswerBean bean = new ExamRecordFileAnswerBean();
-			bean.setId(entity.getId());
-			bean.setExamRecordDataId(entity.getExamRecordDataId());
-
-			bean.setOfflineFileUrl(FssHelper.finalFileUrl(entity.getFileUrl()));
-
-			bean.setOfflineFileName(entity.getFileName());
-			bean.setOriginalFileName(entity.getOriginalFileName());
-			bean.setFileType(entity.getFileType());
-			bean.setSuffix(entity.getSuffix());
-			bean.setProperties(entity.getProperties());
-			resultList.add(bean);
-		}
-
-		return resultList;
-	}
-
-	@Override
-	@ApiOperation(value = "查询有效成绩")
-	@PostMapping("/queryValidExamRecordInfo")
-	public QueryValidExamRecordInfoResp queryValidExamRecordInfo(@RequestBody QueryValidExamRecordInfoReq req) {
-		Check.isNull(req.getExamId(), "examId不能为空");
-		Check.isNull(req.getCourseId(), "courseId不能为空");
-		List<ExamRecordForMarkingEntity> examRecordForMarkingList = examRecordForMarkingService
-				.queryValidExamRecordList(req.getExamId(), req.getCourseId());
-
-		QueryValidExamRecordInfoResp resp = new QueryValidExamRecordInfoResp();
-		List<ExamRecordForMarkingBean> examRecordForMarkingBeanList = new ArrayList<ExamRecordForMarkingBean>();
-		for (ExamRecordForMarkingEntity entity : examRecordForMarkingList) {
-			ExamRecordForMarkingBean examRecordForMarkingBean = new ExamRecordForMarkingBean();
-			examRecordForMarkingBean.setId(entity.getId());
-			examRecordForMarkingBean.setExamId(entity.getExamId());
-			examRecordForMarkingBean.setExamRecordDataId(entity.getExamRecordDataId());
-			examRecordForMarkingBean.setExamStudentId(entity.getExamStudentId());
-			examRecordForMarkingBean.setBasePaperId(entity.getBasePaperId());
-			examRecordForMarkingBean.setPaperType(entity.getPaperType());
-			examRecordForMarkingBean.setCourseId(entity.getCourseId());
-			examRecordForMarkingBean.setObjectiveScore(entity.getObjectiveScore());
-			examRecordForMarkingBeanList.add(examRecordForMarkingBean);
-		}
-		resp.setExamRecordForMarkingBeanList(examRecordForMarkingBeanList);
-		return resp;
-	}
-
-	@Override
-	@ApiOperation(value = "分页查询有效成绩")
-	@PostMapping("/queryValidExamRecordInfoPage")
-	public QueryValidExamRecordInfoPageResp queryValidExamRecordInfoPage(
-			@RequestBody QueryValidExamRecordInfoPageReq req) {
-		Check.isNull(req.getExamId(), "examId不能为空");
-		Check.isNull(req.getCourseId(), "courseId不能为空");
-		Check.isNull(req.getStart(), "start不能为空");
-		Check.isNull(req.getSize(), "size不能为空");
-		if (req.getStart().longValue() <= 0) {
-			throw new StatusException(OE_CODE_400, "start必须大于0");
-		}
-		if (req.getSize().longValue() <= 0) {
-			throw new StatusException(OE_CODE_400, "size必须大于0");
-		}
-		Long courseId = req.getCourseId();
-		Long examId = req.getExamId();
-		Long size = req.getSize();
-		Long start = req.getStart();
-		// 分页获取考生id
-		Pageable pageable = PageRequest.of(0, size.intValue(), Sort.Direction.ASC, "id");
-
-		Specification<ExamStudentEntity> specification = (root, query, cb) -> {
-			List<Predicate> predicates = new ArrayList<>();
-			predicates.add(cb.equal(root.get("examId"), examId));
-			predicates.add(cb.equal(root.get("courseId"), courseId));
-			predicates.add(cb.greaterThanOrEqualTo(root.get("id"), start));
-			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
-		};
-
-		Page<ExamStudentEntity> page = examStudentRepo.findAll(specification, pageable);
-
-		Iterator<ExamStudentEntity> iterator = page.iterator();
-
-		List<Long> stuIdList = Lists.newArrayList();
-		Long next = start;
-		while (iterator.hasNext()) {
-			ExamStudentEntity e = iterator.next();
-			next = e.getId();
-			stuIdList.add(e.getExamStudentId());
-		}
-
-		QueryValidExamRecordInfoPageResp resp = new QueryValidExamRecordInfoPageResp();
-		if (!next.equals(start)) {
-			next++;
-		}
-		resp.setNext(next);
-		// 根据分页获取的考生id获取需要阅卷的试卷
-		List<ExamRecordForMarkingBean> examRecordForMarkingBeanList = new ArrayList<ExamRecordForMarkingBean>();
-		if (stuIdList.size() > 0) {
-			List<ExamRecordForMarkingEntity> examRecordForMarkingList = examRecordForMarkingService
-					.queryValidExamRecordInfoByStuIds(examId, courseId, stuIdList, req.getBatchNum());
-
-			if (CollectionUtils.isEmpty(examRecordForMarkingList)) {
-				resp.setExamRecordForMarkingBeanList(examRecordForMarkingBeanList);
-				return resp;
-			}
-
-			for (ExamRecordForMarkingEntity entity : examRecordForMarkingList) {
-				ExamRecordForMarkingBean examRecordForMarkingBean = new ExamRecordForMarkingBean();
-				examRecordForMarkingBean.setId(entity.getId());
-				examRecordForMarkingBean.setExamId(entity.getExamId());
-				examRecordForMarkingBean.setExamRecordDataId(entity.getExamRecordDataId());
-				examRecordForMarkingBean.setExamStudentId(entity.getExamStudentId());
-				examRecordForMarkingBean.setBasePaperId(entity.getBasePaperId());
-				examRecordForMarkingBean.setPaperType(entity.getPaperType());
-				examRecordForMarkingBean.setCourseId(entity.getCourseId());
-				examRecordForMarkingBean.setObjectiveScore(entity.getObjectiveScore());
-				examRecordForMarkingBean.setBatchNum(entity.getBatchNum());
-				examRecordForMarkingBeanList.add(examRecordForMarkingBean);
-			}
-			fillTatolScoreAndOtherInfo(examRecordForMarkingBeanList);
-		}
-		resp.setExamRecordForMarkingBeanList(examRecordForMarkingBeanList);
-		return resp;
-	}
-
-	private void fillTatolScoreAndOtherInfo(List<ExamRecordForMarkingBean> list) {
-		RowMapper<ExamRecordDataTotalScoreVo> rowMapper = new BeanPropertyRowMapper<>(ExamRecordDataTotalScoreVo.class);
-		StringBuilder sb = new StringBuilder(
-				"select t.id,t.paper_score totalScore,random_paper randomPaper from ec_oe_exam_record_data t where t.id in (");
-		List<Long> ids = list.stream().map(e -> e.getExamRecordDataId()).collect(Collectors.toList());
-		sb.append(StringUtils.join(ids, ","));
-		sb.append(")");
-		List<ExamRecordDataTotalScoreVo> dtos = jdbcTemplate.query(sb.toString(), rowMapper);
-		Map<Long, ExamRecordDataTotalScoreVo> totalScores = dtos.stream().collect(Collectors.toMap(e -> e.getId(), e -> e));
-		for(ExamRecordForMarkingBean b:list) {
-			b.setTotalScore(totalScores.get(b.getExamRecordDataId()).getTotalScore());
-			b.setRandomPaper(totalScores.get(b.getExamRecordDataId()).getRandomPaper());
-		}
-	}
-
-	/**
-	 * 获取单个考试记录信息
-	 *
-	 * @param req
-	 * @return
-	 */
-	@Override
-	@PostMapping("/getSingleExamRecordData")
-	public GetSingleExamRecordDataResp getSingleExamRecordData(@RequestBody GetSingleExamRecordDataReq req) {
-		Check.isNull(req.getId(), "id不能为空");
-		ExamRecordDataEntity entity = GlobalHelper.getEntity(examRecordDataRepo, req.getId(),
-				ExamRecordDataEntity.class);
-		if (entity == null) {
-			return new GetSingleExamRecordDataResp();
-		}
-
-		return copyGetSingleExamRecordDataRespFrom(entity);
-	}
-
-	private GetSingleExamRecordDataResp copyGetSingleExamRecordDataRespFrom(ExamRecordDataEntity entity) {
-		GetSingleExamRecordDataResp resp = new GetSingleExamRecordDataResp();
-
-		ExamRecordDataBean data = new ExamRecordDataBean();
-		data.setId(entity.getId());
-		data.setExamId(entity.getExamId());
-		data.setExamType(entity.getExamType() == null ? null : entity.getExamType().toString());
-		data.setExamStudentId(entity.getExamStudentId());
-		data.setStudentId(entity.getStudentId());
-		data.setStudentCode(entity.getStudentCode());
-		data.setStudentName(entity.getStudentName());
-		data.setIdentityNumber(entity.getIdentityNumber());
-		data.setCourseId(entity.getCourseId());
-		data.setCourseLevel(entity.getCourseLevel());
-		data.setOrgId(entity.getOrgId());
-		data.setRootOrgId(entity.getRootOrgId());
-		data.setBasePaperId(entity.getBasePaperId());
-		data.setPaperType(entity.getPaperType());
-		data.setPaperStructId(entity.getPaperStructId());
-		data.setInfoCollector(entity.getInfoCollector());
-		data.setExamRecordQuestionsId(entity.getExamRecordQuestionsId());
-		data.setExamRecordStatus(entity.getExamRecordStatus() == null ? null : entity.getExamRecordStatus().toString());
-		data.setStartTime(entity.getStartTime());
-		data.setEndTime(entity.getEndTime());
-		data.setCleanTime(entity.getCleanTime());
-		data.setWarn(entity.getIsWarn());
-		data.setAudit(entity.getIsAudit());
-		data.setIllegality(entity.getIsIllegality());
-		data.setUsedExamTime(entity.getUsedExamTime());
-		data.setExamOrder(entity.getExamOrder());
-		data.setReexamine(entity.getIsReexamine());
-		data.setContinued(entity.getIsContinued());
-		data.setAllObjectivePaper(entity.getIsAllObjectivePaper());
-		data.setContinuedCount(entity.getContinuedCount());
-		data.setExceed(entity.getIsExceed());
-		data.setFaceSuccessCount(entity.getFaceSuccessCount());
-		data.setFaceFailedCount(entity.getFaceFailedCount());
-		data.setFaceStrangerCount(entity.getFaceStrangerCount());
-		data.setFaceTotalCount(entity.getFaceTotalCount());
-		data.setFaceSuccessPercent(entity.getFaceSuccessPercent());
-		data.setFaceVerifyResult(entity.getFaceVerifyResult() == null ? null : entity.getFaceVerifyResult().toString());
-		data.setBaiduFaceLivenessSuccessPercent(entity.getBaiduFaceLivenessSuccessPercent());
-		data.setFaceLandmarkVal(entity.getFaceLandmarkVal());
-		data.setRandomPaper(entity.getRandomPaper());
-		data.setPaperScore(entity.getPaperScore());
-
-		resp.setData(data);
-		return resp;
-	}
-
-	@Override
-	@PostMapping("/updateExamRecordForMarkingBatchNum")
-	public void updateExamRecordForMarkingBatchNum(@RequestBody UpdateExamRecordForMarkingBatchNumReq req) {
-		if (req.getIdList() == null || req.getIdList().isEmpty()) {
-			throw new StatusException("222001", "阅卷原始数据表id不允许为空");
-		}
-		if (req.getIdList().size() > 100) {
-			throw new StatusException("222002", "阅卷原始数据表id集合最大不得超过100条");
-		}
-		if (StringUtils.isBlank(req.getBatchNum())) {
-			throw new StatusException("222003", "批次号不允许为空");
-		}
-		examRecordForMarkingRepo.updateBatchNum(req.getIdList(), req.getBatchNum());
-	}
-
-	@Override
-	@PostMapping("/saveExamRecordForMarking")
-	public void saveExamRecordForMarking(@RequestBody SaveExamRecordForMarkingReq req) {
-		ExamRecordForMarkingEntity examRecordForMarkingExists = examRecordForMarkingRepo
-				.findByExamRecordDataId(req.getExamRecordDataId());
-		if (examRecordForMarkingExists != null) {
-			return;
-		}
-		ExamRecordForMarkingEntity examRecordForMarking = new ExamRecordForMarkingEntity();
-		examRecordForMarking.setExamId(req.getExamId());
-		examRecordForMarking.setExamRecordDataId(req.getExamRecordDataId());
-		examRecordForMarking.setExamStudentId(req.getExamStudentId());
-		examRecordForMarking.setBasePaperId(req.getBasePaperId());
-		examRecordForMarking.setPaperType(req.getPaperType());
-		examRecordForMarking.setCourseId(req.getCourseId());
-		examRecordForMarking.setObjectiveScore(req.getObjectiveScore());
-		int subjectiveAnswerLength = examRecordQuestionsService
-				.calculationSubjectiveAnswerLength(req.getExamRecordDataId());
-		examRecordForMarking.setSubjectiveAnswerLength(subjectiveAnswerLength);
-		examRecordForMarkingRepo.save(examRecordForMarking);
-	}
+        implements ExamRecordForMarkingCloudService {
+
+    private static final long serialVersionUID = -8343697288418890873L;
+
+    @Autowired
+    private JdbcTemplate jdbcTemplate;
+
+    @Autowired
+    private ExamRecordForMarkingService examRecordForMarkingService;
+
+    @Autowired
+    private ExamStudentRepo examStudentRepo;
+
+    @Autowired
+    private ExamRecordDataRepo examRecordDataRepo;
+
+    @Autowired
+    private ExamRecordForMarkingRepo examRecordForMarkingRepo;
+
+    @Autowired
+    private ExamRecordQuestionsService examRecordQuestionsService;
+
+    @Autowired
+    private ExamRecordFileAnswerRepo examRecordFileAnswerRepo;
+
+    @Override
+    @ApiOperation(value = "根据条件查询阅卷需要的信息")
+    @PostMapping("/findExamRecordForMarkingInfo")
+    public FindExamRecordForMarkingInfoResp findExamRecordForMarkingInfo(
+            @RequestBody FindExamRecordForMarkingInfoReq req) {
+        Long id = req.getId();
+        Long examId = req.getExamId();
+        FindExamRecordForMarkingInfoResp resp = new FindExamRecordForMarkingInfoResp();
+        if (id == null && examId == null) {
+            return resp;
+        }
+
+        List<ExamRecordForMarkingBean> examRecordForMarkingList = examRecordForMarkingService
+                .findExamRecordForMarkingInfo(id, examId, req.getCourseId(), req.getBatchNum(),
+                        req.getIncludeRandomPaper());
+        for (ExamRecordForMarkingBean examRecordForMarkingBean : examRecordForMarkingList) {
+            Long examRecordDataId = examRecordForMarkingBean.getExamRecordDataId();
+            if (examRecordDataId == null) {
+                throw new StatusException("500101", "阅卷信息错误,考试记录ID存在空值!");
+            }
+            List<ExamRecordFileAnswerEntity> fileAnswerList = examRecordFileAnswerRepo
+                    .findByExamRecordDataId(examRecordDataId);
+            if (fileAnswerList != null) {
+                examRecordForMarkingBean.setOfflineFiles(getOfflineFilesFrom(fileAnswerList));
+            }
+
+        }
+
+        resp.setExamRecordForMarkingBeanList(examRecordForMarkingList);
+        return resp;
+    }
+
+    private List<ExamRecordFileAnswerBean> getOfflineFilesFrom(List<ExamRecordFileAnswerEntity> fileAnswerList) {
+        List<ExamRecordFileAnswerBean> resultList = new ArrayList<>();
+        for (ExamRecordFileAnswerEntity entity : fileAnswerList) {
+            ExamRecordFileAnswerBean bean = new ExamRecordFileAnswerBean();
+            bean.setId(entity.getId());
+            bean.setExamRecordDataId(entity.getExamRecordDataId());
+
+            bean.setOfflineFileUrl(FssHelper.finalFileUrl(entity.getFileUrl()));
+
+            bean.setOfflineFileName(entity.getFileName());
+            bean.setOriginalFileName(entity.getOriginalFileName());
+            bean.setFileType(entity.getFileType());
+            bean.setSuffix(entity.getSuffix());
+            bean.setProperties(entity.getProperties());
+            resultList.add(bean);
+        }
+
+        return resultList;
+    }
+
+    @Override
+    @ApiOperation(value = "查询有效成绩")
+    @PostMapping("/queryValidExamRecordInfo")
+    public QueryValidExamRecordInfoResp queryValidExamRecordInfo(@RequestBody QueryValidExamRecordInfoReq req) {
+        Check.isNull(req.getExamId(), "examId不能为空");
+        Check.isNull(req.getCourseId(), "courseId不能为空");
+        List<ExamRecordForMarkingEntity> examRecordForMarkingList = examRecordForMarkingService
+                .queryValidExamRecordList(req.getExamId(), req.getCourseId());
+
+        QueryValidExamRecordInfoResp resp = new QueryValidExamRecordInfoResp();
+        List<ExamRecordForMarkingBean> examRecordForMarkingBeanList = new ArrayList<ExamRecordForMarkingBean>();
+        for (ExamRecordForMarkingEntity entity : examRecordForMarkingList) {
+            ExamRecordForMarkingBean examRecordForMarkingBean = new ExamRecordForMarkingBean();
+            examRecordForMarkingBean.setId(entity.getId());
+            examRecordForMarkingBean.setExamId(entity.getExamId());
+            examRecordForMarkingBean.setExamRecordDataId(entity.getExamRecordDataId());
+            examRecordForMarkingBean.setExamStudentId(entity.getExamStudentId());
+            examRecordForMarkingBean.setBasePaperId(entity.getBasePaperId());
+            examRecordForMarkingBean.setPaperType(entity.getPaperType());
+            examRecordForMarkingBean.setCourseId(entity.getCourseId());
+            examRecordForMarkingBean.setObjectiveScore(entity.getObjectiveScore());
+            examRecordForMarkingBeanList.add(examRecordForMarkingBean);
+        }
+        resp.setExamRecordForMarkingBeanList(examRecordForMarkingBeanList);
+        return resp;
+    }
+
+    @Override
+    @ApiOperation(value = "分页查询有效成绩")
+    @PostMapping("/queryValidExamRecordInfoPage")
+    public QueryValidExamRecordInfoPageResp queryValidExamRecordInfoPage(
+            @RequestBody QueryValidExamRecordInfoPageReq req) {
+        Check.isNull(req.getExamId(), "examId不能为空");
+        Check.isNull(req.getCourseId(), "courseId不能为空");
+        Check.isNull(req.getStart(), "start不能为空");
+        Check.isNull(req.getSize(), "size不能为空");
+        if (req.getStart().longValue() <= 0) {
+            throw new StatusException(OE_CODE_400, "start必须大于0");
+        }
+        if (req.getSize().longValue() <= 0) {
+            throw new StatusException(OE_CODE_400, "size必须大于0");
+        }
+        Long courseId = req.getCourseId();
+        Long examId = req.getExamId();
+        Long size = req.getSize();
+        Long start = req.getStart();
+        // 分页获取考生id
+        Pageable pageable = PageRequest.of(0, size.intValue(), Sort.Direction.ASC, "id");
+
+        Specification<ExamStudentEntity> specification = (root, query, cb) -> {
+            List<Predicate> predicates = new ArrayList<>();
+            predicates.add(cb.equal(root.get("examId"), examId));
+            predicates.add(cb.equal(root.get("courseId"), courseId));
+            predicates.add(cb.greaterThanOrEqualTo(root.get("id"), start));
+            return cb.and(predicates.toArray(new Predicate[predicates.size()]));
+        };
+
+        Page<ExamStudentEntity> page = examStudentRepo.findAll(specification, pageable);
+
+        Iterator<ExamStudentEntity> iterator = page.iterator();
+
+        List<Long> stuIdList = Lists.newArrayList();
+        Long next = start;
+        while (iterator.hasNext()) {
+            ExamStudentEntity e = iterator.next();
+            next = e.getId();
+            stuIdList.add(e.getExamStudentId());
+        }
+
+        QueryValidExamRecordInfoPageResp resp = new QueryValidExamRecordInfoPageResp();
+        if (!next.equals(start)) {
+            next++;
+        }
+        resp.setNext(next);
+        // 根据分页获取的考生id获取需要阅卷的试卷
+        List<ExamRecordForMarkingBean> examRecordForMarkingBeanList = new ArrayList<ExamRecordForMarkingBean>();
+        if (stuIdList.size() > 0) {
+            List<ExamRecordForMarkingEntity> examRecordForMarkingList = examRecordForMarkingService
+                    .queryValidExamRecordInfoByStuIds(examId, courseId, stuIdList, req.getBatchNum());
+
+            if (CollectionUtils.isEmpty(examRecordForMarkingList)) {
+                resp.setExamRecordForMarkingBeanList(examRecordForMarkingBeanList);
+                return resp;
+            }
+
+            for (ExamRecordForMarkingEntity entity : examRecordForMarkingList) {
+                ExamRecordForMarkingBean examRecordForMarkingBean = new ExamRecordForMarkingBean();
+                examRecordForMarkingBean.setId(entity.getId());
+                examRecordForMarkingBean.setExamId(entity.getExamId());
+                examRecordForMarkingBean.setExamRecordDataId(entity.getExamRecordDataId());
+                examRecordForMarkingBean.setExamStudentId(entity.getExamStudentId());
+                examRecordForMarkingBean.setBasePaperId(entity.getBasePaperId());
+                examRecordForMarkingBean.setPaperType(entity.getPaperType());
+                examRecordForMarkingBean.setCourseId(entity.getCourseId());
+                examRecordForMarkingBean.setObjectiveScore(entity.getObjectiveScore());
+                examRecordForMarkingBean.setBatchNum(entity.getBatchNum());
+                examRecordForMarkingBeanList.add(examRecordForMarkingBean);
+            }
+            fillTatolScoreAndOtherInfo(examRecordForMarkingBeanList);
+        }
+        resp.setExamRecordForMarkingBeanList(examRecordForMarkingBeanList);
+        return resp;
+    }
+
+    private void fillTatolScoreAndOtherInfo(List<ExamRecordForMarkingBean> list) {
+        RowMapper<ExamRecordDataTotalScoreVo> rowMapper = new BeanPropertyRowMapper<>(ExamRecordDataTotalScoreVo.class);
+        StringBuilder sb = new StringBuilder(
+                "select t.id,t.paper_score totalScore,random_paper randomPaper from ec_oe_exam_record_data t where t.id in (");
+        List<Long> ids = list.stream().map(e -> e.getExamRecordDataId()).collect(Collectors.toList());
+        sb.append(StringUtils.join(ids, ","));
+        sb.append(")");
+        List<ExamRecordDataTotalScoreVo> dtos = jdbcTemplate.query(sb.toString(), rowMapper);
+        Map<Long, ExamRecordDataTotalScoreVo> totalScores = dtos.stream()
+                .collect(Collectors.toMap(e -> e.getId(), e -> e));
+        for (ExamRecordForMarkingBean b : list) {
+            b.setTotalScore(totalScores.get(b.getExamRecordDataId()).getTotalScore());
+            b.setRandomPaper(totalScores.get(b.getExamRecordDataId()).getRandomPaper());
+        }
+    }
+
+    /**
+     * 获取单个考试记录信息
+     *
+     * @param req
+     * @return
+     */
+    @Override
+    @PostMapping("/getSingleExamRecordData")
+    public GetSingleExamRecordDataResp getSingleExamRecordData(@RequestBody GetSingleExamRecordDataReq req) {
+        Check.isNull(req.getId(), "id不能为空");
+        ExamRecordDataEntity entity = GlobalHelper.getEntity(examRecordDataRepo, req.getId(),
+                ExamRecordDataEntity.class);
+        if (entity == null) {
+            return new GetSingleExamRecordDataResp();
+        }
+
+        return copyGetSingleExamRecordDataRespFrom(entity);
+    }
+
+    private GetSingleExamRecordDataResp copyGetSingleExamRecordDataRespFrom(ExamRecordDataEntity entity) {
+        GetSingleExamRecordDataResp resp = new GetSingleExamRecordDataResp();
+
+        ExamRecordDataBean data = new ExamRecordDataBean();
+        data.setId(entity.getId());
+        data.setExamId(entity.getExamId());
+        data.setExamType(entity.getExamType() == null ? null : entity.getExamType().toString());
+        data.setExamStudentId(entity.getExamStudentId());
+        data.setStudentId(entity.getStudentId());
+        data.setStudentCode(entity.getStudentCode());
+        data.setStudentName(entity.getStudentName());
+        data.setIdentityNumber(entity.getIdentityNumber());
+        data.setCourseId(entity.getCourseId());
+        data.setCourseLevel(entity.getCourseLevel());
+        data.setOrgId(entity.getOrgId());
+        data.setRootOrgId(entity.getRootOrgId());
+        data.setBasePaperId(entity.getBasePaperId());
+        data.setPaperType(entity.getPaperType());
+        data.setPaperStructId(entity.getPaperStructId());
+        data.setInfoCollector(entity.getInfoCollector());
+        data.setExamRecordQuestionsId(entity.getExamRecordQuestionsId());
+        data.setExamRecordStatus(entity.getExamRecordStatus() == null ? null : entity.getExamRecordStatus().toString());
+        data.setStartTime(entity.getStartTime());
+        data.setEndTime(entity.getEndTime());
+        data.setCleanTime(entity.getCleanTime());
+        data.setWarn(entity.getIsWarn());
+        data.setAudit(entity.getIsAudit());
+        data.setIllegality(entity.getIsIllegality());
+        data.setUsedExamTime(entity.getUsedExamTime());
+        data.setExamOrder(entity.getExamOrder());
+        data.setReexamine(entity.getIsReexamine());
+        data.setContinued(entity.getIsContinued());
+        data.setAllObjectivePaper(entity.getIsAllObjectivePaper());
+        data.setContinuedCount(entity.getContinuedCount());
+        data.setExceed(entity.getIsExceed());
+        data.setFaceSuccessCount(entity.getFaceSuccessCount());
+        data.setFaceFailedCount(entity.getFaceFailedCount());
+        data.setFaceStrangerCount(entity.getFaceStrangerCount());
+        data.setFaceTotalCount(entity.getFaceTotalCount());
+        data.setFaceSuccessPercent(entity.getFaceSuccessPercent());
+        data.setFaceVerifyResult(entity.getFaceVerifyResult() == null ? null : entity.getFaceVerifyResult().toString());
+        data.setBaiduFaceLivenessSuccessPercent(entity.getBaiduFaceLivenessSuccessPercent());
+        data.setFaceLandmarkVal(entity.getFaceLandmarkVal());
+        data.setRandomPaper(entity.getRandomPaper());
+        data.setPaperScore(entity.getPaperScore());
+
+        resp.setData(data);
+        return resp;
+    }
+
+    @Override
+    @PostMapping("/updateExamRecordForMarkingBatchNum")
+    public void updateExamRecordForMarkingBatchNum(@RequestBody UpdateExamRecordForMarkingBatchNumReq req) {
+        if (req.getIdList() == null || req.getIdList().isEmpty()) {
+            throw new StatusException("222001", "阅卷原始数据表id不允许为空");
+        }
+        if (req.getIdList().size() > 100) {
+            throw new StatusException("222002", "阅卷原始数据表id集合最大不得超过100条");
+        }
+        if (StringUtils.isBlank(req.getBatchNum())) {
+            throw new StatusException("222003", "批次号不允许为空");
+        }
+        examRecordForMarkingRepo.updateBatchNum(req.getIdList(), req.getBatchNum());
+    }
+
+    @Override
+    @PostMapping("/saveExamRecordForMarking")
+    public void saveExamRecordForMarking(@RequestBody SaveExamRecordForMarkingReq req) {
+        ExamRecordForMarkingEntity examRecordForMarkingExists = examRecordForMarkingRepo
+                .findByExamRecordDataId(req.getExamRecordDataId());
+        if (examRecordForMarkingExists != null) {
+            return;
+        }
+        ExamRecordForMarkingEntity examRecordForMarking = new ExamRecordForMarkingEntity();
+        examRecordForMarking.setExamId(req.getExamId());
+        examRecordForMarking.setExamRecordDataId(req.getExamRecordDataId());
+        examRecordForMarking.setExamStudentId(req.getExamStudentId());
+        examRecordForMarking.setBasePaperId(req.getBasePaperId());
+        examRecordForMarking.setPaperType(req.getPaperType());
+        examRecordForMarking.setCourseId(req.getCourseId());
+        examRecordForMarking.setObjectiveScore(req.getObjectiveScore());
+        int subjectiveAnswerLength = examRecordQuestionsService
+                .calculationSubjectiveAnswerLength(req.getExamRecordDataId());
+        examRecordForMarking.setSubjectiveAnswerLength(subjectiveAnswerLength);
+        examRecordForMarkingRepo.save(examRecordForMarking);
+    }
+
+    // @ApiOperation(value = "根据条件查询阅卷需要的basepaperId")
+    // @Override
+    // @PostMapping("/findBasePaperForMarkWork")
+    // public FindBasePaperForMarkWorkResp findBasePaperForMarkWork(@RequestBody
+    // FindBasePaperForMarkWorkReq req) {
+    // Long id = req.getId();
+    // Long examId = req.getExamId();
+    // FindBasePaperForMarkWorkResp resp = new FindBasePaperForMarkWorkResp();
+    // if (id == null && examId == null) {
+    // return resp;
+    // }
+    //
+    // List<ExamRecordForMarkingEntity> examRecordForMarkingList =
+    // examRecordForMarkingService
+    // .findExamRecordForMarkingInfo(id, examId, req.getCourseId(),
+    // req.getBatchNum());
+    // Set<String> set = new HashSet<>();
+    // for (ExamRecordForMarkingEntity entity : examRecordForMarkingList) {
+    // set.add(entity.getBasePaperId());
+    // }
+    //
+    // resp.setBasePaperIds(set);
+    // return resp;
+    // }
 
 }

+ 10 - 5
examcloud-core-oe-admin-service/src/main/java/cn/com/qmth/examcloud/core/oe/admin/service/ExamRecordForMarkingService.java

@@ -1,10 +1,11 @@
 package cn.com.qmth.examcloud.core.oe.admin.service;
 
+import java.util.List;
+
+import cn.com.qmth.examcloud.core.oe.admin.api.bean.ExamRecordForMarkingBean;
 import cn.com.qmth.examcloud.core.oe.admin.dao.entity.ExamRecordForMarkingEntity;
 import cn.com.qmth.examcloud.core.oe.admin.service.bean.examrecord.ExamRecordDataBean;
 
-import java.util.List;
-
 /**
  * @author chenken
  * @date 2018年9月17日 下午3:57:58
@@ -27,10 +28,10 @@ public interface ExamRecordForMarkingService {
      * @param batchNum
      * @return
      */
-    List<ExamRecordForMarkingEntity> findExamRecordForMarkingInfo(Long id, Long examId, Long courseId, String batchNum);
+    List<ExamRecordForMarkingBean> findExamRecordForMarkingInfo(Long id, Long examId, Long courseId, String batchNum);
 
     List<ExamRecordForMarkingEntity> queryValidExamRecordInfoByStuIds(Long examId, Long courseId,
-                                                                      List<Long> examStudentIds, String batchNum);
+            List<Long> examStudentIds, String batchNum);
 
     /**
      * 离线考试-保存阅卷相关数据-对内
@@ -47,9 +48,13 @@ public interface ExamRecordForMarkingService {
     /**
      * 获取某个考生的有效考试记录
      *
-     * @param examStudentId 考生id集合
+     * @param examStudentId
+     *            考生id集合
      * @return
      */
     List<ExamRecordForMarkingEntity> queryValidExamRecordList(Long examStudentId);
 
+    List<ExamRecordForMarkingBean> findExamRecordForMarkingInfo(Long id, Long examId, Long courseId, String batchNum,
+            Boolean includeRandomPaper);
+
 }

+ 108 - 87
examcloud-core-oe-admin-service/src/main/java/cn/com/qmth/examcloud/core/oe/admin/service/impl/ExamRecordForMarkingServiceImpl.java

@@ -1,6 +1,23 @@
 package cn.com.qmth.examcloud.core.oe.admin.service.impl;
 
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.stream.Collectors;
+
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.stereotype.Service;
+
 import cn.com.qmth.examcloud.api.commons.enums.ExamType;
+import cn.com.qmth.examcloud.core.oe.admin.api.bean.ExamRecordForMarkingBean;
 import cn.com.qmth.examcloud.core.oe.admin.dao.ExamRecordDataRepo;
 import cn.com.qmth.examcloud.core.oe.admin.dao.ExamRecordForMarkingRepo;
 import cn.com.qmth.examcloud.core.oe.admin.dao.entity.ExamRecordDataEntity;
@@ -12,17 +29,6 @@ import cn.com.qmth.examcloud.core.oe.admin.service.bean.examrecord.ExamRecordDat
 import cn.com.qmth.examcloud.support.enums.ExamProperties;
 import cn.com.qmth.examcloud.support.helper.ExamCacheTransferHelper;
 import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.jdbc.core.RowMapper;
-import org.springframework.stereotype.Service;
-
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.*;
-import java.util.Map.Entry;
-import java.util.stream.Collectors;
 
 /**
  * @author chenken
@@ -46,25 +52,25 @@ public class ExamRecordForMarkingServiceImpl implements ExamRecordForMarkingServ
     private JdbcTemplate jdbcTemplate;
 
     @Override
-    public List<ExamRecordForMarkingEntity> queryValidExamRecordInfoByStuIds(
-            Long examId, Long courseId, List<Long> examStudentIds, String batchNum) {
+    public List<ExamRecordForMarkingEntity> queryValidExamRecordInfoByStuIds(Long examId, Long courseId,
+            List<Long> examStudentIds, String batchNum) {
         ExamType examType = getExamType(examId);
 
         List<ExamRecordForMarkingEntity> examRecordForMarkingList;
 
         String markingType = getMarkingType(examId);
         if (StringUtils.isEmpty(batchNum)) {
-            examRecordForMarkingList =
-                    examRecordForMarkingRepo.findByExamIdAndCourseIdAndExamStudentIds(examId, courseId, examStudentIds);
+            examRecordForMarkingList = examRecordForMarkingRepo.findByExamIdAndCourseIdAndExamStudentIds(examId,
+                    courseId, examStudentIds);
         } else {
-            if ((ExamType.ONLINE == examType || ExamType.ONLINE_HOMEWORK == examType) &&
-                    (MarkingType.OBJECT_SCORE_MAX.name().equals(markingType) ||
-                            MarkingType.LAST_SUBMIT.name().equals(markingType))) {
-                examRecordForMarkingList =
-                        examRecordForMarkingRepo.findByExamIdAndCourseIdAndExamStudentIds(examId, courseId, examStudentIds);
+            if ((ExamType.ONLINE == examType || ExamType.ONLINE_HOMEWORK == examType)
+                    && (MarkingType.OBJECT_SCORE_MAX.name().equals(markingType)
+                            || MarkingType.LAST_SUBMIT.name().equals(markingType))) {
+                examRecordForMarkingList = examRecordForMarkingRepo.findByExamIdAndCourseIdAndExamStudentIds(examId,
+                        courseId, examStudentIds);
             } else {
-                examRecordForMarkingList =
-                        examRecordForMarkingRepo.findByExamIdAndCourseIdAndExamStudentIdsAndBatchNum(examId, courseId, examStudentIds, batchNum);
+                examRecordForMarkingList = examRecordForMarkingRepo.findByExamIdAndCourseIdAndExamStudentIdsAndBatchNum(
+                        examId, courseId, examStudentIds, batchNum);
             }
         }
         if (examType == ExamType.OFFLINE) {
@@ -88,15 +94,16 @@ public class ExamRecordForMarkingServiceImpl implements ExamRecordForMarkingServ
      * @return
      */
     private String getMarkingType(Long examId) {
-        return ExamCacheTransferHelper.
-                getDefaultCachedExamProperty(examId, ExamProperties.MARKING_TYPE.name()).getValue();
+        return ExamCacheTransferHelper.getDefaultCachedExamProperty(examId, ExamProperties.MARKING_TYPE.name())
+                .getValue();
     }
 
     @Override
     public List<ExamRecordForMarkingEntity> queryValidExamRecordList(Long examId, Long courseId) {
         ExamType examType = getExamType(examId);
 
-        List<ExamRecordForMarkingEntity> examRecordForMarkingList = examRecordForMarkingRepo.findByExamIdAndCourseId(examId, courseId);
+        List<ExamRecordForMarkingEntity> examRecordForMarkingList = examRecordForMarkingRepo
+                .findByExamIdAndCourseId(examId, courseId);
         if (examType == ExamType.OFFLINE) {
             return examRecordForMarkingList;
         } else if (ExamType.ONLINE == examType || ExamType.ONLINE_HOMEWORK == examType) {
@@ -129,25 +136,28 @@ public class ExamRecordForMarkingServiceImpl implements ExamRecordForMarkingServ
      * @param examRecordForMarkingAllList
      * @return
      */
-    private List<ExamRecordForMarkingEntity> queryStudentPapersByLastSubmit(List<ExamRecordForMarkingEntity> examRecordForMarkingAllList) {
-        Map<Long, List<ExamRecordForMarkingEntity>> groupByExamStudentIdMap = groupByExamStudentId(examRecordForMarkingAllList);
-        Iterator<Entry<Long, List<ExamRecordForMarkingEntity>>> iterator = groupByExamStudentIdMap.entrySet().iterator();
+    private List<ExamRecordForMarkingEntity> queryStudentPapersByLastSubmit(
+            List<ExamRecordForMarkingEntity> examRecordForMarkingAllList) {
+        Map<Long, List<ExamRecordForMarkingEntity>> groupByExamStudentIdMap = groupByExamStudentId(
+                examRecordForMarkingAllList);
+        Iterator<Entry<Long, List<ExamRecordForMarkingEntity>>> iterator = groupByExamStudentIdMap.entrySet()
+                .iterator();
         List<ExamRecordForMarkingEntity> finalExamRecordForMarkingEntityList = new ArrayList<ExamRecordForMarkingEntity>();
         while (iterator.hasNext()) {
             Entry<Long, List<ExamRecordForMarkingEntity>> entry = iterator.next();
             List<ExamRecordForMarkingEntity> examRecordForMarkingList = entry.getValue();
-            List<ExamRecordForMarkingEntity> listSortByExamRecordDataId = examRecordForMarkingList.stream().sorted((p1, p2) -> p2.getExamRecordDataId().compareTo(p1.getExamRecordDataId())).collect(Collectors.toList());
+            List<ExamRecordForMarkingEntity> listSortByExamRecordDataId = examRecordForMarkingList.stream()
+                    .sorted((p1, p2) -> p2.getExamRecordDataId().compareTo(p1.getExamRecordDataId()))
+                    .collect(Collectors.toList());
             finalExamRecordForMarkingEntityList.add(listSortByExamRecordDataId.get(0));
         }
         /**
-         * 解决下面的问题:
-         *  当一个课程下设置两套试卷一套有主观题,一套没有主观题时,考试完成后给阅卷端传试卷时会传错,例如:
-         *	考试批次设置为取最后一次考试成绩;
-         *	在调卷规则中给课程A设置了两份试卷A1和A2,A1试卷中有主观题,A2试卷没有主观题;
-         *	考生AA在考试时,第一次抽取到了A1试卷,第二次抽取到了A2试卷;
-         *	考试完成后考生AA应该没有试卷传给阅卷端,但实际上系统将A1试卷传给了阅卷端
+         * 解决下面的问题: 当一个课程下设置两套试卷一套有主观题,一套没有主观题时,考试完成后给阅卷端传试卷时会传错,例如:
+         * 考试批次设置为取最后一次考试成绩; 在调卷规则中给课程A设置了两份试卷A1和A2,A1试卷中有主观题,A2试卷没有主观题;
+         * 考生AA在考试时,第一次抽取到了A1试卷,第二次抽取到了A2试卷;
+         * 考试完成后考生AA应该没有试卷传给阅卷端,但实际上系统将A1试卷传给了阅卷端
          */
-        //todo
+        // todo
         return finalExamRecordForMarkingEntityList;
     }
 
@@ -157,31 +167,37 @@ public class ExamRecordForMarkingServiceImpl implements ExamRecordForMarkingServ
      * @param examRecordForMarkingAllList
      * @return
      */
-    private List<ExamRecordForMarkingEntity> queryStudentPapersByObjectScoreMax(List<ExamRecordForMarkingEntity> examRecordForMarkingAllList) {
-        Map<Long, List<ExamRecordForMarkingEntity>> groupByExamStudentIdMap = groupByExamStudentId(examRecordForMarkingAllList);
-        Iterator<Entry<Long, List<ExamRecordForMarkingEntity>>> iterator = groupByExamStudentIdMap.entrySet().iterator();
+    private List<ExamRecordForMarkingEntity> queryStudentPapersByObjectScoreMax(
+            List<ExamRecordForMarkingEntity> examRecordForMarkingAllList) {
+        Map<Long, List<ExamRecordForMarkingEntity>> groupByExamStudentIdMap = groupByExamStudentId(
+                examRecordForMarkingAllList);
+        Iterator<Entry<Long, List<ExamRecordForMarkingEntity>>> iterator = groupByExamStudentIdMap.entrySet()
+                .iterator();
         List<ExamRecordForMarkingEntity> finalExamRecordForMarkingEntityList = new ArrayList<ExamRecordForMarkingEntity>();
         while (iterator.hasNext()) {
             Entry<Long, List<ExamRecordForMarkingEntity>> entry = iterator.next();
             List<ExamRecordForMarkingEntity> examRecordForMarkingList = entry.getValue();
-            //得出该考生的最高客观分
-            double maxObjectiveScore = examRecordForMarkingList.stream().sorted((p1, p2) -> p2.getObjectiveScore().compareTo(p1.getObjectiveScore()))
-                    .limit(1).findFirst().get().getObjectiveScore();
-            //过滤出最高分集合
-            List<ExamRecordForMarkingEntity> examRecordForMarkingByFilterList = examRecordForMarkingList.stream().filter(score -> {
-                return score.getObjectiveScore() == maxObjectiveScore;
-            }).collect(Collectors.toList());
-            //如果最高客观分的有多个,继续按主观题答案长度过滤
+            // 得出该考生的最高客观分
+            double maxObjectiveScore = examRecordForMarkingList.stream()
+                    .sorted((p1, p2) -> p2.getObjectiveScore().compareTo(p1.getObjectiveScore())).limit(1).findFirst()
+                    .get().getObjectiveScore();
+            // 过滤出最高分集合
+            List<ExamRecordForMarkingEntity> examRecordForMarkingByFilterList = examRecordForMarkingList.stream()
+                    .filter(score -> {
+                        return score.getObjectiveScore() == maxObjectiveScore;
+                    }).collect(Collectors.toList());
+            // 如果最高客观分的有多个,继续按主观题答案长度过滤
             if (examRecordForMarkingByFilterList.size() > 1) {
-                int maxAnswerLength = examRecordForMarkingByFilterList.stream().sorted((p1, p2) -> p2.getSubjectiveAnswerLength() - p1.getSubjectiveAnswerLength())
-                        .limit(1).findFirst().get().getSubjectiveAnswerLength();
+                int maxAnswerLength = examRecordForMarkingByFilterList.stream()
+                        .sorted((p1, p2) -> p2.getSubjectiveAnswerLength() - p1.getSubjectiveAnswerLength()).limit(1)
+                        .findFirst().get().getSubjectiveAnswerLength();
                 examRecordForMarkingByFilterList = examRecordForMarkingList.stream().filter(score -> {
                     return score.getSubjectiveAnswerLength() == maxAnswerLength;
                 }).collect(Collectors.toList());
-                //如果主观题答案最长长度一样的还有多个,继续按时间(考试记录ID)过滤出最新的那条
+                // 如果主观题答案最长长度一样的还有多个,继续按时间(考试记录ID)过滤出最新的那条
                 if (examRecordForMarkingByFilterList.size() > 1) {
-                    examRecordForMarkingByFilterList = examRecordForMarkingByFilterList.stream().sorted((p1, p2) -> p2.getExamRecordDataId().compareTo(p1.getExamRecordDataId()))
-                            .limit(1)
+                    examRecordForMarkingByFilterList = examRecordForMarkingByFilterList.stream()
+                            .sorted((p1, p2) -> p2.getExamRecordDataId().compareTo(p1.getExamRecordDataId())).limit(1)
                             .collect(Collectors.toList());
                 }
             }
@@ -190,7 +206,8 @@ public class ExamRecordForMarkingServiceImpl implements ExamRecordForMarkingServ
         return finalExamRecordForMarkingEntityList;
     }
 
-    private Map<Long, List<ExamRecordForMarkingEntity>> groupByExamStudentId(List<ExamRecordForMarkingEntity> examRecordForMarkingList) {
+    private Map<Long, List<ExamRecordForMarkingEntity>> groupByExamStudentId(
+            List<ExamRecordForMarkingEntity> examRecordForMarkingList) {
         Map<Long, List<ExamRecordForMarkingEntity>> groupByExamStudentIdMap = new HashMap<Long, List<ExamRecordForMarkingEntity>>();
         for (ExamRecordForMarkingEntity examRecordForMarkingEntity : examRecordForMarkingList) {
             Long examStudentId = examRecordForMarkingEntity.getExamStudentId();
@@ -207,14 +224,20 @@ public class ExamRecordForMarkingServiceImpl implements ExamRecordForMarkingServ
     }
 
     @Override
-    public List<ExamRecordForMarkingEntity> findExamRecordForMarkingInfo(Long id, Long examId, Long courseId, String batchNum) {
+    public List<ExamRecordForMarkingBean> findExamRecordForMarkingInfo(Long id, Long examId, Long courseId,
+            String batchNum, Boolean includeRandomPaper) {
         if (id == null && examId == null) {
             return null;
         }
         StringBuffer sql = new StringBuffer();
-        sql.append("select t.id,t.exam_id,t.exam_record_data_id,t.base_paper_id,t.paper_type,t.course_id,t.batch_num " +
-                " from ec_oe_exam_record_4_marking t left join ec_oe_exam_record_data f  "
-        		+" on t.exam_record_data_id=f.id  where f.random_paper=0 ");
+        sql.append(
+                "select t.id,t.exam_id,t.exam_record_data_id,t.base_paper_id,t.paper_type,t.course_id,t.batch_num,f.random_paper "
+                        + " from ec_oe_exam_record_4_marking t left join ec_oe_exam_record_data f  "
+                        + " on t.exam_record_data_id=f.id  where 1=1 ");
+
+        if (includeRandomPaper == null || !includeRandomPaper) {
+            sql.append(" and  f.random_paper =0");
+        }
         if (id != null) {
             sql.append(" and t.id = " + id);
         }
@@ -228,25 +251,20 @@ public class ExamRecordForMarkingServiceImpl implements ExamRecordForMarkingServ
             sql.append(" and (t.batch_num is null or t.batch_num != '" + batchNum + "')");
         }
         sql.append(" group by t.base_paper_id");
-        return jdbcTemplate.query(sql.toString(), new RowMapper<ExamRecordForMarkingEntity>() {
-            @Override
-            public ExamRecordForMarkingEntity mapRow(ResultSet rs, int arg1) throws SQLException {
-                ExamRecordForMarkingEntity entity = new ExamRecordForMarkingEntity();
-                entity.setId(rs.getLong("id"));
-                entity.setExamId(rs.getLong("exam_id"));
-                entity.setBasePaperId(rs.getString("base_paper_id"));
-                entity.setPaperType(rs.getString("paper_type"));
-                entity.setCourseId(rs.getLong("course_id"));
-                entity.setBatchNum(rs.getString("batch_num"));
-                entity.setExamRecordDataId(rs.getLong("exam_record_data_id"));
-                return entity;
-            }
-        });
+        RowMapper<ExamRecordForMarkingBean> rowMapper = new BeanPropertyRowMapper<>(ExamRecordForMarkingBean.class);
+        return jdbcTemplate.query(sql.toString(), rowMapper);
+    }
+
+    @Override
+    public List<ExamRecordForMarkingBean> findExamRecordForMarkingInfo(Long id, Long examId, Long courseId,
+            String batchNum) {
+        return findExamRecordForMarkingInfo(id, examId, courseId, batchNum, false);
     }
 
     @Override
     public void saveOffLineExamRecordForMarking(ExamRecordDataBean examRecordData) {
-        ExamRecordForMarkingEntity examRecordForMarking = examRecordForMarkingRepo.findByExamRecordDataId(examRecordData.getId());
+        ExamRecordForMarkingEntity examRecordForMarking = examRecordForMarkingRepo
+                .findByExamRecordDataId(examRecordData.getId());
         if (examRecordForMarking == null) {
             examRecordForMarking = new ExamRecordForMarkingEntity();
             examRecordForMarking.setCreationTime(new Date());
@@ -271,25 +289,26 @@ public class ExamRecordForMarkingServiceImpl implements ExamRecordForMarkingServ
      */
     @Override
     public void saveExamRecordForMarking(Long examRecordDataId, Double objectiveScore) {
-        ExamRecordDataEntity examRecordData =
-                GlobalHelper.getEntity(examRecordDataRepo, examRecordDataId, ExamRecordDataEntity.class);
+        ExamRecordDataEntity examRecordData = GlobalHelper.getEntity(examRecordDataRepo, examRecordDataId,
+                ExamRecordDataEntity.class);
 
-        //全客观题卷
-        if (null == examRecordData.getIsAllObjectivePaper() ||
-                (null != examRecordData.getIsAllObjectivePaper() && examRecordData.getIsAllObjectivePaper())) {
+        // 全客观题卷
+        if (null == examRecordData.getIsAllObjectivePaper()
+                || (null != examRecordData.getIsAllObjectivePaper() && examRecordData.getIsAllObjectivePaper())) {
             return;
         }
-        //违纪
+        // 违纪
         if (null != examRecordData.getIsIllegality() && examRecordData.getIsIllegality()) {
             return;
         }
-        //有警告未审核
-        if (null != examRecordData.getIsWarn() && examRecordData.getIsWarn()
-                && null != examRecordData.getIsAudit() && !examRecordData.getIsAudit()) {
+        // 有警告未审核
+        if (null != examRecordData.getIsWarn() && examRecordData.getIsWarn() && null != examRecordData.getIsAudit()
+                && !examRecordData.getIsAudit()) {
             return;
         }
-        //已经存在
-        ExamRecordForMarkingEntity examRecordForMarkingExists = examRecordForMarkingRepo.findByExamRecordDataId(examRecordData.getId());
+        // 已经存在
+        ExamRecordForMarkingEntity examRecordForMarkingExists = examRecordForMarkingRepo
+                .findByExamRecordDataId(examRecordData.getId());
         if (examRecordForMarkingExists != null) {
             return;
         }
@@ -303,7 +322,8 @@ public class ExamRecordForMarkingServiceImpl implements ExamRecordForMarkingServ
         examRecordForMarking.setCourseId(examRecordData.getCourseId());
         examRecordForMarking.setObjectiveScore(objectiveScore);
 
-        int subjectiveAnswerLength = examRecordQuestionsService.calculationSubjectiveAnswerLength(examRecordData.getId());
+        int subjectiveAnswerLength = examRecordQuestionsService
+                .calculationSubjectiveAnswerLength(examRecordData.getId());
         examRecordForMarking.setSubjectiveAnswerLength(subjectiveAnswerLength);
 
         examRecordForMarkingRepo.save(examRecordForMarking);
@@ -312,13 +332,14 @@ public class ExamRecordForMarkingServiceImpl implements ExamRecordForMarkingServ
     /**
      * 获取某个考生的有效考试记录
      *
-     * @param examStudentId 考生id集合
+     * @param examStudentId
+     *            考生id集合
      * @return
      */
     @Override
     public List<ExamRecordForMarkingEntity> queryValidExamRecordList(Long examStudentId) {
-        List<ExamRecordForMarkingEntity> examRecordForMarkingList =
-                examRecordForMarkingRepo.findByExamStudentId(examStudentId);
+        List<ExamRecordForMarkingEntity> examRecordForMarkingList = examRecordForMarkingRepo
+                .findByExamStudentId(examStudentId);
 
         if (null == examRecordForMarkingList || examRecordForMarkingList.isEmpty()) {
             return null;

+ 15 - 0
examcloud-core-oe-admin-service/src/main/java/cn/com/qmth/examcloud/core/oe/admin/service/impl/FixExamScoreServiceImpl.java

@@ -8,6 +8,8 @@ import cn.com.qmth.examcloud.core.oe.admin.service.ExamRecordQuestionsService;
 import cn.com.qmth.examcloud.core.oe.admin.service.ExamStudentFinalScoreService;
 import cn.com.qmth.examcloud.core.oe.admin.service.FixExamScoreService;
 import cn.com.qmth.examcloud.core.oe.admin.service.bean.examscore.ReFixScoreReq;
+import cn.com.qmth.examcloud.marking.api.StudentPaperCloudService;
+import cn.com.qmth.examcloud.marking.api.request.UpdateObjectiveScoreReq;
 import cn.com.qmth.examcloud.question.commons.core.paper.DefaultPaper;
 import cn.com.qmth.examcloud.question.commons.core.paper.DefaultQuestionGroup;
 import cn.com.qmth.examcloud.question.commons.core.paper.DefaultQuestionStructureWrapper;
@@ -54,6 +56,9 @@ public class FixExamScoreServiceImpl implements FixExamScoreService {
     @Autowired
     private ExamStudentFinalScoreService examStudentFinalScoreService;
 
+    @Autowired
+    private StudentPaperCloudService studentPaperCloudService;
+
     /**
      * 按考生ID重算成绩分数(用于实施小工具,适用场景:考后修改试题正确答案、试题分值)
      */
@@ -224,6 +229,15 @@ public class FixExamScoreServiceImpl implements FixExamScoreService {
             log.warn("【重算成绩】ExamRecordForMarkingEntity-已更新!examRecordDataId:{} objectiveScore:{}",
                     examRecordDataId, objectiveScore);
         }
+
+        try {
+            UpdateObjectiveScoreReq fixReq = new UpdateObjectiveScoreReq();
+            fixReq.setExamRecordDataId(examRecordDataId);
+            fixReq.setScore(objectiveScore);
+            studentPaperCloudService.updateObjectiveScore(fixReq);
+        } catch (Exception e) {
+            log.error("【重算成绩】更新阅卷模块的客观分失败!examRecordDataId:{} err:{}", examRecordDataId, e.getMessage());
+        }
     }
 
     private void changeQuestionScore(ReFixScoreReq req, ExamRecordDataEntity examRecordData,
@@ -366,6 +380,7 @@ public class FixExamScoreServiceImpl implements FixExamScoreService {
             }
 
             if (curQuestionUnits.size() != rightAnswers.size()) {
+                // 注:千人千卷调卷模式出现过抽到重复题BUG,此处需特殊处理 to do...
                 log.warn("【修改试题正确答案】跳过,正确答案集合与小题数量不匹配!questionId:{}", curExamQuestionId);
                 continue;
             }