|
@@ -4,6 +4,7 @@ import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.bson.types.ObjectId;
|
|
|
import org.jsoup.Jsoup;
|
|
@@ -34,6 +35,7 @@ import cn.com.qmth.examcloud.core.questions.service.PaperDetailUnitService;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.PaperService;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.QuesService;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.RandomPaperQuestionService;
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.bean.dto.PaperDetailUnitDto;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.bean.dto.PaperDetailUnitExp;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.cache.BasePaperCache;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.cache.ExtractConfigPaperCache;
|
|
@@ -133,18 +135,34 @@ public class PaperDetailUnitServiceImpl implements PaperDetailUnitService {
|
|
|
}
|
|
|
return o;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean paperInUse(String questionId) {
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("question.$id").is(new ObjectId(questionId)));
|
|
|
+ query.addCriteria(Criteria.where("paperType").is(PaperType.GENERATE.name()));
|
|
|
+ List<PaperDetailUnitDto> units=this.mongoTemplate.find(query, PaperDetailUnitDto.class,"paperDetailUnit");
|
|
|
+ if(CollectionUtils.isEmpty(units)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ for(PaperDetailUnitDto dto:units) {
|
|
|
+ if(dto.getPaper().getInUse()!=null&&dto.getPaper().getInUse()==1) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
/**
|
|
|
* 保存小题
|
|
|
*/
|
|
|
public PaperDetailUnit savePaperDetailUnit(PaperDetailUnitExp updateUnit, User user) {
|
|
|
StringBuilder sb=new StringBuilder();
|
|
|
PaperDetailUnit baseUnit = Model.of(paperDetailUnitRepo.findById(updateUnit.getId()));
|
|
|
- Paper cpaper=baseUnit.getPaper();
|
|
|
- if(cpaper.getInUse()!=null&&cpaper.getInUse()==1) {
|
|
|
- checkUpdate(updateUnit, baseUnit,"试卷已调用,");
|
|
|
+ if(paperInUse(baseUnit.getQuestion().getId())) {
|
|
|
+ PaperUtil.checkUpdate(updateUnit, baseUnit,"试卷已调用,");
|
|
|
}
|
|
|
if(randomPaperQuestionService.existQuestion(baseUnit.getQuestion().getId())) {
|
|
|
- checkUpdateOption(updateUnit, baseUnit,"小题已被抽题模板使用,");
|
|
|
+ PaperUtil.checkUpdateOption(updateUnit, baseUnit,"小题已被抽题模板使用,");
|
|
|
}
|
|
|
Question baseQuestion = baseUnit.getQuestion();
|
|
|
Question updateQuestion = updateUnit.getQuestion();
|
|
@@ -272,81 +290,7 @@ public class PaperDetailUnitServiceImpl implements PaperDetailUnitService {
|
|
|
return baseUnit;
|
|
|
}
|
|
|
|
|
|
- private void checkUpdate(PaperDetailUnitExp updateUnit,PaperDetailUnit baseUnit,String msg) {
|
|
|
- Question baseQuestion = baseUnit.getQuestion();
|
|
|
- Question updateQuestion = updateUnit.getQuestion();
|
|
|
- if (baseUnit.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {
|
|
|
- if (updateQuestion.getId().equals(baseQuestion.getId())) {
|
|
|
- return;
|
|
|
- } else {
|
|
|
- int size = baseQuestion.getSubQuestions().size();
|
|
|
- // 判断更新的对象是哪个子题
|
|
|
- for (int index = 1; index <= size; index++) {
|
|
|
-
|
|
|
- Question sub = baseQuestion.getSubQuestions().get(index - 1);
|
|
|
- if (updateQuestion.getId().equals(sub.getId())) {
|
|
|
- if(updateQuestion.getScore().doubleValue()!=baseUnit.getSubScoreList().get(index - 1).doubleValue()) {
|
|
|
- throw new StatusException("500", msg+"不能修改分数");
|
|
|
- }
|
|
|
- checkUpdate(updateQuestion, sub,msg);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- if(updateUnit.getScore().doubleValue()!=baseUnit.getScore().doubleValue()) {
|
|
|
- throw new StatusException("500", msg+"不能修改分数");
|
|
|
- }
|
|
|
- checkUpdate(updateQuestion, baseQuestion,msg);
|
|
|
- }
|
|
|
- }
|
|
|
- private void checkUpdate(Question update,Question base,String msg) {
|
|
|
- if(QuesStructType.SINGLE_ANSWER_QUESTION.equals(base.getQuestionType())
|
|
|
- ||QuesStructType.MULTIPLE_ANSWER_QUESTION.equals(base.getQuestionType())){
|
|
|
- if(update.getQuesOptions().size()!=base.getQuesOptions().size()) {
|
|
|
- throw new StatusException("500", msg+"不能修改选项数量");
|
|
|
- }
|
|
|
- }
|
|
|
- if(QuesStructType.SINGLE_ANSWER_QUESTION.equals(base.getQuestionType())
|
|
|
- ||QuesStructType.MULTIPLE_ANSWER_QUESTION.equals(base.getQuestionType())
|
|
|
- ||QuesStructType.BOOL_ANSWER_QUESTION.equals(base.getQuestionType())){
|
|
|
- if(!update.getQuesAnswer().equals(base.getQuesAnswer())) {
|
|
|
- throw new StatusException("500", msg+"不能修改客观题答案");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- private void checkUpdateOption(PaperDetailUnitExp updateUnit,PaperDetailUnit baseUnit,String msg) {
|
|
|
- Question baseQuestion = baseUnit.getQuestion();
|
|
|
- Question updateQuestion = updateUnit.getQuestion();
|
|
|
- if (baseUnit.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {
|
|
|
- if (updateQuestion.getId().equals(baseQuestion.getId())) {
|
|
|
- return;
|
|
|
- } else {
|
|
|
- int size = baseQuestion.getSubQuestions().size();
|
|
|
- // 判断更新的对象是哪个子题
|
|
|
- for (int index = 1; index <= size; index++) {
|
|
|
-
|
|
|
- Question sub = baseQuestion.getSubQuestions().get(index - 1);
|
|
|
- if (updateQuestion.getId().equals(sub.getId())) {
|
|
|
- checkUpdateOption(updateQuestion, sub,msg);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- checkUpdateOption(updateQuestion, baseQuestion,msg);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void checkUpdateOption(Question update,Question base,String msg) {
|
|
|
- if(QuesStructType.SINGLE_ANSWER_QUESTION.equals(base.getQuestionType())
|
|
|
- ||QuesStructType.MULTIPLE_ANSWER_QUESTION.equals(base.getQuestionType())){
|
|
|
- if(update.getQuesOptions().size()!=base.getQuesOptions().size()) {
|
|
|
- throw new StatusException("500", msg+"不能修改选项数量");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
private String getQuestionChangeInfo(Question old,Question now) {
|
|
|
StringBuilder sb=new StringBuilder();
|