生成课程速度优化
This commit is contained in:
parent
91e23f39fc
commit
5d743425e5
@ -153,7 +153,7 @@ public class LessonService implements ILessonService {
|
||||
@Override
|
||||
@Transactional
|
||||
public void publish(LessonVO lessonVo, LessonPublishVO publishVO) {
|
||||
LessonVO publishedLesson = this.findByMapAndNameAndPrdType(publishVO.getMapId(), publishVO.getName(),publishVO.getPrdType());
|
||||
LessonVO publishedLesson = this.findByMapAndNameAndPrdType(publishVO.getMapId(), publishVO.getName(), publishVO.getPrdType());
|
||||
lessonVo.apply(publishVO);
|
||||
LsLesson newLesson = lessonVo.toPublic();
|
||||
newLesson.setUpdateTime(LocalDateTime.now());
|
||||
@ -163,7 +163,7 @@ public class LessonService implements ILessonService {
|
||||
newLesson.setId(null);
|
||||
this.lessonDAO.insert(newLesson);
|
||||
//存在班级条件就创建课程班级关系
|
||||
if(!CollectionUtils.isEmpty(publishVO.getClassIdList())){
|
||||
if (!CollectionUtils.isEmpty(publishVO.getClassIdList())) {
|
||||
addRelLessonClass(publishVO, newLesson.getId());
|
||||
}
|
||||
|
||||
@ -174,19 +174,19 @@ public class LessonService implements ILessonService {
|
||||
newLesson.setId(publishedLesson.getId());
|
||||
this.lessonDAO.updateByPrimaryKey(newLesson);
|
||||
//课程存在,预备检查与班级的关系
|
||||
if(!CollectionUtils.isEmpty(publishVO.getClassIdList())){
|
||||
if (!CollectionUtils.isEmpty(publishVO.getClassIdList())) {
|
||||
//目前GZB项目带班级发布
|
||||
StudentRelLessonClassExample relLessonClassExample = new StudentRelLessonClassExample();
|
||||
relLessonClassExample.createCriteria().andLessonIdEqualTo(publishedLesson.getId());
|
||||
List<StudentRelLessonClass> studentRelLessonClasses = this.studentRelLessonClassDAO.selectByExample(relLessonClassExample);
|
||||
if(!CollectionUtils.isEmpty(studentRelLessonClasses)){
|
||||
if (!CollectionUtils.isEmpty(studentRelLessonClasses)) {
|
||||
List<Integer> existedClassIds = studentRelLessonClasses.stream().map(StudentRelLessonClass::getClassId).collect(Collectors.toList());
|
||||
if(!existedClassIds.equals(publishVO.getClassIdList())){
|
||||
if (!existedClassIds.equals(publishVO.getClassIdList())) {
|
||||
//清除现有课程班级关系
|
||||
this.studentRelLessonClassDAO.deleteByExample(relLessonClassExample);
|
||||
addRelLessonClass(publishVO, publishedLesson.getId());
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
addRelLessonClass(publishVO, publishedLesson.getId());
|
||||
}
|
||||
}
|
||||
@ -199,7 +199,9 @@ public class LessonService implements ILessonService {
|
||||
this.saveChapterDetail(newLesson, lessonVo);
|
||||
}
|
||||
|
||||
/**增加课程班级关系*/
|
||||
/**
|
||||
* 增加课程班级关系
|
||||
*/
|
||||
private void addRelLessonClass(LessonPublishVO publishVO, Long id) {
|
||||
publishVO.getClassIdList().forEach(classId -> {
|
||||
StudentRelLessonClass relLessonClass = new StudentRelLessonClass();
|
||||
@ -410,7 +412,7 @@ public class LessonService implements ILessonService {
|
||||
@Transactional
|
||||
public void deleteUsedLesson(Long lessonId, UserVO userVO) {
|
||||
LsLesson lsLesson = this.lessonDAO.selectByPrimaryKey(lessonId);
|
||||
BusinessExceptionAssertEnum.INVALID_OPERATION.assertTrue(Objects.equals(userVO.getId(),lsLesson.getCreatorId()),
|
||||
BusinessExceptionAssertEnum.INVALID_OPERATION.assertTrue(Objects.equals(userVO.getId(), lsLesson.getCreatorId()),
|
||||
"不能删除他人创建的课程");
|
||||
lsLesson.setStatus(BusinessConsts.STATUS_NOT_USE);
|
||||
lessonDAO.updateByPrimaryKey(lsLesson);
|
||||
@ -579,8 +581,8 @@ public class LessonService implements ILessonService {
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void generateLessonAndExam(List<Long> mapIds, UserVO userVO){
|
||||
if(CollectionUtils.isEmpty(mapIds))return;
|
||||
public void generateLessonAndExam(List<Long> mapIds, UserVO userVO) {
|
||||
if (CollectionUtils.isEmpty(mapIds)) return;
|
||||
mapIds.parallelStream().forEach(mapId -> {
|
||||
MapVO mapVO = iMapService.findMapBaseInfoById(mapId);
|
||||
if (Objects.isNull(mapVO)) return;
|
||||
@ -652,9 +654,11 @@ 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())
|
||||
.stream().collect(Collectors.groupingBy(Training::getType, Collectors.groupingBy(Training::getOperateType)));
|
||||
for (BusinessConsts.Training.Type type : BusinessConsts.Training.Type.values()) {
|
||||
List<Training> trainings = iTrainingV1Service.queryTrainingsBy(mapVO.getId(), lesson.getPrdType(), type.name());
|
||||
if (CollectionUtils.isEmpty(trainings)) continue;
|
||||
Map<String, List<Training>> collect = trainings.get(type.name());
|
||||
if (CollectionUtils.isEmpty(collect)) continue;
|
||||
//章节
|
||||
LsLessonChapter chapter = new LsLessonChapter();
|
||||
chapter.setLessonId(lesson.getId());
|
||||
@ -663,26 +667,24 @@ public class LessonService implements ILessonService {
|
||||
chapter.setName(type.getDescription());
|
||||
chapter.setRemarks(chapter.getName() + "章节");
|
||||
lessonChapterDAO.insert(chapter);
|
||||
trainings.stream().collect(Collectors.groupingBy(Training::getOperateType)).forEach((s, ts) -> {
|
||||
examTrainings.add(ts.get(random.nextInt(ts.size())));
|
||||
int i = 1;
|
||||
while (i < 3) {
|
||||
//章节关联实训
|
||||
if (ts.size() == 0) return;
|
||||
Long trainId = ts.remove(random.nextInt(ts.size())).getId();
|
||||
LsRelChapterTraining chapterTraining = new LsRelChapterTraining();
|
||||
chapterTraining.setLessonId(lesson.getId());
|
||||
chapterTraining.setChapterId(chapter.getId());
|
||||
chapterTraining.setOrderNum(i++);
|
||||
chapterTraining.setTrainingId(trainId);
|
||||
chapterTraining.setTrial(true);
|
||||
relChapterTrainingDAO.insert(chapterTraining);
|
||||
}
|
||||
}
|
||||
);
|
||||
collect.forEach((s, ts) -> {
|
||||
if (ts.size() == 0) return;
|
||||
examTrainings.add(ts.get(random.nextInt(ts.size())));
|
||||
int i = 1;
|
||||
while (i < 3) {
|
||||
//章节关联实训
|
||||
Long trainId = ts.remove(random.nextInt(ts.size())).getId();
|
||||
LsRelChapterTraining chapterTraining = new LsRelChapterTraining();
|
||||
chapterTraining.setLessonId(lesson.getId());
|
||||
chapterTraining.setChapterId(chapter.getId());
|
||||
chapterTraining.setOrderNum(i++);
|
||||
chapterTraining.setTrainingId(trainId);
|
||||
chapterTraining.setTrial(true);
|
||||
relChapterTrainingDAO.insert(chapterTraining);
|
||||
}
|
||||
});
|
||||
}
|
||||
//试卷定义
|
||||
|
||||
if (CollectionUtils.isEmpty(examTrainings)) {
|
||||
return;
|
||||
}
|
||||
|
@ -181,4 +181,10 @@ public interface ITrainingV1Service {
|
||||
* 加载实训到仿真中
|
||||
*/
|
||||
TrainingNewVO loadTraining(String group, Long trainingId);
|
||||
|
||||
/**
|
||||
* 根据地图id查询实训
|
||||
* @return
|
||||
*/
|
||||
List<Training> findEntities(Long mapId);
|
||||
}
|
||||
|
@ -687,4 +687,11 @@ public class TrainingV1Service implements ITrainingV1Service {
|
||||
groupSimulationService.loadScenes(group, training.getScenes());
|
||||
return trainingVo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Training> findEntities(Long mapId) {
|
||||
TrainingExample example = new TrainingExample();
|
||||
example.createCriteria().andMapIdEqualTo(mapId);
|
||||
return trainingDAO.selectByExample(example);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user