|
@@ -1,11 +1,11 @@
|
|
|
package com.qmth.distributed.print.business.service.impl;
|
|
|
|
|
|
-import cn.hutool.core.date.DateUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.qmth.boot.api.exception.ApiException;
|
|
|
import com.qmth.distributed.print.business.bean.dto.CardDetailDto;
|
|
|
+import com.qmth.distributed.print.business.bean.dto.ExamDetailCourseDto;
|
|
|
import com.qmth.distributed.print.business.bean.dto.SyncExamStudentDto;
|
|
|
import com.qmth.distributed.print.business.entity.*;
|
|
|
import com.qmth.distributed.print.business.enums.ExamPaperStructureStatusEnum;
|
|
@@ -59,6 +59,9 @@ public class DataSyncServiceImpl implements DataSyncService {
|
|
|
@Resource
|
|
|
private ExamDetailService examDetailService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private ExamDetailCourseService examDetailCourseService;
|
|
|
+
|
|
|
@Resource
|
|
|
private ExamCardService examCardService;
|
|
|
|
|
@@ -91,8 +94,7 @@ public class DataSyncServiceImpl implements DataSyncService {
|
|
|
|
|
|
@Async
|
|
|
@Override
|
|
|
- public void syncExamAndStudentAndCard(Long thirdRelateId, String thirdRelateName, Long examEndTime, TBSyncTask tbSyncTask, SysUser sysUser) {
|
|
|
- UpdateWrapper<ExamPrintPlan> updateWrapper = new UpdateWrapper<>();
|
|
|
+ public void syncExamAndStudentAndCard(Long thirdRelateId, String thirdRelateName, String examTime, TBSyncTask tbSyncTask, SysUser sysUser) {
|
|
|
ExamPrintPlanSyncStatusEnum syncStatus = ExamPrintPlanSyncStatusEnum.INIT;
|
|
|
|
|
|
// 同步初始参数
|
|
@@ -101,27 +103,40 @@ public class DataSyncServiceImpl implements DataSyncService {
|
|
|
String errorMessage = null;
|
|
|
Long schoolId = tbSyncTask.getSchoolId();
|
|
|
Long printPlanId = tbSyncTask.getObjectId();
|
|
|
+ List<Long> examTaskIds = JSONObject.parseArray(tbSyncTask.getRemark(), Long.class);
|
|
|
try {
|
|
|
// 同步中
|
|
|
status = TaskStatusEnum.RUNNING;
|
|
|
tbSyncTaskService.updateStatusAndResultById(tbSyncTask.getId(), null, status, null, null);
|
|
|
|
|
|
// 同步计划 -> 同步到云阅卷考试
|
|
|
- thirdRelateId = saveExam(schoolId, printPlanId, thirdRelateId, thirdRelateName, examEndTime);
|
|
|
- syncStatus = ExamPrintPlanSyncStatusEnum.EXAM_FINISH;
|
|
|
- tbSyncTask.setThirdRelateId(thirdRelateId);
|
|
|
+ thirdRelateId = saveExam(schoolId, printPlanId, thirdRelateId, thirdRelateName, examTime);
|
|
|
+ syncStatus = ExamPrintPlanSyncStatusEnum.PART_FINISH;
|
|
|
// 考试同步成功,才能同步考生和题卡
|
|
|
- if (Objects.nonNull(thirdRelateId)) {
|
|
|
- updateWrapper.lambda().set(ExamPrintPlan::getThirdRelateId, thirdRelateId).set(ExamPrintPlan::getThirdRelateName, thirdRelateName);
|
|
|
- // 同步考生
|
|
|
- saveStudent(schoolId, printPlanId, thirdRelateId);
|
|
|
- syncStatus = ExamPrintPlanSyncStatusEnum.STUDENT_FINISH;
|
|
|
- // 同步题卡
|
|
|
- cardUpload(schoolId, printPlanId, thirdRelateId);
|
|
|
- syncStatus = ExamPrintPlanSyncStatusEnum.FINISH;
|
|
|
- } else {
|
|
|
+ if (Objects.isNull(thirdRelateId)) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("无法获取云阅卷考试ID,同步数据失败");
|
|
|
}
|
|
|
+
|
|
|
+ List<ExamDetailCourseDto> examDetailCourseList = examDetailCourseService.listByPrintPlanIdAndExamTaskId(printPlanId, examTaskIds);
|
|
|
+ for (ExamDetailCourseDto examDetailCourseDto : examDetailCourseList) {
|
|
|
+ try {
|
|
|
+ // 同步考生
|
|
|
+ saveStudent(schoolId, thirdRelateId, examDetailCourseDto.getId());
|
|
|
+ syncStatus = ExamPrintPlanSyncStatusEnum.PART_FINISH;
|
|
|
+ // 同步题卡
|
|
|
+ cardUpload(schoolId, thirdRelateId, examDetailCourseDto.getExamTaskId(), examDetailCourseDto.getPaperType());
|
|
|
+ syncStatus = ExamPrintPlanSyncStatusEnum.FINISH;
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("推送考生信息、题卡信息失败,试卷编号:" + examDetailCourseDto.getPaperNumber() + "," + e.getMessage());
|
|
|
+ } finally {
|
|
|
+ UpdateWrapper<ExamDetailCourse> examDetailCourseUpdateWrapper = new UpdateWrapper<>();
|
|
|
+ examDetailCourseUpdateWrapper.lambda().set(ExamDetailCourse::getThirdRelateId, thirdRelateId)
|
|
|
+ .set(ExamDetailCourse::getSyncStatus, syncStatus)
|
|
|
+ .set(ExamDetailCourse::getSyncUserId, sysUser.getId())
|
|
|
+ .eq(ExamDetailCourse::getId, examDetailCourseDto.getId());
|
|
|
+ examDetailCourseService.update(examDetailCourseUpdateWrapper);
|
|
|
+ }
|
|
|
+ }
|
|
|
// 任务结果
|
|
|
result = TaskResultEnum.SUCCESS;
|
|
|
} catch (Exception e) {
|
|
@@ -130,11 +145,8 @@ public class DataSyncServiceImpl implements DataSyncService {
|
|
|
} finally {
|
|
|
// 同步结束
|
|
|
status = TaskStatusEnum.FINISH;
|
|
|
-
|
|
|
tbSyncTaskService.updateStatusAndResultById(tbSyncTask.getId(), thirdRelateId, status, result, errorMessage);
|
|
|
|
|
|
- updateWrapper.lambda().set(ExamPrintPlan::getSyncStatus, syncStatus).eq(ExamPrintPlan::getId, printPlanId);
|
|
|
- examPrintPlanService.update(updateWrapper);
|
|
|
// 同步成功,发送短信
|
|
|
// if (ExamPrintPlanSyncStatusEnum.FINISH.equals(syncStatus)) {
|
|
|
// examPrintPlanService.sendNoticeUploadStructure(printPlanId, sysUser);
|
|
@@ -436,13 +448,12 @@ public class DataSyncServiceImpl implements DataSyncService {
|
|
|
* @param printPlanId 计划ID
|
|
|
* @param thirdRelateId 云阅卷考试ID
|
|
|
* @param thirdRelateName 云阅卷考试名称
|
|
|
- * @param examEndTime 考试时间
|
|
|
+ * @param examTime 考试时间
|
|
|
*/
|
|
|
- public Long saveExam(Long schoolId, Long printPlanId, Long thirdRelateId, String thirdRelateName, Long examEndTime) {
|
|
|
+ public Long saveExam(Long schoolId, Long printPlanId, Long thirdRelateId, String thirdRelateName, String examTime) {
|
|
|
try {
|
|
|
if (Objects.isNull(thirdRelateId)) {
|
|
|
String code = String.valueOf(printPlanId);
|
|
|
- String examTime = DateUtil.format(new Date(examEndTime), CloudMarkingTaskUtils.DATE_FORMAT);
|
|
|
thirdRelateId = cloudMarkingTaskUtils.syncExam(schoolId, code, thirdRelateName, examTime);
|
|
|
}
|
|
|
return thirdRelateId;
|
|
@@ -454,12 +465,11 @@ public class DataSyncServiceImpl implements DataSyncService {
|
|
|
/**
|
|
|
* 新增考生
|
|
|
*
|
|
|
- * @param schoolId 学校ID
|
|
|
- * @param examPrintPlanId 计划ID
|
|
|
- * @param thirdRelateId 云阅卷考试ID
|
|
|
+ * @param schoolId 学校ID
|
|
|
+ * @param thirdRelateId 云阅卷考试ID
|
|
|
*/
|
|
|
- public void saveStudent(Long schoolId, Long examPrintPlanId, Long thirdRelateId) {
|
|
|
- List<SyncExamStudentDto> examStudents = examStudentService.listStudentByPrintPlanIdAndSyncStatus(examPrintPlanId);
|
|
|
+ public void saveStudent(Long schoolId, Long thirdRelateId, Long examDetailCourseId) {
|
|
|
+ List<SyncExamStudentDto> examStudents = examStudentService.listStudentByExamDetailCourseId(examDetailCourseId);
|
|
|
for (SyncExamStudentDto examStudent : examStudents) {
|
|
|
try {
|
|
|
//参数
|
|
@@ -492,71 +502,58 @@ public class DataSyncServiceImpl implements DataSyncService {
|
|
|
/**
|
|
|
* 同步题卡
|
|
|
*
|
|
|
- * @param schoolId 学校ID
|
|
|
- * @param examPrintPlanId 计划ID
|
|
|
- * @param thirdRelateId 云阅卷考试ID
|
|
|
+ * @param schoolId 学校ID
|
|
|
+ * @param thirdRelateId 云阅卷考试ID
|
|
|
*/
|
|
|
- public void cardUpload(Long schoolId, Long examPrintPlanId, Long thirdRelateId) {
|
|
|
- List<ExamDetailCourse> examDetailCourses = examDetailService.listSyncPaperNumberByPrintPlanId(examPrintPlanId);
|
|
|
- if (CollectionUtils.isEmpty(examDetailCourses)) {
|
|
|
- return;
|
|
|
+ public void cardUpload(Long schoolId, Long thirdRelateId, Long examTaskId, String paperType) {
|
|
|
+ ExamTask examTask = examTaskService.getById(examTaskId);
|
|
|
+ if (examTask == null) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(String.format("[上传题卡格式]数据异常,命题任务ID[%s]数据为空", examTaskId));
|
|
|
+ }
|
|
|
+ ExamTaskDetail examTaskDetail = examTaskDetailService.getByExamTaskId(examTask.getId());
|
|
|
+ List<JSONObject> paperAttachmentIds = JSON.parseArray(examTaskDetail.getPaperAttachmentIds(), JSONObject.class);
|
|
|
+ if (paperAttachmentIds.isEmpty()) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(String.format("[上传题卡格式]数据异常,通过命题任务ID[%s],查询试卷信息为空", examTask.getId()));
|
|
|
}
|
|
|
- for (ExamDetailCourse examDetailCours : examDetailCourses) {
|
|
|
- ExamTask examTask = examTaskService.getByCourseCodeAndPaperNumber(examDetailCours.getSchoolId(), examDetailCours.getCourseCode(), examDetailCours.getPaperNumber());
|
|
|
- if (examTask == null) {
|
|
|
- log.info("[上传题卡格式]数据异常,通过学校:{},课程代码:{},试卷编号:{}查出命题任务为空", examDetailCours.getSchoolId(), examDetailCours.getCourseCode(), examDetailCours.getPaperNumber());
|
|
|
- continue;
|
|
|
- }
|
|
|
- ExamTaskDetail examTaskDetail = examTaskDetailService.getByExamTaskId(examTask.getId());
|
|
|
- List<JSONObject> paperAttachmentIds = JSON.parseArray(examTaskDetail.getPaperAttachmentIds(), JSONObject.class);
|
|
|
- if (paperAttachmentIds.isEmpty()) {
|
|
|
- log.info("[上传题卡格式]数据异常,通过命题任务ID:{}查询试卷信息为空", examTask.getId());
|
|
|
- continue;
|
|
|
- }
|
|
|
|
|
|
- String paperType = examDetailCours.getPaperType();
|
|
|
- if (StringUtils.isBlank(paperType)) {
|
|
|
- log.info("[上传题卡格式]数据异常,通过学校:{},课程代码:{},试卷编号:{}查出考场科目信息中绑定卷型为空", examDetailCours.getSchoolId(), examDetailCours.getCourseCode(), examDetailCours.getPaperNumber());
|
|
|
- continue;
|
|
|
+ if (StringUtils.isBlank(paperType)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("[上传题卡格式]数据异常,考场科目信息中绑定卷型为空");
|
|
|
+ }
|
|
|
+ for (String s : paperType.split(",")) {
|
|
|
+ Optional<JSONObject> optional = paperAttachmentIds.stream().filter(m -> m.getString("name").equals(s)).findFirst();
|
|
|
+ if (!optional.isPresent()) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(String.format("[上传题卡格式]数据异常,未找到卷型[%s]绑定题卡ID", s));
|
|
|
+ }
|
|
|
+ Long cardId = optional.get().getLong("cardId");
|
|
|
+ CardDetailDto cardDetail = examCardService.getCardDetail(cardId);
|
|
|
+ if (cardDetail == null || StringUtils.isBlank(cardDetail.getContent())) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(String.format("[上传题卡格式]数据异常,通过题卡ID[%s],未查到题卡格式信息", cardId));
|
|
|
}
|
|
|
- for (String s : examDetailCours.getPaperType().split(",")) {
|
|
|
- Optional<JSONObject> optional = paperAttachmentIds.stream().filter(m -> m.getString("name").equals(s)).findFirst();
|
|
|
- if (!optional.isPresent()) {
|
|
|
- log.info("[上传题卡格式]数据异常,未找到卷型{}绑定题卡ID", s);
|
|
|
- continue;
|
|
|
- }
|
|
|
- Long cardId = optional.get().getLong("cardId");
|
|
|
- CardDetailDto cardDetail = examCardService.getCardDetail(cardId);
|
|
|
- if (cardDetail == null || StringUtils.isBlank(cardDetail.getContent())) {
|
|
|
- log.info("[上传题卡格式]数据异常,通过题卡ID:{}未查到题卡格式信息", cardId);
|
|
|
- continue;
|
|
|
- }
|
|
|
|
|
|
- //生成json文件
|
|
|
- File file = null;
|
|
|
- try {
|
|
|
- // 文件临时目录
|
|
|
- String filePath = getTempDir(SyncFileTypeEnum.CARD);
|
|
|
- file = createJsonFile(filePath, cardDetail.getContent());
|
|
|
- if (file.exists()) {
|
|
|
- String uploadCardUrl = cloudMarkingTaskUtils.syncFile(schoolId, String.valueOf(thirdRelateId), examTask.getCourseCode() + s + examTask.getSequence(), SyncFileTypeEnum.CARD, file);
|
|
|
- if (StringUtils.isNotBlank(uploadCardUrl)) {
|
|
|
- UpdateWrapper<ExamCard> updateWrapper = new UpdateWrapper<>();
|
|
|
- updateWrapper.lambda().set(ExamCard::getSyncStatus, true).eq(ExamCard::getId, cardId);
|
|
|
- examCardService.update(updateWrapper);
|
|
|
- }
|
|
|
+ //生成json文件
|
|
|
+ File file = null;
|
|
|
+ try {
|
|
|
+ // 文件临时目录
|
|
|
+ String filePath = getTempDir(SyncFileTypeEnum.CARD);
|
|
|
+ file = createJsonFile(filePath, cardDetail.getContent());
|
|
|
+ if (file.exists()) {
|
|
|
+ String uploadCardUrl = cloudMarkingTaskUtils.syncFile(schoolId, String.valueOf(thirdRelateId), examTask.getCourseCode() + s + examTask.getSequence(), SyncFileTypeEnum.CARD, file);
|
|
|
+ if (StringUtils.isNotBlank(uploadCardUrl)) {
|
|
|
+ UpdateWrapper<ExamCard> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.lambda().set(ExamCard::getSyncStatus, true).eq(ExamCard::getId, cardId);
|
|
|
+ examCardService.update(updateWrapper);
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception(e.getMessage());
|
|
|
- } finally {
|
|
|
- if (Objects.nonNull(dictionaryConfig.sysDomain()) && dictionaryConfig.sysDomain().isOss()) {
|
|
|
- if (file != null && file.exists()) {
|
|
|
- file.delete();
|
|
|
- }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(e.getMessage());
|
|
|
+ } finally {
|
|
|
+ if (Objects.nonNull(dictionaryConfig.sysDomain()) && dictionaryConfig.sysDomain().isOss()) {
|
|
|
+ if (file != null && file.exists()) {
|
|
|
+ file.delete();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|