From 5f860faefe15bffa9a46010bd5773392f405bc64 Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Thu, 13 Oct 2022 11:51:09 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E7=BC=BA=E9=99=B7=E4=B8=ADMD=E6=8E=A7=E4=BB=B6=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IssueProxyResourceController.java | 5 ++-- .../io/metersphere/service/IssuesService.java | 28 +++++++++++++++++++ .../wapper/IssueProxyResourceService.java | 6 ++-- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/test-track/backend/src/main/java/io/metersphere/controller/IssueProxyResourceController.java b/test-track/backend/src/main/java/io/metersphere/controller/IssueProxyResourceController.java index 601a810f7a..cc52eacfdd 100644 --- a/test-track/backend/src/main/java/io/metersphere/controller/IssueProxyResourceController.java +++ b/test-track/backend/src/main/java/io/metersphere/controller/IssueProxyResourceController.java @@ -16,7 +16,8 @@ public class IssueProxyResourceController { IssueProxyResourceService issueProxyResourceService; @GetMapping(value = "/md/get/url") - public ResponseEntity getFileByUrl(@RequestParam ("url") String url, @RequestParam (value = "platform", required = false) String platform) { - return issueProxyResourceService.getMdImageByUrl(url, platform); + public ResponseEntity getFileByUrl(@RequestParam ("url") String url, @RequestParam (value = "platform", required = false) String platform, + @RequestParam ("project_id") String projectId, @RequestParam ("workspace_id") String workspaceId) { + return issueProxyResourceService.getMdImageByUrl(url, platform, projectId, workspaceId); } } diff --git a/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java b/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java index 883e8b63ef..7e5094ca8a 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/IssuesService.java @@ -511,6 +511,8 @@ public class IssuesService { item.setCaseCount(caseIdSet.size()); }); buildCustomField(issues); + //处理MD图片链接内容 + handleJiraIssueMdUrl(request.getWorkspaceId(), request.getProjectId(), issues); return issues; } @@ -538,6 +540,32 @@ public class IssuesService { data.setFields(fields); } + private void handleJiraIssueMdUrl(String workPlaceId, String projectId, List issues) { + issues.forEach(issue -> { + if (StringUtils.isNotEmpty(issue.getDescription()) && issue.getDescription().contains("platform=Jira&")) { + issue.setDescription(replaceJiraMdUrlParam(issue.getDescription(), workPlaceId, projectId)); + } + if (StringUtils.isNotEmpty(issue.getCustomFields()) && issue.getCustomFields().contains("platform=Jira&")) { + issue.setCustomFields(replaceJiraMdUrlParam(issue.getCustomFields(), workPlaceId, projectId)); + } + if (CollectionUtils.isNotEmpty(issue.getFields())) { + issue.getFields().forEach(field -> { + if (StringUtils.isNotEmpty(field.getTextValue()) && field.getTextValue().contains("platform=Jira&")) { + field.setTextValue(replaceJiraMdUrlParam(field.getTextValue(), workPlaceId, projectId)); + } + if (StringUtils.isNotEmpty(field.getValue()) && field.getValue().contains("platform=Jira&")) { + field.setValue(replaceJiraMdUrlParam(field.getValue(), workPlaceId, projectId)); + } + }); + } + }); + } + + private String replaceJiraMdUrlParam(String url, String workspaceId, String projectId) { + return url.replaceAll("platform=Jira&", + "platform=Jira&project_id=" + projectId + "&workspace_id=" + workspaceId + "&"); + } + private Map getPlanMap(List issues) { List resourceIds = issues.stream().map(IssuesDao::getResourceId) .filter(Objects::nonNull) diff --git a/test-track/backend/src/main/java/io/metersphere/service/wapper/IssueProxyResourceService.java b/test-track/backend/src/main/java/io/metersphere/service/wapper/IssueProxyResourceService.java index 4da35d0a32..884e4c548f 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/wapper/IssueProxyResourceService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/wapper/IssueProxyResourceService.java @@ -29,14 +29,14 @@ public class IssueProxyResourceService { * @param platform * @return */ - public ResponseEntity getMdImageByUrl(String url, String platform) { + public ResponseEntity getMdImageByUrl(String url, String platform, String projectId, String workspaceId) { if (url.contains("md/get/url")) { MSException.throwException(Translator.get("invalid_parameter")); } if (StringUtils.isNotBlank(platform)) { IssuesRequest issuesRequest = new IssuesRequest(); - issuesRequest.setProjectId(SessionUtils.getCurrentProjectId()); - issuesRequest.setWorkspaceId(SessionUtils.getCurrentWorkspaceId()); + issuesRequest.setProjectId(projectId); + issuesRequest.setWorkspaceId(workspaceId); return IssueFactory.createPlatform(platform, issuesRequest) .proxyForGet(url, byte[].class); }