拷贝地图功能中,拷贝考试逻辑修改
This commit is contained in:
parent
d3c9626947
commit
038f3b3ecd
@ -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<ExamDefinition> 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<Long> examIdList = examDefinitionDAO.selectByRulesNumAndFullPoint(rulesNum, examDefinitionVO.getFullPoint(), examDefinitionVO.getLessonId());
|
||||
if (!CollectionUtils.isEmpty(examIdList)) {
|
||||
//处理待校验数据
|
||||
Map<String, List<ExamDefinitionRulesVO>> trainingTypeMap = examDefinitionVO.getExamDefinitionRulesVOList()
|
||||
.stream().collect(Collectors.groupingBy(ExamDefinitionRulesVO::getTrainingType));
|
||||
for (Long examId : examIdList) {
|
||||
ExamDefinitionRulesExample examDefinitionRulesExample = new ExamDefinitionRulesExample();
|
||||
examDefinitionRulesExample.createCriteria().andExamIdEqualTo(examId);
|
||||
List<ExamDefinitionRules> examDefinitionRulesList = definitionRulesDAO.selectByExample(examDefinitionRulesExample);
|
||||
Map<String, List<ExamDefinitionRulesVO>> existTrainingTypeMap = ExamDefinitionRulesVO.convert2VOList(examDefinitionRulesList)
|
||||
.stream().collect(Collectors.groupingBy(ExamDefinitionRulesVO::getTrainingType));
|
||||
//检查dataMap和map数据是否一样
|
||||
trainingTypeLoop:
|
||||
for (Entry<String, List<ExamDefinitionRulesVO>> entry : trainingTypeMap.entrySet()) {
|
||||
String trainingType = entry.getKey();
|
||||
// 校验实训类型
|
||||
if (null == existTrainingTypeMap.get(trainingType) || existTrainingTypeMap.get(trainingType).size() != entry.getValue().size()) {
|
||||
break;
|
||||
}
|
||||
// 校验操作类型
|
||||
Map<String, ExamDefinitionRulesVO> dataMap = entry.getValue().stream()
|
||||
.collect(Collectors.toMap(ExamDefinitionRulesVO::getOperateType, Function.identity()));
|
||||
Map<String, ExamDefinitionRulesVO> map = existTrainingTypeMap.get(trainingType).stream()
|
||||
.collect(Collectors.toMap(ExamDefinitionRulesVO::getOperateType, Function.identity()));
|
||||
for (Entry<String, ExamDefinitionRulesVO> 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<ExamDefinition> exams = findEntities(fromMapId, null);
|
||||
Map<Long, Long> 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<Long, Long> lessonRelationMap, UserVO user) {
|
||||
ArrayList<Long> lessonIdList = new ArrayList<>(lessonRelationMap.keySet());
|
||||
List<ExamDefinition> examList = findEntityByLessonIdList(lessonIdList);
|
||||
for (ExamDefinition exam : examList) {
|
||||
//因为考试定义的id要变,先将考试规则查出来
|
||||
ExamDefinitionRulesExample rulesExample = new ExamDefinitionRulesExample();
|
||||
rulesExample.createCriteria()
|
||||
.andExamIdEqualTo(exam.getId());
|
||||
List<ExamDefinitionRules> 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<ExamDefinition> findEntities(Long lessonId) {
|
||||
ExamDefinitionExample example = new ExamDefinitionExample();
|
||||
|
@ -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<Long, Long> lessonRelationMap, UserVO user);
|
||||
|
||||
/**
|
||||
* 根据课程id查询考试
|
||||
*/
|
||||
@ -94,4 +93,7 @@ public interface IExamService {
|
||||
List<ExamDefinition> findEntities(List<Long> examIds);
|
||||
|
||||
List<ExamDefinitionVO> queryBasicInfo(Long mapId, String prdType);
|
||||
|
||||
@Transactional
|
||||
void copy(Long fromMapId, Long toMapId, UserVO user);
|
||||
}
|
||||
|
@ -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<Training> examTrainings = new ArrayList<>(20);
|
||||
int orderNum = 1;
|
||||
Random random = new Random();
|
||||
Map<String, Map<String, List<Training>>> trainings = iTrainingV1Service.findEntities(mapVO.getId(), prdType)
|
||||
Map<String, Map<String, List<Training>>> 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<String, List<Training>> 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());
|
||||
|
@ -645,10 +645,8 @@ public class MapService implements IMapService {
|
||||
.copyAllOfMapAndPrd(id, mapNewVO.getId());
|
||||
//拷贝课程
|
||||
Map<Long, Long> 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());
|
||||
// //拷贝剧本
|
||||
|
Loading…
Reference in New Issue
Block a user