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; ...@@ -24,6 +24,7 @@ import org.dinky.data.constant.PermissionConstants;
import org.dinky.data.dto.ResourcesDTO; import org.dinky.data.dto.ResourcesDTO;
import org.dinky.data.dto.TreeNodeDTO; import org.dinky.data.dto.TreeNodeDTO;
import org.dinky.data.enums.BusinessType; import org.dinky.data.enums.BusinessType;
import org.dinky.data.model.Resources;
import org.dinky.data.result.Result; import org.dinky.data.result.Result;
import org.dinky.service.resource.ResourcesService; import org.dinky.service.resource.ResourcesService;
...@@ -86,24 +87,15 @@ public class ResourceController { ...@@ -86,24 +87,15 @@ public class ResourceController {
return Result.succeed(); return Result.succeed();
} }
@GetMapping("/showByTree") /**
@ApiOperation("Query Folder/File Tree") * query Resources tree data
@ApiImplicitParams({ * @return {@link Result}< {@link List}< {@link Resources}>>}
@ApiImplicitParam( */
name = "pid", @GetMapping("/getResourcesTreeData")
value = "Parent ID", @ApiOperation("Get Resources Tree Data")
required = true, public Result<List<Resources>> getResourcesTree() {
dataType = "Integer", List<Resources> resources = resourcesService.getResourcesTree();
paramType = "query"), return Result.succeed(resources);
@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));
} }
@GetMapping("/getContentByResourceId") @GetMapping("/getContentByResourceId")
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
package org.dinky.data.model; package org.dinky.data.model;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import com.baomidou.mybatisplus.annotation.FieldFill; import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.IdType;
...@@ -118,4 +120,16 @@ public class Resources extends Model<Resources> { ...@@ -118,4 +120,16 @@ public class Resources extends Model<Resources> {
@TableField(exist = false) @TableField(exist = false)
private static final long serialVersionUID = 1L; 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; ...@@ -21,6 +21,7 @@ package org.dinky.service.resource;
import org.dinky.data.dto.TreeNodeDTO; import org.dinky.data.dto.TreeNodeDTO;
import org.dinky.data.model.Resources; import org.dinky.data.model.Resources;
import org.dinky.data.result.Result;
import java.util.List; import java.util.List;
...@@ -61,4 +62,10 @@ public interface ResourcesService extends IService<Resources> { ...@@ -61,4 +62,10 @@ public interface ResourcesService extends IService<Resources> {
* @return data * @return data
*/ */
List<Resources> getResourceByPidToChildren(List<Resources> resourcesList, Integer pid); 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; ...@@ -22,12 +22,16 @@ package org.dinky.service.resource.impl;
import org.dinky.data.dto.TreeNodeDTO; import org.dinky.data.dto.TreeNodeDTO;
import org.dinky.data.exception.BusException; import org.dinky.data.exception.BusException;
import org.dinky.data.model.Resources; import org.dinky.data.model.Resources;
import org.dinky.data.result.Result;
import org.dinky.mapper.ResourcesMapper; import org.dinky.mapper.ResourcesMapper;
import org.dinky.service.resource.BaseResourceManager; import org.dinky.service.resource.BaseResourceManager;
import org.dinky.service.resource.ResourcesService; import org.dinky.service.resource.ResourcesService;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -38,6 +42,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; ...@@ -38,6 +42,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.hutool.cache.impl.TimedCache; import cn.hutool.cache.impl.TimedCache;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.Assert;
import cn.hutool.core.lang.Opt; import cn.hutool.core.lang.Opt;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
...@@ -264,6 +269,94 @@ public class ResourceServiceImpl extends ServiceImpl<ResourcesMapper, Resources> ...@@ -264,6 +269,94 @@ public class ResourceServiceImpl extends ServiceImpl<ResourcesMapper, Resources>
return resourcesList; 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() { private BaseResourceManager getBaseResourceManager() {
return BaseResourceManager.getInstance(); return BaseResourceManager.getInstance();
} }
......
...@@ -65,10 +65,8 @@ const ResourceOverView: React.FC = () => { ...@@ -65,10 +65,8 @@ const ResourceOverView: React.FC = () => {
return node; return node;
}); });
const refreshTreeData = async (pid: number, path: string) => { const refreshTreeData = async (path: string) => {
const data = await queryDataByParams<any[]>(API_CONSTANTS.RESOURCE_SHOW_TREE, { const data = await queryDataByParams<any[]>(API_CONSTANTS.RESOURCE_SHOW_TREE);
pid: pid
});
setResourceState((prevState) => ({ setResourceState((prevState) => ({
...prevState, ...prevState,
treeData: updateTreeData(prevState.treeData, path, data ?? []) treeData: updateTreeData(prevState.treeData, path, data ?? [])
...@@ -76,7 +74,7 @@ const ResourceOverView: React.FC = () => { ...@@ -76,7 +74,7 @@ const ResourceOverView: React.FC = () => {
}; };
const refreshTree = async () => { 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 ?? [] })) setResourceState((prevState) => ({ ...prevState, treeData: res ?? [] }))
); );
}; };
...@@ -286,7 +284,7 @@ const ResourceOverView: React.FC = () => { ...@@ -286,7 +284,7 @@ const ResourceOverView: React.FC = () => {
if (children.length > 0) { if (children.length > 0) {
return; return;
} }
await refreshTreeData(id, path); await refreshTreeData(path);
}; };
const access = useAccess(); const access = useAccess();
......
...@@ -265,7 +265,7 @@ export enum API_CONSTANTS { ...@@ -265,7 +265,7 @@ export enum API_CONSTANTS {
FLINK_TABLE_DATA = '/api/subscribe/print', FLINK_TABLE_DATA = '/api/subscribe/print',
// resource // resource
RESOURCE_SHOW_TREE = '/api/resource/showByTree', RESOURCE_SHOW_TREE = '/api/resource/getResourcesTreeData',
RESOURCE_GET_CONTENT_BY_ID = '/api/resource/getContentByResourceId', RESOURCE_GET_CONTENT_BY_ID = '/api/resource/getContentByResourceId',
RESOURCE_REMOVE = '/api/resource/remove', RESOURCE_REMOVE = '/api/resource/remove',
RESOURCE_CREATE_FOLDER = '/api/resource/createFolder', RESOURCE_CREATE_FOLDER = '/api/resource/createFolder',
......
...@@ -444,12 +444,12 @@ export function differenceDays(startDateString: any, endDateString: any): number ...@@ -444,12 +444,12 @@ export function differenceDays(startDateString: any, endDateString: any): number
export const buildTreeData = (data: any): any => export const buildTreeData = (data: any): any =>
data?.map((item: any) => { data?.map((item: any) => {
// build key // build key
let buildKey = item.path + folderSeparator() + item.name; let buildKey = item.path + folderSeparator() + item.fileName;
const buildTitleLabel = () => { const buildTitleLabel = () => {
return ( return (
<> <>
{item.name} {item.fileName}
<span style={{ color: 'gray' }}> <span style={{ color: 'gray' }}>
{' '} {' '}
&nbsp;&nbsp;{l('global.size', '', { size: item.size })} &nbsp;&nbsp;{l('global.size', '', { size: item.size })}
...@@ -461,13 +461,13 @@ export const buildTreeData = (data: any): any => ...@@ -461,13 +461,13 @@ export const buildTreeData = (data: any): any =>
// if has children , recursive build // if has children , recursive build
if (item.children) { if (item.children) {
return { return {
isLeaf: !item.leaf, isLeaf: item.leaf,
id: item?.id, id: item?.id,
name: item.name, fileName: item.fileName,
parentId: item.path ?? item.parentId, parentId: item.path ?? item.pid,
icon: renderIcon(item.name, '.', item.leaf), icon: renderIcon(item.fileName, '.', item.leaf),
content: item.content, content: item.content,
path: item.path, path: item.fullName,
fullName: item?.fullName, fullName: item?.fullName,
title: buildTitleLabel(), title: buildTitleLabel(),
desc: item?.desc ?? item?.description, 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