diff --git a/system-setting/backend/src/main/resources/db/migration/V127__2.0.1__release.sql b/system-setting/backend/src/main/resources/db/migration/V127__2.0.1__release.sql index 76b9883786..4ee019aa7a 100644 --- a/system-setting/backend/src/main/resources/db/migration/V127__2.0.1__release.sql +++ b/system-setting/backend/src/main/resources/db/migration/V127__2.0.1__release.sql @@ -523,7 +523,7 @@ WHERE `type` = ''; -- -- 初始化attachment_module_relation数据 INSERT INTO attachment_module_relation -SELECT case_id, 'test_case', file_id +SELECT case_id, 'testcase', file_id FROM test_case_file; -- 清空test_case_file表数据 DELETE diff --git a/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtAttachmentModuleRelationMapper.java b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtAttachmentModuleRelationMapper.java index 2530f15a3a..3ea6d5099f 100644 --- a/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtAttachmentModuleRelationMapper.java +++ b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtAttachmentModuleRelationMapper.java @@ -15,4 +15,9 @@ public interface ExtAttachmentModuleRelationMapper { * @param attachmentModuleRelations 附件关系记录 */ void batchInsert(@Param("attachmentModuleRelations") List attachmentModuleRelations); + + /** + * 批量更新test_case=>testcase + */ + void batchUpdateErrRelationType(); } diff --git a/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtAttachmentModuleRelationMapper.xml b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtAttachmentModuleRelationMapper.xml index 911c30f4aa..8610f9b519 100644 --- a/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtAttachmentModuleRelationMapper.xml +++ b/test-track/backend/src/main/java/io/metersphere/base/mapper/ext/ExtAttachmentModuleRelationMapper.xml @@ -9,4 +9,8 @@ (#{relation.relationId}, #{relation.relationType}, #{relation.attachmentId}, #{relation.fileMetadataRefId}) + + + UPDATE attachment_module_relation SET relation_type = 'testcase' where relation_type = 'test_case' + diff --git a/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java b/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java index 5683ecb03b..0ad50722dd 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java @@ -132,6 +132,8 @@ public class TestCaseService { TestCaseTestMapper testCaseTestMapper; @Resource AttachmentModuleRelationMapper attachmentModuleRelationMapper; + @Resource + ExtAttachmentModuleRelationMapper extAttachmentModuleRelationMapper; // @Resource // private LoadTestMapper loadTestMapper; // @Resource @@ -2816,6 +2818,8 @@ public class TestCaseService { } public void initAttachment() { + // 处理SQL升级attachment_module_relation类型错误问题 + extAttachmentModuleRelationMapper.batchUpdateErrRelationType(); // 用例有关附件处理 AttachmentModuleRelationExample relationExample = new AttachmentModuleRelationExample(); relationExample.createCriteria().andRelationTypeEqualTo(AttachmentType.TEST_CASE.type()); @@ -2832,7 +2836,7 @@ public class TestCaseService { List allCaseFileMetadatas = fileMetadataMapper.selectByExample(fileMetadataExample); FileContentExample fileContentExample = new FileContentExample(); fileContentExample.createCriteria().andFileIdIn(fileIds); - List allCaseFileContents = fileContentMapper.selectByExample(fileContentExample); + List allCaseFileContents = fileContentMapper.selectByExampleWithBLOBs(fileContentExample); entry.getValue().stream().forEach(relation -> { String filename = StringUtils.EMPTY; List fileMetadatas = allCaseFileMetadatas.stream().filter(fileMetadata -> fileMetadata.getId().equals(relation.getAttachmentId())) @@ -2850,6 +2854,8 @@ public class TestCaseService { fileAttachmentMetadataMapper.insert(fileAttachmentMetadata); AttachmentModuleRelation record = new AttachmentModuleRelation(); record.setAttachmentId(fileAttachmentMetadata.getId()); + record.setRelationId(relation.getRelationId()); + record.setRelationType(relation.getRelationType()); AttachmentModuleRelationExample example = new AttachmentModuleRelationExample(); example.createCriteria().andRelationIdEqualTo(relation.getRelationId()) .andAttachmentIdEqualTo(relation.getAttachmentId()).andRelationTypeEqualTo(relation.getRelationType());