From e62e3c7b759a2be6bb739847aced060cef76f3a4 Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Wed, 20 Jul 2022 10:26:25 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):?= =?UTF-8?q?=20=E9=99=84=E4=BB=B6=E5=8A=9F=E8=83=BD=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --story=1006991 --user=宋昌昌 【测试跟踪】功能用例&缺陷增加附件功能支持视频文件(1.20分支同步上) https://www.tapd.cn/55049933/s/1204166 --- .../listener/AppStartListener.java | 3 +- .../track/service/TestCaseService.java | 30 +++++++++++-------- .../db/migration/V125__2.0.0_ddl__release.sql | 24 ++++++++------- .../db/migration/V126__2.0.0_dml__release.sql | 6 ++++ 4 files changed, 38 insertions(+), 25 deletions(-) diff --git a/backend/src/main/java/io/metersphere/listener/AppStartListener.java b/backend/src/main/java/io/metersphere/listener/AppStartListener.java index 60467cb5f8..516fcb82b1 100644 --- a/backend/src/main/java/io/metersphere/listener/AppStartListener.java +++ b/backend/src/main/java/io/metersphere/listener/AppStartListener.java @@ -159,8 +159,7 @@ public class AppStartListener implements ApplicationListener testCaseFiles = testCaseFileMapper.selectByExample(example); + // 用例有关附件处理 + AttachmentModuleRelationExample relationExample = new AttachmentModuleRelationExample(); + relationExample.createCriteria().andRelationTypeEqualTo(AttachmentType.TEST_CASE.type()); + List relations = attachmentModuleRelationMapper.selectByExample(relationExample); List allFileMeta = fileService.getAllFileMeta(); List allFileContent = fileService.getAllFileContent(); - Map> testCaseFileGroup = testCaseFiles.stream().collect(Collectors.groupingBy(TestCaseFile::getCaseId)); - for(Map.Entry> entry : testCaseFileGroup.entrySet()) { + Map> relationGroup = relations.stream().collect(Collectors.groupingBy(AttachmentModuleRelation::getRelationId)); + for(Map.Entry> 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 fileMetadatas = allFileMeta.stream().filter(fileMetadata -> fileMetadata.getId().equals(testCaseFile.getFileId())) + List fileMetadatas = allFileMeta.stream().filter(fileMetadata -> fileMetadata.getId().equals(relation.getAttachmentId())) .collect(Collectors.toList()); - List fileContents = allFileContent.stream().filter(fileContent -> fileContent.getFileId().equals(testCaseFile.getFileId())) + List 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 { } }); } - } /** diff --git a/backend/src/main/resources/db/migration/V125__2.0.0_ddl__release.sql b/backend/src/main/resources/db/migration/V125__2.0.0_ddl__release.sql index 399f6f676b..5295f899b1 100644 --- a/backend/src/main/resources/db/migration/V125__2.0.0_ddl__release.sql +++ b/backend/src/main/resources/db/migration/V125__2.0.0_ddl__release.sql @@ -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 '需要同步的开始时间'; \ No newline at end of file + 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; \ No newline at end of file diff --git a/backend/src/main/resources/db/migration/V126__2.0.0_dml__release.sql b/backend/src/main/resources/db/migration/V126__2.0.0_dml__release.sql index 5cb1db5d69..f61c9ed8c6 100644 --- a/backend/src/main/resources/db/migration/V126__2.0.0_dml__release.sql +++ b/backend/src/main/resources/db/migration/V126__2.0.0_dml__release.sql @@ -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;