You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

174 lines
6.9 KiB

package com.fr.plugin;
import EDoc2.IAppService.IDocAppService;
import EDoc2.IAppService.IOrgAppService;
import EDoc2.IAppService.Model.FileListAndFolderListDto;
import EDoc2.IAppService.Model.ReturnValueResult;
import EDoc2.IAppService.Model.UserLoginIntegrationByUserLoginNameDto;
import com.alibaba.fastjson.JSONObject;
import com.edoc2.model.ResultBean;
import com.edoc2.model.upload.UploadFileInfo;
import com.edoc2.model.upload.UploadFileResult;
import com.edoc2.model.upload.uploadenum.CalcMD5;
import com.edoc2.model.upload.uploadenum.UpgradeStrategy;
import com.edoc2.proxy.FacadeProxy;
import com.edoc2.sdkconfig.SdkBaseInfo;
import com.edoc2.utils.FileUtils;
import com.edoc2.utils.HttpUtils;
import com.edoc2.utils.UploaderUtils;
import com.fr.stable.StringUtils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* @author xx
* @version 10.0
* @date 2021/6/28
*/
public class EDOTest {
private static int DEMO_FOLDER_ID = 35679;
private static String DEMO_USERNAME = "xx";
private static String DEMO_KEY = "xxx";
public static void main(String[] args) {
SdkBaseInfo.baseUrl = "http://xxx:33333";
IOrgAppService iOrgAppService = FacadeProxy.newProxyInstance(IOrgAppService.class);
UserLoginIntegrationByUserLoginNameDto params = new UserLoginIntegrationByUserLoginNameDto();
params.setLoginName(DEMO_USERNAME);
params.setIntegrationKey(DEMO_KEY);
params.setIPAddress("192.168.2.23");
ReturnValueResult<String> result = iOrgAppService.UserLoginIntegrationByUserLoginName(params);
String token = result.getData();
System.out.println("token:" + token);
// ResultBean resultBean = uploadFile(token, "D:\\test.xlsx");
// System.out.println(resultBean);
// fileDownload(380050 ,390380 , token);
// ReturnValueResult returnValueResult = removeFile(token, 379642);
//System.out.println(returnValueResult);
String[] fileIds = {"380050", "380066"};
String[] folderIds = {};
createBatchDownloadUrl(fileIds, folderIds, token);
}
public static ResultBean uploadFile(String token, String filePath) {
File file = null;
FileInputStream fileInputStream = null;
try {
file = new File(filePath);
fileInputStream = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
return new ResultBean();
}
//文件类型
String mimeType = null;
try {
mimeType = FileUtils.getMimeType(file.getPath());
} catch (IOException e) {
e.printStackTrace();
return new ResultBean();
}
UploadFileInfo uploadFileInfo = new UploadFileInfo();
uploadFileInfo.setName(file.getName());
uploadFileInfo.setType(mimeType);
// 获取文件最后一次更新时间
Date lastModifiedDate = FileUtils.getFileLastModifiedDate(file);
uploadFileInfo.setLastModifiedDate(lastModifiedDate);
//uploadFileInfo.setFileId(44);// 更新的时候需要传文件id ,策略需要设置 MajorUpgrade OverlayLatestVersion
/* UploadFileResult uploadFileResult = UploaderUtils.uploadFileByInputStraemAsync(token, DEMO_FOLDER_ID, UpgradeStrategy.MinorUpgrade,
CalcMD5.Before.getValue(), "test.xlsx", fileInputStream, uploadFileInfo);*/
ResultBean resultBean = null;
try {
resultBean = UploaderUtils.uploadFileByStream(token, DEMO_FOLDER_ID, UpgradeStrategy.MinorUpgrade,
CalcMD5.Before.getValue(), "", fileInputStream, uploadFileInfo);
} catch (IOException e) {
e.printStackTrace();
return new ResultBean();
}
return resultBean;
}
public static String createBatchDownloadUrl(String[] fileList, String[] folderList, String token) {
StringBuilder stringBuilder = new StringBuilder(SdkBaseInfo.baseUrl);
stringBuilder.append("/DownLoad/DownLoadCheck?fileIds=").append(StringUtils.join(",", fileList));
stringBuilder.append("&folderIds=").append(StringUtils.join(",", folderList));
stringBuilder.append("&token=");
stringBuilder.append(token);
//1.2请求
String result = null;
try {
result = HttpUtils.doGet(stringBuilder.toString(), null, null);
} catch (Exception e) {
e.printStackTrace();
}
//1.3获取region hash
JSONObject json = JSONObject.parseObject(result);
String regionHash = (String) json.get("RegionHash");
System.out.println(json);
//2.拼装下载URL
StringBuilder url = new StringBuilder(SdkBaseInfo.baseUrl);
url.append("/downLoad/index?regionHash=");
url.append(regionHash);
url.append("&async=true");
url.append("&token=");
url.append(token);
System.out.println(url);
return url.toString();
}
public static void fileDownload(int fileId, int verId, String token) {
//1.1组装下载请求URL
StringBuilder stringBuilder = new StringBuilder(SdkBaseInfo.baseUrl);
stringBuilder.append("/DownLoad/DownLoadCheck?fileIds=");
stringBuilder.append(fileId);
stringBuilder.append("&ver_id=");
stringBuilder.append(verId);
stringBuilder.append("&token=");
stringBuilder.append(token);
//1.2请求
String result = null;
try {
result = HttpUtils.doGet(stringBuilder.toString(), null, null);
} catch (Exception e) {
e.printStackTrace();
}
//1.3获取region hash
JSONObject json = JSONObject.parseObject(result);
String regionHash = (String) json.get("RegionHash");
System.out.println(json);
//2.拼装下载URL
StringBuilder url = new StringBuilder(SdkBaseInfo.baseUrl);
url.append("/downLoad/index?regionHash=");
url.append(regionHash);
url.append("&async=true");
url.append("&token=");
url.append(token);
System.out.println(url);
}
public static ReturnValueResult removeFile(String token, int fileId) {
IDocAppService service = FacadeProxy.newProxyInstance(IDocAppService.class);
FileListAndFolderListDto fileListAndFolderListDto = new FileListAndFolderListDto();
ArrayList<Integer> fileList = new ArrayList<Integer>();
fileList.add(fileId);
fileListAndFolderListDto.setFileIdList(fileList);
fileListAndFolderListDto.setFilePathList(new ArrayList<String>());
fileListAndFolderListDto.setFolderIdList(new ArrayList<Integer>());
fileListAndFolderListDto.setFolderPathList(new ArrayList<String>());
fileListAndFolderListDto.setToken(token);
return service.RemoveFolderListAndFileList(fileListAndFolderListDto);
}
}