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 = "缺陷管理-列表-批量删除缺陷")
|
@Operation(summary = "缺陷管理-列表-批量删除缺陷")
|
||||||
@RequiresPermissions(PermissionConstants.PROJECT_BUG_DELETE)
|
@RequiresPermissions(PermissionConstants.PROJECT_BUG_DELETE)
|
||||||
@CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project")
|
@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)
|
@SendNotice(taskType = NoticeConstants.TaskType.BUG_TASK, event = NoticeConstants.Event.DELETE, target = "#targetClass.getBatchNoticeByRequest(#request)", targetClass = BugNoticeService.class)
|
||||||
public void batchDelete(@Validated @RequestBody BugBatchRequest request) {
|
public void batchDelete(@Validated @RequestBody BugBatchRequest request) {
|
||||||
request.setUseTrash(false);
|
request.setUseTrash(false);
|
||||||
|
|
|
@ -53,6 +53,7 @@ public class BugTrashController {
|
||||||
@GetMapping("/delete/{id}")
|
@GetMapping("/delete/{id}")
|
||||||
@Operation(summary = "缺陷管理-回收站-彻底删除")
|
@Operation(summary = "缺陷管理-回收站-彻底删除")
|
||||||
@RequiresPermissions(PermissionConstants.PROJECT_BUG_DELETE)
|
@RequiresPermissions(PermissionConstants.PROJECT_BUG_DELETE)
|
||||||
|
@Log(type = OperationLogType.DELETE, expression = "#msClass.deleteTrashLog(#id)", msClass = BugLogService.class)
|
||||||
public void deleteTrash(@PathVariable String id) {
|
public void deleteTrash(@PathVariable String id) {
|
||||||
bugService.deleteTrash(id);
|
bugService.deleteTrash(id);
|
||||||
}
|
}
|
||||||
|
@ -70,6 +71,7 @@ public class BugTrashController {
|
||||||
@Operation(summary = "缺陷管理-回收站-批量彻底删除")
|
@Operation(summary = "缺陷管理-回收站-批量彻底删除")
|
||||||
@RequiresPermissions(PermissionConstants.PROJECT_BUG_DELETE)
|
@RequiresPermissions(PermissionConstants.PROJECT_BUG_DELETE)
|
||||||
@CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project")
|
@CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project")
|
||||||
|
@Log(type = OperationLogType.DELETE, expression = "#msClass.batchDeleteTrashLog(#request)", msClass = BugLogService.class)
|
||||||
public void batchDelete(@Validated @RequestBody BugBatchRequest request) {
|
public void batchDelete(@Validated @RequestBody BugBatchRequest request) {
|
||||||
request.setUseTrash(true);
|
request.setUseTrash(true);
|
||||||
bugService.batchDeleteTrash(request);
|
bugService.batchDeleteTrash(request);
|
||||||
|
|
|
@ -5,10 +5,8 @@ import io.metersphere.project.service.ProjectApplicationService;
|
||||||
import io.metersphere.sdk.util.CommonBeanFactory;
|
import io.metersphere.sdk.util.CommonBeanFactory;
|
||||||
import io.metersphere.sdk.util.LogUtils;
|
import io.metersphere.sdk.util.LogUtils;
|
||||||
import io.metersphere.system.domain.ServiceIntegration;
|
import io.metersphere.system.domain.ServiceIntegration;
|
||||||
import io.metersphere.system.dto.sdk.LicenseDTO;
|
|
||||||
import io.metersphere.system.schedule.BaseScheduleJob;
|
import io.metersphere.system.schedule.BaseScheduleJob;
|
||||||
import io.metersphere.system.service.LicenseService;
|
import io.metersphere.system.service.LicenseService;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.quartz.JobDataMap;
|
import org.quartz.JobDataMap;
|
||||||
import org.quartz.JobExecutionContext;
|
import org.quartz.JobExecutionContext;
|
||||||
import org.quartz.JobKey;
|
import org.quartz.JobKey;
|
||||||
|
@ -45,24 +43,18 @@ public class BugSyncJob extends BaseScheduleJob {
|
||||||
if (!checkBeforeSync(resourceId)) {
|
if (!checkBeforeSync(resourceId)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LogUtils.info("Start verify license and synchronizing bugs");
|
LogUtils.info("Start synchronization defect");
|
||||||
try{
|
try{
|
||||||
if (licenseService == null) {
|
// 根据项目默认配置同步缺陷
|
||||||
// 没有License, 同步存量缺陷
|
boolean increment = projectApplicationService.isPlatformSyncMethodByIncrement(resourceId);
|
||||||
LogUtils.info("No license, synchronization stock bug");
|
if (increment) {
|
||||||
|
// 增量同步
|
||||||
|
LogUtils.info("Incremental synchronization");
|
||||||
bugSyncService.syncPlatformBugBySchedule(resourceId, userId);
|
bugSyncService.syncPlatformBugBySchedule(resourceId, userId);
|
||||||
} else {
|
} else {
|
||||||
LicenseDTO licenseDTO = licenseService.validate();
|
// 全量同步
|
||||||
if (licenseDTO != null && licenseDTO.getLicense() != null
|
LogUtils.info("Full synchronization");
|
||||||
&& StringUtils.equals(licenseDTO.getStatus(), "valid")) {
|
bugSyncService.syncPlatformAllBugBySchedule(resourceId, userId);
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtils.error(e.getMessage());
|
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.BugContent;
|
||||||
import io.metersphere.bug.domain.BugContentExample;
|
import io.metersphere.bug.domain.BugContentExample;
|
||||||
import io.metersphere.bug.domain.BugExample;
|
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.request.BugEditRequest;
|
||||||
import io.metersphere.bug.dto.response.BugCustomFieldDTO;
|
import io.metersphere.bug.dto.response.BugCustomFieldDTO;
|
||||||
import io.metersphere.bug.dto.response.BugDTO;
|
import io.metersphere.bug.dto.response.BugDTO;
|
||||||
|
@ -20,6 +21,7 @@ import jakarta.annotation.Resource;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -116,6 +118,76 @@ public class BugLogService {
|
||||||
return null;
|
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
|
* @param id 缺陷ID
|
||||||
|
|
|
@ -411,6 +411,7 @@ public class BugService {
|
||||||
List<Bug> bugs = bugMapper.selectByExample(example);
|
List<Bug> bugs = bugMapper.selectByExample(example);
|
||||||
String currentPlatform = projectApplicationService.getPlatformName(bugs.getFirst().getProjectId());
|
String currentPlatform = projectApplicationService.getPlatformName(bugs.getFirst().getProjectId());
|
||||||
List<String> platformBugIds = new ArrayList<>();
|
List<String> platformBugIds = new ArrayList<>();
|
||||||
|
List<String> platformBugKeys = new ArrayList<>();
|
||||||
if (CollectionUtils.isNotEmpty(bugs)) {
|
if (CollectionUtils.isNotEmpty(bugs)) {
|
||||||
Map<String, List<Bug>> groupBugs = bugs.stream().collect(Collectors.groupingBy(Bug::getPlatform));
|
Map<String, List<Bug>> groupBugs = bugs.stream().collect(Collectors.groupingBy(Bug::getPlatform));
|
||||||
// 根据不同平台, 删除缺陷
|
// 根据不同平台, 删除缺陷
|
||||||
|
@ -430,33 +431,33 @@ public class BugService {
|
||||||
* 第三方平台缺陷
|
* 第三方平台缺陷
|
||||||
* 和当前项目所属平台不一致, 只删除MS缺陷, 不同步删除平台缺陷, 一致时需同步删除平台缺陷
|
* 和当前项目所属平台不一致, 只删除MS缺陷, 不同步删除平台缺陷, 一致时需同步删除平台缺陷
|
||||||
*/
|
*/
|
||||||
bugCommonService.clearAssociateResource(bugList.getFirst().getProjectId(), bugIds);
|
|
||||||
bugMapper.deleteByExample(example);
|
bugMapper.deleteByExample(example);
|
||||||
|
platformBugIds.addAll(bugIds);
|
||||||
if (StringUtils.equals(platform, currentPlatform)) {
|
if (StringUtils.equals(platform, currentPlatform)) {
|
||||||
platformBugIds.addAll(bugList.stream().map(Bug::getPlatformBugId).toList());
|
platformBugKeys.addAll(bugList.stream().map(Bug::getPlatformBugId).toList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 批量日志
|
if (CollectionUtils.isNotEmpty(platformBugIds)) {
|
||||||
List<LogDTO> logs = getBatchLogByRequest(batchIds, OperationLogType.DELETE.name(), OperationLogModule.BUG_MANAGEMENT_INDEX, "/bug/batch-delete", request.getProjectId(), false, false, null, currentUser);
|
Thread.startVirtualThread(() -> bugCommonService.clearAssociateResource(request.getProjectId(), platformBugIds));
|
||||||
operationLogService.batchAdd(logs);
|
}
|
||||||
|
|
||||||
// 异步处理第三方平台缺陷, 防止超时
|
if (CollectionUtils.isNotEmpty(platformBugKeys)) {
|
||||||
Thread.startVirtualThread(() -> {
|
// 异步处理第三方平台缺陷, 防止超时
|
||||||
if (CollectionUtils.isNotEmpty(platformBugIds)) {
|
Thread.startVirtualThread(() -> {
|
||||||
Platform platform = projectApplicationService.getPlatform(bugs.getFirst().getProjectId(), true);
|
Platform platform = projectApplicationService.getPlatform(bugs.getFirst().getProjectId(), true);
|
||||||
String projectBugThirdPartConfig = projectApplicationService.getProjectBugThirdPartConfig(bugs.getFirst().getProjectId());
|
String projectBugThirdPartConfig = projectApplicationService.getProjectBugThirdPartConfig(bugs.getFirst().getProjectId());
|
||||||
platformBugIds.forEach(platformBugKey -> {
|
platformBugKeys.forEach(platformBugKey -> {
|
||||||
// 需同步删除平台缺陷
|
// 需同步删除平台缺陷
|
||||||
PlatformBugDeleteRequest deleteRequest = new PlatformBugDeleteRequest();
|
PlatformBugDeleteRequest deleteRequest = new PlatformBugDeleteRequest();
|
||||||
deleteRequest.setPlatformBugKey(platformBugKey);
|
deleteRequest.setPlatformBugKey(platformBugKey);
|
||||||
deleteRequest.setProjectConfig(projectBugThirdPartConfig);
|
deleteRequest.setProjectConfig(projectBugThirdPartConfig);
|
||||||
platform.deleteBug(deleteRequest);
|
platform.deleteBug(deleteRequest);
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue