|
@@ -1,9 +1,13 @@
|
|
|
package cn.com.qmth.examcloud.core.questions.service.impl;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
|
|
|
-import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.bson.types.ObjectId;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageImpl;
|
|
@@ -12,29 +16,66 @@ import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
import org.springframework.data.mongodb.core.query.Query;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.api.commons.security.bean.User;
|
|
|
+import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.UserCloudService;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.request.GetUserReq;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.response.GetUserResp;
|
|
|
import cn.com.qmth.examcloud.core.questions.base.CommonUtils;
|
|
|
import cn.com.qmth.examcloud.core.questions.base.Model;
|
|
|
-import cn.com.qmth.examcloud.core.questions.base.bean.randompaper.RandomPaperListVo;
|
|
|
-import cn.com.qmth.examcloud.core.questions.base.bean.randompaper.RandomPaperQuery;
|
|
|
+import cn.com.qmth.examcloud.core.questions.base.enums.PaperStructType;
|
|
|
import cn.com.qmth.examcloud.core.questions.base.enums.PaperType;
|
|
|
+import cn.com.qmth.examcloud.core.questions.base.enums.QuestionDifficulty;
|
|
|
+import cn.com.qmth.examcloud.core.questions.base.question.enums.QuesStructType;
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.PaperDetailUnitRepo;
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.PaperRepo;
|
|
|
import cn.com.qmth.examcloud.core.questions.dao.PaperStructRepo;
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.PropertyRepo;
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.RandomPaperQuestionRepo;
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.RandomPaperRepo;
|
|
|
import cn.com.qmth.examcloud.core.questions.dao.entity.Paper;
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.entity.PaperDetailStruct;
|
|
|
import cn.com.qmth.examcloud.core.questions.dao.entity.PaperStruct;
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.entity.Property;
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.entity.QuesProperty;
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.entity.RandomPaper;
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.entity.RandomPaperQuestion;
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.entity.dto.CoursePropertyNumberDto;
|
|
|
+import cn.com.qmth.examcloud.core.questions.dao.entity.dto.PaperDetailUnitStructDto;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.RandomPaperService;
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.PaperDetailUnitDto;
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.QuestionDto;
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.RandomPaperDomain;
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.RandomPaperListVo;
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.RandomPaperQuery;
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.RandomPaperQuestionDto;
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.StructInfo;
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.StructQuestionCountInfo;
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.StructQuestionInfo;
|
|
|
import cn.com.qmth.examcloud.support.cache.CacheHelper;
|
|
|
import cn.com.qmth.examcloud.support.cache.bean.CourseCacheBean;
|
|
|
|
|
|
+@Service
|
|
|
public class RandomPaperServiceImpl implements RandomPaperService {
|
|
|
|
|
|
@Autowired
|
|
|
private MongoTemplate mongoTemplate;
|
|
|
@Autowired
|
|
|
private PaperStructRepo paperStructRepo;
|
|
|
-
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PropertyRepo propertyRepo;
|
|
|
+ @Autowired
|
|
|
+ private PaperRepo paperRepo;
|
|
|
+ @Autowired
|
|
|
+ private PaperDetailUnitRepo unitRepo;
|
|
|
+ @Autowired
|
|
|
+ private RandomPaperRepo randomPaperRepo;
|
|
|
+ @Autowired
|
|
|
+ private RandomPaperQuestionRepo randomPaperQuestionRepo;
|
|
|
@Autowired
|
|
|
private UserCloudService userCloudService;
|
|
|
|
|
@@ -88,14 +129,526 @@ public class RandomPaperServiceImpl implements RandomPaperService {
|
|
|
vo.setPaperStructTypeStr(vo.getPaperStructType().getName());
|
|
|
PaperStruct paperStruct = Model.of(paperStructRepo.findById(vo.getPaperStructId()));
|
|
|
vo.setPaperStructName(paperStruct.getName());
|
|
|
- vo.setEnableStr(vo.getEnable()?"启用":"禁用");
|
|
|
- GetUserReq ureq=new GetUserReq();
|
|
|
+ vo.setEnableStr(vo.getEnable() ? "启用" : "禁用");
|
|
|
+ GetUserReq ureq = new GetUserReq();
|
|
|
ureq.setUserId(vo.getUpdateBy());
|
|
|
- GetUserResp ures=userCloudService.getUser(ureq);
|
|
|
+ GetUserResp ures = userCloudService.getUser(ureq);
|
|
|
vo.setUpdateByName(ures.getUserBean().getDisplayName());
|
|
|
}
|
|
|
|
|
|
return new PageImpl<>(paperList, pageable, total);
|
|
|
}
|
|
|
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public void toggle(String id, Boolean enable, User user) {
|
|
|
+ RandomPaper paperStruct = Model.of(randomPaperRepo.findById(id));
|
|
|
+ if (paperStruct == null) {
|
|
|
+ throw new StatusException("未找到模板");
|
|
|
+ }
|
|
|
+ if (!paperStruct.getRootOrgId().equals(user.getRootOrgId())) {
|
|
|
+ throw new StatusException("非法操作");
|
|
|
+ }
|
|
|
+ paperStruct.setEnable(enable);
|
|
|
+ randomPaperRepo.save(paperStruct);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public StructInfo getStructQuestionInfo(String structId) {
|
|
|
+ StructInfo ret = new StructInfo();
|
|
|
+ PaperStruct ps = Model.of(paperStructRepo.findById(structId));
|
|
|
+ ret.setTotalScore(ps.getTotalScore());
|
|
|
+ if (PaperStructType.BLUEPRINT.equals(ps.getPaperStrucType())) {
|
|
|
+ ret.setDifficultyDegree(ps.getDifficulty());
|
|
|
+ if (CollectionUtils.isNotEmpty(ps.getPaperDetailStructs())) {
|
|
|
+ List<StructQuestionInfo> sqinfos = new ArrayList<>();
|
|
|
+ ret.setStructQuestionInfo(sqinfos);
|
|
|
+ for (PaperDetailStruct paperDetailStruct : ps.getPaperDetailStructs()) {
|
|
|
+ StructQuestionInfo sqinfo = new StructQuestionInfo();
|
|
|
+ sqinfos.add(sqinfo);
|
|
|
+ sqinfo.setDetailName(paperDetailStruct.getName());
|
|
|
+ sqinfo.setTotalCount(paperDetailStruct.getDetailCount());
|
|
|
+ sqinfo.setTotalScore(paperDetailStruct.getTotalScore());
|
|
|
+ Integer simpleCount = 0;
|
|
|
+ Integer mediumCount = 0;
|
|
|
+ Integer difficultyCount = 0;
|
|
|
+ simpleCount = paperDetailStruct.getPublicSimpleCount() + paperDetailStruct.getNoPublicSimpleCount();
|
|
|
+ mediumCount = paperDetailStruct.getPublicMediumCount() + paperDetailStruct.getNoPublicMediumCount();
|
|
|
+ difficultyCount = paperDetailStruct.getPublicDifficultyCount()
|
|
|
+ + paperDetailStruct.getNoPublicDifficultyCount();
|
|
|
+ sqinfo.setHardInfo(new StructQuestionCountInfo(difficultyCount, true));
|
|
|
+ sqinfo.setMediumInfo(new StructQuestionCountInfo(mediumCount, true));
|
|
|
+ sqinfo.setEasyInfo(new StructQuestionCountInfo(simpleCount, true));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (PaperStructType.EXACT.equals(ps.getPaperStrucType())) {
|
|
|
+ ret.setDifficultyDegree(getExactDifficulty(ps));
|
|
|
+ if (CollectionUtils.isNotEmpty(ps.getPaperDetailStructs())) {
|
|
|
+ List<StructQuestionInfo> sqinfos = new ArrayList<>();
|
|
|
+ ret.setStructQuestionInfo(sqinfos);
|
|
|
+ for (PaperDetailStruct paperDetailStruct : ps.getPaperDetailStructs()) {
|
|
|
+ StructQuestionInfo sqinfo = new StructQuestionInfo();
|
|
|
+ sqinfos.add(sqinfo);
|
|
|
+ sqinfo.setDetailName(paperDetailStruct.getName());
|
|
|
+ sqinfo.setTotalCount(paperDetailStruct.getDetailCount());
|
|
|
+ sqinfo.setTotalScore(paperDetailStruct.getTotalScore());
|
|
|
+ Integer simpleCount = 0;
|
|
|
+ Integer mediumCount = 0;
|
|
|
+ Integer difficultyCount = 0;
|
|
|
+ if (CollectionUtils.isNotEmpty(paperDetailStruct.getUnitStructs())) {
|
|
|
+ for (PaperDetailUnitStructDto unitStruct : paperDetailStruct.getUnitStructs()) {
|
|
|
+ simpleCount = unitStruct.getPublicSimple() + unitStruct.getNoPublicSimple();
|
|
|
+ mediumCount = unitStruct.getPublicMedium() + unitStruct.getNoPublicMedium();
|
|
|
+ difficultyCount = unitStruct.getPublicDifficulty() + unitStruct.getNoPublicDifficulty();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sqinfo.setHardInfo(new StructQuestionCountInfo(difficultyCount, true));
|
|
|
+ sqinfo.setMediumInfo(new StructQuestionCountInfo(mediumCount, true));
|
|
|
+ sqinfo.setEasyInfo(new StructQuestionCountInfo(simpleCount, true));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Double getExactDifficulty(PaperStruct ps) {
|
|
|
+ Double sum = 0.0;
|
|
|
+ Double totalScore = ps.getTotalScore();
|
|
|
+ if (CollectionUtils.isNotEmpty(ps.getPaperDetailStructs())) {
|
|
|
+ Integer simpleCount = 0;
|
|
|
+ Integer mediumCount = 0;
|
|
|
+ Integer difficultyCount = 0;
|
|
|
+ for (PaperDetailStruct paperDetailStruct : ps.getPaperDetailStructs()) {
|
|
|
+ if (CollectionUtils.isNotEmpty(paperDetailStruct.getUnitStructs())) {
|
|
|
+ for (PaperDetailUnitStructDto unitStruct : paperDetailStruct.getUnitStructs()) {
|
|
|
+ simpleCount = unitStruct.getPublicSimple() + unitStruct.getNoPublicSimple();
|
|
|
+ mediumCount = unitStruct.getPublicMedium() + unitStruct.getNoPublicMedium();
|
|
|
+ difficultyCount = unitStruct.getPublicDifficulty() + unitStruct.getNoPublicDifficulty();
|
|
|
+ sum = simpleCount * paperDetailStruct.getScore() * 0.8
|
|
|
+ + mediumCount * paperDetailStruct.getScore() * 0.5
|
|
|
+ + difficultyCount * paperDetailStruct.getScore() * 0.2 + sum;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Double dif = sum / totalScore;
|
|
|
+ BigDecimal b = BigDecimal.valueOf(dif);
|
|
|
+ Double difficulty = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
+ return difficulty;
|
|
|
+ }
|
|
|
+ return (double) 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public StructInfo getPaperQuestionViewInfo(String structId, List<String> paperIds) {
|
|
|
+ StructInfo ret=getPaperQuestionInfo(structId, paperIds);
|
|
|
+ clearQuestionIds(ret);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+ private StructInfo getPaperQuestionInfo(String structId, List<String> paperIds) {
|
|
|
+ StructInfo ret = new StructInfo();
|
|
|
+ ret.setValid(true);
|
|
|
+ PaperStruct ps = Model.of(paperStructRepo.findById(structId));
|
|
|
+ List<PaperDetailUnitDto> unitList = new ArrayList<>();
|
|
|
+ List<QuestionDto> questionList = new ArrayList<>();
|
|
|
+ for (String paperId : paperIds) {
|
|
|
+ unitList.addAll(findUnitPaperId(paperId));
|
|
|
+ }
|
|
|
+ if (PaperStructType.BLUEPRINT.equals(ps.getPaperStrucType())) {
|
|
|
+ for (PaperDetailUnitDto unit : unitList) {
|
|
|
+ unit.getQuestion().setQuesName(unit.getPaperDetail().getName());
|
|
|
+ unit.getQuestion().setPropertyGroup(bulidPropertyGroup(unit.getQuestion()));
|
|
|
+ questionList.add(unit.getQuestion());
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(ps.getPaperDetailStructs())) {
|
|
|
+ List<StructQuestionInfo> sqinfos = new ArrayList<>();
|
|
|
+ ret.setStructQuestionInfo(sqinfos);
|
|
|
+ int detailNumber = 0;
|
|
|
+ for (PaperDetailStruct ds : ps.getPaperDetailStructs()) {
|
|
|
+ detailNumber++;
|
|
|
+ StructQuestionInfo sqinfo = new StructQuestionInfo();
|
|
|
+ sqinfos.add(sqinfo);
|
|
|
+ sqinfo.setDetailName(ds.getName());
|
|
|
+ for (CoursePropertyNumberDto cp : ds.getCoursePropertyNumberDtos()) {
|
|
|
+ if (!cp.getDisable()) {
|
|
|
+ setQuestionInfoByBlue(detailNumber, ds.getQuestionType(), ds.getQuesNames(), sqinfo, cp,
|
|
|
+ questionList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sqinfo.setTotalCount(sqinfo.getHardInfo().getCount() + sqinfo.getMediumInfo().getCount()
|
|
|
+ + sqinfo.getEasyInfo().getCount());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (PaperStructType.EXACT.equals(ps.getPaperStrucType())) {
|
|
|
+ for (PaperDetailUnitDto unit : unitList) {
|
|
|
+ unit.getQuestion().setQuesName(unit.getPaperDetail().getName());
|
|
|
+ questionList.add(unit.getQuestion());
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(ps.getPaperDetailStructs())) {
|
|
|
+ List<StructQuestionInfo> sqinfos = new ArrayList<>();
|
|
|
+ ret.setStructQuestionInfo(sqinfos);
|
|
|
+ int detailNumber = 0;
|
|
|
+ for (PaperDetailStruct ds : ps.getPaperDetailStructs()) {
|
|
|
+ detailNumber++;
|
|
|
+ StructQuestionInfo sqinfo = new StructQuestionInfo();
|
|
|
+ sqinfos.add(sqinfo);
|
|
|
+ sqinfo.setDetailName(ds.getName());
|
|
|
+ int index = 0;
|
|
|
+ for (PaperDetailUnitStructDto us : ds.getUnitStructs()) {
|
|
|
+ index++;
|
|
|
+ setQuestionInfoByExact(index, detailNumber, us, sqinfo, questionList);
|
|
|
+ }
|
|
|
+ sqinfo.setTotalCount(sqinfo.getHardInfo().getCount() + sqinfo.getMediumInfo().getCount()
|
|
|
+ + sqinfo.getEasyInfo().getCount());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fillValid(ret);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void fillValid(StructInfo ret) {
|
|
|
+ if (CollectionUtils.isEmpty(ret.getStructQuestionInfo())) {
|
|
|
+ ret.setValid(false);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (StructQuestionInfo si : ret.getStructQuestionInfo()) {
|
|
|
+ if (!si.getHardInfo().getValid()) {
|
|
|
+ ret.setValid(false);
|
|
|
+ }
|
|
|
+ if (!si.getMediumInfo().getValid()) {
|
|
|
+ ret.setValid(false);
|
|
|
+ }
|
|
|
+ if (!si.getEasyInfo().getValid()) {
|
|
|
+ ret.setValid(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void clearQuestionIds(StructInfo ret) {
|
|
|
+ if (CollectionUtils.isEmpty(ret.getStructQuestionInfo())) {
|
|
|
+ ret.setValid(false);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (StructQuestionInfo si : ret.getStructQuestionInfo()) {
|
|
|
+ if (!si.getHardInfo().getValid()) {
|
|
|
+ ret.setValid(false);
|
|
|
+ }
|
|
|
+ if (!si.getMediumInfo().getValid()) {
|
|
|
+ ret.setValid(false);
|
|
|
+ }
|
|
|
+ if (!si.getEasyInfo().getValid()) {
|
|
|
+ ret.setValid(false);
|
|
|
+ }
|
|
|
+ for (RandomPaperQuestionDto dto : si.getHardInfo().getQuestionInfo()) {
|
|
|
+ dto.setQuestionIds(new ArrayList<>());
|
|
|
+ }
|
|
|
+ for (RandomPaperQuestionDto dto : si.getMediumInfo().getQuestionInfo()) {
|
|
|
+ dto.setQuestionIds(new ArrayList<>());
|
|
|
+ }
|
|
|
+ for (RandomPaperQuestionDto dto : si.getEasyInfo().getQuestionInfo()) {
|
|
|
+ dto.setQuestionIds(new ArrayList<>());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setQuestionInfoByExact(Integer index, Integer detailNumber, PaperDetailUnitStructDto us,
|
|
|
+ StructQuestionInfo sqinfo, List<QuestionDto> questionList) {
|
|
|
+ StructQuestionCountInfo si = null;
|
|
|
+ if (us.getNoPublicDifficulty() > 0) {
|
|
|
+ si = sqinfo.getHardInfo();
|
|
|
+ setQuestionInfoByExact(index, detailNumber, us.getQuestionType(), us.getQuesNames(), si, false,
|
|
|
+ QuestionDifficulty.HARD.getName(), us.getNoPublicDifficulty(), questionList);
|
|
|
+ }
|
|
|
+ if (us.getPublicDifficulty() > 0) {
|
|
|
+ si = sqinfo.getHardInfo();
|
|
|
+ setQuestionInfoByExact(index, detailNumber, us.getQuestionType(), us.getQuesNames(), si, true,
|
|
|
+ QuestionDifficulty.HARD.getName(), us.getPublicDifficulty(), questionList);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (us.getNoPublicMedium() > 0) {
|
|
|
+ si = sqinfo.getMediumInfo();
|
|
|
+ setQuestionInfoByExact(index, detailNumber, us.getQuestionType(), us.getQuesNames(), si, false,
|
|
|
+ QuestionDifficulty.MEDIUM.getName(), us.getNoPublicMedium(), questionList);
|
|
|
+ }
|
|
|
+ if (us.getPublicMedium() > 0) {
|
|
|
+ si = sqinfo.getMediumInfo();
|
|
|
+ setQuestionInfoByExact(index, detailNumber, us.getQuestionType(), us.getQuesNames(), si, true,
|
|
|
+ QuestionDifficulty.MEDIUM.getName(), us.getPublicMedium(), questionList);
|
|
|
+ }
|
|
|
+ if (us.getNoPublicSimple() > 0) {
|
|
|
+ si = sqinfo.getEasyInfo();
|
|
|
+ setQuestionInfoByExact(index, detailNumber, us.getQuestionType(), us.getQuesNames(), si, false,
|
|
|
+ QuestionDifficulty.EASY.getName(), us.getNoPublicSimple(), questionList);
|
|
|
+ }
|
|
|
+ if (us.getPublicSimple() > 0) {
|
|
|
+ si = sqinfo.getEasyInfo();
|
|
|
+ setQuestionInfoByExact(index, detailNumber, us.getQuestionType(), us.getQuesNames(), si, true,
|
|
|
+ QuestionDifficulty.EASY.getName(), us.getPublicSimple(), questionList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setQuestionInfoByExact(Integer index, Integer detailNumber, QuesStructType st, List<String> quesNames,
|
|
|
+ StructQuestionCountInfo si, Boolean pub, String difficulty, Integer count, List<QuestionDto> questionList) {
|
|
|
+ RandomPaperQuestionDto rq = new RandomPaperQuestionDto();
|
|
|
+ rq.setDetailNumber(detailNumber);
|
|
|
+ rq.setKey(index + "-" + pub + "-" + difficulty);
|
|
|
+ si.getQuestionInfo().add(rq);
|
|
|
+ if (CollectionUtils.isNotEmpty(questionList)) {
|
|
|
+ Iterator<QuestionDto> it = questionList.iterator();
|
|
|
+ while (it.hasNext()) {
|
|
|
+ QuestionDto q = it.next();
|
|
|
+ if (checkExactQuesType(quesNames, st, pub, difficulty, q)) {
|
|
|
+ rq.getQuestionIds().add(q.getId());
|
|
|
+ it.remove();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ si.setCount(si.getCount() + rq.getQuestionIds().size());
|
|
|
+ if (si.getValid() && count > rq.getQuestionIds().size()) {
|
|
|
+ si.setValid(false);
|
|
|
+ si.setInvalidMsg(getExactErrmsg(index, detailNumber, pub, difficulty));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setQuestionInfoByBlue(Integer detailNumber, QuesStructType st, List<String> quesNames,
|
|
|
+ StructQuestionInfo sqinfo, CoursePropertyNumberDto cp, List<QuestionDto> questionList) {
|
|
|
+ StructQuestionCountInfo si = null;
|
|
|
+ if (cp.getNoPublicDifficulty() > 0) {
|
|
|
+ si = sqinfo.getHardInfo();
|
|
|
+ setQuestionInfoByBlueProp(detailNumber, st, quesNames, si, cp.getPropertyParentId(), cp.getPropertyId(),
|
|
|
+ false, QuestionDifficulty.HARD.getName(), cp.getNoPublicDifficulty(), questionList);
|
|
|
+ }
|
|
|
+ if (cp.getPublicDifficulty() > 0) {
|
|
|
+ si = sqinfo.getHardInfo();
|
|
|
+ setQuestionInfoByBlueProp(detailNumber, st, quesNames, si, cp.getPropertyParentId(), cp.getPropertyId(),
|
|
|
+ true, QuestionDifficulty.HARD.getName(), cp.getPublicDifficulty(), questionList);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (cp.getNoPublicMedium() > 0) {
|
|
|
+ si = sqinfo.getMediumInfo();
|
|
|
+ setQuestionInfoByBlueProp(detailNumber, st, quesNames, si, cp.getPropertyParentId(), cp.getPropertyId(),
|
|
|
+ false, QuestionDifficulty.MEDIUM.getName(), cp.getNoPublicMedium(), questionList);
|
|
|
+ }
|
|
|
+ if (cp.getPublicMedium() > 0) {
|
|
|
+ si = sqinfo.getMediumInfo();
|
|
|
+ setQuestionInfoByBlueProp(detailNumber, st, quesNames, si, cp.getPropertyParentId(), cp.getPropertyId(),
|
|
|
+ true, QuestionDifficulty.MEDIUM.getName(), cp.getPublicMedium(), questionList);
|
|
|
+ }
|
|
|
+ if (cp.getNoPublicSimple() > 0) {
|
|
|
+ si = sqinfo.getEasyInfo();
|
|
|
+ setQuestionInfoByBlueProp(detailNumber, st, quesNames, si, cp.getPropertyParentId(), cp.getPropertyId(),
|
|
|
+ false, QuestionDifficulty.EASY.getName(), cp.getNoPublicSimple(), questionList);
|
|
|
+ }
|
|
|
+ if (cp.getPublicSimple() > 0) {
|
|
|
+ si = sqinfo.getEasyInfo();
|
|
|
+ setQuestionInfoByBlueProp(detailNumber, st, quesNames, si, cp.getPropertyParentId(), cp.getPropertyId(),
|
|
|
+ true, QuestionDifficulty.EASY.getName(), cp.getPublicSimple(), questionList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setQuestionInfoByBlueProp(Integer detailNumber, QuesStructType st, List<String> quesNames,
|
|
|
+ StructQuestionCountInfo si, String pproid, String proid, Boolean pub, String difficulty, Integer count,
|
|
|
+ List<QuestionDto> questionList) {
|
|
|
+ RandomPaperQuestionDto rq = new RandomPaperQuestionDto();
|
|
|
+ rq.setDetailNumber(detailNumber);
|
|
|
+ rq.setKey(bulidPropertyGroupByBlueStruct(pproid, proid, pub, difficulty));
|
|
|
+ si.getQuestionInfo().add(rq);
|
|
|
+ if (CollectionUtils.isNotEmpty(questionList)) {
|
|
|
+ Iterator<QuestionDto> it = questionList.iterator();
|
|
|
+ while (it.hasNext()) {
|
|
|
+ QuestionDto q = it.next();
|
|
|
+ if (checkBlueQuesType(quesNames, st, rq.getKey(), q)) {
|
|
|
+ rq.getQuestionIds().add(q.getId());
|
|
|
+ it.remove();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ si.setCount(si.getCount() + rq.getQuestionIds().size());
|
|
|
+ if (si.getValid() && count > rq.getQuestionIds().size()) {
|
|
|
+ si.setValid(false);
|
|
|
+ si.setInvalidMsg(getBlueErrmsg(detailNumber, pproid, proid, pub, difficulty));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getExactErrmsg(Integer index, Integer detailNumber, Boolean pub, String difficulty) {
|
|
|
+ String pubstr;
|
|
|
+ if (pub) {
|
|
|
+ pubstr = "公开";
|
|
|
+ } else {
|
|
|
+ pubstr = "非公开";
|
|
|
+ }
|
|
|
+ return "第" + detailNumber + "大题 " + "第" + index + "题型结构 " + pubstr + "-" + difficulty + "题源数量不满足";
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getBlueErrmsg(Integer detailNumber, String pproid, String proid, Boolean pub, String difficulty) {
|
|
|
+ String pubstr;
|
|
|
+ if (pub) {
|
|
|
+ pubstr = "公开";
|
|
|
+ } else {
|
|
|
+ pubstr = "非公开";
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(pproid) && !"0".equals(pproid)) {
|
|
|
+ // 有一级 和 二级
|
|
|
+ Property fp = Model.of(propertyRepo.findById(pproid));
|
|
|
+ Property sp = Model.of(propertyRepo.findById(proid));
|
|
|
+ return "第" + detailNumber + "大题 " + fp.getName() + "-" + sp.getName() + "-" + pubstr + "-" + difficulty
|
|
|
+ + "题源数量不满足";
|
|
|
+ } else {
|
|
|
+ // 有一级 无 二级
|
|
|
+ Property fp = Model.of(propertyRepo.findById(proid));
|
|
|
+ return "第" + detailNumber + "大题 " + fp.getName() + "-" + pubstr + "-" + difficulty + "题源数量不满足";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean checkExactQuesType(List<String> quesNames, QuesStructType st, Boolean pub, String difficulty,
|
|
|
+ QuestionDto question) {
|
|
|
+ if (CollectionUtils.isNotEmpty(quesNames)) {
|
|
|
+ if (quesNames.contains(question.getQuesName()) && st.equals(question.getQuestionType())) {
|
|
|
+ if (question.getPublicity().equals(pub) && question.getDifficulty().equals(difficulty)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean checkBlueQuesType(List<String> quesNames, QuesStructType st, String propertyGroup,
|
|
|
+ QuestionDto question) {
|
|
|
+ if (CollectionUtils.isNotEmpty(quesNames)) {
|
|
|
+ if (quesNames.contains(question.getQuesName()) && st.equals(question.getQuestionType())) {
|
|
|
+ if (question.getPropertyGroup() != null) {
|
|
|
+ if (question.getPropertyGroup().contains(propertyGroup)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<PaperDetailUnitDto> findUnitPaperId(String paperId) {
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("paper.$id").is(new ObjectId(paperId)));
|
|
|
+ List<PaperDetailUnitDto> units = this.mongoTemplate.find(query, PaperDetailUnitDto.class, "paperDetailUnit");
|
|
|
+ return units;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String bulidPropertyGroupByBlueStruct(String pproid, String proid, Boolean pub, String difficulty) {
|
|
|
+ String propertyGroup = null;
|
|
|
+ // 获取试题关联的多组属性
|
|
|
+ if (StringUtils.isNotBlank(pproid) && !"0".equals(pproid)) {
|
|
|
+ // 有一级 和 二级
|
|
|
+ propertyGroup = pproid + "-" + proid + "-" + pub + "-" + difficulty;
|
|
|
+ } else {
|
|
|
+ // 有一级 无 二级
|
|
|
+ propertyGroup = proid + "-" + pub + "-" + difficulty;
|
|
|
+ }
|
|
|
+ return propertyGroup;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<String> bulidPropertyGroup(QuestionDto question) {
|
|
|
+ String propertyGroup = null;
|
|
|
+ List<String> propertyGroups = new ArrayList<>();
|
|
|
+ // 获取试题关联的多组属性
|
|
|
+ List<QuesProperty> quesProperties = question.getQuesProperties();
|
|
|
+ if (quesProperties != null && quesProperties.size() > 0) {
|
|
|
+ for (QuesProperty quesProperty : quesProperties) {
|
|
|
+ if (quesProperty.getSecondProperty() != null) {
|
|
|
+ // 有一级 和 二级
|
|
|
+ if (quesProperty.getSecondProperty().getId() == null
|
|
|
+ || StringUtils.isBlank(String.valueOf(quesProperty.getSecondProperty().getId()))) {
|
|
|
+ propertyGroup = String.valueOf(quesProperty.getFirstProperty().getId()) + "-"
|
|
|
+ + String.valueOf(question.getPublicity()) + "-" + question.getDifficulty();
|
|
|
+ } else {
|
|
|
+ propertyGroup = String.valueOf(quesProperty.getFirstProperty().getId()) + "-"
|
|
|
+ + String.valueOf(quesProperty.getSecondProperty().getId()) + "-"
|
|
|
+ + String.valueOf(question.getPublicity()) + "-" + question.getDifficulty();
|
|
|
+ }
|
|
|
+ propertyGroups.add(propertyGroup);
|
|
|
+ } else {
|
|
|
+ // 有一级 无 二级
|
|
|
+ propertyGroup = String.valueOf(quesProperty.getFirstProperty().getId()) + "-"
|
|
|
+ + String.valueOf(question.getPublicity()) + "-" + question.getDifficulty();
|
|
|
+ propertyGroups.add(propertyGroup);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return propertyGroups;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public StructInfo saveRandomPaper(RandomPaperDomain domain) {
|
|
|
+ if (domain.getCourseId() == null) {
|
|
|
+ throw new StatusException("课程id不能为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(domain.getName())) {
|
|
|
+ throw new StatusException("模板名称不能为空");
|
|
|
+ }
|
|
|
+ if (domain.getPaperStructType() == null) {
|
|
|
+ throw new StatusException("组卷模式不能为空");
|
|
|
+ }
|
|
|
+ if (domain.getPaperStructId() == null) {
|
|
|
+ throw new StatusException("组卷结构不能为空");
|
|
|
+ }
|
|
|
+ if (domain.getPaperType() == null) {
|
|
|
+ throw new StatusException("题源范围不能为空");
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isEmpty(domain.getPaperIds())) {
|
|
|
+ throw new StatusException("试卷id不能为空");
|
|
|
+ }
|
|
|
+ RandomPaper rp = randomPaperRepo.findByRootOrgIdAndName(domain.getRootOrgId(), domain.getName());
|
|
|
+ if (rp != null && !rp.getId().equals(domain.getId())) {
|
|
|
+ throw new StatusException("模板名称已存在");
|
|
|
+ }
|
|
|
+ StructInfo ret = getPaperQuestionInfo(domain.getPaperStructId(), domain.getPaperIds());
|
|
|
+ if (ret.getValid()) {
|
|
|
+ RandomPaper e;
|
|
|
+ if (StringUtils.isNotBlank(domain.getId())) {
|
|
|
+ e = Model.of(randomPaperRepo.findById(domain.getId()));
|
|
|
+ } else {
|
|
|
+ e = new RandomPaper();
|
|
|
+ e.setCourseId(domain.getCourseId());
|
|
|
+ e.setEnable(true);
|
|
|
+ }
|
|
|
+ e.setName(domain.getName());
|
|
|
+ e.setPaperIds(domain.getPaperIds());
|
|
|
+ e.setPaperStructType(domain.getPaperStructType());
|
|
|
+ e.setPaperStructId(domain.getPaperStructId());
|
|
|
+ e.setPaperType(domain.getPaperType());
|
|
|
+ randomPaperRepo.save(e);
|
|
|
+ randomPaperQuestionRepo.deleteByRandomPaperId(e.getId());
|
|
|
+ List<RandomPaperQuestion> rqs = new ArrayList<>();
|
|
|
+ for (StructQuestionInfo si : ret.getStructQuestionInfo()) {
|
|
|
+ for (RandomPaperQuestionDto dto : si.getHardInfo().getQuestionInfo()) {
|
|
|
+ addRqs(rqs, dto, e);
|
|
|
+ }
|
|
|
+ for (RandomPaperQuestionDto dto : si.getMediumInfo().getQuestionInfo()) {
|
|
|
+ addRqs(rqs, dto, e);
|
|
|
+ }
|
|
|
+ for (RandomPaperQuestionDto dto : si.getEasyInfo().getQuestionInfo()) {
|
|
|
+ addRqs(rqs, dto, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ randomPaperQuestionRepo.saveAll(rqs);
|
|
|
+ }
|
|
|
+ clearQuestionIds(ret);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addRqs(List<RandomPaperQuestion> rqs, RandomPaperQuestionDto dto, RandomPaper e) {
|
|
|
+ if (CollectionUtils.isNotEmpty(dto.getQuestionIds())) {
|
|
|
+ RandomPaperQuestion rq = new RandomPaperQuestion();
|
|
|
+ rqs.add(rq);
|
|
|
+ rq.setCourseId(e.getCourseId());
|
|
|
+ rq.setDetailNumber(dto.getDetailNumber());
|
|
|
+ rq.setKey(dto.getKey());
|
|
|
+ rq.setQuestionIds(dto.getQuestionIds());
|
|
|
+ rq.setRandomPaperId(e.getId());
|
|
|
+ rq.setRootOrgId(e.getRootOrgId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|