增加日志

This commit is contained in:
zhouxin5253@163.com 2021-01-17 09:53:37 +08:00
parent 5af1fc9b1a
commit 6e0ac3ed78
2 changed files with 14 additions and 9 deletions

View File

@ -14,11 +14,11 @@ import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.annotation.PostConstruct;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
@Service
public class TeambitionClientService {
@ -36,7 +36,7 @@ public class TeambitionClientService {
TeambitionFileSystemStore.setBean(this);
}
public List<TFile> getTFiles(String nodeId) {
public Set<TFile> getTFiles(String nodeId) {
NodeQuery nodeQuery = new NodeQuery();
nodeQuery.setOrgId(client.getOrgId());
nodeQuery.setOffset(0);
@ -50,8 +50,15 @@ public class TeambitionClientService {
ListResult<TFile> tFileListResult = JsonUtil.readValue(json, new TypeReference<ListResult<TFile>>() {
});
List<TFile> tFileList = tFileListResult.getData();
tFileList.sort(Comparator.comparing(TFile::getUpdated).reversed());
Set<TFile> tFileSets = new LinkedHashSet<>();
for (TFile tFile : tFileList) {
if (!tFileSets.add(tFile)) {
LOGGER.info("当前目录下{} 存在同名文件:{},文件大小:{}", nodeId, tFile.getName(), tFile.getSize());
}
}
// 对文件名进行去重只保留最新的一个
return tFileList.stream().sorted(Comparator.comparing(TFile::getUpdated).reversed()).distinct().collect(Collectors.toList());
return tFileSets;
}
@ -128,6 +135,7 @@ public class TeambitionClientService {
TFile oldFile = getNodeIdByPath2(path);
// 如果旧文件存在则先删除
if (oldFile != null) {
LOGGER.info("旧文件{}还存在,大小为{},进行删除操作,可前往网页版的回收站查看", path, oldFile.getSize());
remove(path);
}
RenameRequest renameRequest = new RenameRequest();
@ -264,7 +272,7 @@ public class TeambitionClientService {
}
private TFile getNodeIdByParentId(String parentId, String name) {
List<TFile> tFiles = getTFiles(parentId);
Set<TFile> tFiles = getTFiles(parentId);
for (TFile tFile : tFiles) {
if (tFile.getName().equals(name)) {
return tFile;

View File

@ -7,8 +7,6 @@ import net.sf.webdav.IWebdavStore;
import net.sf.webdav.StoredObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
@ -16,8 +14,7 @@ import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.InputStream;
import java.security.Principal;
import java.util.Date;
import java.util.List;
import java.util.Set;
public class TeambitionFileSystemStore implements IWebdavStore {
private static final Logger LOGGER = LoggerFactory.getLogger(TeambitionFileSystemStore.class);
@ -99,7 +96,7 @@ public class TeambitionFileSystemStore implements IWebdavStore {
public String[] getChildrenNames(ITransaction transaction, String folderUri) {
LOGGER.debug("getChildrenNames: {}", folderUri);
TFile tFile = teambitionClientService.getTFileByPath(folderUri);
List<TFile> tFileList = teambitionClientService.getTFiles(tFile.getNodeId());
Set<TFile> tFileList = teambitionClientService.getTFiles(tFile.getNodeId());
return tFileList.stream().map(TFile::getName).toArray(String[]::new);
}