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 1955e57c0f..0529bf81cd 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 @@ -191,6 +191,7 @@ public class BugController { @Operation(summary = "缺陷管理-列表-批量删除缺陷") @RequiresPermissions(PermissionConstants.PROJECT_BUG_DELETE) @CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project") + @Log(type = OperationLogType.DELETE, expression = "#msClass.batchDeleteLog(#request)", msClass = BugLogService.class) @SendNotice(taskType = NoticeConstants.TaskType.BUG_TASK, event = NoticeConstants.Event.DELETE, target = "#targetClass.getBatchNoticeByRequest(#request)", targetClass = BugNoticeService.class) public void batchDelete(@Validated @RequestBody BugBatchRequest request) { request.setUseTrash(false); diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/controller/BugTrashController.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/controller/BugTrashController.java index 7cf1f15b4e..4620feb70b 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/controller/BugTrashController.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/controller/BugTrashController.java @@ -53,6 +53,7 @@ public class BugTrashController { @GetMapping("/delete/{id}") @Operation(summary = "缺陷管理-回收站-彻底删除") @RequiresPermissions(PermissionConstants.PROJECT_BUG_DELETE) + @Log(type = OperationLogType.DELETE, expression = "#msClass.deleteTrashLog(#id)", msClass = BugLogService.class) public void deleteTrash(@PathVariable String id) { bugService.deleteTrash(id); } @@ -70,6 +71,7 @@ public class BugTrashController { @Operation(summary = "缺陷管理-回收站-批量彻底删除") @RequiresPermissions(PermissionConstants.PROJECT_BUG_DELETE) @CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project") + @Log(type = OperationLogType.DELETE, expression = "#msClass.batchDeleteTrashLog(#request)", msClass = BugLogService.class) public void batchDelete(@Validated @RequestBody BugBatchRequest request) { request.setUseTrash(true); bugService.batchDeleteTrash(request); 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 9420de655e..4fd40d176b 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 @@ -5,10 +5,8 @@ import io.metersphere.project.service.ProjectApplicationService; import io.metersphere.sdk.util.CommonBeanFactory; import io.metersphere.sdk.util.LogUtils; import io.metersphere.system.domain.ServiceIntegration; -import io.metersphere.system.dto.sdk.LicenseDTO; import io.metersphere.system.schedule.BaseScheduleJob; import io.metersphere.system.service.LicenseService; -import org.apache.commons.lang3.StringUtils; import org.quartz.JobDataMap; import org.quartz.JobExecutionContext; import org.quartz.JobKey; @@ -45,24 +43,18 @@ public class BugSyncJob extends BaseScheduleJob { if (!checkBeforeSync(resourceId)) { return; } - LogUtils.info("Start verify license and synchronizing bugs"); + LogUtils.info("Start synchronization defect"); try{ - if (licenseService == null) { - // 没有License, 同步存量缺陷 - LogUtils.info("No license, synchronization stock bug"); + // 根据项目默认配置同步缺陷 + boolean increment = projectApplicationService.isPlatformSyncMethodByIncrement(resourceId); + if (increment) { + // 增量同步 + LogUtils.info("Incremental synchronization"); bugSyncService.syncPlatformBugBySchedule(resourceId, userId); } else { - LicenseDTO licenseDTO = licenseService.validate(); - if (licenseDTO != null && licenseDTO.getLicense() != null - && StringUtils.equals(licenseDTO.getStatus(), "valid")) { - // License校验成功, 同步全量缺陷 - LogUtils.info("License verification successful, synchronization full bug"); - bugSyncService.syncPlatformAllBugBySchedule(resourceId, userId); - } else { - // License校验失败, 同步存量缺陷 - LogUtils.info("License verification failed, synchronization stock bug"); - bugSyncService.syncPlatformBugBySchedule(resourceId, userId); - } + // 全量同步 + LogUtils.info("Full synchronization"); + bugSyncService.syncPlatformAllBugBySchedule(resourceId, userId); } } catch (Exception e) { LogUtils.error(e.getMessage()); diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugLogService.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugLogService.java index cf99ad6cda..d764799308 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugLogService.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugLogService.java @@ -4,6 +4,7 @@ import io.metersphere.bug.domain.Bug; import io.metersphere.bug.domain.BugContent; import io.metersphere.bug.domain.BugContentExample; import io.metersphere.bug.domain.BugExample; +import io.metersphere.bug.dto.request.BugBatchRequest; import io.metersphere.bug.dto.request.BugEditRequest; import io.metersphere.bug.dto.response.BugCustomFieldDTO; import io.metersphere.bug.dto.response.BugDTO; @@ -20,6 +21,7 @@ import jakarta.annotation.Resource; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; import org.springframework.web.multipart.MultipartFile; import java.util.ArrayList; @@ -116,6 +118,76 @@ public class BugLogService { return null; } + /** + * 批量删除缺陷日志 + * @param request 请求参数 + * @return 日志 + */ + public List batchDeleteLog(BugBatchRequest request) { + List batchIds = bugService.getBatchIdsByRequest(request); + BugExample example = new BugExample(); + example.createCriteria().andIdIn(batchIds); + List bugs = bugMapper.selectByExample(example); + if (CollectionUtils.isEmpty(bugs)) { + return null; + } + List logs = new ArrayList<>(); + bugs.forEach(bug -> { + LogDTO dto = new LogDTO(bug.getProjectId(), null, bug.getId(), null, OperationLogType.DELETE.name(), OperationLogModule.BUG_MANAGEMENT_INDEX, bug.getTitle()); + dto.setHistory(true); + dto.setPath("/bug/delete"); + dto.setMethod(HttpMethodConstants.POST.name()); + dto.setOriginalValue(JSON.toJSONBytes(bug)); + logs.add(dto); + }); + return logs; + } + + /** + * 删除回收站缺陷日志 + * + * @param id 缺陷ID + * @return 日志 + */ + @SuppressWarnings("unused") + public LogDTO deleteTrashLog(String id) { + Bug bug = bugMapper.selectByPrimaryKey(id); + if (bug != null) { + LogDTO dto = new LogDTO(bug.getProjectId(), null, bug.getId(), null, OperationLogType.DELETE.name(), OperationLogModule.BUG_MANAGEMENT_RECYCLE, bug.getTitle()); + dto.setHistory(true); + dto.setPath("/bug/delete"); + dto.setMethod(HttpMethodConstants.GET.name()); + dto.setOriginalValue(JSON.toJSONBytes(bug)); + return dto; + } + return null; + } + + /** + * 批量删除回收站缺陷日志 + * @param request 请求参数 + * @return 日志 + */ + public List batchDeleteTrashLog(BugBatchRequest request) { + List batchIds = bugService.getBatchIdsByRequest(request); + BugExample example = new BugExample(); + example.createCriteria().andIdIn(batchIds); + List bugs = bugMapper.selectByExample(example); + if (CollectionUtils.isEmpty(bugs)) { + return null; + } + List logs = new ArrayList<>(); + bugs.forEach(bug -> { + LogDTO dto = new LogDTO(bug.getProjectId(), null, bug.getId(), null, OperationLogType.DELETE.name(), OperationLogModule.BUG_MANAGEMENT_RECYCLE, bug.getTitle()); + dto.setHistory(true); + dto.setPath("/bug/delete"); + dto.setMethod(HttpMethodConstants.POST.name()); + dto.setOriginalValue(JSON.toJSONBytes(bug)); + logs.add(dto); + }); + return logs; + } + /** * 获取历史缺陷 * @param id 缺陷ID 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 60f77f2e63..a99d6241e1 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 @@ -411,6 +411,7 @@ public class BugService { List bugs = bugMapper.selectByExample(example); String currentPlatform = projectApplicationService.getPlatformName(bugs.getFirst().getProjectId()); List platformBugIds = new ArrayList<>(); + List platformBugKeys = new ArrayList<>(); if (CollectionUtils.isNotEmpty(bugs)) { Map> groupBugs = bugs.stream().collect(Collectors.groupingBy(Bug::getPlatform)); // 根据不同平台, 删除缺陷 @@ -430,33 +431,33 @@ public class BugService { * 第三方平台缺陷 * 和当前项目所属平台不一致, 只删除MS缺陷, 不同步删除平台缺陷, 一致时需同步删除平台缺陷 */ - bugCommonService.clearAssociateResource(bugList.getFirst().getProjectId(), bugIds); bugMapper.deleteByExample(example); + platformBugIds.addAll(bugIds); if (StringUtils.equals(platform, currentPlatform)) { - platformBugIds.addAll(bugList.stream().map(Bug::getPlatformBugId).toList()); + platformBugKeys.addAll(bugList.stream().map(Bug::getPlatformBugId).toList()); } } }); } - // 批量日志 - List logs = getBatchLogByRequest(batchIds, OperationLogType.DELETE.name(), OperationLogModule.BUG_MANAGEMENT_INDEX, "/bug/batch-delete", request.getProjectId(), false, false, null, currentUser); - operationLogService.batchAdd(logs); + if (CollectionUtils.isNotEmpty(platformBugIds)) { + Thread.startVirtualThread(() -> bugCommonService.clearAssociateResource(request.getProjectId(), platformBugIds)); + } - // 异步处理第三方平台缺陷, 防止超时 - Thread.startVirtualThread(() -> { - if (CollectionUtils.isNotEmpty(platformBugIds)) { + if (CollectionUtils.isNotEmpty(platformBugKeys)) { + // 异步处理第三方平台缺陷, 防止超时 + Thread.startVirtualThread(() -> { Platform platform = projectApplicationService.getPlatform(bugs.getFirst().getProjectId(), true); String projectBugThirdPartConfig = projectApplicationService.getProjectBugThirdPartConfig(bugs.getFirst().getProjectId()); - platformBugIds.forEach(platformBugKey -> { + platformBugKeys.forEach(platformBugKey -> { // 需同步删除平台缺陷 PlatformBugDeleteRequest deleteRequest = new PlatformBugDeleteRequest(); deleteRequest.setPlatformBugKey(platformBugKey); deleteRequest.setProjectConfig(projectBugThirdPartConfig); platform.deleteBug(deleteRequest); }); - } - }); + }); + } } /**