|
|
@@ -1,7 +1,5 @@
|
|
|
package com.uas.platform.b2b.service.impl;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.uas.dfs.service.FileClient;
|
|
|
import com.uas.platform.b2b.core.util.PathUtils;
|
|
|
import com.uas.platform.b2b.dao.AttachDao;
|
|
|
import com.uas.platform.b2b.model.Attach;
|
|
|
@@ -11,7 +9,6 @@ import com.uas.platform.b2b.support.HttpUtils;
|
|
|
import com.uas.platform.b2b.support.SystemSession;
|
|
|
import com.uas.platform.b2b.temporary.model.FileUrl;
|
|
|
import com.uas.platform.core.util.FileUtils;
|
|
|
-import org.apache.commons.io.FilenameUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
@@ -20,14 +17,21 @@ import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
|
|
|
+/**
|
|
|
+ * 文件服务
|
|
|
+ *
|
|
|
+ * @author hejq
|
|
|
+ */
|
|
|
@Service
|
|
|
public class AttachServiceImpl implements AttachService {
|
|
|
|
|
|
@Autowired
|
|
|
private AttachDao attachDao;
|
|
|
|
|
|
- @Autowired
|
|
|
- private FileClient fileClient;
|
|
|
+ /**
|
|
|
+ * 文件最大100M
|
|
|
+ */
|
|
|
+ private final Integer MAX_FILE_SIZE = 100 * 1024 * 1024;
|
|
|
|
|
|
@Override
|
|
|
public Attach getAttach(Long id) {
|
|
|
@@ -52,7 +56,7 @@ public class AttachServiceImpl implements AttachService {
|
|
|
public Attach upload(FileUpload uploadItem, String description) {
|
|
|
String filename = uploadItem.getFile().getOriginalFilename();
|
|
|
long size = uploadItem.getFile().getSize();
|
|
|
- if(size > 100 * 1024 * 1024) {// 100Mb
|
|
|
+ if(size > MAX_FILE_SIZE) {
|
|
|
// 是否限制文件上传大小
|
|
|
}
|
|
|
String path = null;
|
|
|
@@ -61,7 +65,6 @@ public class AttachServiceImpl implements AttachService {
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
-// String path = fileClient.upload(uploadItem.getFile().getBytes(), size, FilenameUtils.getExtension(filename), null);
|
|
|
Attach attach = new Attach(filename, path, description, size, new Date());
|
|
|
return attach;
|
|
|
}
|
|
|
@@ -78,7 +81,8 @@ public class AttachServiceImpl implements AttachService {
|
|
|
File file = new File(fileMap.get(entry));
|
|
|
if (file.exists()) {
|
|
|
Map<String, Object> params = entryParams.get(entry);
|
|
|
- sources = params.get("sourceId").toString().split(",");// multi sources
|
|
|
+ // multi sources
|
|
|
+ sources = params.get("sourceId").toString().split(",");
|
|
|
for (String sr : sources) {
|
|
|
Attach attach = new Attach(String.valueOf(params.get("name")), fileMap.get(entry), description, file.length(),
|
|
|
new Date());
|
|
|
@@ -125,17 +129,20 @@ public class AttachServiceImpl implements AttachService {
|
|
|
private String getDir(String parentDir) {
|
|
|
String path = PathUtils.getFilePath() + "postattach";
|
|
|
File dir = new File(path);
|
|
|
- if (!dir.isDirectory())
|
|
|
- dir.mkdir();
|
|
|
+ if (!dir.isDirectory()) {
|
|
|
+ dir.mkdir();
|
|
|
+ }
|
|
|
path += File.separator + parentDir;
|
|
|
dir = new File(path);
|
|
|
- if (!dir.isDirectory())
|
|
|
- dir.mkdir();
|
|
|
+ if (!dir.isDirectory()) {
|
|
|
+ dir.mkdir();
|
|
|
+ }
|
|
|
if (SystemSession.getUser() != null) {
|
|
|
path += File.separator + SystemSession.getUser().getEnterprise().getUu();
|
|
|
dir = new File(path);
|
|
|
- if (!dir.isDirectory())
|
|
|
- dir.mkdir();
|
|
|
+ if (!dir.isDirectory()) {
|
|
|
+ dir.mkdir();
|
|
|
+ }
|
|
|
}
|
|
|
return path;
|
|
|
}
|