From 8e3bf3d0872d4c7217f135816a62d596a7911bd2 Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Sat, 27 Jan 2024 15:18:02 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E5=8A=9F=E8=83=BD=E7=94=A8=E4=BE=8B):?= =?UTF-8?q?=20=E5=85=B3=E8=81=94=E9=9C=80=E6=B1=82=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E7=88=B6=E5=AD=90=E5=B1=82=E7=BA=A7&&=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E5=AD=97=E6=AE=B5=E6=90=9C=E7=B4=A2=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/reponse/PlatformDemandDTO.java | 4 + .../dto/request/DemandPageRequest.java | 3 +- .../io/metersphere/dto/BugProviderDTO.java | 5 +- .../request/AssociateBugPageRequest.java | 4 + .../bug/controller/BugController.java | 4 +- .../bug/provider/AssociateBugProvider.java | 35 +++- .../bug/service/BugAttachmentService.java | 152 +++++++++++++-- .../bug/service/BugCommonService.java | 103 ++++++++++ .../bug/service/BugNoticeService.java | 4 +- .../metersphere/bug/service/BugService.java | 91 ++------- .../bug/service/BugSyncExtraService.java | 179 +----------------- .../controller/AssociateBugProviderTests.java | 1 + .../BugAttachmentControllerTests.java | 10 +- .../bug/service/BugSyncExtraServiceTests.java | 10 +- .../service/FunctionalCaseDemandService.java | 2 +- .../FunctionalTestCaseControllerTests.java | 1 + 16 files changed, 319 insertions(+), 289 deletions(-) create mode 100644 backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugCommonService.java diff --git a/backend/framework/plugin/plugin-platform-sdk/src/main/java/io/metersphere/plugin/platform/dto/reponse/PlatformDemandDTO.java b/backend/framework/plugin/plugin-platform-sdk/src/main/java/io/metersphere/plugin/platform/dto/reponse/PlatformDemandDTO.java index 46ddb479ce..8d076fc3fd 100644 --- a/backend/framework/plugin/plugin-platform-sdk/src/main/java/io/metersphere/plugin/platform/dto/reponse/PlatformDemandDTO.java +++ b/backend/framework/plugin/plugin-platform-sdk/src/main/java/io/metersphere/plugin/platform/dto/reponse/PlatformDemandDTO.java @@ -35,6 +35,10 @@ public class PlatformDemandDTO { * 需求地址 */ private String demandUrl; + /** + * 子需求集合 + */ + private List children; /** * 自定义字段 */ diff --git a/backend/framework/plugin/plugin-platform-sdk/src/main/java/io/metersphere/plugin/platform/dto/request/DemandPageRequest.java b/backend/framework/plugin/plugin-platform-sdk/src/main/java/io/metersphere/plugin/platform/dto/request/DemandPageRequest.java index 5d67e6bd2a..b3f7f5fb99 100644 --- a/backend/framework/plugin/plugin-platform-sdk/src/main/java/io/metersphere/plugin/platform/dto/request/DemandPageRequest.java +++ b/backend/framework/plugin/plugin-platform-sdk/src/main/java/io/metersphere/plugin/platform/dto/request/DemandPageRequest.java @@ -2,6 +2,7 @@ package io.metersphere.plugin.platform.dto.request; import lombok.Data; +import java.util.List; import java.util.Map; @Data @@ -20,7 +21,7 @@ public class DemandPageRequest { /** * 筛选条件 */ - private Map filter; + private Map> filter; /** * 开始页码 diff --git a/backend/framework/provider/src/main/java/io/metersphere/dto/BugProviderDTO.java b/backend/framework/provider/src/main/java/io/metersphere/dto/BugProviderDTO.java index 0a90a33e9e..890193fddb 100644 --- a/backend/framework/provider/src/main/java/io/metersphere/dto/BugProviderDTO.java +++ b/backend/framework/provider/src/main/java/io/metersphere/dto/BugProviderDTO.java @@ -28,12 +28,15 @@ public class BugProviderDTO implements Serializable { @Schema(description = "处理人") private String handleUser; - @Schema(description = "处理人姓名") + @Schema(description = "处理人名称") private String handleUserName; @Schema(description = "缺陷状态") private String status; + @Schema(description = "缺陷状态名称") + private String statusName; + @Schema(description = "标签") private List tags; diff --git a/backend/framework/provider/src/main/java/io/metersphere/request/AssociateBugPageRequest.java b/backend/framework/provider/src/main/java/io/metersphere/request/AssociateBugPageRequest.java index 375dce4292..90453f8b47 100644 --- a/backend/framework/provider/src/main/java/io/metersphere/request/AssociateBugPageRequest.java +++ b/backend/framework/provider/src/main/java/io/metersphere/request/AssociateBugPageRequest.java @@ -24,6 +24,10 @@ public class AssociateBugPageRequest extends BaseProviderCondition { @NotBlank(message = "{functional_case.id.not_blank}") private String caseId; + @Schema(description = "项目ID", requiredMode = Schema.RequiredMode.REQUIRED) + @NotBlank(message = "{functional_case.project_id.not_blank}") + private String projectId; + @Min(value = 1, message = "当前页码必须大于0") @Schema(description = "当前页码") diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/controller/BugController.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/controller/BugController.java index 15160d5391..b246e02fda 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/controller/BugController.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/controller/BugController.java @@ -50,6 +50,8 @@ public class BugController { @Resource private BugService bugService; @Resource + private BugCommonService bugCommonService; + @Resource private BugSyncService bugSyncService; @Resource private BugStatusService bugStatusService; @@ -77,7 +79,7 @@ public class BugController { @RequiresPermissions(PermissionConstants.PROJECT_BUG_READ) @CheckOwner(resourceId = "#projectId", resourceType = "project") public List getHeaderHandleOption(@PathVariable String projectId) { - return bugService.getHeaderHandlerOption(projectId); + return bugCommonService.getHeaderHandlerOption(projectId); } @PostMapping("/page") diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/provider/AssociateBugProvider.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/provider/AssociateBugProvider.java index 840c46b11b..e193583d4c 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/provider/AssociateBugProvider.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/provider/AssociateBugProvider.java @@ -5,8 +5,11 @@ import io.metersphere.bug.domain.BugRelationCase; import io.metersphere.bug.mapper.BugRelationCaseMapper; import io.metersphere.bug.mapper.ExtBugMapper; import io.metersphere.bug.mapper.ExtBugRelateCaseMapper; +import io.metersphere.bug.service.BugCommonService; import io.metersphere.bug.service.BugRelateCaseCommonService; +import io.metersphere.bug.service.BugStatusService; import io.metersphere.dto.BugProviderDTO; +import io.metersphere.plugin.platform.dto.SelectOption; import io.metersphere.provider.BaseAssociateBugProvider; import io.metersphere.request.AssociateBugPageRequest; import io.metersphere.request.AssociateBugRequest; @@ -24,6 +27,11 @@ import java.util.List; @Service public class AssociateBugProvider implements BaseAssociateBugProvider { + + @Resource + private BugCommonService bugCommonService; + @Resource + private BugStatusService bugStatusService; @Resource private ExtBugMapper extBugMapper; @Resource @@ -36,8 +44,8 @@ public class AssociateBugProvider implements BaseAssociateBugProvider { @Override public List getBugList(String sourceType, String sourceName, String bugColumnName, BugPageProviderRequest bugPageProviderRequest) { - return extBugMapper.listByProviderRequest(sourceType, sourceName, bugColumnName, bugPageProviderRequest, false); - //TODO 需要转义状态和处理人属性 + List associateBugs = extBugMapper.listByProviderRequest(sourceType, sourceName, bugColumnName, bugPageProviderRequest, false); + return buildAssociateBugs(associateBugs, bugPageProviderRequest.getProjectId()); } @Override @@ -78,14 +86,33 @@ public class AssociateBugProvider implements BaseAssociateBugProvider { @Override public List hasAssociateBugPage(AssociateBugPageRequest request) { List associateBugs = extBugRelateCaseMapper.getAssociateBugs(request, request.getSortString()); - //TODO 需要转义状态和处理人属性 - associateBugs.stream().forEach(item -> { + associateBugs.forEach(item -> { if (StringUtils.isNotBlank(item.getTestPlanName())) { item.setSource(Translator.get("test_plan_relate")); } else { item.setSource(Translator.get("direct_related")); } }); + return buildAssociateBugs(associateBugs, request.getProjectId()); + } + + /** + * 关联缺陷列表数据处理 + * @param associateBugs 关联缺陷 + * @param projectId 项目ID + * @return 关联缺陷列表 + */ + private List buildAssociateBugs(List associateBugs, String projectId) { + List headerHandlerOption = bugCommonService.getHeaderHandlerOption(projectId); + List statusOption = bugStatusService.getHeaderStatusOption(projectId); + associateBugs.forEach(item -> { + headerHandlerOption.stream().filter(option -> StringUtils.equals(option.getValue(), item.getHandleUser())).findFirst().ifPresent(option -> { + item.setHandleUserName(option.getText()); + }); + statusOption.stream().filter(option -> StringUtils.equals(option.getValue(), item.getStatus())).findFirst().ifPresent(option -> { + item.setStatusName(option.getText()); + }); + }); return associateBugs; } } diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugAttachmentService.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugAttachmentService.java index 899aad5757..28a5961c51 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugAttachmentService.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugAttachmentService.java @@ -12,8 +12,10 @@ import io.metersphere.bug.enums.BugAttachmentSourceType; import io.metersphere.bug.enums.BugPlatform; import io.metersphere.bug.mapper.BugLocalAttachmentMapper; import io.metersphere.bug.mapper.BugMapper; +import io.metersphere.plugin.platform.dto.PlatformAttachment; import io.metersphere.plugin.platform.dto.request.SyncAttachmentToPlatformRequest; import io.metersphere.plugin.platform.enums.SyncAttachmentType; +import io.metersphere.plugin.platform.spi.Platform; import io.metersphere.project.domain.FileAssociation; import io.metersphere.project.domain.FileAssociationExample; import io.metersphere.project.domain.FileMetadata; @@ -27,6 +29,7 @@ import io.metersphere.project.mapper.FileMetadataMapper; import io.metersphere.project.service.FileAssociationService; import io.metersphere.project.service.FileMetadataService; import io.metersphere.project.service.FileService; +import io.metersphere.project.service.ProjectApplicationService; import io.metersphere.sdk.constants.DefaultRepositoryDir; import io.metersphere.sdk.constants.StorageType; import io.metersphere.sdk.exception.MSException; @@ -42,10 +45,10 @@ import jakarta.annotation.Resource; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Lazy; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import org.springframework.util.unit.DataSize; @@ -55,10 +58,7 @@ import java.io.File; import java.io.IOException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -74,14 +74,13 @@ public class BugAttachmentService { @Resource private FileMetadataService fileMetadataService; @Resource - @Lazy - private BugSyncExtraService bugSyncExtraService; - @Resource private FileAssociationMapper fileAssociationMapper; @Resource private FileAssociationService fileAssociationService; @Resource private BugLocalAttachmentMapper bugLocalAttachmentMapper; + @Resource + private ProjectApplicationService projectApplicationService; @Value("50MB") private DataSize maxFileSize; @@ -161,7 +160,7 @@ public class BugAttachmentService { // 同步至第三方(异步调用) if (!StringUtils.equals(bug.getPlatform(), BugPlatform.LOCAL.getName())) { - bugSyncExtraService.syncAttachmentToPlatform(platformAttachments, request.getProjectId(), tempFileDir); + syncAttachmentToPlatform(platformAttachments, request.getProjectId(), tempFileDir); } } @@ -187,7 +186,7 @@ public class BugAttachmentService { } // 同步至第三方(异步调用) if (!StringUtils.equals(bug.getPlatform(), BugPlatform.LOCAL.getName())) { - bugSyncExtraService.syncAttachmentToPlatform(platformAttachments, request.getProjectId(), tempFileDir); + syncAttachmentToPlatform(platformAttachments, request.getProjectId(), tempFileDir); } } @@ -254,7 +253,7 @@ public class BugAttachmentService { List syncLinkFiles = uploadLinkFile(bug.getId(), bug.getPlatformBugId(), request.getProjectId(), tempFileDir, List.of(upgradeFileId), currentUser, bug.getPlatform(), true); List platformAttachments = Stream.concat(syncUnlinkFiles.stream(), syncLinkFiles.stream()).toList(); if (!StringUtils.equals(bug.getPlatform(), BugPlatform.LOCAL.getName())) { - bugSyncExtraService.syncAttachmentToPlatform(platformAttachments, request.getProjectId(), tempFileDir); + syncAttachmentToPlatform(platformAttachments, request.getProjectId(), tempFileDir); } return upgradeFileId; } @@ -286,6 +285,137 @@ public class BugAttachmentService { return fileId; } + /** + * 同步附件到平台 + * @param platformAttachments 平台附件参数 + * @param projectId 项目ID + * @param tmpFilePath 临时文件路径 + */ + @Async + public void syncAttachmentToPlatform(List platformAttachments, String projectId, File tmpFilePath) { + // 平台缺陷需同步附件 + Platform platform = projectApplicationService.getPlatform(projectId, true); + platformAttachments.forEach(platform::syncAttachmentToPlatform); + tmpFilePath.deleteOnExit(); + } + + /** + * 同步平台附件到MS + * @param platform 平台对象 + * @param attachmentMap 平台附件缺陷集合 + * @param projectId 项目ID + */ + @Async + public void syncAttachmentToMs(Platform platform, Map> attachmentMap, String projectId) { + for (String bugId : attachmentMap.keySet()) { + List syncAttachments = attachmentMap.get(bugId); + // 获取所有MS附件 + Set platformAttachmentSet = new HashSet<>(); + List allBugFiles = getAllBugFiles(bugId); + Set attachmentsNameSet = allBugFiles.stream().map(BugFileDTO::getFileName).collect(Collectors.toSet()); + for (PlatformAttachment syncAttachment : syncAttachments) { + String fileName = syncAttachment.getFileName(); + String fileKey = syncAttachment.getFileKey(); + platformAttachmentSet.add(fileName); + if (!attachmentsNameSet.contains(fileName)) { + saveSyncAttachmentToMs(platform, bugId, fileName, fileKey, projectId); + } + } + + // 删除Jira中不存在的附件 + deleteSyncAttachmentFromMs(platformAttachmentSet, allBugFiles, bugId, projectId); + } + } + + /** + * 保存同步附件到MS + * @param platform 平台对象 + * @param bugId 缺陷ID + * @param fileName 附件名称 + * @param fileKey 附件唯一Key + * @param projectId 项目ID + */ + public void saveSyncAttachmentToMs(Platform platform, String bugId, String fileName, String fileKey, String projectId) { + try { + platform.getAttachmentContent(fileKey, (in) -> { + if (in == null) { + return; + } + String fileId = IDGenerator.nextStr(); + byte[] bytes; + try { + // upload platform attachment to minio + bytes = in.readAllBytes(); + FileCenter.getDefaultRepository().saveFile(bytes, buildBugFileRequest(projectId, bugId, fileId, fileName)); + } catch (Exception e) { + throw new MSException(e.getMessage()); + } + // save bug attachment relation + BugLocalAttachment localAttachment = new BugLocalAttachment(); + localAttachment.setId(IDGenerator.nextStr()); + localAttachment.setBugId(bugId); + localAttachment.setFileId(fileId); + localAttachment.setFileName(fileName); + localAttachment.setSize((long) bytes.length); + localAttachment.setCreateTime(System.currentTimeMillis()); + localAttachment.setCreateUser("admin"); + localAttachment.setSource(BugAttachmentSourceType.ATTACHMENT.name()); + bugLocalAttachmentMapper.insert(localAttachment); + }); + } catch (Exception e) { + LogUtils.error(e.getMessage()); + throw new MSException(e.getMessage()); + } + } + + /** + * 删除MS中不存在的平台附件 + * @param platformAttachmentSet 已处理的平台附件集合 + * @param allMsAttachments 所有MS附件集合 + * @param bugId 缺陷ID + * @param projectId 项目ID + */ + public void deleteSyncAttachmentFromMs(Set platformAttachmentSet, List allMsAttachments, String bugId, String projectId) { + try { + // 删除MS中不存在的平台附件 + if (!CollectionUtils.isEmpty(allMsAttachments)) { + List deleteMsAttachments = allMsAttachments.stream() + .filter(msAttachment -> !platformAttachmentSet.contains(msAttachment.getFileName())) + .toList(); + List unLinkIds = new ArrayList<>(); + List deleteLocalIds = new ArrayList<>(); + deleteMsAttachments.forEach(deleteMsFile -> { + if (deleteMsFile.getAssociated()) { + unLinkIds.add(deleteMsFile.getRefId()); + } else { + deleteLocalIds.add(deleteMsFile.getRefId()); + } + }); + if (!CollectionUtils.isEmpty(unLinkIds)) { + FileAssociationExample example = new FileAssociationExample(); + example.createCriteria().andIdIn(unLinkIds); + fileAssociationMapper.deleteByExample(example); + } + if (!CollectionUtils.isEmpty(deleteLocalIds)) { + Map localFileMap = deleteMsAttachments.stream().collect(Collectors.toMap(BugFileDTO::getRefId, f -> f)); + deleteLocalIds.forEach(deleteLocalId -> { + try { + BugFileDTO bugFileDTO = localFileMap.get(deleteLocalId); + FileCenter.getDefaultRepository().delete(buildBugFileRequest(projectId, bugId, bugFileDTO.getFileId(), bugFileDTO.getFileName())); + } catch (Exception e) { + throw new MSException(e.getMessage()); + } + }); + BugLocalAttachmentExample example = new BugLocalAttachmentExample(); + example.createCriteria().andIdIn(deleteLocalIds); + bugLocalAttachmentMapper.deleteByExample(example); + } + } + } catch (Exception e) { + LogUtils.error(e.getMessage()); + throw new MSException(e.getMessage()); + } + } /** * 获取本地文件字节流 diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugCommonService.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugCommonService.java new file mode 100644 index 0000000000..90f141c302 --- /dev/null +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugCommonService.java @@ -0,0 +1,103 @@ +package io.metersphere.bug.service; + +import io.metersphere.bug.dto.BugTemplateInjectField; +import io.metersphere.bug.enums.BugPlatform; +import io.metersphere.bug.enums.BugTemplateCustomField; +import io.metersphere.plugin.platform.dto.SelectOption; +import io.metersphere.plugin.platform.dto.request.GetOptionRequest; +import io.metersphere.plugin.platform.spi.AbstractPlatformPlugin; +import io.metersphere.plugin.platform.spi.Platform; +import io.metersphere.project.dto.ProjectUserDTO; +import io.metersphere.project.request.ProjectMemberRequest; +import io.metersphere.project.service.ProjectApplicationService; +import io.metersphere.project.service.ProjectMemberService; +import io.metersphere.sdk.util.JSON; +import io.metersphere.system.domain.ServiceIntegration; +import io.metersphere.system.service.PlatformPluginService; +import io.metersphere.system.service.PluginLoadService; +import jakarta.annotation.Resource; +import org.apache.commons.collections4.ListUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +@Service +@Transactional(rollbackFor = Exception.class) +public class BugCommonService { + + @Resource + private PluginLoadService pluginLoadService; + @Resource + private ProjectMemberService projectMemberService; + @Resource + private PlatformPluginService platformPluginService; + @Resource + private ProjectApplicationService projectApplicationService; + + /** + * 获取表头处理人选项 + * @param projectId 项目ID + * @return 处理人选项集合 + */ + public List getHeaderHandlerOption(String projectId) { + String platformName = projectApplicationService.getPlatformName(projectId); + // 需要校验服务集成是否开启 + ServiceIntegration serviceIntegration = projectApplicationService.getPlatformServiceIntegrationWithSyncOrDemand(projectId, true); + if (StringUtils.equals(platformName, BugPlatform.LOCAL.getName())) { + // Local处理人 + return getLocalHandlerOption(projectId); + } else { + // 第三方平台(Local处理人 && 平台处理人) + List localHandlerOption = getLocalHandlerOption(projectId); + // 获取插件中自定义的注入字段(处理人) + Platform platform = platformPluginService.getPlatform(serviceIntegration.getPluginId(), serviceIntegration.getOrganizationId(), + new String(serviceIntegration.getConfiguration())); + List platformHandlerOption = new ArrayList<>(); + List platformInjectFields = getPlatformInjectFields(projectId); + for (BugTemplateInjectField injectField : platformInjectFields) { + if (StringUtils.equals(injectField.getKey(), BugTemplateCustomField.HANDLE_USER.getId())) { + GetOptionRequest request = new GetOptionRequest(); + request.setOptionMethod(injectField.getOptionMethod()); + request.setProjectConfig(projectApplicationService.getProjectBugThirdPartConfig(projectId)); + platformHandlerOption = platform.getFormOptions(request); + } + } + return ListUtils.union(localHandlerOption, platformHandlerOption); + } + } + + /** + * 项目成员选项(处理人) + * @param projectId 项目ID + * @return 处理人选项集合 + */ + public List getLocalHandlerOption(String projectId) { + ProjectMemberRequest request = new ProjectMemberRequest(); + request.setProjectId(projectId); + List projectMembers = projectMemberService.listMember(request); + return projectMembers.stream().map(user -> { + SelectOption option = new SelectOption(); + option.setText(user.getName()); + option.setValue(user.getId()); + return option; + }).toList(); + } + + /** + * 获取平台注入的字段 + * @param projectId 项目ID + * @return 注入的字段集合 + */ + public List getPlatformInjectFields(String projectId) { + // 获取插件中自定义的注入字段(处理人) + ServiceIntegration serviceIntegration = projectApplicationService.getPlatformServiceIntegrationWithSyncOrDemand(projectId, true); + AbstractPlatformPlugin platformPlugin = (AbstractPlatformPlugin) pluginLoadService.getMsPluginManager().getPlugin(serviceIntegration.getPluginId()).getPlugin(); + Object scriptContent = pluginLoadService.getPluginScriptContent(serviceIntegration.getPluginId(), platformPlugin.getProjectBugTemplateInjectField()); + String injectFields = JSON.toJSONString(((Map) scriptContent).get("injectFields")); + return JSON.parseArray(injectFields, BugTemplateInjectField.class); + } +} diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugNoticeService.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugNoticeService.java index dd8ceebf15..4c18927c5f 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugNoticeService.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugNoticeService.java @@ -37,7 +37,7 @@ public class BugNoticeService { @Resource private UserMapper userMapper; @Resource - private BugService bugService; + private BugCommonService bugCommonService; @Resource private BugStatusService bugStatusService; @Resource @@ -133,7 +133,7 @@ public class BugNoticeService { * @return 处理人集合 */ private Map getHandleMap(String projectId) { - List handlerOption = bugService.getHeaderHandlerOption(projectId); + List handlerOption = bugCommonService.getHeaderHandlerOption(projectId); return handlerOption.stream().collect(Collectors.toMap(SelectOption::getValue, SelectOption::getText)); } } 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 3ae9e20679..81a8c22e54 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 @@ -18,16 +18,13 @@ import io.metersphere.plugin.platform.dto.reponse.PlatformBugUpdateDTO; import io.metersphere.plugin.platform.dto.reponse.PlatformCustomFieldItemDTO; import io.metersphere.plugin.platform.dto.request.*; import io.metersphere.plugin.platform.enums.SyncAttachmentType; -import io.metersphere.plugin.platform.spi.AbstractPlatformPlugin; import io.metersphere.plugin.platform.spi.Platform; import io.metersphere.project.domain.*; import io.metersphere.project.dto.ProjectTemplateOptionDTO; -import io.metersphere.project.dto.ProjectUserDTO; import io.metersphere.project.dto.filemanagement.FileLogRecord; import io.metersphere.project.mapper.FileAssociationMapper; import io.metersphere.project.mapper.FileMetadataMapper; import io.metersphere.project.mapper.ProjectMapper; -import io.metersphere.project.request.ProjectMemberRequest; import io.metersphere.project.service.*; import io.metersphere.sdk.constants.*; import io.metersphere.sdk.exception.MSException; @@ -47,7 +44,10 @@ import io.metersphere.system.log.dto.LogDTO; import io.metersphere.system.log.service.OperationLogService; import io.metersphere.system.mapper.BaseUserMapper; import io.metersphere.system.mapper.TemplateMapper; -import io.metersphere.system.service.*; +import io.metersphere.system.service.BaseTemplateCustomFieldService; +import io.metersphere.system.service.BaseTemplateService; +import io.metersphere.system.service.PlatformPluginService; +import io.metersphere.system.service.UserPlatformAccountService; import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.uid.NumGenerator; import io.metersphere.system.utils.ServiceUtils; @@ -62,7 +62,6 @@ import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionUtils; -import org.springframework.context.annotation.Lazy; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -114,9 +113,10 @@ public class BugService { @Resource private BaseTemplateCustomFieldService baseTemplateCustomFieldService; @Resource - @Lazy private BugNoticeService bugNoticeService; @Resource + private BugCommonService bugCommonService; + @Resource private BugCustomFieldMapper bugCustomFieldMapper; @Resource private ExtBugCustomFieldMapper extBugCustomFieldMapper; @@ -147,16 +147,12 @@ public class BugService { @Resource private ProjectApplicationService projectApplicationService; @Resource - private PluginLoadService pluginLoadService; - @Resource private BugSyncExtraService bugSyncExtraService; @Resource private BugSyncNoticeService bugSyncNoticeService; @Resource private BugStatusService bugStatusService; @Resource - private ProjectMemberService projectMemberService; - @Resource private BugAttachmentService bugAttachmentService; public static final Long INTERVAL_POS = 5000L; @@ -615,7 +611,7 @@ public class BugService { // 同步附件至MS if (MapUtils.isNotEmpty(syncBugResult.getAttachmentMap())) { - bugSyncExtraService.syncAttachmentToMs(platform, syncBugResult.getAttachmentMap(), project.getId()); + bugAttachmentService.syncAttachmentToMs(platform, syncBugResult.getAttachmentMap(), project.getId()); } sqlSession.commit(); @@ -650,7 +646,7 @@ public class BugService { // 状态选项获取时, 获取平台校验了服务集成配置, 所以此处不需要再次校验 Platform platform = platformPluginService.getPlatform(serviceIntegration.getPluginId(), serviceIntegration.getOrganizationId(), new String(serviceIntegration.getConfiguration())); - List injectFieldList = getPlatformInjectFields(projectId); + List injectFieldList = bugCommonService.getPlatformInjectFields(projectId); for (BugTemplateInjectField injectField : injectFieldList) { TemplateCustomFieldDTO templateCustomFieldDTO = new TemplateCustomFieldDTO(); BeanUtils.copyBean(templateCustomFieldDTO, injectField); @@ -681,7 +677,7 @@ public class BugService { handleUserField.setFieldName(BugTemplateCustomField.HANDLE_USER.getName()); handleUserField.setFieldKey(BugTemplateCustomField.HANDLE_USER.getId()); handleUserField.setType(CustomFieldType.SELECT.getType()); - List localHandlerOption = getLocalHandlerOption(projectId); + List localHandlerOption = bugCommonService.getLocalHandlerOption(projectId); handleUserOption = localHandlerOption.stream().map(user -> { CustomFieldOption option = new CustomFieldOption(); option.setText(user.getText()); @@ -915,7 +911,7 @@ public class BugService { // 同步至第三方(异步调用) if (!StringUtils.equals(platformName, BugPlatform.LOCAL.getName()) && CollectionUtils.isNotEmpty(allSyncAttachments)) { - bugSyncExtraService.syncAttachmentToPlatform(allSyncAttachments, request.getProjectId(), tempFileDir); + bugAttachmentService.syncAttachmentToPlatform(allSyncAttachments, request.getProjectId(), tempFileDir); } } @@ -1284,7 +1280,7 @@ public class BugService { handleCustomField(bugs, request.getProjectId()); bugs = buildExtraInfo(bugs); // 表头处理人选项 - List handleUserOption = getHeaderHandlerOption(request.getProjectId()); + List handleUserOption = bugCommonService.getHeaderHandlerOption(request.getProjectId()); Map handleUserMap = handleUserOption.stream().collect(Collectors.toMap(SelectOption::getValue, SelectOption::getText)); // 表头状态选项 List statusOption = bugStatusService.getHeaderStatusOption(request.getProjectId()); @@ -1367,69 +1363,6 @@ public class BugService { } } - /** - * 获取表头处理人选项 - * @param projectId 项目ID - * @return 处理人选项集合 - */ - public List getHeaderHandlerOption(String projectId) { - String platformName = projectApplicationService.getPlatformName(projectId); - // 需要校验服务集成是否开启 - ServiceIntegration serviceIntegration = projectApplicationService.getPlatformServiceIntegrationWithSyncOrDemand(projectId, true); - if (StringUtils.equals(platformName, BugPlatform.LOCAL.getName())) { - // Local处理人 - return getLocalHandlerOption(projectId); - } else { - // 第三方平台(Local处理人 && 平台处理人) - List localHandlerOption = getLocalHandlerOption(projectId); - // 获取插件中自定义的注入字段(处理人) - Platform platform = platformPluginService.getPlatform(serviceIntegration.getPluginId(), serviceIntegration.getOrganizationId(), - new String(serviceIntegration.getConfiguration())); - List platformHandlerOption = new ArrayList<>(); - List platformInjectFields = getPlatformInjectFields(projectId); - for (BugTemplateInjectField injectField : platformInjectFields) { - if (StringUtils.equals(injectField.getKey(), BugTemplateCustomField.HANDLE_USER.getId())) { - GetOptionRequest request = new GetOptionRequest(); - request.setOptionMethod(injectField.getOptionMethod()); - request.setProjectConfig(projectApplicationService.getProjectBugThirdPartConfig(projectId)); - platformHandlerOption = platform.getFormOptions(request); - } - } - return ListUtils.union(localHandlerOption, platformHandlerOption); - } - } - - /** - * 项目成员选项(处理人) - * @param projectId 项目ID - * @return 处理人选项集合 - */ - private List getLocalHandlerOption(String projectId) { - ProjectMemberRequest request = new ProjectMemberRequest(); - request.setProjectId(projectId); - List projectMembers = projectMemberService.listMember(request); - return projectMembers.stream().map(user -> { - SelectOption option = new SelectOption(); - option.setText(user.getName()); - option.setValue(user.getId()); - return option; - }).toList(); - } - - /** - * 获取平台注入的字段 - * @param projectId 项目ID - * @return 注入的字段集合 - */ - private List getPlatformInjectFields(String projectId) { - // 获取插件中自定义的注入字段(处理人) - ServiceIntegration serviceIntegration = projectApplicationService.getPlatformServiceIntegrationWithSyncOrDemand(projectId, true); - AbstractPlatformPlugin platformPlugin = (AbstractPlatformPlugin) pluginLoadService.getMsPluginManager().getPlugin(serviceIntegration.getPluginId()).getPlugin(); - Object scriptContent = pluginLoadService.getPluginScriptContent(serviceIntegration.getPluginId(), platformPlugin.getProjectBugTemplateInjectField()); - String injectFields = JSON.toJSONString(((Map) scriptContent).get("injectFields")); - return JSON.parseArray(injectFields, BugTemplateInjectField.class); - } - /** * 获取表头自定义字段 * @param projectId 项目ID @@ -1441,7 +1374,7 @@ public class BugService { List