|
@@ -21,6 +21,7 @@ import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.core.questions.base.BeanCopierUtil;
|
|
|
import cn.com.qmth.examcloud.core.questions.base.CommonUtils;
|
|
|
import cn.com.qmth.examcloud.core.questions.base.IoUtils;
|
|
|
+import cn.com.qmth.examcloud.core.questions.base.enums.PaperType;
|
|
|
import cn.com.qmth.examcloud.core.questions.base.multithread.Consumer;
|
|
|
import cn.com.qmth.examcloud.core.questions.dao.CoursePropertyRepo;
|
|
|
import cn.com.qmth.examcloud.core.questions.dao.PaperDetailRepo;
|
|
@@ -40,6 +41,7 @@ import cn.com.qmth.examcloud.core.questions.dao.entity.QuestionAudio;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.CoursePropertyService;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.PaperService;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.PropertyService;
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.QuesService;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.QuestionAudioService;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.UpYunService;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.bean.CopyDataDto;
|
|
@@ -81,6 +83,8 @@ public class CopyDataConsumer extends Consumer<CopyDataDto> {
|
|
|
@Autowired
|
|
|
private QuesRepo quesRepo;
|
|
|
@Autowired
|
|
|
+ private QuesService quesService;
|
|
|
+ @Autowired
|
|
|
private RedisClient redisClient;
|
|
|
|
|
|
@Transactional
|
|
@@ -88,24 +92,31 @@ public class CopyDataConsumer extends Consumer<CopyDataDto> {
|
|
|
public int consume(CopyDataDto dto) {
|
|
|
disposeCourse(dto);
|
|
|
dto.setSouceIdMap(null);
|
|
|
+ dto.setPaperType(PaperType.GENERATE);
|
|
|
+ disposeCourse(dto);
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
private void disposeCourse(CopyDataDto dto) {
|
|
|
redisClient.expire(copyQuestionDataLock, cacheLockTimeout);
|
|
|
- copyCourseProperty(dto);
|
|
|
- List<Paper> papers = paperService.getImportPapersByCourse(dto.getFromRootOrgId(),
|
|
|
- dto.getCourse().getCourseCode());
|
|
|
+
|
|
|
+ if (PaperType.IMPORT.equals(dto.getPaperType())) {
|
|
|
+ copyCourseProperty(dto);
|
|
|
+ }
|
|
|
+ List<Paper> papers = paperService.getPapersByCourse(dto.getFromRootOrgId(), dto.getCourse().getCourseCode(),
|
|
|
+ dto.getPaperType());
|
|
|
|
|
|
redisClient.expire(copyQuestionDataLock, cacheLockTimeout);
|
|
|
|
|
|
if (CollectionUtils.isEmpty(papers)) {
|
|
|
return;
|
|
|
}
|
|
|
- fillSouceIdMap(dto);
|
|
|
+ if (PaperType.IMPORT.equals(dto.getPaperType())) {
|
|
|
+ fillSouceIdMap(dto);
|
|
|
+ }
|
|
|
for (Paper paper : papers) {
|
|
|
- if (!paperService.existsImportPaperBySourceId(dto.getToRootOrgId(), dto.getCourse().getCourseCode(),
|
|
|
- paper.getId())) {
|
|
|
+ if (!paperService.existsPaperBySourceId(dto.getToRootOrgId(), dto.getCourse().getCourseCode(),
|
|
|
+ dto.getPaperType(), paper.getId())) {
|
|
|
clonePaper(paper, dto);
|
|
|
}
|
|
|
redisClient.expire(copyQuestionDataLock, cacheLockTimeout);
|
|
@@ -232,12 +243,13 @@ public class CopyDataConsumer extends Consumer<CopyDataDto> {
|
|
|
|
|
|
// 复制原试卷的所有试题信息
|
|
|
Map<PaperDetail, List<PaperDetailUnit>> detailMaps = this.copyPaperDetails(oldPaper, dto);
|
|
|
-
|
|
|
- // 处理试题的音频(下载上传到云存储)
|
|
|
- try {
|
|
|
- this.dealQuestionAudios(detailMaps, user.getDisplayName());
|
|
|
- } catch (Exception e) {
|
|
|
- throw new StatusException("500", "复制音频失败!", e);
|
|
|
+ if (PaperType.IMPORT.equals(dto.getPaperType())) {// 复制原卷才处理音频
|
|
|
+ // 处理试题的音频(下载上传到云存储)
|
|
|
+ try {
|
|
|
+ this.dealQuestionAudios(detailMaps, user.getDisplayName());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new StatusException("500", "复制音频失败!", e);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 复制原试卷的信息
|
|
@@ -274,19 +286,21 @@ public class CopyDataConsumer extends Consumer<CopyDataDto> {
|
|
|
newQuestions.add(detailUnit.getQuestion());
|
|
|
}
|
|
|
}
|
|
|
- // 批量新增试题
|
|
|
- quesRepo.saveAll(newQuestions);
|
|
|
+ if (PaperType.IMPORT.equals(newPaper.getPaperType())) {// 复制原卷才处理
|
|
|
+ // 批量新增试题
|
|
|
+ quesRepo.saveAll(newQuestions);
|
|
|
|
|
|
- for (Question question : newQuestions) {
|
|
|
- List<QuestionAudio> audioList = question.getAudioList();
|
|
|
- if (audioList != null && audioList.size() > 0) {
|
|
|
- for (QuestionAudio audio : audioList) {
|
|
|
- audio.setQuestionId(question.getId());
|
|
|
- questionAudioService.saveQuestionAudio(audio, user);
|
|
|
+ for (Question question : newQuestions) {
|
|
|
+ List<QuestionAudio> audioList = question.getAudioList();
|
|
|
+ if (audioList != null && audioList.size() > 0) {
|
|
|
+ for (QuestionAudio audio : audioList) {
|
|
|
+ audio.setQuestionId(question.getId());
|
|
|
+ questionAudioService.saveQuestionAudio(audio, user);
|
|
|
+ }
|
|
|
+ this.updateQuestionBody(question, audioList);
|
|
|
+ // 如果试题存在音频,则更新试题的音频信息
|
|
|
+ quesRepo.save(question);
|
|
|
}
|
|
|
- this.updateQuestionBody(question, audioList);
|
|
|
- // 如果试题存在音频,则更新试题的音频信息
|
|
|
- quesRepo.save(question);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -455,6 +469,7 @@ public class CopyDataConsumer extends Consumer<CopyDataDto> {
|
|
|
question.setPropertyGroup(null);
|
|
|
question.setCreationBy(dto.getUser().getUserId());
|
|
|
question.setUpdateBy(dto.getUser().getUserId());
|
|
|
+ question.setSourceId(oldQuestion.getId());
|
|
|
if (oldQuestion.getHasAudio() == null || !oldQuestion.getHasAudio()) {
|
|
|
question.setHasAudio(false);
|
|
|
return question;
|
|
@@ -474,7 +489,7 @@ public class CopyDataConsumer extends Consumer<CopyDataDto> {
|
|
|
if (CollectionUtils.isNotEmpty(question.getQuesProperties())) {
|
|
|
for (QuesProperty qp : question.getQuesProperties()) {
|
|
|
if (qp != null) {
|
|
|
- if (qp.getFirstProperty() != null&&qp.getFirstProperty().getId()!=null) {
|
|
|
+ if (qp.getFirstProperty() != null && qp.getFirstProperty().getId() != null) {
|
|
|
Property p = dto.getSouceIdMap().get(qp.getFirstProperty().getId());
|
|
|
if (p == null) {
|
|
|
throw new StatusException("未找到试题属性 CourseCode:" + dto.getCourse().getCourseCode()
|
|
@@ -482,7 +497,7 @@ public class CopyDataConsumer extends Consumer<CopyDataDto> {
|
|
|
}
|
|
|
qp.setFirstProperty(p);
|
|
|
}
|
|
|
- if (qp.getSecondProperty() != null&&qp.getSecondProperty().getId()!=null) {
|
|
|
+ if (qp.getSecondProperty() != null && qp.getSecondProperty().getId() != null) {
|
|
|
Property p = dto.getSouceIdMap().get(qp.getSecondProperty().getId());
|
|
|
if (p == null) {
|
|
|
throw new StatusException("未找到试题属性 CourseCode:" + dto.getCourse().getCourseCode()
|
|
@@ -494,7 +509,7 @@ public class CopyDataConsumer extends Consumer<CopyDataDto> {
|
|
|
}
|
|
|
}
|
|
|
if (CollectionUtils.isNotEmpty(question.getSubQuestions())) {
|
|
|
- for(Question sub:question.getSubQuestions()) {
|
|
|
+ for (Question sub : question.getSubQuestions()) {
|
|
|
disposeProperty(sub, dto);
|
|
|
}
|
|
|
}
|
|
@@ -522,9 +537,23 @@ public class CopyDataConsumer extends Consumer<CopyDataDto> {
|
|
|
detailUnit.setUpdateBy(dto.getUser().getUserId());
|
|
|
detailUnit.setPaper(null);
|
|
|
detailUnit.setPaperDetail(null);
|
|
|
- // 复制试题信息
|
|
|
- Question question = this.copyQuestion(oldQuestion, dto);
|
|
|
- detailUnit.setQuestion(question);
|
|
|
+ if (PaperType.IMPORT.equals(dto.getPaperType())) {// 原卷才处理
|
|
|
+ // 复制试题信息
|
|
|
+ Question question = this.copyQuestion(oldQuestion, dto);
|
|
|
+ detailUnit.setQuestion(question);
|
|
|
+ } else {
|
|
|
+ List<Question> qs = quesService.findByOrgIdAndCourseCodeAndSourceId(dto.getToRootOrgId(),
|
|
|
+ dto.getCourse().getCourseCode(), oldQuestion.getId());
|
|
|
+ if (CollectionUtils.isEmpty(qs)) {
|
|
|
+ throw new StatusException("原试题信息不存在:courseCode" + dto.getCourse().getCourseCode() + "|" + "sourceId:"
|
|
|
+ + oldQuestion.getId());
|
|
|
+ }
|
|
|
+ if (qs.size() > 1) {
|
|
|
+ throw new StatusException("原试题信息存在多个:courseCode" + dto.getCourse().getCourseCode() + "|" + "sourceId:"
|
|
|
+ + oldQuestion.getId());
|
|
|
+ }
|
|
|
+ detailUnit.setQuestion(qs.get(0));
|
|
|
+ }
|
|
|
return detailUnit;
|
|
|
}
|
|
|
|