|
@@ -1,40 +1,24 @@
|
|
|
package com.qmth.cqb.paper.service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
-import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
-import org.springframework.data.mongodb.core.query.Query;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
-import com.qmth.cqb.paper.dao.PaperDetailUnitRepo;
|
|
|
import com.qmth.cqb.paper.dto.PaperDetailUnitExp;
|
|
|
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.question.model.Question;
|
|
|
-import com.qmth.cqb.question.service.QuesService;
|
|
|
import com.qmth.cqb.utils.enums.PaperType;
|
|
|
|
|
|
-import cn.com.qmth.examcloud.common.dto.question.enums.QuesStructType;
|
|
|
import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
|
|
|
|
|
|
-@Service
|
|
|
-public class PaperDetailUnitService {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- PaperDetailUnitRepo paperDetailUnitRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- QuesService quesService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- PaperService paperService;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- MongoTemplate mongoTemplate;
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * @author chenken
|
|
|
+ * @date 2017年9月13日 上午11:32:00
|
|
|
+ * @company QMTH
|
|
|
+ * @description PaperDetailUnitService.java
|
|
|
+ */
|
|
|
+public interface PaperDetailUnitService {
|
|
|
|
|
|
/**
|
|
|
* 根据Id获得对应的试题对象
|
|
@@ -42,9 +26,7 @@ public class PaperDetailUnitService {
|
|
|
* @param id
|
|
|
* @return
|
|
|
*/
|
|
|
- public Question getQuestionByPaperDetailUnitId(String id) {
|
|
|
- return paperDetailUnitRepo.findOne(id).getQuestion();
|
|
|
- }
|
|
|
+ public Question getQuestionByPaperDetailUnitId(String id);
|
|
|
|
|
|
/**
|
|
|
* 按ID查询小题
|
|
@@ -52,9 +34,7 @@ public class PaperDetailUnitService {
|
|
|
* @param id
|
|
|
* @return
|
|
|
*/
|
|
|
- public PaperDetailUnit findById(String id) {
|
|
|
- return paperDetailUnitRepo.findOne(id);
|
|
|
- }
|
|
|
+ public PaperDetailUnit findById(String id);
|
|
|
|
|
|
/**
|
|
|
* 保存小题
|
|
@@ -62,45 +42,7 @@ public class PaperDetailUnitService {
|
|
|
* @param pduExp
|
|
|
* @return
|
|
|
*/
|
|
|
- public PaperDetailUnit savePaperDetailUnit(PaperDetailUnitExp pduExp, AccessUser user) {
|
|
|
- PaperDetailUnit oldPdu = paperDetailUnitRepo.findOne(pduExp.getId());
|
|
|
- if (oldPdu.getQuestionType() == QuesStructType.NESTED_ANSWER_QUESTION) {
|
|
|
- if (pduExp.getQuestion().getId().equals(oldPdu.getQuestion().getId())) {
|
|
|
- // 更新对象为套题本身
|
|
|
- oldPdu.setQuestion(quesService.saveQues(pduExp.getQuestion()));
|
|
|
- } else {
|
|
|
- List<Double> subScoreList = oldPdu.getSubScoreList();
|
|
|
- int size = oldPdu.getQuestion().getSubQuestions().size();
|
|
|
- boolean match = false;
|
|
|
- // 判断更新的对象是哪个子题
|
|
|
- for (int index = 1; index <= size; index++) {
|
|
|
- // 检查子题分数,确保没有错误数据
|
|
|
- if (subScoreList.size() < index) {
|
|
|
- subScoreList.add(0d);
|
|
|
- }
|
|
|
- Question sub = oldPdu.getQuestion().getSubQuestions().get(index - 1);
|
|
|
- if (pduExp.getQuestion().getId().equals(sub.getId())) {
|
|
|
- // 匹配到子题
|
|
|
- subScoreList.set(index - 1, pduExp.getScore());
|
|
|
- oldPdu.getQuestion().getSubQuestions().set(index - 1, pduExp.getQuestion());
|
|
|
- match = true;
|
|
|
- }
|
|
|
- }
|
|
|
- if (match) {
|
|
|
- oldPdu.setQuestion(quesService.saveQues(oldPdu.getQuestion()));
|
|
|
- }
|
|
|
- // 更新套题unit当前总分与子题分数
|
|
|
- oldPdu.setSubScoreList(subScoreList);
|
|
|
- }
|
|
|
- } else {
|
|
|
- oldPdu.setQuestion(quesService.saveQues(pduExp.getQuestion()));
|
|
|
- oldPdu.setScore(pduExp.getScore());
|
|
|
- }
|
|
|
- // 同时要跟新小题里面的Qustion对象
|
|
|
- oldPdu = paperDetailUnitRepo.save(oldPdu);
|
|
|
- paperService.formatPaper(oldPdu.getPaper(), user);
|
|
|
- return oldPdu;
|
|
|
- }
|
|
|
+ public PaperDetailUnit savePaperDetailUnit(PaperDetailUnitExp pduExp, AccessUser user);
|
|
|
|
|
|
/**
|
|
|
* 删除小题
|
|
@@ -108,11 +50,7 @@ public class PaperDetailUnitService {
|
|
|
* @param id
|
|
|
* @return
|
|
|
*/
|
|
|
- public void deletePaperDetailUnit(String id, AccessUser user) {
|
|
|
- Paper paper = paperDetailUnitRepo.findOne(id).getPaper();
|
|
|
- paperDetailUnitRepo.delete(id);
|
|
|
- paperService.formatPaper(paper, user);
|
|
|
- }
|
|
|
+ public void deletePaperDetailUnit(String id, AccessUser user);
|
|
|
|
|
|
/**
|
|
|
* 根据大题查小题
|
|
@@ -120,41 +58,28 @@ public class PaperDetailUnitService {
|
|
|
* @param paperDetail
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<PaperDetailUnit> getUnitsByPaperDetail(PaperDetail paperDetail) {
|
|
|
- return paperDetailUnitRepo.findByPaperDetailOrderByNumber(paperDetail);
|
|
|
- }
|
|
|
+ public List<PaperDetailUnit> getUnitsByPaperDetail(PaperDetail paperDetail);
|
|
|
|
|
|
/**
|
|
|
* 根据大题集合删除小题
|
|
|
*
|
|
|
* @param paperDetails
|
|
|
*/
|
|
|
- public void deleteUnitsByPaperDetails(List<PaperDetail> paperDetails) {
|
|
|
- List<PaperDetailUnit> units = new ArrayList<PaperDetailUnit>();
|
|
|
- for (PaperDetail pd : paperDetails) {
|
|
|
- units.addAll(getUnitsByPaperDetail(pd));
|
|
|
- }
|
|
|
- paperDetailUnitRepo.delete(units);
|
|
|
- }
|
|
|
+ public void deleteUnitsByPaperDetails(List<PaperDetail> paperDetails);
|
|
|
|
|
|
- public List<PaperDetailUnit> findByQuestionAndPaperTypes(Question question,List<PaperType> paperTypes){
|
|
|
- Query query = new Query();
|
|
|
- query.addCriteria(Criteria.where("paperType").in(paperTypes));
|
|
|
- query.addCriteria(Criteria.where("question").is(question));
|
|
|
- return this.mongoTemplate.find(query, PaperDetailUnit.class);
|
|
|
- }
|
|
|
+ public List<PaperDetailUnit> findByQuestionAndPaperTypes(Question question,List<PaperType> paperTypes);
|
|
|
|
|
|
/**
|
|
|
* 查询大题下的小题
|
|
|
* 按number升序或降序排列,取第一个
|
|
|
* @return
|
|
|
*/
|
|
|
- public PaperDetailUnit findTopOrderByNumber(PaperDetail paperDetail,String orderType){
|
|
|
- if("ASC".equals(orderType)){
|
|
|
- return paperDetailUnitRepo.findTopByPaperDetailOrderByNumberAsc(paperDetail);
|
|
|
- }else if("DESC".equals(orderType)){
|
|
|
- return paperDetailUnitRepo.findTopByPaperDetailOrderByNumberDesc(paperDetail);
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
+ public PaperDetailUnit findTopOrderByNumber(PaperDetail paperDetail,String orderType);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 按试卷 查询 小题,并将小题按number,createTime排序
|
|
|
+ * @param paper
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<PaperDetailUnit> findByPaperAndSort(Paper paper);
|
|
|
}
|