feat: 🎸 课程列表接口,参数查询逻辑补齐
This commit is contained in:
parent
d2b61c6d95
commit
4c160a7bb3
@ -43,7 +43,7 @@ public class CourseBizController {
|
|||||||
private ISysBaseAPI sysBaseApi;
|
private ISysBaseAPI sysBaseApi;
|
||||||
|
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
@Operation(summary = "查询课程列表", description = "可根据分类、难度、专题进行检索,三个参数可任意传递其中之一、之二或全部,不传参则查询所有课程,携带讲师信息")
|
@Operation(summary = "查询课程列表", description = "可根据分类、难度、专题进行检索,三个参数可任意传递其中之一、之二或全部,每个参数可传递多个值,用英文逗号分割,不传参或传递all则查询所有课程,携带讲师信息")
|
||||||
@IgnoreAuth
|
@IgnoreAuth
|
||||||
public Result<List<CourseWithTeacherInfo>> queryCourseList(
|
public Result<List<CourseWithTeacherInfo>> queryCourseList(
|
||||||
@RequestParam(value = "categoryId", required = false) String categoryId,
|
@RequestParam(value = "categoryId", required = false) String categoryId,
|
||||||
|
@ -150,10 +150,77 @@ public class CourseBizServiceImpl extends ServiceImpl<CourseMapper, Course> impl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<CourseWithTeacherInfo> getCourseList(String categoryId, String difficulty, String topic) {
|
public List<CourseWithTeacherInfo> getCourseList(String categoryId, String difficulty, String topic) {
|
||||||
// TODO GC 根据分类 专题进行查询
|
|
||||||
QueryWrapper<Course> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<Course> queryWrapper = new QueryWrapper<>();
|
||||||
if (difficulty != null && difficulty.trim().length() > 0) {
|
|
||||||
queryWrapper.eq("difficulty", difficulty);
|
// 根据分类查询 - 支持多个分类ID,用逗号分隔
|
||||||
|
if (!"all".equals(categoryId) && categoryId != null) {
|
||||||
|
String[] categoryIds = categoryId.split(",");
|
||||||
|
Set<String> allCourseIds = new HashSet<>();
|
||||||
|
|
||||||
|
for (String catId : categoryIds) {
|
||||||
|
catId = catId.trim();
|
||||||
|
if (!catId.isEmpty()) {
|
||||||
|
List<String> courseIds = entityLinkBizService.listTargetIds(
|
||||||
|
EntityLinkConst.SourceType.COURSE_CATEGORY, catId, EntityLinkConst.TargetType.COURSE);
|
||||||
|
allCourseIds.addAll(courseIds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!allCourseIds.isEmpty()) {
|
||||||
|
queryWrapper.in("id", allCourseIds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据专题查询 - 支持多个专题值,用逗号分隔
|
||||||
|
if (!"all".equals(topic) && topic != null) {
|
||||||
|
String[] topics = topic.split(",");
|
||||||
|
List<String> validTopics = new ArrayList<>();
|
||||||
|
for (String topicValue : topics) {
|
||||||
|
topicValue = topicValue.trim();
|
||||||
|
if (!topicValue.isEmpty()) {
|
||||||
|
validTopics.add(topicValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!validTopics.isEmpty()) {
|
||||||
|
queryWrapper.and(wrapper -> {
|
||||||
|
for (int i = 0; i < validTopics.size(); i++) {
|
||||||
|
String topicValue = validTopics.get(i);
|
||||||
|
if (i == 0) {
|
||||||
|
// 第一个条件,直接开始
|
||||||
|
wrapper.and(subWrapper -> {
|
||||||
|
subWrapper.like("subject", topicValue + ",") // 开头匹配
|
||||||
|
.or().like("subject", "," + topicValue + ",") // 中间匹配
|
||||||
|
.or().like("subject", "," + topicValue) // 结尾匹配
|
||||||
|
.or().eq("subject", topicValue); // 单独匹配
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// 后续条件用OR连接,表示任一专题匹配即可
|
||||||
|
wrapper.or(subWrapper -> {
|
||||||
|
subWrapper.like("subject", topicValue + ",") // 开头匹配
|
||||||
|
.or().like("subject", "," + topicValue + ",") // 中间匹配
|
||||||
|
.or().like("subject", "," + topicValue) // 结尾匹配
|
||||||
|
.or().eq("subject", topicValue); // 单独匹配
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根据难度查询 - 支持多个难度值,用逗号分隔
|
||||||
|
if (!"all".equals(difficulty) && difficulty != null) {
|
||||||
|
String[] difficulties = difficulty.split(",");
|
||||||
|
List<String> difficultyList = new ArrayList<>();
|
||||||
|
for (String diff : difficulties) {
|
||||||
|
diff = diff.trim();
|
||||||
|
if (!diff.isEmpty()) {
|
||||||
|
difficultyList.add(diff);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!difficultyList.isEmpty()) {
|
||||||
|
queryWrapper.in("difficulty", difficultyList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
List<Course> courseList = courseMapper.selectList(queryWrapper);
|
List<Course> courseList = courseMapper.selectList(queryWrapper);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user