在线h5开发

This commit is contained in:
Github_lizhw 2026-03-15 19:29:16 +08:00
parent b862bbbec8
commit 000497f2d4
4 changed files with 72 additions and 35 deletions

View File

@ -3,17 +3,15 @@ package com.luban.api.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.luban.api.dto.H5ComponentDTO; 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.service.H5ComponentService;
import com.luban.api.vo.H5ComponentVO; import com.luban.api.vo.H5ComponentVO;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag; 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 jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -41,15 +39,8 @@ public class H5ComponentController {
@Operation(summary = "分页查询组件列表") @Operation(summary = "分页查询组件列表")
@GetMapping("/page") @GetMapping("/page")
public Page<H5ComponentVO> getPage( public Page<H5ComponentVO> getPage(@Valid H5ComponentPageQueryDTO queryDTO) {
@Parameter(description = "页码", required = true) @RequestParam Integer page, return h5ComponentService.getPage(queryDTO);
@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);
} }
@Operation(summary = "查询指定分类下排行前几的组件") @Operation(summary = "查询指定分类下排行前几的组件")
@ -114,4 +105,4 @@ public class H5ComponentController {
return h5ComponentService.getHotComponents(type, limit); return h5ComponentService.getHotComponents(type, limit);
} }
} }

View File

@ -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;
}

View File

@ -2,7 +2,7 @@ package com.luban.api.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.luban.api.dto.H5ComponentDTO; 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 com.luban.api.vo.H5ComponentVO;
import java.util.List; 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<H5ComponentVO> getPage(Integer page, Integer pageSize, String type, String keyword, Long categoryId, Long tagId); Page<H5ComponentVO> getPage(H5ComponentPageQueryDTO queryDTO);
/** /**
* 创建组件 * 创建组件

View File

@ -9,6 +9,7 @@ import com.luban.api.dao.H5ComponentCategoryRelDao;
import com.luban.api.dao.H5ComponentDao; import com.luban.api.dao.H5ComponentDao;
import com.luban.api.dao.H5ComponentTagRelDao; import com.luban.api.dao.H5ComponentTagRelDao;
import com.luban.api.dto.H5ComponentDTO; import com.luban.api.dto.H5ComponentDTO;
import com.luban.api.dto.query.H5ComponentPageQueryDTO;
import com.luban.api.entity.H5Component; import com.luban.api.entity.H5Component;
import com.luban.api.entity.H5ComponentCategory; import com.luban.api.entity.H5ComponentCategory;
import com.luban.api.entity.H5ComponentCategoryRel; import com.luban.api.entity.H5ComponentCategoryRel;
@ -48,25 +49,25 @@ public class H5ComponentServiceImpl extends ServiceImpl<H5ComponentDao, H5Compon
} }
@Override @Override
public Page<H5ComponentVO> getPage(Integer page, Integer pageSize, String type, String keyword, Long categoryId, Long tagId) { public Page<H5ComponentVO> getPage(H5ComponentPageQueryDTO queryDTO) {
//将参数封装成对象方便后续加参数 //将参数封装成对象方便后续加参数
Map<String, Object> params = new HashMap<>(); Map<String, Object> params = new HashMap<>();
params.put("type", type); params.put("type", queryDTO.getType());
params.put("keyword", keyword); params.put("keyword", queryDTO.getKeyword());
params.put("tagId", tagId); params.put("tagId", queryDTO.getTagId());
//categoryId 查询出所有子集一起查询 //categoryId 查询出所有子集一起查询
List<Long> categoryIds = new ArrayList<>(); List<Long> categoryIds = new ArrayList<>();
if (categoryId != null) { if (queryDTO.getCategoryId() != null) {
categoryIds.add(categoryId); categoryIds.add(queryDTO.getCategoryId());
// 查询所有子分类ID // 查询所有子分类ID
List<Long> childCategoryIds = getChildCategoryIds(categoryId); List<Long> childCategoryIds = getChildCategoryIds(queryDTO.getCategoryId());
categoryIds.addAll(childCategoryIds); categoryIds.addAll(childCategoryIds);
} }
params.put("categoryIds", categoryIds); params.put("categoryIds", categoryIds);
//使用xml sql 分页查询 //使用xml sql 分页查询
Page<H5Component> resultPage = new Page<>(page, pageSize); Page<H5Component> resultPage = new Page<>(queryDTO.getPage(), queryDTO.getPageSize());
List<H5Component> componentList = h5ComponentDao.selectPageList(resultPage, params); List<H5Component> componentList = h5ComponentDao.selectPageList(resultPage, params);
resultPage.setRecords(componentList); resultPage.setRecords(componentList);