diff --git a/backend/src/main/java/io/metersphere/track/issue/ZentaoPlatform.java b/backend/src/main/java/io/metersphere/track/issue/ZentaoPlatform.java index 6b7c6d111b..47b8696624 100644 --- a/backend/src/main/java/io/metersphere/track/issue/ZentaoPlatform.java +++ b/backend/src/main/java/io/metersphere/track/issue/ZentaoPlatform.java @@ -430,8 +430,8 @@ public class ZentaoPlatform extends AbstractIssuePlatform { RestTemplate restTemplate = new RestTemplate(); try { String fileUpload = zentaoClient.requestUrl.getFileUpload(); - ResponseEntity responseEntity = restTemplate.exchange(fileUpload + session, - HttpMethod.POST, requestEntity, String.class); + ResponseEntity responseEntity = restTemplate.exchange(fileUpload, HttpMethod.POST, requestEntity, + String.class, "bug", null, session); String body = responseEntity.getBody(); JSONObject obj = JSONObject.parseObject(body); JSONObject data = obj.getJSONObject("data"); @@ -579,8 +579,14 @@ public class ZentaoPlatform extends AbstractIssuePlatform { List allMsAttachments = attachmentService.listMetadata(request); List msAttachmentsName = allMsAttachments.stream().map(FileAttachmentMetadata::getName).collect(Collectors.toList()); JSONObject bugInfo = zentaoClient.getBugById(issue.getPlatformId()); - JSONObject zenFiles = bugInfo.getJSONObject("files"); - // 同步Jira中新的附件 + Object files = bugInfo.get("files"); + JSONObject zenFiles; + if (files instanceof JSONArray && ((JSONArray) files).size() == 0) { + zenFiles = null; + } else { + zenFiles = (JSONObject) files; + } + // 同步禅道中新的附件 if (zenFiles != null) { for (String fileId : zenFiles.keySet()) { JSONObject fileInfo = zenFiles.getJSONObject(fileId); @@ -602,7 +608,7 @@ public class ZentaoPlatform extends AbstractIssuePlatform { } } - // 删除Jira中不存在的附件 + // 删除禅道中不存在的附件 if (CollectionUtils.isNotEmpty(allMsAttachments)) { List deleteMsAttachments = allMsAttachments.stream() .filter(msAttachment -> !znetaoAttachmentsName.contains(msAttachment.getName())).collect(Collectors.toList()); diff --git a/backend/src/main/java/io/metersphere/track/issue/client/ZentaoClient.java b/backend/src/main/java/io/metersphere/track/issue/client/ZentaoClient.java index 8d02ffa00d..2e52b8f4c4 100644 --- a/backend/src/main/java/io/metersphere/track/issue/client/ZentaoClient.java +++ b/backend/src/main/java/io/metersphere/track/issue/client/ZentaoClient.java @@ -226,7 +226,7 @@ public abstract class ZentaoClient extends BaseClient { HttpEntity> requestEntity = new HttpEntity<>(paramMap, authHeader); try { - restTemplate.exchange(requestUrl.getFileUpload(), HttpMethod.POST, requestEntity, + restTemplate.exchange(requestUrl.getFileUpload(), HttpMethod.POST, requestEntity, String.class, objectType, objectId, sessionId); } catch (Exception e) { LogUtil.info("upload zentao attachment error"); diff --git a/backend/src/main/java/io/metersphere/track/issue/client/ZentaoPathInfoClient.java b/backend/src/main/java/io/metersphere/track/issue/client/ZentaoPathInfoClient.java index a0305c7b83..bb224155bf 100644 --- a/backend/src/main/java/io/metersphere/track/issue/client/ZentaoPathInfoClient.java +++ b/backend/src/main/java/io/metersphere/track/issue/client/ZentaoPathInfoClient.java @@ -17,7 +17,7 @@ public class ZentaoPathInfoClient extends ZentaoClient { private static final String USER_GET = "/api-getModel-user-getList?zentaosid="; private static final String BUILDS_GET = "/api-getModel-build-getProductBuildPairs-productID={0}?zentaosid={1}"; private static final String CREATE_META_DATA="/bug-create-{0}.json?zentaosid={1}"; - private static final String FILE_UPLOAD = "/api-getModel-file-saveUpload-{1}-{2}.json?zentaosid={3}"; + private static final String FILE_UPLOAD = "/api-getModel-file-saveUpload-objectType={1},objectID={2}?zentaosid={3}"; private static final String FILE_DELETE = "/file-delete-{1}-.yes.json?zentaosid={2}"; private static final String FILE_DOWNLOAD="/file-download-{1}-.click.json?zentaosid={2}"; private static final String REPLACE_IMG_URL = ""; @@ -48,7 +48,7 @@ public class ZentaoPathInfoClient extends ZentaoClient { request.setCreateMetaData(getUrl(CREATE_META_DATA)); request.setProductGet(getUrl(PRODUCT_GET)); request.setFileDelete(getUrl(FILE_DELETE)); - request.setFileDelete(getUrl(FILE_DOWNLOAD)); + request.setFileDownload(getUrl(FILE_DOWNLOAD)); requestUrl = request; }