From 2ad4ca9d0d4537a2bcdff2f54b7be5762e6d0d81 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Sun, 4 Feb 2024 18:55:24 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E9=A1=B9=E7=9B=AE=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AD=98=E5=82=A8=E5=BA=93=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=97=B6=E6=B2=A1=E6=9C=89=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=88=B0=E6=9C=80=E6=96=B0commit=E7=9A=84=E7=BC=BA=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1035308 --user=宋天阳 【用例管理】-用例关联文件,文件详情页关联用例列表中,用例关联的文件版本显示错误 https://www.tapd.cn/55049933/s/1460285 --- .../io/metersphere/sdk/util/GitRepositoryUtil.java | 5 ++--- .../project/service/FileMetadataService.java | 10 +++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/GitRepositoryUtil.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/GitRepositoryUtil.java index c4fa492d4d..0fd85801fe 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/GitRepositoryUtil.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/GitRepositoryUtil.java @@ -140,11 +140,10 @@ public class GitRepositoryUtil { private String getFileLastCommitId(ObjectId objectId, String filePath) throws Exception { Iterable logs = git.log().add(objectId).addPath(filePath).call(); - String returnStr = StringUtils.EMPTY; for (RevCommit rev : logs) { - returnStr = rev.getName(); + return rev.getName(); } - return returnStr; + return null; } private RevCommit getRevTreeByRepositoryAndCommitId(InMemoryRepository repo, ObjectId fileCommitId) throws Exception { diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java index 9e66be027f..bbaa744301 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java @@ -532,13 +532,16 @@ public class FileMetadataService { private void setFileVersionIsOld(FileMetadata oldFile, String operator) { //删除旧的预览文件 TempFileUtils.deleteTmpFile(oldFile.getId()); - //更新文件版本分支 + //通过refId批量更新 + FileMetadataExample example = new FileMetadataExample(); + example.createCriteria().andRefIdEqualTo(oldFile.getRefId()).andLatestEqualTo(true); + FileMetadata updateModel = new FileMetadata(); - updateModel.setId(oldFile.getId()); updateModel.setLatest(false); updateModel.setUpdateTime(System.currentTimeMillis()); updateModel.setUpdateUser(operator); - fileMetadataMapper.updateByPrimaryKeySelective(updateModel); + + fileMetadataMapper.updateByExampleSelective(updateModel, example); } private void genNewFileVersionByOldFile(FileMetadata oldFile, FileMetadata fileMetadata, String operator) { @@ -620,6 +623,7 @@ public class FileMetadataService { //获取fileMetadata以及可能存在的fileMetadataRepository FileMetadataExample example = new FileMetadataExample(); example.createCriteria().andRefIdEqualTo(fileMetadata.getRefId()); + example.setOrderByClause(" create_time DESC "); List fileMetadataList = fileMetadataMapper.selectByExample(example); List fileIdList = fileMetadataList.stream().map(FileMetadata::getId).toList(); FileMetadataRepositoryExample repositoryExample = new FileMetadataRepositoryExample();