mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-18 09:35:29 +08:00
根据需求开发:组件库系统开发完成
This commit is contained in:
parent
2d79940ce8
commit
3271c7f86d
@ -4,7 +4,7 @@ public interface BaseConstant {
|
|||||||
/**
|
/**
|
||||||
* 微服务上下文路径
|
* 微服务上下文路径
|
||||||
*/
|
*/
|
||||||
String CONTEXT_PATH = "/booksflow/form/v1.0/";
|
String CONTEXT_PATH = "/form/";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微服务名称
|
* 微服务名称
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package com.luban.api.controller;
|
|||||||
|
|
||||||
import com.luban.api.entity.H5ComponentCategory;
|
import com.luban.api.entity.H5ComponentCategory;
|
||||||
import com.luban.api.service.H5ComponentCategoryService;
|
import com.luban.api.service.H5ComponentCategoryService;
|
||||||
|
import com.luban.api.vo.H5ComponentCategoryTreeVO;
|
||||||
import com.luban.api.vo.Result;
|
import com.luban.api.vo.Result;
|
||||||
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;
|
||||||
@ -53,8 +54,8 @@ public class H5ComponentCategoryController {
|
|||||||
|
|
||||||
@Operation(summary = "获取分类树形结构")
|
@Operation(summary = "获取分类树形结构")
|
||||||
@GetMapping("/tree")
|
@GetMapping("/tree")
|
||||||
public Result<List<H5ComponentCategory>> getCategoryTree() {
|
public Result<List<H5ComponentCategoryTreeVO>> getCategoryTree() {
|
||||||
List<H5ComponentCategory> result = h5ComponentCategoryService.getCategoryTree();
|
List<H5ComponentCategoryTreeVO> result = h5ComponentCategoryService.getCategoryTree();
|
||||||
return new Result<>(result);
|
return new Result<>(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package com.luban.api.service;
|
package com.luban.api.service;
|
||||||
|
|
||||||
import com.luban.api.entity.H5ComponentCategory;
|
import com.luban.api.entity.H5ComponentCategory;
|
||||||
|
import com.luban.api.vo.H5ComponentCategoryTreeVO;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -62,5 +63,5 @@ public interface H5ComponentCategoryService {
|
|||||||
*
|
*
|
||||||
* @return 树形分类列表
|
* @return 树形分类列表
|
||||||
*/
|
*/
|
||||||
List<H5ComponentCategory> getCategoryTree();
|
List<H5ComponentCategoryTreeVO> getCategoryTree();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,17 +1,21 @@
|
|||||||
package com.luban.api.service.impl;
|
package com.luban.api.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.luban.api.dao.H5ComponentCategoryDao;
|
import com.luban.api.dao.H5ComponentCategoryDao;
|
||||||
import com.luban.api.entity.H5ComponentCategory;
|
import com.luban.api.entity.H5ComponentCategory;
|
||||||
import com.luban.api.service.H5ComponentCategoryService;
|
import com.luban.api.service.H5ComponentCategoryService;
|
||||||
|
import com.luban.api.vo.H5ComponentCategoryTreeVO;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* H5 组件分类服务实现类
|
* H5 组件分类服务实现类
|
||||||
@ -91,20 +95,61 @@ public class H5ComponentCategoryServiceImpl extends ServiceImpl<H5ComponentCateg
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<H5ComponentCategory> getCategoryTree() {
|
public List<H5ComponentCategoryTreeVO> getCategoryTree() {
|
||||||
// 查询所有一级分类
|
// 一次性查询所有分类(排除已删除的)
|
||||||
List<H5ComponentCategory> topLevelCategories = getTopLevelCategories();
|
LambdaQueryWrapper<H5ComponentCategory> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.orderByAsc(H5ComponentCategory::getParentId, H5ComponentCategory::getSort);
|
||||||
|
|
||||||
// 为每个一级分类查询子分类
|
List<H5ComponentCategory> allCategories = baseMapper.selectList(wrapper);
|
||||||
for (H5ComponentCategory topLevel : topLevelCategories) {
|
|
||||||
List<H5ComponentCategory> childCategories = getChildCategories(topLevel.getId());
|
// 转换为 VO
|
||||||
// 这里简单处理,实际可以考虑使用专门的树形结构 VO
|
List<H5ComponentCategoryTreeVO> allVOs = allCategories.stream()
|
||||||
if (!childCategories.isEmpty()) {
|
.map(this::convertToTreeVO)
|
||||||
// 可以在返回时添加额外信息
|
.toList();
|
||||||
log.debug("分类 {} 有 {} 个子分类", topLevel.getName(), childCategories.size());
|
|
||||||
|
// 构建树形结构
|
||||||
|
return buildTree(allVOs);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建树形结构
|
||||||
|
*
|
||||||
|
* @param allNodes 所有节点
|
||||||
|
* @return 树形结构(只包含一级分类)
|
||||||
|
*/
|
||||||
|
private List<H5ComponentCategoryTreeVO> buildTree(List<H5ComponentCategoryTreeVO> allNodes) {
|
||||||
|
List<H5ComponentCategoryTreeVO> tree = new ArrayList<>();
|
||||||
|
|
||||||
|
// 使用 Map 提高查找效率
|
||||||
|
Map<Long, H5ComponentCategoryTreeVO> nodeMap = allNodes.stream()
|
||||||
|
.collect(Collectors.toMap(
|
||||||
|
H5ComponentCategoryTreeVO::getId,
|
||||||
|
vo -> vo
|
||||||
|
));
|
||||||
|
|
||||||
|
// 遍历所有节点,构建父子关系
|
||||||
|
for (H5ComponentCategoryTreeVO node : allNodes) {
|
||||||
|
if (node.getParentId() == null || node.getParentId() == 0) {
|
||||||
|
// 一级分类直接添加到树中
|
||||||
|
tree.add(node);
|
||||||
|
} else {
|
||||||
|
// 子分类添加到父分类的 children 中
|
||||||
|
H5ComponentCategoryTreeVO parent = nodeMap.get(node.getParentId());
|
||||||
|
if (parent != null) {
|
||||||
|
parent.getChildren().add(node);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return topLevelCategories;
|
return tree;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转换为树形 VO
|
||||||
|
*/
|
||||||
|
private H5ComponentCategoryTreeVO convertToTreeVO(H5ComponentCategory entity) {
|
||||||
|
H5ComponentCategoryTreeVO vo = new H5ComponentCategoryTreeVO();
|
||||||
|
BeanUtils.copyProperties(entity, vo);
|
||||||
|
return vo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,66 @@
|
|||||||
|
package com.luban.api.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* H5 组件分类树形结构 VO
|
||||||
|
*
|
||||||
|
* @author system
|
||||||
|
* @since 2026-03-06
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class H5ComponentCategoryTreeVO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键 ID
|
||||||
|
*/
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 父分类 ID(0 为一级分类)
|
||||||
|
*/
|
||||||
|
private Long parentId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分类名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分类类型 (text/image/extension/background/music)
|
||||||
|
*/
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序值
|
||||||
|
*/
|
||||||
|
private Integer sort;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分类图标 URL
|
||||||
|
*/
|
||||||
|
private String icon;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分类描述
|
||||||
|
*/
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否系统预设 (1:是 0:否)
|
||||||
|
*/
|
||||||
|
private Integer isSystem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间 (Unix 时间戳秒级)
|
||||||
|
*/
|
||||||
|
private Long createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 子分类列表
|
||||||
|
*/
|
||||||
|
private List<H5ComponentCategoryTreeVO> children = new ArrayList<>();
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user