|
@@ -30,6 +30,7 @@ import org.apache.poi.xssf.usermodel.XSSFCell;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
+import org.bson.types.ObjectId;
|
|
|
import org.jsoup.Jsoup;
|
|
|
import org.jsoup.nodes.Document;
|
|
|
import org.nlpcn.commons.lang.util.StringUtil;
|
|
@@ -107,6 +108,7 @@ import cn.com.qmth.examcloud.core.questions.service.bean.dto.PaperExp;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.bean.dto.PaperQuestionStructureInfo;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.bean.dto.SubjectiveQuestionStructure;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.bean.paper.PaperAnswerDomain;
|
|
|
+import cn.com.qmth.examcloud.core.questions.service.bean.randompaper.PaperDetailUnitDto;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.cache.BasePaperCache;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.cache.ExtractConfigPaperCache;
|
|
|
import cn.com.qmth.examcloud.core.questions.service.cache.QuestionAnswerCache;
|
|
@@ -588,6 +590,7 @@ public class PaperServiceImpl implements PaperService {
|
|
|
*
|
|
|
* @param paperIds
|
|
|
*/
|
|
|
+ @Override
|
|
|
public void deletePapers(List<String> paperIds, User user) {
|
|
|
List<Paper> papers = CommonUtils.toList(paperRepo.findByIdIn(paperIds));
|
|
|
if (papers.get(0).getPaperType() == PaperType.IMPORT) {
|
|
@@ -656,6 +659,125 @@ public class PaperServiceImpl implements PaperService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ private List<PaperDetailUnitDto> findUnitByPaperId(String paperId) {
|
|
|
+ Object id ;
|
|
|
+ if (paperId.length() > 24) {
|
|
|
+ id=paperId;
|
|
|
+ } else {
|
|
|
+ id=new ObjectId(paperId);
|
|
|
+ }
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("paper.$id").is(id));
|
|
|
+ List<PaperDetailUnitDto> units = this.mongoTemplate.find(query, PaperDetailUnitDto.class, "paperDetailUnit");
|
|
|
+ return units;
|
|
|
+ }
|
|
|
+ private boolean existGenerateQuestion(List<String> questionIds) {
|
|
|
+ List<Object> ids = new ArrayList<>();
|
|
|
+ for (String pid : questionIds) {
|
|
|
+ if (pid.length() > 24) {
|
|
|
+ ids.add(pid);
|
|
|
+ } else {
|
|
|
+ ids.add(new ObjectId(pid));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("question.$id").in(ids));
|
|
|
+ query.addCriteria(Criteria.where("paperType").is(PaperType.GENERATE.name()));
|
|
|
+ long count=mongoTemplate.count(query,"paperDetailUnit");
|
|
|
+ return count>0;
|
|
|
+ }
|
|
|
+ private void removeByIds(List<String> stringIds,String collectionName) {
|
|
|
+ List<Object> ids = new ArrayList<>();
|
|
|
+ for (String pid : stringIds) {
|
|
|
+ if (pid.length() > 24) {
|
|
|
+ ids.add(pid);
|
|
|
+ } else {
|
|
|
+ ids.add(new ObjectId(pid));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("_id").in(ids));
|
|
|
+ mongoTemplate.remove(query,collectionName);
|
|
|
+ }
|
|
|
+ private void removeDetailByPaperIds(List<String> paperIds) {
|
|
|
+ List<Object> ids = new ArrayList<>();
|
|
|
+ for (String pid : paperIds) {
|
|
|
+ if (pid.length() > 24) {
|
|
|
+ ids.add(pid);
|
|
|
+ } else {
|
|
|
+ ids.add(new ObjectId(pid));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("paper.$id").in(ids));
|
|
|
+ mongoTemplate.remove(query,"paperDetail");
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public void deletePapersPlus(List<String> paperIds, User user) {
|
|
|
+ List<Paper> papers = paperRepo.findByIdIn(paperIds);
|
|
|
+ List<PaperDetailUnitDto> unitList=new ArrayList<>();
|
|
|
+ if (papers.get(0).getPaperType() == PaperType.IMPORT) {
|
|
|
+ List<String> quesList = new ArrayList<>();
|
|
|
+ for (Paper paper : papers) {
|
|
|
+ List<PaperDetailUnitDto> paperUnits = findUnitByPaperId(paper.getId());
|
|
|
+ if(CollectionUtils.isEmpty(paperUnits)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<String> questionIds=paperUnits.stream().map(e->e.getQuestion().id).collect(Collectors.toList());
|
|
|
+ if(existGenerateQuestion(questionIds)) {
|
|
|
+ throw new StatusException("试卷[" + paper.getName() + "]中有试题被组卷使用,不能删除");
|
|
|
+ }
|
|
|
+ if(randomPaperQuestionService.existQuestion(questionIds)) {
|
|
|
+ throw new StatusException("试卷[" + paper.getName() + "]中有试题被抽题模板使用,不能删除");
|
|
|
+ }
|
|
|
+ unitList.addAll(paperUnits);
|
|
|
+ quesList.addAll(questionIds);
|
|
|
+ }
|
|
|
+ if(CollectionUtils.isNotEmpty(quesList)) {
|
|
|
+ questionAudioService.deleteAudioByQuestionId(quesList);
|
|
|
+ removeByIds(quesList, "question");
|
|
|
+ }
|
|
|
+ } else if (papers.get(0).getPaperType() == PaperType.GENERATE) {
|
|
|
+ for (Paper paper : papers) {
|
|
|
+ if (paper.getInUse() != null && paper.getInUse() == 1) {
|
|
|
+ throw new StatusException("试卷[" + paper.getName() + "]已调用,不能删除");
|
|
|
+ }
|
|
|
+ if(randomPaperService.existPaper(Long.valueOf(paper.getCourse().getId()),paper.getId())) {
|
|
|
+ throw new StatusException("试卷[" + paper.getName() + "]被抽题模板使用,不能删除");
|
|
|
+ }
|
|
|
+ List<PaperDetailUnitDto> paperUnits = findUnitByPaperId(paper.getId());
|
|
|
+ if(CollectionUtils.isEmpty(paperUnits)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ unitList.addAll(paperUnits);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<String> unitids=unitList.stream().map(e->e.getId()).collect(Collectors.toList());
|
|
|
+ if(CollectionUtils.isNotEmpty(unitids)) {
|
|
|
+ removeByIds(unitids, "paperDetailUnit");
|
|
|
+ }
|
|
|
+ removeDetailByPaperIds(paperIds);
|
|
|
+ removeByIds(paperIds, "paper");
|
|
|
+
|
|
|
+ for (String paperId : paperIds) {
|
|
|
+ // 清除缓存
|
|
|
+ this.clearPaperCache(paperId);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Paper paper : papers) {
|
|
|
+ StringBuilder paperInfo = new StringBuilder();
|
|
|
+ paperInfo.append("课程:" + paper.getCourse().getName() + "(" + paper.getCourse().getCode() + ")");
|
|
|
+ paperInfo.append(" 试卷名称:" + paper.getName());
|
|
|
+ if (PaperType.IMPORT.equals(paper.getPaperType())) {
|
|
|
+ ReportsUtil.report(new AdminOperateReport(user.getRootOrgId(), user.getUserId(),
|
|
|
+ AdminOperateType.TYPE46.getDesc(), paperInfo.toString()));
|
|
|
+ } else {
|
|
|
+ ReportsUtil.report(new AdminOperateReport(user.getRootOrgId(), user.getUserId(),
|
|
|
+ AdminOperateType.TYPE47.getDesc(), paperInfo.toString()));
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 批量通过试卷
|