From 4c160a7bb3ed1222586c8dea8dec6b191b27b255 Mon Sep 17 00:00:00 2001 From: GoCo Date: Mon, 18 Aug 2025 11:49:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3=EF=BC=8C=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E9=80=BB=E8=BE=91=E8=A1=A5=E9=BD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../biz/controller/CourseBizController.java | 2 +- .../service/impl/CourseBizServiceImpl.java | 73 ++++++++++++++++++- 2 files changed, 71 insertions(+), 4 deletions(-) diff --git a/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/biz/controller/CourseBizController.java b/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/biz/controller/CourseBizController.java index 5b87ea71..bc24d465 100644 --- a/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/biz/controller/CourseBizController.java +++ b/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/biz/controller/CourseBizController.java @@ -43,7 +43,7 @@ public class CourseBizController { private ISysBaseAPI sysBaseApi; @GetMapping("/list") - @Operation(summary = "查询课程列表", description = "可根据分类、难度、专题进行检索,三个参数可任意传递其中之一、之二或全部,不传参则查询所有课程,携带讲师信息") + @Operation(summary = "查询课程列表", description = "可根据分类、难度、专题进行检索,三个参数可任意传递其中之一、之二或全部,每个参数可传递多个值,用英文逗号分割,不传参或传递all则查询所有课程,携带讲师信息") @IgnoreAuth public Result> queryCourseList( @RequestParam(value = "categoryId", required = false) String categoryId, diff --git a/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/biz/service/impl/CourseBizServiceImpl.java b/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/biz/service/impl/CourseBizServiceImpl.java index f1d71f93..d002e8cf 100644 --- a/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/biz/service/impl/CourseBizServiceImpl.java +++ b/jeecg-boot/jeecg-boot-module/jeecg-module-learn/src/main/java/org/jeecg/modules/biz/service/impl/CourseBizServiceImpl.java @@ -150,10 +150,77 @@ public class CourseBizServiceImpl extends ServiceImpl impl @Override public List getCourseList(String categoryId, String difficulty, String topic) { - // TODO GC 根据分类 专题进行查询 QueryWrapper 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 allCourseIds = new HashSet<>(); + + for (String catId : categoryIds) { + catId = catId.trim(); + if (!catId.isEmpty()) { + List 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 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 difficultyList = new ArrayList<>(); + for (String diff : difficulties) { + diff = diff.trim(); + if (!diff.isEmpty()) { + difficultyList.add(diff); + } + } + if (!difficultyList.isEmpty()) { + queryWrapper.in("difficulty", difficultyList); + } } List courseList = courseMapper.selectList(queryWrapper);