diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugService.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugService.java index 1788c7d3c7..a108deb3a9 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugService.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugService.java @@ -772,7 +772,16 @@ public class BugService { } } List originalBugs = batchBugMapper.selectByExample(bugExample); - Map msOriginalBugMap = originalBugs.stream().collect(Collectors.toMap(Bug::getPlatformBugId, bug -> bug)); + Map msOriginalBugMap = new HashMap<>(0); + List syncToDeleteIds = new ArrayList<>(); + originalBugs.forEach(originalBug -> { + if (!msOriginalBugMap.containsKey(originalBug.getPlatformBugId())) { + msOriginalBugMap.put(originalBug.getPlatformBugId(), originalBug); + } else { + // 相同的缺陷, 不重复同步, 删除 + syncToDeleteIds.add(originalBug.getId()); + } + }); // 获取原始缺陷的模板字段信息(同步更新缺陷使用) List templateIds = originalBugs.stream().map(Bug::getTemplateId).distinct().toList(); List templateCustomsFields = baseTemplateCustomFieldService.getByTemplateIds(templateIds); @@ -855,7 +864,7 @@ public class BugService { execSyncAll(project, syncAllBugRequest); // 删除缺陷在后置方法处理完再执行 - List syncToDeleteIds = originalBugs.stream().filter(msOriginalBug -> !allSyncIds.get().contains(msOriginalBug.getPlatformBugId())).map(Bug::getId).toList(); + syncToDeleteIds.addAll(originalBugs.stream().filter(msOriginalBug -> !allSyncIds.get().contains(msOriginalBug.getPlatformBugId())).map(Bug::getId).toList()); if (CollectionUtils.isNotEmpty(syncToDeleteIds)) { syncCount.addAndGet(syncToDeleteIds.size()); // 删除缺陷(单独处理)