|
@@ -1,15 +1,13 @@
|
|
package com.ym.mec.biz.service;
|
|
package com.ym.mec.biz.service;
|
|
|
|
|
|
-import java.io.File;
|
|
|
|
-import java.io.FileOutputStream;
|
|
|
|
-import java.io.IOException;
|
|
|
|
-import java.io.InputStream;
|
|
|
|
|
|
+import java.io.*;
|
|
|
|
|
|
import org.apache.commons.io.FileUtils;
|
|
import org.apache.commons.io.FileUtils;
|
|
import org.apache.commons.io.IOUtils;
|
|
import org.apache.commons.io.IOUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.ym.mec.common.entity.UploadReturnBean;
|
|
import com.ym.mec.common.entity.UploadReturnBean;
|
|
@@ -17,6 +15,7 @@ import com.ym.mec.common.exception.BizException;
|
|
import com.ym.mec.thirdparty.storage.StoragePluginContext;
|
|
import com.ym.mec.thirdparty.storage.StoragePluginContext;
|
|
import com.ym.mec.thirdparty.storage.provider.KS3StoragePlugin;
|
|
import com.ym.mec.thirdparty.storage.provider.KS3StoragePlugin;
|
|
import com.ym.mec.util.upload.UploadUtil;
|
|
import com.ym.mec.util.upload.UploadUtil;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 上传工具服务层实现类
|
|
* 上传工具服务层实现类
|
|
@@ -40,7 +39,6 @@ public class UploadFileService {
|
|
private String fileRoot;
|
|
private String fileRoot;
|
|
|
|
|
|
public UploadReturnBean uploadFile(InputStream in, String ext) {
|
|
public UploadReturnBean uploadFile(InputStream in, String ext) {
|
|
-
|
|
|
|
UploadReturnBean uploadReturn = new UploadReturnBean("", false, "");
|
|
UploadReturnBean uploadReturn = new UploadReturnBean("", false, "");
|
|
String fileName = UploadUtil.getFileName(ext);
|
|
String fileName = UploadUtil.getFileName(ext);
|
|
|
|
|
|
@@ -77,6 +75,32 @@ public class UploadFileService {
|
|
return uploadReturn;
|
|
return uploadReturn;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ @Async
|
|
|
|
+ public UploadReturnBean uploadImHistoryMsgFile(File msgFile) throws FileNotFoundException {
|
|
|
|
+ InputStream in = new FileInputStream(msgFile);
|
|
|
|
+ UploadReturnBean uploadReturn = new UploadReturnBean("", false, "");
|
|
|
|
+ String fileName = UploadUtil.getFileName(msgFile.getName());
|
|
|
|
+
|
|
|
|
+ String root = fileRoot + "im_history_msg/";
|
|
|
|
+ if (StringUtils.isBlank(root)) {
|
|
|
|
+ uploadReturn.setMessage("上传临时目录没有配置");
|
|
|
|
+ return uploadReturn;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String staticFloder = "";
|
|
|
|
+ String folder = UploadUtil.getFileFloder();
|
|
|
|
+ String filePath = UploadUtil.getFilePath(root, staticFloder, folder);
|
|
|
|
+ File file = uploadFile(in, filePath, fileName);
|
|
|
|
+ String url = storagePluginContext.uploadFile(KS3StoragePlugin.PLUGIN_NAME,staticFloder + folder, file);
|
|
|
|
+
|
|
|
|
+ FileUtils.deleteQuietly(file);
|
|
|
|
+
|
|
|
|
+ uploadReturn.setStatus(true);
|
|
|
|
+ uploadReturn.setUrl(url);
|
|
|
|
+ return uploadReturn;
|
|
|
|
+ }
|
|
|
|
+
|
|
public void setMaxSize(int maxSize) {
|
|
public void setMaxSize(int maxSize) {
|
|
this.maxSize = maxSize;
|
|
this.maxSize = maxSize;
|
|
}
|
|
}
|