Commit 774fb97d authored by 黎博's avatar 黎博

优化

parent 3dd2e2c9
......@@ -84,6 +84,7 @@ public class PipelineController {
@Transactional
@PostMapping("/add")
public JsonResult addRobotAndPipeline(@RequestBody DingRobotPipelineVo dingRobotPipelineVo) {
try {
DingRobot dingRobot = dingRobotPipelineVo.getDingRobot();
String projectName = dingRobot.getProjectName();
String jiraProjectKey = dingRobot.getJiraProjectKey();
......@@ -102,10 +103,18 @@ public class PipelineController {
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);
}
return JsonResult.buildSuccessResult(pipelineService.saveBatch(pipelineList));
pipelineService.saveBatch(pipelineList);
}
return JsonResult.buildSuccessResult(true);
} catch (Exception e) {
e.printStackTrace();
return JsonResult.buildErrorStateResult("新增失败", false);
}
}
/**
......@@ -116,6 +125,7 @@ public class PipelineController {
@Transactional
@PostMapping("/modify")
public JsonResult modifyPipeline(@RequestBody DingRobotPipelineVo dingRobotPipelineVo) {
try {
DingRobot dingRobot = dingRobotPipelineVo.getDingRobot();
boolean dingRobotResult = dingRobotService.saveOrUpdate(dingRobot);
if (!dingRobotResult) {
......@@ -127,18 +137,23 @@ public class PipelineController {
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) {
......@@ -146,7 +161,12 @@ public class PipelineController {
}
}
// 剩下的直接更新
return JsonResult.buildSuccessResult(pipelineService.saveOrUpdateBatch(pipelineList));
pipelineService.saveOrUpdateBatch(pipelineList);
return JsonResult.buildSuccessResult(true);
} catch (Exception e) {
e.printStackTrace();
return JsonResult.buildErrorStateResult("修改失败!", false);
}
}
/**
......
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