Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dlink
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
zhaowei
dlink
Commits
38050864
Commit
38050864
authored
Jun 01, 2021
by
wenmo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
目录作业CRUD
parent
82cbc496
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
320 additions
and
19 deletions
+320
-19
CatalogueController.java
...c/main/java/com/dlink/controller/CatalogueController.java
+28
-3
CatalogueTaskDTO.java
...k-admin/src/main/java/com/dlink/dto/CatalogueTaskDTO.java
+20
-0
Task.java
dlink-admin/src/main/java/com/dlink/model/Task.java
+2
-0
CatalogueService.java
...min/src/main/java/com/dlink/service/CatalogueService.java
+7
-0
CatalogueServiceImpl.java
...ain/java/com/dlink/service/impl/CatalogueServiceImpl.java
+55
-0
UpdateCatalogueForm.tsx
...ents/Studio/StudioTree/components/UpdateCatalogueForm.tsx
+2
-2
UpdateTaskForm.tsx
...omponents/Studio/StudioTree/components/UpdateTaskForm.tsx
+101
-0
data.d.ts
dlink-web/src/components/Studio/StudioTree/data.d.ts
+7
-0
index.tsx
dlink-web/src/components/Studio/StudioTree/index.tsx
+98
-14
No files found.
dlink-admin/src/main/java/com/dlink/controller/CatalogueController.java
View file @
38050864
...
...
@@ -2,6 +2,7 @@ package com.dlink.controller;
import
com.dlink.common.result.ProTableResult
;
import
com.dlink.common.result.Result
;
import
com.dlink.dto.CatalogueTaskDTO
;
import
com.dlink.model.Catalogue
;
import
com.dlink.service.CatalogueService
;
import
com.fasterxml.jackson.databind.JsonNode
;
...
...
@@ -36,9 +37,9 @@ public class CatalogueController {
@PutMapping
public
Result
saveOrUpdate
(
@RequestBody
Catalogue
catalogue
)
throws
Exception
{
if
(
catalogueService
.
saveOrUpdate
(
catalogue
)){
return
Result
.
succeed
(
"
新增
成功"
);
return
Result
.
succeed
(
"
创建
成功"
);
}
else
{
return
Result
.
failed
(
"
新增
失败"
);
return
Result
.
failed
(
"
创建
失败"
);
}
}
...
...
@@ -60,7 +61,7 @@ public class CatalogueController {
List
<
Integer
>
error
=
new
ArrayList
<>();
for
(
final
JsonNode
item
:
para
){
Integer
id
=
item
.
asInt
();
if
(!
catalogueService
.
removeById
(
id
)){
if
(!
catalogueService
.
remove
CatalogueAndTask
ById
(
id
)){
error
.
add
(
id
);
}
}
...
...
@@ -91,4 +92,28 @@ public class CatalogueController {
List
<
Catalogue
>
catalogues
=
catalogueService
.
getAllData
();
return
Result
.
succeed
(
catalogues
,
"获取成功"
);
}
/**
* 创建节点和作业
*/
@PutMapping
(
"/createTask"
)
public
Result
createTask
(
@RequestBody
CatalogueTaskDTO
catalogueTaskDTO
)
throws
Exception
{
if
(
catalogueService
.
createCatalogueAndTask
(
catalogueTaskDTO
)){
return
Result
.
succeed
(
"创建成功"
);
}
else
{
return
Result
.
failed
(
"创建失败"
);
}
}
/**
* 创建节点和作业
*/
@PutMapping
(
"/toRename"
)
public
Result
toRename
(
@RequestBody
Catalogue
catalogue
)
throws
Exception
{
if
(
catalogueService
.
toRename
(
catalogue
)){
return
Result
.
succeed
(
"重命名成功"
);
}
else
{
return
Result
.
failed
(
"重命名失败"
);
}
}
}
dlink-admin/src/main/java/com/dlink/dto/CatalogueTaskDTO.java
0 → 100644
View file @
38050864
package
com
.
dlink
.
dto
;
import
lombok.Getter
;
import
lombok.Setter
;
/**
* CatalogueTaskDTO
*
* @author wenmo
* @since 2021/6/1 20:16
*/
@Getter
@Setter
public
class
CatalogueTaskDTO
{
private
Integer
id
;
private
Integer
parentId
;
private
boolean
isLeaf
;
private
String
name
;
private
String
alias
;
}
dlink-admin/src/main/java/com/dlink/model/Task.java
View file @
38050864
...
...
@@ -43,4 +43,6 @@ public class Task extends SuperEntity{
public
ExecutorSetting
getRemoteExecutorSetting
(){
return
new
ExecutorSetting
(
Executor
.
REMOTE
,
checkPoint
,
parallelism
,
fragment
,
savePointPath
);
}
}
dlink-admin/src/main/java/com/dlink/service/CatalogueService.java
View file @
38050864
package
com
.
dlink
.
service
;
import
com.dlink.db.service.ISuperService
;
import
com.dlink.dto.CatalogueTaskDTO
;
import
com.dlink.model.Catalogue
;
import
java.util.List
;
...
...
@@ -14,4 +15,10 @@ import java.util.List;
public
interface
CatalogueService
extends
ISuperService
<
Catalogue
>
{
List
<
Catalogue
>
getAllData
();
boolean
createCatalogueAndTask
(
CatalogueTaskDTO
catalogueTaskDTO
);
boolean
toRename
(
Catalogue
catalogue
);
boolean
removeCatalogueAndTaskById
(
Integer
id
);
}
dlink-admin/src/main/java/com/dlink/service/impl/CatalogueServiceImpl.java
View file @
38050864
package
com
.
dlink
.
service
.
impl
;
import
com.dlink.assertion.Assert
;
import
com.dlink.db.service.impl.SuperServiceImpl
;
import
com.dlink.dto.CatalogueTaskDTO
;
import
com.dlink.mapper.CatalogueMapper
;
import
com.dlink.model.Catalogue
;
import
com.dlink.model.Task
;
import
com.dlink.service.CatalogueService
;
import
com.dlink.service.TaskService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.List
;
...
...
@@ -16,8 +22,57 @@ import java.util.List;
**/
@Service
public
class
CatalogueServiceImpl
extends
SuperServiceImpl
<
CatalogueMapper
,
Catalogue
>
implements
CatalogueService
{
@Autowired
private
TaskService
taskService
;
@Override
public
List
<
Catalogue
>
getAllData
()
{
return
this
.
list
();
}
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Override
public
boolean
createCatalogueAndTask
(
CatalogueTaskDTO
catalogueTaskDTO
)
{
Task
task
=
new
Task
();
task
.
setName
(
catalogueTaskDTO
.
getName
());
task
.
setAlias
(
catalogueTaskDTO
.
getAlias
());
taskService
.
save
(
task
);
Catalogue
catalogue
=
new
Catalogue
();
catalogue
.
setName
(
catalogueTaskDTO
.
getAlias
());
catalogue
.
setIsLeaf
(
true
);
catalogue
.
setTaskId
(
task
.
getId
());
catalogue
.
setParentId
(
catalogueTaskDTO
.
getParentId
());
return
this
.
save
(
catalogue
);
}
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Override
public
boolean
toRename
(
Catalogue
catalogue
)
{
Catalogue
oldCatalogue
=
this
.
getById
(
catalogue
.
getId
());
if
(
oldCatalogue
==
null
){
return
false
;
}
else
{
Task
task
=
new
Task
();
task
.
setId
(
oldCatalogue
.
getTaskId
());
task
.
setAlias
(
oldCatalogue
.
getName
());
taskService
.
updateById
(
task
);
this
.
updateById
(
catalogue
);
return
true
;
}
}
@Override
public
boolean
removeCatalogueAndTaskById
(
Integer
id
)
{
Catalogue
catalogue
=
this
.
getById
(
id
);
if
(
catalogue
==
null
){
return
false
;
}
else
{
if
(
catalogue
.
getTaskId
()!=
null
)
{
taskService
.
removeById
(
catalogue
.
getTaskId
());
}
this
.
removeById
(
id
);
return
true
;
}
}
}
dlink-web/src/components/Studio/StudioTree/components/UpdateCatalogueForm.tsx
View file @
38050864
...
...
@@ -17,7 +17,7 @@ const formLayout = {
wrapperCol
:
{
span
:
13
},
};
const
UpdateForm
:
React
.
FC
<
UpdateFormProps
>
=
(
props
)
=>
{
const
Update
Catalogue
Form
:
React
.
FC
<
UpdateFormProps
>
=
(
props
)
=>
{
const
[
formVals
,
setFormVals
]
=
useState
<
Partial
<
CatalogueTableListItem
>>
({
id
:
props
.
values
.
id
,
name
:
props
.
values
.
name
,
...
...
@@ -91,4 +91,4 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
);
};
export
default
UpdateForm
;
export
default
Update
Catalogue
Form
;
dlink-web/src/components/Studio/StudioTree/components/UpdateTaskForm.tsx
0 → 100644
View file @
38050864
import
React
,
{
useEffect
,
useState
}
from
'react'
;
import
{
Form
,
Button
,
Input
,
Modal
}
from
'antd'
;
import
type
{
TaskTableListItem
}
from
'../data.d'
;
export
type
UpdateFormProps
=
{
onCancel
:
(
flag
?:
boolean
,
formVals
?:
Partial
<
TaskTableListItem
>
)
=>
void
;
onSubmit
:
(
values
:
Partial
<
TaskTableListItem
>
)
=>
void
;
updateModalVisible
:
boolean
;
isCreate
:
boolean
;
values
:
Partial
<
TaskTableListItem
>
;
};
const
FormItem
=
Form
.
Item
;
const
formLayout
=
{
labelCol
:
{
span
:
7
},
wrapperCol
:
{
span
:
13
},
};
const
UpdateTaskForm
:
React
.
FC
<
UpdateFormProps
>
=
(
props
)
=>
{
const
[
formVals
,
setFormVals
]
=
useState
<
Partial
<
TaskTableListItem
>>
({
id
:
props
.
values
.
id
,
name
:
props
.
values
.
name
,
alias
:
props
.
values
.
alias
,
parentId
:
props
.
values
.
parentId
,
});
const
[
form
]
=
Form
.
useForm
();
const
{
onSubmit
:
handleUpdate
,
onCancel
:
handleUpdateModalVisible
,
updateModalVisible
,
values
,
isCreate
,
}
=
props
;
const
submitForm
=
async
()
=>
{
const
fieldsValue
=
await
form
.
validateFields
();
setFormVals
({...
formVals
,
...
fieldsValue
});
handleUpdate
({...
formVals
,
...
fieldsValue
});
};
const
renderContent
=
()
=>
{
return
(
<>
<
FormItem
name=
"name"
label=
"名称"
rules=
{
[{
required
:
true
,
message
:
'请输入唯一名称!'
}]
}
>
<
Input
placeholder=
"请输入"
/>
</
FormItem
>
<
FormItem
name=
"alias"
label=
"别名"
rules=
{
[{
required
:
true
,
message
:
'请输入别名!'
}]
}
>
<
Input
placeholder=
"请输入"
/>
</
FormItem
>
</>
);
};
const
renderFooter
=
()
=>
{
return
(
<>
<
Button
onClick=
{
()
=>
handleUpdateModalVisible
(
false
,
values
)
}
>
取消
</
Button
>
<
Button
type=
"primary"
onClick=
{
()
=>
submitForm
()
}
>
完成
</
Button
>
</>
);
};
return
(
<
Modal
width=
{
640
}
bodyStyle=
{
{
padding
:
'32px 40px 48px'
}
}
destroyOnClose
title=
{
isCreate
?
'创建新作业'
:
(
'重命名作业-'
+
formVals
.
name
)
}
visible=
{
updateModalVisible
}
footer=
{
renderFooter
()
}
onCancel=
{
()
=>
handleUpdateModalVisible
()
}
>
<
Form
{
...
formLayout
}
form=
{
form
}
initialValues=
{
{
id
:
formVals
.
id
,
name
:
formVals
.
name
,
alias
:
formVals
.
alias
,
parentId
:
formVals
.
parentId
,
}
}
>
{
renderContent
()
}
</
Form
>
</
Modal
>
);
};
export
default
UpdateTaskForm
;
dlink-web/src/components/Studio/StudioTree/data.d.ts
View file @
38050864
...
...
@@ -4,3 +4,10 @@ export type CatalogueTableListItem = {
isLeaf
:
string
,
parentId
:
number
,
};
export
type
TaskTableListItem
=
{
id
:
number
,
name
:
string
,
alias
:
string
,
parentId
:
number
,
};
dlink-web/src/components/Studio/StudioTree/index.tsx
View file @
38050864
import
React
,
{
useEffect
,
useRef
,
useState
}
from
"react"
;
import
{
connect
}
from
"umi"
;
import
{
DownOutlined
,
FrownFilled
,
FrownOutlined
,
MehOutlined
,
SmileOutlined
}
from
"@ant-design/icons"
;
import
{
Tree
,
Input
,
Menu
,
Empty
,
Button
}
from
'antd'
;
import
{
Tree
,
Input
,
Menu
,
Empty
,
Button
,
message
,
Modal
}
from
'antd'
;
import
{
getCatalogueTreeData
}
from
"@/pages/FlinkSqlStudio/service"
;
import
{
convertToTreeData
,
DataType
,
TreeDataNode
}
from
"@/components/Studio/StudioTree/Function"
;
import
style
from
"./index.less"
;
import
{
StateType
}
from
"@/pages/FlinkSqlStudio/model"
;
import
{
handleAddOrUpdate
}
from
"@/components/Common/crud"
;
import
{
handleAddOrUpdate
,
handleRemove
}
from
"@/components/Common/crud"
;
import
UpdateCatalogueForm
from
'./components/UpdateCatalogueForm'
;
import
{
ActionType
}
from
"@ant-design/pro-table"
;
import
UpdateTaskForm
from
"@/components/Studio/StudioTree/components/UpdateTaskForm"
;
const
{
DirectoryTree
}
=
Tree
;
...
...
@@ -45,9 +46,11 @@ const StudioTree: React.FC<StudioTreeProps> = (props) => {
const
[
rightClickNodeTreeItem
,
setRightClickNodeTreeItem
]
=
useState
<
RightClickMenu
>
();
const
{
currentPath
,
dispatch
}
=
props
;
const
[
updateCatalogueModalVisible
,
handleUpdateCatalogueModalVisible
]
=
useState
<
boolean
>
(
false
);
const
[
isCreateCatalogue
,
setIsCreateCatalogue
]
=
useState
<
boolean
>
(
true
);
const
[
updateTaskModalVisible
,
handleUpdateTaskModalVisible
]
=
useState
<
boolean
>
(
false
);
const
[
isCreate
,
setIsCreate
]
=
useState
<
boolean
>
(
true
);
const
[
catalogueFormValues
,
setCatalogueFormValues
]
=
useState
({});
const
actionRef
=
useRef
<
ActionType
>
();
const
[
taskFormValues
,
setTaskFormValues
]
=
useState
({});
const
[
rightClickNode
,
setRightClickNode
]
=
useState
<
TreeDataNode
>
();
const
getTreeData
=
async
()
=>
{
const
result
=
await
getCatalogueTreeData
();
...
...
@@ -56,7 +59,6 @@ const StudioTree: React.FC<StudioTreeProps> = (props) => {
for
(
let
i
=
0
;
i
<
list
.
length
;
i
++
){
list
[
i
].
title
=
list
[
i
].
name
;
list
[
i
].
key
=
list
[
i
].
id
;
list
[
i
].
isLeaf
=!
list
[
i
].
isDir
;
}
setDataList
(
list
);
data
=
convertToTreeData
(
data
,
0
);
...
...
@@ -71,8 +73,69 @@ const StudioTree: React.FC<StudioTreeProps> = (props) => {
};
const
handleMenuClick
=
()
=>
{
const
handleMenuClick
=
(
key
:
string
)
=>
{
setRightClickNodeTreeItem
(
null
);
if
(
key
==
'CreateCatalogue'
){
createCatalogue
(
rightClickNode
);
}
else
if
(
key
==
'CreateTask'
){
createTask
(
rightClickNode
);
}
else
if
(
key
==
'Rename'
){
toRename
(
rightClickNode
);
}
else
if
(
key
==
'Delete'
){
toDelete
(
rightClickNode
);
}
};
const
createCatalogue
=
(
node
:
TreeDataNode
)
=>
{
if
(
!
node
.
isLeaf
)
{
handleUpdateCatalogueModalVisible
(
true
);
setIsCreate
(
true
);
setCatalogueFormValues
({
isLeaf
:
false
,
parentId
:
node
.
id
,
});
getTreeData
();
}
else
{
message
.
error
(
'只能在目录上创建目录'
);
}
};
const
toRename
=
(
node
:
TreeDataNode
)
=>
{
handleUpdateCatalogueModalVisible
(
true
);
setIsCreate
(
false
);
setCatalogueFormValues
({
id
:
node
.
id
,
name
:
node
.
name
,
});
getTreeData
();
};
const
createTask
=
(
node
:
TreeDataNode
)
=>
{
if
(
!
node
.
isLeaf
)
{
handleUpdateTaskModalVisible
(
true
);
setIsCreate
(
true
);
setTaskFormValues
({
parentId
:
node
.
id
,
});
getTreeData
();
}
else
{
message
.
error
(
'只能在目录上创建作业'
);
}
};
const
toDelete
=
(
node
:
TreeDataNode
)
=>
{
let
label
=
(
node
.
taskId
==
null
)?
'目录'
:
'作业'
;
Modal
.
confirm
({
title
:
`删除
${
label
}
`
,
content
:
`确定删除该
${
label
}
吗?`
,
okText
:
'确认'
,
cancelText
:
'取消'
,
onOk
:
async
()
=>
{
await
handleRemove
(
'api/catalogue'
,[
node
]);
getTreeData
();
}
});
};
const
getNodeTreeRightClickMenu
=
()
=>
{
...
...
@@ -84,14 +147,14 @@ const StudioTree: React.FC<StudioTreeProps> = (props) => {
};
const
menu
=
(
<
Menu
onClick=
{
handleMenuClick
}
onClick=
{
({
key
})
=>
handleMenuClick
(
key
)
}
style=
{
tmpStyle
}
className=
{
style
.
right_click_menu
}
>
<
Menu
.
Item
key=
'
1
'
>
{
'创建目录'
}
</
Menu
.
Item
>
<
Menu
.
Item
key=
'
2
'
>
{
'创建作业'
}
</
Menu
.
Item
>
<
Menu
.
Item
key=
'
4'
>
{
'修改
'
}
</
Menu
.
Item
>
<
Menu
.
Item
key=
'
3
'
>
{
'删除'
}
</
Menu
.
Item
>
<
Menu
.
Item
key=
'
CreateCatalogue
'
>
{
'创建目录'
}
</
Menu
.
Item
>
<
Menu
.
Item
key=
'
CreateTask
'
>
{
'创建作业'
}
</
Menu
.
Item
>
<
Menu
.
Item
key=
'
Rename'
>
{
'重命名
'
}
</
Menu
.
Item
>
<
Menu
.
Item
key=
'
Delete
'
>
{
'删除'
}
</
Menu
.
Item
>
</
Menu
>
);
return
(
rightClickNodeTreeItem
==
null
)
?
''
:
menu
;
...
...
@@ -100,7 +163,7 @@ const StudioTree: React.FC<StudioTreeProps> = (props) => {
const
getEmpty
=
()
=>
{
const
empty
=
(<
Empty
image=
{
Empty
.
PRESENTED_IMAGE_SIMPLE
}
><
Button
type=
"primary"
onClick=
{
()
=>
{
handleUpdateCatalogueModalVisible
(
true
);
setIsCreate
Catalogue
(
true
);
setIsCreate
(
true
);
setCatalogueFormValues
({
isLeaf
:
false
,
parentId
:
0
,
...
...
@@ -110,6 +173,7 @@ const StudioTree: React.FC<StudioTreeProps> = (props) => {
};
const
onRightClick
=
(
e
:
any
)
=>
{
setRightClickNode
(
e
.
node
);
setRightClickNodeTreeItem
({
pageX
:
e
.
event
.
pageX
,
pageY
:
e
.
event
.
pageY
,
...
...
@@ -142,7 +206,8 @@ const StudioTree: React.FC<StudioTreeProps> = (props) => {
{
updateCatalogueModalVisible
?
(
<
UpdateCatalogueForm
onSubmit=
{
async
(
value
)
=>
{
const
success
=
await
handleAddOrUpdate
(
'api/catalogue'
,
value
);
const
success
=
await
handleAddOrUpdate
(
isCreate
?
'api/catalogue'
:
'api/catalogue/toRename'
,
value
);
if
(
success
)
{
handleUpdateCatalogueModalVisible
(
false
);
setCatalogueFormValues
({});
...
...
@@ -155,7 +220,26 @@ const StudioTree: React.FC<StudioTreeProps> = (props) => {
}
}
updateModalVisible=
{
updateCatalogueModalVisible
}
values=
{
catalogueFormValues
}
isCreate=
{
isCreateCatalogue
}
isCreate=
{
isCreate
}
/>
)
:
null
}
{
updateTaskModalVisible
?
(
<
UpdateTaskForm
onSubmit=
{
async
(
value
)
=>
{
const
success
=
await
handleAddOrUpdate
(
'api/catalogue/createTask'
,
value
);
if
(
success
)
{
handleUpdateTaskModalVisible
(
false
);
setTaskFormValues
({});
getTreeData
()
}
}
}
onCancel=
{
()
=>
{
handleUpdateTaskModalVisible
(
false
);
setTaskFormValues
({});
}
}
updateModalVisible=
{
updateTaskModalVisible
}
values=
{
taskFormValues
}
isCreate=
{
isCreate
}
/>
)
:
null
}
</
div
>
...
...
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