From 9dc624aeadad0bd10dde76eae9219888ef910afb Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Wed, 17 Apr 2024 14:38:16 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=BC=BA=E9=99=B7=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E7=BC=BA=E9=99=B7=E5=90=8C=E6=AD=A5=E7=9B=B8=E5=85=B3=E7=9A=84?= =?UTF-8?q?BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1039563 --user=宋昌昌 【项目管理】项目与权限-缺陷管理-同步缺陷设置6小时增量同步一次不生效 https://www.tapd.cn/55049933/s/1499368 --- .../io/metersphere/bug/job/BugSyncJob.java | 36 ++++++------------- .../metersphere/bug/service/BugService.java | 4 +++ .../bug/service/BugSyncService.java | 32 +++++++++++++++++ .../bug/service/XpackBugService.java | 7 ---- .../bug/mock/XpackBugMockServiceImpl.java | 5 --- frontend/src/views/bug-management/index.vue | 1 - .../src/views/bug-management/locale/en-US.ts | 4 +-- .../src/views/bug-management/locale/zh-CN.ts | 3 +- .../menuManagement/components/defectSync.vue | 2 +- .../menuManagement/locale/en-US.ts | 4 +-- .../menuManagement/locale/zh-CN.ts | 4 +-- 11 files changed, 55 insertions(+), 47 deletions(-) diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/job/BugSyncJob.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/job/BugSyncJob.java index 896f073434..af7f56773f 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/job/BugSyncJob.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/job/BugSyncJob.java @@ -1,8 +1,6 @@ package io.metersphere.bug.job; -import io.metersphere.bug.service.BugSyncExtraService; import io.metersphere.bug.service.BugSyncService; -import io.metersphere.bug.service.XpackBugService; import io.metersphere.project.service.ProjectApplicationService; import io.metersphere.sdk.util.CommonBeanFactory; import io.metersphere.sdk.util.LogUtils; @@ -23,15 +21,11 @@ public class BugSyncJob extends BaseScheduleJob { private final LicenseService licenseService; private final BugSyncService bugSyncService; - private final XpackBugService xpackBugService; - private final BugSyncExtraService bugSyncExtraService; private final ProjectApplicationService projectApplicationService; public BugSyncJob() { licenseService = CommonBeanFactory.getBean(LicenseService.class); - xpackBugService = CommonBeanFactory.getBean(XpackBugService.class); bugSyncService = CommonBeanFactory.getBean(BugSyncService.class); - bugSyncExtraService = CommonBeanFactory.getBean(BugSyncExtraService.class); projectApplicationService = CommonBeanFactory.getBean(ProjectApplicationService.class); } @@ -52,30 +46,22 @@ public class BugSyncJob extends BaseScheduleJob { return; } LogUtils.info("bug sync job start......"); - // 获取当前项目同步缺陷唯一Key try{ - String syncValue = bugSyncExtraService.getSyncKey(resourceId); - if (StringUtils.isEmpty(syncValue)) { - // 不存在, 设置保证唯一性, 并开始同步 - bugSyncExtraService.setSyncKey(resourceId); - if (licenseService == null) { - LogUtils.info("license is null, sync remain bug"); - bugSyncService.syncPlatformBugBySchedule(resourceId, userId); + if (licenseService == null) { + LogUtils.info("license is null, sync remain bug"); + bugSyncService.syncPlatformBugBySchedule(resourceId, userId); + } else { + LicenseDTO licenseDTO = licenseService.validate(); + if (licenseDTO != null && licenseDTO.getLicense() != null + && StringUtils.equals(licenseDTO.getStatus(), "valid")) { + LogUtils.info("license is valid, sync all bug"); + bugSyncService.syncPlatformAllBugBySchedule(resourceId, userId); } else { - LicenseDTO licenseDTO = licenseService.validate(); - if (licenseDTO != null && licenseDTO.getLicense() != null - && StringUtils.equals(licenseDTO.getStatus(), "valid")) { - LogUtils.info("license is valid, sync all bug"); - xpackBugService.syncPlatformBugsBySchedule(resourceId, userId); - } else { - LogUtils.info("license is invalid, sync remain bug"); - bugSyncService.syncPlatformBugBySchedule(resourceId, userId); - } + LogUtils.info("license is invalid, sync remain bug"); + bugSyncService.syncPlatformBugBySchedule(resourceId, userId); } - bugSyncExtraService.deleteSyncKey(resourceId); } } catch (Exception e) { - bugSyncExtraService.deleteSyncKey(resourceId); LogUtils.error(e.getMessage()); } LogUtils.info("bug sync job end......"); 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 f6f83c9175..c7b709edab 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 @@ -528,6 +528,8 @@ public class BugService { } } catch (Exception e) { LogUtils.error(e); + // 异常或正常结束都得删除当前项目执行同步的唯一Key + bugSyncExtraService.deleteSyncKey(request.getProjectId()); // 同步缺陷异常, 当前同步错误信息 -> Redis(check接口获取) bugSyncExtraService.setSyncErrorMsg(request.getProjectId(), e.getMessage()); } finally { @@ -548,6 +550,8 @@ public class BugService { SubListUtils.dealForSubList(remainBugs, 100, (subBugs) -> doSyncPlatformBugs(subBugs, project)); } catch (Exception e) { LogUtils.error(e); + // 异常或正常结束都得删除当前项目执行同步的Key + bugSyncExtraService.deleteSyncKey(project.getId()); // 同步缺陷异常, 当前同步错误信息 -> Redis(check接口获取) bugSyncExtraService.setSyncErrorMsg(project.getId(), e.getMessage()); } finally { 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 d9aaeef6fd..7b90b856ab 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,8 @@ 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.CommonBeanFactory; +import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.Translator; import io.metersphere.system.domain.Template; import io.metersphere.system.domain.TemplateExample; @@ -133,11 +135,41 @@ public class BugSyncService { /** * 定时任务同步缺陷(存量-默认中文环境通知) + * @param projectId 项目ID + * @param scheduleUser 任务触发用户 */ public void syncPlatformBugBySchedule(String projectId, String scheduleUser) { syncBugs(projectId, scheduleUser, Locale.SIMPLIFIED_CHINESE.getLanguage(), Translator.get("sync_mode.auto")); } + /** + * 定时任务同步缺陷(全量-默认中文环境通知) + * @param projectId 项目ID + * @param scheduleUser 任务触发用户 + */ + public void syncPlatformAllBugBySchedule(String projectId, String scheduleUser) { + try { + String syncValue = bugSyncExtraService.getSyncKey(projectId); + if (StringUtils.isEmpty(syncValue)) { + // 不存在, 设置保证唯一性, 并开始同步 + bugSyncExtraService.setSyncKey(projectId); + XpackBugService bugService = CommonBeanFactory.getBean(XpackBugService.class); + if (bugService != null) { + Project project = getProjectById(projectId); + BugSyncRequest syncRequest = new BugSyncRequest(); + syncRequest.setProjectId(projectId); + bugService.syncPlatformBugs(project, syncRequest, scheduleUser, Locale.SIMPLIFIED_CHINESE.getLanguage(), Translator.get("sync_mode.auto")); + } + } + } catch (Exception e) { + LogUtils.error(e); + // 异常或正常结束都得删除当前项目执行同步的唯一Key + bugSyncExtraService.deleteSyncKey(projectId); + // 同步缺陷异常, 当前同步错误信息 -> Redis(check接口获取) + bugSyncExtraService.setSyncErrorMsg(projectId, e.getMessage()); + } + } + /** * 根据项目ID获取项目信息 * @param projectId 项目ID 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 60cb346b1b..eba3b9be32 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 @@ -8,13 +8,6 @@ import io.metersphere.project.domain.Project; */ public interface XpackBugService { - /** - * 同步系统下所有第三方平台项目缺陷(定时任务) - * @param projectId 项目ID - * @param scheduleUser 定时任务执行用户 - */ - void syncPlatformBugsBySchedule(String projectId, String scheduleUser); - /** * 同步当前项目第三方平台缺陷(前台调用, 支持全量及同步条件区间) * @param project 项目 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 a57135587e..9a05bd4f50 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 @@ -8,11 +8,6 @@ import org.springframework.stereotype.Service; @Service public class XpackBugMockServiceImpl implements XpackBugService { - @Override - public void syncPlatformBugsBySchedule(String projectId, String scheduleUser) { - - } - @Override public void syncPlatformBugs(Project project, BugSyncRequest request, String currentUser, String language, String triggerMode) { diff --git a/frontend/src/views/bug-management/index.vue b/frontend/src/views/bug-management/index.vue index d0d9a1bd7e..9d0411f8a0 100644 --- a/frontend/src/views/bug-management/index.vue +++ b/frontend/src/views/bug-management/index.vue @@ -154,7 +154,6 @@ diff --git a/frontend/src/views/bug-management/locale/en-US.ts b/frontend/src/views/bug-management/locale/en-US.ts index 6e7bc00447..286229af40 100644 --- a/frontend/src/views/bug-management/locale/en-US.ts +++ b/frontend/src/views/bug-management/locale/en-US.ts @@ -21,8 +21,8 @@ export default { sync: 'Sync', synchronizing: 'Synchronizing', syncSuccess: 'Synchronous success', - syncBugTipRowOne: 'Sync third plant bug,', - syncBugTipRowTwo: 'Create bug and sync bug?', + syncBugTipRowOne: + 'Synchronize third-party platform bug to MS as configured in << Project Management - Application Settings - Defect Management >>', bugAutoSync: 'System will auto sync by the project application setting frequency', syncTime: 'Sync time', deleteLabel: 'Local bug will in recycle bin and third plant bug will be deleted', diff --git a/frontend/src/views/bug-management/locale/zh-CN.ts b/frontend/src/views/bug-management/locale/zh-CN.ts index 1eb9a70e36..4a8f458a91 100644 --- a/frontend/src/views/bug-management/locale/zh-CN.ts +++ b/frontend/src/views/bug-management/locale/zh-CN.ts @@ -21,8 +21,7 @@ export default { sync: '同步', synchronizing: '正在同步中', syncSuccess: '同步成功', - syncBugTipRowOne: '将第三方的缺陷同步到缺陷管理中,', - syncBugTipRowTwo: '新增缺陷和更新已有的缺陷?', + syncBugTipRowOne: '根据<<项目管理-应用设置-缺陷管理>>中的配置来同步第三方平台缺陷至MS', bugAutoSync: '系统将按照项目应用设置频率自动同步', syncTime: '同步时间', deleteLabel: '删除后, Local 的缺陷进入回收站; 第三方平台同步的缺陷将不做回收', diff --git a/frontend/src/views/project-management/projectAndPermission/menuManagement/components/defectSync.vue b/frontend/src/views/project-management/projectAndPermission/menuManagement/components/defectSync.vue index 338452e9e7..8a0c6ee60e 100644 --- a/frontend/src/views/project-management/projectAndPermission/menuManagement/components/defectSync.vue +++ b/frontend/src/views/project-management/projectAndPermission/menuManagement/components/defectSync.vue @@ -56,7 +56,7 @@
{{ t('project.menu.fullSync') }} - +