|
|
@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.dromara.platform.domain.bo.ServiceCatalogCategoryBo; |
|
|
|
import org.dromara.platform.domain.vo.ServiceCatalogCategoryVo; |
|
|
@ -69,7 +70,7 @@ public class ServiceCatalogCategoryServiceImpl implements IServiceCatalogCategor |
|
|
|
private LambdaQueryWrapper<ServiceCatalogCategory> buildQueryWrapper(ServiceCatalogCategoryBo bo) { |
|
|
|
Map<String, Object> params = bo.getParams(); |
|
|
|
LambdaQueryWrapper<ServiceCatalogCategory> lqw = Wrappers.lambdaQuery(); |
|
|
|
lqw.like(StringUtils.isNotBlank(bo.getProjectName()), ServiceCatalogCategory::getProjectName, bo.getProjectName()); |
|
|
|
lqw.like(StringUtils.isNotBlank(bo.getCategoryName()), ServiceCatalogCategory::getCategoryName, bo.getCategoryName()); |
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getDescription()), ServiceCatalogCategory::getDescription, bo.getDescription()); |
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getCode()), ServiceCatalogCategory::getCode, bo.getCode()); |
|
|
|
lqw.eq(bo.getIsChildren() != null, ServiceCatalogCategory::getIsChildren, bo.getIsChildren()); |
|
|
@ -183,5 +184,45 @@ public class ServiceCatalogCategoryServiceImpl implements IServiceCatalogCategor |
|
|
|
return new ArrayList<>(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<ServiceCatalogCategoryVo> queryCategory() { |
|
|
|
LambdaQueryWrapper<ServiceCatalogCategory> queryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
queryWrapper.eq(ServiceCatalogCategory::getIsChildren, false); |
|
|
|
List<ServiceCatalogCategory> serviceCatalogCategories = baseMapper.selectList(queryWrapper); |
|
|
|
List<ServiceCatalogCategoryVo> convertList = MapstructUtils.convert(serviceCatalogCategories, ServiceCatalogCategoryVo.class); |
|
|
|
return convertList; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public List<ServiceCatalogCategory> buildFullTree() { |
|
|
|
// 获取所有服务类别记录
|
|
|
|
List<ServiceCatalogCategory> allCategories = baseMapper.selectList(null); |
|
|
|
|
|
|
|
// 创建一个Map以便快速查找任何ID对应的类别
|
|
|
|
Map<String, ServiceCatalogCategory> categoryMap = new HashMap<>(); |
|
|
|
for (ServiceCatalogCategory category : allCategories) { |
|
|
|
categoryMap.put(category.getId(), category); |
|
|
|
} |
|
|
|
|
|
|
|
// 根节点列表
|
|
|
|
List<ServiceCatalogCategory> rootNodes = new ArrayList<>(); |
|
|
|
|
|
|
|
for (ServiceCatalogCategory category : allCategories) { |
|
|
|
String ownerId = category.getOwnerId(); // 获取父级目录ID
|
|
|
|
if (ownerId == null || !categoryMap.containsKey(ownerId)) { |
|
|
|
// 如果没有父节点或父节点不在当前集合中,则认为它是根节点
|
|
|
|
rootNodes.add(category); |
|
|
|
} else { |
|
|
|
// 否则添加到父节点的children列表中
|
|
|
|
ServiceCatalogCategory parentCategory = categoryMap.get(ownerId); |
|
|
|
if (parentCategory.getChildren() == null) { |
|
|
|
parentCategory.setChildren(new ArrayList<>()); |
|
|
|
} |
|
|
|
parentCategory.getChildren().add(category); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return rootNodes; |
|
|
|
} |
|
|
|
} |
|
|
|