refactor(缺陷管理): 补充缺陷删除时清理富文本文件的逻辑
This commit is contained in:
parent
cc084bd67d
commit
0895f10c99
|
@ -5,7 +5,7 @@ package io.metersphere.bug.constants;
|
|||
*/
|
||||
public class BugExportMultipleField {
|
||||
|
||||
public static final String MULTIPLE_FIELD = "multiple";
|
||||
public static final String CASCADING_FIELD = "cascading";
|
||||
public static final String CHECKBOX_FIELD = "checkbox";
|
||||
public static final String MULTIPLE_FIELD = "MULTIPLE";
|
||||
public static final String CASCADING_FIELD = "CASCADER";
|
||||
public static final String CHECKBOX_FIELD = "CHECKBOX";
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import io.metersphere.bug.constants.BugExportColumns;
|
|||
import io.metersphere.bug.domain.Bug;
|
||||
import io.metersphere.bug.dto.BugSyncResult;
|
||||
import io.metersphere.bug.dto.request.*;
|
||||
import io.metersphere.bug.dto.response.BugColumnsOptionResponse;
|
||||
import io.metersphere.bug.dto.response.BugColumnsOptionDTO;
|
||||
import io.metersphere.bug.dto.response.BugDTO;
|
||||
import io.metersphere.bug.dto.response.BugDetailDTO;
|
||||
import io.metersphere.bug.service.*;
|
||||
|
@ -79,8 +79,8 @@ public class BugController {
|
|||
@Operation(summary = "缺陷管理-列表-获取表头状态选项")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_BUG_READ)
|
||||
@CheckOwner(resourceId = "#projectId", resourceType = "project")
|
||||
public BugColumnsOptionResponse getHeaderStatusOption(@PathVariable String projectId) {
|
||||
return bugStatusService.getColumnsOption(projectId);
|
||||
public BugColumnsOptionDTO getHeaderOption(@PathVariable String projectId) {
|
||||
return bugService.getHeaderOption(projectId);
|
||||
}
|
||||
|
||||
@PostMapping("/page")
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.util.List;
|
|||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class BugColumnsOptionResponse {
|
||||
public class BugColumnsOptionDTO {
|
||||
@Schema(description = "用户相关的下拉选项")
|
||||
List<SelectOption> userOption;
|
||||
@Schema(description = "处理人下拉选项")
|
|
@ -7,7 +7,7 @@ public enum BugAttachmentSourceType {
|
|||
*/
|
||||
ATTACHMENT,
|
||||
/**
|
||||
* 缺陷内容
|
||||
* 富文本
|
||||
*/
|
||||
RICH_TEXT
|
||||
}
|
||||
|
|
|
@ -12,23 +12,7 @@ public enum BugPlatform {
|
|||
/**
|
||||
* 本地
|
||||
*/
|
||||
LOCAL("Local"),
|
||||
/**
|
||||
* Jira
|
||||
*/
|
||||
JIRA("Jira"),
|
||||
/**
|
||||
* Tapd
|
||||
*/
|
||||
TAPD("Tapd"),
|
||||
/**
|
||||
* 禅道
|
||||
*/
|
||||
ZENDAO("Zentao"),
|
||||
/**
|
||||
* Azure
|
||||
*/
|
||||
AZURE("Azure");
|
||||
LOCAL("Local");
|
||||
|
||||
private final String name;
|
||||
|
||||
|
|
|
@ -66,5 +66,10 @@ public interface ExtBugRelateCaseMapper {
|
|||
*/
|
||||
List<BugProviderDTO> getAssociateBugs(@Param("request") AssociateBugPageRequest request, @Param("sort") String sort);
|
||||
|
||||
/**
|
||||
* 获取关联的Case数量
|
||||
* @param caseId 用例ID
|
||||
* @return 关联数量
|
||||
*/
|
||||
long countByCaseId(String caseId);
|
||||
}
|
||||
|
|
|
@ -95,6 +95,7 @@
|
|||
brc.create_time desc
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="countByCaseId" resultType="java.lang.Long">
|
||||
SELECT count(fc.id)
|
||||
FROM bug_relation_case brc
|
||||
|
|
|
@ -1,17 +1,27 @@
|
|||
package io.metersphere.bug.service;
|
||||
|
||||
import io.metersphere.bug.domain.*;
|
||||
import io.metersphere.bug.dto.BugTemplateInjectField;
|
||||
import io.metersphere.bug.enums.BugPlatform;
|
||||
import io.metersphere.bug.enums.BugTemplateCustomField;
|
||||
import io.metersphere.bug.mapper.*;
|
||||
import io.metersphere.plugin.platform.dto.SelectOption;
|
||||
import io.metersphere.plugin.platform.dto.request.GetOptionRequest;
|
||||
import io.metersphere.plugin.platform.spi.AbstractPlatformPlugin;
|
||||
import io.metersphere.plugin.platform.spi.Platform;
|
||||
import io.metersphere.project.domain.FileAssociationExample;
|
||||
import io.metersphere.project.dto.ProjectUserDTO;
|
||||
import io.metersphere.project.mapper.FileAssociationMapper;
|
||||
import io.metersphere.project.request.ProjectMemberRequest;
|
||||
import io.metersphere.project.service.FileService;
|
||||
import io.metersphere.project.service.ProjectApplicationService;
|
||||
import io.metersphere.project.service.ProjectMemberService;
|
||||
import io.metersphere.sdk.constants.DefaultRepositoryDir;
|
||||
import io.metersphere.sdk.constants.StorageType;
|
||||
import io.metersphere.sdk.file.FileRequest;
|
||||
import io.metersphere.sdk.util.FileAssociationSourceUtil;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.sdk.util.LogUtils;
|
||||
import io.metersphere.system.domain.ServiceIntegration;
|
||||
import io.metersphere.system.service.PlatformPluginService;
|
||||
import io.metersphere.system.service.PluginLoadService;
|
||||
|
@ -28,13 +38,29 @@ import java.util.Map;
|
|||
@Transactional(rollbackFor = Exception.class)
|
||||
public class BugCommonService {
|
||||
|
||||
@Resource
|
||||
private FileService fileService;
|
||||
@Resource
|
||||
private BugCommentMapper bugCommentMapper;
|
||||
@Resource
|
||||
private BugContentMapper bugContentMapper;
|
||||
@Resource
|
||||
private BugFollowerMapper bugFollowerMapper;
|
||||
@Resource
|
||||
private PluginLoadService pluginLoadService;
|
||||
@Resource
|
||||
private BugCustomFieldMapper bugCustomFieldMapper;
|
||||
@Resource
|
||||
private ProjectMemberService projectMemberService;
|
||||
@Resource
|
||||
private BugRelationCaseMapper bugRelationCaseMapper;
|
||||
@Resource
|
||||
private PlatformPluginService platformPluginService;
|
||||
@Resource
|
||||
private FileAssociationMapper fileAssociationMapper;
|
||||
@Resource
|
||||
private BugLocalAttachmentMapper bugLocalAttachmentMapper;
|
||||
@Resource
|
||||
private ProjectApplicationService projectApplicationService;
|
||||
|
||||
/**
|
||||
|
@ -98,4 +124,52 @@ public class BugCommonService {
|
|||
String injectFields = JSON.toJSONString(((Map<?, ?>) scriptContent).get("injectFields"));
|
||||
return JSON.parseArray(injectFields, BugTemplateInjectField.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空缺陷关联的资源(删除缺陷)
|
||||
* @param projectId 项目ID
|
||||
* @param bugIds 缺陷ID集合
|
||||
*/
|
||||
public void clearAssociateResource(String projectId, List<String> bugIds) {
|
||||
// 清空附件(关联, 本地上传, 富文本)
|
||||
FileAssociationExample example = new FileAssociationExample();
|
||||
example.createCriteria().andSourceIdIn(bugIds).andSourceTypeEqualTo(FileAssociationSourceUtil.SOURCE_TYPE_BUG);
|
||||
fileAssociationMapper.deleteByExample(example);
|
||||
BugLocalAttachmentExample attachmentExample = new BugLocalAttachmentExample();
|
||||
attachmentExample.createCriteria().andBugIdIn(bugIds);
|
||||
List<BugLocalAttachment> bugLocalAttachments = bugLocalAttachmentMapper.selectByExample(attachmentExample);
|
||||
// 附件类型
|
||||
bugLocalAttachments.forEach(bugLocalAttachment -> {
|
||||
FileRequest fileRequest = new FileRequest();
|
||||
fileRequest.setFolder(DefaultRepositoryDir.getBugDir(projectId, bugLocalAttachment.getBugId()) + "/" + bugLocalAttachment.getFileId());
|
||||
fileRequest.setFileName(StringUtils.isEmpty(bugLocalAttachment.getFileName()) ? null : bugLocalAttachment.getFileName());
|
||||
fileRequest.setStorage(StorageType.MINIO.name());
|
||||
try {
|
||||
fileService.deleteFile(fileRequest);
|
||||
} catch (Exception e) {
|
||||
LogUtils.info("清理缺陷相关附件发生错误: " + e.getMessage());
|
||||
}
|
||||
});
|
||||
bugLocalAttachmentMapper.deleteByExample(attachmentExample);
|
||||
// 清空缺陷内容
|
||||
BugContentExample contentExample = new BugContentExample();
|
||||
contentExample.createCriteria().andBugIdIn(bugIds);
|
||||
bugContentMapper.deleteByExample(contentExample);
|
||||
// 清除自定义字段关系
|
||||
BugCustomFieldExample customFieldExample = new BugCustomFieldExample();
|
||||
customFieldExample.createCriteria().andBugIdIn(bugIds);
|
||||
bugCustomFieldMapper.deleteByExample(customFieldExample);
|
||||
// 清空关联用例
|
||||
BugRelationCaseExample relationCaseExample = new BugRelationCaseExample();
|
||||
relationCaseExample.createCriteria().andBugIdIn(bugIds);
|
||||
bugRelationCaseMapper.deleteByExample(relationCaseExample);
|
||||
// 清空评论
|
||||
BugCommentExample commentExample = new BugCommentExample();
|
||||
commentExample.createCriteria().andBugIdIn(bugIds);
|
||||
bugCommentMapper.deleteByExample(commentExample);
|
||||
// 清空关注人
|
||||
BugFollowerExample followerExample = new BugFollowerExample();
|
||||
followerExample.createCriteria().andBugIdIn(bugIds);
|
||||
bugFollowerMapper.deleteByExample(followerExample);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,16 +114,15 @@ public class BugRelateCaseCommonService extends ModuleTreeService {
|
|||
List<BugRelationCase> planRelatedCases = bugRelationCaseMapper.selectByExample(bugRelationCaseExample);
|
||||
Map<String, String> planRelatedMap = planRelatedCases.stream().collect(Collectors.toMap(BugRelationCase::getTestPlanCaseId, BugRelationCase::getId));
|
||||
relatedIds.forEach(relatedId -> {
|
||||
if (planRelatedMap.containsKey(relatedId)) {
|
||||
BugRelationCase record = new BugRelationCase();
|
||||
if (planRelatedMap.containsKey(relatedId)) {
|
||||
// 计划已关联
|
||||
BugRelationCase record = new BugRelationCase();
|
||||
record.setId(planRelatedMap.get(relatedId));
|
||||
record.setId(planRelatedMap.get(relatedId));
|
||||
record.setCaseId(relatedId);
|
||||
record.setUpdateTime(System.currentTimeMillis());
|
||||
relationCaseMapper.updateByPrimaryKeySelective(record);
|
||||
} else {
|
||||
BugRelationCase record = new BugRelationCase();
|
||||
record.setId(IDGenerator.nextStr());
|
||||
record.setId(IDGenerator.nextStr());
|
||||
record.setCaseId(relatedId);
|
||||
record.setBugId(request.getSourceId());
|
||||
record.setCaseType(request.getSourceType());
|
||||
|
|
|
@ -103,6 +103,8 @@ public class BugService {
|
|||
@Resource
|
||||
protected TemplateMapper templateMapper;
|
||||
@Resource
|
||||
private BugCommentMapper bugCommentMapper;
|
||||
@Resource
|
||||
private BugContentMapper bugContentMapper;
|
||||
@Resource
|
||||
private SqlSessionFactory sqlSessionFactory;
|
||||
|
@ -190,7 +192,7 @@ public class BugService {
|
|||
* @return 缺陷
|
||||
*/
|
||||
public Bug addOrUpdate(BugEditRequest request, List<MultipartFile> files, String currentUser, String currentOrgId, boolean isUpdate) {
|
||||
// 校验标签长度
|
||||
// 前置校验: 标签长度
|
||||
this.checkTagLength(request.getTags());
|
||||
/*
|
||||
* 缺陷创建或者修改逻辑:
|
||||
|
@ -199,7 +201,7 @@ public class BugService {
|
|||
* 3. 保存MS缺陷(基础字段, 自定义字段)
|
||||
* 4. 处理附件(第三方平台缺陷需异步调用接口同步附件至第三方)
|
||||
* 5. 处理富文本临时文件
|
||||
* 6. 处理缺陷-用例关联关系
|
||||
* 6. 处理用例关联关系
|
||||
*/
|
||||
String platformName = projectApplicationService.getPlatformName(request.getProjectId());
|
||||
PlatformBugUpdateDTO platformBug = null;
|
||||
|
@ -326,7 +328,7 @@ public class BugService {
|
|||
platform.deleteBug(bug.getPlatformBugId());
|
||||
}
|
||||
// 删除缺陷后, 前置操作: 删除关联用例, 删除关联附件
|
||||
clearAssociate(id, bug.getProjectId());
|
||||
bugCommonService.clearAssociateResource(bug.getProjectId(), List.of(id));
|
||||
bugMapper.deleteByPrimaryKey(id);
|
||||
}
|
||||
}
|
||||
|
@ -498,6 +500,19 @@ public class BugService {
|
|||
bugFollowerMapper.deleteByExample(example);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表头列选项
|
||||
* @param projectId 项目ID
|
||||
* @return 表头列选项
|
||||
*/
|
||||
public BugColumnsOptionDTO getHeaderOption(String projectId) {
|
||||
return new BugColumnsOptionDTO(
|
||||
bugCommonService.getLocalHandlerOption(projectId),
|
||||
bugCommonService.getHeaderHandlerOption(projectId),
|
||||
bugStatusService.getHeaderStatusOption(projectId)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步平台缺陷(全量)
|
||||
* @param request 同步请求参数
|
||||
|
@ -600,38 +615,8 @@ public class BugService {
|
|||
|
||||
// 批量更新缺陷
|
||||
updateBugs.forEach(updateBug -> {
|
||||
if (CollectionUtils.isNotEmpty(updateBug.getRichTextImageKeys())) {
|
||||
// 同步第三方的富文本文件
|
||||
updateBug.getRichTextImageKeys().forEach(key -> {
|
||||
platform.getAttachmentContent(key, (in) -> {
|
||||
if (in == null) {
|
||||
return;
|
||||
}
|
||||
String fileId = IDGenerator.nextStr();
|
||||
byte[] bytes;
|
||||
try {
|
||||
// upload platform attachment to minio
|
||||
bytes = in.readAllBytes();
|
||||
FileCenter.getDefaultRepository().saveFile(bytes, buildBugFileRequest(updateBug.getProjectId(), updateBug.getId(), fileId, "image.png"));
|
||||
} catch (Exception e) {
|
||||
throw new MSException(e.getMessage());
|
||||
}
|
||||
// save bug attachment relation
|
||||
BugLocalAttachment localAttachment = new BugLocalAttachment();
|
||||
localAttachment.setId(IDGenerator.nextStr());
|
||||
localAttachment.setBugId(updateBug.getId());
|
||||
localAttachment.setFileId(fileId);
|
||||
localAttachment.setFileName("image.png");
|
||||
localAttachment.setSize((long) bytes.length);
|
||||
localAttachment.setCreateTime(System.currentTimeMillis());
|
||||
localAttachment.setCreateUser("admin");
|
||||
localAttachment.setSource(BugAttachmentSourceType.RICH_TEXT.name());
|
||||
bugLocalAttachmentMapper.insert(localAttachment);
|
||||
// 替换富文本中的临时URL
|
||||
updateBug.setDescription(updateBug.getDescription().replace("alt=\"" + key + "\"", "src=\"/attachment/download/file/" + updateBug.getProjectId() + "/" + fileId + "/true\""));
|
||||
});
|
||||
});
|
||||
}
|
||||
// 处理同步的BUG中的富文本图片
|
||||
syncRichTextToMs(updateBug, platform);
|
||||
updateBug.setCreateUser(null);
|
||||
Bug bug = new Bug();
|
||||
BeanUtils.copyBean(bug, updateBug);
|
||||
|
@ -660,7 +645,7 @@ public class BugService {
|
|||
|
||||
// 批量删除缺陷
|
||||
syncBugResult.getDeleteBugIds().forEach(deleteBugId -> {
|
||||
clearAssociate(deleteBugId, project.getId());
|
||||
bugCommonService.clearAssociateResource(project.getId(), List.of(deleteBugId));
|
||||
bugMapper.deleteByPrimaryKey(deleteBugId);
|
||||
});
|
||||
|
||||
|
@ -1265,6 +1250,44 @@ public class BugService {
|
|||
return bugs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理同步缺陷中的富文本图片
|
||||
* @param updateBug 同步更新的缺陷
|
||||
* @param platform 平台对象
|
||||
*/
|
||||
private void syncRichTextToMs(PlatformBugDTO updateBug, Platform platform) {
|
||||
if (CollectionUtils.isNotEmpty(updateBug.getRichTextImageKeys())) {
|
||||
// 同步第三方的富文本文件
|
||||
updateBug.getRichTextImageKeys().forEach(key -> platform.getAttachmentContent(key, (in) -> {
|
||||
if (in == null) {
|
||||
return;
|
||||
}
|
||||
String fileId = IDGenerator.nextStr();
|
||||
byte[] bytes;
|
||||
try {
|
||||
// upload platform attachment to minio
|
||||
bytes = in.readAllBytes();
|
||||
FileCenter.getDefaultRepository().saveFile(bytes, buildBugFileRequest(updateBug.getProjectId(), updateBug.getId(), fileId, "image.png"));
|
||||
} catch (Exception e) {
|
||||
throw new MSException(e.getMessage());
|
||||
}
|
||||
// save bug attachment relation
|
||||
BugLocalAttachment localAttachment = new BugLocalAttachment();
|
||||
localAttachment.setId(IDGenerator.nextStr());
|
||||
localAttachment.setBugId(updateBug.getId());
|
||||
localAttachment.setFileId(fileId);
|
||||
localAttachment.setFileName("image.png");
|
||||
localAttachment.setSize((long) bytes.length);
|
||||
localAttachment.setCreateTime(System.currentTimeMillis());
|
||||
localAttachment.setCreateUser("admin");
|
||||
localAttachment.setSource(BugAttachmentSourceType.RICH_TEXT.name());
|
||||
bugLocalAttachmentMapper.insert(localAttachment);
|
||||
// 替换富文本中的临时URL
|
||||
updateBug.setDescription(updateBug.getDescription().replace("alt=\"" + key + "\"", "src=\"/attachment/download/file/" + updateBug.getProjectId() + "/" + fileId + "/true\""));
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 自定义字段转换为平台字段
|
||||
|
@ -1351,42 +1374,6 @@ public class BugService {
|
|||
return template;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空关联信息
|
||||
* @param bugId 缺陷ID
|
||||
* @param projectId 项目ID
|
||||
*/
|
||||
public void clearAssociate(String bugId, String projectId) {
|
||||
// 清空附件关系及本地附件
|
||||
FileAssociationExample example = new FileAssociationExample();
|
||||
example.createCriteria().andSourceIdEqualTo(bugId).andSourceTypeEqualTo(FileAssociationSourceUtil.SOURCE_TYPE_BUG);
|
||||
fileAssociationMapper.deleteByExample(example);
|
||||
BugLocalAttachmentExample attachmentExample = new BugLocalAttachmentExample();
|
||||
attachmentExample.createCriteria().andBugIdEqualTo(bugId);
|
||||
List<BugLocalAttachment> bugLocalAttachments = bugLocalAttachmentMapper.selectByExample(attachmentExample);
|
||||
bugLocalAttachments.forEach(bugLocalAttachment -> {
|
||||
FileRequest fileRequest = buildBugFileRequest(projectId, bugId, bugLocalAttachment.getFileId(), bugLocalAttachment.getFileName());
|
||||
try {
|
||||
fileService.deleteFile(fileRequest);
|
||||
} catch (Exception e) {
|
||||
throw new MSException(e);
|
||||
}
|
||||
});
|
||||
bugLocalAttachmentMapper.deleteByExample(attachmentExample);
|
||||
// 清空关联用例
|
||||
BugRelationCaseExample relationCaseExample = new BugRelationCaseExample();
|
||||
relationCaseExample.createCriteria().andBugIdEqualTo(bugId);
|
||||
bugRelationCaseMapper.deleteByExample(relationCaseExample);
|
||||
// 清除自定义字段关系
|
||||
BugCustomFieldExample customFieldExample = new BugCustomFieldExample();
|
||||
customFieldExample.createCriteria().andBugIdEqualTo(bugId);
|
||||
bugCustomFieldMapper.deleteByExample(customFieldExample);
|
||||
// 清空缺陷内容
|
||||
BugContentExample contentExample = new BugContentExample();
|
||||
contentExample.createCriteria().andBugIdEqualTo(bugId);
|
||||
bugContentMapper.deleteByExample(contentExample);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param operator 操作人
|
||||
|
|
|
@ -2,7 +2,6 @@ package io.metersphere.bug.service;
|
|||
|
||||
import io.metersphere.bug.domain.Bug;
|
||||
import io.metersphere.bug.domain.BugExample;
|
||||
import io.metersphere.bug.dto.response.BugColumnsOptionResponse;
|
||||
import io.metersphere.bug.enums.BugPlatform;
|
||||
import io.metersphere.bug.mapper.BugMapper;
|
||||
import io.metersphere.plugin.platform.dto.SelectOption;
|
||||
|
@ -29,8 +28,6 @@ public class BugStatusService {
|
|||
private ProjectApplicationService projectApplicationService;
|
||||
@Resource
|
||||
private BaseStatusFlowSettingService baseStatusFlowSettingService;
|
||||
@Resource
|
||||
private BugCommonService bugCommonService;
|
||||
|
||||
/**
|
||||
* 获取表头缺陷状态选项
|
||||
|
@ -114,17 +111,4 @@ public class BugStatusService {
|
|||
return StringUtils.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取
|
||||
* @param projectId
|
||||
* @return
|
||||
*/
|
||||
public BugColumnsOptionResponse getColumnsOption(String projectId) {
|
||||
return new BugColumnsOptionResponse(
|
||||
bugCommonService.getLocalHandlerOption(projectId),
|
||||
bugCommonService.getHeaderHandlerOption(projectId),
|
||||
getHeaderStatusOption(projectId)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ public class BugSyncNoticeService {
|
|||
Map<String, String> defaultSubjectMap = MessageTemplateUtils.getDefaultTemplateSubjectMap();
|
||||
String subject = defaultSubjectMap.get(NoticeConstants.TemplateText.BUG_SYNC_TASK_EXECUTE_COMPLETED);
|
||||
// ${OPERATOR}同步了${total}条缺陷
|
||||
Map paramMap = new HashMap<>();
|
||||
Map<String, Object> paramMap = new HashMap<>(3);
|
||||
paramMap.put(NoticeConstants.RelatedUser.OPERATOR, user.getName());
|
||||
paramMap.put("total", total);
|
||||
paramMap.put("projectId", projectId);
|
||||
|
|
|
@ -1,106 +0,0 @@
|
|||
package io.metersphere.bug.service;
|
||||
|
||||
import io.metersphere.bug.domain.*;
|
||||
import io.metersphere.bug.mapper.*;
|
||||
import io.metersphere.sdk.util.LogUtils;
|
||||
import io.metersphere.system.service.CleanupProjectResourceService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 缺陷相关资源清理
|
||||
*/
|
||||
@Component
|
||||
public class CleanupBugResourceService implements CleanupProjectResourceService {
|
||||
|
||||
@Resource
|
||||
private BugMapper bugMapper;
|
||||
@Resource
|
||||
private BugContentMapper bugContentMapper;
|
||||
@Resource
|
||||
private BugFollowerMapper bugFollowerMapper;
|
||||
@Resource
|
||||
private BugLocalAttachmentMapper bugLocalAttachmentMapper;
|
||||
@Resource
|
||||
private BugCommentMapper bugCommentMapper;
|
||||
@Resource
|
||||
private BugCustomFieldMapper bugCustomFieldMapper;
|
||||
@Resource
|
||||
private BugRelationCaseMapper bugRelationCaseMapper;
|
||||
|
||||
@Async
|
||||
@Override
|
||||
public void deleteResources(String projectId) {
|
||||
LogUtils.info("删除当前项目[" + projectId + "]相关缺陷测试资源");
|
||||
List<String> deleteIds = getBugIds(projectId);
|
||||
if (CollectionUtils.isNotEmpty(deleteIds)) {
|
||||
// 清理缺陷
|
||||
deleteBug(deleteIds);
|
||||
// 清理缺陷内容
|
||||
deleteBugContent(deleteIds);
|
||||
// 清理缺陷关注人信息
|
||||
deleteBugFollower(deleteIds);
|
||||
// 清理缺陷本地附件
|
||||
deleteBugLocalAttachment(deleteIds);
|
||||
// 清理缺陷评论
|
||||
deleteBugComment(deleteIds);
|
||||
// 清理缺陷自定义字段
|
||||
deleteBugCustomField(deleteIds);
|
||||
// 清理缺陷关联用例
|
||||
deleteBugRelateCase(deleteIds);
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getBugIds(String projectId) {
|
||||
BugExample example = new BugExample();
|
||||
example.createCriteria().andProjectIdEqualTo(projectId);
|
||||
List<Bug> bugs = bugMapper.selectByExample(example);
|
||||
return bugs.stream().map(Bug::getId).toList();
|
||||
}
|
||||
|
||||
private void deleteBug(List<String> bugIds) {
|
||||
BugExample example = new BugExample();
|
||||
example.createCriteria().andIdIn(bugIds);
|
||||
bugMapper.deleteByExample(example);
|
||||
}
|
||||
|
||||
private void deleteBugContent(List<String> bugIds) {
|
||||
BugContentExample example = new BugContentExample();
|
||||
example.createCriteria().andBugIdIn(bugIds);
|
||||
bugContentMapper.deleteByExample(example);
|
||||
}
|
||||
|
||||
private void deleteBugFollower(List<String> bugIds) {
|
||||
BugFollowerExample example = new BugFollowerExample();
|
||||
example.createCriteria().andBugIdIn(bugIds);
|
||||
bugFollowerMapper.deleteByExample(example);
|
||||
}
|
||||
|
||||
private void deleteBugLocalAttachment(List<String> bugIds) {
|
||||
BugLocalAttachmentExample example = new BugLocalAttachmentExample();
|
||||
example.createCriteria().andBugIdIn(bugIds);
|
||||
bugLocalAttachmentMapper.deleteByExample(example);
|
||||
}
|
||||
|
||||
private void deleteBugComment(List<String> bugIds) {
|
||||
BugCommentExample example = new BugCommentExample();
|
||||
example.createCriteria().andBugIdIn(bugIds);
|
||||
bugCommentMapper.deleteByExample(example);
|
||||
}
|
||||
|
||||
private void deleteBugCustomField(List<String> bugIds) {
|
||||
BugCustomFieldExample example = new BugCustomFieldExample();
|
||||
example.createCriteria().andBugIdIn(bugIds);
|
||||
bugCustomFieldMapper.deleteByExample(example);
|
||||
}
|
||||
|
||||
private void deleteBugRelateCase(List<String> bugIds) {
|
||||
BugRelationCaseExample example = new BugRelationCaseExample();
|
||||
example.createCriteria().andBugIdIn(bugIds);
|
||||
bugRelationCaseMapper.deleteByExample(example);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
package io.metersphere.bug.service;
|
||||
|
||||
import io.metersphere.bug.domain.Bug;
|
||||
import io.metersphere.bug.domain.BugExample;
|
||||
import io.metersphere.bug.mapper.BugMapper;
|
||||
import io.metersphere.sdk.util.LogUtils;
|
||||
import io.metersphere.system.service.CleanupProjectResourceService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 缺陷相关资源清理
|
||||
*/
|
||||
@Component
|
||||
public class CleanupBugResourceServiceImpl implements CleanupProjectResourceService {
|
||||
|
||||
@Resource
|
||||
private BugMapper bugMapper;
|
||||
@Resource
|
||||
private BugCommonService bugCommonService;
|
||||
|
||||
@Async
|
||||
@Override
|
||||
public void deleteResources(String projectId) {
|
||||
LogUtils.info("删除当前项目[" + projectId + "]相关缺陷测试资源");
|
||||
List<String> deleteIds = getBugIds(projectId);
|
||||
if (CollectionUtils.isNotEmpty(deleteIds)) {
|
||||
// 清理缺陷
|
||||
deleteBug(deleteIds);
|
||||
// 清空关联关系
|
||||
bugCommonService.clearAssociateResource(projectId, deleteIds);
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getBugIds(String projectId) {
|
||||
BugExample example = new BugExample();
|
||||
example.createCriteria().andProjectIdEqualTo(projectId);
|
||||
List<Bug> bugs = bugMapper.selectByExample(example);
|
||||
return bugs.stream().map(Bug::getId).toList();
|
||||
}
|
||||
|
||||
private void deleteBug(List<String> bugIds) {
|
||||
BugExample example = new BugExample();
|
||||
example.createCriteria().andIdIn(bugIds);
|
||||
bugMapper.deleteByExample(example);
|
||||
}
|
||||
}
|
|
@ -4,7 +4,7 @@ import io.metersphere.bug.dto.request.BugSyncRequest;
|
|||
import io.metersphere.project.domain.Project;
|
||||
|
||||
/**
|
||||
* 缺陷相关xpack功能接口
|
||||
* 缺陷相关企业版功能接口
|
||||
*/
|
||||
public interface XpackBugService {
|
||||
|
||||
|
@ -16,7 +16,7 @@ public interface XpackBugService {
|
|||
void syncPlatformBugsBySchedule(String projectId, String scheduleUser);
|
||||
|
||||
/**
|
||||
* 同步当前项目第三方平台缺陷(前台调用, 全量同步)
|
||||
* 同步当前项目第三方平台缺陷(前台调用, 支持全量及同步条件区间)
|
||||
* @param project 项目
|
||||
* @param request 同步请求参数
|
||||
* @param currentUser 当前用户
|
||||
|
|
|
@ -2,7 +2,6 @@ package io.metersphere.bug.service;
|
|||
|
||||
import io.metersphere.system.base.BaseTest;
|
||||
import io.metersphere.system.invoker.ProjectServiceInvoker;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -19,8 +18,6 @@ import org.springframework.test.context.jdbc.SqlConfig;
|
|||
public class CleanBugResourceServiceTests extends BaseTest {
|
||||
|
||||
private final ProjectServiceInvoker serviceInvoker;
|
||||
@Resource
|
||||
private CleanupBugResourceService cleanupBugResourceService;
|
||||
|
||||
@Autowired
|
||||
public CleanBugResourceServiceTests(ProjectServiceInvoker serviceInvoker) {
|
||||
|
|
Loading…
Reference in New Issue