diff --git a/backend/framework/sdk/src/main/resources/i18n/bug.properties b/backend/framework/sdk/src/main/resources/i18n/bug.properties index 0645257cae..7833b4fb85 100644 --- a/backend/framework/sdk/src/main/resources/i18n/bug.properties +++ b/backend/framework/sdk/src/main/resources/i18n/bug.properties @@ -116,4 +116,7 @@ bug.export.system.other.columns.comment=评论 bug.export.system.other.columns.platform=所属平台 permission.bug.name=缺陷管理 -permission.bug=缺陷 \ No newline at end of file +permission.bug=缺陷 +# sync mode +sync_mode.manual=手动同步 +sync_mode.auto=定时同步 \ No newline at end of file diff --git a/backend/framework/sdk/src/main/resources/i18n/bug_en_US.properties b/backend/framework/sdk/src/main/resources/i18n/bug_en_US.properties index 697a467063..a39dae9255 100644 --- a/backend/framework/sdk/src/main/resources/i18n/bug_en_US.properties +++ b/backend/framework/sdk/src/main/resources/i18n/bug_en_US.properties @@ -117,4 +117,8 @@ bug.export.system.other.columns.platform=Platform permission.bug.name=Bug management test_plan_related=Test plan related direct_related=Direct related -permission.bug=Bug \ No newline at end of file +permission.bug=Bug + +# sync mode +sync_mode.manual=Manual +sync_mode.auto=Auto \ No newline at end of file diff --git a/backend/framework/sdk/src/main/resources/i18n/bug_zh_CN.properties b/backend/framework/sdk/src/main/resources/i18n/bug_zh_CN.properties index 1b092bd2c7..e764dbbdd6 100644 --- a/backend/framework/sdk/src/main/resources/i18n/bug_zh_CN.properties +++ b/backend/framework/sdk/src/main/resources/i18n/bug_zh_CN.properties @@ -117,4 +117,8 @@ bug.export.system.other.columns.platform=所属平台 permission.bug.name=缺陷管理 test_plan_relate=测试计划关联 direct_related=直接关联 -permission.bug=缺陷 \ No newline at end of file +permission.bug=缺陷 + +# sync mode +sync_mode.manual=手动同步 +sync_mode.auto=定时同步 \ No newline at end of file diff --git a/backend/framework/sdk/src/main/resources/i18n/bug_zh_TW.properties b/backend/framework/sdk/src/main/resources/i18n/bug_zh_TW.properties index c31a3859e6..b56ad80bfc 100644 --- a/backend/framework/sdk/src/main/resources/i18n/bug_zh_TW.properties +++ b/backend/framework/sdk/src/main/resources/i18n/bug_zh_TW.properties @@ -118,4 +118,8 @@ bug.export.system.other.columns.platform=所屬平台 permission.bug.name=缺陷管理 test_plan_related=測試計劃關聯 direct_related=直接關聯 -permission.bug=缺陷 \ No newline at end of file +permission.bug=缺陷 + +# sync mode +sync_mode.manual=手動同步 +sync_mode.auto=定時同步 \ No newline at end of file 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 160cc32bc4..3ef44efa41 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 @@ -18,6 +18,7 @@ import io.metersphere.project.service.ProjectApplicationService; import io.metersphere.project.service.ProjectTemplateService; import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.sdk.constants.TemplateScene; +import io.metersphere.sdk.util.Translator; import io.metersphere.system.dto.sdk.TemplateCustomFieldDTO; import io.metersphere.system.dto.sdk.TemplateDTO; import io.metersphere.system.dto.sdk.request.PosRequest; @@ -146,7 +147,7 @@ public class BugController { @RequiresPermissions(PermissionConstants.PROJECT_BUG_UPDATE) @CheckOwner(resourceId = "#projectId", resourceType = "project") public void sync(@PathVariable String projectId) { - bugSyncService.syncBugs(projectId, SessionUtils.getUserId(), Objects.requireNonNull(SessionUtils.getUser()).getLanguage()); + bugSyncService.syncBugs(projectId, SessionUtils.getUserId(), Objects.requireNonNull(SessionUtils.getUser()).getLanguage(), Translator.get("sync_mode.manual")); } @PostMapping("/sync/all") 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 cdbb0a7770..d451190a37 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 @@ -524,7 +524,7 @@ public class BugService { try { XpackBugService bugService = CommonBeanFactory.getBean(XpackBugService.class); if (bugService != null) { - bugService.syncPlatformBugs(project, request, currentUser, language); + bugService.syncPlatformBugs(project, request, currentUser, language, Translator.get("sync_mode.manual")); } } catch (Exception e) { LogUtils.error(e); @@ -542,7 +542,7 @@ public class BugService { * @param project 项目 */ @Async - public void syncPlatformBugs(List remainBugs, Project project, String currentUser, String language) { + public void syncPlatformBugs(List remainBugs, Project project, String currentUser, String language, String triggerMode) { try { // 分页同步 SubListUtils.dealForSubList(remainBugs, 100, (subBugs) -> doSyncPlatformBugs(subBugs, project)); @@ -554,7 +554,7 @@ public class BugService { // 异常或正常结束都得删除当前项目执行同步的Key bugSyncExtraService.deleteSyncKey(project.getId()); // 发送同步通知 - bugSyncNoticeService.sendNotice(remainBugs.size(), currentUser, language, project.getId()); + bugSyncNoticeService.sendNotice(remainBugs.size(), currentUser, language, triggerMode, project.getId()); } } diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugSyncNoticeService.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugSyncNoticeService.java index a8c3c67279..d2029329d8 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugSyncNoticeService.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugSyncNoticeService.java @@ -30,7 +30,7 @@ public class BugSyncNoticeService { @Resource private ProjectApplicationService projectApplicationService; - public void sendNotice(int total, String currentUser, String language, String projectId) { + public void sendNotice(int total, String currentUser, String language, String triggerMode, String projectId) { String platformName = projectApplicationService.getPlatformName(projectId); User user = userMapper.selectByPrimaryKey(currentUser); setLanguage(user.getLanguage()); @@ -45,6 +45,7 @@ public class BugSyncNoticeService { paramMap.put("projectId", projectId); paramMap.put("Language", language); paramMap.put("platform", platformName); + paramMap.put("triggerMode", triggerMode); NoticeModel noticeModel = NoticeModel.builder().operator(currentUser).excludeSelf(false) .context(template).subject(subject).paramMap(paramMap).event(NoticeConstants.Event.EXECUTE_COMPLETED).build(); noticeSendService.send(NoticeConstants.TaskType.BUG_SYNC_TASK, noticeModel); diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugSyncService.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugSyncService.java index f218852f4e..d9aaeef6fd 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugSyncService.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugSyncService.java @@ -12,6 +12,7 @@ import io.metersphere.project.service.ProjectApplicationService; import io.metersphere.project.service.ProjectTemplateService; import io.metersphere.sdk.constants.TemplateScene; import io.metersphere.sdk.exception.MSException; +import io.metersphere.sdk.util.Translator; import io.metersphere.system.domain.Template; import io.metersphere.system.domain.TemplateExample; import io.metersphere.system.mapper.TemplateMapper; @@ -73,7 +74,7 @@ public class BugSyncService { * 开源用户 (同步存量缺陷) * @param projectId 项目ID */ - public void syncBugs(String projectId, String currentUser, String language) { + public void syncBugs(String projectId, String currentUser, String language, String triggerMode) { try { String syncValue = bugSyncExtraService.getSyncKey(projectId); if (StringUtils.isEmpty(syncValue)) { @@ -99,7 +100,7 @@ public class BugSyncService { Map templateMap = templates.stream().collect(Collectors.toMap(Template::getId, t -> t)); // 非插件默认模板且模板不存在, 无需同步 bugs.removeIf(bug -> !templateMap.containsKey(bug.getTemplateId()) && !StringUtils.equals(bug.getTemplateId(), pluginTemplate.getId())); - bugService.syncPlatformBugs(bugs, project, currentUser, language); + bugService.syncPlatformBugs(bugs, project, currentUser, language, triggerMode); } } } catch (Exception e) { @@ -134,7 +135,7 @@ public class BugSyncService { * 定时任务同步缺陷(存量-默认中文环境通知) */ public void syncPlatformBugBySchedule(String projectId, String scheduleUser) { - syncBugs(projectId, scheduleUser, Locale.SIMPLIFIED_CHINESE.getLanguage()); + syncBugs(projectId, scheduleUser, Locale.SIMPLIFIED_CHINESE.getLanguage(), Translator.get("sync_mode.auto")); } /** diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/XpackBugService.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/XpackBugService.java index 6bc7c2166a..60cb346b1b 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/XpackBugService.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/XpackBugService.java @@ -21,7 +21,8 @@ public interface XpackBugService { * @param request 同步请求参数 * @param currentUser 当前用户 * @param language 语言环境 + * @param triggerMode 同步触发方式 */ - void syncPlatformBugs(Project project, BugSyncRequest request, String currentUser, String language); + void syncPlatformBugs(Project project, BugSyncRequest request, String currentUser, String language, String triggerMode); } diff --git a/backend/services/bug-management/src/test/java/io/metersphere/bug/controller/BugControllerTests.java b/backend/services/bug-management/src/test/java/io/metersphere/bug/controller/BugControllerTests.java index 23a15c8017..71f9acf7e5 100644 --- a/backend/services/bug-management/src/test/java/io/metersphere/bug/controller/BugControllerTests.java +++ b/backend/services/bug-management/src/test/java/io/metersphere/bug/controller/BugControllerTests.java @@ -28,6 +28,7 @@ import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.file.FileRequest; import io.metersphere.sdk.util.FileAssociationSourceUtil; import io.metersphere.sdk.util.JSON; +import io.metersphere.sdk.util.Translator; import io.metersphere.system.base.BaseTest; import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.domain.CustomField; @@ -634,13 +635,13 @@ public class BugControllerTests extends BaseTest { List remainBugs = bugMapper.selectByExample(example); Project defaultProject = projectMapper.selectByPrimaryKey("default-project-for-bug"); // 同步第一次 - bugService.syncPlatformBugs(remainBugs, defaultProject, "admin", Locale.SIMPLIFIED_CHINESE.getLanguage()); + bugService.syncPlatformBugs(remainBugs, defaultProject, "admin", Locale.SIMPLIFIED_CHINESE.getLanguage(), Translator.get("sync_mode.manual")); // 同步第二次 renameLocalFile(updateRequest2.getId()); // 重命名后, 同步时会删除本地文件 - bugService.syncPlatformBugs(remainBugs, defaultProject, "admin", Locale.SIMPLIFIED_CHINESE.getLanguage()); + bugService.syncPlatformBugs(remainBugs, defaultProject, "admin", Locale.SIMPLIFIED_CHINESE.getLanguage(), Translator.get("sync_mode.manual")); // 同步第三次 deleteLocalFile(updateRequest2.getId()); // 手动删除关联的文件, 重新同步时会下载平台附件 - bugService.syncPlatformBugs(remainBugs, defaultProject, "admin", Locale.SIMPLIFIED_CHINESE.getLanguage()); + bugService.syncPlatformBugs(remainBugs, defaultProject, "admin", Locale.SIMPLIFIED_CHINESE.getLanguage(), Translator.get("sync_mode.manual")); // 全选删除所有Jira缺陷 BugBatchRequest request = new BugBatchRequest(); diff --git a/backend/services/bug-management/src/test/java/io/metersphere/bug/mock/XpackBugMockServiceImpl.java b/backend/services/bug-management/src/test/java/io/metersphere/bug/mock/XpackBugMockServiceImpl.java index 13d5199464..a57135587e 100644 --- a/backend/services/bug-management/src/test/java/io/metersphere/bug/mock/XpackBugMockServiceImpl.java +++ b/backend/services/bug-management/src/test/java/io/metersphere/bug/mock/XpackBugMockServiceImpl.java @@ -14,7 +14,7 @@ public class XpackBugMockServiceImpl implements XpackBugService { } @Override - public void syncPlatformBugs(Project project, BugSyncRequest request, String currentUser, String language) { + public void syncPlatformBugs(Project project, BugSyncRequest request, String currentUser, String language, String triggerMode) { } } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeTemplateService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeTemplateService.java index 02f1191dc3..92ac672b55 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeTemplateService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeTemplateService.java @@ -81,8 +81,9 @@ public class NoticeTemplateService { } case NoticeConstants.TaskType.BUG_SYNC_TASK -> { Field[] allFields = FieldUtils.getAllFields(BugSyncNoticeDTO.class); + // TODO: 待修改, 同步仅需的字段{操作人, 触发方式} + // 该方法提供了统一的内置通知模板字段; {操作人, 关注人, 触发方式} addOptionDto(messageTemplateFieldDTOList, allFields, null); - //TODO:获取报告 } case NoticeConstants.TaskType.UI_SCENARIO_TASK -> { Field[] allFields = FieldUtils.getAllFields(UiScenario.class); diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/notice/sender/AbstractNoticeSender.java b/backend/services/system-setting/src/main/java/io/metersphere/system/notice/sender/AbstractNoticeSender.java index ada51c0d4b..b18547b072 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/notice/sender/AbstractNoticeSender.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/notice/sender/AbstractNoticeSender.java @@ -148,11 +148,11 @@ public abstract class AbstractNoticeSender implements NoticeSender { } // 去重复 - List userIds = toUsers.stream().map(Receiver::getUserId).distinct().toList(); - LogUtils.info("userIds: ", JSON.toJSONString(userIds)); - List users = getUsers(userIds, messageDetail.getProjectId()); - List realUserIds = users.stream().map(User::getId).toList(); - return toUsers.stream().filter(t -> realUserIds.contains(t.getUserId())).toList(); + // List userIds = toUsers.stream().map(Receiver::getUserId).distinct().toList(); + // LogUtils.info("userIds: ", JSON.toJSONString(userIds)); + // List users = getUsers(userIds, messageDetail.getProjectId()); + // List realUserIds = users.stream().map(User::getId).toList(); + return toUsers; } private List handleFollows(MessageDetail messageDetail, NoticeModel noticeModel) {