fix(测试跟踪): 升级导致的附件旧数据处理问题

This commit is contained in:
song-cc-rock 2023-04-06 20:56:10 +08:00
parent cd4bccf4c1
commit 3c954f9ee6
4 changed files with 17 additions and 2 deletions

View File

@ -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

View File

@ -15,4 +15,9 @@ public interface ExtAttachmentModuleRelationMapper {
* @param attachmentModuleRelations 附件关系记录
*/
void batchInsert(@Param("attachmentModuleRelations") List<AttachmentModuleRelation> attachmentModuleRelations);
/**
* 批量更新test_case=>testcase
*/
void batchUpdateErrRelationType();
}

View File

@ -9,4 +9,8 @@
(#{relation.relationId}, #{relation.relationType}, #{relation.attachmentId}, #{relation.fileMetadataRefId})
</foreach>
</insert>
<update id="batchUpdateErrRelationType">
UPDATE attachment_module_relation SET relation_type = 'testcase' where relation_type = 'test_case'
</update>
</mapper>

View File

@ -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<FileMetadata> allCaseFileMetadatas = fileMetadataMapper.selectByExample(fileMetadataExample);
FileContentExample fileContentExample = new FileContentExample();
fileContentExample.createCriteria().andFileIdIn(fileIds);
List<FileContent> allCaseFileContents = fileContentMapper.selectByExample(fileContentExample);
List<FileContent> allCaseFileContents = fileContentMapper.selectByExampleWithBLOBs(fileContentExample);
entry.getValue().stream().forEach(relation -> {
String filename = StringUtils.EMPTY;
List<FileMetadata> 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());