|
@@ -852,22 +852,10 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
|
|
|
List<SubjectGroup> subjectGroupList = subjectGroupMapper.selectList(new LambdaQueryWrapper<>());
|
|
|
Map<String, Long> subjectGroupNameAndIdMap = subjectGroupList.stream().collect(Collectors.toMap(SubjectGroup::getGroupName, SubjectGroup::getId, (k1, k2) -> k1));
|
|
|
|
|
|
- //使用年级
|
|
|
- List<BaseGrade> baseGradeList = baseGradeMapper.selectList(new LambdaQueryWrapper<>());
|
|
|
- Map<String, Long> baseGradeNameAndIdMap = baseGradeList.stream().collect(Collectors.toMap(BaseGrade::getName, BaseGrade::getId, (k1, k2) -> k1));
|
|
|
-
|
|
|
- //使用班级
|
|
|
- List<BaseClass> baseClassList = baseClassService.list();
|
|
|
- Map<String, Long> baseClassNameAndIdMap = baseClassList.stream().collect(Collectors.toMap(BaseClass::getName, BaseClass::getId, (k1, k2) -> k1));
|
|
|
-
|
|
|
//使用课程
|
|
|
List<BaseCourseSubject> baseCourseSubjectList = baseCourseSubjectMapper.selectList(new LambdaQueryWrapper<>());
|
|
|
Map<String, Long> baseCourseSubjectNameAndIdMap = baseCourseSubjectList.stream().collect(Collectors.toMap(BaseCourseSubject::getName, BaseCourseSubject::getId, (k1, k2) -> k1));
|
|
|
|
|
|
- //使用学期
|
|
|
- List<BaseSemester> baseSemesterList = baseSemesterMapper.selectList(new LambdaQueryWrapper<>());
|
|
|
- Map<String, Long> baseSemesterNameAndIdMap = baseSemesterList.stream().collect(Collectors.toMap(BaseSemester::getName, BaseSemester::getId, (k1, k2) -> k1));
|
|
|
-
|
|
|
//批量插入或更新数据
|
|
|
for (TextbookImportDto textbookImportDto : dataList) {
|
|
|
TextbookCoreAttribute textbookCoreAttribute = new TextbookCoreAttribute();
|
|
@@ -890,13 +878,6 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
|
|
|
.orElse(null);
|
|
|
textbook.setCourseSubjectId(courseSubjectId);
|
|
|
|
|
|
- // 处理年级映射
|
|
|
- String useGrade = textbookImportDto.getUseGrade();
|
|
|
- Long gradeId = Optional.ofNullable(useGrade)
|
|
|
- .map(baseGradeNameAndIdMap::get)
|
|
|
- .orElse(null);
|
|
|
- textbook.setGradeId(gradeId);
|
|
|
-
|
|
|
// 处理是否教材计划字段
|
|
|
String isTextbookPlanCn = textbookImportDto.getIsTextbookPlanCn();
|
|
|
String isTextbookPlan = Optional.ofNullable(isTextbookPlanCn)
|
|
@@ -912,69 +893,25 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
|
|
|
.orElse(null);
|
|
|
textbook.setTextbookType(textbookTypeCode);
|
|
|
|
|
|
- // 处理学期映射
|
|
|
- String useSemester = textbookImportDto.getUseSemester();
|
|
|
- Long baseSemesterId = Optional.ofNullable(useSemester)
|
|
|
- .map(baseSemesterNameAndIdMap::get)
|
|
|
- .orElse(null);
|
|
|
- textbook.setBaseSemesterId(baseSemesterId);
|
|
|
-
|
|
|
- // 处理班级映射
|
|
|
- List<Long> classIdList = Optional.ofNullable(textbookImportDto.getUseClass())
|
|
|
- .map(classNames -> Arrays.stream(classNames.split(","))
|
|
|
- .map(String::trim)
|
|
|
- .map(baseClassNameAndIdMap::get)
|
|
|
- .filter(Objects::nonNull)
|
|
|
- .collect(Collectors.toList()))
|
|
|
- .orElse(Collections.emptyList());
|
|
|
-
|
|
|
-
|
|
|
// 判断导入的教材是否已经存在,根据教材的 ISBN 码和使用的学期判断
|
|
|
LambdaQueryWrapper<Textbook> textbookLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
textbookLambdaQueryWrapper
|
|
|
.eq(Textbook::getIssn, textbook.getIssn())
|
|
|
- .eq(Textbook::getBaseSemesterId, textbook.getBaseSemesterId())
|
|
|
;
|
|
|
|
|
|
Textbook oldTextbook = this.getOne(textbookLambdaQueryWrapper);
|
|
|
|
|
|
-
|
|
|
-
|
|
|
// 已经存在,更新数据
|
|
|
if (oldTextbook != null) {
|
|
|
// 更新教材数据
|
|
|
+ textbook.setId(oldTextbook.getId());
|
|
|
textbookTextbookMapper.updateById(textbook);
|
|
|
-
|
|
|
- // 先删除使用班级的信息,再新增
|
|
|
- LambdaQueryWrapper<TextbookClassRelation> textbookClassRelationLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
- textbookClassRelationLambdaQueryWrapper
|
|
|
- .eq(TextbookClassRelation::getTextbookId, textbook.getId());
|
|
|
-
|
|
|
- textbookTextbookClassRelationMapper.delete(textbookClassRelationLambdaQueryWrapper);
|
|
|
-
|
|
|
- // 批量插入班级关系
|
|
|
- for (Long classId : classIdList) {
|
|
|
- textbookTextbookClassRelationMapper.insert(new TextbookClassRelation() {{
|
|
|
- setCreateDate(new Date());
|
|
|
- setTextbookId(textbook.getId());
|
|
|
- setClassId(classId);
|
|
|
- }});
|
|
|
- }
|
|
|
} else {
|
|
|
textbookCoreAttributeService.save(textbookCoreAttribute);
|
|
|
|
|
|
textbook.setTextbookCoreAttributeId(textbookCoreAttribute.getId());
|
|
|
// 插入教材数据
|
|
|
textbookTextbookMapper.insert(textbook);
|
|
|
-
|
|
|
- //插入班级和教材关系
|
|
|
- for (Long classId : classIdList) {
|
|
|
- textbookTextbookClassRelationMapper.insert(new TextbookClassRelation() {{
|
|
|
- setCreateDate(new Date());
|
|
|
- setTextbookId(textbook.getId());
|
|
|
- setClassId(classId);
|
|
|
- }});
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
}
|