|
@@ -4,38 +4,45 @@ import cn.hutool.core.date.DateUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
-import com.qmth.boot.tools.signature.SignatureType;
|
|
|
+import com.qmth.boot.api.exception.ApiException;
|
|
|
+import com.qmth.distributed.print.business.bean.dto.ExamPaperObjectiveStructureDto;
|
|
|
+import com.qmth.distributed.print.business.bean.dto.ExamPaperSubjectiveStructureDto;
|
|
|
import com.qmth.distributed.print.business.bean.dto.SyncExamCardDto;
|
|
|
import com.qmth.distributed.print.business.bean.dto.SyncExamStudentDto;
|
|
|
import com.qmth.distributed.print.business.bean.params.SyncDataParam;
|
|
|
import com.qmth.distributed.print.business.entity.*;
|
|
|
+import com.qmth.distributed.print.business.enums.ExamPaperStructureStatusEnum;
|
|
|
+import com.qmth.distributed.print.business.enums.ExamPrintPlanSyncStatusEnum;
|
|
|
import com.qmth.distributed.print.business.enums.PrintPlanStatusEnum;
|
|
|
import com.qmth.distributed.print.business.service.*;
|
|
|
-import com.qmth.distributed.print.business.util.HttpKit;
|
|
|
-import com.qmth.teachcloud.common.SignatureEntityTest;
|
|
|
-import com.qmth.teachcloud.common.config.DictionaryConfig;
|
|
|
+import com.qmth.teachcloud.common.bean.dto.QuestionDTO;
|
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
|
-import com.qmth.teachcloud.common.entity.BasicSchool;
|
|
|
+import com.qmth.teachcloud.common.entity.BasicAttachment;
|
|
|
import com.qmth.teachcloud.common.entity.SysConfig;
|
|
|
+import com.qmth.teachcloud.common.entity.SysOrg;
|
|
|
+import com.qmth.teachcloud.common.entity.SysUser;
|
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
|
+import com.qmth.teachcloud.common.enums.SyncFileTypeEnum;
|
|
|
import com.qmth.teachcloud.common.enums.TaskResultEnum;
|
|
|
import com.qmth.teachcloud.common.enums.TaskStatusEnum;
|
|
|
-import com.qmth.teachcloud.common.service.CommonCacheService;
|
|
|
+import com.qmth.teachcloud.common.service.BasicAttachmentService;
|
|
|
import com.qmth.teachcloud.common.service.SysConfigService;
|
|
|
+import com.qmth.teachcloud.common.service.TeachcloudCommonService;
|
|
|
+import com.qmth.teachcloud.common.sync.StmmsUtils;
|
|
|
import com.qmth.teachcloud.common.util.ServletUtil;
|
|
|
-import org.apache.commons.codec.digest.DigestUtils;
|
|
|
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.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.io.*;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @Date: 2021/5/20.
|
|
@@ -51,12 +58,6 @@ public class DataSyncServiceImpl implements DataSyncService {
|
|
|
@Autowired
|
|
|
private TBSyncTaskService tbSyncTaskService;
|
|
|
|
|
|
- @Autowired
|
|
|
- private DictionaryConfig dictionaryConfig;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CommonCacheService commonCacheService;
|
|
|
-
|
|
|
@Autowired
|
|
|
private ExamStudentService examStudentService;
|
|
|
|
|
@@ -66,14 +67,24 @@ public class DataSyncServiceImpl implements DataSyncService {
|
|
|
@Autowired
|
|
|
private ExamCardService examCardService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ExamPaperStructureService examPaperStructureService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private SysConfigService sysConfigService;
|
|
|
|
|
|
- private ExecutorService executors = Executors.newFixedThreadPool(5);
|
|
|
+ @Autowired
|
|
|
+ private TeachcloudCommonService teachcloudCommonService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BasicAttachmentService basicAttachmentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ StmmsUtils stmmsUtils;
|
|
|
+
|
|
|
+ ExecutorService executorService = Executors.newFixedThreadPool(5);
|
|
|
|
|
|
- private static final String SAVE_EXAM_TYPE = "SCAN_IMAGE";
|
|
|
private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
|
|
- private static final String POST_METHOD = "POST";
|
|
|
|
|
|
/**
|
|
|
* 定时任务批量同步
|
|
@@ -81,13 +92,14 @@ public class DataSyncServiceImpl implements DataSyncService {
|
|
|
@Override
|
|
|
public void syncToCloudReview() {
|
|
|
// 查询可同步计划(同步状态为空:未同步,false:同步失败)
|
|
|
+ SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
QueryWrapper<ExamPrintPlan> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.lambda().eq(ExamPrintPlan::getStatus, PrintPlanStatusEnum.END)
|
|
|
.and(q -> q.isNull(ExamPrintPlan::getSyncStatus).or().eq(ExamPrintPlan::getSyncStatus, false));
|
|
|
List<ExamPrintPlan> examPrintPlans = examPrintPlanService.list(queryWrapper);
|
|
|
if (!CollectionUtils.isEmpty(examPrintPlans)) {
|
|
|
for (ExamPrintPlan examPrintPlan : examPrintPlans) {
|
|
|
- executors.execute(syncData(examPrintPlan, null, examPrintPlan.getName()));
|
|
|
+ executorService.execute(syncBaseData(examPrintPlan, null, examPrintPlan.getName(), sysUser));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -100,6 +112,7 @@ public class DataSyncServiceImpl implements DataSyncService {
|
|
|
*/
|
|
|
@Override
|
|
|
public void syncDataCloud(Long printPlanId, Long thirdRelateId) {
|
|
|
+ SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
ExamPrintPlan examPrintPlan = examPrintPlanService.getById(printPlanId);
|
|
|
if (examPrintPlan == null) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("印刷计划数据异常");
|
|
@@ -109,189 +122,337 @@ public class DataSyncServiceImpl implements DataSyncService {
|
|
|
}
|
|
|
Long relateId = Objects.isNull(thirdRelateId) ? examPrintPlan.getThirdRelateId() : thirdRelateId;
|
|
|
String thirdRelateName = Objects.isNull(examPrintPlan.getThirdRelateId()) ? examPrintPlan.getName() : examPrintPlan.getThirdRelateName();
|
|
|
- executors.execute(syncData(examPrintPlan, relateId, thirdRelateName));
|
|
|
+ executorService.execute(syncBaseData(examPrintPlan, relateId, thirdRelateName, sysUser));
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void syncDataMerge(SyncDataParam syncDataParam) {
|
|
|
+ SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
List<Long> printPlans = syncDataParam.getList();
|
|
|
if (CollectionUtils.isEmpty(printPlans)) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("请选择需要合并的印刷任务");
|
|
|
}
|
|
|
|
|
|
- if(Objects.isNull(syncDataParam.getThirdRelateId()) && Objects.isNull(syncDataParam.getThirdRelateName())){
|
|
|
+ if (Objects.isNull(syncDataParam.getThirdRelateId()) && Objects.isNull(syncDataParam.getThirdRelateName())) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("考试ID、考试名称至少填一个");
|
|
|
}
|
|
|
|
|
|
// todo 校验印刷计划是否完成
|
|
|
if (syncDataParam.getThirdRelateId() == null) {
|
|
|
- Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
|
|
|
String time = String.valueOf(System.currentTimeMillis());
|
|
|
QueryWrapper<ExamPrintPlan> printPlanQueryWrapper = new QueryWrapper<>();
|
|
|
printPlanQueryWrapper.lambda().in(ExamPrintPlan::getId, syncDataParam.getList());
|
|
|
List<ExamPrintPlan> examPrintPlans = examPrintPlanService.list(printPlanQueryWrapper);
|
|
|
ExamPrintPlan examPrintPlan = examPrintPlans.stream().max(Comparator.comparingLong(ExamPrintPlan::getExamEndTime)).get();
|
|
|
String examTime = DateUtil.format(new Date(examPrintPlan.getExamEndTime()), DATE_FORMAT);
|
|
|
- syncDataParam.setThirdRelateId(getExamId(schoolId, time, syncDataParam.getThirdRelateName(), examTime));
|
|
|
+ syncDataParam.setThirdRelateId(stmmsUtils.syncExam(examPrintPlan.getSchoolId(), time, syncDataParam.getThirdRelateName(), examTime));
|
|
|
}
|
|
|
|
|
|
for (Long printPlanId : printPlans) {
|
|
|
ExamPrintPlan printPlan = examPrintPlanService.getById(printPlanId);
|
|
|
- executors.execute(syncData(printPlan, syncDataParam.getThirdRelateId(), syncDataParam.getThirdRelateName()));
|
|
|
+ executorService.execute(syncBaseData(printPlan, syncDataParam.getThirdRelateId(), syncDataParam.getThirdRelateName(), sysUser));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private TimerTask syncData(ExamPrintPlan examPrintPlan, Long thirdRelateId, String thirdRelateName) {
|
|
|
+ @Override
|
|
|
+ public void syncPaperStructure(ExamPaperStructure examPaperStructure) {
|
|
|
+ executorService.execute(syncStructure(examPaperStructure));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 同步基础信息
|
|
|
+ *
|
|
|
+ * @param examPrintPlan
|
|
|
+ * @param thirdRelateId
|
|
|
+ * @param thirdRelateName
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private TimerTask syncBaseData(ExamPrintPlan examPrintPlan, Long thirdRelateId, String thirdRelateName, SysUser sysUser) {
|
|
|
return new TimerTask() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
SysConfig sysConfig = sysConfigService.getByKey("sys.sync.enable");
|
|
|
if (sysConfig != null && "true".equals(sysConfig.getConfigValue())) {
|
|
|
TBSyncTask syncTask = tbSyncTaskService.saveTask(examPrintPlan);
|
|
|
- doSyncCore(examPrintPlan, thirdRelateId, thirdRelateName, syncTask);
|
|
|
+ doSyncBaseData(examPrintPlan, thirdRelateId, thirdRelateName, syncTask, sysUser);
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 同步试卷结构信息
|
|
|
+ *
|
|
|
+ * @param examPaperStructure
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private TimerTask syncStructure(ExamPaperStructure examPaperStructure) {
|
|
|
+ return new TimerTask() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ SysConfig sysConfig = sysConfigService.getByKey("sys.sync.enable");
|
|
|
+ if (sysConfig != null && "true".equals(sysConfig.getConfigValue())) {
|
|
|
+ doSyncStructure(examPaperStructure);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ public void doSyncStructure(ExamPaperStructure examPaperStructure) {
|
|
|
+
|
|
|
+ // 开始同步
|
|
|
+ examPaperStructureService.updateStatusById(examPaperStructure.getId(), ExamPaperStructureStatusEnum.START_SYNC);
|
|
|
+ ExamPaperStructureStatusEnum status = ExamPaperStructureStatusEnum.UPLOAD_FINISH;
|
|
|
+ try {
|
|
|
+ String paperAnswer = examPaperStructure.getPaperAnswer();
|
|
|
+ if (StringUtils.isBlank(paperAnswer)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("没有找到标答文件");
|
|
|
+ }
|
|
|
+
|
|
|
+ String paperTypes = examPaperStructure.getPaperType();
|
|
|
+ if (StringUtils.isBlank(paperTypes)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("没有找到试卷类型");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> paperTypeList = Arrays.asList(paperTypes.split(","));
|
|
|
+
|
|
|
+ AtomicInteger atomicInteger = new AtomicInteger(0);
|
|
|
+ // 同步试卷
|
|
|
+ List<JSONObject> paperAnswerJsons = JSONObject.parseArray(paperAnswer, JSONObject.class);
|
|
|
+ for (JSONObject paperAnswerJson : paperAnswerJsons) {
|
|
|
+ if (!paperAnswerJson.containsKey("paperType") || !paperAnswerJson.containsKey("paper")) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("没有找到试卷文件");
|
|
|
+ }
|
|
|
+ String paperType = paperAnswerJson.getString("paperType");
|
|
|
+ String paper = paperAnswerJson.getString("paper");
|
|
|
+ if (StringUtils.isAnyBlank(paperType, paper)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("没有找到试卷文件");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!paperTypeList.contains(paperType)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("试卷对应的类型有误");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 同步试卷文件
|
|
|
+ File paperFile = downFileFromFss(paper, paperType, SyncFileTypeEnum.PAPER);
|
|
|
+ String syncPaperFileUrl = stmmsUtils.syncFile(examPaperStructure.getSchoolId(), String.valueOf(examPaperStructure.getThirdRelateId()), examPaperStructure.getPaperNumber() + paperType, SyncFileTypeEnum.PAPER, paperFile);
|
|
|
+ if (StringUtils.isNotBlank(syncPaperFileUrl)) {
|
|
|
+ atomicInteger.getAndIncrement();
|
|
|
+ }
|
|
|
+ // 试卷文件保存url
|
|
|
+ paperAnswerJson.put("paperUrl", syncPaperFileUrl);
|
|
|
+ }
|
|
|
+ if (atomicInteger.intValue() - paperAnswerJsons.size() == 0) {
|
|
|
+ status = ExamPaperStructureStatusEnum.PAPER_FINISH;
|
|
|
+ examPaperStructure.setPaperAnswer(JSONObject.toJSONString(paperAnswerJsons));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 同步标答
|
|
|
+ atomicInteger.set(0);
|
|
|
+ for (JSONObject paperAnswerJson : paperAnswerJsons) {
|
|
|
+ if (!paperAnswerJson.containsKey("paperType") || !paperAnswerJson.containsKey("answer")) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("没有找到标答文件");
|
|
|
+ }
|
|
|
+ String paperType = paperAnswerJson.getString("paperType");
|
|
|
+ String answer = paperAnswerJson.getString("answer");
|
|
|
+ if (StringUtils.isAnyBlank(paperType, answer)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("没有找到标答文件");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!paperTypeList.contains(paperType)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("标答对应的试卷类型有误");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 同步标答文件
|
|
|
+ File answerFile = downFileFromFss(answer, paperType, SyncFileTypeEnum.ANSWER);
|
|
|
+ String syncAnswerFileUrl = stmmsUtils.syncFile(examPaperStructure.getSchoolId(), String.valueOf(examPaperStructure.getThirdRelateId()), examPaperStructure.getPaperNumber() + paperType, SyncFileTypeEnum.ANSWER, answerFile);
|
|
|
+ if (StringUtils.isNotBlank(syncAnswerFileUrl)) {
|
|
|
+ atomicInteger.getAndIncrement();
|
|
|
+ }
|
|
|
+ // 标答文件保存url
|
|
|
+ paperAnswerJson.put("answerUrl", syncAnswerFileUrl);
|
|
|
+ }
|
|
|
+ if (atomicInteger.intValue() - paperAnswerJsons.size() == 0) {
|
|
|
+ status = ExamPaperStructureStatusEnum.ANSWER_FINISH;
|
|
|
+ examPaperStructure.setPaperAnswer(JSONObject.toJSONString(paperAnswerJsons));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 同步客观题
|
|
|
+ atomicInteger.set(0);
|
|
|
+ String objectiveStructure = examPaperStructure.getObjectiveStructure();
|
|
|
+ if (StringUtils.isBlank(objectiveStructure)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("没有找到客观题数据");
|
|
|
+ }
|
|
|
+ List<JSONObject> objectiveJsons = JSONObject.parseArray(objectiveStructure, JSONObject.class);
|
|
|
+ for (JSONObject objectiveJson : objectiveJsons) {
|
|
|
+ if (!objectiveJson.containsKey("paperType") || !objectiveJson.containsKey("content")) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("客观题文件未上传");
|
|
|
+ }
|
|
|
+ String objectivePaperType = objectiveJson.getString("paperType");
|
|
|
+ String objectiveContent = objectiveJson.getString("content");
|
|
|
+ if (StringUtils.isAnyBlank(objectivePaperType, objectiveContent)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("没有找到客观题数据");
|
|
|
+ }
|
|
|
+ if (!paperTypeList.contains(objectivePaperType)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("客观题对应的试卷类型有误");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ExamPaperObjectiveStructureDto> objectiveStructureDtos = JSONObject.parseArray(objectiveContent, ExamPaperObjectiveStructureDto.class);
|
|
|
+ List<QuestionDTO> syncObjectiveStructureDatas = objectiveStructureDtos.stream().map(m -> {
|
|
|
+ QuestionDTO syncStructureData = new QuestionDTO();
|
|
|
+ syncStructureData.setMainNumber(Integer.valueOf(m.getMainNumber()));
|
|
|
+ syncStructureData.setSubNumber(m.getSubNumber());
|
|
|
+ syncStructureData.setMainTitle(m.getMainName());
|
|
|
+ syncStructureData.setTotalScore(Double.valueOf(m.getScore()));
|
|
|
+ syncStructureData.setAnswer(m.getAnswer());
|
|
|
+ return syncStructureData;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ boolean syncObjectiveStructure = stmmsUtils.syncPaperStructure(examPaperStructure.getSchoolId(), String.valueOf(examPaperStructure.getThirdRelateId()), examPaperStructure.getPaperNumber() + objectivePaperType, true, null, syncObjectiveStructureDatas);
|
|
|
+ if (syncObjectiveStructure) {
|
|
|
+ atomicInteger.getAndIncrement();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (atomicInteger.intValue() - paperAnswerJsons.size() == 0) {
|
|
|
+ status = ExamPaperStructureStatusEnum.OBJECTIVE_FINISH;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 同步主观题
|
|
|
+ atomicInteger.set(0);
|
|
|
+ String subjectiveStructure = examPaperStructure.getSubjectiveStructure();
|
|
|
+ if (StringUtils.isBlank(subjectiveStructure)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("没有找到主观题数据");
|
|
|
+ }
|
|
|
+ List<JSONObject> subjectiveJsons = JSONObject.parseArray(subjectiveStructure, JSONObject.class);
|
|
|
+ for (JSONObject subjectiveJson : subjectiveJsons) {
|
|
|
+ if (!subjectiveJson.containsKey("paperType") || !subjectiveJson.containsKey("content")) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("主观题文件未上传");
|
|
|
+ }
|
|
|
+ String subjectivePaperType = subjectiveJson.getString("paperType");
|
|
|
+ String subjectiveContent = subjectiveJson.getString("content");
|
|
|
+ if (StringUtils.isAnyBlank(subjectivePaperType, subjectiveContent)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("没有找到主观题数据");
|
|
|
+ }
|
|
|
+ List<ExamPaperSubjectiveStructureDto> subjectiveStructureDtos = JSONObject.parseArray(subjectiveContent, ExamPaperSubjectiveStructureDto.class);
|
|
|
+ List<QuestionDTO> syncSubjectiveStructureDatas = subjectiveStructureDtos.stream().map(m -> {
|
|
|
+ QuestionDTO syncStructureData = new QuestionDTO();
|
|
|
+ syncStructureData.setMainNumber(Integer.valueOf(m.getMainNumber()));
|
|
|
+ syncStructureData.setSubNumber(m.getSubNumber());
|
|
|
+ syncStructureData.setMainTitle(m.getMainName());
|
|
|
+ syncStructureData.setTotalScore(Double.valueOf(m.getScore()));
|
|
|
+ return syncStructureData;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ boolean syncSubjectiveStructure = stmmsUtils.syncPaperStructure(examPaperStructure.getSchoolId(), String.valueOf(examPaperStructure.getThirdRelateId()), examPaperStructure.getPaperNumber() + subjectivePaperType, false, null, syncSubjectiveStructureDatas);
|
|
|
+ if (syncSubjectiveStructure) {
|
|
|
+ atomicInteger.getAndIncrement();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (atomicInteger.intValue() - paperAnswerJsons.size() == 0) {
|
|
|
+ status = ExamPaperStructureStatusEnum.FINISH;
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (ApiException e) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("试卷结构同步失败:" + e.getMessage());
|
|
|
+ } finally {
|
|
|
+ examPaperStructure.setStatus(status);
|
|
|
+ examPaperStructureService.updateById(examPaperStructure);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 同步核心方法
|
|
|
*
|
|
|
* @param thirdRelateName
|
|
|
* @param syncTask
|
|
|
*/
|
|
|
- @Transactional
|
|
|
- public void doSyncCore(ExamPrintPlan examPrintPlan, Long thirdRelateId, String thirdRelateName, TBSyncTask syncTask) {
|
|
|
+ public void doSyncBaseData(ExamPrintPlan examPrintPlan, Long thirdRelateId, String thirdRelateName, TBSyncTask syncTask, SysUser sysUser) {
|
|
|
UpdateWrapper<ExamPrintPlan> updateWrapper = new UpdateWrapper<>();
|
|
|
+ ExamPrintPlanSyncStatusEnum syncStatus = ExamPrintPlanSyncStatusEnum.INIT;
|
|
|
try {
|
|
|
if (!PrintPlanStatusEnum.END.equals(examPrintPlan.getStatus()) && !PrintPlanStatusEnum.PRINT_FINISH.equals(examPrintPlan.getStatus())) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("印刷计划未打印完成或者未结束,不能同步数据");
|
|
|
}
|
|
|
- // 校验同步url
|
|
|
- validatUrl();
|
|
|
UpdateWrapper<TBSyncTask> tbSyncTaskUpdateWrapper = new UpdateWrapper<>();
|
|
|
tbSyncTaskUpdateWrapper.lambda().set(TBSyncTask::getStatus, TaskStatusEnum.RUNNING).eq(TBSyncTask::getId, syncTask.getId());
|
|
|
tbSyncTaskService.update(tbSyncTaskUpdateWrapper);
|
|
|
|
|
|
// 同步计划 -> 对应云阅卷考试
|
|
|
- ExamPrintPlan printPlan = examSave(examPrintPlan, thirdRelateId, thirdRelateName);
|
|
|
- syncTask.setThirdRelateId(printPlan.getThirdRelateId());
|
|
|
+ thirdRelateId = saveExam(examPrintPlan, thirdRelateId);
|
|
|
+ syncStatus = ExamPrintPlanSyncStatusEnum.EXAM_FINISH;
|
|
|
+ syncTask.setThirdRelateId(thirdRelateId);
|
|
|
// 考试同步成功,才能同步考生和题卡
|
|
|
- if (Objects.nonNull(printPlan.getThirdRelateId())) {
|
|
|
- studentSave(printPlan);
|
|
|
- cardUpload(printPlan);
|
|
|
+ if (Objects.nonNull(thirdRelateId)) {
|
|
|
+ updateWrapper.lambda().set(ExamPrintPlan::getThirdRelateId, thirdRelateId).set(ExamPrintPlan::getThirdRelateName, thirdRelateName);
|
|
|
+ saveStudent(examPrintPlan.getSchoolId(), examPrintPlan.getId(), thirdRelateId);
|
|
|
+ syncStatus = ExamPrintPlanSyncStatusEnum.STUDENT_FINISH;
|
|
|
+ cardUpload(examPrintPlan.getSchoolId(), examPrintPlan.getId(), thirdRelateId);
|
|
|
+ syncStatus = ExamPrintPlanSyncStatusEnum.FINISH;
|
|
|
} else {
|
|
|
throw ExceptionResultEnum.ERROR.exception("无法获取云阅卷考试,同步数据失败");
|
|
|
}
|
|
|
|
|
|
- // 更新计划状态
|
|
|
- updateWrapper.lambda().set(ExamPrintPlan::getSyncStatus, true).eq(ExamPrintPlan::getId, examPrintPlan.getId());
|
|
|
-
|
|
|
// 更新日志表
|
|
|
syncTask.setResult(TaskResultEnum.SUCCESS);
|
|
|
syncTask.setErrorMessage(null);
|
|
|
} catch (Exception e) {
|
|
|
syncTask.setResult(TaskResultEnum.ERROR);
|
|
|
syncTask.setErrorMessage(e.getMessage());
|
|
|
- updateWrapper.lambda().set(ExamPrintPlan::getSyncStatus, false).eq(ExamPrintPlan::getId, examPrintPlan.getId());
|
|
|
} finally {
|
|
|
syncTask.setStatus(TaskStatusEnum.FINISH);
|
|
|
tbSyncTaskService.saveOrUpdate(syncTask);
|
|
|
+ updateWrapper.lambda().set(ExamPrintPlan::getSyncStatus, syncStatus).eq(ExamPrintPlan::getId, examPrintPlan.getId());
|
|
|
examPrintPlanService.update(updateWrapper);
|
|
|
+ // 同步成功,发送短信
|
|
|
+ if(ExamPrintPlanSyncStatusEnum.FINISH.equals(syncStatus)) {
|
|
|
+ examPrintPlanService.sendNoticeUploadStructure(examPrintPlan.getId(), sysUser);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 校验url是否非空
|
|
|
- */
|
|
|
- private void validatUrl() {
|
|
|
- String hostUrl = dictionaryConfig.syncDataDomain().getHostUrl();
|
|
|
- String examSaveUrl = dictionaryConfig.syncDataDomain().getExamSaveUrl();
|
|
|
- String studentSaveUrl = dictionaryConfig.syncDataDomain().getStudentSaveUrl();
|
|
|
- String cardUploadUrl = dictionaryConfig.syncDataDomain().getCardUploadUrl();
|
|
|
-
|
|
|
- if (StringUtils.isAnyBlank(hostUrl, examSaveUrl, studentSaveUrl, cardUploadUrl)) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("云阅卷同步接口URL未正确配置");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 创建考试
|
|
|
*
|
|
|
* @param examPrintPlan
|
|
|
- * @param thirdRelateName
|
|
|
* @return
|
|
|
*/
|
|
|
- public ExamPrintPlan examSave(ExamPrintPlan examPrintPlan, Long thirdRelateId, String thirdRelateName) {
|
|
|
+ public Long saveExam(ExamPrintPlan examPrintPlan, Long thirdRelateId) {
|
|
|
try {
|
|
|
if (Objects.isNull(thirdRelateId)) {
|
|
|
String code = String.valueOf(examPrintPlan.getId());
|
|
|
String name = examPrintPlan.getName();
|
|
|
String examTime = DateUtil.format(new Date(examPrintPlan.getExamEndTime()), DATE_FORMAT);
|
|
|
- thirdRelateId = getExamId(examPrintPlan.getSchoolId(), code, name, examTime);
|
|
|
+ thirdRelateId = stmmsUtils.syncExam(examPrintPlan.getSchoolId(), code, name, examTime);
|
|
|
}
|
|
|
- UpdateWrapper<ExamPrintPlan> updateWrapper = new UpdateWrapper<>();
|
|
|
- updateWrapper.lambda().set(ExamPrintPlan::getThirdRelateId, thirdRelateId)
|
|
|
- .set(ExamPrintPlan::getThirdRelateName, thirdRelateName)
|
|
|
- .set(ExamPrintPlan::getSyncStatus, null)
|
|
|
- .eq(ExamPrintPlan::getId, examPrintPlan.getId());
|
|
|
- examPrintPlanService.update(updateWrapper);
|
|
|
- return examPrintPlanService.getById(examPrintPlan.getId());
|
|
|
+ return thirdRelateId;
|
|
|
} catch (Exception e) {
|
|
|
throw ExceptionResultEnum.ERROR.exception(e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public Long getExamId(Long schoolId, String code, String name, String examTime) {
|
|
|
- String hostUrl = dictionaryConfig.syncDataDomain().getHostUrl();
|
|
|
- String examSaveUrl = dictionaryConfig.syncDataDomain().getExamSaveUrl();
|
|
|
- String postUrl = hostUrl.concat(examSaveUrl);
|
|
|
- //参数
|
|
|
- Map<String, String> map = new HashMap<>();
|
|
|
- map.put("code", code);
|
|
|
- map.put("name", name);
|
|
|
- map.put("examTime", examTime);
|
|
|
- map.put("type", SAVE_EXAM_TYPE);
|
|
|
-
|
|
|
- String result = HttpKit.sendPost(postUrl, getHeaders(schoolId, examSaveUrl), map, null, null, null);
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
- if (jsonObject.containsKey("id")) {
|
|
|
- return Long.valueOf(jsonObject.get("id").toString());
|
|
|
- } else {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("考试同步失败");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 新增考生
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- public void studentSave(ExamPrintPlan examPrintPlan) {
|
|
|
- String hostUrl = dictionaryConfig.syncDataDomain().getHostUrl();
|
|
|
- String studentSaveUrl = dictionaryConfig.syncDataDomain().getStudentSaveUrl();
|
|
|
- String postUrl = hostUrl.concat(studentSaveUrl);
|
|
|
-
|
|
|
- List<SyncExamStudentDto> examStudents = examStudentService.listStudentByPrintPlanIdAndSyncStatus(examPrintPlan.getId());
|
|
|
+ public void saveStudent(Long schoolId, Long examPrintPlanId, Long thirdRelateId) {
|
|
|
+ List<SyncExamStudentDto> examStudents = examStudentService.listStudentByPrintPlanIdAndSyncStatus(examPrintPlanId);
|
|
|
for (SyncExamStudentDto examStudent : examStudents) {
|
|
|
try {
|
|
|
//参数
|
|
|
- Map<String, String> map = new HashMap<>();
|
|
|
- map.put("examId", String.valueOf(examPrintPlan.getThirdRelateId()));
|
|
|
- map.put("examNumber", examStudent.getTicketNumber());
|
|
|
- map.put("studentCode", examStudent.getStudentCode());
|
|
|
- map.put("name", examStudent.getStudentName());
|
|
|
- map.put("college", "无");
|
|
|
- map.put("className", getClassName(examStudent.getExtendFields()));
|
|
|
- map.put("teacher", "无");
|
|
|
- map.put("subjectCode", examStudent.getPaperNumber()); // 取试卷编号
|
|
|
- map.put("subjectName", examStudent.getCourseName());
|
|
|
-
|
|
|
- String result = HttpKit.sendPost(postUrl, getHeaders(examPrintPlan.getSchoolId(), studentSaveUrl), map, null, null, null);
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
- if (jsonObject.containsKey("updateTime")) {
|
|
|
+ String examId = String.valueOf(thirdRelateId);
|
|
|
+ String examNumber = examStudent.getTicketNumber();
|
|
|
+ String studentCode = examStudent.getStudentCode();
|
|
|
+ String name = examStudent.getStudentName();
|
|
|
+ SysOrg sysOrg = examStudentService.getSysOrgByBelongOrgId(studentCode);
|
|
|
+ String college = Objects.nonNull(sysOrg) && StringUtils.isNotBlank(sysOrg.getName()) ? sysOrg.getName() : "无";
|
|
|
+ String className = StringUtils.isBlank(examStudent.getClazzName()) ? getClassName(examStudent.getExtendFields()) : examStudent.getClazzName();
|
|
|
+ String teacher = "无";
|
|
|
+ String subjectCode = examStudent.getPaperNumber() + examStudent.getPaperType(); // 取试卷编号
|
|
|
+ String subjectName = examStudent.getCourseName();
|
|
|
+ boolean syncStudent = stmmsUtils.syncStudent(schoolId, examId, examNumber, studentCode, name, college, className, teacher, subjectCode, subjectName, null, null, null, null);
|
|
|
+
|
|
|
+ if (syncStudent) {
|
|
|
UpdateWrapper<ExamStudent> updateWrapper = new UpdateWrapper<>();
|
|
|
updateWrapper.lambda().set(ExamStudent::getSyncStatus, true).eq(ExamStudent::getId, examStudent.getId());
|
|
|
examStudentService.update(updateWrapper);
|
|
@@ -303,15 +464,12 @@ public class DataSyncServiceImpl implements DataSyncService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 推送题卡
|
|
|
+ * 同步题卡
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- public void cardUpload(ExamPrintPlan examPrintPlan) {
|
|
|
- String hostUrl = dictionaryConfig.syncDataDomain().getHostUrl();
|
|
|
- String cardUploadUrl = dictionaryConfig.syncDataDomain().getCardUploadUrl();
|
|
|
- String postUrl = hostUrl.concat(cardUploadUrl);
|
|
|
- List<ExamDetailCourse> examDetailCourses = examDetailService.listSyncPaperNumberByPrintPlanId(examPrintPlan.getId());
|
|
|
+ public void cardUpload(Long schoolId, Long examPrintPlanId, Long thirdRelateId) {
|
|
|
+ List<ExamDetailCourse> examDetailCourses = examDetailService.listSyncPaperNumberByPrintPlanId(examPrintPlanId);
|
|
|
if (CollectionUtils.isEmpty(examDetailCourses)) {
|
|
|
return;
|
|
|
}
|
|
@@ -322,92 +480,66 @@ public class DataSyncServiceImpl implements DataSyncService {
|
|
|
}
|
|
|
|
|
|
if (syncExamCardDtos.size() > 1) {
|
|
|
-// throw ExceptionResultEnum.ERROR.exception(String.format("数据异常,通过学校:%s,课程代码:%s,试卷编号:%s查出多个题卡数据", examDetailCours.getSchoolId(), examDetailCours.getCourseCode(), examDetailCours.getPaperNumber()));
|
|
|
log.info("数据异常,通过学校:{},课程代码:{},试卷编号:{}查出{}个题卡数据", examDetailCours.getSchoolId(), examDetailCours.getCourseCode(), examDetailCours.getPaperNumber(), syncExamCardDtos.size());
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ String paperType = examDetailCours.getPaperType();
|
|
|
+ if (StringUtils.isBlank(paperType)) {
|
|
|
+ log.info("数据异常,通过学校:{},课程代码:{},试卷编号:{}查出绑定试卷类型为空", examDetailCours.getSchoolId(), examDetailCours.getCourseCode(), examDetailCours.getPaperNumber());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
SyncExamCardDto syncExamCardDto = syncExamCardDtos.get(0);
|
|
|
if (StringUtils.isNotEmpty(syncExamCardDto.getContent())) {
|
|
|
- //生成json文件
|
|
|
- File file = null;
|
|
|
- try {
|
|
|
- String filePath = SystemConstant.TEMP_FILES_DIR + File.separator + "card-upload" + File.separator + System.currentTimeMillis();
|
|
|
- file = createJsonFile(filePath, syncExamCardDto.getContent());
|
|
|
- Map<String, String> files = new HashMap<>();
|
|
|
- if (file.exists()) {
|
|
|
- files.put(syncExamCardDto.getTitle(), file.getPath());
|
|
|
- }
|
|
|
-
|
|
|
- //表单数据
|
|
|
- Map<String, String> formText = new HashMap<>();
|
|
|
- formText.put("examId", String.valueOf(examPrintPlan.getThirdRelateId()));
|
|
|
- formText.put("subjectCode", syncExamCardDto.getPaperNumber());
|
|
|
- formText.put("format", "json");
|
|
|
- formText.put("md5", DigestUtils.md5Hex(new FileInputStream(file)));
|
|
|
-
|
|
|
-
|
|
|
- String result = HttpKit.sendPost(postUrl, getHeaders(examDetailCours.getSchoolId(), cardUploadUrl), formText, files, null, null);
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
- if (jsonObject.containsKey("success")) {
|
|
|
- String success = jsonObject.get("success").toString();
|
|
|
- if (Boolean.valueOf(success)) {
|
|
|
- UpdateWrapper<ExamCard> updateWrapper = new UpdateWrapper<>();
|
|
|
- updateWrapper.lambda().set(ExamCard::getSyncStatus, true).eq(ExamCard::getId, syncExamCardDto.getId());
|
|
|
- examCardService.update(updateWrapper);
|
|
|
+ for (String s : paperType.split(",")) {
|
|
|
+ //生成json文件
|
|
|
+ File file = null;
|
|
|
+ try {
|
|
|
+ // 文件临时目录
|
|
|
+ String filePath = getTempDir(SyncFileTypeEnum.CARD);
|
|
|
+ file = createJsonFile(filePath, syncExamCardDto.getContent());
|
|
|
+ if (file.exists()) {
|
|
|
+ String uploadCardUrl = stmmsUtils.syncFile(schoolId, String.valueOf(thirdRelateId), syncExamCardDto.getPaperNumber() + s, SyncFileTypeEnum.CARD, file);
|
|
|
+ if (StringUtils.isNotBlank(uploadCardUrl)) {
|
|
|
+ UpdateWrapper<ExamCard> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.lambda().set(ExamCard::getSyncStatus, true).eq(ExamCard::getId, syncExamCardDto.getId());
|
|
|
+ examCardService.update(updateWrapper);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(e.getMessage());
|
|
|
+ } finally {
|
|
|
+ if (file != null && file.exists()) {
|
|
|
+ file.delete();
|
|
|
}
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception(e.getMessage());
|
|
|
- } finally {
|
|
|
- if (file != null && file.exists()) {
|
|
|
- file.delete();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * http请求头
|
|
|
+ * 上传文件临时目录
|
|
|
*
|
|
|
- * @param url
|
|
|
+ * @param type
|
|
|
* @return
|
|
|
*/
|
|
|
- private Map<String, String> getHeaders(Long schoolId, String url) {
|
|
|
- long time = System.currentTimeMillis();
|
|
|
- Map<String, String> header = new HashMap<>();
|
|
|
- header.put(SystemConstant.HEADER_AUTHORIZATION, createSign(schoolId, time, url));
|
|
|
- header.put(SystemConstant.HEADER_TIME, String.valueOf(time));
|
|
|
- return header;
|
|
|
+ private String getTempDir(SyncFileTypeEnum type) {
|
|
|
+ return SystemConstant.TEMP_FILES_DIR + File.separator + "upload-temp" + File.separator + type.name().toLowerCase() + File.separator + System.currentTimeMillis();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 签名
|
|
|
+ * 通过扩展字段,获取班级名称
|
|
|
*
|
|
|
- * @param schoolId
|
|
|
- * @param time
|
|
|
- * @param url
|
|
|
+ * @param extendCloumn
|
|
|
* @return
|
|
|
*/
|
|
|
- private String createSign(Long schoolId, long time, String url) {
|
|
|
- BasicSchool basicSchool = commonCacheService.schoolCache(schoolId);
|
|
|
- if (basicSchool == null) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("学校不存在");
|
|
|
- } else {
|
|
|
- if (!basicSchool.getEnable()) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("学校已禁用");
|
|
|
- }
|
|
|
- }
|
|
|
- String signature = SignatureEntityTest.build(SignatureType.SECRET, POST_METHOD, url, time, basicSchool.getAccessKey(), basicSchool.getAccessSecret());
|
|
|
- return signature;
|
|
|
- }
|
|
|
-
|
|
|
private String getClassName(String extendCloumn) {
|
|
|
List<Map> mapList = JSONObject.parseArray(extendCloumn, Map.class);
|
|
|
for (Map map : mapList) {
|
|
|
- if (Objects.equals("className", map.get("code").toString())) {
|
|
|
+ if (Objects.equals("className", map.get("code").toString())
|
|
|
+ || Objects.equals("clazzName", map.get("code").toString())) {
|
|
|
return map.get("value").toString();
|
|
|
}
|
|
|
}
|
|
@@ -440,4 +572,29 @@ public class DataSyncServiceImpl implements DataSyncService {
|
|
|
}
|
|
|
return file;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下载附件临时文件
|
|
|
+ *
|
|
|
+ * @param attachmentId
|
|
|
+ * @param name
|
|
|
+ * @param type
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private File downFileFromFss(String attachmentId, String name, SyncFileTypeEnum type) {
|
|
|
+ try {
|
|
|
+ if (Objects.nonNull(attachmentId)) {
|
|
|
+ BasicAttachment attachment = basicAttachmentService.getById(attachmentId);
|
|
|
+ if (attachment == null) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("附件数据异常");
|
|
|
+ }
|
|
|
+ String fileName = attachment.getName() + "-" + name + attachment.getType();
|
|
|
+ File file = teachcloudCommonService.copyFile(getTempDir(type), fileName, attachment);
|
|
|
+ return file;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(e.getMessage());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|