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); }