|
@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.qmth.boot.tools.signature.SignatureType;
|
|
|
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.PrintPlanStatusEnum;
|
|
|
import com.qmth.distributed.print.business.service.*;
|
|
@@ -15,12 +16,17 @@ import com.qmth.teachcloud.common.SignatureEntityTest;
|
|
|
import com.qmth.teachcloud.common.config.DictionaryConfig;
|
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
|
import com.qmth.teachcloud.common.entity.BasicSchool;
|
|
|
+import com.qmth.teachcloud.common.entity.SysConfig;
|
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
|
import com.qmth.teachcloud.common.enums.TaskResultEnum;
|
|
|
import com.qmth.teachcloud.common.enums.TaskStatusEnum;
|
|
|
import com.qmth.teachcloud.common.service.CacheService;
|
|
|
+import com.qmth.teachcloud.common.service.SysConfigService;
|
|
|
+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;
|
|
@@ -37,6 +43,8 @@ import java.util.concurrent.Executors;
|
|
|
@Service
|
|
|
public class DataSyncServiceImpl implements DataSyncService {
|
|
|
|
|
|
+ private final static Logger log = LoggerFactory.getLogger(DataSyncServiceImpl.class);
|
|
|
+
|
|
|
@Autowired
|
|
|
private ExamPrintPlanService examPrintPlanService;
|
|
|
|
|
@@ -58,9 +66,12 @@ public class DataSyncServiceImpl implements DataSyncService {
|
|
|
@Autowired
|
|
|
private ExamCardService examCardService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SysConfigService sysConfigService;
|
|
|
+
|
|
|
private ExecutorService executors = Executors.newFixedThreadPool(5);
|
|
|
|
|
|
- private static final String SAVE_EXAM_TYPE = "MULTI_MEDIA";
|
|
|
+ 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";
|
|
|
|
|
@@ -76,7 +87,7 @@ public class DataSyncServiceImpl implements DataSyncService {
|
|
|
List<ExamPrintPlan> examPrintPlans = examPrintPlanService.list(queryWrapper);
|
|
|
if (!CollectionUtils.isEmpty(examPrintPlans)) {
|
|
|
for (ExamPrintPlan examPrintPlan : examPrintPlans) {
|
|
|
- executors.execute(syncData(examPrintPlan));
|
|
|
+ executors.execute(syncData(examPrintPlan, null));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -85,28 +96,51 @@ public class DataSyncServiceImpl implements DataSyncService {
|
|
|
* 单个同步
|
|
|
*
|
|
|
* @param printPlanId
|
|
|
+ * @param thirdRelateId
|
|
|
*/
|
|
|
@Override
|
|
|
- public void syncDataCloud(Long printPlanId) {
|
|
|
+ public void syncDataCloud(Long printPlanId, Long thirdRelateId) {
|
|
|
ExamPrintPlan examPrintPlan = examPrintPlanService.getById(printPlanId);
|
|
|
if (examPrintPlan == null) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("印刷计划数据异常");
|
|
|
}
|
|
|
- if (!PrintPlanStatusEnum.PRINT_FINISH.equals(examPrintPlan.getStatus())) {
|
|
|
+ if (!PrintPlanStatusEnum.END.equals(examPrintPlan.getStatus())) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("印刷计划未结束,不能同步数据");
|
|
|
}
|
|
|
- if (Objects.nonNull(examPrintPlan.getSyncStatus()) && examPrintPlan.getSyncStatus()) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("印刷计划数据同步成功");
|
|
|
+ executors.execute(syncData(examPrintPlan, thirdRelateId));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void syncDataMerge(SyncDataParam syncDataParam) {
|
|
|
+ List<ExamPrintPlan> printPlans = syncDataParam.getList();
|
|
|
+ if(CollectionUtils.isEmpty(printPlans)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo 校验印刷计划是否完成
|
|
|
+ if(syncDataParam.getThirdRelateId() == null){
|
|
|
+ Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
|
|
|
+ String time = String.valueOf(System.currentTimeMillis());
|
|
|
+ ExamPrintPlan examPrintPlan = printPlans.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));
|
|
|
+ }
|
|
|
+
|
|
|
+ for (ExamPrintPlan printPlan : printPlans) {
|
|
|
+ executors.execute(syncData(printPlan, syncDataParam.getThirdRelateId()));
|
|
|
}
|
|
|
- executors.execute(syncData(examPrintPlan));
|
|
|
}
|
|
|
|
|
|
- private TimerTask syncData(ExamPrintPlan examPrintPlan) {
|
|
|
+ private TimerTask syncData(ExamPrintPlan examPrintPlan, Long thirdRelateId) {
|
|
|
return new TimerTask() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- TBSyncTask syncTask = tbSyncTaskService.saveTask(examPrintPlan);
|
|
|
- doSyncCore(examPrintPlan, syncTask);
|
|
|
+ SysConfig sysConfig = sysConfigService.getByKey("sys.sync.enable");
|
|
|
+ if (sysConfig != null && "true".equals(sysConfig.getConfigValue())) {
|
|
|
+ TBSyncTask syncTask = tbSyncTaskService.saveTask(examPrintPlan);
|
|
|
+ doSyncCore(examPrintPlan, thirdRelateId, syncTask);
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
}
|
|
@@ -117,9 +151,10 @@ public class DataSyncServiceImpl implements DataSyncService {
|
|
|
* @param syncTask
|
|
|
*/
|
|
|
@Transactional
|
|
|
- public void doSyncCore(ExamPrintPlan examPrintPlan, TBSyncTask syncTask) {
|
|
|
+ public void doSyncCore(ExamPrintPlan examPrintPlan, Long thirdRelateId, TBSyncTask syncTask) {
|
|
|
+ UpdateWrapper<ExamPrintPlan> updateWrapper = new UpdateWrapper<>();
|
|
|
try {
|
|
|
- if (!PrintPlanStatusEnum.PRINT_FINISH.equals(examPrintPlan.getStatus())) {
|
|
|
+ if (!PrintPlanStatusEnum.END.equals(examPrintPlan.getStatus())) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("印刷计划未结束,不能同步数据");
|
|
|
}
|
|
|
// 校验同步url
|
|
@@ -129,26 +164,29 @@ public class DataSyncServiceImpl implements DataSyncService {
|
|
|
tbSyncTaskService.update(tbSyncTaskUpdateWrapper);
|
|
|
|
|
|
// 同步计划 -> 对应云阅卷考试
|
|
|
- ExamPrintPlan printPlan = examSave(examPrintPlan);
|
|
|
+ ExamPrintPlan printPlan = examSave(examPrintPlan, thirdRelateId);
|
|
|
// 考试同步成功,才能同步考生和题卡
|
|
|
if (Objects.nonNull(printPlan.getThirdRelateId())) {
|
|
|
studentSave(printPlan);
|
|
|
cardUpload(printPlan);
|
|
|
+ } else {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("无法获取云阅卷考试,同步数据失败");
|
|
|
}
|
|
|
|
|
|
// 更新计划状态
|
|
|
- UpdateWrapper<ExamPrintPlan> updateWrapper = new UpdateWrapper<>();
|
|
|
updateWrapper.lambda().set(ExamPrintPlan::getSyncStatus, true).eq(ExamPrintPlan::getId, examPrintPlan.getId());
|
|
|
- examPrintPlanService.update(updateWrapper);
|
|
|
|
|
|
// 更新日志表
|
|
|
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);
|
|
|
+ examPrintPlanService.update(updateWrapper);
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -173,32 +211,42 @@ public class DataSyncServiceImpl implements DataSyncService {
|
|
|
* @param examPrintPlan
|
|
|
* @return
|
|
|
*/
|
|
|
- public ExamPrintPlan examSave(ExamPrintPlan examPrintPlan) {
|
|
|
- String hostUrl = dictionaryConfig.syncDataDomain().getHostUrl();
|
|
|
- String examSaveUrl = dictionaryConfig.syncDataDomain().getExamSaveUrl();
|
|
|
- String postUrl = hostUrl.concat(examSaveUrl);
|
|
|
+ public ExamPrintPlan examSave(ExamPrintPlan examPrintPlan, Long thirdRelateId) {
|
|
|
try {
|
|
|
- //参数
|
|
|
- Map<String, String> map = new HashMap<>();
|
|
|
- map.put("code", String.valueOf(examPrintPlan.getId()));
|
|
|
- map.put("name", examPrintPlan.getName());
|
|
|
- map.put("examTime", DateUtil.format(new Date(examPrintPlan.getExamEndTime()), DATE_FORMAT));
|
|
|
- map.put("type", SAVE_EXAM_TYPE);
|
|
|
-
|
|
|
- String result = HttpKit.sendPost(postUrl, getHeaders(examPrintPlan.getSchoolId(), examSaveUrl), map, null, null, null);
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
- if (jsonObject.containsKey("id")) {
|
|
|
- Long id = Long.valueOf(jsonObject.get("id").toString());
|
|
|
- UpdateWrapper<ExamPrintPlan> updateWrapper = new UpdateWrapper<>();
|
|
|
- updateWrapper.lambda().set(ExamPrintPlan::getThirdRelateId, id).eq(ExamPrintPlan::getId, examPrintPlan.getId());
|
|
|
- examPrintPlanService.update(updateWrapper);
|
|
|
- return examPrintPlanService.getById(examPrintPlan.getId());
|
|
|
+ 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);
|
|
|
}
|
|
|
+ UpdateWrapper<ExamPrintPlan> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.lambda().set(ExamPrintPlan::getThirdRelateId, thirdRelateId).set(ExamPrintPlan::getSyncStatus, null).eq(ExamPrintPlan::getId, examPrintPlan.getId());
|
|
|
+ examPrintPlanService.update(updateWrapper);
|
|
|
+ return examPrintPlanService.getById(examPrintPlan.getId());
|
|
|
} catch (Exception e) {
|
|
|
throw ExceptionResultEnum.ERROR.exception(e.getMessage());
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- return null;
|
|
|
+ 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("考试同步失败");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -254,8 +302,14 @@ public class DataSyncServiceImpl implements DataSyncService {
|
|
|
}
|
|
|
for (ExamDetailCourse examDetailCours : examDetailCourses) {
|
|
|
List<SyncExamCardDto> syncExamCardDtos = examCardService.listSyncCardByCourseCodeAndPaperNumber(examDetailCours.getSchoolId(), examDetailCours.getCourseCode(), examDetailCours.getPaperNumber());
|
|
|
- if (CollectionUtils.isEmpty(syncExamCardDtos) || syncExamCardDtos.size() != 1) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception(String.format("数据异常,通过学校:%s,课程代码:%s,试卷编号:%s查出多个题卡数据", examDetailCours.getSchoolId(), examDetailCours.getCourseCode(), examDetailCours.getPaperNumber()));
|
|
|
+ if (CollectionUtils.isEmpty(syncExamCardDtos)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
}
|
|
|
|
|
|
SyncExamCardDto syncExamCardDto = syncExamCardDtos.get(0);
|