|
@@ -1,550 +1,550 @@
|
|
-package com.qmth.cqb.paper.service;
|
|
|
|
-
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.Collections;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.HashSet;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
-import java.util.Set;
|
|
|
|
-
|
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
-import org.springframework.data.domain.Example;
|
|
|
|
-import org.springframework.data.domain.Page;
|
|
|
|
-import org.springframework.data.domain.PageRequest;
|
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
|
-
|
|
|
|
-import com.google.gson.Gson;
|
|
|
|
-import com.qmth.cqb.paper.dao.ExamPaperRepo;
|
|
|
|
-import com.qmth.cqb.paper.dao.PaperDetailRepo;
|
|
|
|
-import com.qmth.cqb.paper.dao.PaperDetailUnitRepo;
|
|
|
|
-import com.qmth.cqb.paper.dao.PaperRepo;
|
|
|
|
-import com.qmth.cqb.paper.dto.PaperDetailExp;
|
|
|
|
-import com.qmth.cqb.paper.dto.PaperDetailUnitExp;
|
|
|
|
-import com.qmth.cqb.paper.dto.PaperExp;
|
|
|
|
-import com.qmth.cqb.paper.model.ExamPaper;
|
|
|
|
-import com.qmth.cqb.paper.model.Paper;
|
|
|
|
-import com.qmth.cqb.paper.model.PaperDetail;
|
|
|
|
-import com.qmth.cqb.paper.model.PaperDetailUnit;
|
|
|
|
-import com.qmth.cqb.paper.model.PaperSearchInfo;
|
|
|
|
-import com.qmth.cqb.question.dao.QuesBakRepo;
|
|
|
|
-import com.qmth.cqb.question.dao.QuesRepo;
|
|
|
|
-import com.qmth.cqb.question.model.Question;
|
|
|
|
-import com.qmth.cqb.question.model.QuestionBak;
|
|
|
|
-import com.qmth.cqb.question.service.QuesService;
|
|
|
|
-import com.qmth.cqb.utils.BeanCopierUtil;
|
|
|
|
-import com.qmth.cqb.utils.CommonUtils;
|
|
|
|
-import com.qmth.cqb.utils.enums.PaperStatus;
|
|
|
|
-import com.qmth.cqb.utils.enums.PaperType;
|
|
|
|
-
|
|
|
|
-import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
|
|
|
|
-import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * Created by songyue on 16/12/28.
|
|
|
|
- */
|
|
|
|
-@Service
|
|
|
|
-public class PaperService {
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- PaperRepo paperRepo;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- PaperDetailService paperDetailService;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- ExamPaperRepo examPaperRepo;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- PaperDetailRepo paperDetailRepo;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- PaperDetailUnitRepo paperDetailUnitRepo;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- QuesRepo quesRepo;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- QuesBakRepo quesBakRepo;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- Gson gson;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- PaperDetailUnitService paperDetailUnitService;
|
|
|
|
-
|
|
|
|
- @Autowired
|
|
|
|
- QuesService quesService;
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 查询所有已导入试卷
|
|
|
|
- *
|
|
|
|
- * @param paperSearchInfo
|
|
|
|
- * @param curPage
|
|
|
|
- * @param pageSize
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- public Page<Paper> getImportPapers(PaperSearchInfo paperSearchInfo, int curPage, int pageSize) {
|
|
|
|
- formatPaperSearchInfo(paperSearchInfo);
|
|
|
|
- Paper importPaper = BeanCopierUtil.copyProperties(paperSearchInfo, Paper.class);
|
|
|
|
- importPaper.setPaperType(PaperType.IMPORT);
|
|
|
|
- return paperRepo.findAll(Example.of(importPaper), new PageRequest(curPage - 1, pageSize));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 保存试卷
|
|
|
|
- *
|
|
|
|
- * @param paperExp
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- public Paper savePaper(PaperExp paperExp) {
|
|
|
|
- Paper paper = BeanCopierUtil.copyProperties(paperExp, Paper.class);
|
|
|
|
- formatPaper(paper);
|
|
|
|
- return paperRepo.save(paper);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 查询所有已组试卷
|
|
|
|
- *
|
|
|
|
- * @param paperSearchInfo
|
|
|
|
- * @param curPage
|
|
|
|
- * @param pageSize
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- public Page<Paper> getGenPapers(PaperSearchInfo paperSearchInfo, int curPage, int pageSize) {
|
|
|
|
- formatPaperSearchInfo(paperSearchInfo);
|
|
|
|
- Paper importPaper = BeanCopierUtil.copyProperties(paperSearchInfo, Paper.class);
|
|
|
|
- importPaper.setPaperType(PaperType.GENERATE);
|
|
|
|
- return paperRepo.findAll(Example.of(importPaper), new PageRequest(curPage - 1, pageSize));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 查询考试试卷
|
|
|
|
- *
|
|
|
|
- * @param id
|
|
|
|
- * @param courseCode
|
|
|
|
- * @param groupCode
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- public List<Paper> listExamPapers(long id, String courseCode, String groupCode) {
|
|
|
|
- List<Paper> papers = new ArrayList<Paper>();
|
|
|
|
- ExamPaper examPaper = new ExamPaper();
|
|
|
|
- examPaper.setExamId(id);
|
|
|
|
- examPaper.setCourseCode(courseCode);
|
|
|
|
- examPaper.setGroupCode(groupCode);
|
|
|
|
- Example<ExamPaper> example = Example.of(examPaper);
|
|
|
|
- List<ExamPaper> examPapers = examPaperRepo.findAll(example);
|
|
|
|
- for (ExamPaper ePaper : examPapers) {
|
|
|
|
- Paper paper = paperRepo.findOne(ePaper.getPaperId());
|
|
|
|
- papers.add(paper);
|
|
|
|
- }
|
|
|
|
- return papers;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 设置考试试卷
|
|
|
|
- *
|
|
|
|
- * @param examId
|
|
|
|
- * @param courseCode
|
|
|
|
- * @param groupCode
|
|
|
|
- * @param paperId
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- public void joinToExamPaper(long examId, String courseCode, String groupCode, String paperId) {
|
|
|
|
- ExamPaper examPaper = new ExamPaper();
|
|
|
|
- examPaper.setExamId(examId);
|
|
|
|
- examPaper.setGroupCode(groupCode);
|
|
|
|
- examPaper.setCourseCode(courseCode);
|
|
|
|
- examPaper.setPaperId(paperId);
|
|
|
|
- examPaperRepo.save(examPaper);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void releaseExamPaper(long examId, String courseCode, String groupCode, String paperId) {
|
|
|
|
- ExamPaper examPaper = new ExamPaper();
|
|
|
|
- examPaper.setExamId(examId);
|
|
|
|
- examPaper.setGroupCode(groupCode);
|
|
|
|
- examPaper.setCourseCode(courseCode);
|
|
|
|
- examPaper.setPaperId(paperId);
|
|
|
|
- examPaperRepo.delete(examPaper);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public Set<String> listGroupCodes(long examId, String courseCode) {
|
|
|
|
- Set<String> groupSet = new HashSet<String>();
|
|
|
|
- ExamPaper examPaper = new ExamPaper();
|
|
|
|
- examPaper.setExamId(examId);
|
|
|
|
- examPaper.setCourseCode(courseCode);
|
|
|
|
- List<ExamPaper> examPapers = examPaperRepo.findAll(Example.of(examPaper));
|
|
|
|
- for (ExamPaper expaper : examPapers) {
|
|
|
|
- groupSet.add(expaper.getGroupCode());
|
|
|
|
- }
|
|
|
|
- return groupSet;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void deletGroupCode(long examId, String courseCode, String groupCode) {
|
|
|
|
- ExamPaper examPaper = new ExamPaper();
|
|
|
|
- examPaper.setExamId(examId);
|
|
|
|
- examPaper.setCourseCode(courseCode);
|
|
|
|
- examPaper.setCourseCode(courseCode);
|
|
|
|
- examPaperRepo.delete(examPaper);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 根据试卷ID获取试卷下面的大题
|
|
|
|
- *
|
|
|
|
- * @param id
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- public List<PaperDetail> findPaperDetailsById(String id) {
|
|
|
|
- return paperDetailService.getPaperDetailsByPaper(paperRepo.findOne(id));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 批量删除试卷
|
|
|
|
- *
|
|
|
|
- * @param paperIds
|
|
|
|
- */
|
|
|
|
- public String deletePapers(List<String> paperIds) {
|
|
|
|
- String msg = "";
|
|
|
|
- List<Paper> papers = CommonUtils.toList(paperRepo.findAll(paperIds));
|
|
|
|
- for (Paper paper : papers) {
|
|
|
|
- List<PaperDetailUnit> units = paperDetailUnitRepo.findByPaper(paper);
|
|
|
|
- if (units.size() > 0) {
|
|
|
|
- return msg = "试卷里面还有小题,不能删除";
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- paperDetailService.deletePaperDetailsByPapers(papers);
|
|
|
|
- paperRepo.delete(papers);
|
|
|
|
- msg = "success";
|
|
|
|
- return msg;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 批量通过试卷
|
|
|
|
- *
|
|
|
|
- * @param paperIds
|
|
|
|
- */
|
|
|
|
- public void passPapers(List<String> paperIds) {
|
|
|
|
- List<Paper> papers = CommonUtils.toList(paperRepo.findAll(paperIds));
|
|
|
|
- papers.stream().forEach(paper -> {
|
|
|
|
- paper.setPaperStatus(PaperStatus.PASS);
|
|
|
|
- });
|
|
|
|
- paperRepo.save(papers);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 批量不通过试卷
|
|
|
|
- *
|
|
|
|
- * @param paperIds
|
|
|
|
- */
|
|
|
|
- public void noPassPapers(List<String> paperIds) {
|
|
|
|
- List<Paper> papers = CommonUtils.toList(paperRepo.findAll(paperIds));
|
|
|
|
- papers.stream().forEach(paper -> {
|
|
|
|
- paper.setPaperStatus(PaperStatus.NOPASS);
|
|
|
|
- });
|
|
|
|
- paperRepo.save(papers);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 批量待审核试卷
|
|
|
|
- *
|
|
|
|
- * @param paperIds
|
|
|
|
- */
|
|
|
|
- public void backPapers(List<String> paperIds) {
|
|
|
|
- List<Paper> papers = CommonUtils.toList(paperRepo.findAll(paperIds));
|
|
|
|
- papers.stream().forEach(paper -> {
|
|
|
|
- paper.setPaperStatus(PaperStatus.DRAFT);
|
|
|
|
- });
|
|
|
|
- paperRepo.save(papers);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 初始化导出试卷DTO
|
|
|
|
- *
|
|
|
|
- * @param id
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- public PaperExp getPaperDto(String id) {
|
|
|
|
-
|
|
|
|
- // 获取paper
|
|
|
|
- Paper paper = paperRepo.findOne(id);
|
|
|
|
- // 创建paperDto
|
|
|
|
- PaperExp paperExp = BeanCopierUtil.copyProperties(paper, PaperExp.class);
|
|
|
|
- // 获取大题
|
|
|
|
- List<PaperDetail> paperDetails = paperDetailRepo.findByPaper(paper);
|
|
|
|
- List<PaperDetailExp> paperDetailExps = BeanCopierUtil.copyPropertiesOfList(paperDetails, PaperDetailExp.class);
|
|
|
|
- paperExp.setPaperDetails(paperDetailExps);
|
|
|
|
-
|
|
|
|
- // 封装小题
|
|
|
|
- for (int i = 0; i < paperDetailExps.size(); i++) {
|
|
|
|
- List<PaperDetailUnit> paperDetailUnits = paperDetailUnitRepo.findByPaperDetail(paperDetails.get(i));
|
|
|
|
- if (paperDetailUnits != null && paperDetailUnits.size() > 0) {
|
|
|
|
- List<PaperDetailUnitExp> paperDetailUnitExps = BeanCopierUtil.copyPropertiesOfList(paperDetailUnits,
|
|
|
|
- PaperDetailUnitExp.class);
|
|
|
|
- paperDetailExps.get(i).setPaperDetailUnits(paperDetailUnitExps);
|
|
|
|
- } else {
|
|
|
|
- paperDetailExps.get(i).setUnitCount(0);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- // 初始化试卷内容
|
|
|
|
- initPaper(paperExp);
|
|
|
|
-
|
|
|
|
- return paperExp;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 初始化试卷内容(增加序号)
|
|
|
|
- *
|
|
|
|
- * @param paperExp
|
|
|
|
- */
|
|
|
|
- public void initPaper(PaperExp paperExp) {
|
|
|
|
- if (paperExp.getPaperDetails() == null || paperExp.getPaperDetails().size() == 0) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- int mainNum = 0;
|
|
|
|
- int subNum = 0;
|
|
|
|
- Collections.sort(paperExp.getPaperDetails());
|
|
|
|
- for (PaperDetailExp paperDetail : paperExp.getPaperDetails()) {
|
|
|
|
- // 大题序号
|
|
|
|
- paperDetail.setCnNum(CommonUtils.toCHNum(paperDetail.getNumber()));
|
|
|
|
- paperDetail.setNumber(++mainNum);
|
|
|
|
- if (paperDetail.getPaperDetailUnits() == null || paperDetail.getPaperDetailUnits().size() == 0) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- // 小题序号
|
|
|
|
- for (PaperDetailUnitExp paperDetailUnit : paperDetail.getPaperDetailUnits()) {
|
|
|
|
-
|
|
|
|
- quesService.formatQuesUnit(paperDetailUnit.getQuestion());
|
|
|
|
-
|
|
|
|
- List<Question> subQuesList = paperDetailUnit.getQuestion().getSubQuestions();
|
|
|
|
- // 套题序号
|
|
|
|
- if (subQuesList != null && subQuesList.size() > 0) {
|
|
|
|
- for (Question subQues : subQuesList) {
|
|
|
|
- Map<String, String> params = new HashMap<String, String>();
|
|
|
|
- params.put("number", String.valueOf(++subNum));
|
|
|
|
- subQues.setQuesParams(params);
|
|
|
|
- quesService.formatQuesUnit(subQues);
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- paperDetailUnit.setNumber(++subNum);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 格式化查询条件
|
|
|
|
- *
|
|
|
|
- * @param paperSearchInfo
|
|
|
|
- */
|
|
|
|
- public void formatPaperSearchInfo(PaperSearchInfo paperSearchInfo) {
|
|
|
|
- if (StringUtils.isEmpty(paperSearchInfo.getCourseNo())) {
|
|
|
|
- paperSearchInfo.setCourseNo(null);
|
|
|
|
- }
|
|
|
|
- if (StringUtils.isEmpty(paperSearchInfo.getCreateTime())) {
|
|
|
|
- paperSearchInfo.setCreateTime(null);
|
|
|
|
- }
|
|
|
|
- if (StringUtils.isEmpty(paperSearchInfo.getCreator())) {
|
|
|
|
- paperSearchInfo.setCreator(null);
|
|
|
|
- }
|
|
|
|
- if (StringUtils.isEmpty(paperSearchInfo.getName())) {
|
|
|
|
- paperSearchInfo.setName(null);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 填充大题小题数量与分数
|
|
|
|
- *
|
|
|
|
- * @param paper
|
|
|
|
- */
|
|
|
|
- public void formatPaper(Paper paper) {
|
|
|
|
- List<PaperDetail> paperDetails = paperDetailRepo.findByPaper(paper);
|
|
|
|
- // 计算试卷总分
|
|
|
|
- List<PaperDetailUnit> paperDetailUnitAll = paperDetailUnitRepo.findByPaper(paper);
|
|
|
|
- double totalScore = 0;
|
|
|
|
- for (PaperDetailUnit unit : paperDetailUnitAll) {
|
|
|
|
- if (unit.getScore() != null) {
|
|
|
|
- totalScore += unit.getScore();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- // 计算各大题总分
|
|
|
|
- for (PaperDetail paperDetail : paperDetails) {
|
|
|
|
- List<PaperDetailUnit> paperDetailUnits = paperDetailUnitRepo.findByPaperDetail(paperDetail);
|
|
|
|
- Collections.sort(paperDetailUnits);
|
|
|
|
- if (paperDetailUnits.size() > 0) {
|
|
|
|
- int count = 0;
|
|
|
|
- double score = 0;
|
|
|
|
- int nestQusNum = 0;
|
|
|
|
- for (PaperDetailUnit unit : paperDetailUnits) {
|
|
|
|
- if (unit.getScore() != null) {
|
|
|
|
- score += unit.getScore();
|
|
|
|
- }
|
|
|
|
- if (unit.getQuestion().getSubQuestions() != null
|
|
|
|
- && unit.getQuestion().getSubQuestions().size() > 0) {
|
|
|
|
- nestQusNum += unit.getQuestion().getSubQuestions().size() - 1;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- count = paperDetailUnits.size() + nestQusNum;
|
|
|
|
- paperDetail.setScore(score);
|
|
|
|
- paperDetail.setUnitCount(count);
|
|
|
|
- } else {
|
|
|
|
- paperDetail.setScore(0d);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- paper.setUnitCount(paperDetailUnitAll.size());
|
|
|
|
- paper.setPaperDetailCount(paperDetails.size());
|
|
|
|
- paper.setTotalScore(totalScore);
|
|
|
|
- paperDetailRepo.save(paperDetails);
|
|
|
|
- paperRepo.save(paper);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 先备份准备删掉的试题,然后再删掉
|
|
|
|
- *
|
|
|
|
- * @param questionId
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- public List<String> deleteImportQuestionById(String questionId) {
|
|
|
|
- Question ques = quesRepo.findOne(questionId);
|
|
|
|
- List<PaperDetailUnit> pdus = CommonUtils.toList(paperDetailUnitRepo.findByQuestion(ques));
|
|
|
|
- List<String> paperNames = new ArrayList<String>();
|
|
|
|
- List<PaperDetailUnit> needPdus = new ArrayList<PaperDetailUnit>();// 需要删除的小题
|
|
|
|
- List<Paper> papers = new ArrayList<Paper>();
|
|
|
|
- for (PaperDetailUnit pdu : pdus) {
|
|
|
|
- if (PaperType.GENERATE == pdu.getPaper().getPaperType()) {
|
|
|
|
- paperNames.add(pdu.getPaper().getName());
|
|
|
|
- needPdus.add(pdu);
|
|
|
|
- if (!papers.contains(pdu.getPaper())) {
|
|
|
|
- papers.add(pdu.getPaper());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (paperNames.size() == 0) {// 此试题没有被组卷调用,则可以删除此试题
|
|
|
|
- paperDetailUnitRepo.delete(needPdus);
|
|
|
|
- quesBakRepo.save(BeanCopierUtil.copyProperties(ques, QuestionBak.class));
|
|
|
|
- quesRepo.delete(ques);
|
|
|
|
- for (Paper paper : papers) {
|
|
|
|
- formatPaper(paper);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- return paperNames;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 向试卷中插入一个试题
|
|
|
|
- *
|
|
|
|
- * @param paperId
|
|
|
|
- * @param paperDetailId
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- public Paper insertQuestionToPaper(String paperId, String paperDetailId, Question question, AccessUser user) {
|
|
|
|
- question.setOrgId(user.getOrgId().toString());
|
|
|
|
- quesService.updateQuesWord(question);
|
|
|
|
- question = quesRepo.save(question);
|
|
|
|
- Paper paper = paperRepo.findOne(paperId);
|
|
|
|
- PaperDetail pd = paperDetailRepo.findOne(paperDetailId);
|
|
|
|
- PaperDetailUnit pdu = new PaperDetailUnit();
|
|
|
|
- List<PaperDetailUnit> pdus = paperDetailUnitRepo.findByPaperDetail(pd);
|
|
|
|
- pdu.setPaper(paper);
|
|
|
|
- pdu.setQuestionType(question.getQuestionType());
|
|
|
|
- pdu.setQuestion(question);
|
|
|
|
- pdu.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
|
- pdu.setPaperDetail(pd);
|
|
|
|
- pdus.add(pdu);
|
|
|
|
- Collections.sort(pdus);
|
|
|
|
- pdu.setNumber(pdus.indexOf(pdu) + 1);
|
|
|
|
- pdu.setScore(0d);
|
|
|
|
- paperDetailUnitRepo.save(pdu);
|
|
|
|
- formatPaper(paper);
|
|
|
|
- return paper;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 获取试题所的试卷名称
|
|
|
|
- *
|
|
|
|
- * @param questionId
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- public List<String> getPaperNamesByQuestionId(String questionId) {
|
|
|
|
- List<String> paperNames = new ArrayList<String>();
|
|
|
|
- List<PaperDetailUnit> pdus = paperDetailUnitRepo.findByQuestion(quesRepo.findOne(questionId));
|
|
|
|
- for (PaperDetailUnit pdu : pdus) {
|
|
|
|
- paperNames.add(pdu.getPaper().getName());
|
|
|
|
- }
|
|
|
|
- return paperNames;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public Page<Question> listQuestionforSelect(String paperId, int curPage, int pageSize, QuesStructType quesType) {
|
|
|
|
- Set<String> selectedIds = new HashSet<>();
|
|
|
|
- Paper paper = paperRepo.findOne(paperId);
|
|
|
|
- // QuestionSearchCondition ques = new QuestionSearchCondition();
|
|
|
|
- // if (quesType != null) {
|
|
|
|
- // ques.setQuestionType(quesType);
|
|
|
|
- // }
|
|
|
|
- // Map<String, String> quesParams = new HashMap<String, String>();
|
|
|
|
- // quesParams.put("courseName", paper.getCourseName());
|
|
|
|
- // ques.setQuesParams(quesParams);
|
|
|
|
- List<PaperDetailUnit> pdus = paperDetailUnitRepo.findByPaper(paper);
|
|
|
|
- for (PaperDetailUnit pdu : pdus) {
|
|
|
|
- selectedIds.add(pdu.getQuestion().getId());
|
|
|
|
- }
|
|
|
|
- // Page<Question> allQuestions = quesService.findAll(ques, curPage,
|
|
|
|
- // pageSize);
|
|
|
|
- // Iterator<Question> que = allQuestions.iterator();
|
|
|
|
- // while (que.hasNext()) {
|
|
|
|
- // if (selectedIds.contains(que.next().getId())) {
|
|
|
|
- // que.remove();
|
|
|
|
- // }
|
|
|
|
- // }
|
|
|
|
- return quesService.findByIdExclude(selectedIds, paper.getCourseNo(), quesType, curPage, pageSize);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public Paper selectQuestionsToPaper(String paperId, String paperDetailId, List<Question> questions) {
|
|
|
|
- Paper paper = paperRepo.findOne(paperId);
|
|
|
|
- PaperDetail pd = paperDetailRepo.findOne(paperDetailId);
|
|
|
|
- List<PaperDetailUnit> pdus = paperDetailUnitRepo.findByPaperDetail(pd);
|
|
|
|
- List<PaperDetailUnit> saveUnits = new ArrayList<PaperDetailUnit>();
|
|
|
|
- for (Question ques : questions) {
|
|
|
|
- PaperDetailUnit pdu = new PaperDetailUnit();
|
|
|
|
- pdu.setPaper(paper);
|
|
|
|
- pdu.setQuestionType(ques.getQuestionType());
|
|
|
|
- pdu.setQuestion(ques);
|
|
|
|
- pdu.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
|
- pdu.setPaperDetail(pd);
|
|
|
|
- pdu.setScore(0d);
|
|
|
|
- pdus.add(pdu);
|
|
|
|
- saveUnits.add(pdu);
|
|
|
|
- }
|
|
|
|
- Collections.sort(pdus);
|
|
|
|
- for (int i = 0; i < saveUnits.size(); i++) {
|
|
|
|
- saveUnits.get(i).setNumber(pdus.indexOf(saveUnits.get(i)) + 1);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- paperDetailUnitRepo.save(saveUnits);
|
|
|
|
- formatPaper(paper);
|
|
|
|
- return paper;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public String checkPaperName(String paperName, String orgId) {
|
|
|
|
- String msg = null;
|
|
|
|
- Paper paperTemp = new Paper();
|
|
|
|
- paperTemp.setName(paperName);
|
|
|
|
- paperTemp.setOrgId(orgId);
|
|
|
|
- Paper paper = paperRepo.findOne(Example.of(paperTemp));
|
|
|
|
- if (paper != null) {
|
|
|
|
- msg = "试卷名称重复,请重新命名";
|
|
|
|
- }
|
|
|
|
- return msg;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
|
|
+package com.qmth.cqb.paper.service;
|
|
|
|
+
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Collections;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.HashSet;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.Set;
|
|
|
|
+
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.data.domain.Example;
|
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import com.google.gson.Gson;
|
|
|
|
+import com.qmth.cqb.paper.dao.ExamPaperRepo;
|
|
|
|
+import com.qmth.cqb.paper.dao.PaperDetailRepo;
|
|
|
|
+import com.qmth.cqb.paper.dao.PaperDetailUnitRepo;
|
|
|
|
+import com.qmth.cqb.paper.dao.PaperRepo;
|
|
|
|
+import com.qmth.cqb.paper.dto.PaperDetailExp;
|
|
|
|
+import com.qmth.cqb.paper.dto.PaperDetailUnitExp;
|
|
|
|
+import com.qmth.cqb.paper.dto.PaperExp;
|
|
|
|
+import com.qmth.cqb.paper.model.ExamPaper;
|
|
|
|
+import com.qmth.cqb.paper.model.Paper;
|
|
|
|
+import com.qmth.cqb.paper.model.PaperDetail;
|
|
|
|
+import com.qmth.cqb.paper.model.PaperDetailUnit;
|
|
|
|
+import com.qmth.cqb.paper.model.PaperSearchInfo;
|
|
|
|
+import com.qmth.cqb.question.dao.QuesBakRepo;
|
|
|
|
+import com.qmth.cqb.question.dao.QuesRepo;
|
|
|
|
+import com.qmth.cqb.question.model.Question;
|
|
|
|
+import com.qmth.cqb.question.model.QuestionBak;
|
|
|
|
+import com.qmth.cqb.question.service.QuesService;
|
|
|
|
+import com.qmth.cqb.utils.BeanCopierUtil;
|
|
|
|
+import com.qmth.cqb.utils.CommonUtils;
|
|
|
|
+import com.qmth.cqb.utils.enums.PaperStatus;
|
|
|
|
+import com.qmth.cqb.utils.enums.PaperType;
|
|
|
|
+
|
|
|
|
+import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
|
|
|
|
+import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Created by songyue on 16/12/28.
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class PaperService {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ PaperRepo paperRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ PaperDetailService paperDetailService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ ExamPaperRepo examPaperRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ PaperDetailRepo paperDetailRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ PaperDetailUnitRepo paperDetailUnitRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ QuesRepo quesRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ QuesBakRepo quesBakRepo;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ Gson gson;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ PaperDetailUnitService paperDetailUnitService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ QuesService quesService;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询所有已导入试卷
|
|
|
|
+ *
|
|
|
|
+ * @param paperSearchInfo
|
|
|
|
+ * @param curPage
|
|
|
|
+ * @param pageSize
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public Page<Paper> getImportPapers(PaperSearchInfo paperSearchInfo, int curPage, int pageSize) {
|
|
|
|
+ formatPaperSearchInfo(paperSearchInfo);
|
|
|
|
+ Paper importPaper = BeanCopierUtil.copyProperties(paperSearchInfo, Paper.class);
|
|
|
|
+ importPaper.setPaperType(PaperType.IMPORT);
|
|
|
|
+ return paperRepo.findAll(Example.of(importPaper), new PageRequest(curPage - 1, pageSize));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 保存试卷
|
|
|
|
+ *
|
|
|
|
+ * @param paperExp
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public Paper savePaper(PaperExp paperExp) {
|
|
|
|
+ Paper paper = BeanCopierUtil.copyProperties(paperExp, Paper.class);
|
|
|
|
+ formatPaper(paper);
|
|
|
|
+ return paperRepo.save(paper);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询所有已组试卷
|
|
|
|
+ *
|
|
|
|
+ * @param paperSearchInfo
|
|
|
|
+ * @param curPage
|
|
|
|
+ * @param pageSize
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public Page<Paper> getGenPapers(PaperSearchInfo paperSearchInfo, int curPage, int pageSize) {
|
|
|
|
+ formatPaperSearchInfo(paperSearchInfo);
|
|
|
|
+ Paper importPaper = BeanCopierUtil.copyProperties(paperSearchInfo, Paper.class);
|
|
|
|
+ importPaper.setPaperType(PaperType.GENERATE);
|
|
|
|
+ return paperRepo.findAll(Example.of(importPaper), new PageRequest(curPage - 1, pageSize));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 查询考试试卷
|
|
|
|
+ *
|
|
|
|
+ * @param id
|
|
|
|
+ * @param courseCode
|
|
|
|
+ * @param groupCode
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public List<Paper> listExamPapers(long id, String courseCode, String groupCode) {
|
|
|
|
+ List<Paper> papers = new ArrayList<Paper>();
|
|
|
|
+ ExamPaper examPaper = new ExamPaper();
|
|
|
|
+ examPaper.setExamId(id);
|
|
|
|
+ examPaper.setCourseCode(courseCode);
|
|
|
|
+ examPaper.setGroupCode(groupCode);
|
|
|
|
+ Example<ExamPaper> example = Example.of(examPaper);
|
|
|
|
+ List<ExamPaper> examPapers = examPaperRepo.findAll(example);
|
|
|
|
+ for (ExamPaper ePaper : examPapers) {
|
|
|
|
+ Paper paper = paperRepo.findOne(ePaper.getPaper().getId());
|
|
|
|
+ papers.add(paper);
|
|
|
|
+ }
|
|
|
|
+ return papers;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 设置考试试卷
|
|
|
|
+ *
|
|
|
|
+ * @param examId
|
|
|
|
+ * @param courseCode
|
|
|
|
+ * @param groupCode
|
|
|
|
+ * @param paperId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public void joinToExamPaper(long examId, String courseCode, String groupCode, String paperId) {
|
|
|
|
+ ExamPaper examPaper = new ExamPaper();
|
|
|
|
+ examPaper.setExamId(examId);
|
|
|
|
+ examPaper.setGroupCode(groupCode);
|
|
|
|
+ examPaper.setCourseCode(courseCode);
|
|
|
|
+// examPaper.setPaperId(paperId);
|
|
|
|
+ examPaperRepo.save(examPaper);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void releaseExamPaper(long examId, String courseCode, String groupCode, String paperId) {
|
|
|
|
+ ExamPaper examPaper = new ExamPaper();
|
|
|
|
+ examPaper.setExamId(examId);
|
|
|
|
+ examPaper.setGroupCode(groupCode);
|
|
|
|
+ examPaper.setCourseCode(courseCode);
|
|
|
|
+// examPaper.setPaperId(paperId);
|
|
|
|
+ examPaperRepo.delete(examPaper);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Set<String> listGroupCodes(long examId, String courseCode) {
|
|
|
|
+ Set<String> groupSet = new HashSet<String>();
|
|
|
|
+ ExamPaper examPaper = new ExamPaper();
|
|
|
|
+ examPaper.setExamId(examId);
|
|
|
|
+ examPaper.setCourseCode(courseCode);
|
|
|
|
+ List<ExamPaper> examPapers = examPaperRepo.findAll(Example.of(examPaper));
|
|
|
|
+ for (ExamPaper expaper : examPapers) {
|
|
|
|
+ groupSet.add(expaper.getGroupCode());
|
|
|
|
+ }
|
|
|
|
+ return groupSet;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void deletGroupCode(long examId, String courseCode, String groupCode) {
|
|
|
|
+ ExamPaper examPaper = new ExamPaper();
|
|
|
|
+ examPaper.setExamId(examId);
|
|
|
|
+ examPaper.setCourseCode(courseCode);
|
|
|
|
+ examPaper.setCourseCode(courseCode);
|
|
|
|
+ examPaperRepo.delete(examPaper);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 根据试卷ID获取试卷下面的大题
|
|
|
|
+ *
|
|
|
|
+ * @param id
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public List<PaperDetail> findPaperDetailsById(String id) {
|
|
|
|
+ return paperDetailService.getPaperDetailsByPaper(paperRepo.findOne(id));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 批量删除试卷
|
|
|
|
+ *
|
|
|
|
+ * @param paperIds
|
|
|
|
+ */
|
|
|
|
+ public String deletePapers(List<String> paperIds) {
|
|
|
|
+ String msg = "";
|
|
|
|
+ List<Paper> papers = CommonUtils.toList(paperRepo.findAll(paperIds));
|
|
|
|
+ for (Paper paper : papers) {
|
|
|
|
+ List<PaperDetailUnit> units = paperDetailUnitRepo.findByPaper(paper);
|
|
|
|
+ if (units.size() > 0) {
|
|
|
|
+ return msg = "试卷里面还有小题,不能删除";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ paperDetailService.deletePaperDetailsByPapers(papers);
|
|
|
|
+ paperRepo.delete(papers);
|
|
|
|
+ msg = "success";
|
|
|
|
+ return msg;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 批量通过试卷
|
|
|
|
+ *
|
|
|
|
+ * @param paperIds
|
|
|
|
+ */
|
|
|
|
+ public void passPapers(List<String> paperIds) {
|
|
|
|
+ List<Paper> papers = CommonUtils.toList(paperRepo.findAll(paperIds));
|
|
|
|
+ papers.stream().forEach(paper -> {
|
|
|
|
+ paper.setPaperStatus(PaperStatus.PASS);
|
|
|
|
+ });
|
|
|
|
+ paperRepo.save(papers);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 批量不通过试卷
|
|
|
|
+ *
|
|
|
|
+ * @param paperIds
|
|
|
|
+ */
|
|
|
|
+ public void noPassPapers(List<String> paperIds) {
|
|
|
|
+ List<Paper> papers = CommonUtils.toList(paperRepo.findAll(paperIds));
|
|
|
|
+ papers.stream().forEach(paper -> {
|
|
|
|
+ paper.setPaperStatus(PaperStatus.NOPASS);
|
|
|
|
+ });
|
|
|
|
+ paperRepo.save(papers);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 批量待审核试卷
|
|
|
|
+ *
|
|
|
|
+ * @param paperIds
|
|
|
|
+ */
|
|
|
|
+ public void backPapers(List<String> paperIds) {
|
|
|
|
+ List<Paper> papers = CommonUtils.toList(paperRepo.findAll(paperIds));
|
|
|
|
+ papers.stream().forEach(paper -> {
|
|
|
|
+ paper.setPaperStatus(PaperStatus.DRAFT);
|
|
|
|
+ });
|
|
|
|
+ paperRepo.save(papers);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 初始化导出试卷DTO
|
|
|
|
+ *
|
|
|
|
+ * @param id
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public PaperExp getPaperDto(String id) {
|
|
|
|
+
|
|
|
|
+ // 获取paper
|
|
|
|
+ Paper paper = paperRepo.findOne(id);
|
|
|
|
+ // 创建paperDto
|
|
|
|
+ PaperExp paperExp = BeanCopierUtil.copyProperties(paper, PaperExp.class);
|
|
|
|
+ // 获取大题
|
|
|
|
+ List<PaperDetail> paperDetails = paperDetailRepo.findByPaper(paper);
|
|
|
|
+ List<PaperDetailExp> paperDetailExps = BeanCopierUtil.copyPropertiesOfList(paperDetails, PaperDetailExp.class);
|
|
|
|
+ paperExp.setPaperDetails(paperDetailExps);
|
|
|
|
+
|
|
|
|
+ // 封装小题
|
|
|
|
+ for (int i = 0; i < paperDetailExps.size(); i++) {
|
|
|
|
+ List<PaperDetailUnit> paperDetailUnits = paperDetailUnitRepo.findByPaperDetail(paperDetails.get(i));
|
|
|
|
+ if (paperDetailUnits != null && paperDetailUnits.size() > 0) {
|
|
|
|
+ List<PaperDetailUnitExp> paperDetailUnitExps = BeanCopierUtil.copyPropertiesOfList(paperDetailUnits,
|
|
|
|
+ PaperDetailUnitExp.class);
|
|
|
|
+ paperDetailExps.get(i).setPaperDetailUnits(paperDetailUnitExps);
|
|
|
|
+ } else {
|
|
|
|
+ paperDetailExps.get(i).setUnitCount(0);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ // 初始化试卷内容
|
|
|
|
+ initPaper(paperExp);
|
|
|
|
+
|
|
|
|
+ return paperExp;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 初始化试卷内容(增加序号)
|
|
|
|
+ *
|
|
|
|
+ * @param paperExp
|
|
|
|
+ */
|
|
|
|
+ public void initPaper(PaperExp paperExp) {
|
|
|
|
+ if (paperExp.getPaperDetails() == null || paperExp.getPaperDetails().size() == 0) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ int mainNum = 0;
|
|
|
|
+ int subNum = 0;
|
|
|
|
+ Collections.sort(paperExp.getPaperDetails());
|
|
|
|
+ for (PaperDetailExp paperDetail : paperExp.getPaperDetails()) {
|
|
|
|
+ // 大题序号
|
|
|
|
+ paperDetail.setCnNum(CommonUtils.toCHNum(paperDetail.getNumber()));
|
|
|
|
+ paperDetail.setNumber(++mainNum);
|
|
|
|
+ if (paperDetail.getPaperDetailUnits() == null || paperDetail.getPaperDetailUnits().size() == 0) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // 小题序号
|
|
|
|
+ for (PaperDetailUnitExp paperDetailUnit : paperDetail.getPaperDetailUnits()) {
|
|
|
|
+
|
|
|
|
+ quesService.formatQuesUnit(paperDetailUnit.getQuestion());
|
|
|
|
+
|
|
|
|
+ List<Question> subQuesList = paperDetailUnit.getQuestion().getSubQuestions();
|
|
|
|
+ // 套题序号
|
|
|
|
+ if (subQuesList != null && subQuesList.size() > 0) {
|
|
|
|
+ for (Question subQues : subQuesList) {
|
|
|
|
+ Map<String, String> params = new HashMap<String, String>();
|
|
|
|
+ params.put("number", String.valueOf(++subNum));
|
|
|
|
+ subQues.setQuesParams(params);
|
|
|
|
+ quesService.formatQuesUnit(subQues);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ paperDetailUnit.setNumber(++subNum);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 格式化查询条件
|
|
|
|
+ *
|
|
|
|
+ * @param paperSearchInfo
|
|
|
|
+ */
|
|
|
|
+ public void formatPaperSearchInfo(PaperSearchInfo paperSearchInfo) {
|
|
|
|
+ if (StringUtils.isEmpty(paperSearchInfo.getCourseNo())) {
|
|
|
|
+ paperSearchInfo.setCourseNo(null);
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isEmpty(paperSearchInfo.getCreateTime())) {
|
|
|
|
+ paperSearchInfo.setCreateTime(null);
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isEmpty(paperSearchInfo.getCreator())) {
|
|
|
|
+ paperSearchInfo.setCreator(null);
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.isEmpty(paperSearchInfo.getName())) {
|
|
|
|
+ paperSearchInfo.setName(null);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 填充大题小题数量与分数
|
|
|
|
+ *
|
|
|
|
+ * @param paper
|
|
|
|
+ */
|
|
|
|
+ public void formatPaper(Paper paper) {
|
|
|
|
+ List<PaperDetail> paperDetails = paperDetailRepo.findByPaper(paper);
|
|
|
|
+ // 计算试卷总分
|
|
|
|
+ List<PaperDetailUnit> paperDetailUnitAll = paperDetailUnitRepo.findByPaper(paper);
|
|
|
|
+ double totalScore = 0;
|
|
|
|
+ for (PaperDetailUnit unit : paperDetailUnitAll) {
|
|
|
|
+ if (unit.getScore() != null) {
|
|
|
|
+ totalScore += unit.getScore();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ // 计算各大题总分
|
|
|
|
+ for (PaperDetail paperDetail : paperDetails) {
|
|
|
|
+ List<PaperDetailUnit> paperDetailUnits = paperDetailUnitRepo.findByPaperDetail(paperDetail);
|
|
|
|
+ Collections.sort(paperDetailUnits);
|
|
|
|
+ if (paperDetailUnits.size() > 0) {
|
|
|
|
+ int count = 0;
|
|
|
|
+ double score = 0;
|
|
|
|
+ int nestQusNum = 0;
|
|
|
|
+ for (PaperDetailUnit unit : paperDetailUnits) {
|
|
|
|
+ if (unit.getScore() != null) {
|
|
|
|
+ score += unit.getScore();
|
|
|
|
+ }
|
|
|
|
+ if (unit.getQuestion().getSubQuestions() != null
|
|
|
|
+ && unit.getQuestion().getSubQuestions().size() > 0) {
|
|
|
|
+ nestQusNum += unit.getQuestion().getSubQuestions().size() - 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ count = paperDetailUnits.size() + nestQusNum;
|
|
|
|
+ paperDetail.setScore(score);
|
|
|
|
+ paperDetail.setUnitCount(count);
|
|
|
|
+ } else {
|
|
|
|
+ paperDetail.setScore(0d);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ paper.setUnitCount(paperDetailUnitAll.size());
|
|
|
|
+ paper.setPaperDetailCount(paperDetails.size());
|
|
|
|
+ paper.setTotalScore(totalScore);
|
|
|
|
+ paperDetailRepo.save(paperDetails);
|
|
|
|
+ paperRepo.save(paper);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 先备份准备删掉的试题,然后再删掉
|
|
|
|
+ *
|
|
|
|
+ * @param questionId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public List<String> deleteImportQuestionById(String questionId) {
|
|
|
|
+ Question ques = quesRepo.findOne(questionId);
|
|
|
|
+ List<PaperDetailUnit> pdus = CommonUtils.toList(paperDetailUnitRepo.findByQuestion(ques));
|
|
|
|
+ List<String> paperNames = new ArrayList<String>();
|
|
|
|
+ List<PaperDetailUnit> needPdus = new ArrayList<PaperDetailUnit>();// 需要删除的小题
|
|
|
|
+ List<Paper> papers = new ArrayList<Paper>();
|
|
|
|
+ for (PaperDetailUnit pdu : pdus) {
|
|
|
|
+ if (PaperType.GENERATE == pdu.getPaper().getPaperType()) {
|
|
|
|
+ paperNames.add(pdu.getPaper().getName());
|
|
|
|
+ needPdus.add(pdu);
|
|
|
|
+ if (!papers.contains(pdu.getPaper())) {
|
|
|
|
+ papers.add(pdu.getPaper());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (paperNames.size() == 0) {// 此试题没有被组卷调用,则可以删除此试题
|
|
|
|
+ paperDetailUnitRepo.delete(needPdus);
|
|
|
|
+ quesBakRepo.save(BeanCopierUtil.copyProperties(ques, QuestionBak.class));
|
|
|
|
+ quesRepo.delete(ques);
|
|
|
|
+ for (Paper paper : papers) {
|
|
|
|
+ formatPaper(paper);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ return paperNames;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 向试卷中插入一个试题
|
|
|
|
+ *
|
|
|
|
+ * @param paperId
|
|
|
|
+ * @param paperDetailId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public Paper insertQuestionToPaper(String paperId, String paperDetailId, Question question, AccessUser user) {
|
|
|
|
+ question.setOrgId(user.getOrgId().toString());
|
|
|
|
+ quesService.updateQuesWord(question);
|
|
|
|
+ question = quesRepo.save(question);
|
|
|
|
+ Paper paper = paperRepo.findOne(paperId);
|
|
|
|
+ PaperDetail pd = paperDetailRepo.findOne(paperDetailId);
|
|
|
|
+ PaperDetailUnit pdu = new PaperDetailUnit();
|
|
|
|
+ List<PaperDetailUnit> pdus = paperDetailUnitRepo.findByPaperDetail(pd);
|
|
|
|
+ pdu.setPaper(paper);
|
|
|
|
+ pdu.setQuestionType(question.getQuestionType());
|
|
|
|
+ pdu.setQuestion(question);
|
|
|
|
+ pdu.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
|
+ pdu.setPaperDetail(pd);
|
|
|
|
+ pdus.add(pdu);
|
|
|
|
+ Collections.sort(pdus);
|
|
|
|
+ pdu.setNumber(pdus.indexOf(pdu) + 1);
|
|
|
|
+ pdu.setScore(0d);
|
|
|
|
+ paperDetailUnitRepo.save(pdu);
|
|
|
|
+ formatPaper(paper);
|
|
|
|
+ return paper;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取试题所的试卷名称
|
|
|
|
+ *
|
|
|
|
+ * @param questionId
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public List<String> getPaperNamesByQuestionId(String questionId) {
|
|
|
|
+ List<String> paperNames = new ArrayList<String>();
|
|
|
|
+ List<PaperDetailUnit> pdus = paperDetailUnitRepo.findByQuestion(quesRepo.findOne(questionId));
|
|
|
|
+ for (PaperDetailUnit pdu : pdus) {
|
|
|
|
+ paperNames.add(pdu.getPaper().getName());
|
|
|
|
+ }
|
|
|
|
+ return paperNames;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Page<Question> listQuestionforSelect(String paperId, int curPage, int pageSize, QuesStructType quesType) {
|
|
|
|
+ Set<String> selectedIds = new HashSet<>();
|
|
|
|
+ Paper paper = paperRepo.findOne(paperId);
|
|
|
|
+ // QuestionSearchCondition ques = new QuestionSearchCondition();
|
|
|
|
+ // if (quesType != null) {
|
|
|
|
+ // ques.setQuestionType(quesType);
|
|
|
|
+ // }
|
|
|
|
+ // Map<String, String> quesParams = new HashMap<String, String>();
|
|
|
|
+ // quesParams.put("courseName", paper.getCourseName());
|
|
|
|
+ // ques.setQuesParams(quesParams);
|
|
|
|
+ List<PaperDetailUnit> pdus = paperDetailUnitRepo.findByPaper(paper);
|
|
|
|
+ for (PaperDetailUnit pdu : pdus) {
|
|
|
|
+ selectedIds.add(pdu.getQuestion().getId());
|
|
|
|
+ }
|
|
|
|
+ // Page<Question> allQuestions = quesService.findAll(ques, curPage,
|
|
|
|
+ // pageSize);
|
|
|
|
+ // Iterator<Question> que = allQuestions.iterator();
|
|
|
|
+ // while (que.hasNext()) {
|
|
|
|
+ // if (selectedIds.contains(que.next().getId())) {
|
|
|
|
+ // que.remove();
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ return quesService.findByIdExclude(selectedIds, paper.getCourseNo(), quesType, curPage, pageSize);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Paper selectQuestionsToPaper(String paperId, String paperDetailId, List<Question> questions) {
|
|
|
|
+ Paper paper = paperRepo.findOne(paperId);
|
|
|
|
+ PaperDetail pd = paperDetailRepo.findOne(paperDetailId);
|
|
|
|
+ List<PaperDetailUnit> pdus = paperDetailUnitRepo.findByPaperDetail(pd);
|
|
|
|
+ List<PaperDetailUnit> saveUnits = new ArrayList<PaperDetailUnit>();
|
|
|
|
+ for (Question ques : questions) {
|
|
|
|
+ PaperDetailUnit pdu = new PaperDetailUnit();
|
|
|
|
+ pdu.setPaper(paper);
|
|
|
|
+ pdu.setQuestionType(ques.getQuestionType());
|
|
|
|
+ pdu.setQuestion(ques);
|
|
|
|
+ pdu.setCreateTime(CommonUtils.getCurDateTime());
|
|
|
|
+ pdu.setPaperDetail(pd);
|
|
|
|
+ pdu.setScore(0d);
|
|
|
|
+ pdus.add(pdu);
|
|
|
|
+ saveUnits.add(pdu);
|
|
|
|
+ }
|
|
|
|
+ Collections.sort(pdus);
|
|
|
|
+ for (int i = 0; i < saveUnits.size(); i++) {
|
|
|
|
+ saveUnits.get(i).setNumber(pdus.indexOf(saveUnits.get(i)) + 1);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ paperDetailUnitRepo.save(saveUnits);
|
|
|
|
+ formatPaper(paper);
|
|
|
|
+ return paper;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public String checkPaperName(String paperName, String orgId) {
|
|
|
|
+ String msg = null;
|
|
|
|
+ Paper paperTemp = new Paper();
|
|
|
|
+ paperTemp.setName(paperName);
|
|
|
|
+ paperTemp.setOrgId(orgId);
|
|
|
|
+ Paper paper = paperRepo.findOne(Example.of(paperTemp));
|
|
|
|
+ if (paper != null) {
|
|
|
|
+ msg = "试卷名称重复,请重新命名";
|
|
|
|
+ }
|
|
|
|
+ return msg;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|