refactor(测试跟踪): 附件功能代码优化处理

--story=1006991 --user=宋昌昌 【测试跟踪】功能用例&缺陷增加附件功能支持视频文件(1.20分支同步上) https://www.tapd.cn/55049933/s/1204166
This commit is contained in:
song-cc-rock 2022-07-20 10:26:25 +08:00 committed by f2c-ci-robot[bot]
parent 8c469a6893
commit e62e3c7b75
4 changed files with 38 additions and 25 deletions

View File

@ -159,8 +159,7 @@ public class AppStartListener implements ApplicationListener<ApplicationReadyEve
initOnceOperate(mockConfigService::initExpectNum, "init.mock.expectNum");
initOnceOperate(customFieldResourceService::compatibleData, "init.custom.field.resource");
initOnceOperate(jarConfigService::initJarPath, "init.jar.path");
initOnceOperate(testCaseService::initAttachment, "init.attachment.test.case");
initOnceOperate(attachmentService::initAttachment, "init.attachment.all");
initOnceOperate(testCaseService::initAttachment, "init.test.case.attachment");
}
/**

View File

@ -127,6 +127,8 @@ public class TestCaseService {
@Resource
TestCaseTestMapper testCaseTestMapper;
@Resource
AttachmentModuleRelationMapper attachmentModuleRelationMapper;
@Resource
private LoadTestMapper loadTestMapper;
@Resource
private ApiScenarioMapper apiScenarioMapper;
@ -2549,19 +2551,21 @@ public class TestCaseService {
}
public void initAttachment() {
TestCaseFileExample example = new TestCaseFileExample();
List<TestCaseFile> testCaseFiles = testCaseFileMapper.selectByExample(example);
// 用例有关附件处理
AttachmentModuleRelationExample relationExample = new AttachmentModuleRelationExample();
relationExample.createCriteria().andRelationTypeEqualTo(AttachmentType.TEST_CASE.type());
List<AttachmentModuleRelation> relations = attachmentModuleRelationMapper.selectByExample(relationExample);
List<FileMetadata> allFileMeta = fileService.getAllFileMeta();
List<FileContent> allFileContent = fileService.getAllFileContent();
Map<String, List<TestCaseFile>> testCaseFileGroup = testCaseFiles.stream().collect(Collectors.groupingBy(TestCaseFile::getCaseId));
for(Map.Entry<String, List<TestCaseFile>> entry : testCaseFileGroup.entrySet()) {
Map<String, List<AttachmentModuleRelation>> relationGroup = relations.stream().collect(Collectors.groupingBy(AttachmentModuleRelation::getRelationId));
for(Map.Entry<String, List<AttachmentModuleRelation>> entry : relationGroup.entrySet()) {
final String caseId = entry.getKey();
final String uploadPath = FileUtils.ATTACHMENT_DIR + "/" + AttachmentType.TEST_CASE.type() + "/" + caseId;
entry.getValue().stream().forEach(testCaseFile -> {
entry.getValue().stream().forEach(relation -> {
String filename = "";
List<FileMetadata> fileMetadatas = allFileMeta.stream().filter(fileMetadata -> fileMetadata.getId().equals(testCaseFile.getFileId()))
List<FileMetadata> fileMetadatas = allFileMeta.stream().filter(fileMetadata -> fileMetadata.getId().equals(relation.getAttachmentId()))
.collect(Collectors.toList());
List<FileContent> fileContents = allFileContent.stream().filter(fileContent -> fileContent.getFileId().equals(testCaseFile.getFileId()))
List<FileContent> fileContents = allFileContent.stream().filter(fileContent -> fileContent.getFileId().equals(relation.getAttachmentId()))
.collect(Collectors.toList());
if (fileMetadatas.size() == 1) {
FileMetadata fileMetadata = fileMetadatas.get(0);
@ -2572,11 +2576,12 @@ public class TestCaseService {
fileAttachmentMetadata.setCreator("");
fileAttachmentMetadata.setFilePath(uploadPath);
fileAttachmentMetadataMapper.insert(fileAttachmentMetadata);
TestCaseFile newTestCaseFile = new TestCaseFile();
newTestCaseFile.setFileId(fileAttachmentMetadata.getId());
TestCaseFileExample testCaseFileExample = new TestCaseFileExample();
testCaseFileExample.createCriteria().andCaseIdEqualTo(testCaseFile.getCaseId()).andFileIdEqualTo(testCaseFile.getFileId());
testCaseFileMapper.updateByExampleSelective(newTestCaseFile, testCaseFileExample);
AttachmentModuleRelation record = new AttachmentModuleRelation();
record.setAttachmentId(fileAttachmentMetadata.getId());
AttachmentModuleRelationExample example = new AttachmentModuleRelationExample();
example.createCriteria().andRelationIdEqualTo(relation.getRelationId())
.andAttachmentIdEqualTo(relation.getAttachmentId()).andRelationTypeEqualTo(relation.getRelationType());
attachmentModuleRelationMapper.updateByExample(record, example);
fileMetadataMapper.deleteByPrimaryKey(fileMetadata.getId());
}
if (StringUtils.isNotEmpty(filename) && fileContents.size() == 1) {
@ -2586,7 +2591,6 @@ public class TestCaseService {
}
});
}
}
/**

View File

@ -182,15 +182,6 @@ CREATE TABLE IF NOT EXISTS `file_attachment_metadata`
COLLATE = utf8mb4_general_ci;
CREATE TABLE IF NOT EXISTS `issue_file`
(
`issue_id` varchar(64) NOT NULL COMMENT 'ISSUE ID',
`file_id` varchar(64) NOT NULL COMMENT 'File ID',
PRIMARY KEY `issue_file_unique_key` (`issue_id`, `file_id`) USING BTREE
) ENGINE = InnoDB
CHARACTER SET = utf8mb4
COLLATE = utf8mb4_general_ci;
--
-- V129_2-0-0_test_case_report_api_base_count
ALTER TABLE `test_plan_report_content`
@ -249,4 +240,17 @@ ALTER TABLE `api_definition`
--
-- v2_api_case_add_to_update_time
ALTER TABLE `api_test_case`
ADD to_be_update_Time bigint(13) DEFAULT NULL COMMENT '需要同步的开始时间';
ADD to_be_update_Time bigint(13) DEFAULT NULL COMMENT '需要同步的开始时间';
--
-- 新增附件关系表
-- v2_init_attachment_module_relation
CREATE TABLE IF NOT EXISTS `attachment_module_relation`
(
`relation_id` varchar(64) NOT NULL COMMENT 'RELATION ID',
`relation_type` varchar(64) NOT NULL COMMENT 'RELATION TYPE',
`attachment_id` varchar(64) NOT NULL COMMENT 'ATTACHMENT ID',
INDEX `attachment_module_index`(`relation_id`, `relation_type`) USING BTREE
) ENGINE = InnoDB
CHARACTER SET = utf8mb4
COLLATE = utf8mb4_general_ci;

View File

@ -254,3 +254,9 @@ WHERE status IN ('Prepare', 'Underway', 'Failure', 'Blocking', 'Skip');
UPDATE test_case_comment
SET `type` = 'CASE'
WHERE `type` = '';
--
-- 初始化attachment_module_relation数据
INSERT INTO attachment_module_relation SELECT case_id, 'test_case', file_id FROM test_case_file;
-- 清空test_case_file表数据
DELETE FROM test_case_file;