test:测试调用在线编辑文件获取
This commit is contained in:
+9
-2
@@ -113,7 +113,7 @@ public class SarBussionessStandServiceImpl extends ServiceImpl<SarBussionessStan
|
|||||||
private String filePath;//文件存储路径
|
private String filePath;//文件存储路径
|
||||||
|
|
||||||
@Value("${onlyoffice.url}")
|
@Value("${onlyoffice.url}")
|
||||||
private String onlyofficeUrl;//文件存储路径
|
private String onlyofficeUrl;//onlyoffice文件转换服务URL
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SarBussionessStandDao sarBussionessStandEODao;
|
private SarBussionessStandDao sarBussionessStandEODao;
|
||||||
@@ -4937,14 +4937,21 @@ public class SarBussionessStandServiceImpl extends ServiceImpl<SarBussionessStan
|
|||||||
try {
|
try {
|
||||||
logger.info("======================================远程调用转换开始启动=================================");
|
logger.info("======================================远程调用转换开始启动=================================");
|
||||||
logger.info("=================================="+ onlineFileLogs.get(0).toString());
|
logger.info("=================================="+ onlineFileLogs.get(0).toString());
|
||||||
File file = OnlyofficePdfUtil.downloadFile(filePath+"/",onlineFileLogs.get(0).getOLdFileName(), onlineFileLogs.get(0).getFilekey(), onlineFileLogs.get(0).getFilePath());
|
File file = OnlyofficePdfUtil.downloadFile(onlyofficeUrl,filePath,onlineFileLogs.get(0).getOLdFileName(), onlineFileLogs.get(0).getFilekey(), onlineFileLogs.get(0).getFilePath());
|
||||||
logger.info("======================================远程调用转换开始结束=================================");
|
logger.info("======================================远程调用转换开始结束=================================");
|
||||||
// File file = new File(filePath+"/onlineFile/"+onlineFileLogs.get(0).getOLdFileName());
|
// File file = new File(filePath+"/onlineFile/"+onlineFileLogs.get(0).getOLdFileName());
|
||||||
logger.info("======================================file文件路径================================="+filePath+"/onlineFile/"+onlineFileLogs.get(0).getOLdFileName());
|
logger.info("======================================file文件路径================================="+filePath+"/onlineFile/"+onlineFileLogs.get(0).getOLdFileName());
|
||||||
if(file != null && file.exists()){
|
if(file != null && file.exists()){
|
||||||
|
logger.info("==============================文件所在位置:{}",file.getAbsolutePath());
|
||||||
logger.info("======================================file文件保存================================="+filePath+"/onlineFile/"+onlineFileLogs.get(0).getOLdFileName());
|
logger.info("======================================file文件保存================================="+filePath+"/onlineFile/"+onlineFileLogs.get(0).getOLdFileName());
|
||||||
AttFileVo attFileVo = attFileEOService.saveFileInfo(file);
|
AttFileVo attFileVo = attFileEOService.saveFileInfo(file);
|
||||||
|
if (file.delete()) {
|
||||||
|
logger.info("==================删除临时文件成功================");
|
||||||
|
}else{
|
||||||
|
logger.info("====================删除临时文件失败=================");
|
||||||
|
}
|
||||||
if(attFileVo!=null){
|
if(attFileVo!=null){
|
||||||
|
logger.info("============================文件ID:{},文件存储位置:{}",attFileVo.getId(),attFileVo.getFilePath());
|
||||||
SarBussStandFile sarBussStandFile = new SarBussStandFile();
|
SarBussStandFile sarBussStandFile = new SarBussStandFile();
|
||||||
//sarBussStandFile.setId();
|
//sarBussStandFile.setId();
|
||||||
String uuId = com.adc.da.util.utils.UUID.randomUUID(20);
|
String uuId = com.adc.da.util.utils.UUID.randomUUID(20);
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package com.adc.da.utils.util;
|
package com.adc.da.utils.util;
|
||||||
|
|
||||||
|
|
||||||
import com.adc.da.http.ResponseMessage;
|
|
||||||
import com.adc.da.http.Result;
|
|
||||||
import com.adc.da.slrs.sarBussionessStand.service.impl.SarBussionessStandServiceImpl;
|
import com.adc.da.slrs.sarBussionessStand.service.impl.SarBussionessStandServiceImpl;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
@@ -22,26 +20,20 @@ import org.dom4j.DocumentHelper;
|
|||||||
import org.dom4j.Element;
|
import org.dom4j.Element;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class OnlyofficePdfUtil {
|
public class OnlyofficePdfUtil {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(SarBussionessStandServiceImpl.class);
|
private static final Logger logger = LoggerFactory.getLogger(SarBussionessStandServiceImpl.class);
|
||||||
|
|
||||||
@Value("${onlyoffice.url}")
|
public static File downloadFile(String onlyOfficeUrl,String filePathInfo,String filePdfName, String key, String onlineFilePath) throws Exception {
|
||||||
private static String onlyOfficeUrl; //onlyoffice文件转换服务URL
|
String filePath = filePathInfo+"/onlineFile/"+filePdfName+".pdf";
|
||||||
|
|
||||||
|
|
||||||
public static File downloadFile(String filePathInfo,String filePdfName, String key, String onlineFilePath) throws Exception {
|
|
||||||
String filePath = filePathInfo+"/onlineFile/"+filePdfName;
|
|
||||||
logger.info("================================="+filePath);
|
logger.info("================================="+filePath);
|
||||||
logger.info("====================filePdfName:{},key:{},onlineFilePath:{}",filePdfName,key,onlineFilePath);
|
logger.info("====================转换的请求参数:onlyOfficeUrl:{},filePdfName:{},key:{},onlineFilePath:{}",onlyOfficeUrl,filePdfName,key,onlineFilePath);
|
||||||
String fileUrl = convertFile(filePdfName,key,onlineFilePath);
|
String fileUrl = convertFile(onlyOfficeUrl,filePdfName,key,onlineFilePath);
|
||||||
logger.info("================================="+fileUrl);
|
logger.info("================================="+fileUrl);
|
||||||
// 创建HttpClientBuilder
|
// 创建HttpClientBuilder
|
||||||
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
|
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
|
||||||
@@ -77,6 +69,7 @@ public class OnlyofficePdfUtil {
|
|||||||
// File file = new File(Objects.requireNonNull(this.getClass().getClassLoader().getResource("")).getPath()+ filePdfName);
|
// File file = new File(Objects.requireNonNull(this.getClass().getClassLoader().getResource("")).getPath()+ filePdfName);
|
||||||
File file = new File(filePath);
|
File file = new File(filePath);
|
||||||
FileUtils.copyInputStreamToFile(content,file);
|
FileUtils.copyInputStreamToFile(content,file);
|
||||||
|
content.close();
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -98,7 +91,6 @@ public class OnlyofficePdfUtil {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// return Result.success();
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +102,7 @@ public class OnlyofficePdfUtil {
|
|||||||
return newFileUrl;
|
return newFileUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String convertFile(String titleName,String key, String onlineFilePath) throws Exception{
|
public static String convertFile(String onlyOfficeUrl,String titleName,String key, String onlineFilePath) throws Exception{
|
||||||
//String url = "http://47.92.92.38:8103/7.2.1-34/ConvertService.ashx";
|
//String url = "http://47.92.92.38:8103/7.2.1-34/ConvertService.ashx";
|
||||||
// String url = "http://10.100.5.116:8088/7.2.1-34/ConvertService.ashx";
|
// String url = "http://10.100.5.116:8088/7.2.1-34/ConvertService.ashx";
|
||||||
Map<String,Object> map = new HashMap<>();
|
Map<String,Object> map = new HashMap<>();
|
||||||
@@ -123,8 +115,8 @@ public class OnlyofficePdfUtil {
|
|||||||
map.put("url","https://srms.foton.com.cn/file/"+onlineFilePath);
|
map.put("url","https://srms.foton.com.cn/file/"+onlineFilePath);
|
||||||
logger.info("=======================================https://srms.foton.com.cn/file/"+onlineFilePath);
|
logger.info("=======================================https://srms.foton.com.cn/file/"+onlineFilePath);
|
||||||
//map.put("url","https://srms.foton.com.cn/file/model/task_768330d8/task_768330d8_top_768330d8_node.docx");
|
//map.put("url","https://srms.foton.com.cn/file/model/task_768330d8/task_768330d8_top_768330d8_node.docx");
|
||||||
logger.info("=========================map:{}",map);
|
|
||||||
JSONObject requestJson = new JSONObject(map);
|
JSONObject requestJson = new JSONObject(map);
|
||||||
|
logger.info("=========================post参数:{}",requestJson);
|
||||||
// 创建HttpClientBuilder
|
// 创建HttpClientBuilder
|
||||||
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
|
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
|
||||||
// HttpClient
|
// HttpClient
|
||||||
@@ -138,10 +130,12 @@ public class OnlyofficePdfUtil {
|
|||||||
.setConnectTimeout(60000)
|
.setConnectTimeout(60000)
|
||||||
.build();
|
.build();
|
||||||
httpPost.setConfig(requestConfig);
|
httpPost.setConfig(requestConfig);
|
||||||
|
// httpPost.addHeader("Content-Type","application/json");
|
||||||
CloseableHttpResponse response = null;
|
CloseableHttpResponse response = null;
|
||||||
try {
|
try {
|
||||||
//设置post请求方式为JSON
|
//设置post请求方式为JSON
|
||||||
StringEntity data = new StringEntity(String.valueOf(requestJson), "UTF-8");
|
StringEntity data = new StringEntity(String.valueOf(requestJson), "UTF-8");
|
||||||
|
logger.info("=========================post参数:{}",data);
|
||||||
data.setContentType("application/json; charset=UTF-8");
|
data.setContentType("application/json; charset=UTF-8");
|
||||||
httpPost.setEntity(data);
|
httpPost.setEntity(data);
|
||||||
//发送post请求
|
//发送post请求
|
||||||
@@ -157,6 +151,7 @@ public class OnlyofficePdfUtil {
|
|||||||
HttpEntity entityRes = response.getEntity();
|
HttpEntity entityRes = response.getEntity();
|
||||||
if (entityRes != null) {
|
if (entityRes != null) {
|
||||||
String responsetData = EntityUtils.toString(entityRes, "UTF-8");
|
String responsetData = EntityUtils.toString(entityRes, "UTF-8");
|
||||||
|
logger.info("=================================响应结果数据:{}",responsetData);
|
||||||
String fileUrl = analysisXML(responsetData);
|
String fileUrl = analysisXML(responsetData);
|
||||||
logger.info("===========================================返回的文件路径"+fileUrl+"===============================");
|
logger.info("===========================================返回的文件路径"+fileUrl+"===============================");
|
||||||
return fileUrl;
|
return fileUrl;
|
||||||
|
|||||||
Reference in New Issue
Block a user