《实训生成时,未根据prdType筛选》bug修改(考试开始的bug同时消除);开始考试效率优化

This commit is contained in:
joylink_zhangsai 2020-11-30 17:12:54 +08:00
parent bbeaa73c14
commit 5eddc4d8e0
4 changed files with 27 additions and 25 deletions

View File

@ -71,6 +71,9 @@ public class LessonService implements ILessonService {
@Autowired
private StudentRelLessonClassDAO studentRelLessonClassDAO;
@Autowired
private IExamService iExamService;
@Override
public LessonTreeVO getLessonTree(Long id, UserVO userVO) {
LessonTreeVO lessonTreeVO = new LessonTreeVO();
@ -616,7 +619,7 @@ public class LessonService implements ILessonService {
if (Objects.nonNull(existedDefaultLesson)) {
lesson.setId(existedDefaultLesson.getId());
lessonDAO.updateByPrimaryKey(lesson);
//存在默认课程删除旧版本章节及关联实训数据
//存在默认课程删除旧版本章节考试及关联实训数据
LsLessonVersionExample versionExample = new LsLessonVersionExample();
versionExample.createCriteria().andLessonIdEqualTo(existedDefaultLesson.getId());
lessonVersionDAO.deleteByExample(versionExample);
@ -654,7 +657,7 @@ public class LessonService implements ILessonService {
List<Training> examTrainings = new ArrayList<>(20);
int orderNum = 1;
Random random = new Random();
Map<String, Map<String, List<Training>>> trainings = iTrainingV1Service.findEntities(mapVO.getId())
Map<String, Map<String, List<Training>>> trainings = iTrainingV1Service.findEntities(mapVO.getId(), prdType)
.stream().collect(Collectors.groupingBy(Training::getType, Collectors.groupingBy(Training::getOperateType)));
for (BusinessConsts.Training.Type type : BusinessConsts.Training.Type.values()) {
Map<String, List<Training>> collect = trainings.get(type.name());

View File

@ -51,9 +51,6 @@ public class UserExamService implements IUserExamService {
@Autowired
private LsLessonDAO lessonDAO;
@Autowired
private ISysUserService iSysUserService;
@Override
@Transactional
public UserExamVO generateExamInstance(long examId, UserVO userVO) {
@ -73,7 +70,7 @@ public class UserExamService implements IUserExamService {
// 判断是否在考试时间之内
if (examDef.getStartTime() != null) {
LocalDateTime now = LocalDateTime.now();
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertTrue(now.isAfter(examDef.getStartTime())&&now.isBefore(examDef.getEndTime()));
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertTrue(now.isAfter(examDef.getStartTime()) && now.isBefore(examDef.getEndTime()));
}
// 保存用户考试信息
UserExam userExam = new UserExam();
@ -89,28 +86,30 @@ public class UserExamService implements IUserExamService {
ruleExample.createCriteria().andExamIdEqualTo(examId);
List<ExamDefinitionRules> rules = this.examDefinitionRulesDAO.selectByExample(ruleExample);
BusinessExceptionAssertEnum.DATA_ERROR.assertCollectionNotEmpty(rules);
//确认课程存在
LsLesson lesson = this.lessonDAO.selectByPrimaryKey(examDef.getLessonId());
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(lesson);
//查询实训生成试卷
Map<String, Map<String, List<Training>>> trainings = iTrainingService.findEntities(lesson.getMapId(), lesson.getPrdType())
.stream().collect(Collectors.groupingBy(Training::getType, Collectors.groupingBy(Training::getOperateType)));
for (ExamDefinitionRules rule : rules) {
// 根据课程所属产品的编码和规则中实训类型查找实训
LsLesson lesson = this.lessonDAO.selectByPrimaryKey(examDef.getLessonId());
BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertNotNull(lesson);
TrainingExample te = new TrainingExample();
TrainingExample.Criteria criteria = te.createCriteria()
.andMapIdEqualTo(lesson.getMapId())
.andPrdTypeEqualTo(lesson.getPrdType())
.andTypeEqualTo(rule.getTrainingType());
List<Training> collect;
if (StringUtils.hasText(rule.getOperateType())) {
criteria.andOperateTypeEqualTo(rule.getOperateType());
collect = trainings.get(rule.getTrainingType()).get(rule.getOperateType());
} else {
collect = new ArrayList<>();
for (List<Training> value : trainings.get(rule.getTrainingType()).values()) {
collect.addAll(value);
}
}
// 符合生成规则的实训
List<Training> trainings = this.trainingDAO.selectByExample(te);
BusinessExceptionAssertEnum.DATA_ERROR.assertTrue(trainings.size() > rule.getNum());
BusinessExceptionAssertEnum.DATA_ERROR.assertTrue(collect.size() > rule.getNum());
// 随机生成考试并保存
boolean flag = true;
List<UserExamQuestionsVO> questionsVOs = new ArrayList<>();
while (flag) {
Random random = new Random();
int i = random.nextInt(trainings.size());
Long trainId = trainings.get(i).getId();
int i = random.nextInt(collect.size());
Long trainId = collect.get(i).getId();
// 保存考试题目
UserExamQuestions questions = new UserExamQuestions();
questions.setPoint(rule.getPoint());
@ -121,10 +120,10 @@ public class UserExamService implements IUserExamService {
this.userExamQuestionsMapper.insert(questions);
// 返回考试题目
UserExamQuestionsVO userExamQuestionsVO = new UserExamQuestionsVO(questions);
userExamQuestionsVO.setTrainingName(trainings.get(i).getName());
userExamQuestionsVO.setTrainingName(collect.get(i).getName());
questionsVOs.add(userExamQuestionsVO);
// 从集合中剔除已使用实训
trainings.remove(i);
collect.remove(i);
if (questionsVOs.size() == rule.getNum()) {
flag = false;
}

View File

@ -186,5 +186,5 @@ public interface ITrainingV1Service {
* 根据地图id查询实训
* @return
*/
List<Training> findEntities(Long mapId);
List<Training> findEntities(Long mapId, String prdType);
}

View File

@ -689,9 +689,9 @@ public class TrainingV1Service implements ITrainingV1Service {
}
@Override
public List<Training> findEntities(Long mapId) {
public List<Training> findEntities(Long mapId, String prdType) {
TrainingExample example = new TrainingExample();
example.createCriteria().andMapIdEqualTo(mapId);
example.createCriteria().andMapIdEqualTo(mapId).andPrdTypeEqualTo(prdType);
return trainingDAO.selectByExample(example);
}
}