|
@@ -1,24 +1,34 @@
|
|
|
package com.zhongzheng.modules.bank.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.lang.Validator;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.zhongzheng.common.exception.CustomException;
|
|
|
import com.zhongzheng.common.utils.DateUtils;
|
|
|
-import com.zhongzheng.modules.bank.bo.ExamSimulateAddBo;
|
|
|
-import com.zhongzheng.modules.bank.bo.ExamSimulateEditBo;
|
|
|
-import com.zhongzheng.modules.bank.bo.ExamSimulateQueryBo;
|
|
|
+import com.zhongzheng.common.utils.ServletUtils;
|
|
|
+import com.zhongzheng.modules.bank.bo.*;
|
|
|
+import com.zhongzheng.modules.bank.domain.Exam;
|
|
|
import com.zhongzheng.modules.bank.domain.ExamSimulate;
|
|
|
+import com.zhongzheng.modules.bank.domain.ExamSimulateQuestion;
|
|
|
+import com.zhongzheng.modules.bank.domain.ExamTempQuestion;
|
|
|
import com.zhongzheng.modules.bank.mapper.ExamSimulateMapper;
|
|
|
-import com.zhongzheng.modules.bank.service.IExamSimulateService;
|
|
|
+import com.zhongzheng.modules.bank.service.*;
|
|
|
import com.zhongzheng.modules.bank.vo.ExamSimulateVo;
|
|
|
+import com.zhongzheng.modules.bank.vo.ExamTempVo;
|
|
|
+import com.zhongzheng.modules.bank.vo.QuestionVo;
|
|
|
+import com.zhongzheng.modules.exam.service.IExamPaperService;
|
|
|
+import com.zhongzheng.modules.goods.vo.GoodsPlayConfigVo;
|
|
|
+import com.zhongzheng.modules.order.domain.Order;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.github.pagehelper.Page;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.util.Collection;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -30,6 +40,15 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
public class ExamSimulateServiceImpl extends ServiceImpl<ExamSimulateMapper, ExamSimulate> implements IExamSimulateService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IExamService iExamService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IExamSimulateQuestionService iExamSimulateQuestionService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IQuestionService iQuestionService;
|
|
|
+
|
|
|
@Override
|
|
|
public ExamSimulateVo queryById(Long examId){
|
|
|
ExamSimulate db = this.baseMapper.selectById(examId);
|
|
@@ -70,12 +89,135 @@ public class ExamSimulateServiceImpl extends ServiceImpl<ExamSimulateMapper, Exa
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Boolean insertByAddBo(ExamSimulateAddBo bo) {
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public ExamSimulateVo insertByAddBo(ExamSimulateAddBo bo) {
|
|
|
ExamSimulate add = BeanUtil.toBean(bo, ExamSimulate.class);
|
|
|
+ Exam exam = iExamService.getOne(new LambdaQueryWrapper<Exam>().eq(Exam::getExamId, bo.getExamId()));
|
|
|
+ if(exam.getDoType()!=2||exam.getSimulateStatus()==0){
|
|
|
+ throw new CustomException("该试卷没开启模拟随机考");
|
|
|
+ }
|
|
|
+ if(Validator.isEmpty(exam.getSimulateConfigJson())){
|
|
|
+ throw new CustomException("该试卷没配置模拟随机考");
|
|
|
+ }
|
|
|
+ ExamSimulateConfigBo simulateConfig = JSON.parseObject(exam.getSimulateConfigJson(), ExamSimulateConfigBo.class);
|
|
|
+
|
|
|
+
|
|
|
+ ExamSimulateQueryBo qk1Bo = new ExamSimulateQueryBo(); //单选知识点
|
|
|
+ qk1Bo.setExamId(exam.getExamId());
|
|
|
+ qk1Bo.setKnowledIds(simulateConfig.getSingleChoice().getKnowledIds());
|
|
|
+ qk1Bo.setKnum(simulateConfig.getSingleChoice().getKnum());
|
|
|
+ qk1Bo.setRandomNum(simulateConfig.getType());
|
|
|
+ qk1Bo.setType(1);
|
|
|
+ List<Long> qk1 = baseMapper.getKnowledQuestionList(qk1Bo);
|
|
|
+
|
|
|
+ ExamSimulateQueryBo qk2Bo = new ExamSimulateQueryBo(); //多选知识点
|
|
|
+ qk2Bo.setExamId(exam.getExamId());
|
|
|
+ qk2Bo.setKnowledIds(simulateConfig.getMultipleChoice().getKnowledIds());
|
|
|
+ qk2Bo.setKnum(simulateConfig.getMultipleChoice().getKnum());
|
|
|
+ qk2Bo.setRandomNum(simulateConfig.getType());
|
|
|
+ qk2Bo.setType(2);
|
|
|
+ List<Long> qk2 = baseMapper.getKnowledQuestionList(qk2Bo);
|
|
|
+
|
|
|
+ ExamSimulateQueryBo qk3Bo = new ExamSimulateQueryBo(); //案例选知识点
|
|
|
+ qk3Bo.setExamId(exam.getExamId());
|
|
|
+ qk3Bo.setKnowledIds(simulateConfig.getCaseQuestion().getKnowledIds());
|
|
|
+ qk3Bo.setKnum(simulateConfig.getCaseQuestion().getKnum());
|
|
|
+ qk3Bo.setRandomNum(simulateConfig.getType());
|
|
|
+ qk3Bo.setType(4);
|
|
|
+ List<Long> qk3 = baseMapper.getKnowledQuestionList(qk3Bo);
|
|
|
+
|
|
|
+ ExamSimulateQueryBo q1Bo = new ExamSimulateQueryBo(); //单选
|
|
|
+ q1Bo.setExamId(exam.getExamId());
|
|
|
+ q1Bo.setKnowledQuestionIds(qk1);
|
|
|
+ q1Bo.setQnum(simulateConfig.getSingleChoice().getQnum()-qk1.size());
|
|
|
+ q1Bo.setRandomNum(simulateConfig.getType());
|
|
|
+ q1Bo.setType(1);
|
|
|
+ List<Long> q1 = baseMapper.getQuestionList(q1Bo);
|
|
|
+
|
|
|
+ ExamSimulateQueryBo q2Bo = new ExamSimulateQueryBo(); //多选
|
|
|
+ q2Bo.setExamId(exam.getExamId());
|
|
|
+ q2Bo.setKnowledQuestionIds(qk2);
|
|
|
+ q2Bo.setQnum(simulateConfig.getMultipleChoice().getQnum()-qk2.size());
|
|
|
+ q2Bo.setRandomNum(simulateConfig.getType());
|
|
|
+ q2Bo.setType(2);
|
|
|
+ List<Long> q2 = baseMapper.getQuestionList(q2Bo);
|
|
|
+
|
|
|
+ ExamSimulateQueryBo q3Bo = new ExamSimulateQueryBo(); //案例选
|
|
|
+ q3Bo.setExamId(exam.getExamId());
|
|
|
+ q3Bo.setKnowledQuestionIds(qk3);
|
|
|
+ q3Bo.setQnum(simulateConfig.getCaseQuestion().getQnum()-qk3.size());
|
|
|
+ q3Bo.setRandomNum(simulateConfig.getType());
|
|
|
+ q3Bo.setType(4);
|
|
|
+ List<Long> q3 = baseMapper.getQuestionList(q3Bo);
|
|
|
+
|
|
|
+ qk1.addAll(q1);
|
|
|
+ qk2.addAll(q2);
|
|
|
+ qk3.addAll(q3);
|
|
|
+
|
|
|
+ List<Long> allQ = new ArrayList<>();
|
|
|
+ if(simulateConfig.getSingleChoice().getRandomNum()==1){ //题型顺序
|
|
|
+ for(int i=1;i<4;i++){
|
|
|
+ if(simulateConfig.getSingleChoice().getOrderNum()==i){
|
|
|
+ allQ.addAll(qk1);
|
|
|
+ }
|
|
|
+ if(simulateConfig.getMultipleChoice().getOrderNum()==i){
|
|
|
+ allQ.addAll(qk2);
|
|
|
+ }
|
|
|
+ if(simulateConfig.getCaseQuestion().getOrderNum()==i){
|
|
|
+ allQ.addAll(qk3);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{//题型随机
|
|
|
+ Map<Integer,Integer> map = new HashMap<>();
|
|
|
+ for(int i=1;i<50;i++){
|
|
|
+ int num = (int)(10.0*Math.random()) + 1;
|
|
|
+ if(num%3==0){
|
|
|
+ if(!map.containsKey(0)){
|
|
|
+ map.put(0,0);
|
|
|
+ allQ.addAll(qk1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(num%3==1){
|
|
|
+ if(!map.containsKey(1)){
|
|
|
+ map.put(1,1);
|
|
|
+ allQ.addAll(qk2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(num%3==2){
|
|
|
+ if(!map.containsKey(2)){
|
|
|
+ map.put(2,2);
|
|
|
+ allQ.addAll(qk3);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(allQ.size()>=3){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
validEntityBeforeSave(add);
|
|
|
add.setCreateTime(DateUtils.getNowTime());
|
|
|
add.setUpdateTime(DateUtils.getNowTime());
|
|
|
- return this.save(add);
|
|
|
+ add.setExamPaperId(exam.getExamPaperId());
|
|
|
+ add.setExamName(exam.getExamName()+"-"+ServletUtils.getEncoded(""));
|
|
|
+ boolean result = this.save(add);
|
|
|
+ Collection<ExamSimulateQuestion> coll = new HashSet<>();
|
|
|
+ for(int i=0;i<allQ.size();i++){
|
|
|
+ ExamSimulateQuestion addItem = new ExamSimulateQuestion();
|
|
|
+ addItem.setSimulateExamId(add.getSimulateExamId());
|
|
|
+ addItem.setQuestionId(allQ.get(i));
|
|
|
+ addItem.setSort(new Long(i));
|
|
|
+ coll.add(addItem);
|
|
|
+ }
|
|
|
+ if(!iExamSimulateQuestionService.saveBatch(coll)){
|
|
|
+ throw new CustomException("试卷绑定错误");
|
|
|
+ }
|
|
|
+ ExamSimulateVo examSimulateVo = BeanUtil.toBean(add, ExamSimulateVo.class);
|
|
|
+ ExamSimulateQueryBo questionQueryBo = new ExamSimulateQueryBo();
|
|
|
+ questionQueryBo.setSimulateExamId(examSimulateVo.getSimulateExamId());
|
|
|
+ List<QuestionVo> questionlist = queryBatchList(questionQueryBo);
|
|
|
+ examSimulateVo.setQuestionList(questionlist);
|
|
|
+ examSimulateVo.setDoMode(3);
|
|
|
+ return examSimulateVo;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -102,4 +244,14 @@ public class ExamSimulateServiceImpl extends ServiceImpl<ExamSimulateMapper, Exa
|
|
|
}
|
|
|
return this.removeByIds(ids);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Long> getQuestionList(ExamSimulateQueryBo bo) {
|
|
|
+ return this.baseMapper.getQuestionList(bo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<QuestionVo> queryBatchList(ExamSimulateQueryBo bo) {
|
|
|
+ return this.baseMapper.queryBatchList(bo);
|
|
|
+ }
|
|
|
}
|