fix(项目设置): 调整缺陷同步定时任务存量全量逻辑
--bug=1048396 --user=宋昌昌 【项目设置】社区版-定时全量同步tapd缺陷-同步失败 https://www.tapd.cn/55049933/s/1606147
This commit is contained in:
parent
e3ea9f0f0e
commit
8212fb094a
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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");
|
||||
// 全量同步
|
||||
LogUtils.info("Full synchronization");
|
||||
bugSyncService.syncPlatformAllBugBySchedule(resourceId, userId);
|
||||
} else {
|
||||
// License校验失败, 同步存量缺陷
|
||||
LogUtils.info("License verification failed, synchronization stock bug");
|
||||
bugSyncService.syncPlatformBugBySchedule(resourceId, userId);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtils.error(e.getMessage());
|
||||
|
|
|
@ -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<LogDTO> batchDeleteLog(BugBatchRequest request) {
|
||||
List<String> batchIds = bugService.getBatchIdsByRequest(request);
|
||||
BugExample example = new BugExample();
|
||||
example.createCriteria().andIdIn(batchIds);
|
||||
List<Bug> bugs = bugMapper.selectByExample(example);
|
||||
if (CollectionUtils.isEmpty(bugs)) {
|
||||
return null;
|
||||
}
|
||||
List<LogDTO> 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<LogDTO> batchDeleteTrashLog(BugBatchRequest request) {
|
||||
List<String> batchIds = bugService.getBatchIdsByRequest(request);
|
||||
BugExample example = new BugExample();
|
||||
example.createCriteria().andIdIn(batchIds);
|
||||
List<Bug> bugs = bugMapper.selectByExample(example);
|
||||
if (CollectionUtils.isEmpty(bugs)) {
|
||||
return null;
|
||||
}
|
||||
List<LogDTO> 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
|
||||
|
|
|
@ -411,6 +411,7 @@ public class BugService {
|
|||
List<Bug> bugs = bugMapper.selectByExample(example);
|
||||
String currentPlatform = projectApplicationService.getPlatformName(bugs.getFirst().getProjectId());
|
||||
List<String> platformBugIds = new ArrayList<>();
|
||||
List<String> platformBugKeys = new ArrayList<>();
|
||||
if (CollectionUtils.isNotEmpty(bugs)) {
|
||||
Map<String, List<Bug>> groupBugs = bugs.stream().collect(Collectors.groupingBy(Bug::getPlatform));
|
||||
// 根据不同平台, 删除缺陷
|
||||
|
@ -430,34 +431,34 @@ 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<LogDTO> 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));
|
||||
}
|
||||
|
||||
if (CollectionUtils.isNotEmpty(platformBugKeys)) {
|
||||
// 异步处理第三方平台缺陷, 防止超时
|
||||
Thread.startVirtualThread(() -> {
|
||||
if (CollectionUtils.isNotEmpty(platformBugIds)) {
|
||||
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);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量恢复缺陷
|
||||
|
|
Loading…
Reference in New Issue