mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-18 01:25:28 +08:00
分页查询分类
This commit is contained in:
parent
88197f942c
commit
57355457ba
@ -5,7 +5,6 @@ import com.luban.api.dto.H5ComponentCategoryQueryDTO;
|
||||
import com.luban.api.entity.H5ComponentCategory;
|
||||
import com.luban.api.service.H5ComponentCategoryService;
|
||||
import com.luban.api.vo.H5ComponentCategoryTreeVO;
|
||||
import com.luban.api.vo.Result;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@ -31,53 +30,51 @@ public class H5ComponentCategoryController {
|
||||
|
||||
@Operation(summary = "分页查询分类", description = "支持查询一级分类和子分类。不传 parentId 时查询一级分类,传入 parentId 时查询对应子分类")
|
||||
@GetMapping("/page")
|
||||
public Result<Page<H5ComponentCategory>> pageCategories(
|
||||
public Page<H5ComponentCategory> pageCategories(
|
||||
@Parameter(description = "查询参数") @ModelAttribute H5ComponentCategoryQueryDTO queryDTO) {
|
||||
Page<H5ComponentCategory> result = h5ComponentCategoryService.pageCategories(queryDTO);
|
||||
return new Result<>(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Operation(summary = "根据类型查询分类")
|
||||
@GetMapping("/by-type")
|
||||
public Result<List<H5ComponentCategory>> getCategoriesByType(
|
||||
public List<H5ComponentCategory> getCategoriesByType(
|
||||
@Parameter(description = "组件类型", required = true) @RequestParam String type) {
|
||||
|
||||
List<H5ComponentCategory> result = h5ComponentCategoryService.getCategoriesByType(type);
|
||||
return new Result<>(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Operation(summary = "获取分类树形结构")
|
||||
@GetMapping("/tree")
|
||||
public Result<List<H5ComponentCategoryTreeVO>> getCategoryTree() {
|
||||
public List<H5ComponentCategoryTreeVO> getCategoryTree() {
|
||||
List<H5ComponentCategoryTreeVO> result = h5ComponentCategoryService.getCategoryTree();
|
||||
return new Result<>(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Operation(summary = "创建分类")
|
||||
@PostMapping
|
||||
public Result<Long> create(
|
||||
public Long create(
|
||||
@Parameter(description = "分类信息", required = true) @RequestBody @Validated H5ComponentCategory category) {
|
||||
|
||||
Long id = h5ComponentCategoryService.create(category);
|
||||
return new Result<>(id);
|
||||
return id;
|
||||
}
|
||||
|
||||
@Operation(summary = "更新分类")
|
||||
@PostMapping("/update/{id}")
|
||||
public Result<Void> update(
|
||||
public void update(
|
||||
@Parameter(description = "分类 ID", required = true) @PathVariable Long id,
|
||||
@Parameter(description = "分类信息", required = true) @RequestBody @Validated H5ComponentCategory category) {
|
||||
|
||||
category.setId(id);
|
||||
h5ComponentCategoryService.update(category);
|
||||
return new Result<>();
|
||||
}
|
||||
|
||||
@Operation(summary = "删除分类")
|
||||
@PostMapping("/delete/{id}")
|
||||
public Result<Void> deleteById(
|
||||
public void deleteById(
|
||||
@Parameter(description = "分类 ID", required = true) @PathVariable Long id) {
|
||||
h5ComponentCategoryService.deleteById(id);
|
||||
return new Result<>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,12 +1,10 @@
|
||||
|
||||
package com.luban.api.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.luban.api.entity.H5Component;
|
||||
import com.luban.api.service.H5ComponentService;
|
||||
import com.luban.api.vo.H5ComponentVO;
|
||||
import com.luban.api.vo.Result;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@ -32,15 +30,14 @@ public class H5ComponentController {
|
||||
|
||||
@Operation(summary = "根据 ID 查询组件")
|
||||
@GetMapping("/{id}")
|
||||
public Result<H5ComponentVO> getById(
|
||||
public H5ComponentVO getById(
|
||||
@Parameter(description = "组件 ID") @PathVariable Long id) {
|
||||
H5ComponentVO vo = h5ComponentService.getById(id);
|
||||
return new Result<>(vo);
|
||||
return h5ComponentService.getById(id);
|
||||
}
|
||||
|
||||
@Operation(summary = "分页查询组件列表")
|
||||
@GetMapping("/page")
|
||||
public Result<Page<H5ComponentVO>> getPage(
|
||||
public Page<H5ComponentVO> getPage(
|
||||
@Parameter(description = "页码", required = true) @RequestParam Integer page,
|
||||
@Parameter(description = "每页大小", required = true) @RequestParam Integer pageSize,
|
||||
@Parameter(description = "组件类型") @RequestParam(required = false) String type,
|
||||
@ -48,24 +45,22 @@ public class H5ComponentController {
|
||||
@Parameter(description = "分类 ID") @RequestParam(required = false) Long categoryId,
|
||||
@Parameter(description = "标签 ID") @RequestParam(required = false) Long tagId) {
|
||||
|
||||
Page<H5ComponentVO> result = h5ComponentService.getPage(page, pageSize, type, keyword, categoryId, tagId);
|
||||
return new Result<>(result);
|
||||
return h5ComponentService.getPage(page, pageSize, type, keyword, categoryId, tagId);
|
||||
}
|
||||
|
||||
@Operation(summary = "创建组件")
|
||||
@PostMapping
|
||||
public Result<Long> create(
|
||||
public Long create(
|
||||
@Parameter(description = "组件信息", required = true) @RequestBody @Validated H5Component component,
|
||||
@Parameter(description = "分类 ID 列表") @RequestBody(required = false) List<Long> categoryIds,
|
||||
@Parameter(description = "标签 ID 列表") @RequestBody(required = false) List<Long> tagIds) {
|
||||
|
||||
Long id = h5ComponentService.create(component, categoryIds, tagIds);
|
||||
return new Result<>(id);
|
||||
return h5ComponentService.create(component, categoryIds, tagIds);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新组件")
|
||||
@PostMapping("/update/{id}")
|
||||
public Result<Void> update(
|
||||
public void update(
|
||||
@Parameter(description = "组件 ID", required = true) @PathVariable Long id,
|
||||
@Parameter(description = "组件信息", required = true) @RequestBody @Validated H5Component component,
|
||||
@Parameter(description = "分类 ID 列表") @RequestBody(required = false) List<Long> categoryIds,
|
||||
@ -73,48 +68,42 @@ public class H5ComponentController {
|
||||
|
||||
component.setId(id);
|
||||
h5ComponentService.update(component, categoryIds, tagIds);
|
||||
return new Result<>();
|
||||
}
|
||||
|
||||
@Operation(summary = "删除组件")
|
||||
@PostMapping("/delete/{id}")
|
||||
public Result<Void> deleteById(
|
||||
public void deleteById(
|
||||
@Parameter(description = "组件 ID", required = true) @PathVariable Long id) {
|
||||
h5ComponentService.deleteById(id);
|
||||
return new Result<>();
|
||||
}
|
||||
|
||||
@Operation(summary = "批量删除组件")
|
||||
@PostMapping("/batch")
|
||||
public Result<Void> deleteBatch(
|
||||
public void deleteBatch(
|
||||
@Parameter(description = "组件 ID 列表", required = true) @RequestBody List<Long> ids) {
|
||||
h5ComponentService.deleteBatch(ids);
|
||||
return new Result<>();
|
||||
}
|
||||
|
||||
@Operation(summary = "增加使用次数")
|
||||
@PostMapping("/{id}/usage")
|
||||
public Result<Void> incrementUsageCount(
|
||||
public void incrementUsageCount(
|
||||
@Parameter(description = "组件 ID", required = true) @PathVariable Long id) {
|
||||
h5ComponentService.incrementUsageCount(id);
|
||||
return new Result<>();
|
||||
}
|
||||
|
||||
@Operation(summary = "增加点赞数")
|
||||
@PostMapping("/{id}/like")
|
||||
public Result<Void> incrementLikeCount(
|
||||
public void incrementLikeCount(
|
||||
@Parameter(description = "组件 ID", required = true) @PathVariable Long id) {
|
||||
h5ComponentService.incrementLikeCount(id);
|
||||
return new Result<>();
|
||||
}
|
||||
|
||||
@Operation(summary = "获取热门组件")
|
||||
@GetMapping("/hot")
|
||||
public Result<List<H5ComponentVO>> getHotComponents(
|
||||
public List<H5ComponentVO> getHotComponents(
|
||||
@Parameter(description = "组件类型") @RequestParam(required = false) String type,
|
||||
@Parameter(description = "数量限制", required = true) @RequestParam Integer limit) {
|
||||
|
||||
List<H5ComponentVO> result = h5ComponentService.getHotComponents(type, limit);
|
||||
return new Result<>(result);
|
||||
return h5ComponentService.getHotComponents(type, limit);
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,16 +39,4 @@ public class H5ComponentCategoryPageVO {
|
||||
*/
|
||||
private Integer pages;
|
||||
|
||||
/**
|
||||
* 从 MyBatis-Plus Page 构建分页 VO
|
||||
*/
|
||||
public static H5ComponentCategoryPageVO from(Page<H5ComponentCategoryTreeVO> page) {
|
||||
H5ComponentCategoryPageVO vo = new H5ComponentCategoryPageVO();
|
||||
vo.setList(page.getRecords());
|
||||
vo.setTotal(page.getTotal());
|
||||
vo.setPageNum((int) page.getCurrent());
|
||||
vo.setPageSize((int) page.getSize());
|
||||
vo.setPages((int) ((page.getTotal() + page.getSize() - 1) / page.getSize()));
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user