|
|
@@ -14,6 +14,15 @@ import com.doc.system.domain.SysOperLog;
|
|
|
import com.doc.system.service.ISysOperLogService;
|
|
|
import com.doc.system.service.ISysUserService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.http.HttpEntity;
|
|
|
+import org.apache.http.HttpResponse;
|
|
|
+import org.apache.http.client.methods.HttpGet;
|
|
|
+import org.apache.http.conn.ssl.NoopHostnameVerifier;
|
|
|
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
|
|
+import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
+import org.apache.http.impl.client.HttpClients;
|
|
|
+import org.apache.http.ssl.SSLContexts;
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
@@ -23,6 +32,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.InputStream;
|
|
|
import java.io.PrintWriter;
|
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.URL;
|
|
|
@@ -103,28 +113,29 @@ public class OnlyOfficeController {
|
|
|
DocInfo info = docInfoService.selectDocInfoByDocId(id);
|
|
|
|
|
|
try {
|
|
|
- URL url = new URL(downloadUri);
|
|
|
- HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();
|
|
|
+ MultipartFile multipartFile;
|
|
|
+ String https = "https";
|
|
|
+ if (downloadUri.contains(https)) {
|
|
|
+ SSLConnectionSocketFactory scsf = new SSLConnectionSocketFactory(SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build(),
|
|
|
+ NoopHostnameVerifier.INSTANCE);
|
|
|
+ CloseableHttpClient client = HttpClients.custom().setSSLSocketFactory(scsf).build();
|
|
|
+ HttpGet httpget = new HttpGet(downloadUri);
|
|
|
+ HttpResponse res = client.execute(httpget);
|
|
|
+ HttpEntity entity = res.getEntity();
|
|
|
+ try (InputStream is = entity.getContent()) {
|
|
|
+ multipartFile = FileUtils.getMultipartFile(is, info.getFileName());
|
|
|
+ process(id, info, user, multipartFile);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ URL url = new URL(downloadUri);
|
|
|
+ HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();
|
|
|
+ multipartFile = FileUtils.getMultipartFile(connection.getInputStream(), info.getFileName());
|
|
|
+ process(id, info, user, multipartFile);
|
|
|
+ connection.disconnect();
|
|
|
+ }
|
|
|
|
|
|
- MultipartFile multipartFile = FileUtils.getMultipartFile(connection.getInputStream(), info.getFileName());
|
|
|
- //保存版本信息
|
|
|
- DocVersion version = new DocVersion();
|
|
|
- version.setDocId(id);
|
|
|
- version.setFileId(info.getFileId());
|
|
|
- version.setCreateBy(info.getCreateBy());
|
|
|
- version.setCreateTime(info.getCreateTime());
|
|
|
- versionService.insertDocVersion(version);
|
|
|
-
|
|
|
- //保存新的文件信息
|
|
|
- DocumentVO vo = mongoService.uploadFile(multipartFile);
|
|
|
- info.setFileId(vo.getFileId());
|
|
|
- info.setFileSize(vo.getFileSize());
|
|
|
- info.setCreateBy(user.getUserName());
|
|
|
- info.setCreateTime(new Date());
|
|
|
- info.setUpdateBy(user.getUserName());
|
|
|
- docInfoService.updateDocInfoByOnlyOffice(info);
|
|
|
-
|
|
|
- connection.disconnect();
|
|
|
} catch (Exception ex) {
|
|
|
log.error("OnlyOffice异常消息:{}", ex.getMessage());
|
|
|
saved = 1;
|
|
|
@@ -153,4 +164,23 @@ public class OnlyOfficeController {
|
|
|
/*插入操作日志--end*/
|
|
|
writer.write(result);
|
|
|
}
|
|
|
+
|
|
|
+ private void process(Long id, DocInfo info, SysUser user, MultipartFile multipartFile) throws Exception {
|
|
|
+ //保存版本信息
|
|
|
+ DocVersion version = new DocVersion();
|
|
|
+ version.setDocId(id);
|
|
|
+ version.setFileId(info.getFileId());
|
|
|
+ version.setCreateBy(info.getCreateBy());
|
|
|
+ version.setCreateTime(info.getCreateTime());
|
|
|
+ versionService.insertDocVersion(version);
|
|
|
+
|
|
|
+ //保存新的文件信息
|
|
|
+ DocumentVO vo = mongoService.uploadFile(multipartFile);
|
|
|
+ info.setFileId(vo.getFileId());
|
|
|
+ info.setFileSize(vo.getFileSize());
|
|
|
+ info.setCreateBy(user.getUserName());
|
|
|
+ info.setCreateTime(new Date());
|
|
|
+ info.setUpdateBy(user.getUserName());
|
|
|
+ docInfoService.updateDocInfoByOnlyOffice(info);
|
|
|
+ }
|
|
|
}
|