From c06192f060f4343c3a08942bff9821a7882b1e45 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Mon, 19 Sep 2022 17:54:40 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E9=A1=B9=E7=9B=AE=E8=AE=BE=E7=BD=AE):=20?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=BA=93=E7=AE=A1=E7=90=86=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=B9=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1016894 --user=宋天阳 【项目设置】性能用例关联第三方仓库文件,关联用例列表不显示该用例 https://www.tapd.cn/55049933/s/1245702 --- .../mapper/ext/ExtLoadTestFileMapper.java | 7 +++ .../base/mapper/ext/ExtLoadTestFileMapper.xml | 8 ++++ .../metadata/service/FileMetadataService.java | 45 ++++++++++++++----- .../request/QueryProjectFileRequest.java | 2 + .../menu/file/list/FileCaseRelevanceList.vue | 29 ++++++++++-- 5 files changed, 76 insertions(+), 15 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestFileMapper.java create mode 100644 backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestFileMapper.xml diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestFileMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestFileMapper.java new file mode 100644 index 0000000000..84768c9dc8 --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestFileMapper.java @@ -0,0 +1,7 @@ +package io.metersphere.base.mapper.ext; + +import org.apache.ibatis.annotations.Param; + +public interface ExtLoadTestFileMapper { + public int updateFileIdByTestIdAndFileId(@Param("fileId") String fileId, @Param("testId") String loadTestId, @Param("oldFileId") String oldFileId); +} diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestFileMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestFileMapper.xml new file mode 100644 index 0000000000..7aaafc27dd --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestFileMapper.xml @@ -0,0 +1,8 @@ + + + + + update load_test_file SET file_id = #{fileId} + WHERE test_id = #{testId} AND file_id = #{oldFileId} + + diff --git a/backend/src/main/java/io/metersphere/metadata/service/FileMetadataService.java b/backend/src/main/java/io/metersphere/metadata/service/FileMetadataService.java index 05f0bd454f..8f3e94054b 100644 --- a/backend/src/main/java/io/metersphere/metadata/service/FileMetadataService.java +++ b/backend/src/main/java/io/metersphere/metadata/service/FileMetadataService.java @@ -8,6 +8,7 @@ import com.github.pagehelper.PageHelper; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.*; import io.metersphere.base.mapper.ext.ExtFileMetadataMapper; +import io.metersphere.base.mapper.ext.ExtLoadTestFileMapper; import io.metersphere.commons.constants.ApiTestConstants; import io.metersphere.commons.constants.FileAssociationType; import io.metersphere.commons.constants.FileModuleTypeConstants; @@ -30,6 +31,7 @@ import io.metersphere.metadata.vo.repository.GitFileAttachInfo; import io.metersphere.performance.request.QueryProjectFileRequest; import io.metersphere.service.UserService; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; @@ -70,6 +72,8 @@ public class FileMetadataService { private ApiScenarioMapper apiScenarioMapper; @Resource private TestCaseMapper testCaseMapper; + @Resource + private ExtLoadTestFileMapper extLoadTestFileMapper; public List create(FileMetadataCreateRequest fileMetadata, List files) { List result = new ArrayList<>(); @@ -655,6 +659,11 @@ public class FileMetadataService { this.add("TEST_CASE"); }}); List fileAssociationList = fileAssociationMapper.selectByExample(associationExample); + + LoadTestFileExample loadTestFileExample = new LoadTestFileExample(); + loadTestFileExample.createCriteria().andFileIdIn(new ArrayList<>(fileCommitIdMap.keySet())); + List loadTestFileList = loadTestFileMapper.selectByExample(loadTestFileExample); + for (FileAssociation fileAssociation : fileAssociationList) { String caseId = null; String caseName = null; @@ -689,6 +698,14 @@ public class FileMetadataService { list.add(dto); } } + for (LoadTestFile loadTestFile : loadTestFileList) { + LoadTest loadTest = loadTestMapper.selectByPrimaryKey(loadTestFile.getTestId()); + if (loadTest != null) { + FileRelevanceCaseDTO dto = new FileRelevanceCaseDTO(loadTestFile.getFileId(), loadTest.getId(), loadTest.getName(), "LOAD_CASE" + , fileCommitIdMap.get(loadTestFile.getFileId())); + list.add(dto); + } + } } } @@ -703,23 +720,29 @@ public class FileMetadataService { public String updateCaseVersion(String refId, QueryProjectFileRequest request) { String returnString = ""; - if (CollectionUtils.isNotEmpty(request.getIds())) { - FileMetadataExample example = new FileMetadataExample(); - example.createCriteria().andRefIdEqualTo(refId).andLatestEqualTo(true); - List fileMetadataList = fileMetadataMapper.selectByExample(example); - if (CollectionUtils.isNotEmpty(fileMetadataList)) { - String latestId = fileMetadataList.get(0).getId(); - + int updateCount = 0; + FileMetadataExample example = new FileMetadataExample(); + example.createCriteria().andRefIdEqualTo(refId).andLatestEqualTo(true); + List fileMetadataList = fileMetadataMapper.selectByExample(example); + if (CollectionUtils.isNotEmpty(fileMetadataList)) { + String latestId = fileMetadataList.get(0).getId(); + if (CollectionUtils.isNotEmpty(request.getIds())) { FileAssociationExample associationExample = new FileAssociationExample(); associationExample.createCriteria().andIdIn(request.getIds()); - FileAssociation fileAssociation = new FileAssociation(); fileAssociation.setFileMetadataId(latestId); - - int updateCount = fileAssociationMapper.updateByExampleSelective(fileAssociation, associationExample); - returnString = String.valueOf(updateCount); + updateCount = fileAssociationMapper.updateByExampleSelective(fileAssociation, associationExample); + } + if (MapUtils.isNotEmpty(request.getLoadCaseFileIdMap())) { + for (Map.Entry entry : request.getLoadCaseFileIdMap().entrySet()) { + String caseId = entry.getKey(); + String fileId = entry.getValue(); + extLoadTestFileMapper.updateFileIdByTestIdAndFileId(latestId, caseId, fileId); + } } } + + returnString = String.valueOf(updateCount); return returnString; } } diff --git a/backend/src/main/java/io/metersphere/performance/request/QueryProjectFileRequest.java b/backend/src/main/java/io/metersphere/performance/request/QueryProjectFileRequest.java index 9a7ba384f1..c3875ab169 100644 --- a/backend/src/main/java/io/metersphere/performance/request/QueryProjectFileRequest.java +++ b/backend/src/main/java/io/metersphere/performance/request/QueryProjectFileRequest.java @@ -4,10 +4,12 @@ import io.metersphere.controller.request.BaseQueryRequest; import lombok.Data; import java.util.List; +import java.util.Map; @Data public class QueryProjectFileRequest extends BaseQueryRequest { private String name; private String moduleId; + private Map loadCaseFileIdMap; private List types; } diff --git a/frontend/src/business/components/project/menu/file/list/FileCaseRelevanceList.vue b/frontend/src/business/components/project/menu/file/list/FileCaseRelevanceList.vue index f6dbe3d53a..e31116ee37 100644 --- a/frontend/src/business/components/project/menu/file/list/FileCaseRelevanceList.vue +++ b/frontend/src/business/components/project/menu/file/list/FileCaseRelevanceList.vue @@ -41,7 +41,9 @@ {{ $t('test_track.case.test_case') }} - + + {{ $t('commons.performance') }} + @@ -118,16 +120,35 @@ export default { }); }, updateFileVersion(row) { - this.condition.ids = [row.id]; + + if (row.caseType === 'LOAD_CASE') { + this.condition.loadCaseFileIdMap = {}; + this.$set(this.condition.loadCaseFileIdMap, row.caseId, row.id); + } else { + this.condition.ids = [row.id]; + } this.$post('/file/metadata/case/version/update/' + this.fileMetadataRefId, this.condition, res => { this.$success('Pull ' + this.$t('variables.end')); + this.condition.ids = []; + this.condition.loadCaseFileIdMap = {}; this.selectData(); }); + }, batchUpdateFileVersion() { - let selectIds = this.$refs.table.selectIds; - this.condition.ids = selectIds; + let selectRows = this.$refs.table.selectRows; + this.condition.ids = []; + this.condition.loadCaseFileIdMap = {}; + this.$refs.table.selectRows.forEach(row => { + if (row.caseType === 'LOAD_CASE') { + this.$set(this.condition.loadCaseFileIdMap, row.caseId, row.id); + } else { + this.condition.ids.push(row.id); + } + }); this.$post('/file/metadata/case/version/update/' + this.fileMetadataRefId, this.condition, res => { + this.condition.ids = []; + this.condition.loadCaseFileIdMap = {}; this.$success('Pull ' + this.$t('variables.end')); this.selectData(); });