Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
holmes
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
QA
holmes
Commits
774fb97d
Commit
774fb97d
authored
Jun 09, 2021
by
黎博
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化
parent
3dd2e2c9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
48 deletions
+68
-48
PipelineController.java
...va/cn/qg/holmes/controller/gitlab/PipelineController.java
+68
-48
No files found.
src/main/java/cn/qg/holmes/controller/gitlab/PipelineController.java
View file @
774fb97d
...
...
@@ -84,28 +84,37 @@ public class PipelineController {
@Transactional
@PostMapping
(
"/add"
)
public
JsonResult
addRobotAndPipeline
(
@RequestBody
DingRobotPipelineVo
dingRobotPipelineVo
)
{
DingRobot
dingRobot
=
dingRobotPipelineVo
.
getDingRobot
();
String
projectName
=
dingRobot
.
getProjectName
();
String
jiraProjectKey
=
dingRobot
.
getJiraProjectKey
();
QueryWrapper
<
DingRobot
>
dingRobotQueryWrapper
=
new
QueryWrapper
<>();
dingRobotQueryWrapper
.
eq
(
"jira_project_key"
,
jiraProjectKey
);
dingRobotQueryWrapper
.
eq
(
"project_name"
,
projectName
);
// 根据jira project key和项目名判断是否已存在
if
(
dingRobotService
.
getOne
(
dingRobotQueryWrapper
)
!=
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"项目已存在"
,
false
);
}
boolean
dingRobotResult
=
dingRobotService
.
save
(
dingRobot
);
if
(!
dingRobotResult
)
{
return
JsonResult
.
buildErrorStateResult
(
"服务器异常,保存失败!"
,
false
);
}
// 获取该robot id,并赋值给pipelineList
DingRobot
dingRobotNew
=
dingRobotService
.
getOne
(
dingRobotQueryWrapper
);
Integer
dingRobotId
=
dingRobotNew
.
getId
();
List
<
Pipeline
>
pipelineList
=
dingRobotPipelineVo
.
getPipelineList
();
for
(
Pipeline
pipeline:
pipelineList
)
{
pipeline
.
setDingRobotId
(
dingRobotId
);
try
{
DingRobot
dingRobot
=
dingRobotPipelineVo
.
getDingRobot
();
String
projectName
=
dingRobot
.
getProjectName
();
String
jiraProjectKey
=
dingRobot
.
getJiraProjectKey
();
QueryWrapper
<
DingRobot
>
dingRobotQueryWrapper
=
new
QueryWrapper
<>();
dingRobotQueryWrapper
.
eq
(
"jira_project_key"
,
jiraProjectKey
);
dingRobotQueryWrapper
.
eq
(
"project_name"
,
projectName
);
// 根据jira project key和项目名判断是否已存在
if
(
dingRobotService
.
getOne
(
dingRobotQueryWrapper
)
!=
null
)
{
return
JsonResult
.
buildErrorStateResult
(
"项目已存在"
,
false
);
}
boolean
dingRobotResult
=
dingRobotService
.
save
(
dingRobot
);
if
(!
dingRobotResult
)
{
return
JsonResult
.
buildErrorStateResult
(
"服务器异常,保存失败!"
,
false
);
}
// 获取该robot id,并赋值给pipelineList
DingRobot
dingRobotNew
=
dingRobotService
.
getOne
(
dingRobotQueryWrapper
);
Integer
dingRobotId
=
dingRobotNew
.
getId
();
List
<
Pipeline
>
pipelineList
=
dingRobotPipelineVo
.
getPipelineList
();
// 判断pipelineList是否为空
if
(
pipelineList
.
size
()
>
0
)
{
for
(
Pipeline
pipeline:
pipelineList
)
{
pipeline
.
setDingRobotId
(
dingRobotId
);
}
pipelineService
.
saveBatch
(
pipelineList
);
}
return
JsonResult
.
buildSuccessResult
(
true
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
JsonResult
.
buildErrorStateResult
(
"新增失败"
,
false
);
}
return
JsonResult
.
buildSuccessResult
(
pipelineService
.
saveBatch
(
pipelineList
));
}
/**
...
...
@@ -116,37 +125,48 @@ public class PipelineController {
@Transactional
@PostMapping
(
"/modify"
)
public
JsonResult
modifyPipeline
(
@RequestBody
DingRobotPipelineVo
dingRobotPipelineVo
)
{
DingRobot
dingRobot
=
dingRobotPipelineVo
.
getDingRobot
();
boolean
dingRobotResult
=
dingRobotService
.
saveOrUpdate
(
dingRobot
);
if
(!
dingRobotResult
)
{
return
JsonResult
.
buildErrorStateResult
(
"修改失败!"
,
false
);
}
Integer
dingRobotId
=
dingRobot
.
getId
();
List
<
Pipeline
>
pipelineList
=
dingRobotPipelineVo
.
getPipelineList
();
QueryWrapper
<
Pipeline
>
pipelineQueryWrapper
=
new
QueryWrapper
<>();
pipelineQueryWrapper
.
eq
(
"ding_robot_id"
,
dingRobotId
);
List
<
Pipeline
>
pipelineListInDb
=
pipelineService
.
list
(
pipelineQueryWrapper
);
// 判断是否有删除的部分
for
(
Pipeline
pipelineDb:
pipelineListInDb
)
{
boolean
flag
=
false
;
for
(
Pipeline
pipeline:
pipelineList
)
{
if
(
pipelineDb
.
getId
().
equals
(
pipeline
.
getId
()))
{
flag
=
true
;
break
;
}
try
{
DingRobot
dingRobot
=
dingRobotPipelineVo
.
getDingRobot
();
boolean
dingRobotResult
=
dingRobotService
.
saveOrUpdate
(
dingRobot
);
if
(!
dingRobotResult
)
{
return
JsonResult
.
buildErrorStateResult
(
"修改失败!"
,
false
);
}
if
(!
flag
)
{
pipelineService
.
removeById
(
pipelineDb
.
getId
());
Integer
dingRobotId
=
dingRobot
.
getId
();
List
<
Pipeline
>
pipelineList
=
dingRobotPipelineVo
.
getPipelineList
();
QueryWrapper
<
Pipeline
>
pipelineQueryWrapper
=
new
QueryWrapper
<>();
pipelineQueryWrapper
.
eq
(
"ding_robot_id"
,
dingRobotId
);
List
<
Pipeline
>
pipelineListInDb
=
pipelineService
.
list
(
pipelineQueryWrapper
);
// 判断是否有删除的部分
if
(
pipelineListInDb
.
size
()
>
0
)
{
for
(
Pipeline
pipelineDb:
pipelineListInDb
)
{
boolean
flag
=
false
;
if
(
pipelineList
.
size
()
>
0
)
{
for
(
Pipeline
pipeline:
pipelineList
)
{
if
(
pipelineDb
.
getId
().
equals
(
pipeline
.
getId
()))
{
flag
=
true
;
break
;
}
}
}
if
(!
flag
)
{
pipelineService
.
removeById
(
pipelineDb
.
getId
());
}
}
}
}
// 判断是否有新增的
for
(
Pipeline
pipeline:
pipelineList
)
{
if
(
pipeline
.
getId
()
==
null
)
{
pipeline
.
setDingRobotId
(
dingRobotId
);
// 判断是否有新增的
for
(
Pipeline
pipeline:
pipelineList
)
{
if
(
pipeline
.
getId
()
==
null
)
{
pipeline
.
setDingRobotId
(
dingRobotId
);
}
}
// 剩下的直接更新
pipelineService
.
saveOrUpdateBatch
(
pipelineList
);
return
JsonResult
.
buildSuccessResult
(
true
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
JsonResult
.
buildErrorStateResult
(
"修改失败!"
,
false
);
}
// 剩下的直接更新
return
JsonResult
.
buildSuccessResult
(
pipelineService
.
saveOrUpdateBatch
(
pipelineList
));
}
/**
...
...
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