diff --git a/src/main/java/club/joylink/rtss/services/ExamService.java b/src/main/java/club/joylink/rtss/services/ExamService.java index 721e37f20..3b6a271af 100644 --- a/src/main/java/club/joylink/rtss/services/ExamService.java +++ b/src/main/java/club/joylink/rtss/services/ExamService.java @@ -18,7 +18,6 @@ import com.github.pagehelper.PageHelper; import lombok.NonNull; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; @@ -104,53 +103,6 @@ public class ExamService implements IExamService { }); } - private void checkExam(ExamDefinitionVO examDefinitionVO) { - //一个课程下考试名称查重 - ExamDefinitionExample examDefinitionExample = new ExamDefinitionExample(); - examDefinitionExample.createCriteria().andLessonIdEqualTo(examDefinitionVO.getLessonId()).andNameEqualTo(examDefinitionVO.getName()); - List examDefinitionList = examDefinitionDAO.selectByExample(examDefinitionExample); - BusinessExceptionAssertEnum.DATA_UNIQUE_PROPERTY_REPEAT.assertCollectionEmpty(examDefinitionList); - //考试规则查重 - //查询已创建的考试规则数据 - int rulesNum = examDefinitionVO.getExamDefinitionRulesVOList().stream().map(ExamDefinitionRulesVO::getNum).reduce(Integer::sum).orElse(0); - List examIdList = examDefinitionDAO.selectByRulesNumAndFullPoint(rulesNum, examDefinitionVO.getFullPoint(), examDefinitionVO.getLessonId()); - if (!CollectionUtils.isEmpty(examIdList)) { - //处理待校验数据 - Map> trainingTypeMap = examDefinitionVO.getExamDefinitionRulesVOList() - .stream().collect(Collectors.groupingBy(ExamDefinitionRulesVO::getTrainingType)); - for (Long examId : examIdList) { - ExamDefinitionRulesExample examDefinitionRulesExample = new ExamDefinitionRulesExample(); - examDefinitionRulesExample.createCriteria().andExamIdEqualTo(examId); - List examDefinitionRulesList = definitionRulesDAO.selectByExample(examDefinitionRulesExample); - Map> existTrainingTypeMap = ExamDefinitionRulesVO.convert2VOList(examDefinitionRulesList) - .stream().collect(Collectors.groupingBy(ExamDefinitionRulesVO::getTrainingType)); - //检查dataMap和map数据是否一样 - trainingTypeLoop: - for (Entry> entry : trainingTypeMap.entrySet()) { - String trainingType = entry.getKey(); - // 校验实训类型 - if (null == existTrainingTypeMap.get(trainingType) || existTrainingTypeMap.get(trainingType).size() != entry.getValue().size()) { - break; - } - // 校验操作类型 - Map dataMap = entry.getValue().stream() - .collect(Collectors.toMap(ExamDefinitionRulesVO::getOperateType, Function.identity())); - Map map = existTrainingTypeMap.get(trainingType).stream() - .collect(Collectors.toMap(ExamDefinitionRulesVO::getOperateType, Function.identity())); - for (Entry en : dataMap.entrySet()) { - String operateType = en.getKey(); - if (null == map.get(operateType) || !en.getValue().equals(map.get(operateType))) { - break trainingTypeLoop; - } else { - rulesNum -= en.getValue().getNum(); - } - } - } - BusinessExceptionAssertEnum.DATA_UNIQUE_PROPERTY_REPEAT.assertNotTrue(0 == rulesNum); - } - } - } - /** * 确认名称唯一 * @@ -405,6 +357,30 @@ public class ExamService implements IExamService { return ExamDefinitionVO.convert(findEntities(mapId, prdType)); } + @Override + public void copy(Long fromMapId, Long toMapId, UserVO user) { + /* 拷贝考试定义 */ + List exams = findEntities(fromMapId, null); + Map old_new_examIdMap = new HashMap<>(); + exams.forEach(examDefinition -> { + Long oldId = examDefinition.getId(); + examDefinition.setId(null); + examDefinition.setMapId(toMapId); + examDefinition.setCreatorId(user.getId()); + examDefinition.setCreateTime(LocalDateTime.now()); + examDefinitionDAO.insert(examDefinition); + old_new_examIdMap.put(oldId, examDefinition.getId()); + }); + /* 拷贝考试规则 */ + ExamDefinitionRulesExample ruleExample = new ExamDefinitionRulesExample(); + ruleExample.createCriteria().andExamIdIn(new ArrayList<>(old_new_examIdMap.keySet())); + definitionRulesDAO.selectByExample(ruleExample).forEach(rule->{ + rule.setId(null); + rule.setExamId(old_new_examIdMap.get(rule.getExamId())); + definitionRulesDAO.insert(rule); + }); + } + @Override public void update(Long id, ExamDefinitionVO examDefinitionVO) { ExamDefinition examDefinition = this.examDefinitionDAO.selectByPrimaryKey(id); @@ -418,31 +394,6 @@ public class ExamService implements IExamService { this.examDefinitionDAO.updateByPrimaryKey(examDefinition); } - @Override - @Transactional - public void copy(Map lessonRelationMap, UserVO user) { - ArrayList lessonIdList = new ArrayList<>(lessonRelationMap.keySet()); - List examList = findEntityByLessonIdList(lessonIdList); - for (ExamDefinition exam : examList) { - //因为考试定义的id要变,先将考试规则查出来 - ExamDefinitionRulesExample rulesExample = new ExamDefinitionRulesExample(); - rulesExample.createCriteria() - .andExamIdEqualTo(exam.getId()); - List rulesList = examDefinitionRulesDAO.selectByExample(rulesExample); - //拷贝考试定义 - exam.setLessonId(lessonRelationMap.get(exam.getLessonId())); - exam.setCreatorId(user.getId()); - exam.setCreateTime(LocalDateTime.now()); - exam.setId(null); - examDefinitionDAO.insertSelective(exam); - for (ExamDefinitionRules rules : rulesList) { - rules.setId(null); - rules.setExamId(exam.getId()); - examDefinitionRulesDAO.insertSelective(rules); - } - } - } - @Override public List findEntities(Long lessonId) { ExamDefinitionExample example = new ExamDefinitionExample(); diff --git a/src/main/java/club/joylink/rtss/services/IExamService.java b/src/main/java/club/joylink/rtss/services/IExamService.java index 78130a34e..7e415a626 100644 --- a/src/main/java/club/joylink/rtss/services/IExamService.java +++ b/src/main/java/club/joylink/rtss/services/IExamService.java @@ -7,6 +7,7 @@ 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 org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.Map; @@ -67,8 +68,6 @@ public interface IExamService { */ void update(Long id, ExamDefinitionVO examDefinitionVO); - void copy(Map lessonRelationMap, UserVO user); - /** * 根据课程id查询考试 */ @@ -94,4 +93,7 @@ public interface IExamService { List findEntities(List examIds); List queryBasicInfo(Long mapId, String prdType); + + @Transactional + void copy(Long fromMapId, Long toMapId, UserVO user); } diff --git a/src/main/java/club/joylink/rtss/services/LessonService.java b/src/main/java/club/joylink/rtss/services/LessonService.java index ef78d2270..4d7e02880 100644 --- a/src/main/java/club/joylink/rtss/services/LessonService.java +++ b/src/main/java/club/joylink/rtss/services/LessonService.java @@ -641,17 +641,18 @@ public class LessonService implements ILessonService { } private void generateLessonBy(UserVO userVO, MapVO mapVO, BusinessConsts.Lesson.PrdInfo prdLessonInfo, String prdType) { + Long mapId = mapVO.getId(); //课程 LsLesson lesson = new LsLesson(); lesson.setUpdateTime(LocalDateTime.now()); lesson.setStatus(BusinessConsts.STATUS_USE); lesson.setCreatorId(userVO.getId()); - lesson.setMapId(mapVO.getId()); + lesson.setMapId(mapId); lesson.setName(String.join("-", mapVO.getName(), prdLessonInfo.getName())); lesson.setPrdType(prdType); lesson.setRemarks(prdLessonInfo.getRemarks()); lesson.setSysfault(true); - LessonVO existedDefaultLesson = this.findSysFaultByMapAndPrdType(mapVO.getId(), prdType); + LessonVO existedDefaultLesson = this.findSysFaultByMapAndPrdType(mapId, prdType); if (Objects.nonNull(existedDefaultLesson)) { lesson.setId(existedDefaultLesson.getId()); lessonDAO.updateByPrimaryKey(lesson); @@ -694,7 +695,7 @@ public class LessonService implements ILessonService { List examTrainings = new ArrayList<>(20); int orderNum = 1; Random random = new Random(); - Map>> trainings = iTrainingV1Service.findEntities(mapVO.getId(), prdType) + Map>> trainings = iTrainingV1Service.findEntities(mapId, prdType) .stream().collect(Collectors.groupingBy(Training::getType, Collectors.groupingBy(Training::getOperateType))); for (BusinessConsts.Training.Type type : BusinessConsts.Training.Type.values()) { Map> collect = trainings.get(type.name()); @@ -731,7 +732,9 @@ public class LessonService implements ILessonService { return; } ExamDefinition examDefinition = new ExamDefinition(); + examDefinition.setMapId(mapId); examDefinition.setLessonId(lesson.getId()); + examDefinition.setType(prdType); examDefinition.setName(lesson.getName() + "试卷"); examDefinition.setDuration(1800); examDefinition.setCreatorId(userVO.getId()); diff --git a/src/main/java/club/joylink/rtss/services/MapService.java b/src/main/java/club/joylink/rtss/services/MapService.java index 2d14a0936..7e8bc436e 100644 --- a/src/main/java/club/joylink/rtss/services/MapService.java +++ b/src/main/java/club/joylink/rtss/services/MapService.java @@ -645,10 +645,8 @@ public class MapService implements IMapService { .copyAllOfMapAndPrd(id, mapNewVO.getId()); //拷贝课程 Map lessonRelationMap = iLessonService.copy(id, mapNewVO.getId(), relMap, user); - if (!CollectionUtils.isEmpty(lessonRelationMap)) { - //拷贝考试 - iExamService.copy(lessonRelationMap, user); - } + //拷贝考试 + iExamService.copy(id, mapNewVO.getId(), user); //拷贝system this.iMapSystemService.copyOfMap(id, mapNewVO.getId()); // //拷贝剧本