Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dinky
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wangpeng
dinky
Commits
7f501245
Unverified
Commit
7f501245
authored
Nov 10, 2022
by
Forus
Committed by
GitHub
Nov 10, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Feature-1236]新增作业树目录级删除功能(包括删除子目录/作业) (#1239)
parent
d3f59c91
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
91 additions
and
33 deletions
+91
-33
CatalogueController.java
...c/main/java/com/dlink/controller/CatalogueController.java
+17
-11
CatalogueService.java
...min/src/main/java/com/dlink/service/CatalogueService.java
+1
-1
CatalogueServiceImpl.java
...ain/java/com/dlink/service/impl/CatalogueServiceImpl.java
+72
-20
index.tsx
dlink-web/src/components/Studio/StudioTree/index.tsx
+1
-1
No files found.
dlink-admin/src/main/java/com/dlink/controller/CatalogueController.java
View file @
7f501245
...
@@ -59,14 +59,15 @@ import lombok.extern.slf4j.Slf4j;
...
@@ -59,14 +59,15 @@ import lombok.extern.slf4j.Slf4j;
@RestController
@RestController
@RequestMapping
(
"/api/catalogue"
)
@RequestMapping
(
"/api/catalogue"
)
public
class
CatalogueController
{
public
class
CatalogueController
{
@Autowired
@Autowired
private
CatalogueService
catalogueService
;
private
CatalogueService
catalogueService
;
@PostMapping
(
"/upload/{id}"
)
@PostMapping
(
"/upload/{id}"
)
public
Result
<
String
>
upload
(
MultipartFile
file
,
@PathVariable
Integer
id
)
{
public
Result
<
String
>
upload
(
MultipartFile
file
,
@PathVariable
Integer
id
)
{
//获取上传的路径
//
获取上传的路径
String
filePath
=
System
.
getProperty
(
"user.dir"
);
String
filePath
=
System
.
getProperty
(
"user.dir"
);
//获取源文件的名称
//
获取源文件的名称
String
fileName
=
file
.
getOriginalFilename
();
String
fileName
=
file
.
getOriginalFilename
();
String
zipPath
=
filePath
+
File
.
separator
+
fileName
;
String
zipPath
=
filePath
+
File
.
separator
+
fileName
;
String
unzipFileName
=
fileName
.
substring
(
0
,
fileName
.
lastIndexOf
(
"."
));
String
unzipFileName
=
fileName
.
substring
(
0
,
fileName
.
lastIndexOf
(
"."
));
...
@@ -78,7 +79,7 @@ public class CatalogueController {
...
@@ -78,7 +79,7 @@ public class CatalogueController {
return
Result
.
failed
(
"工程已存在"
);
return
Result
.
failed
(
"工程已存在"
);
}
}
try
{
try
{
//文件写入上传的路径
//
文件写入上传的路径
FileUtil
.
writeBytes
(
file
.
getBytes
(),
zipPath
);
FileUtil
.
writeBytes
(
file
.
getBytes
(),
zipPath
);
Thread
.
sleep
(
1L
);
Thread
.
sleep
(
1L
);
if
(!
unzipFile
.
exists
())
{
if
(!
unzipFile
.
exists
())
{
...
@@ -102,11 +103,14 @@ public class CatalogueController {
...
@@ -102,11 +103,14 @@ public class CatalogueController {
}
}
for
(
File
fl
:
fs
)
{
for
(
File
fl
:
fs
)
{
if
(
fl
.
isFile
())
{
if
(
fl
.
isFile
())
{
CatalogueTaskDTO
dto
=
getCatalogueTaskDTO
(
fl
.
getName
(),
catalogueService
.
findByParentIdAndName
(
catalog
.
getParentId
(),
catalog
.
getName
()).
getId
());
CatalogueTaskDTO
dto
=
getCatalogueTaskDTO
(
fl
.
getName
(),
catalogueService
.
findByParentIdAndName
(
catalog
.
getParentId
(),
catalog
.
getName
()).
getId
());
String
fileText
=
getFileText
(
fl
);
String
fileText
=
getFileText
(
fl
);
catalogueService
.
createCatalogAndFileTask
(
dto
,
fileText
);
catalogueService
.
createCatalogAndFileTask
(
dto
,
fileText
);
}
else
{
}
else
{
Catalogue
newCata
=
getCatalogue
(
catalogueService
.
findByParentIdAndName
(
catalog
.
getParentId
(),
catalog
.
getName
()).
getId
(),
fl
.
getName
());
Catalogue
newCata
=
getCatalogue
(
catalogueService
.
findByParentIdAndName
(
catalog
.
getParentId
(),
catalog
.
getName
()).
getId
(),
fl
.
getName
());
traverseFile
(
fl
.
getPath
(),
newCata
);
traverseFile
(
fl
.
getPath
(),
newCata
);
}
}
}
}
...
@@ -114,7 +118,8 @@ public class CatalogueController {
...
@@ -114,7 +118,8 @@ public class CatalogueController {
private
String
getFileText
(
File
sourceFile
)
{
private
String
getFileText
(
File
sourceFile
)
{
StringBuilder
sb
=
new
StringBuilder
();
StringBuilder
sb
=
new
StringBuilder
();
try
(
InputStreamReader
isr
=
new
InputStreamReader
(
new
FileInputStream
(
sourceFile
));
try
(
InputStreamReader
isr
=
new
InputStreamReader
(
new
FileInputStream
(
sourceFile
));
BufferedReader
br
=
new
BufferedReader
(
isr
);)
{
BufferedReader
br
=
new
BufferedReader
(
isr
);)
{
if
(
sourceFile
.
isFile
()
&&
sourceFile
.
exists
())
{
if
(
sourceFile
.
isFile
()
&&
sourceFile
.
exists
())
{
...
@@ -147,7 +152,7 @@ public class CatalogueController {
...
@@ -147,7 +152,7 @@ public class CatalogueController {
catalogueTaskDTO
.
setId
(
null
);
catalogueTaskDTO
.
setId
(
null
);
catalogueTaskDTO
.
setParentId
(
parentId
);
catalogueTaskDTO
.
setParentId
(
parentId
);
catalogueTaskDTO
.
setLeaf
(
true
);
catalogueTaskDTO
.
setLeaf
(
true
);
//catalogueTaskDTO.setDialect("FlinkSql");
//
catalogueTaskDTO.setDialect("FlinkSql");
return
catalogueTaskDTO
;
return
catalogueTaskDTO
;
}
}
...
@@ -178,17 +183,18 @@ public class CatalogueController {
...
@@ -178,17 +183,18 @@ public class CatalogueController {
public
Result
deleteMul
(
@RequestBody
JsonNode
para
)
{
public
Result
deleteMul
(
@RequestBody
JsonNode
para
)
{
if
(
para
.
size
()
>
0
)
{
if
(
para
.
size
()
>
0
)
{
boolean
isAdmin
=
false
;
boolean
isAdmin
=
false
;
List
<
Integer
>
error
=
new
ArrayList
<>();
List
<
String
>
error
=
new
ArrayList
<>();
for
(
final
JsonNode
item
:
para
)
{
for
(
final
JsonNode
item
:
para
)
{
Integer
id
=
item
.
asInt
();
Integer
id
=
item
.
asInt
();
if
(!
catalogueService
.
removeCatalogueAndTaskById
(
id
))
{
List
<
String
>
ids
=
catalogueService
.
removeCatalogueAndTaskById
(
id
);
error
.
add
(
id
);
if
(!
ids
.
isEmpty
())
{
error
.
addAll
(
ids
);
}
}
}
}
if
(
error
.
size
()
==
0
&&
!
isAdmin
)
{
if
(
error
.
size
()
==
0
&&
!
isAdmin
)
{
return
Result
.
succeed
(
"删除成功"
);
return
Result
.
succeed
(
"删除成功"
);
}
else
{
}
else
{
return
Result
.
succeed
(
"删除
部分成功,但"
+
error
.
toString
()
+
"删除失败,共"
+
error
.
size
()
+
"次失败
。"
);
return
Result
.
succeed
(
"删除
失败,请检查作业"
+
error
.
toString
()
+
"状态
。"
);
}
}
}
else
{
}
else
{
return
Result
.
failed
(
"请选择要删除的记录"
);
return
Result
.
failed
(
"请选择要删除的记录"
);
...
...
dlink-admin/src/main/java/com/dlink/service/CatalogueService.java
View file @
7f501245
...
@@ -43,7 +43,7 @@ public interface CatalogueService extends ISuperService<Catalogue> {
...
@@ -43,7 +43,7 @@ public interface CatalogueService extends ISuperService<Catalogue> {
boolean
toRename
(
Catalogue
catalogue
);
boolean
toRename
(
Catalogue
catalogue
);
boolean
removeCatalogueAndTaskById
(
Integer
id
);
List
<
String
>
removeCatalogueAndTaskById
(
Integer
id
);
boolean
moveCatalogue
(
Integer
id
,
Integer
parentId
);
boolean
moveCatalogue
(
Integer
id
,
Integer
parentId
);
...
...
dlink-admin/src/main/java/com/dlink/service/impl/CatalogueServiceImpl.java
View file @
7f501245
...
@@ -27,17 +27,22 @@ import com.dlink.db.service.impl.SuperServiceImpl;
...
@@ -27,17 +27,22 @@ import com.dlink.db.service.impl.SuperServiceImpl;
import
com.dlink.dto.CatalogueTaskDTO
;
import
com.dlink.dto.CatalogueTaskDTO
;
import
com.dlink.mapper.CatalogueMapper
;
import
com.dlink.mapper.CatalogueMapper
;
import
com.dlink.model.Catalogue
;
import
com.dlink.model.Catalogue
;
import
com.dlink.model.JobInstance
;
import
com.dlink.model.JobLifeCycle
;
import
com.dlink.model.JobLifeCycle
;
import
com.dlink.model.JobStatus
;
import
com.dlink.model.Statement
;
import
com.dlink.model.Statement
;
import
com.dlink.model.Task
;
import
com.dlink.model.Task
;
import
com.dlink.model.TaskVersion
;
import
com.dlink.service.CatalogueService
;
import
com.dlink.service.CatalogueService
;
import
com.dlink.service.JobInstanceService
;
import
com.dlink.service.StatementService
;
import
com.dlink.service.StatementService
;
import
com.dlink.service.TaskService
;
import
com.dlink.service.TaskService
;
import
com.dlink.service.TaskVersionService
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -62,10 +67,9 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata
...
@@ -62,10 +67,9 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata
@Autowired
@Autowired
private
TaskService
taskService
;
private
TaskService
taskService
;
@Autowired
@Autowired
private
StatementService
statementService
;
private
JobInstanceService
jobInstanceService
;
@Autowired
@Autowired
private
TaskVersionService
taskVersion
Service
;
private
StatementService
statement
Service
;
@Override
@Override
public
List
<
Catalogue
>
getAllData
()
{
public
List
<
Catalogue
>
getAllData
()
{
...
@@ -134,23 +138,69 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata
...
@@ -134,23 +138,69 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata
}
}
@Override
@Override
public
boolean
removeCatalogueAndTaskById
(
Integer
id
)
{
public
List
<
String
>
removeCatalogueAndTaskById
(
Integer
id
)
{
List
<
String
>
errors
=
new
ArrayList
<>();
Catalogue
catalogue
=
this
.
getById
(
id
);
Catalogue
catalogue
=
this
.
getById
(
id
);
if
(
isNull
(
catalogue
))
{
if
(
isNull
(
catalogue
))
{
return
false
;
errors
.
add
(
id
+
"不存在!"
)
;
}
else
{
}
else
{
if
(
isNotNull
(
catalogue
.
getTaskId
()))
{
if
(
isNotNull
(
catalogue
.
getTaskId
()))
{
taskService
.
removeById
(
catalogue
.
getTaskId
());
Integer
taskId
=
catalogue
.
getTaskId
();
statementService
.
removeById
(
catalogue
.
getTaskId
());
JobInstance
job
=
jobInstanceService
.
getJobInstanceByTaskId
(
taskId
);
List
<
TaskVersion
>
taskVersionList
=
taskVersionService
.
getTaskVersionByTaskId
(
catalogue
.
getTaskId
());
if
(
job
==
null
if
(
taskVersionList
.
size
()
>
0
)
{
||
(
JobStatus
.
FINISHED
.
equals
(
job
.
getStatus
())
taskVersionService
.
removeByIds
(
taskVersionList
);
||
JobStatus
.
FAILED
.
equals
(
job
.
getStatus
())
||
JobStatus
.
CANCELED
.
equals
(
job
.
getStatus
())
||
JobStatus
.
UNKNOWN
.
equals
(
job
.
getStatus
())))
{
taskService
.
removeById
(
taskId
);
statementService
.
removeById
(
taskId
);
this
.
removeById
(
id
);
}
else
{
errors
.
add
(
job
.
getName
());
}
}
}
else
{
List
<
Catalogue
>
all
=
this
.
getAllData
();
Set
<
Catalogue
>
del
=
new
HashSet
<>();
this
.
findAllCatalogueInDir
(
id
,
all
,
del
);
List
<
String
>
actives
=
this
.
analysisActiveCatalogues
(
del
);
if
(
actives
.
isEmpty
())
{
for
(
Catalogue
c
:
del
)
{
taskService
.
removeById
(
c
.
getTaskId
());
statementService
.
removeById
(
c
.
getTaskId
());
this
.
removeById
(
c
.
getId
());
}
}
this
.
removeById
(
id
);
}
else
{
return
true
;
errors
.
addAll
(
actives
)
;
}
}
}
}
}
return
errors
;
}
private
void
findAllCatalogueInDir
(
Integer
id
,
List
<
Catalogue
>
all
,
Set
<
Catalogue
>
del
)
{
List
<
Catalogue
>
relatedList
=
all
.
stream
().
filter
(
catalogue
->
id
.
equals
(
catalogue
.
getId
())
||
id
.
equals
(
catalogue
.
getParentId
()))
.
collect
(
Collectors
.
toList
());
List
<
Catalogue
>
subDirCatalogue
=
relatedList
.
stream
().
filter
(
catalogue
->
catalogue
.
getType
()
==
null
).
collect
(
Collectors
.
toList
());
subDirCatalogue
.
forEach
(
catalogue
->
{
if
(
id
!=
catalogue
.
getId
())
{
findAllCatalogueInDir
(
catalogue
.
getId
(),
all
,
del
);
}
});
del
.
addAll
(
relatedList
);
}
private
List
<
String
>
analysisActiveCatalogues
(
Set
<
Catalogue
>
del
)
{
List
<
Integer
>
actives
=
jobInstanceService
.
listJobInstanceActive
().
stream
().
map
(
JobInstance:
:
getTaskId
)
.
collect
(
Collectors
.
toList
());
List
<
Catalogue
>
activeCatalogue
=
del
.
stream
()
.
filter
(
catalogue
->
catalogue
.
getTaskId
()
!=
null
&&
actives
.
contains
(
catalogue
.
getTaskId
()))
.
collect
(
Collectors
.
toList
());
return
activeCatalogue
.
stream
().
map
(
catalogue
->
taskService
.
getById
(
catalogue
.
getTaskId
()).
getName
())
.
collect
(
Collectors
.
toList
());
}
@Override
@Override
public
boolean
moveCatalogue
(
Integer
id
,
Integer
parentId
)
{
public
boolean
moveCatalogue
(
Integer
id
,
Integer
parentId
)
{
...
@@ -176,13 +226,13 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata
...
@@ -176,13 +226,13 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata
if
(
ObjectUtil
.
isNull
(
oldTask
))
{
if
(
ObjectUtil
.
isNull
(
oldTask
))
{
return
false
;
return
false
;
}
}
//查询作业名称
//
查询作业名称
int
size
=
taskService
.
queryAllSizeByName
(
oldTask
.
getName
());
int
size
=
taskService
.
queryAllSizeByName
(
oldTask
.
getName
());
Task
newTask
=
new
Task
();
Task
newTask
=
new
Task
();
BeanUtil
.
copyProperties
(
oldTask
,
newTask
);
BeanUtil
.
copyProperties
(
oldTask
,
newTask
);
newTask
.
setId
(
null
);
newTask
.
setId
(
null
);
//设置复制后的作业名称为:原名称+自增序列
//
设置复制后的作业名称为:原名称+自增序列
size
=
size
+
1
;
size
=
size
+
1
;
newTask
.
setName
(
oldTask
.
getName
()
+
"_"
+
size
);
newTask
.
setName
(
oldTask
.
getName
()
+
"_"
+
size
);
newTask
.
setAlias
(
oldTask
.
getAlias
()
+
"_"
+
size
);
newTask
.
setAlias
(
oldTask
.
getAlias
()
+
"_"
+
size
);
...
@@ -190,13 +240,14 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata
...
@@ -190,13 +240,14 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata
taskService
.
save
(
newTask
);
taskService
.
save
(
newTask
);
Statement
statementServiceById
=
statementService
.
getById
(
catalogue
.
getTaskId
());
Statement
statementServiceById
=
statementService
.
getById
(
catalogue
.
getTaskId
());
//新建作业的sql语句
//
新建作业的sql语句
Statement
statement
=
new
Statement
();
Statement
statement
=
new
Statement
();
statement
.
setId
(
newTask
.
getId
());
statement
.
setStatement
(
statementServiceById
.
getStatement
());
statement
.
setStatement
(
statementServiceById
.
getStatement
());
statement
.
setId
(
newTask
.
getId
());
statementService
.
save
(
statement
);
statementService
.
save
(
statement
);
Catalogue
one
=
this
.
getOne
(
new
LambdaQueryWrapper
<
Catalogue
>().
eq
(
Catalogue:
:
getTaskId
,
catalogue
.
getTaskId
()));
Catalogue
one
=
this
.
getOne
(
new
LambdaQueryWrapper
<
Catalogue
>().
eq
(
Catalogue:
:
getTaskId
,
catalogue
.
getTaskId
()));
catalogue
.
setName
(
newTask
.
getAlias
());
catalogue
.
setName
(
newTask
.
getAlias
());
catalogue
.
setIsLeaf
(
one
.
getIsLeaf
());
catalogue
.
setIsLeaf
(
one
.
getIsLeaf
());
...
@@ -213,7 +264,8 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata
...
@@ -213,7 +264,8 @@ public class CatalogueServiceImpl extends SuperServiceImpl<CatalogueMapper, Cata
Integer
parentId
=
0
;
Integer
parentId
=
0
;
for
(
int
i
=
0
;
i
<
catalogueNames
.
length
-
1
;
i
++)
{
for
(
int
i
=
0
;
i
<
catalogueNames
.
length
-
1
;
i
++)
{
String
catalogueName
=
catalogueNames
[
i
];
String
catalogueName
=
catalogueNames
[
i
];
Catalogue
catalogue
=
getOne
(
new
QueryWrapper
<
Catalogue
>().
eq
(
"name"
,
catalogueName
).
eq
(
"parent_id"
,
parentId
).
last
(
" limit 1"
));
Catalogue
catalogue
=
getOne
(
new
QueryWrapper
<
Catalogue
>().
eq
(
"name"
,
catalogueName
).
eq
(
"parent_id"
,
parentId
).
last
(
" limit 1"
));
if
(
Asserts
.
isNotNull
(
catalogue
))
{
if
(
Asserts
.
isNotNull
(
catalogue
))
{
parentId
=
catalogue
.
getId
();
parentId
=
catalogue
.
getId
();
continue
;
continue
;
...
...
dlink-web/src/components/Studio/StudioTree/index.tsx
View file @
7f501245
...
@@ -471,7 +471,7 @@ const StudioTree: React.FC<StudioTreeProps> = (props) => {
...
@@ -471,7 +471,7 @@ const StudioTree: React.FC<StudioTreeProps> = (props) => {
<Menu.Item key='Copy'>{l('right.menu.copy')}</Menu.Item>
<Menu.Item key='Copy'>{l('right.menu.copy')}</Menu.Item>
<Menu.Item key='Cut'>{l('right.menu.cut')}</Menu.Item>
<Menu.Item key='Cut'>{l('right.menu.cut')}</Menu.Item>
{cutId && <Menu.Item key='Paste'>{l('right.menu.paste')}</Menu.Item>}
{cutId && <Menu.Item key='Paste'>{l('right.menu.paste')}</Menu.Item>}
<Menu.Item
disabled
>{l('right.menu.delete')}</Menu.Item>
<Menu.Item
key='Delete'
>{l('right.menu.delete')}</Menu.Item>
</>)
</>)
} else {
} else {
menuItems = (<>
menuItems = (<>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment