生成课程、考试时:如果课程下有试卷,不生成试卷;如果没有试卷,生成默认试卷

This commit is contained in:
joylink_zhangsai 2020-12-04 20:10:58 +08:00
parent 64f5ec3d7b
commit b4876fa189
3 changed files with 75 additions and 68 deletions

View File

@ -536,6 +536,13 @@ public class ExamService implements IExamService{
// } // }
} }
@Override
public List<ExamDefinition> findEntities(Long lessonId) {
ExamDefinitionExample example = new ExamDefinitionExample();
example.createCriteria().andLessonIdEqualTo(lessonId);
return examDefinitionDAO.selectByExample(example);
}
private List<ExamDefinition> findEntityByLessonIdList(ArrayList<Long> lessonIdList) { private List<ExamDefinition> findEntityByLessonIdList(ArrayList<Long> lessonIdList) {
ExamDefinitionExample example = new ExamDefinitionExample(); ExamDefinitionExample example = new ExamDefinitionExample();
example.createCriteria().andLessonIdIn(lessonIdList); example.createCriteria().andLessonIdIn(lessonIdList);

View File

@ -1,7 +1,11 @@
package club.joylink.rtss.services; package club.joylink.rtss.services;
import club.joylink.rtss.entity.ExamDefinition;
import club.joylink.rtss.vo.UserVO; import club.joylink.rtss.vo.UserVO;
import club.joylink.rtss.vo.client.*; import club.joylink.rtss.vo.client.ExamDefinitionQueryVO;
import club.joylink.rtss.vo.client.ExamDefinitionVO;
import club.joylink.rtss.vo.client.ExamsLessonVO;
import club.joylink.rtss.vo.client.PageVO;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -26,14 +30,11 @@ public interface IExamService {
/** /**
* 查询课程所属产品下有实训的实训类型 * 查询课程所属产品下有实训的实训类型
* @param lessonId
* @return
*/ */
List<String> queryTrainingTypes(Long lessonId); List<String> queryTrainingTypes(Long lessonId);
/** /**
* 查询试题定义的详细信息 * 查询试题定义的详细信息
* @param examId
*/ */
ExamDefinitionVO queryExamInfo(Long examId); ExamDefinitionVO queryExamInfo(Long examId);
@ -59,32 +60,28 @@ public interface IExamService {
/** /**
* 根据课程和实训类型查询实训数量 * 根据课程和实训类型查询实训数量
* @param lessonId
* @param trainingType
* @return
*/ */
Long queryTrainingNum(Long lessonId, String trainingType, String operateType); Long queryTrainingNum(Long lessonId, String trainingType, String operateType);
/** /**
* 试题上线 * 试题上线
* @param id
* @param userVO
*/ */
void onLine(Long id, UserVO userVO); void onLine(Long id, UserVO userVO);
/** /**
* 试题下线 * 试题下线
* @param id
* @param userVO
*/ */
void offLine(Long id, UserVO userVO); void offLine(Long id, UserVO userVO);
/** /**
* 更新试题 * 更新试题
* @param id
* @param examDefinitionVO
*/ */
void update(Long id, ExamDefinitionVO examDefinitionVO); void update(Long id, ExamDefinitionVO examDefinitionVO);
void copy(Map<Long, Long> lessonRelationMap, UserVO user); void copy(Map<Long, Long> lessonRelationMap, UserVO user);
/**
* 根据课程id查询考试
*/
List<ExamDefinition> findEntities(Long lessonId);
} }

View File

@ -619,7 +619,7 @@ public class LessonService implements ILessonService {
if (Objects.nonNull(existedDefaultLesson)) { if (Objects.nonNull(existedDefaultLesson)) {
lesson.setId(existedDefaultLesson.getId()); lesson.setId(existedDefaultLesson.getId());
lessonDAO.updateByPrimaryKey(lesson); lessonDAO.updateByPrimaryKey(lesson);
//存在默认课程删除旧版本章节考试及关联实训数据 //存在默认课程删除旧版本章节章节关联的实训
LsLessonVersionExample versionExample = new LsLessonVersionExample(); LsLessonVersionExample versionExample = new LsLessonVersionExample();
versionExample.createCriteria().andLessonIdEqualTo(existedDefaultLesson.getId()); versionExample.createCriteria().andLessonIdEqualTo(existedDefaultLesson.getId());
lessonVersionDAO.deleteByExample(versionExample); lessonVersionDAO.deleteByExample(versionExample);
@ -632,21 +632,21 @@ public class LessonService implements ILessonService {
chapterExample.createCriteria().andLessonIdEqualTo(existedDefaultLesson.getId()); chapterExample.createCriteria().andLessonIdEqualTo(existedDefaultLesson.getId());
lessonChapterDAO.deleteByExample(chapterExample); lessonChapterDAO.deleteByExample(chapterExample);
ExamDefinitionExample examDefinitionExample = new ExamDefinitionExample(); // ExamDefinitionExample examDefinitionExample = new ExamDefinitionExample();
examDefinitionExample.createCriteria().andLessonIdEqualTo(existedDefaultLesson.getId()); // examDefinitionExample.createCriteria().andLessonIdEqualTo(existedDefaultLesson.getId());
List<ExamDefinition> examDefinitions = examDefinitionDAO.selectByExample(examDefinitionExample); // List<ExamDefinition> examDefinitions = examDefinitionDAO.selectByExample(examDefinitionExample);
if (!CollectionUtils.isEmpty(examDefinitions)) { // if (!CollectionUtils.isEmpty(examDefinitions)) {
List<Long> list = examDefinitions.stream().map(ExamDefinition::getId).collect(Collectors.toList()); // List<Long> list = examDefinitions.stream().map(ExamDefinition::getId).collect(Collectors.toList());
ExamDefinitionRulesExample rulesExample = new ExamDefinitionRulesExample(); // ExamDefinitionRulesExample rulesExample = new ExamDefinitionRulesExample();
rulesExample.createCriteria().andExamIdIn(list); // rulesExample.createCriteria().andExamIdIn(list);
definitionRulesDAO.deleteByExample(rulesExample); // definitionRulesDAO.deleteByExample(rulesExample);
examDefinitionDAO.deleteByExample(examDefinitionExample); // examDefinitionDAO.deleteByExample(examDefinitionExample);
} // }
} else { } else {
lessonDAO.insert(lesson); lessonDAO.insert(lesson);
} }
//版本0.0 //课程版本0.0
LsLessonVersion lessonVersion = new LsLessonVersion(); LsLessonVersion lessonVersion = new LsLessonVersion();
lessonVersion.setLessonId(lesson.getId()); lessonVersion.setLessonId(lesson.getId());
lessonVersion.setCreatorId(lesson.getCreatorId()); lessonVersion.setCreatorId(lesson.getCreatorId());
@ -654,6 +654,7 @@ public class LessonService implements ILessonService {
lessonVersion.setVersion(BusinessConsts.Lesson.Version.originalVersion); lessonVersion.setVersion(BusinessConsts.Lesson.Version.originalVersion);
lessonVersionDAO.insert(lessonVersion); lessonVersionDAO.insert(lessonVersion);
//生成课程的章节
List<Training> examTrainings = new ArrayList<>(20); List<Training> examTrainings = new ArrayList<>(20);
int orderNum = 1; int orderNum = 1;
Random random = new Random(); Random random = new Random();
@ -687,49 +688,51 @@ public class LessonService implements ILessonService {
} }
}); });
} }
//试卷定义 List<ExamDefinition> exams = iExamService.findEntities(lesson.getId());
if (CollectionUtils.isEmpty(examTrainings)) { if (CollectionUtils.isEmpty(exams)) {
return; //试卷定义
} if (CollectionUtils.isEmpty(examTrainings)) {
ExamDefinition examDefinition = new ExamDefinition(); return;
examDefinition.setLessonId(lesson.getId()); }
examDefinition.setName(lesson.getName() + "试卷"); ExamDefinition examDefinition = new ExamDefinition();
examDefinition.setDuration(1800); examDefinition.setLessonId(lesson.getId());
examDefinition.setCreatorId(userVO.getId()); examDefinition.setName(lesson.getName() + "试卷");
examDefinition.setCreateTime(LocalDateTime.now()); examDefinition.setDuration(1800);
examDefinition.setRemarks(examDefinition.getName() + "-默认试卷"); examDefinition.setCreatorId(userVO.getId());
examDefinition.setStatus("1"); examDefinition.setCreateTime(LocalDateTime.now());
examDefinition.setTrial(true); examDefinition.setRemarks(examDefinition.getName() + "-默认试卷");
//试卷规则 取20道题每中实训类型取一道 examDefinition.setStatus("1");
if (examTrainings.size() < 20) { examDefinition.setTrial(true);
examDefinition.setFullPoint(examTrainings.size() * 5); //试卷规则 取20道题每中实训类型取一道
examDefinition.setPassingPoint(Double.valueOf(examDefinition.getFullPoint() * 0.6).intValue()); if (examTrainings.size() < 20) {
examDefinitionDAO.insert(examDefinition); examDefinition.setFullPoint(examTrainings.size() * 5);
examTrainings.forEach(training -> { examDefinition.setPassingPoint(Double.valueOf(examDefinition.getFullPoint() * 0.6).intValue());
ExamDefinitionRules examRules = new ExamDefinitionRules(); examDefinitionDAO.insert(examDefinition);
examRules.setExamId(examDefinition.getId()); examTrainings.forEach(training -> {
examRules.setNum(1); ExamDefinitionRules examRules = new ExamDefinitionRules();
examRules.setPoint(5); examRules.setExamId(examDefinition.getId());
examRules.setTrainingType(training.getType()); examRules.setNum(1);
examRules.setOperateType(training.getOperateType()); examRules.setPoint(5);
definitionRulesDAO.insert(examRules); examRules.setTrainingType(training.getType());
}); examRules.setOperateType(training.getOperateType());
definitionRulesDAO.insert(examRules);
} else { });
examDefinition.setFullPoint(100); } else {
examDefinition.setPassingPoint(60); examDefinition.setFullPoint(100);
examDefinitionDAO.insert(examDefinition); examDefinition.setPassingPoint(60);
int i = 1; examDefinitionDAO.insert(examDefinition);
do { int i = 1;
ExamDefinitionRules examRules = new ExamDefinitionRules(); do {
examRules.setExamId(examDefinition.getId()); ExamDefinitionRules examRules = new ExamDefinitionRules();
examRules.setNum(1); examRules.setExamId(examDefinition.getId());
examRules.setPoint(5); examRules.setNum(1);
Training training = examTrainings.remove(random.nextInt(examTrainings.size())); examRules.setPoint(5);
examRules.setTrainingType(training.getType()); Training training = examTrainings.remove(random.nextInt(examTrainings.size()));
examRules.setOperateType(training.getOperateType()); examRules.setTrainingType(training.getType());
definitionRulesDAO.insert(examRules); examRules.setOperateType(training.getOperateType());
} while (i++ < 20); definitionRulesDAO.insert(examRules);
} while (i++ < 20);
}
} }
} }
} }