fix(项目设置): 文件库管理页面增加对性能测试的支持

--bug=1016894 --user=宋天阳 【项目设置】性能用例关联第三方仓库文件,关联用例列表不显示该用例
https://www.tapd.cn/55049933/s/1245702
This commit is contained in:
song-tianyang 2022-09-19 17:54:40 +08:00 committed by 建国
parent f4889b7636
commit c06192f060
5 changed files with 76 additions and 15 deletions

View File

@ -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);
}

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="io.metersphere.base.mapper.ext.ExtLoadTestFileMapper">
<update id="updateFileIdByTestIdAndFileId">
update load_test_file SET file_id = #{fileId}
WHERE test_id = #{testId} AND file_id = #{oldFileId}
</update>
</mapper>

View File

@ -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<FileMetadata> create(FileMetadataCreateRequest fileMetadata, List<MultipartFile> files) {
List<FileMetadata> result = new ArrayList<>();
@ -655,6 +659,11 @@ public class FileMetadataService {
this.add("TEST_CASE");
}});
List<FileAssociation> fileAssociationList = fileAssociationMapper.selectByExample(associationExample);
LoadTestFileExample loadTestFileExample = new LoadTestFileExample();
loadTestFileExample.createCriteria().andFileIdIn(new ArrayList<>(fileCommitIdMap.keySet()));
List<LoadTestFile> 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<FileMetadata> 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<FileMetadata> 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<String, String> entry : request.getLoadCaseFileIdMap().entrySet()) {
String caseId = entry.getKey();
String fileId = entry.getValue();
extLoadTestFileMapper.updateFileIdByTestIdAndFileId(latestId, caseId, fileId);
}
}
}
returnString = String.valueOf(updateCount);
return returnString;
}
}

View File

@ -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<String, String> loadCaseFileIdMap;
private List<String> types;
}

View File

@ -41,7 +41,9 @@
<span v-else-if="scope.row.caseType === 'TEST_CASE'">
{{ $t('test_track.case.test_case') }}
</span>
<span v-else-if="scope.row.caseType === 'LOAD_CASE'">
{{ $t('commons.performance') }}
</span>
</template>
</ms-table-column>
@ -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();
});