fix: 重复 file 路径 Bug

This commit is contained in:
gaibu 2023-01-02 12:27:52 +08:00
parent 639c7820f9
commit 906a3a2c50

View File

@ -8,6 +8,7 @@ import org.springframework.stereotype.Repository;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
import java.util.Optional;
@Repository @Repository
public class FileContentDAOImpl implements DBFileContentFrameworkDAO { public class FileContentDAOImpl implements DBFileContentFrameworkDAO {
@ -29,9 +30,11 @@ public class FileContentDAOImpl implements DBFileContentFrameworkDAO {
@Override @Override
public byte[] selectContent(Long configId, String path) { public byte[] selectContent(Long configId, String path) {
List<FileContentDO> fileContentDOs = fileContentMapper.selectList( List<FileContentDO> list = fileContentMapper.selectList(
buildQuery(configId, path).select(FileContentDO::getContent).orderByDesc(FileContentDO::getId)); buildQuery(configId, path).select(FileContentDO::getContent).orderByDesc(FileContentDO::getId));
return CollUtil.isNotEmpty(fileContentDOs) ? CollUtil.getFirst(fileContentDOs).getContent() : null; return Optional.ofNullable(CollUtil.getFirst(list))
.map(FileContentDO::getContent)
.orElse(null);
} }
private LambdaQueryWrapper<FileContentDO> buildQuery(Long configId, String path) { private LambdaQueryWrapper<FileContentDO> buildQuery(Long configId, String path) {