From 000497f2d44b6e52cb1d09abb0e679adf0652c68 Mon Sep 17 00:00:00 2001 From: Github_lizhw <171332584@qq.com> Date: Sun, 15 Mar 2026 19:29:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E7=BA=BFh5=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/controller/H5ComponentController.java | 21 +++----- .../dto/query/H5ComponentPageQueryDTO.java | 53 +++++++++++++++++++ .../luban/api/service/H5ComponentService.java | 12 +---- .../service/impl/H5ComponentServiceImpl.java | 21 ++++---- 4 files changed, 72 insertions(+), 35 deletions(-) create mode 100644 ruoyi-site/ruoyi-h5/src/main/java/com/luban/api/dto/query/H5ComponentPageQueryDTO.java diff --git a/ruoyi-site/ruoyi-h5/src/main/java/com/luban/api/controller/H5ComponentController.java b/ruoyi-site/ruoyi-h5/src/main/java/com/luban/api/controller/H5ComponentController.java index 8e6dcee06..227660886 100644 --- a/ruoyi-site/ruoyi-h5/src/main/java/com/luban/api/controller/H5ComponentController.java +++ b/ruoyi-site/ruoyi-h5/src/main/java/com/luban/api/controller/H5ComponentController.java @@ -3,17 +3,15 @@ package com.luban.api.controller; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.luban.api.dto.H5ComponentDTO; -import com.luban.api.entity.H5Component; +import com.luban.api.dto.query.H5ComponentPageQueryDTO; import com.luban.api.service.H5ComponentService; import com.luban.api.vo.H5ComponentVO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.RequiredArgsConstructor; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; import java.util.List; import java.util.Map; @@ -41,15 +39,8 @@ public class H5ComponentController { @Operation(summary = "分页查询组件列表") @GetMapping("/page") - public Page getPage( - @Parameter(description = "页码", required = true) @RequestParam Integer page, - @Parameter(description = "每页大小", required = true) @RequestParam Integer pageSize, - @Parameter(description = "组件类型") @RequestParam(required = false) String type, - @Parameter(description = "搜索关键词") @RequestParam(required = false) String keyword, - @Parameter(description = "分类 ID") @RequestParam(required = false) Long categoryId, - @Parameter(description = "标签 ID") @RequestParam(required = false) Long tagId) { - - return h5ComponentService.getPage(page, pageSize, type, keyword, categoryId, tagId); + public Page getPage(@Valid H5ComponentPageQueryDTO queryDTO) { + return h5ComponentService.getPage(queryDTO); } @Operation(summary = "查询指定分类下排行前几的组件") @@ -114,4 +105,4 @@ public class H5ComponentController { return h5ComponentService.getHotComponents(type, limit); } -} +} \ No newline at end of file diff --git a/ruoyi-site/ruoyi-h5/src/main/java/com/luban/api/dto/query/H5ComponentPageQueryDTO.java b/ruoyi-site/ruoyi-h5/src/main/java/com/luban/api/dto/query/H5ComponentPageQueryDTO.java new file mode 100644 index 000000000..732aa39a1 --- /dev/null +++ b/ruoyi-site/ruoyi-h5/src/main/java/com/luban/api/dto/query/H5ComponentPageQueryDTO.java @@ -0,0 +1,53 @@ +package com.luban.api.dto.query; + +import io.swagger.v3.oas.annotations.Parameter; +import jakarta.validation.constraints.NotNull; +import lombok.Data; + +/** + * H5 组件分页查询 DTO + * + * @author system + * @since 2026-03-15 + */ +@Data +public class H5ComponentPageQueryDTO { + + /** + * 页码 + */ + @Parameter(description = "页码", required = true) + @NotNull(message = "页码不能为空") + private Integer page; + + /** + * 每页大小 + */ + @Parameter(description = "每页大小", required = true) + @NotNull(message = "每页大小不能为空") + private Integer pageSize; + + /** + * 组件类型 (text/image/form/map/background/music) + */ + @Parameter(description = "组件类型 (text/image/form/map/background/music)") + private String type; + + /** + * 搜索关键词(支持名称和描述模糊搜索) + */ + @Parameter(description = "搜索关键词") + private String keyword; + + /** + * 分类 ID(包含所有子分类) + */ + @Parameter(description = "分类 ID(包含所有子分类)") + private Long categoryId; + + /** + * 标签 ID + */ + @Parameter(description = "标签 ID") + private Long tagId; +} \ No newline at end of file diff --git a/ruoyi-site/ruoyi-h5/src/main/java/com/luban/api/service/H5ComponentService.java b/ruoyi-site/ruoyi-h5/src/main/java/com/luban/api/service/H5ComponentService.java index 5da4bb1ec..6c9daed56 100644 --- a/ruoyi-site/ruoyi-h5/src/main/java/com/luban/api/service/H5ComponentService.java +++ b/ruoyi-site/ruoyi-h5/src/main/java/com/luban/api/service/H5ComponentService.java @@ -2,7 +2,7 @@ package com.luban.api.service; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.luban.api.dto.H5ComponentDTO; -import com.luban.api.entity.H5Component; +import com.luban.api.dto.query.H5ComponentPageQueryDTO; import com.luban.api.vo.H5ComponentVO; import java.util.List; @@ -26,16 +26,8 @@ public interface H5ComponentService { /** * 分页查询组件列表 - * - * @param page 页码 - * @param pageSize 每页大小 - * @param type 组件类型 (可选) - * @param keyword 搜索关键词 (可选) - * @param categoryId 分类 ID(可选) - * @param tagId 标签 ID(可选) - * @return 分页数据 */ - Page getPage(Integer page, Integer pageSize, String type, String keyword, Long categoryId, Long tagId); + Page getPage(H5ComponentPageQueryDTO queryDTO); /** * 创建组件 diff --git a/ruoyi-site/ruoyi-h5/src/main/java/com/luban/api/service/impl/H5ComponentServiceImpl.java b/ruoyi-site/ruoyi-h5/src/main/java/com/luban/api/service/impl/H5ComponentServiceImpl.java index 01d1fc68e..d462af2b5 100644 --- a/ruoyi-site/ruoyi-h5/src/main/java/com/luban/api/service/impl/H5ComponentServiceImpl.java +++ b/ruoyi-site/ruoyi-h5/src/main/java/com/luban/api/service/impl/H5ComponentServiceImpl.java @@ -9,6 +9,7 @@ import com.luban.api.dao.H5ComponentCategoryRelDao; import com.luban.api.dao.H5ComponentDao; import com.luban.api.dao.H5ComponentTagRelDao; import com.luban.api.dto.H5ComponentDTO; +import com.luban.api.dto.query.H5ComponentPageQueryDTO; import com.luban.api.entity.H5Component; import com.luban.api.entity.H5ComponentCategory; import com.luban.api.entity.H5ComponentCategoryRel; @@ -48,25 +49,25 @@ public class H5ComponentServiceImpl extends ServiceImpl getPage(Integer page, Integer pageSize, String type, String keyword, Long categoryId, Long tagId) { + public Page getPage(H5ComponentPageQueryDTO queryDTO) { //将参数封装成对象,方便后续加参数 Map params = new HashMap<>(); - params.put("type", type); - params.put("keyword", keyword); - params.put("tagId", tagId); - + params.put("type", queryDTO.getType()); + params.put("keyword", queryDTO.getKeyword()); + params.put("tagId", queryDTO.getTagId()); + //categoryId 查询出所有子集一起查询 List categoryIds = new ArrayList<>(); - if (categoryId != null) { - categoryIds.add(categoryId); + if (queryDTO.getCategoryId() != null) { + categoryIds.add(queryDTO.getCategoryId()); // 查询所有子分类ID - List childCategoryIds = getChildCategoryIds(categoryId); + List childCategoryIds = getChildCategoryIds(queryDTO.getCategoryId()); categoryIds.addAll(childCategoryIds); } params.put("categoryIds", categoryIds); - + //使用xml sql 分页查询 - Page resultPage = new Page<>(page, pageSize); + Page resultPage = new Page<>(queryDTO.getPage(), queryDTO.getPageSize()); List componentList = h5ComponentDao.selectPageList(resultPage, params); resultPage.setRecords(componentList);