|
@@ -1,1237 +1,1238 @@
|
|
|
-package com.qmth.cqb.paper.service.impl;
|
|
|
-
|
|
|
-import java.io.BufferedInputStream;
|
|
|
-import java.io.File;
|
|
|
-import java.io.FileOutputStream;
|
|
|
-import java.io.IOException;
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.math.RoundingMode;
|
|
|
-import java.text.DecimalFormat;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Random;
|
|
|
-import java.util.Set;
|
|
|
-import java.util.regex.Matcher;
|
|
|
-import java.util.regex.Pattern;
|
|
|
-
|
|
|
-import main.java.com.UpYun;
|
|
|
-
|
|
|
-import org.apache.commons.io.FileUtils;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.nlpcn.commons.lang.util.StringUtil;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.data.domain.Example;
|
|
|
-import org.springframework.data.domain.Page;
|
|
|
-import org.springframework.data.domain.PageImpl;
|
|
|
-import org.springframework.data.domain.PageRequest;
|
|
|
-import org.springframework.data.domain.Sort;
|
|
|
-import org.springframework.data.domain.Sort.Direction;
|
|
|
-import org.springframework.data.domain.Sort.Order;
|
|
|
-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.data.redis.core.RedisTemplate;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.util.Assert;
|
|
|
-import org.springframework.web.multipart.MultipartFile;
|
|
|
-
|
|
|
-import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
|
|
|
-import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
|
|
|
-
|
|
|
-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.paper.service.ExtractConfigService;
|
|
|
-import com.qmth.cqb.paper.service.PaperDetailService;
|
|
|
-import com.qmth.cqb.paper.service.PaperDetailUnitService;
|
|
|
-import com.qmth.cqb.paper.service.PaperService;
|
|
|
-import com.qmth.cqb.question.dao.QuesBakRepo;
|
|
|
-import com.qmth.cqb.question.dao.QuesRepo;
|
|
|
-import com.qmth.cqb.question.dao.QuestionAudioRepo;
|
|
|
-import com.qmth.cqb.question.model.QuesOption;
|
|
|
-import com.qmth.cqb.question.model.Question;
|
|
|
-import com.qmth.cqb.question.model.QuestionAudio;
|
|
|
-import com.qmth.cqb.question.model.QuestionBak;
|
|
|
-import com.qmth.cqb.question.service.QuesService;
|
|
|
-import com.qmth.cqb.question.service.impl.QuestionAudioServiceImpl;
|
|
|
-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 com.qmth.cqb.utils.exception.PaperException;
|
|
|
-
|
|
|
-/**
|
|
|
- * @author chenken
|
|
|
- * @date 2017年9月12日 上午11:20:44
|
|
|
- * @company QMTH
|
|
|
- * @description PaperServiceImpl.java
|
|
|
- */
|
|
|
-@Service("paperService")
|
|
|
-public class PaperServiceImpl implements 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;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- ExtractConfigService extractConfigService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private MongoTemplate mongoTemplate;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private QuestionAudioServiceImpl questionAudioService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private QuestionAudioRepo questionAudioRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private RedisTemplate redisTemplate;
|
|
|
-
|
|
|
- @Value("${upyun.radioType}")
|
|
|
- private String radioType;
|
|
|
-
|
|
|
- @Value("${upyun.audio.maxsize}")
|
|
|
- private String audioMaxsize;
|
|
|
-
|
|
|
- @Value("${upyun.audio.uploadUrl}")
|
|
|
- private String upyunRadioPath;
|
|
|
-
|
|
|
- @Value("${upyun.bucketName}")
|
|
|
- private String bucketName;
|
|
|
-
|
|
|
- @Value("${upyun.userName}")
|
|
|
- private String userName;
|
|
|
-
|
|
|
- @Value("${upyun.password}")
|
|
|
- private String password;
|
|
|
-
|
|
|
- public static final String TEMP_FILE_EXP = "docxExport/";
|
|
|
-
|
|
|
- /**
|
|
|
- * 查询所有已导入试卷
|
|
|
- *
|
|
|
- * @param paperSearchInfo
|
|
|
- * @param curPage
|
|
|
- * @param pageSize
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Page<Paper> getImportPapers(PaperSearchInfo paperSearchInfo, int curPage, int pageSize) {
|
|
|
- Query query = new Query();
|
|
|
- query.addCriteria(Criteria.where("orgId").is(paperSearchInfo.getOrgId()));
|
|
|
- query.addCriteria(Criteria.where("paperType").is(PaperType.IMPORT));
|
|
|
- query.addCriteria(Criteria.where("course.enable").is("true"));
|
|
|
- if(StringUtils.isNotBlank(paperSearchInfo.getCourseNo())){
|
|
|
- query.addCriteria(Criteria.where("course.code").is(paperSearchInfo.getCourseNo()));
|
|
|
- }
|
|
|
- if(StringUtils.isNotBlank(paperSearchInfo.getSpecialtyNo())){
|
|
|
- query.addCriteria(Criteria.where("specialty.code").is(paperSearchInfo.getSpecialtyNo()));
|
|
|
- }
|
|
|
- if(StringUtils.isNotBlank(paperSearchInfo.getLevel())){
|
|
|
- query.addCriteria(Criteria.where("course.level").is(paperSearchInfo.getLevel()));
|
|
|
- }
|
|
|
- long count = this.mongoTemplate.count(query, Paper.class);
|
|
|
- query.with(new Sort(new Order(Direction.DESC,"createTime")));
|
|
|
- query.limit(pageSize);
|
|
|
- query.skip((curPage - 1) * pageSize);
|
|
|
- List<Paper> paperList = this.mongoTemplate.find(query, Paper.class);
|
|
|
- return new PageImpl<Paper>(paperList, new PageRequest(curPage - 1, pageSize), count);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 查询所有待审核和审核不通过的导入试卷
|
|
|
- *
|
|
|
- * @param paperSearchInfo
|
|
|
- * @param curPage
|
|
|
- * @param pageSize
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Page<Paper> getImportPapersNotSuccess(PaperSearchInfo paperSearchInfo, int curPage, int pageSize) {
|
|
|
- Query query = new Query();
|
|
|
- query.addCriteria(Criteria.where("orgId").is(paperSearchInfo.getOrgId()));
|
|
|
- query.addCriteria(Criteria.where("paperType").is(PaperType.IMPORT));
|
|
|
- query.addCriteria(Criteria.where("course.enable").is("true"));
|
|
|
- if (paperSearchInfo.getPaperStatus() != null) {
|
|
|
- query.addCriteria(Criteria.where("paperStatus").is(paperSearchInfo.getPaperStatus()));
|
|
|
- } else {
|
|
|
- query.addCriteria(Criteria.where("paperStatus").ne(PaperStatus.PASS));
|
|
|
- }
|
|
|
- if (StringUtil.isNotBlank(paperSearchInfo.getCourseNo())) {
|
|
|
- query.addCriteria(Criteria.where("course.code").is(paperSearchInfo.getCourseNo()));
|
|
|
- }
|
|
|
- long totalNumber = this.mongoTemplate.count(query, Paper.class);
|
|
|
- query.limit(pageSize);
|
|
|
- query.skip((curPage - 1) * pageSize);
|
|
|
- List<Paper> paperList = this.mongoTemplate.find(query, Paper.class);
|
|
|
- return new PageImpl<Paper>(paperList, new PageRequest(curPage - 1, pageSize), totalNumber);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 根据条件查询
|
|
|
- *
|
|
|
- * @param paperSearchInfo
|
|
|
- * @return
|
|
|
- */
|
|
|
- public List<Paper> getImportPapersBySearch(PaperSearchInfo paperSearchInfo) {
|
|
|
- Query query = new Query();
|
|
|
- query.addCriteria(Criteria.where("orgId").is(paperSearchInfo.getOrgId()));
|
|
|
- query.addCriteria(Criteria.where("paperType").is(PaperType.IMPORT.name()));
|
|
|
- query.addCriteria(Criteria.where("course.enable").is("true"));
|
|
|
- if(StringUtils.isNotBlank(paperSearchInfo.getCourseNo())){
|
|
|
- query.addCriteria(Criteria.where("course.code").is(paperSearchInfo.getCourseNo()));
|
|
|
- }
|
|
|
- if(StringUtils.isNotBlank(paperSearchInfo.getLevel())){
|
|
|
- query.addCriteria(Criteria.where("course.level").is(paperSearchInfo.getLevel()));
|
|
|
- }
|
|
|
- List<Paper> paperList = this.mongoTemplate.find(query, Paper.class);
|
|
|
- return paperList;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 根据条件查询
|
|
|
- *
|
|
|
- * @param paperSearchInfo
|
|
|
- * @return
|
|
|
- */
|
|
|
- public List<Paper> getGenPapersBySearch(PaperSearchInfo paperSearchInfo) {
|
|
|
- Query query = new Query();
|
|
|
- query.addCriteria(Criteria.where("orgId").is(paperSearchInfo.getOrgId()));
|
|
|
- query.addCriteria(Criteria.where("paperType").is(PaperType.GENERATE.name()));
|
|
|
- query.addCriteria(Criteria.where("course.enable").is("true"));
|
|
|
- if(StringUtils.isNotBlank(paperSearchInfo.getCourseNo())){
|
|
|
- query.addCriteria(Criteria.where("course.code").is(paperSearchInfo.getCourseNo()));
|
|
|
- }
|
|
|
- if(StringUtils.isNotBlank(paperSearchInfo.getLevel())){
|
|
|
- query.addCriteria(Criteria.where("course.level").is(paperSearchInfo.getLevel()));
|
|
|
- }
|
|
|
- List<Paper> paperList = this.mongoTemplate.find(query, Paper.class);
|
|
|
- return paperList;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 保存试卷
|
|
|
- *
|
|
|
- * @param paperExp
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Map<String, Object> savePaper(PaperExp paperExp, AccessUser user) {
|
|
|
- Map<String, Object> msgMap = new HashMap<String, Object>();
|
|
|
- Paper oldPaper = paperRepo.findOne(paperExp.getId());
|
|
|
- if (oldPaper != null) {
|
|
|
- String oldName = oldPaper.getName().trim();
|
|
|
- oldPaper.setTitle(paperExp.getTitle());
|
|
|
- oldPaper.setName(paperExp.getName().trim());
|
|
|
- oldPaper.setLastModifyName(user.getName());
|
|
|
- if (!oldName.equals(paperExp.getName().trim())) {// 假如改变了试卷名称
|
|
|
- // 则要效验试卷名称唯一性
|
|
|
- String msg = this.checkPaperName(paperExp.getName().trim(), user.getRootOrgId().toString());
|
|
|
- if (msg == null) {
|
|
|
- formatPaper(oldPaper, user);
|
|
|
- paperRepo.save(oldPaper);
|
|
|
- msgMap.put("msg", "success");
|
|
|
- } else {
|
|
|
- msgMap.put("msg", msg);
|
|
|
- }
|
|
|
- } else {
|
|
|
- formatPaper(oldPaper, user);
|
|
|
- paperRepo.save(oldPaper);
|
|
|
- msgMap.put("msg", "success");
|
|
|
- }
|
|
|
- }
|
|
|
- //删除缓存
|
|
|
- redisTemplate.delete(paperExp.getId());
|
|
|
- return msgMap;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 查询所有已组试卷
|
|
|
- *
|
|
|
- * @param paperSearchInfo
|
|
|
- * @param curPage
|
|
|
- * @param pageSize
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Page<Paper> getGenPapers(PaperSearchInfo paperSearchInfo, int curPage, int pageSize) {
|
|
|
- Query query = new Query();
|
|
|
- query.addCriteria(Criteria.where("orgId").is(paperSearchInfo.getOrgId()));
|
|
|
- query.addCriteria(Criteria.where("paperType").is(PaperType.GENERATE.name()));
|
|
|
- query.addCriteria(Criteria.where("course.enable").is("true"));
|
|
|
- if(StringUtils.isNotBlank(paperSearchInfo.getCourseNo())){
|
|
|
- query.addCriteria(Criteria.where("course.code").is(paperSearchInfo.getCourseNo()));
|
|
|
- }
|
|
|
- if(StringUtils.isNoneBlank(paperSearchInfo.getName())){
|
|
|
- query.addCriteria(Criteria.where("name").regex(".*?\\.*" +paperSearchInfo.getName() + ".*"));
|
|
|
- }
|
|
|
- if(StringUtils.isNotBlank(paperSearchInfo.getLevel())){
|
|
|
- query.addCriteria(Criteria.where("course.level").is(paperSearchInfo.getLevel()));
|
|
|
- }
|
|
|
- long count = this.mongoTemplate.count(query, Paper.class);
|
|
|
- query.with(new Sort(new Order(Direction.DESC,"createTime")));
|
|
|
- query.limit(pageSize);
|
|
|
- query.skip((curPage - 1) * pageSize);
|
|
|
- List<Paper> paperList = this.mongoTemplate.find(query, Paper.class);
|
|
|
- return new PageImpl<Paper>(paperList, new PageRequest(curPage - 1, pageSize), count);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 查询考试试卷
|
|
|
- *
|
|
|
- * @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 Map<String, Object> deletePapers(List<String> paperIds) {
|
|
|
- Map<String, Object> msgMap = new HashMap<String, Object>();
|
|
|
- String msg = "";
|
|
|
- List<Paper> papers = CommonUtils.toList(paperRepo.findAll(paperIds));
|
|
|
- if (papers.get(0).getPaperType() == PaperType.IMPORT) {
|
|
|
- List<Question> quesList = new ArrayList<Question>();
|
|
|
- for (Paper paper : papers) {
|
|
|
- List<PaperDetailUnit> paperUnits = paperDetailUnitRepo.findByPaperOrderByNumber(paper);
|
|
|
- for (PaperDetailUnit pdu : paperUnits) {
|
|
|
- if (pdu.getQuestion() != null) {
|
|
|
- quesList.add(pdu.getQuestion());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- List<PaperDetailUnit> allUnits = paperDetailUnitRepo.findByQuestionIn(quesList);
|
|
|
- for (PaperDetailUnit pdu : allUnits) {
|
|
|
- if (pdu.getPaper() != null && pdu.getPaper().getPaperType() == PaperType.GENERATE) {
|
|
|
- msg = "待删除试卷中有试题被组卷使用,不能删除!";
|
|
|
- msgMap.put("msg", msg);
|
|
|
- msgMap.put("paperName", pdu.getPaper().getName());
|
|
|
- return msgMap;
|
|
|
- // for(PaperDetailUnit ipdu: importPaperUnits){
|
|
|
- // if(ipdu.getQuestion().getId().equals(pdu.getQuestion().getId())){
|
|
|
- //
|
|
|
- // }
|
|
|
- // }
|
|
|
- }
|
|
|
- }
|
|
|
- quesRepo.delete(quesList);
|
|
|
- } else if (papers.get(0).getPaperType() == PaperType.GENERATE) {
|
|
|
- for (Paper paper : papers) {
|
|
|
- List<String> examPaperIds = extractConfigService.getExamPaperId(paper.getCourseNo(), paper.getOrgId());
|
|
|
- if (examPaperIds != null && examPaperIds.contains(paper.getId())) {
|
|
|
- msg = "待删除试卷有被调卷规则使 用,不能删除!";
|
|
|
- msgMap.put("msg", msg);
|
|
|
- msgMap.put("paperName", paper.getName());
|
|
|
- return msgMap;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- paperDetailService.deletePaperDetailsByPapers(papers);
|
|
|
- paperRepo.delete(papers);
|
|
|
- //删除缓存
|
|
|
- redisTemplate.delete(paperIds);
|
|
|
- msg = "success";
|
|
|
- msgMap.put("msg", msg);
|
|
|
- return msgMap;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 批量通过试卷
|
|
|
- *
|
|
|
- * @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 = paperRepo.findOne(id);
|
|
|
- // 创建paperDto
|
|
|
- PaperExp paperExp = BeanCopierUtil.copyProperties(paper,PaperExp.class);
|
|
|
- paperExp.setCourse(paper.getCourse());
|
|
|
- // 获取大题
|
|
|
- List<PaperDetail> paperDetails = paperDetailRepo.findByPaperOrderByNumber(paper);
|
|
|
- List<PaperDetailExp> paperDetailExps = BeanCopierUtil.copyPropertiesOfList(paperDetails, PaperDetailExp.class);
|
|
|
- // 封装小题
|
|
|
- for (int i = 0; i < paperDetailExps.size(); i++) {
|
|
|
- List<PaperDetailUnit> paperDetailUnits = paperDetailUnitRepo.findByPaperDetailOrderByNumber(paperDetails.get(i));
|
|
|
- if (paperDetailUnits != null && paperDetailUnits.size() > 0) {
|
|
|
- List<PaperDetailUnitExp> paperDetailUnitExps = BeanCopierUtil.copyPropertiesOfList(paperDetailUnits,PaperDetailUnitExp.class);
|
|
|
- // 选择题,套题下选择题 选项顺序重新排列
|
|
|
- reorderChoicequestionOption(paperDetailUnitExps);
|
|
|
- paperDetailExps.get(i).setPaperDetailUnits(paperDetailUnitExps);
|
|
|
- } else {
|
|
|
- paperDetailExps.get(i).setUnitCount(0);
|
|
|
- }
|
|
|
- }
|
|
|
- paperExp.setPaperDetails(paperDetailExps);
|
|
|
- // 初始化试卷内容
|
|
|
- initPaper(paperExp);
|
|
|
- return paperExp;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 重新对选择题option进行排序(多选、单选、套题下选择题)
|
|
|
- */
|
|
|
- public void reorderChoicequestionOption(List<PaperDetailUnitExp> paperDetailUnitExps) {
|
|
|
- for (PaperDetailUnitExp paperDetailUnitExp : paperDetailUnitExps) {
|
|
|
- String optionOrder = paperDetailUnitExp.getOptionOrder();
|
|
|
- if (StringUtil.isNotBlank(optionOrder)) {
|
|
|
- Question question = paperDetailUnitExp.getQuestion();
|
|
|
- if (question.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION
|
|
|
- || question.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION) {
|
|
|
- question.setQuesOptions(reorderOptionCore(question.getQuesOptions(), optionOrder));
|
|
|
- }
|
|
|
- if (question.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {
|
|
|
- List<Question> subQuestions = question.getSubQuestions();
|
|
|
- int index = 0;
|
|
|
- for (int k = 0; k < subQuestions.size(); k++) {
|
|
|
- Question subQuestion = subQuestions.get(k);
|
|
|
- if (subQuestion.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION
|
|
|
- || subQuestion.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION) {
|
|
|
- subQuestion.setQuesOptions(
|
|
|
- reorderOptionCore(subQuestion.getQuesOptions(), optionOrder.split(";")[index]));
|
|
|
- index++;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private List<QuesOption> reorderOptionCore(List<QuesOption> quesOptions, String optionOrder) {
|
|
|
- List<QuesOption> newQuesOptions = new ArrayList<QuesOption>();
|
|
|
- if (StringUtil.isBlank(optionOrder) || quesOptions.isEmpty()) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- String[] optionOrderArr = optionOrder.split(",");
|
|
|
- for (int j = 0; j < optionOrderArr.length; j++) {
|
|
|
- for (int k = 0; k < quesOptions.size(); k++) {
|
|
|
- if (optionOrderArr[j].equals(quesOptions.get(k).getNumber())) {
|
|
|
- newQuesOptions.add(quesOptions.get(k));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- quesOptions = null;
|
|
|
- return newQuesOptions;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 初始化试卷内容(增加序号)
|
|
|
- *
|
|
|
- * @param paperExp
|
|
|
- */
|
|
|
- public void initPaper(PaperExp paperExp) {
|
|
|
- DecimalFormat df = new DecimalFormat("#.00");
|
|
|
- if (paperExp.getPaperDetails() == null || paperExp.getPaperDetails().size() == 0) {
|
|
|
- return;
|
|
|
- }
|
|
|
- int mainNum = 0;
|
|
|
- List<PaperDetailExp> paperDetailExpList = paperExp.getPaperDetails();
|
|
|
- for (PaperDetailExp paperDetail : paperDetailExpList) {
|
|
|
- // 大题序号
|
|
|
- paperDetail.setNumber(++mainNum);
|
|
|
- paperDetail.setCnNum(CommonUtils.toCHNum(paperDetail.getNumber()));
|
|
|
- if (paperDetail != null && paperDetail.getPaperDetailUnits() != null&& paperDetail.getPaperDetailUnits().size() > 0) {
|
|
|
- for (PaperDetailUnitExp paperDetailUnit : paperDetail.getPaperDetailUnits()) {
|
|
|
- Question question = paperDetailUnit.getQuestion();
|
|
|
- if (question != null) {
|
|
|
- if(question.getHasAudio()!=null&&question.getHasAudio()){
|
|
|
- paperExp.setHasAudio(true); //设置试卷含有音频
|
|
|
- }
|
|
|
- quesService.formatQuesUnit(question);
|
|
|
- List<Question> subQuesList = question.getSubQuestions();
|
|
|
- // 套题序号
|
|
|
- if (subQuesList != null && subQuesList.size() > 0) {
|
|
|
- int index = 0;
|
|
|
- for (Question subQues : subQuesList) {
|
|
|
- Map<String, String> params = new HashMap<String, String>();
|
|
|
- params.put("number", String.valueOf(++index));
|
|
|
- subQues.setQuesParams(params);
|
|
|
- quesService.formatQuesUnit(subQues);
|
|
|
- }
|
|
|
- String quesBodyHtml = relaceQuestionIdx(question.getQuesBody(),0);
|
|
|
- question.setQuesBody(quesBodyHtml);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 格式化查询条件
|
|
|
- *
|
|
|
- * @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);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- *1.重新设置小题number,并返回试卷总分
|
|
|
- *2.重新计算大题的总分和小题总数
|
|
|
- *3.重新保存试卷大题数量、小题数量、试卷总分等信息
|
|
|
- * @param paper
|
|
|
- */
|
|
|
- public void formatPaper(Paper paper, AccessUser user) {
|
|
|
- double paperTotalScore = reSetPaperDetailUnit(paper);
|
|
|
- paper.setDifficultyDegree(reSetDifficulty(paper,paperTotalScore));
|
|
|
- Map<String,Object> paperInfoMap = reSetPaperDetail(paper);
|
|
|
- reSetPaper(paper,user,paperInfoMap,paperTotalScore);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 计算试卷难度
|
|
|
- * @param paper
|
|
|
- * @param paperTotalScore
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Double reSetDifficulty(Paper paper,double paperTotalScore) {
|
|
|
- Double sum = 0.0;
|
|
|
- List<PaperDetail> paperDetails = paperDetailRepo.findByPaperOrderByNumber(paper);
|
|
|
- if(paperDetails != null && paperDetails.size()>0){
|
|
|
- for(PaperDetail paperDetail:paperDetails){
|
|
|
- //获取每个大题下面的所有小题
|
|
|
- List<PaperDetailUnit> paperDetailUnits = paperDetailUnitRepo.findByPaperDetailOrderByNumber(paperDetail);
|
|
|
- if(paperDetailUnits!=null && paperDetailUnits.size()>0){
|
|
|
- for(PaperDetailUnit paperDetailUnit:paperDetailUnits){
|
|
|
- //如果为套题,重新计算难度
|
|
|
- if(paperDetailUnit.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION){
|
|
|
- //重新计算套题的难度,公开度
|
|
|
- boolean publicity = false;
|
|
|
- double totalSum = 0d;
|
|
|
- double totalDou = 0d;
|
|
|
- for(int i =0;i<paperDetailUnit.getQuestion().getSubQuestions().size();i++){
|
|
|
- Question subQuestion = paperDetailUnit.getQuestion().getSubQuestions().get(i);
|
|
|
- //设置公开度
|
|
|
- if(subQuestion.getPublicity()){
|
|
|
- publicity = true;
|
|
|
- }
|
|
|
- if(subQuestion.getDifficultyDegree() == null){
|
|
|
- subQuestion.setDifficultyDegree(0.5);
|
|
|
- }
|
|
|
- totalSum = subQuestion.getDifficultyDegree()*paperDetailUnit.getSubScoreList().get(i) + totalSum;
|
|
|
- totalDou = paperDetailUnit.getSubScoreList().get(i) + totalDou;
|
|
|
- }
|
|
|
- BigDecimal b = new BigDecimal(totalSum / totalDou);
|
|
|
- Double difficulty = b.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
- paperDetailUnit.getQuestion().setDifficultyDegree(difficulty);
|
|
|
- paperDetailUnit.setScore(totalDou);
|
|
|
- }
|
|
|
- //旧题没有难度值,需要重新赋值
|
|
|
- if(paperDetailUnit.getQuestion().getDifficultyDegree()== null){
|
|
|
- paperDetailUnit.getQuestion().setDifficultyDegree(0.5);
|
|
|
- }
|
|
|
- if(paperDetailUnit.getScore()== null){
|
|
|
- paperDetailUnit.setScore(0d);
|
|
|
- }
|
|
|
- sum = paperDetailUnit.getScore() * paperDetailUnit.getQuestion().getDifficultyDegree() + sum;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if(paperTotalScore < 0.1){
|
|
|
- return 0.0;
|
|
|
- }
|
|
|
- BigDecimal b = new BigDecimal(sum / paperTotalScore);
|
|
|
- Double difficulty = b.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
- return difficulty;
|
|
|
- }
|
|
|
- return 0.0;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 重新设置小题number,并返回试卷总分
|
|
|
- * @param paper
|
|
|
- * @return
|
|
|
- */
|
|
|
- private double reSetPaperDetailUnit(Paper paper) {
|
|
|
- List<PaperDetailUnit> paperDetailUnitAll = paperDetailUnitService.findByPaperAndSort(paper);
|
|
|
- double totalScore = 0;
|
|
|
- for (int i = 0;i<paperDetailUnitAll.size();i++) {
|
|
|
- PaperDetailUnit unit = paperDetailUnitAll.get(i);
|
|
|
- if (unit.getScore() != null) {
|
|
|
- totalScore += unit.getScore();
|
|
|
- }
|
|
|
- unit.setNumber(i+1);
|
|
|
- }
|
|
|
- paperDetailUnitRepo.save(paperDetailUnitAll);
|
|
|
- totalScore = CommonUtils.formatDouble(totalScore);
|
|
|
- return totalScore;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 重新计算大题的总分和小题总数
|
|
|
- * @param paper
|
|
|
- */
|
|
|
- private Map<String,Object> reSetPaperDetail(Paper paper) {
|
|
|
- Map<String,Object> paperInfoMap = new HashMap<String,Object>();
|
|
|
- int allQuesCount = 0;
|
|
|
- List<PaperDetail> paperDetails = paperDetailRepo.findByPaperOrderByNumber(paper);
|
|
|
- // 计算各大题总分和小题数量
|
|
|
- for (PaperDetail paperDetail : paperDetails) {
|
|
|
- List<PaperDetailUnit> paperDetailUnits = paperDetailUnitRepo.findByPaperDetailOrderByNumber(paperDetail);
|
|
|
- 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() != null
|
|
|
- && unit.getQuestion().getSubQuestions() != null
|
|
|
- && unit.getQuestion().getSubQuestions().size() > 0) {
|
|
|
- nestQusNum += unit.getQuestion().getSubQuestions().size() - 1;
|
|
|
- }
|
|
|
- }
|
|
|
- count = paperDetailUnits.size() + nestQusNum;
|
|
|
- score = CommonUtils.formatDouble(score);
|
|
|
- paperDetail.setScore(score);
|
|
|
- paperDetail.setUnitCount(count);
|
|
|
- allQuesCount += count;
|
|
|
- } else {
|
|
|
- paperDetail.setScore(0d);
|
|
|
- }
|
|
|
- }
|
|
|
- paperDetailRepo.save(paperDetails);
|
|
|
- paperInfoMap.put("allQuesCount", allQuesCount);
|
|
|
- paperInfoMap.put("paperDetails", paperDetails);
|
|
|
- return paperInfoMap;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 重新设置试卷大题数量、小题数量、试卷总分等属性
|
|
|
- * @param paper
|
|
|
- * @param user
|
|
|
- * @param paperInfoMap
|
|
|
- * @param paperTotalScore
|
|
|
- */
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- private void reSetPaper(Paper paper, AccessUser user,Map<String, Object> paperInfoMap,double paperTotalScore) {
|
|
|
- List<PaperDetail> paperDetails = (List<PaperDetail>) paperInfoMap.get("paperDetails");
|
|
|
- paper.setPaperDetailCount(paperDetails.size());//设置大题数量
|
|
|
- paper.setUnitCount(Integer.parseInt(paperInfoMap.get("allQuesCount")+""));//设置小题数量
|
|
|
- paper.setTotalScore(paperTotalScore);//设置试卷总分
|
|
|
- if (user != null) {
|
|
|
- paper.setLastModifyName(user.getName());
|
|
|
- }
|
|
|
- paperRepo.save(paper);
|
|
|
- redisTemplate.delete(paper.getId());
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 先备份准备删掉的试题,然后再删掉
|
|
|
- *
|
|
|
- * @param questionId
|
|
|
- * @return
|
|
|
- */
|
|
|
- public List<String> deleteImportQuestionById(String questionId, AccessUser user) {
|
|
|
- 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 (pdu.getPaper() != null) {
|
|
|
- if (!papers.contains(pdu.getPaper())) {
|
|
|
- papers.add(pdu.getPaper());
|
|
|
- }
|
|
|
- if (PaperType.GENERATE == pdu.getPaper().getPaperType()) {
|
|
|
- paperNames.add(pdu.getPaper().getName());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (paperNames.size() == 0) {
|
|
|
- needPdus.addAll(pdus);// 此试题没有被组卷调用,则可以删除此试题
|
|
|
- paperDetailUnitRepo.delete(needPdus);
|
|
|
- quesBakRepo.save(BeanCopierUtil.copyProperties(ques, QuestionBak.class));
|
|
|
- quesRepo.delete(ques);
|
|
|
- for (Paper paper : papers) {
|
|
|
- formatPaper(paper,user);
|
|
|
- }
|
|
|
- }
|
|
|
- return paperNames;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 向试卷中插入一个试题
|
|
|
- *
|
|
|
- * @param paperId
|
|
|
- * @param paperDetailId
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Paper insertQuestionToPaper(String paperId, String paperDetailId, Question question, AccessUser user) {
|
|
|
- Paper paper = paperRepo.findOne(paperId);
|
|
|
- question.setOrgId(user.getRootOrgId().toString());
|
|
|
- question.setCourse(paper.getCourse());
|
|
|
- question.setCourseNo(paper.getCourse().getCode());//必须设置,因为部分方法需要courseNo作为查询条件
|
|
|
- question = quesService.saveQues(question);
|
|
|
-
|
|
|
- PaperDetail paperDetail = paperDetailRepo.findOne(paperDetailId);
|
|
|
- PaperDetailUnit paperDetailUnit = new PaperDetailUnit(paper,paperDetail,question);
|
|
|
- PaperDetailUnit paperDetailUnit2 = paperDetailUnitService.findTopOrderByNumber(paperDetail,"DESC");
|
|
|
- paperDetailUnit.setNumber(paperDetailUnit2.getNumber());//设置number为大题的最大题号
|
|
|
- paperDetailUnitRepo.save(paperDetailUnit);
|
|
|
- formatPaper(paper,user);
|
|
|
- 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,AccessUser accessUser,String quesBody) {
|
|
|
- Set<String> selectedIds = new HashSet<>();
|
|
|
- Paper paper = paperRepo.findOne(paperId);
|
|
|
- List<PaperDetailUnit> pdus = paperDetailUnitRepo.findByPaperOrderByNumber(paper);
|
|
|
- for (PaperDetailUnit pdu : pdus) {
|
|
|
- selectedIds.add(pdu.getQuestion().getId());
|
|
|
- }
|
|
|
- return quesService.findByIdExclude(selectedIds, paper.getCourseNo(), quesType, curPage, pageSize,accessUser.getRootOrgId(),quesBody);
|
|
|
- }
|
|
|
-
|
|
|
- public Paper selectQuestionsToPaper(String paperId, String paperDetailId, List<Question> questions,
|
|
|
- AccessUser user) {
|
|
|
- Paper paper = paperRepo.findOne(paperId);
|
|
|
- PaperDetail paperDetail = paperDetailRepo.findOne(paperDetailId);
|
|
|
- PaperDetailUnit paperDetailUnit = paperDetailUnitRepo.findTopByPaperDetailOrderByNumberDesc(paperDetail);
|
|
|
- List<PaperDetailUnit> saveUnits = new ArrayList<PaperDetailUnit>();
|
|
|
- for (Question ques : questions) {
|
|
|
- PaperDetailUnit pdu = new PaperDetailUnit(paper,paperDetail,ques);
|
|
|
- //如果大题没有小题,取导入的试题分数
|
|
|
- if(paperDetailUnit == null){
|
|
|
- pdu.setNumber(1);
|
|
|
- }else {
|
|
|
- pdu.setNumber(paperDetailUnit.getNumber());//设置为大题中最大的number
|
|
|
- }
|
|
|
- pdu.setScore(ques.getScore() == null? 0d:ques.getScore());
|
|
|
- //处理套题
|
|
|
- if(pdu.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION){
|
|
|
- List<Question> subQuestions = ques.getSubQuestions();
|
|
|
- List<Double> subScoreList = new ArrayList<>();
|
|
|
- if(subQuestions != null && subQuestions.size() > 0){
|
|
|
- for(Question subQuestion:subQuestions){
|
|
|
- subScoreList.add(CommonUtils.formatDouble(pdu.getScore()/subQuestions.size()));
|
|
|
- }
|
|
|
- }
|
|
|
- pdu.setSubScoreListNew(subScoreList);
|
|
|
- }
|
|
|
- saveUnits.add(pdu);
|
|
|
- }
|
|
|
- paperDetailUnitRepo.save(saveUnits);
|
|
|
- formatPaper(paper, user);
|
|
|
- return paper;
|
|
|
- }
|
|
|
-
|
|
|
- public String checkPaperName(String paperName, String orgId) {
|
|
|
- String msg = null;
|
|
|
- List<Paper> paperList= paperRepo.findByNameAndOrgId(paperName,orgId);
|
|
|
- if (paperList != null && paperList.size() > 0) {
|
|
|
- msg = "试卷名称重复,请重新命名";
|
|
|
- }
|
|
|
- return msg;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public void checkPaperNameNew(String paperName, String orgId)throws Exception{
|
|
|
- List<Paper> paperList= paperRepo.findByNameAndOrgId(paperName,orgId);
|
|
|
- if (paperList != null && paperList.size() > 0) {
|
|
|
- throw new PaperException("试卷名称重复,请重新命名");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private String relaceQuestionIdx(String str, int baseIdx) {
|
|
|
- StringBuffer sb = new StringBuffer("");
|
|
|
- Pattern pattern = Pattern.compile("##(\\d+)##");
|
|
|
-
|
|
|
- Matcher matcher = pattern.matcher(str);
|
|
|
-
|
|
|
- while (matcher.find()) {
|
|
|
- String idx = matcher.group(1);
|
|
|
- matcher.appendReplacement(sb, "___" + String.valueOf(Integer.parseInt(idx) + baseIdx) + "___");
|
|
|
- }
|
|
|
-
|
|
|
- if (StringUtils.isEmpty(sb.toString())) {
|
|
|
- return str;
|
|
|
- } else {
|
|
|
- matcher.appendTail(sb);
|
|
|
- return sb.toString();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public Page<Paper> getImportPapersNotInIds(PaperSearchInfo paperSearchInfo, String[] ids, int curPage,int pageSize) {
|
|
|
- Set<String> selectedIds = new HashSet<>();
|
|
|
- for (String id : ids) {
|
|
|
- selectedIds.add(id);
|
|
|
- }
|
|
|
- Query query = new Query();
|
|
|
- query.addCriteria(Criteria.where("orgId").is(paperSearchInfo.getOrgId()));
|
|
|
- query.addCriteria(Criteria.where("paperType").is(PaperType.IMPORT));
|
|
|
- query.addCriteria(Criteria.where("course.code").is(paperSearchInfo.getCourseNo()));
|
|
|
- query.addCriteria(Criteria.where("id").nin(selectedIds));
|
|
|
- long total = this.mongoTemplate.count(query, Paper.class);
|
|
|
- query.with(new Sort(new Order(Direction.DESC,"createTime")));
|
|
|
- query.limit(pageSize);
|
|
|
- query.skip((curPage - 1) * pageSize);
|
|
|
- List<Paper> paperList = this.mongoTemplate.find(query,Paper.class);
|
|
|
- Page<Paper> paperPageList = new PageImpl<Paper>(paperList,new PageRequest(curPage - 1, pageSize), total);
|
|
|
- return paperPageList;
|
|
|
- }
|
|
|
- /**
|
|
|
- * 将选中的导入试卷复制为卷库试卷
|
|
|
- */
|
|
|
- public void useBasePaper(String selectedPaperIds,String userId){
|
|
|
- Assert.hasLength(selectedPaperIds, "试卷id不能为空!");
|
|
|
- String[] paperIds = selectedPaperIds.split(",");
|
|
|
- for(int i = 0;i<paperIds.length;i++){
|
|
|
- Paper oldpaper = paperRepo.findOne(paperIds[i]);
|
|
|
- List<PaperDetail> paperDetails = paperDetailRepo.findByPaperOrderByNumber(oldpaper);
|
|
|
- oldpaper.setId(null);
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- String createTime = sdf.format(new Date());
|
|
|
- oldpaper.setCreateTime(createTime);
|
|
|
- oldpaper.setCreator(userId);
|
|
|
- oldpaper.setLastModifyName(userId);
|
|
|
- oldpaper.setPaperType(PaperType.GENERATE);//试卷类型 修改为组卷
|
|
|
- Paper newPaper = paperRepo.save(oldpaper);
|
|
|
- for(int j = 0;j<paperDetails.size();j++){
|
|
|
- PaperDetail paperDetail = paperDetails.get(j);
|
|
|
- List<PaperDetailUnit> paperDetailUnits = paperDetailUnitService.getUnitsByPaperDetail(paperDetail);
|
|
|
- paperDetail.setPaper(newPaper);//关联新Paper
|
|
|
- paperDetail.setId(null);
|
|
|
- paperDetail.setCreateTime(createTime);
|
|
|
- paperDetail.setCreator(userId);
|
|
|
- PaperDetail newPaperDetail = paperDetailRepo.save(paperDetail);//保存新的paperDetail
|
|
|
- for(int k = 0;k<paperDetailUnits.size();k++){
|
|
|
- //重新设置保存PaperDetailUnit
|
|
|
- PaperDetailUnit paperDetailUnit = paperDetailUnits.get(k);
|
|
|
- paperDetailUnit.setPaper(newPaper); //关联新Paper
|
|
|
- paperDetailUnit.setPaperDetail(newPaperDetail); //关联新paperDetail
|
|
|
- paperDetailUnit.setId(null);
|
|
|
- paperDetailUnit.setCreateTime(createTime);
|
|
|
- paperDetailUnit.setCreator(userId);
|
|
|
- paperDetailUnitRepo.save(paperDetailUnit);//保存新的paperDetailUnit
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- /**
|
|
|
- * 根据试卷名称、试卷类型检查名称是否存在
|
|
|
- * @param paperName
|
|
|
- * @param paperType
|
|
|
- * @param orgId
|
|
|
- * @return
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- public boolean checkPaperName(String paperName, PaperType paperType,String orgId)throws Exception{
|
|
|
- Paper paperTemp = new Paper();
|
|
|
- paperTemp.setCreateTime(null);
|
|
|
- paperTemp.setName(paperName.trim());
|
|
|
- paperTemp.setOrgId(orgId);
|
|
|
- paperTemp.setPaperType(paperType);
|
|
|
- Paper paper = paperRepo.findOne(Example.of(paperTemp));
|
|
|
- if(paper!=null){
|
|
|
- return false;
|
|
|
- }
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 上传音频文件检查
|
|
|
- * @param paperId
|
|
|
- * @param filesName
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Map<String, String> checkRadioFile(String paperId,List<String> filesName){
|
|
|
- Map<String, String> messageMap = new HashMap<String, String>();
|
|
|
- //判断文件名中格式是否正确
|
|
|
- for(String fileName: filesName){
|
|
|
- String[] fileNames = fileName.split("\\.");
|
|
|
- String fileType = fileNames[fileNames.length-1];
|
|
|
- if(radioType.indexOf(fileType)<0){
|
|
|
- messageMap.put("errorMsg", fileName+",文件格式不正确,当前支持格式:"+radioType);
|
|
|
- return messageMap;
|
|
|
- }
|
|
|
- String pattern_01 = "\\d+_1_\\d{1,2}"; //题干正则
|
|
|
- String pattern_02 = "\\d+_2_[A-Z|a-z]_\\d{1,2}"; //选项正则
|
|
|
- if(!(Pattern.matches(pattern_01,fileNames[0])||
|
|
|
- Pattern.matches(pattern_02,fileNames[0]))){
|
|
|
- messageMap.put("errorMsg", fileName+"文件名格式不正确,请检查");
|
|
|
- return messageMap;
|
|
|
- }
|
|
|
- }
|
|
|
- //根据试卷id,查询该试卷
|
|
|
- Paper paper = paperRepo.findOne(paperId);
|
|
|
- //根据试卷查询所有的小题
|
|
|
- List<PaperDetailUnit> paperDetailUnits = paperDetailUnitRepo.findByPaperOrderByNumber(paper);
|
|
|
- String names = "";
|
|
|
- for(PaperDetailUnit paperDetailUnit:paperDetailUnits){
|
|
|
- names = names + paperDetailUnit.getNumber().toString() + ",";
|
|
|
- }
|
|
|
- for(String fileName: filesName){
|
|
|
- String fileNames[] = fileName.split("_");
|
|
|
- //先判断小题号是否正确
|
|
|
- String fileNameFirst = fileNames[0];
|
|
|
- if(!names.contains(fileNameFirst)){
|
|
|
- messageMap.put("errorMsg", fileName + "文件,试卷中没有对应的小题");
|
|
|
- return messageMap;
|
|
|
- }
|
|
|
- //再判断题干中是否存在ABCD
|
|
|
- String fileNameSecond = fileNames[1];
|
|
|
- if(fileNameSecond.equals("1")){
|
|
|
- if(fileNames.length>3){
|
|
|
- Matcher m = Pattern.compile(".*[a-zA-Z]+.*").matcher(fileNames[2]);
|
|
|
- if(m.matches()){
|
|
|
- messageMap.put("errorMsg", fileName + "文件名称不对,文件名为题干,但存在选项");
|
|
|
- return messageMap;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- //判断选项
|
|
|
- else if(fileNameSecond.equals("2")){
|
|
|
- messageMap = checkOptions(paperDetailUnits, fileNames, fileName);
|
|
|
- if(messageMap != null){
|
|
|
- return messageMap;
|
|
|
- }
|
|
|
- messageMap = new HashMap<String, String>();
|
|
|
- }else {
|
|
|
- messageMap.put("errorMsg", fileName + "文件名称不对,无法识别为题干或选项 ");
|
|
|
- return messageMap;
|
|
|
- }
|
|
|
- }
|
|
|
- messageMap.put("errorMsg", "OK");
|
|
|
- return messageMap;
|
|
|
- }
|
|
|
-
|
|
|
- //判断选项
|
|
|
- public Map<String, String> checkOptions(List<PaperDetailUnit> paperDetailUnits,String fileNames[],String fileName){
|
|
|
- Map<String, String> messageMap = new HashMap<String, String>();
|
|
|
- for(PaperDetailUnit paperDetailUnit:paperDetailUnits){
|
|
|
- if(paperDetailUnit.getNumber().toString().equals(fileNames[0])){
|
|
|
- //判断是否为选择题
|
|
|
- if(paperDetailUnit.getQuestionType() != QuesStructType.SINGLE_ANSWER_QUESTION
|
|
|
- &&paperDetailUnit.getQuestionType() != QuesStructType.MULTIPLE_ANSWER_QUESTION){
|
|
|
- Matcher m = Pattern.compile(".*[a-zA-Z]+.*").matcher(fileNames[2]);
|
|
|
- if(m.matches()){
|
|
|
- messageMap.put("errorMsg", fileName + "文件名称有误,题目不是选择题");
|
|
|
- return messageMap;
|
|
|
- }
|
|
|
- break;
|
|
|
- }else {
|
|
|
- List<QuesOption> options = paperDetailUnit.getQuestion().getQuesOptions();
|
|
|
- String option = "";
|
|
|
- for(QuesOption quesOption:options){
|
|
|
- option = option + quesOption.getNumber()+",";
|
|
|
- }
|
|
|
- Integer integer = CommonUtils.characterToNumber(fileNames[2]);
|
|
|
- if(!option.contains(integer.toString())){
|
|
|
- messageMap.put("errorMsg", fileName + "文件名称有误,题目中没有对应的"+fileNames[2]+"选项");
|
|
|
- return messageMap;
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 上传音频文件到又拍云
|
|
|
- * @param files
|
|
|
- * @param paperId
|
|
|
- * @param accessUser
|
|
|
- * @throws IOException
|
|
|
- */
|
|
|
- public void uploadRadio(List<MultipartFile> files,String paperId,AccessUser accessUser) throws IOException{
|
|
|
- //根据试卷id,查询该试卷
|
|
|
- Paper paper = paperRepo.findOne(paperId);
|
|
|
- for(MultipartFile file: files){
|
|
|
- //判断文件大小
|
|
|
- long fileSize = file.getSize();
|
|
|
- int size = Integer.parseInt(audioMaxsize);
|
|
|
- if(fileSize>size * 1048576){
|
|
|
- throw new RuntimeException("音频文件大小超过5M,不能上传");
|
|
|
- }
|
|
|
- //根据试卷查询所有的小题,根据文件名匹配出当前小题ID
|
|
|
- Question question = null;
|
|
|
- String numbers[] = file.getOriginalFilename().split("_");
|
|
|
- List<PaperDetailUnit> paperDetailUnits = paperDetailUnitRepo.findByPaperOrderByNumber(paper);
|
|
|
- for(PaperDetailUnit paperDetailUnit:paperDetailUnits){
|
|
|
- if(paperDetailUnit.getNumber().toString().equals(numbers[0])){
|
|
|
- question = paperDetailUnit.getQuestion();
|
|
|
- }
|
|
|
- }
|
|
|
- uploadAudioFile(paperId,question.getId(),file,accessUser);
|
|
|
- appendAudioTag(file.getOriginalFilename(),question.getId());
|
|
|
- }
|
|
|
- //删除服务器文件夹
|
|
|
- String mp3DirectoryPath = TEMP_FILE_EXP + File.separator + paperId;
|
|
|
- File mp3Directory = new File(mp3DirectoryPath);
|
|
|
- FileUtils.deleteDirectory(mp3Directory);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 上传音频文件至又拍云
|
|
|
- * @param paperId
|
|
|
- * @param questionId
|
|
|
- * @param file
|
|
|
- */
|
|
|
- private void uploadAudioFile(String paperId,String questionId,MultipartFile file,AccessUser accessUser){
|
|
|
- try {
|
|
|
- String mp3DirectoryPath = TEMP_FILE_EXP + File.separator + paperId;
|
|
|
- //新建文件夹
|
|
|
- File mp3Directory = new File(mp3DirectoryPath);
|
|
|
- if(!mp3Directory.exists()){
|
|
|
- mp3Directory.mkdirs();
|
|
|
- }
|
|
|
- byte[] bufs = new byte[1024 * 4];
|
|
|
- //使用随机数,防止缓存
|
|
|
- Random random = new Random();
|
|
|
- int randomNumber = random.nextInt(1000);
|
|
|
- String mp3FileNameString = questionId+"_"+randomNumber+"_"+ file.getOriginalFilename();
|
|
|
- File mp3File = new File(mp3DirectoryPath + File.separator +mp3FileNameString);
|
|
|
- FileOutputStream outputStream = new FileOutputStream(mp3File);
|
|
|
- BufferedInputStream bis = new BufferedInputStream(file.getInputStream(),1024*10);
|
|
|
- int read = 0;
|
|
|
- while ((read = bis.read(bufs,0,1024*4)) != -1) {
|
|
|
- outputStream.write(bufs,0,read);
|
|
|
- }
|
|
|
- bis.close();
|
|
|
- outputStream.flush();
|
|
|
- outputStream.close();
|
|
|
- //上传到又拍云
|
|
|
- UpYun upYun = new UpYun(bucketName, userName, password);
|
|
|
- upYun.writeFile(upyunRadioPath+mp3FileNameString, mp3File,true);
|
|
|
- mp3File.delete();
|
|
|
- //保存记录
|
|
|
- questionAudioService.saveQuestionAudio(new QuestionAudio(questionId,file.getOriginalFilename(),upyunRadioPath+mp3FileNameString),accessUser);
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 音频文件插入到标签
|
|
|
- * @param fileName
|
|
|
- * @param questionId
|
|
|
- */
|
|
|
- public void appendAudioTag(String fileName,String questionId){
|
|
|
- QuestionAudio questionAudio = questionAudioService.findByQuestionIdAndFileName(questionId,fileName);
|
|
|
- if(questionAudio != null){
|
|
|
- String numbers[] = fileName.split("_");
|
|
|
- Question question = quesRepo.findOne(questionAudio.getQuestionId());
|
|
|
- if(numbers[1].equals("1")){
|
|
|
- String quesBody = question.getQuesBody();
|
|
|
- if(!quesBody.contains(fileName)){
|
|
|
- String quesBodyNew = quesBody.substring(0, quesBody.lastIndexOf("</p>"))
|
|
|
- + "<a id=\"" + questionAudio.getId() + "\" name=\"" + fileName + "\"></a></p>";
|
|
|
- question.setQuesBody(quesBodyNew);
|
|
|
- }
|
|
|
- }else {
|
|
|
- List<QuesOption> quesOptions = question.getQuesOptions();
|
|
|
- List<QuesOption> quesOptionsNew = new ArrayList<QuesOption>();
|
|
|
- for(QuesOption quesOption:quesOptions){
|
|
|
- if(quesOption.getNumber().equals(CommonUtils.characterToNumber(numbers[2]).toString())){
|
|
|
- String optionBody = quesOption.getOptionBody();
|
|
|
- if(!optionBody.contains(fileName)){
|
|
|
- String optionBodyNew = "";
|
|
|
- if(StringUtils.isBlank(optionBody)){
|
|
|
- optionBodyNew = "<p><a id=\""+questionAudio.getId()+"\" name=\""+fileName+"\"></a></p>";
|
|
|
- }else{
|
|
|
- optionBodyNew = optionBody.substring(0, optionBody.lastIndexOf("</p>"))
|
|
|
- + "<a id=\""+questionAudio.getId()+"\" name=\""+fileName+"\"></a></p>";
|
|
|
- }
|
|
|
- quesOption.setOptionBody(optionBodyNew);
|
|
|
- }
|
|
|
- }
|
|
|
- quesOptionsNew.add(quesOption);
|
|
|
- }
|
|
|
- quesOptions = null;
|
|
|
- question.setQuesOptions(quesOptionsNew);
|
|
|
- }
|
|
|
- question.setHasAudio(true);
|
|
|
- quesRepo.save(question);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
+package com.qmth.cqb.paper.service.impl;
|
|
|
+
|
|
|
+import java.io.BufferedInputStream;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.text.DecimalFormat;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Random;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+
|
|
|
+import main.java.com.UpYun;
|
|
|
+
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.nlpcn.commons.lang.util.StringUtil;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.data.domain.Example;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageImpl;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
+import org.springframework.data.domain.Sort.Direction;
|
|
|
+import org.springframework.data.domain.Sort.Order;
|
|
|
+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.data.redis.core.RedisTemplate;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.Assert;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
|
|
|
+import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
|
|
|
+
|
|
|
+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.paper.service.ExtractConfigService;
|
|
|
+import com.qmth.cqb.paper.service.PaperDetailService;
|
|
|
+import com.qmth.cqb.paper.service.PaperDetailUnitService;
|
|
|
+import com.qmth.cqb.paper.service.PaperService;
|
|
|
+import com.qmth.cqb.question.dao.QuesBakRepo;
|
|
|
+import com.qmth.cqb.question.dao.QuesRepo;
|
|
|
+import com.qmth.cqb.question.dao.QuestionAudioRepo;
|
|
|
+import com.qmth.cqb.question.model.QuesOption;
|
|
|
+import com.qmth.cqb.question.model.Question;
|
|
|
+import com.qmth.cqb.question.model.QuestionAudio;
|
|
|
+import com.qmth.cqb.question.model.QuestionBak;
|
|
|
+import com.qmth.cqb.question.service.QuesService;
|
|
|
+import com.qmth.cqb.question.service.impl.QuestionAudioServiceImpl;
|
|
|
+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 com.qmth.cqb.utils.exception.PaperException;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author chenken
|
|
|
+ * @date 2017年9月12日 上午11:20:44
|
|
|
+ * @company QMTH
|
|
|
+ * @description PaperServiceImpl.java
|
|
|
+ */
|
|
|
+@Service("paperService")
|
|
|
+public class PaperServiceImpl implements 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;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ExtractConfigService extractConfigService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MongoTemplate mongoTemplate;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private QuestionAudioServiceImpl questionAudioService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private QuestionAudioRepo questionAudioRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RedisTemplate redisTemplate;
|
|
|
+
|
|
|
+ @Value("${upyun.radioType}")
|
|
|
+ private String radioType;
|
|
|
+
|
|
|
+ @Value("${upyun.audio.maxsize}")
|
|
|
+ private String audioMaxsize;
|
|
|
+
|
|
|
+ @Value("${upyun.audio.uploadUrl}")
|
|
|
+ private String upyunRadioPath;
|
|
|
+
|
|
|
+ @Value("${upyun.bucketName}")
|
|
|
+ private String bucketName;
|
|
|
+
|
|
|
+ @Value("${upyun.userName}")
|
|
|
+ private String userName;
|
|
|
+
|
|
|
+ @Value("${upyun.password}")
|
|
|
+ private String password;
|
|
|
+
|
|
|
+ public static final String TEMP_FILE_EXP = "docxExport/";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询所有已导入试卷
|
|
|
+ *
|
|
|
+ * @param paperSearchInfo
|
|
|
+ * @param curPage
|
|
|
+ * @param pageSize
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Page<Paper> getImportPapers(PaperSearchInfo paperSearchInfo, int curPage, int pageSize) {
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("orgId").is(paperSearchInfo.getOrgId()));
|
|
|
+ query.addCriteria(Criteria.where("paperType").is(PaperType.IMPORT));
|
|
|
+ query.addCriteria(Criteria.where("course.enable").is("true"));
|
|
|
+ if(StringUtils.isNotBlank(paperSearchInfo.getCourseNo())){
|
|
|
+ query.addCriteria(Criteria.where("course.code").is(paperSearchInfo.getCourseNo()));
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(paperSearchInfo.getSpecialtyNo())){
|
|
|
+ query.addCriteria(Criteria.where("specialty.code").is(paperSearchInfo.getSpecialtyNo()));
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(paperSearchInfo.getLevel())){
|
|
|
+ query.addCriteria(Criteria.where("course.level").is(paperSearchInfo.getLevel()));
|
|
|
+ }
|
|
|
+ long count = this.mongoTemplate.count(query, Paper.class);
|
|
|
+ query.with(new Sort(new Order(Direction.DESC,"createTime")));
|
|
|
+ query.limit(pageSize);
|
|
|
+ query.skip((curPage - 1) * pageSize);
|
|
|
+ List<Paper> paperList = this.mongoTemplate.find(query, Paper.class);
|
|
|
+ return new PageImpl<Paper>(paperList, new PageRequest(curPage - 1, pageSize), count);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询所有待审核和审核不通过的导入试卷
|
|
|
+ *
|
|
|
+ * @param paperSearchInfo
|
|
|
+ * @param curPage
|
|
|
+ * @param pageSize
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Page<Paper> getImportPapersNotSuccess(PaperSearchInfo paperSearchInfo, int curPage, int pageSize) {
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("orgId").is(paperSearchInfo.getOrgId()));
|
|
|
+ query.addCriteria(Criteria.where("paperType").is(PaperType.IMPORT));
|
|
|
+ query.addCriteria(Criteria.where("course.enable").is("true"));
|
|
|
+ if (paperSearchInfo.getPaperStatus() != null) {
|
|
|
+ query.addCriteria(Criteria.where("paperStatus").is(paperSearchInfo.getPaperStatus()));
|
|
|
+ } else {
|
|
|
+ query.addCriteria(Criteria.where("paperStatus").ne(PaperStatus.PASS));
|
|
|
+ }
|
|
|
+ if (StringUtil.isNotBlank(paperSearchInfo.getCourseNo())) {
|
|
|
+ query.addCriteria(Criteria.where("course.code").is(paperSearchInfo.getCourseNo()));
|
|
|
+ }
|
|
|
+ long totalNumber = this.mongoTemplate.count(query, Paper.class);
|
|
|
+ query.limit(pageSize);
|
|
|
+ query.skip((curPage - 1) * pageSize);
|
|
|
+ List<Paper> paperList = this.mongoTemplate.find(query, Paper.class);
|
|
|
+ return new PageImpl<Paper>(paperList, new PageRequest(curPage - 1, pageSize), totalNumber);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据条件查询
|
|
|
+ *
|
|
|
+ * @param paperSearchInfo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<Paper> getImportPapersBySearch(PaperSearchInfo paperSearchInfo) {
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("orgId").is(paperSearchInfo.getOrgId()));
|
|
|
+ query.addCriteria(Criteria.where("paperType").is(PaperType.IMPORT.name()));
|
|
|
+ query.addCriteria(Criteria.where("course.enable").is("true"));
|
|
|
+ if(StringUtils.isNotBlank(paperSearchInfo.getCourseNo())){
|
|
|
+ query.addCriteria(Criteria.where("course.code").is(paperSearchInfo.getCourseNo()));
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(paperSearchInfo.getLevel())){
|
|
|
+ query.addCriteria(Criteria.where("course.level").is(paperSearchInfo.getLevel()));
|
|
|
+ }
|
|
|
+ List<Paper> paperList = this.mongoTemplate.find(query, Paper.class);
|
|
|
+ return paperList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据条件查询
|
|
|
+ *
|
|
|
+ * @param paperSearchInfo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<Paper> getGenPapersBySearch(PaperSearchInfo paperSearchInfo) {
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("orgId").is(paperSearchInfo.getOrgId()));
|
|
|
+ query.addCriteria(Criteria.where("paperType").is(PaperType.GENERATE.name()));
|
|
|
+ query.addCriteria(Criteria.where("course.enable").is("true"));
|
|
|
+ if(StringUtils.isNotBlank(paperSearchInfo.getCourseNo())){
|
|
|
+ query.addCriteria(Criteria.where("course.code").is(paperSearchInfo.getCourseNo()));
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(paperSearchInfo.getLevel())){
|
|
|
+ query.addCriteria(Criteria.where("course.level").is(paperSearchInfo.getLevel()));
|
|
|
+ }
|
|
|
+ List<Paper> paperList = this.mongoTemplate.find(query, Paper.class);
|
|
|
+ return paperList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存试卷
|
|
|
+ *
|
|
|
+ * @param paperExp
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map<String, Object> savePaper(PaperExp paperExp, AccessUser user) {
|
|
|
+ Map<String, Object> msgMap = new HashMap<String, Object>();
|
|
|
+ Paper oldPaper = paperRepo.findOne(paperExp.getId());
|
|
|
+ if (oldPaper != null) {
|
|
|
+ String oldName = oldPaper.getName().trim();
|
|
|
+ oldPaper.setTitle(paperExp.getTitle());
|
|
|
+ oldPaper.setName(paperExp.getName().trim());
|
|
|
+ oldPaper.setLastModifyName(user.getName());
|
|
|
+ oldPaper.setExamRemark(paperExp.getExamRemark());
|
|
|
+ if (!oldName.equals(paperExp.getName().trim())) {// 假如改变了试卷名称
|
|
|
+ // 则要效验试卷名称唯一性
|
|
|
+ String msg = this.checkPaperName(paperExp.getName().trim(), user.getRootOrgId().toString());
|
|
|
+ if (msg == null) {
|
|
|
+ formatPaper(oldPaper, user);
|
|
|
+ paperRepo.save(oldPaper);
|
|
|
+ msgMap.put("msg", "success");
|
|
|
+ } else {
|
|
|
+ msgMap.put("msg", msg);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ formatPaper(oldPaper, user);
|
|
|
+ paperRepo.save(oldPaper);
|
|
|
+ msgMap.put("msg", "success");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //删除缓存
|
|
|
+ redisTemplate.delete(paperExp.getId());
|
|
|
+ return msgMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询所有已组试卷
|
|
|
+ *
|
|
|
+ * @param paperSearchInfo
|
|
|
+ * @param curPage
|
|
|
+ * @param pageSize
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Page<Paper> getGenPapers(PaperSearchInfo paperSearchInfo, int curPage, int pageSize) {
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("orgId").is(paperSearchInfo.getOrgId()));
|
|
|
+ query.addCriteria(Criteria.where("paperType").is(PaperType.GENERATE.name()));
|
|
|
+ query.addCriteria(Criteria.where("course.enable").is("true"));
|
|
|
+ if(StringUtils.isNotBlank(paperSearchInfo.getCourseNo())){
|
|
|
+ query.addCriteria(Criteria.where("course.code").is(paperSearchInfo.getCourseNo()));
|
|
|
+ }
|
|
|
+ if(StringUtils.isNoneBlank(paperSearchInfo.getName())){
|
|
|
+ query.addCriteria(Criteria.where("name").regex(".*?\\.*" +paperSearchInfo.getName() + ".*"));
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(paperSearchInfo.getLevel())){
|
|
|
+ query.addCriteria(Criteria.where("course.level").is(paperSearchInfo.getLevel()));
|
|
|
+ }
|
|
|
+ long count = this.mongoTemplate.count(query, Paper.class);
|
|
|
+ query.with(new Sort(new Order(Direction.DESC,"createTime")));
|
|
|
+ query.limit(pageSize);
|
|
|
+ query.skip((curPage - 1) * pageSize);
|
|
|
+ List<Paper> paperList = this.mongoTemplate.find(query, Paper.class);
|
|
|
+ return new PageImpl<Paper>(paperList, new PageRequest(curPage - 1, pageSize), count);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询考试试卷
|
|
|
+ *
|
|
|
+ * @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 Map<String, Object> deletePapers(List<String> paperIds) {
|
|
|
+ Map<String, Object> msgMap = new HashMap<String, Object>();
|
|
|
+ String msg = "";
|
|
|
+ List<Paper> papers = CommonUtils.toList(paperRepo.findAll(paperIds));
|
|
|
+ if (papers.get(0).getPaperType() == PaperType.IMPORT) {
|
|
|
+ List<Question> quesList = new ArrayList<Question>();
|
|
|
+ for (Paper paper : papers) {
|
|
|
+ List<PaperDetailUnit> paperUnits = paperDetailUnitRepo.findByPaperOrderByNumber(paper);
|
|
|
+ for (PaperDetailUnit pdu : paperUnits) {
|
|
|
+ if (pdu.getQuestion() != null) {
|
|
|
+ quesList.add(pdu.getQuestion());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<PaperDetailUnit> allUnits = paperDetailUnitRepo.findByQuestionIn(quesList);
|
|
|
+ for (PaperDetailUnit pdu : allUnits) {
|
|
|
+ if (pdu.getPaper() != null && pdu.getPaper().getPaperType() == PaperType.GENERATE) {
|
|
|
+ msg = "待删除试卷中有试题被组卷使用,不能删除!";
|
|
|
+ msgMap.put("msg", msg);
|
|
|
+ msgMap.put("paperName", pdu.getPaper().getName());
|
|
|
+ return msgMap;
|
|
|
+ // for(PaperDetailUnit ipdu: importPaperUnits){
|
|
|
+ // if(ipdu.getQuestion().getId().equals(pdu.getQuestion().getId())){
|
|
|
+ //
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ quesRepo.delete(quesList);
|
|
|
+ } else if (papers.get(0).getPaperType() == PaperType.GENERATE) {
|
|
|
+ for (Paper paper : papers) {
|
|
|
+ List<String> examPaperIds = extractConfigService.getExamPaperId(paper.getCourseNo(), paper.getOrgId());
|
|
|
+ if (examPaperIds != null && examPaperIds.contains(paper.getId())) {
|
|
|
+ msg = "待删除试卷有被调卷规则使 用,不能删除!";
|
|
|
+ msgMap.put("msg", msg);
|
|
|
+ msgMap.put("paperName", paper.getName());
|
|
|
+ return msgMap;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ paperDetailService.deletePaperDetailsByPapers(papers);
|
|
|
+ paperRepo.delete(papers);
|
|
|
+ //删除缓存
|
|
|
+ redisTemplate.delete(paperIds);
|
|
|
+ msg = "success";
|
|
|
+ msgMap.put("msg", msg);
|
|
|
+ return msgMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量通过试卷
|
|
|
+ *
|
|
|
+ * @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 = paperRepo.findOne(id);
|
|
|
+ // 创建paperDto
|
|
|
+ PaperExp paperExp = BeanCopierUtil.copyProperties(paper,PaperExp.class);
|
|
|
+ paperExp.setCourse(paper.getCourse());
|
|
|
+ // 获取大题
|
|
|
+ List<PaperDetail> paperDetails = paperDetailRepo.findByPaperOrderByNumber(paper);
|
|
|
+ List<PaperDetailExp> paperDetailExps = BeanCopierUtil.copyPropertiesOfList(paperDetails, PaperDetailExp.class);
|
|
|
+ // 封装小题
|
|
|
+ for (int i = 0; i < paperDetailExps.size(); i++) {
|
|
|
+ List<PaperDetailUnit> paperDetailUnits = paperDetailUnitRepo.findByPaperDetailOrderByNumber(paperDetails.get(i));
|
|
|
+ if (paperDetailUnits != null && paperDetailUnits.size() > 0) {
|
|
|
+ List<PaperDetailUnitExp> paperDetailUnitExps = BeanCopierUtil.copyPropertiesOfList(paperDetailUnits,PaperDetailUnitExp.class);
|
|
|
+ // 选择题,套题下选择题 选项顺序重新排列
|
|
|
+ reorderChoicequestionOption(paperDetailUnitExps);
|
|
|
+ paperDetailExps.get(i).setPaperDetailUnits(paperDetailUnitExps);
|
|
|
+ } else {
|
|
|
+ paperDetailExps.get(i).setUnitCount(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ paperExp.setPaperDetails(paperDetailExps);
|
|
|
+ // 初始化试卷内容
|
|
|
+ initPaper(paperExp);
|
|
|
+ return paperExp;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 重新对选择题option进行排序(多选、单选、套题下选择题)
|
|
|
+ */
|
|
|
+ public void reorderChoicequestionOption(List<PaperDetailUnitExp> paperDetailUnitExps) {
|
|
|
+ for (PaperDetailUnitExp paperDetailUnitExp : paperDetailUnitExps) {
|
|
|
+ String optionOrder = paperDetailUnitExp.getOptionOrder();
|
|
|
+ if (StringUtil.isNotBlank(optionOrder)) {
|
|
|
+ Question question = paperDetailUnitExp.getQuestion();
|
|
|
+ if (question.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION
|
|
|
+ || question.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION) {
|
|
|
+ question.setQuesOptions(reorderOptionCore(question.getQuesOptions(), optionOrder));
|
|
|
+ }
|
|
|
+ if (question.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {
|
|
|
+ List<Question> subQuestions = question.getSubQuestions();
|
|
|
+ int index = 0;
|
|
|
+ for (int k = 0; k < subQuestions.size(); k++) {
|
|
|
+ Question subQuestion = subQuestions.get(k);
|
|
|
+ if (subQuestion.getQuestionType() == QuesStructType.SINGLE_ANSWER_QUESTION
|
|
|
+ || subQuestion.getQuestionType() == QuesStructType.MULTIPLE_ANSWER_QUESTION) {
|
|
|
+ subQuestion.setQuesOptions(
|
|
|
+ reorderOptionCore(subQuestion.getQuesOptions(), optionOrder.split(";")[index]));
|
|
|
+ index++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<QuesOption> reorderOptionCore(List<QuesOption> quesOptions, String optionOrder) {
|
|
|
+ List<QuesOption> newQuesOptions = new ArrayList<QuesOption>();
|
|
|
+ if (StringUtil.isBlank(optionOrder) || quesOptions.isEmpty()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ String[] optionOrderArr = optionOrder.split(",");
|
|
|
+ for (int j = 0; j < optionOrderArr.length; j++) {
|
|
|
+ for (int k = 0; k < quesOptions.size(); k++) {
|
|
|
+ if (optionOrderArr[j].equals(quesOptions.get(k).getNumber())) {
|
|
|
+ newQuesOptions.add(quesOptions.get(k));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ quesOptions = null;
|
|
|
+ return newQuesOptions;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化试卷内容(增加序号)
|
|
|
+ *
|
|
|
+ * @param paperExp
|
|
|
+ */
|
|
|
+ public void initPaper(PaperExp paperExp) {
|
|
|
+ DecimalFormat df = new DecimalFormat("#.00");
|
|
|
+ if (paperExp.getPaperDetails() == null || paperExp.getPaperDetails().size() == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ int mainNum = 0;
|
|
|
+ List<PaperDetailExp> paperDetailExpList = paperExp.getPaperDetails();
|
|
|
+ for (PaperDetailExp paperDetail : paperDetailExpList) {
|
|
|
+ // 大题序号
|
|
|
+ paperDetail.setNumber(++mainNum);
|
|
|
+ paperDetail.setCnNum(CommonUtils.toCHNum(paperDetail.getNumber()));
|
|
|
+ if (paperDetail != null && paperDetail.getPaperDetailUnits() != null&& paperDetail.getPaperDetailUnits().size() > 0) {
|
|
|
+ for (PaperDetailUnitExp paperDetailUnit : paperDetail.getPaperDetailUnits()) {
|
|
|
+ Question question = paperDetailUnit.getQuestion();
|
|
|
+ if (question != null) {
|
|
|
+ if(question.getHasAudio()!=null&&question.getHasAudio()){
|
|
|
+ paperExp.setHasAudio(true); //设置试卷含有音频
|
|
|
+ }
|
|
|
+ quesService.formatQuesUnit(question);
|
|
|
+ List<Question> subQuesList = question.getSubQuestions();
|
|
|
+ // 套题序号
|
|
|
+ if (subQuesList != null && subQuesList.size() > 0) {
|
|
|
+ int index = 0;
|
|
|
+ for (Question subQues : subQuesList) {
|
|
|
+ Map<String, String> params = new HashMap<String, String>();
|
|
|
+ params.put("number", String.valueOf(++index));
|
|
|
+ subQues.setQuesParams(params);
|
|
|
+ quesService.formatQuesUnit(subQues);
|
|
|
+ }
|
|
|
+ String quesBodyHtml = relaceQuestionIdx(question.getQuesBody(),0);
|
|
|
+ question.setQuesBody(quesBodyHtml);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 格式化查询条件
|
|
|
+ *
|
|
|
+ * @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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *1.重新设置小题number,并返回试卷总分
|
|
|
+ *2.重新计算大题的总分和小题总数
|
|
|
+ *3.重新保存试卷大题数量、小题数量、试卷总分等信息
|
|
|
+ * @param paper
|
|
|
+ */
|
|
|
+ public void formatPaper(Paper paper, AccessUser user) {
|
|
|
+ double paperTotalScore = reSetPaperDetailUnit(paper);
|
|
|
+ paper.setDifficultyDegree(reSetDifficulty(paper,paperTotalScore));
|
|
|
+ Map<String,Object> paperInfoMap = reSetPaperDetail(paper);
|
|
|
+ reSetPaper(paper,user,paperInfoMap,paperTotalScore);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算试卷难度
|
|
|
+ * @param paper
|
|
|
+ * @param paperTotalScore
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Double reSetDifficulty(Paper paper,double paperTotalScore) {
|
|
|
+ Double sum = 0.0;
|
|
|
+ List<PaperDetail> paperDetails = paperDetailRepo.findByPaperOrderByNumber(paper);
|
|
|
+ if(paperDetails != null && paperDetails.size()>0){
|
|
|
+ for(PaperDetail paperDetail:paperDetails){
|
|
|
+ //获取每个大题下面的所有小题
|
|
|
+ List<PaperDetailUnit> paperDetailUnits = paperDetailUnitRepo.findByPaperDetailOrderByNumber(paperDetail);
|
|
|
+ if(paperDetailUnits!=null && paperDetailUnits.size()>0){
|
|
|
+ for(PaperDetailUnit paperDetailUnit:paperDetailUnits){
|
|
|
+ //如果为套题,重新计算难度
|
|
|
+ if(paperDetailUnit.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION){
|
|
|
+ //重新计算套题的难度,公开度
|
|
|
+ boolean publicity = false;
|
|
|
+ double totalSum = 0d;
|
|
|
+ double totalDou = 0d;
|
|
|
+ for(int i =0;i<paperDetailUnit.getQuestion().getSubQuestions().size();i++){
|
|
|
+ Question subQuestion = paperDetailUnit.getQuestion().getSubQuestions().get(i);
|
|
|
+ //设置公开度
|
|
|
+ if(subQuestion.getPublicity()){
|
|
|
+ publicity = true;
|
|
|
+ }
|
|
|
+ if(subQuestion.getDifficultyDegree() == null){
|
|
|
+ subQuestion.setDifficultyDegree(0.5);
|
|
|
+ }
|
|
|
+ totalSum = subQuestion.getDifficultyDegree()*paperDetailUnit.getSubScoreList().get(i) + totalSum;
|
|
|
+ totalDou = paperDetailUnit.getSubScoreList().get(i) + totalDou;
|
|
|
+ }
|
|
|
+ BigDecimal b = new BigDecimal(totalSum / totalDou);
|
|
|
+ Double difficulty = b.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
+ paperDetailUnit.getQuestion().setDifficultyDegree(difficulty);
|
|
|
+ paperDetailUnit.setScore(totalDou);
|
|
|
+ }
|
|
|
+ //旧题没有难度值,需要重新赋值
|
|
|
+ if(paperDetailUnit.getQuestion().getDifficultyDegree()== null){
|
|
|
+ paperDetailUnit.getQuestion().setDifficultyDegree(0.5);
|
|
|
+ }
|
|
|
+ if(paperDetailUnit.getScore()== null){
|
|
|
+ paperDetailUnit.setScore(0d);
|
|
|
+ }
|
|
|
+ sum = paperDetailUnit.getScore() * paperDetailUnit.getQuestion().getDifficultyDegree() + sum;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(paperTotalScore < 0.1){
|
|
|
+ return 0.0;
|
|
|
+ }
|
|
|
+ BigDecimal b = new BigDecimal(sum / paperTotalScore);
|
|
|
+ Double difficulty = b.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
|
|
|
+ return difficulty;
|
|
|
+ }
|
|
|
+ return 0.0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 重新设置小题number,并返回试卷总分
|
|
|
+ * @param paper
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private double reSetPaperDetailUnit(Paper paper) {
|
|
|
+ List<PaperDetailUnit> paperDetailUnitAll = paperDetailUnitService.findByPaperAndSort(paper);
|
|
|
+ double totalScore = 0;
|
|
|
+ for (int i = 0;i<paperDetailUnitAll.size();i++) {
|
|
|
+ PaperDetailUnit unit = paperDetailUnitAll.get(i);
|
|
|
+ if (unit.getScore() != null) {
|
|
|
+ totalScore += unit.getScore();
|
|
|
+ }
|
|
|
+ unit.setNumber(i+1);
|
|
|
+ }
|
|
|
+ paperDetailUnitRepo.save(paperDetailUnitAll);
|
|
|
+ totalScore = CommonUtils.formatDouble(totalScore);
|
|
|
+ return totalScore;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 重新计算大题的总分和小题总数
|
|
|
+ * @param paper
|
|
|
+ */
|
|
|
+ private Map<String,Object> reSetPaperDetail(Paper paper) {
|
|
|
+ Map<String,Object> paperInfoMap = new HashMap<String,Object>();
|
|
|
+ int allQuesCount = 0;
|
|
|
+ List<PaperDetail> paperDetails = paperDetailRepo.findByPaperOrderByNumber(paper);
|
|
|
+ // 计算各大题总分和小题数量
|
|
|
+ for (PaperDetail paperDetail : paperDetails) {
|
|
|
+ List<PaperDetailUnit> paperDetailUnits = paperDetailUnitRepo.findByPaperDetailOrderByNumber(paperDetail);
|
|
|
+ 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() != null
|
|
|
+ && unit.getQuestion().getSubQuestions() != null
|
|
|
+ && unit.getQuestion().getSubQuestions().size() > 0) {
|
|
|
+ nestQusNum += unit.getQuestion().getSubQuestions().size() - 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ count = paperDetailUnits.size() + nestQusNum;
|
|
|
+ score = CommonUtils.formatDouble(score);
|
|
|
+ paperDetail.setScore(score);
|
|
|
+ paperDetail.setUnitCount(count);
|
|
|
+ allQuesCount += count;
|
|
|
+ } else {
|
|
|
+ paperDetail.setScore(0d);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ paperDetailRepo.save(paperDetails);
|
|
|
+ paperInfoMap.put("allQuesCount", allQuesCount);
|
|
|
+ paperInfoMap.put("paperDetails", paperDetails);
|
|
|
+ return paperInfoMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 重新设置试卷大题数量、小题数量、试卷总分等属性
|
|
|
+ * @param paper
|
|
|
+ * @param user
|
|
|
+ * @param paperInfoMap
|
|
|
+ * @param paperTotalScore
|
|
|
+ */
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ private void reSetPaper(Paper paper, AccessUser user,Map<String, Object> paperInfoMap,double paperTotalScore) {
|
|
|
+ List<PaperDetail> paperDetails = (List<PaperDetail>) paperInfoMap.get("paperDetails");
|
|
|
+ paper.setPaperDetailCount(paperDetails.size());//设置大题数量
|
|
|
+ paper.setUnitCount(Integer.parseInt(paperInfoMap.get("allQuesCount")+""));//设置小题数量
|
|
|
+ paper.setTotalScore(paperTotalScore);//设置试卷总分
|
|
|
+ if (user != null) {
|
|
|
+ paper.setLastModifyName(user.getName());
|
|
|
+ }
|
|
|
+ paperRepo.save(paper);
|
|
|
+ redisTemplate.delete(paper.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 先备份准备删掉的试题,然后再删掉
|
|
|
+ *
|
|
|
+ * @param questionId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<String> deleteImportQuestionById(String questionId, AccessUser user) {
|
|
|
+ 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 (pdu.getPaper() != null) {
|
|
|
+ if (!papers.contains(pdu.getPaper())) {
|
|
|
+ papers.add(pdu.getPaper());
|
|
|
+ }
|
|
|
+ if (PaperType.GENERATE == pdu.getPaper().getPaperType()) {
|
|
|
+ paperNames.add(pdu.getPaper().getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (paperNames.size() == 0) {
|
|
|
+ needPdus.addAll(pdus);// 此试题没有被组卷调用,则可以删除此试题
|
|
|
+ paperDetailUnitRepo.delete(needPdus);
|
|
|
+ quesBakRepo.save(BeanCopierUtil.copyProperties(ques, QuestionBak.class));
|
|
|
+ quesRepo.delete(ques);
|
|
|
+ for (Paper paper : papers) {
|
|
|
+ formatPaper(paper,user);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return paperNames;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 向试卷中插入一个试题
|
|
|
+ *
|
|
|
+ * @param paperId
|
|
|
+ * @param paperDetailId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Paper insertQuestionToPaper(String paperId, String paperDetailId, Question question, AccessUser user) {
|
|
|
+ Paper paper = paperRepo.findOne(paperId);
|
|
|
+ question.setOrgId(user.getRootOrgId().toString());
|
|
|
+ question.setCourse(paper.getCourse());
|
|
|
+ question.setCourseNo(paper.getCourse().getCode());//必须设置,因为部分方法需要courseNo作为查询条件
|
|
|
+ question = quesService.saveQues(question);
|
|
|
+
|
|
|
+ PaperDetail paperDetail = paperDetailRepo.findOne(paperDetailId);
|
|
|
+ PaperDetailUnit paperDetailUnit = new PaperDetailUnit(paper,paperDetail,question);
|
|
|
+ PaperDetailUnit paperDetailUnit2 = paperDetailUnitService.findTopOrderByNumber(paperDetail,"DESC");
|
|
|
+ paperDetailUnit.setNumber(paperDetailUnit2.getNumber());//设置number为大题的最大题号
|
|
|
+ paperDetailUnitRepo.save(paperDetailUnit);
|
|
|
+ formatPaper(paper,user);
|
|
|
+ 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,AccessUser accessUser,String quesBody) {
|
|
|
+ Set<String> selectedIds = new HashSet<>();
|
|
|
+ Paper paper = paperRepo.findOne(paperId);
|
|
|
+ List<PaperDetailUnit> pdus = paperDetailUnitRepo.findByPaperOrderByNumber(paper);
|
|
|
+ for (PaperDetailUnit pdu : pdus) {
|
|
|
+ selectedIds.add(pdu.getQuestion().getId());
|
|
|
+ }
|
|
|
+ return quesService.findByIdExclude(selectedIds, paper.getCourseNo(), quesType, curPage, pageSize,accessUser.getRootOrgId(),quesBody);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Paper selectQuestionsToPaper(String paperId, String paperDetailId, List<Question> questions,
|
|
|
+ AccessUser user) {
|
|
|
+ Paper paper = paperRepo.findOne(paperId);
|
|
|
+ PaperDetail paperDetail = paperDetailRepo.findOne(paperDetailId);
|
|
|
+ PaperDetailUnit paperDetailUnit = paperDetailUnitRepo.findTopByPaperDetailOrderByNumberDesc(paperDetail);
|
|
|
+ List<PaperDetailUnit> saveUnits = new ArrayList<PaperDetailUnit>();
|
|
|
+ for (Question ques : questions) {
|
|
|
+ PaperDetailUnit pdu = new PaperDetailUnit(paper,paperDetail,ques);
|
|
|
+ //如果大题没有小题,取导入的试题分数
|
|
|
+ if(paperDetailUnit == null){
|
|
|
+ pdu.setNumber(1);
|
|
|
+ }else {
|
|
|
+ pdu.setNumber(paperDetailUnit.getNumber());//设置为大题中最大的number
|
|
|
+ }
|
|
|
+ pdu.setScore(ques.getScore() == null? 0d:ques.getScore());
|
|
|
+ //处理套题
|
|
|
+ if(pdu.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION){
|
|
|
+ List<Question> subQuestions = ques.getSubQuestions();
|
|
|
+ List<Double> subScoreList = new ArrayList<>();
|
|
|
+ if(subQuestions != null && subQuestions.size() > 0){
|
|
|
+ for(Question subQuestion:subQuestions){
|
|
|
+ subScoreList.add(CommonUtils.formatDouble(pdu.getScore()/subQuestions.size()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ pdu.setSubScoreListNew(subScoreList);
|
|
|
+ }
|
|
|
+ saveUnits.add(pdu);
|
|
|
+ }
|
|
|
+ paperDetailUnitRepo.save(saveUnits);
|
|
|
+ formatPaper(paper, user);
|
|
|
+ return paper;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String checkPaperName(String paperName, String orgId) {
|
|
|
+ String msg = null;
|
|
|
+ List<Paper> paperList= paperRepo.findByNameAndOrgId(paperName,orgId);
|
|
|
+ if (paperList != null && paperList.size() > 0) {
|
|
|
+ msg = "试卷名称重复,请重新命名";
|
|
|
+ }
|
|
|
+ return msg;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void checkPaperNameNew(String paperName, String orgId)throws Exception{
|
|
|
+ List<Paper> paperList= paperRepo.findByNameAndOrgId(paperName,orgId);
|
|
|
+ if (paperList != null && paperList.size() > 0) {
|
|
|
+ throw new PaperException("试卷名称重复,请重新命名");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String relaceQuestionIdx(String str, int baseIdx) {
|
|
|
+ StringBuffer sb = new StringBuffer("");
|
|
|
+ Pattern pattern = Pattern.compile("##(\\d+)##");
|
|
|
+
|
|
|
+ Matcher matcher = pattern.matcher(str);
|
|
|
+
|
|
|
+ while (matcher.find()) {
|
|
|
+ String idx = matcher.group(1);
|
|
|
+ matcher.appendReplacement(sb, "___" + String.valueOf(Integer.parseInt(idx) + baseIdx) + "___");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isEmpty(sb.toString())) {
|
|
|
+ return str;
|
|
|
+ } else {
|
|
|
+ matcher.appendTail(sb);
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Page<Paper> getImportPapersNotInIds(PaperSearchInfo paperSearchInfo, String[] ids, int curPage,int pageSize) {
|
|
|
+ Set<String> selectedIds = new HashSet<>();
|
|
|
+ for (String id : ids) {
|
|
|
+ selectedIds.add(id);
|
|
|
+ }
|
|
|
+ Query query = new Query();
|
|
|
+ query.addCriteria(Criteria.where("orgId").is(paperSearchInfo.getOrgId()));
|
|
|
+ query.addCriteria(Criteria.where("paperType").is(PaperType.IMPORT));
|
|
|
+ query.addCriteria(Criteria.where("course.code").is(paperSearchInfo.getCourseNo()));
|
|
|
+ query.addCriteria(Criteria.where("id").nin(selectedIds));
|
|
|
+ long total = this.mongoTemplate.count(query, Paper.class);
|
|
|
+ query.with(new Sort(new Order(Direction.DESC,"createTime")));
|
|
|
+ query.limit(pageSize);
|
|
|
+ query.skip((curPage - 1) * pageSize);
|
|
|
+ List<Paper> paperList = this.mongoTemplate.find(query,Paper.class);
|
|
|
+ Page<Paper> paperPageList = new PageImpl<Paper>(paperList,new PageRequest(curPage - 1, pageSize), total);
|
|
|
+ return paperPageList;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 将选中的导入试卷复制为卷库试卷
|
|
|
+ */
|
|
|
+ public void useBasePaper(String selectedPaperIds,String userId){
|
|
|
+ Assert.hasLength(selectedPaperIds, "试卷id不能为空!");
|
|
|
+ String[] paperIds = selectedPaperIds.split(",");
|
|
|
+ for(int i = 0;i<paperIds.length;i++){
|
|
|
+ Paper oldpaper = paperRepo.findOne(paperIds[i]);
|
|
|
+ List<PaperDetail> paperDetails = paperDetailRepo.findByPaperOrderByNumber(oldpaper);
|
|
|
+ oldpaper.setId(null);
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String createTime = sdf.format(new Date());
|
|
|
+ oldpaper.setCreateTime(createTime);
|
|
|
+ oldpaper.setCreator(userId);
|
|
|
+ oldpaper.setLastModifyName(userId);
|
|
|
+ oldpaper.setPaperType(PaperType.GENERATE);//试卷类型 修改为组卷
|
|
|
+ Paper newPaper = paperRepo.save(oldpaper);
|
|
|
+ for(int j = 0;j<paperDetails.size();j++){
|
|
|
+ PaperDetail paperDetail = paperDetails.get(j);
|
|
|
+ List<PaperDetailUnit> paperDetailUnits = paperDetailUnitService.getUnitsByPaperDetail(paperDetail);
|
|
|
+ paperDetail.setPaper(newPaper);//关联新Paper
|
|
|
+ paperDetail.setId(null);
|
|
|
+ paperDetail.setCreateTime(createTime);
|
|
|
+ paperDetail.setCreator(userId);
|
|
|
+ PaperDetail newPaperDetail = paperDetailRepo.save(paperDetail);//保存新的paperDetail
|
|
|
+ for(int k = 0;k<paperDetailUnits.size();k++){
|
|
|
+ //重新设置保存PaperDetailUnit
|
|
|
+ PaperDetailUnit paperDetailUnit = paperDetailUnits.get(k);
|
|
|
+ paperDetailUnit.setPaper(newPaper); //关联新Paper
|
|
|
+ paperDetailUnit.setPaperDetail(newPaperDetail); //关联新paperDetail
|
|
|
+ paperDetailUnit.setId(null);
|
|
|
+ paperDetailUnit.setCreateTime(createTime);
|
|
|
+ paperDetailUnit.setCreator(userId);
|
|
|
+ paperDetailUnitRepo.save(paperDetailUnit);//保存新的paperDetailUnit
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 根据试卷名称、试卷类型检查名称是否存在
|
|
|
+ * @param paperName
|
|
|
+ * @param paperType
|
|
|
+ * @param orgId
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public boolean checkPaperName(String paperName, PaperType paperType,String orgId)throws Exception{
|
|
|
+ Paper paperTemp = new Paper();
|
|
|
+ paperTemp.setCreateTime(null);
|
|
|
+ paperTemp.setName(paperName.trim());
|
|
|
+ paperTemp.setOrgId(orgId);
|
|
|
+ paperTemp.setPaperType(paperType);
|
|
|
+ Paper paper = paperRepo.findOne(Example.of(paperTemp));
|
|
|
+ if(paper!=null){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上传音频文件检查
|
|
|
+ * @param paperId
|
|
|
+ * @param filesName
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Map<String, String> checkRadioFile(String paperId,List<String> filesName){
|
|
|
+ Map<String, String> messageMap = new HashMap<String, String>();
|
|
|
+ //判断文件名中格式是否正确
|
|
|
+ for(String fileName: filesName){
|
|
|
+ String[] fileNames = fileName.split("\\.");
|
|
|
+ String fileType = fileNames[fileNames.length-1];
|
|
|
+ if(radioType.indexOf(fileType)<0){
|
|
|
+ messageMap.put("errorMsg", fileName+",文件格式不正确,当前支持格式:"+radioType);
|
|
|
+ return messageMap;
|
|
|
+ }
|
|
|
+ String pattern_01 = "\\d+_1_\\d{1,2}"; //题干正则
|
|
|
+ String pattern_02 = "\\d+_2_[A-Z|a-z]_\\d{1,2}"; //选项正则
|
|
|
+ if(!(Pattern.matches(pattern_01,fileNames[0])||
|
|
|
+ Pattern.matches(pattern_02,fileNames[0]))){
|
|
|
+ messageMap.put("errorMsg", fileName+"文件名格式不正确,请检查");
|
|
|
+ return messageMap;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //根据试卷id,查询该试卷
|
|
|
+ Paper paper = paperRepo.findOne(paperId);
|
|
|
+ //根据试卷查询所有的小题
|
|
|
+ List<PaperDetailUnit> paperDetailUnits = paperDetailUnitRepo.findByPaperOrderByNumber(paper);
|
|
|
+ String names = "";
|
|
|
+ for(PaperDetailUnit paperDetailUnit:paperDetailUnits){
|
|
|
+ names = names + paperDetailUnit.getNumber().toString() + ",";
|
|
|
+ }
|
|
|
+ for(String fileName: filesName){
|
|
|
+ String fileNames[] = fileName.split("_");
|
|
|
+ //先判断小题号是否正确
|
|
|
+ String fileNameFirst = fileNames[0];
|
|
|
+ if(!names.contains(fileNameFirst)){
|
|
|
+ messageMap.put("errorMsg", fileName + "文件,试卷中没有对应的小题");
|
|
|
+ return messageMap;
|
|
|
+ }
|
|
|
+ //再判断题干中是否存在ABCD
|
|
|
+ String fileNameSecond = fileNames[1];
|
|
|
+ if(fileNameSecond.equals("1")){
|
|
|
+ if(fileNames.length>3){
|
|
|
+ Matcher m = Pattern.compile(".*[a-zA-Z]+.*").matcher(fileNames[2]);
|
|
|
+ if(m.matches()){
|
|
|
+ messageMap.put("errorMsg", fileName + "文件名称不对,文件名为题干,但存在选项");
|
|
|
+ return messageMap;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //判断选项
|
|
|
+ else if(fileNameSecond.equals("2")){
|
|
|
+ messageMap = checkOptions(paperDetailUnits, fileNames, fileName);
|
|
|
+ if(messageMap != null){
|
|
|
+ return messageMap;
|
|
|
+ }
|
|
|
+ messageMap = new HashMap<String, String>();
|
|
|
+ }else {
|
|
|
+ messageMap.put("errorMsg", fileName + "文件名称不对,无法识别为题干或选项 ");
|
|
|
+ return messageMap;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ messageMap.put("errorMsg", "OK");
|
|
|
+ return messageMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断选项
|
|
|
+ public Map<String, String> checkOptions(List<PaperDetailUnit> paperDetailUnits,String fileNames[],String fileName){
|
|
|
+ Map<String, String> messageMap = new HashMap<String, String>();
|
|
|
+ for(PaperDetailUnit paperDetailUnit:paperDetailUnits){
|
|
|
+ if(paperDetailUnit.getNumber().toString().equals(fileNames[0])){
|
|
|
+ //判断是否为选择题
|
|
|
+ if(paperDetailUnit.getQuestionType() != QuesStructType.SINGLE_ANSWER_QUESTION
|
|
|
+ &&paperDetailUnit.getQuestionType() != QuesStructType.MULTIPLE_ANSWER_QUESTION){
|
|
|
+ Matcher m = Pattern.compile(".*[a-zA-Z]+.*").matcher(fileNames[2]);
|
|
|
+ if(m.matches()){
|
|
|
+ messageMap.put("errorMsg", fileName + "文件名称有误,题目不是选择题");
|
|
|
+ return messageMap;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }else {
|
|
|
+ List<QuesOption> options = paperDetailUnit.getQuestion().getQuesOptions();
|
|
|
+ String option = "";
|
|
|
+ for(QuesOption quesOption:options){
|
|
|
+ option = option + quesOption.getNumber()+",";
|
|
|
+ }
|
|
|
+ Integer integer = CommonUtils.characterToNumber(fileNames[2]);
|
|
|
+ if(!option.contains(integer.toString())){
|
|
|
+ messageMap.put("errorMsg", fileName + "文件名称有误,题目中没有对应的"+fileNames[2]+"选项");
|
|
|
+ return messageMap;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上传音频文件到又拍云
|
|
|
+ * @param files
|
|
|
+ * @param paperId
|
|
|
+ * @param accessUser
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ public void uploadRadio(List<MultipartFile> files,String paperId,AccessUser accessUser) throws IOException{
|
|
|
+ //根据试卷id,查询该试卷
|
|
|
+ Paper paper = paperRepo.findOne(paperId);
|
|
|
+ for(MultipartFile file: files){
|
|
|
+ //判断文件大小
|
|
|
+ long fileSize = file.getSize();
|
|
|
+ int size = Integer.parseInt(audioMaxsize);
|
|
|
+ if(fileSize>size * 1048576){
|
|
|
+ throw new RuntimeException("音频文件大小超过5M,不能上传");
|
|
|
+ }
|
|
|
+ //根据试卷查询所有的小题,根据文件名匹配出当前小题ID
|
|
|
+ Question question = null;
|
|
|
+ String numbers[] = file.getOriginalFilename().split("_");
|
|
|
+ List<PaperDetailUnit> paperDetailUnits = paperDetailUnitRepo.findByPaperOrderByNumber(paper);
|
|
|
+ for(PaperDetailUnit paperDetailUnit:paperDetailUnits){
|
|
|
+ if(paperDetailUnit.getNumber().toString().equals(numbers[0])){
|
|
|
+ question = paperDetailUnit.getQuestion();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ uploadAudioFile(paperId,question.getId(),file,accessUser);
|
|
|
+ appendAudioTag(file.getOriginalFilename(),question.getId());
|
|
|
+ }
|
|
|
+ //删除服务器文件夹
|
|
|
+ String mp3DirectoryPath = TEMP_FILE_EXP + File.separator + paperId;
|
|
|
+ File mp3Directory = new File(mp3DirectoryPath);
|
|
|
+ FileUtils.deleteDirectory(mp3Directory);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上传音频文件至又拍云
|
|
|
+ * @param paperId
|
|
|
+ * @param questionId
|
|
|
+ * @param file
|
|
|
+ */
|
|
|
+ private void uploadAudioFile(String paperId,String questionId,MultipartFile file,AccessUser accessUser){
|
|
|
+ try {
|
|
|
+ String mp3DirectoryPath = TEMP_FILE_EXP + File.separator + paperId;
|
|
|
+ //新建文件夹
|
|
|
+ File mp3Directory = new File(mp3DirectoryPath);
|
|
|
+ if(!mp3Directory.exists()){
|
|
|
+ mp3Directory.mkdirs();
|
|
|
+ }
|
|
|
+ byte[] bufs = new byte[1024 * 4];
|
|
|
+ //使用随机数,防止缓存
|
|
|
+ Random random = new Random();
|
|
|
+ int randomNumber = random.nextInt(1000);
|
|
|
+ String mp3FileNameString = questionId+"_"+randomNumber+"_"+ file.getOriginalFilename();
|
|
|
+ File mp3File = new File(mp3DirectoryPath + File.separator +mp3FileNameString);
|
|
|
+ FileOutputStream outputStream = new FileOutputStream(mp3File);
|
|
|
+ BufferedInputStream bis = new BufferedInputStream(file.getInputStream(),1024*10);
|
|
|
+ int read = 0;
|
|
|
+ while ((read = bis.read(bufs,0,1024*4)) != -1) {
|
|
|
+ outputStream.write(bufs,0,read);
|
|
|
+ }
|
|
|
+ bis.close();
|
|
|
+ outputStream.flush();
|
|
|
+ outputStream.close();
|
|
|
+ //上传到又拍云
|
|
|
+ UpYun upYun = new UpYun(bucketName, userName, password);
|
|
|
+ upYun.writeFile(upyunRadioPath+mp3FileNameString, mp3File,true);
|
|
|
+ mp3File.delete();
|
|
|
+ //保存记录
|
|
|
+ questionAudioService.saveQuestionAudio(new QuestionAudio(questionId,file.getOriginalFilename(),upyunRadioPath+mp3FileNameString),accessUser);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 音频文件插入到标签
|
|
|
+ * @param fileName
|
|
|
+ * @param questionId
|
|
|
+ */
|
|
|
+ public void appendAudioTag(String fileName,String questionId){
|
|
|
+ QuestionAudio questionAudio = questionAudioService.findByQuestionIdAndFileName(questionId,fileName);
|
|
|
+ if(questionAudio != null){
|
|
|
+ String numbers[] = fileName.split("_");
|
|
|
+ Question question = quesRepo.findOne(questionAudio.getQuestionId());
|
|
|
+ if(numbers[1].equals("1")){
|
|
|
+ String quesBody = question.getQuesBody();
|
|
|
+ if(!quesBody.contains(fileName)){
|
|
|
+ String quesBodyNew = quesBody.substring(0, quesBody.lastIndexOf("</p>"))
|
|
|
+ + "<a id=\"" + questionAudio.getId() + "\" name=\"" + fileName + "\"></a></p>";
|
|
|
+ question.setQuesBody(quesBodyNew);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ List<QuesOption> quesOptions = question.getQuesOptions();
|
|
|
+ List<QuesOption> quesOptionsNew = new ArrayList<QuesOption>();
|
|
|
+ for(QuesOption quesOption:quesOptions){
|
|
|
+ if(quesOption.getNumber().equals(CommonUtils.characterToNumber(numbers[2]).toString())){
|
|
|
+ String optionBody = quesOption.getOptionBody();
|
|
|
+ if(!optionBody.contains(fileName)){
|
|
|
+ String optionBodyNew = "";
|
|
|
+ if(StringUtils.isBlank(optionBody)){
|
|
|
+ optionBodyNew = "<p><a id=\""+questionAudio.getId()+"\" name=\""+fileName+"\"></a></p>";
|
|
|
+ }else{
|
|
|
+ optionBodyNew = optionBody.substring(0, optionBody.lastIndexOf("</p>"))
|
|
|
+ + "<a id=\""+questionAudio.getId()+"\" name=\""+fileName+"\"></a></p>";
|
|
|
+ }
|
|
|
+ quesOption.setOptionBody(optionBodyNew);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ quesOptionsNew.add(quesOption);
|
|
|
+ }
|
|
|
+ quesOptions = null;
|
|
|
+ question.setQuesOptions(quesOptionsNew);
|
|
|
+ }
|
|
|
+ question.setHasAudio(true);
|
|
|
+ quesRepo.save(question);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|