合并分支 'fix_foton_20230613' 到 'master'
Fix foton 20230613 查看合并请求 laws-foton-slrs/foton-slrs-system-rest!113
This commit is contained in:
@@ -72,4 +72,8 @@ OCR.ocrPath=/data/slrs/ocrResultFile/
|
|||||||
# OCR文件请求下载或在线预览时URL
|
# OCR文件请求下载或在线预览时URL
|
||||||
OCR.ocrDownPath=/data/slrs/ocrResultFile/
|
OCR.ocrDownPath=/data/slrs/ocrResultFile/
|
||||||
OCR.times=20
|
OCR.times=20
|
||||||
OCR.convertType=BOTH
|
OCR.convertType=BOTH
|
||||||
|
|
||||||
|
# 在线编辑的调用
|
||||||
|
onlyoffice.url=http://47.92.92.38:8103/7.2.1-34/ConvertService.ashx
|
||||||
|
#onlyoffice.url=http://10.100.5.116:8088/7.2.1-34/ConvertService.ashx
|
||||||
+11
-2
@@ -112,6 +112,9 @@ public class SarBussionessStandServiceImpl extends ServiceImpl<SarBussionessStan
|
|||||||
@Value("${file.path}")
|
@Value("${file.path}")
|
||||||
private String filePath;//文件存储路径
|
private String filePath;//文件存储路径
|
||||||
|
|
||||||
|
@Value("${onlyoffice.url}")
|
||||||
|
private String onlyofficeUrl;//文件存储路径
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private SarBussionessStandDao sarBussionessStandEODao;
|
private SarBussionessStandDao sarBussionessStandEODao;
|
||||||
|
|
||||||
@@ -4932,9 +4935,13 @@ public class SarBussionessStandServiceImpl extends ServiceImpl<SarBussionessStan
|
|||||||
if(!onlineFileLogs.isEmpty()){
|
if(!onlineFileLogs.isEmpty()){
|
||||||
if(StringUtils.isNotBlank(onlineFileLogs.get(0).getOLdFileName()) && StringUtils.isNotBlank(onlineFileLogs.get(0).getFilekey()) && StringUtils.isNotBlank(onlineFileLogs.get(0).getFilePath())){
|
if(StringUtils.isNotBlank(onlineFileLogs.get(0).getOLdFileName()) && StringUtils.isNotBlank(onlineFileLogs.get(0).getFilekey()) && StringUtils.isNotBlank(onlineFileLogs.get(0).getFilePath())){
|
||||||
try {
|
try {
|
||||||
OnlyofficePdfUtil.downloadFile(filePath,onlineFileLogs.get(0).getOLdFileName(), onlineFileLogs.get(0).getFilekey(), onlineFileLogs.get(0).getFilePath());
|
logger.info("======================================远程调用转换开始启动=================================");
|
||||||
File file = new File(filePath+"/onlineFile/"+onlineFileLogs.get(0).getOLdFileName());
|
OnlyofficePdfUtil.downloadFile(onlyofficeUrl,filePath+"/",onlineFileLogs.get(0).getOLdFileName(), onlineFileLogs.get(0).getFilekey(), onlineFileLogs.get(0).getFilePath());
|
||||||
|
logger.info("======================================远程调用转换开始结束=================================");
|
||||||
|
File file = new File(filePath+"/onlineFile/"+onlineFileLogs.get(0).getOLdFileName()+onlineFileLogs.get(0).getOLdFileName()+".pdf");
|
||||||
|
logger.info("======================================file文件路径================================="+filePath+"/onlineFile/"+onlineFileLogs.get(0).getOLdFileName());
|
||||||
if(file.exists()){
|
if(file.exists()){
|
||||||
|
logger.info("======================================file文件保存================================="+filePath+"/onlineFile/"+onlineFileLogs.get(0).getOLdFileName());
|
||||||
AttFileVo attFileVo = attFileEOService.saveFileInfo(file);
|
AttFileVo attFileVo = attFileEOService.saveFileInfo(file);
|
||||||
if(attFileVo!=null){
|
if(attFileVo!=null){
|
||||||
SarBussStandFile sarBussStandFile = new SarBussStandFile();
|
SarBussStandFile sarBussStandFile = new SarBussStandFile();
|
||||||
@@ -4956,6 +4963,8 @@ public class SarBussionessStandServiceImpl extends ServiceImpl<SarBussionessStan
|
|||||||
}else {
|
}else {
|
||||||
logger.info("======================================word.doc转换失败=================================");
|
logger.info("======================================word.doc转换失败=================================");
|
||||||
}
|
}
|
||||||
|
}else {
|
||||||
|
logger.info("======================================pdf文件不存在!!!!=================================");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.adc.da.utils.util;
|
|||||||
|
|
||||||
import com.adc.da.http.ResponseMessage;
|
import com.adc.da.http.ResponseMessage;
|
||||||
import com.adc.da.http.Result;
|
import com.adc.da.http.Result;
|
||||||
|
import com.adc.da.slrs.sarBussionessStand.service.impl.SarBussionessStandServiceImpl;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.HttpStatus;
|
import org.apache.http.HttpStatus;
|
||||||
@@ -18,7 +19,8 @@ import org.dom4j.Document;
|
|||||||
import org.dom4j.DocumentException;
|
import org.dom4j.DocumentException;
|
||||||
import org.dom4j.DocumentHelper;
|
import org.dom4j.DocumentHelper;
|
||||||
import org.dom4j.Element;
|
import org.dom4j.Element;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -26,250 +28,138 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class OnlyofficePdfUtil {
|
public class OnlyofficePdfUtil {
|
||||||
|
|
||||||
public static ResponseMessage downloadFile(String filePathInfo,String filePdfName, String key, String onlineFilePath) throws Exception {
|
private static final Logger logger = LoggerFactory.getLogger(SarBussionessStandServiceImpl.class);
|
||||||
|
|
||||||
|
|
||||||
|
public static ResponseMessage downloadFile(String url,String filePathInfo,String filePdfName, String key, String onlineFilePath) throws Exception {
|
||||||
String filePath = filePathInfo+"/onlineFile/"+filePdfName;
|
String filePath = filePathInfo+"/onlineFile/"+filePdfName;
|
||||||
|
logger.info("================================="+filePath);
|
||||||
System.out.println("================"+filePath);
|
String fileUrl = convertFile(url,filePdfName,key,onlineFilePath);
|
||||||
|
logger.info("================================="+fileUrl);
|
||||||
String fileUrl = convertFile(key,onlineFilePath);
|
|
||||||
|
|
||||||
System.out.println("=============================="+fileUrl);
|
|
||||||
|
|
||||||
// 创建HttpClientBuilder
|
// 创建HttpClientBuilder
|
||||||
|
|
||||||
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
|
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
|
||||||
|
|
||||||
// HttpClient
|
// HttpClient
|
||||||
|
|
||||||
CloseableHttpClient closeableHttpClient = httpClientBuilder.build();
|
CloseableHttpClient closeableHttpClient = httpClientBuilder.build();
|
||||||
|
|
||||||
HttpGet get = new HttpGet(fileUrl);
|
HttpGet get = new HttpGet(fileUrl);
|
||||||
|
|
||||||
// 设置请求和传输超时时间
|
// 设置请求和传输超时时间
|
||||||
|
|
||||||
RequestConfig requestConfig = RequestConfig.custom()
|
RequestConfig requestConfig = RequestConfig.custom()
|
||||||
|
|
||||||
.setSocketTimeout(60000)
|
.setSocketTimeout(60000)
|
||||||
|
|
||||||
.setConnectionRequestTimeout(60000)
|
.setConnectionRequestTimeout(60000)
|
||||||
|
|
||||||
.setConnectTimeout(60000)
|
.setConnectTimeout(60000)
|
||||||
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
get.setConfig(requestConfig);
|
get.setConfig(requestConfig);
|
||||||
|
|
||||||
CloseableHttpResponse response = null;
|
CloseableHttpResponse response = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
//发送get请求
|
//发送get请求
|
||||||
|
|
||||||
response = closeableHttpClient.execute(get);
|
response = closeableHttpClient.execute(get);
|
||||||
|
|
||||||
if (response == null || response.getStatusLine() == null) {
|
if (response == null || response.getStatusLine() == null) {
|
||||||
|
|
||||||
throw new Exception("发送GET请求失败,返回结果为空!");
|
throw new Exception("发送GET请求失败,返回结果为空!");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//返回状态是否200
|
//返回状态是否200
|
||||||
|
|
||||||
int statusCode = response.getStatusLine().getStatusCode();
|
int statusCode = response.getStatusLine().getStatusCode();
|
||||||
|
|
||||||
if (statusCode == HttpStatus.SC_OK) {
|
if (statusCode == HttpStatus.SC_OK) {
|
||||||
|
|
||||||
//得到请求结果
|
//得到请求结果
|
||||||
|
|
||||||
HttpEntity entityRes = response.getEntity();
|
HttpEntity entityRes = response.getEntity();
|
||||||
|
|
||||||
if (entityRes != null) {
|
if (entityRes != null) {
|
||||||
|
|
||||||
InputStream content = entityRes.getContent();
|
InputStream content = entityRes.getContent();
|
||||||
|
|
||||||
byte[] getData = readInputStream(content);
|
byte[] getData = readInputStream(content);
|
||||||
|
|
||||||
File file = new File(filePath);
|
File file = new File(filePath);
|
||||||
|
|
||||||
FileOutputStream fos = new FileOutputStream(file);
|
FileOutputStream fos = new FileOutputStream(file);
|
||||||
|
|
||||||
fos.write(getData);
|
fos.write(getData);
|
||||||
|
|
||||||
fos.close();
|
fos.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
throw new Exception("发送GET请求出错:" + response);
|
throw new Exception("发送GET请求出错:" + response);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
throw new Exception("发送GET请求出现异常," + e.getMessage());
|
throw new Exception("发送GET请求出现异常," + e.getMessage());
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// 关闭连接释放资源
|
// 关闭连接释放资源
|
||||||
|
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
|
|
||||||
response.close();
|
response.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (closeableHttpClient != null) {
|
if (closeableHttpClient != null) {
|
||||||
|
|
||||||
closeableHttpClient.close();
|
closeableHttpClient.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Result.success();
|
return Result.success();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String analysisXML(String xmlString) throws DocumentException {
|
public static String analysisXML(String xmlString) throws DocumentException {
|
||||||
|
|
||||||
Document document = DocumentHelper.parseText(xmlString);
|
Document document = DocumentHelper.parseText(xmlString);
|
||||||
|
|
||||||
Element rootElement = document.getRootElement();
|
Element rootElement = document.getRootElement();
|
||||||
|
|
||||||
String fileUrl = rootElement.elementText("FileUrl");
|
String fileUrl = rootElement.elementText("FileUrl");
|
||||||
|
|
||||||
String newFileUrl = fileUrl.replaceAll("&", "&");
|
String newFileUrl = fileUrl.replaceAll("&", "&");
|
||||||
|
|
||||||
return newFileUrl;
|
return newFileUrl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String convertFile(String key, String onlineFilePath) throws Exception{
|
public static String convertFile(String url,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";
|
||||||
|
|
||||||
Map<String,Object> map = new HashMap<>();
|
Map<String,Object> map = new HashMap<>();
|
||||||
|
|
||||||
map.put("async",false);
|
map.put("async",false);
|
||||||
|
|
||||||
map.put("filetype","docx");
|
map.put("filetype","docx");
|
||||||
|
|
||||||
map.put("key",key);
|
map.put("key",key);
|
||||||
|
|
||||||
map.put("outputtype","pdf");
|
map.put("outputtype","pdf");
|
||||||
|
map.put("title",titleName+".pdf");
|
||||||
map.put("title","test.pdf");
|
map.put("url","https://10.100.5.111:3306/file/"+onlineFilePath);
|
||||||
map.put("url","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");
|
||||||
|
|
||||||
JSONObject requestJson = new JSONObject(map);
|
JSONObject requestJson = new JSONObject(map);
|
||||||
|
|
||||||
// 创建HttpClientBuilder
|
// 创建HttpClientBuilder
|
||||||
|
|
||||||
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
|
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
|
||||||
|
|
||||||
// HttpClient
|
// HttpClient
|
||||||
|
|
||||||
CloseableHttpClient closeableHttpClient = httpClientBuilder.build();
|
CloseableHttpClient closeableHttpClient = httpClientBuilder.build();
|
||||||
|
|
||||||
HttpPost httpPost = new HttpPost(url);
|
HttpPost httpPost = new HttpPost(url);
|
||||||
|
|
||||||
// 设置请求和传输超时时间
|
// 设置请求和传输超时时间
|
||||||
|
|
||||||
RequestConfig requestConfig = RequestConfig.custom()
|
RequestConfig requestConfig = RequestConfig.custom()
|
||||||
|
|
||||||
.setSocketTimeout(60000)
|
.setSocketTimeout(60000)
|
||||||
|
|
||||||
.setConnectionRequestTimeout(60000)
|
.setConnectionRequestTimeout(60000)
|
||||||
|
|
||||||
.setConnectTimeout(60000)
|
.setConnectTimeout(60000)
|
||||||
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
httpPost.setConfig(requestConfig);
|
httpPost.setConfig(requestConfig);
|
||||||
|
|
||||||
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");
|
||||||
|
|
||||||
data.setContentType("application/json; charset=UTF-8");
|
data.setContentType("application/json; charset=UTF-8");
|
||||||
|
|
||||||
httpPost.setEntity(data);
|
httpPost.setEntity(data);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//发送post请求
|
//发送post请求
|
||||||
|
|
||||||
response = closeableHttpClient.execute(httpPost);
|
response = closeableHttpClient.execute(httpPost);
|
||||||
|
|
||||||
if (response == null || response.getStatusLine() == null) {
|
if (response == null || response.getStatusLine() == null) {
|
||||||
|
|
||||||
throw new Exception("发送POST请求失败,返回结果为空!");
|
throw new Exception("发送POST请求失败,返回结果为空!");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//返回状态是否200
|
//返回状态是否200
|
||||||
|
|
||||||
int statusCode = response.getStatusLine().getStatusCode();
|
int statusCode = response.getStatusLine().getStatusCode();
|
||||||
|
|
||||||
if (statusCode == HttpStatus.SC_OK) {
|
if (statusCode == HttpStatus.SC_OK) {
|
||||||
|
|
||||||
//得到请求结果
|
//得到请求结果
|
||||||
|
logger.info("===========================================返回状态是否200===============================");
|
||||||
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");
|
||||||
|
|
||||||
String fileUrl = analysisXML(responsetData);
|
String fileUrl = analysisXML(responsetData);
|
||||||
|
logger.info("===========================================返回的文件路径"+fileUrl+"===============================");
|
||||||
return fileUrl;
|
return fileUrl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
throw new Exception("发送POST-JSON请求出错:" + response);
|
throw new Exception("发送POST-JSON请求出错:" + response);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
throw new Exception("发送POST请求出现异常," + e.getMessage());
|
throw new Exception("发送POST请求出现异常," + e.getMessage());
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// 关闭连接释放资源
|
// 关闭连接释放资源
|
||||||
|
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
|
|
||||||
response.close();
|
response.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (closeableHttpClient != null) {
|
if (closeableHttpClient != null) {
|
||||||
|
|
||||||
closeableHttpClient.close();
|
closeableHttpClient.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|||||||
@@ -348,7 +348,6 @@ public class AttFileEOController {
|
|||||||
String fileOldName = fileNameEncoding(attFileEO.getOldFileName(),request);
|
String fileOldName = fileNameEncoding(attFileEO.getOldFileName(),request);
|
||||||
response.setHeader("Content-Disposition", "attachment;filename=\""+fileOldName+"\"");
|
response.setHeader("Content-Disposition", "attachment;filename=\""+fileOldName+"\"");
|
||||||
response.setContentType("application/octet-stream");
|
response.setContentType("application/octet-stream");
|
||||||
response.setCharacterEncoding("UTF-8");
|
|
||||||
File file = new File(filePath+attFileEO.getFilePath()+attFileEO.getFileName());
|
File file = new File(filePath+attFileEO.getFilePath()+attFileEO.getFileName());
|
||||||
is = new FileInputStream(file);
|
is = new FileInputStream(file);
|
||||||
os = response.getOutputStream();
|
os = response.getOutputStream();
|
||||||
@@ -497,7 +496,8 @@ public class AttFileEOController {
|
|||||||
+ base64Encoder.encode(fileName.getBytes("utf-8")) + "?=";*/
|
+ base64Encoder.encode(fileName.getBytes("utf-8")) + "?=";*/
|
||||||
fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1"); // firefox浏览器
|
fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1"); // firefox浏览器
|
||||||
} else {
|
} else {
|
||||||
fileName = URLEncoder.encode(fileName, "utf-8");
|
//fileName = URLEncoder.encode(fileName, "utf-8");
|
||||||
|
fileName = new String(fileName.getBytes("UTF-8"), "ISO8859-1");
|
||||||
//谷歌中空格变为+问题
|
//谷歌中空格变为+问题
|
||||||
fileName = fileName.replaceAll("\\+","%20");
|
fileName = fileName.replaceAll("\\+","%20");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user