优化
This commit is contained in:
parent
a2751d7aa5
commit
7743ae7a01
@ -21,6 +21,12 @@ public interface CourseLessonService extends IService<CourseLesson> {
|
|||||||
*/
|
*/
|
||||||
CourseLesson findById(Long id);
|
CourseLesson findById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按 lessonType 查询包含该类型环节的课程 ID 列表
|
||||||
|
* 兼容多种存储格式:SOCIAL/SOCIETY/DOMAIN_SOCIAL、INTRODUCTION/INTRO 等
|
||||||
|
*/
|
||||||
|
List<Long> findCourseIdsByLessonType(String lessonType);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 按类型查询课程环节
|
* 按类型查询课程环节
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -14,7 +14,10 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 课程环节服务实现类
|
* 课程环节服务实现类
|
||||||
@ -59,6 +62,50 @@ public class CourseLessonServiceImpl extends ServiceImpl<CourseLessonMapper, Cou
|
|||||||
return lesson;
|
return lesson;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按 lessonType 查询包含该类型环节的课程 ID 列表
|
||||||
|
* 兼容多种存储格式:SOCIAL/SOCIETY/DOMAIN_SOCIAL、INTRODUCTION/INTRO 等
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<Long> findCourseIdsByLessonType(String lessonType) {
|
||||||
|
List<String> typesToMatch = resolveLessonTypeVariants(lessonType);
|
||||||
|
if (typesToMatch.isEmpty()) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
LambdaQueryWrapper<CourseLesson> wrapper = new LambdaQueryWrapper<CourseLesson>()
|
||||||
|
.select(CourseLesson::getCourseId);
|
||||||
|
if (typesToMatch.size() == 1) {
|
||||||
|
wrapper.eq(CourseLesson::getLessonType, typesToMatch.get(0));
|
||||||
|
} else {
|
||||||
|
wrapper.in(CourseLesson::getLessonType, typesToMatch);
|
||||||
|
}
|
||||||
|
return this.list(wrapper).stream()
|
||||||
|
.map(CourseLesson::getCourseId)
|
||||||
|
.distinct()
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将前端传入的 lessonType 解析为数据库中可能存储的多种格式
|
||||||
|
*/
|
||||||
|
private List<String> resolveLessonTypeVariants(String lessonType) {
|
||||||
|
if (lessonType == null || lessonType.isBlank()) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
return switch (lessonType.toUpperCase()) {
|
||||||
|
case "SOCIAL" -> Arrays.asList("SOCIAL", "SOCIETY", "DOMAIN_SOCIAL");
|
||||||
|
case "SOCIETY" -> Arrays.asList("SOCIAL", "SOCIETY", "DOMAIN_SOCIAL");
|
||||||
|
case "SCIENCE" -> Arrays.asList("SCIENCE", "DOMAIN_SCIENCE");
|
||||||
|
case "LANGUAGE" -> Arrays.asList("LANGUAGE", "DOMAIN_LANGUAGE");
|
||||||
|
case "HEALTH" -> Arrays.asList("HEALTH", "DOMAIN_HEALTH");
|
||||||
|
case "ART" -> Arrays.asList("ART", "DOMAIN_ART");
|
||||||
|
case "INTRODUCTION" -> Arrays.asList("INTRODUCTION", "INTRO");
|
||||||
|
case "INTRO" -> Arrays.asList("INTRODUCTION", "INTRO");
|
||||||
|
case "COLLECTIVE" -> Collections.singletonList("COLLECTIVE");
|
||||||
|
default -> Collections.singletonList(lessonType);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 按类型查询课程环节
|
* 按类型查询课程环节
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user