From 9ee75314e44e535e726a4377aebe3195a676b996 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Tue, 21 Feb 2023 21:09:57 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E5=85=B3=E8=81=94=E9=9C=80=E6=B1=82AzureDevo?= =?UTF-8?q?ps=E6=B7=BB=E5=8A=A0=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1022724 --user=陈建星 【缺陷管理】github #21633,项目关联devops三方平台,批量关联需求后,tfs平台的需求未全部关联上所选用例 https://www.tapd.cn/55049933/s/1340165 --- .../metersphere/service/TestCaseService.java | 47 +++++++++++++++---- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java b/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java index 07af296351..18ae9c0192 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java @@ -261,19 +261,28 @@ public class TestCaseService { } public void addDemandHyperLink(EditTestCaseRequest request, String type) { + IssuesRequest updateRequest = getIssuesRequest(request); + Project project = baseProjectService.getProjectById(request.getProjectId()); + if (StringUtils.equals(project.getPlatform(), IssuesManagePlatform.AzureDevops.name())) { + doAddDemandHyperLink(request, type, updateRequest, project); + } + } + + private void doAddDemandHyperLink(EditTestCaseRequest request, String type, IssuesRequest updateRequest, Project project) { + updateRequest.setWorkspaceId(project.getWorkspaceId()); + List platformList = getAddPlatforms(updateRequest); + platformList.forEach(platform -> { + platform.updateDemandHyperLink(request, project, type); + }); + } + + private IssuesRequest getIssuesRequest(EditTestCaseRequest request) { IssuesRequest updateRequest = new IssuesRequest(); updateRequest.setId(request.getId()); updateRequest.setResourceId(request.getDemandId()); updateRequest.setProjectId(request.getProjectId()); updateRequest.setTestCaseId(request.getId()); - Project project = baseProjectService.getProjectById(request.getProjectId()); - if (StringUtils.equals(project.getPlatform(), IssuesManagePlatform.AzureDevops.name())) { - updateRequest.setWorkspaceId(project.getWorkspaceId()); - List platformList = getAddPlatforms(updateRequest); - platformList.forEach(platform -> { - platform.updateDemandHyperLink(request, project, type); - }); - } + return updateRequest; } public void addDemandHyperLinkBatch(List testcaseIds, String projectId) { @@ -456,6 +465,10 @@ public class TestCaseService { if (!StringUtils.equals(project.getPlatform(), IssuesManagePlatform.AzureDevops.name())) { return; } + doUpdateThirdPartyIssuesLink(testCase, project); + } + + private void doUpdateThirdPartyIssuesLink(EditTestCaseRequest testCase, Project project) { IssuesRequest issuesRequest = new IssuesRequest(); if (!issuesService.isThirdPartTemplate(project)) { issuesRequest.setDefaultCustomFields(issuesService.getDefaultCustomFields(testCase.getProjectId())); @@ -3121,8 +3134,26 @@ public class TestCaseService { TestCaseExample example = new TestCaseExample(); example.createCriteria().andIdIn(request.getIds()); List testCaseList = testCaseMapper.selectByExample(example); + Project project = null; + if (CollectionUtils.isNotEmpty(testCaseList)) { + project = baseProjectService.getProjectById(testCaseList.get(0).getProjectId()); + } for (TestCase tc : testCaseList) { + + if (project != null && StringUtils.equals(project.getPlatform(), IssuesManagePlatform.AzureDevops.name())) { + EditTestCaseRequest editTestCaseRequest = new EditTestCaseRequest(); + BeanUtils.copyBean(editTestCaseRequest, tc); + try { + doUpdateThirdPartyIssuesLink(editTestCaseRequest, project); + // 同步用例与需求的关联关系 + IssuesRequest updateRequest = getIssuesRequest(editTestCaseRequest); + doAddDemandHyperLink(editTestCaseRequest, "edit", updateRequest, project); + } catch (Exception e) { + LogUtil.error(e); + } + } + tc.setDemandId(demandId); tc.setDemandName(demandName); mapper.updateByPrimaryKey(tc);