Unverified Commit 0ba9d2c3 authored by zhangyongtian's avatar zhangyongtian Committed by GitHub

[Optimization][admin] Modify the resource directory from partial to one-time acquisition (#2375)

* [Fix][admin] H2 SQL file exceptions and divide by zero exceptions * [Fix][admin] Remove designated tenants * [Fix][web] Popup box cannot be closed * [Fix][admin] Exceptions caused by duplicate names of udf's Java classes * [Optimization][admin] Modify the resource directory from partial to one-time acquisition
parent 96576a95
......@@ -24,6 +24,7 @@ import org.dinky.data.constant.PermissionConstants;
import org.dinky.data.dto.ResourcesDTO;
import org.dinky.data.dto.TreeNodeDTO;
import org.dinky.data.enums.BusinessType;
import org.dinky.data.model.Resources;
import org.dinky.data.result.Result;
import org.dinky.service.resource.ResourcesService;
......@@ -86,24 +87,15 @@ public class ResourceController {
return Result.succeed();
}
@GetMapping("/showByTree")
@ApiOperation("Query Folder/File Tree")
@ApiImplicitParams({
@ApiImplicitParam(
name = "pid",
value = "Parent ID",
required = true,
dataType = "Integer",
paramType = "query"),
@ApiImplicitParam(
name = "showFloorNum",
value = "Show Floor Number",
required = true,
dataType = "Integer",
paramType = "query")
})
public Result<List<TreeNodeDTO>> showByTree(Integer pid, Integer showFloorNum) {
return Result.succeed(resourcesService.showByTree(pid, showFloorNum));
/**
* query Resources tree data
* @return {@link Result}< {@link List}< {@link Resources}>>}
*/
@GetMapping("/getResourcesTreeData")
@ApiOperation("Get Resources Tree Data")
public Result<List<Resources>> getResourcesTree() {
List<Resources> resources = resourcesService.getResourcesTree();
return Result.succeed(resources);
}
@GetMapping("/getContentByResourceId")
......
......@@ -20,6 +20,8 @@
package org.dinky.data.model;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
......@@ -118,4 +120,16 @@ public class Resources extends Model<Resources> {
@TableField(exist = false)
private static final long serialVersionUID = 1L;
@TableField(exist = false)
@ApiModelProperty(value = "Children", required = true, dataType = "List<Resources>", example = "[]")
private List<Resources> children = new ArrayList<>();
@TableField(exist = false)
@ApiModelProperty(
value = "Is Leaf",
dataType = "boolean",
example = "false",
notes = "Indicates whether the tree node is a leaf node (true/false)")
private boolean isLeaf;
}
......@@ -21,6 +21,7 @@ package org.dinky.service.resource;
import org.dinky.data.dto.TreeNodeDTO;
import org.dinky.data.model.Resources;
import org.dinky.data.result.Result;
import java.util.List;
......@@ -61,4 +62,10 @@ public interface ResourcesService extends IService<Resources> {
* @return data
*/
List<Resources> getResourceByPidToChildren(List<Resources> resourcesList, Integer pid);
/**
* query Resources tree data
* @return {@link Result}< {@link List}< {@link Resources}>>}
*/
List<Resources> getResourcesTree();
}
......@@ -22,12 +22,16 @@ package org.dinky.service.resource.impl;
import org.dinky.data.dto.TreeNodeDTO;
import org.dinky.data.exception.BusException;
import org.dinky.data.model.Resources;
import org.dinky.data.result.Result;
import org.dinky.mapper.ResourcesMapper;
import org.dinky.service.resource.BaseResourceManager;
import org.dinky.service.resource.ResourcesService;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -38,6 +42,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.hutool.cache.impl.TimedCache;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.lang.Opt;
import cn.hutool.core.util.StrUtil;
......@@ -229,7 +234,7 @@ public class ResourceServiceImpl extends ServiceImpl<ResourcesMapper, Resources>
* 递归获取所有的资源,从pid到0
*
* @param resourcesList data
* @param pid pid
* @param pid pid
* @return data
*/
@Override
......@@ -246,7 +251,7 @@ public class ResourceServiceImpl extends ServiceImpl<ResourcesMapper, Resources>
* 递归获取所有的资源,从id往下穿
*
* @param resourcesList data
* @param pid pid
* @param pid pid
* @return data
*/
@Override
......@@ -264,6 +269,94 @@ public class ResourceServiceImpl extends ServiceImpl<ResourcesMapper, Resources>
return resourcesList;
}
/**
* query Resources tree data
*
* @return {@link Result}< {@link List}< {@link Resources}>>}
*/
@Override
public List<Resources> getResourcesTree() {
return buildResourcesTree(this.list());
}
/**
* build resources tree
*
* @param resourcesList resources list
* @return Resources tree
*/
private List<Resources> buildResourcesTree(List<Resources> resourcesList) {
// sort
if (CollectionUtil.isNotEmpty(resourcesList)) {
resourcesList = resourcesList.stream()
.sorted(Comparator.comparing(Resources::getId))
.collect(Collectors.toList());
}
List<Resources> returnList = new ArrayList<>();
for (Iterator<Resources> iterator = resourcesList.iterator(); iterator.hasNext(); ) {
Resources resources = iterator.next();
// get all child catalogue of parent catalogue id , the -1 is root catalogue
if (resources.getPid() == -1) {
recursionBuildResourcesAndChildren(resourcesList, resources);
returnList.add(resources);
}
}
if (returnList.isEmpty()) {
returnList = resourcesList;
}
return returnList;
}
/**
* recursion build resources and children
*
* @param resourcesList
* @param resources
*/
private void recursionBuildResourcesAndChildren(List<Resources> resourcesList, Resources resources) {
// obtain a list of child nodes
List<Resources> childList = getChildList(resourcesList, resources);
resources.setChildren(childList);
for (Resources tChild : childList) {
if (hasChild(resourcesList, tChild)) {
// Determine whether there are child nodes
recursionBuildResourcesAndChildren(resourcesList, tChild);
} else {
tChild.setLeaf(true);
}
}
}
/**
* get child list
*
* @param list
* @param resources
* @return
*/
private List<Resources> getChildList(List<Resources> list, Resources resources) {
List<Resources> childList = new ArrayList<>();
for (Resources n : list) {
if (n.getPid().longValue() == resources.getId().longValue()) {
childList.add(n);
}
}
return childList;
}
/**
* Determine whether there are child nodes
*
* @param resourcesList
* @param resources
* @return
*/
private boolean hasChild(List<Resources> resourcesList, Resources resources) {
return getChildList(resourcesList, resources).size() > 0;
}
private BaseResourceManager getBaseResourceManager() {
return BaseResourceManager.getInstance();
}
......
......@@ -65,10 +65,8 @@ const ResourceOverView: React.FC = () => {
return node;
});
const refreshTreeData = async (pid: number, path: string) => {
const data = await queryDataByParams<any[]>(API_CONSTANTS.RESOURCE_SHOW_TREE, {
pid: pid
});
const refreshTreeData = async (path: string) => {
const data = await queryDataByParams<any[]>(API_CONSTANTS.RESOURCE_SHOW_TREE);
setResourceState((prevState) => ({
...prevState,
treeData: updateTreeData(prevState.treeData, path, data ?? [])
......@@ -76,7 +74,7 @@ const ResourceOverView: React.FC = () => {
};
const refreshTree = async () => {
await queryDataByParams<any[]>(API_CONSTANTS.RESOURCE_SHOW_TREE, { pid: -1 }).then((res) =>
await queryDataByParams<any[]>(API_CONSTANTS.RESOURCE_SHOW_TREE).then((res) =>
setResourceState((prevState) => ({ ...prevState, treeData: res ?? [] }))
);
};
......@@ -286,7 +284,7 @@ const ResourceOverView: React.FC = () => {
if (children.length > 0) {
return;
}
await refreshTreeData(id, path);
await refreshTreeData(path);
};
const access = useAccess();
......
......@@ -265,7 +265,7 @@ export enum API_CONSTANTS {
FLINK_TABLE_DATA = '/api/subscribe/print',
// resource
RESOURCE_SHOW_TREE = '/api/resource/showByTree',
RESOURCE_SHOW_TREE = '/api/resource/getResourcesTreeData',
RESOURCE_GET_CONTENT_BY_ID = '/api/resource/getContentByResourceId',
RESOURCE_REMOVE = '/api/resource/remove',
RESOURCE_CREATE_FOLDER = '/api/resource/createFolder',
......
......@@ -444,12 +444,12 @@ export function differenceDays(startDateString: any, endDateString: any): number
export const buildTreeData = (data: any): any =>
data?.map((item: any) => {
// build key
let buildKey = item.path + folderSeparator() + item.name;
let buildKey = item.path + folderSeparator() + item.fileName;
const buildTitleLabel = () => {
return (
<>
{item.name}
{item.fileName}
<span style={{ color: 'gray' }}>
{' '}
&nbsp;&nbsp;{l('global.size', '', { size: item.size })}
......@@ -461,13 +461,13 @@ export const buildTreeData = (data: any): any =>
// if has children , recursive build
if (item.children) {
return {
isLeaf: !item.leaf,
isLeaf: item.leaf,
id: item?.id,
name: item.name,
parentId: item.path ?? item.parentId,
icon: renderIcon(item.name, '.', item.leaf),
fileName: item.fileName,
parentId: item.path ?? item.pid,
icon: renderIcon(item.fileName, '.', item.leaf),
content: item.content,
path: item.path,
path: item.fullName,
fullName: item?.fullName,
title: buildTitleLabel(),
desc: item?.desc ?? item?.description,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment