diff --git a/yudao-module-education/src/main/java/cn/iocoder/yudao/module/education/dal/mysql/catalog/QuestionMapper.java b/yudao-module-education/src/main/java/cn/iocoder/yudao/module/education/dal/mysql/catalog/QuestionMapper.java index fb8efb12..74680745 100644 --- a/yudao-module-education/src/main/java/cn/iocoder/yudao/module/education/dal/mysql/catalog/QuestionMapper.java +++ b/yudao-module-education/src/main/java/cn/iocoder/yudao/module/education/dal/mysql/catalog/QuestionMapper.java @@ -47,6 +47,32 @@ public interface QuestionMapper extends BaseMapperX { @Param("tenantId") Long tenantId, @Param("nodeId") Long nodeId, @Param("type") String type, @Param("difficulty") String difficulty); + @Select(""" + + """) + IPage selectPublishedPageByAvailableCollection(IPage page, + @Param("tenantId") Long tenantId, @Param("collectionId") Long collectionId, + @Param("type") String type, @Param("difficulty") String difficulty); + default IPage selectPublishedPageByIds(IPage page, Long tenantId, List ids, String type, String difficulty) { if (ids == null || ids.isEmpty()) { diff --git a/yudao-module-education/src/main/java/cn/iocoder/yudao/module/education/service/catalog/provider/JavaCatalogProvider.java b/yudao-module-education/src/main/java/cn/iocoder/yudao/module/education/service/catalog/provider/JavaCatalogProvider.java index 688c7ae6..4f06195c 100644 --- a/yudao-module-education/src/main/java/cn/iocoder/yudao/module/education/service/catalog/provider/JavaCatalogProvider.java +++ b/yudao-module-education/src/main/java/cn/iocoder/yudao/module/education/service/catalog/provider/JavaCatalogProvider.java @@ -47,7 +47,6 @@ public class JavaCatalogProvider implements CatalogProvider, QuestionCatalogProv private final QuestionCollectionMapper questionCollectionMapper; private final QuestionMapper questionMapper; private final PracticeBlueprintMapper practiceBlueprintMapper; - private final QuestionCollectionQuestionMapper collectionQuestionMapper; public JavaCatalogProvider(EducationProperties properties, RegionMapper regionMapper, @@ -59,8 +58,7 @@ public class JavaCatalogProvider implements CatalogProvider, QuestionCatalogProv ContentNodeMapper contentNodeMapper, QuestionCollectionMapper questionCollectionMapper, QuestionMapper questionMapper, - PracticeBlueprintMapper practiceBlueprintMapper, - QuestionCollectionQuestionMapper collectionQuestionMapper) { + PracticeBlueprintMapper practiceBlueprintMapper) { this.properties = properties; this.regionMapper = regionMapper; this.schoolMapper = schoolMapper; @@ -72,7 +70,6 @@ public class JavaCatalogProvider implements CatalogProvider, QuestionCatalogProv this.questionCollectionMapper = questionCollectionMapper; this.questionMapper = questionMapper; this.practiceBlueprintMapper = practiceBlueprintMapper; - this.collectionQuestionMapper = collectionQuestionMapper; } @Override @@ -157,10 +154,9 @@ public class JavaCatalogProvider implements CatalogProvider, QuestionCatalogProv int pageNo, int pageSize) { Long cid = parseOptionalLong(collectionId); Long nid = parseOptionalLong(nodeId); int bounded = clampPageSize(pageSize); int page = pageNo > 0 ? pageNo : 1; - List ids = cid == null ? null : readWithExplicitCatalogScope(() -> collectionQuestionMapper.selectByCollectionId(tenantId(), cid)).stream() - .map(QuestionCollectionQuestionDO::getQuestionId).toList(); - IPage result = ids != null - ? readWithExplicitCatalogScope(() -> questionMapper.selectPublishedPageByIds(new Page<>(page, bounded), tenantId(), ids, type, difficulty)) + IPage result = cid != null + ? readWithExplicitCatalogScope(() -> questionMapper.selectPublishedPageByAvailableCollection( + new Page<>(page, bounded), tenantId(), cid, type, difficulty)) : nid != null ? readWithExplicitCatalogScope(() -> questionMapper.selectPublishedPageByAvailableNode( new Page<>(page, bounded), tenantId(), nid, type, difficulty)) @@ -172,9 +168,8 @@ public class JavaCatalogProvider implements CatalogProvider, QuestionCatalogProv @Override public CatalogQuestionPageResult listCollectionQuestions(String collectionId, String type, String difficulty, int pageNo, int pageSize) { Long cid = parseRequiredLong(collectionId); int page = pageNo > 0 ? pageNo : 1; - List ids = readWithExplicitCatalogScope(() -> collectionQuestionMapper.selectByCollectionId(tenantId(), cid)).stream() - .map(QuestionCollectionQuestionDO::getQuestionId).toList(); - IPage result = readWithExplicitCatalogScope(() -> questionMapper.selectPublishedPageByIds(new Page<>(page, clampPageSize(pageSize)), tenantId(), ids, type, difficulty)); + IPage result = readWithExplicitCatalogScope(() -> questionMapper.selectPublishedPageByAvailableCollection( + new Page<>(page, clampPageSize(pageSize)), tenantId(), cid, type, difficulty)); return buildPageResult(result); } @@ -234,10 +229,9 @@ public class JavaCatalogProvider implements CatalogProvider, QuestionCatalogProv } private long countVisibleCollectionQuestions(Long collectionId, String type, String difficulty) { - List ids = readWithExplicitCatalogScope(() -> collectionQuestionMapper - .selectByCollectionId(tenantId(), collectionId)).stream() - .map(QuestionCollectionQuestionDO::getQuestionId).toList(); - return readWithExplicitCatalogScope(() -> questionMapper.countPublishedByIds(tenantId(), ids, type, difficulty)); + IPage page = readWithExplicitCatalogScope(() -> questionMapper.selectPublishedPageByAvailableCollection( + new Page<>(1, 1), tenantId(), collectionId, type, difficulty)); + return page.getTotal(); } private long countVisibleNodeQuestions(Long nodeId, String type, String difficulty) {