|
|
@@ -4,7 +4,6 @@ import java.io.BufferedInputStream;
|
|
|
import java.io.BufferedOutputStream;
|
|
|
import java.io.File;
|
|
|
import java.io.FileOutputStream;
|
|
|
-import java.util.List;
|
|
|
import java.util.UUID;
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -24,22 +23,21 @@ public class AttachServiceImpl implements AttachService{
|
|
|
private AttachDao attachDao;
|
|
|
|
|
|
@Override
|
|
|
- public List<Attach> getAttachById(Long id) {
|
|
|
+ public Attach getAttachById(Long id) {
|
|
|
return attachDao.findAttachByAtId(id);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Long saveAttachPath(Attach attach) {
|
|
|
- attach.setAtId(null);
|
|
|
- return attachDao.save(attach).getAtId();
|
|
|
+ public Attach saveAttachPath(Attach attach) {
|
|
|
+ return attachDao.save(attach);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String uploadAttach(FileUpload uploadItem) {
|
|
|
+ public Attach uploadAndSaveAttach(FileUpload uploadItem) {
|
|
|
String filename = uploadItem.getFile().getOriginalFilename();
|
|
|
long size = uploadItem.getFile().getSize();
|
|
|
if (size > 104857600) {
|
|
|
- return "FORBIDEN";//文件过大,上传失败
|
|
|
+ return null;//文件过大,上传失败
|
|
|
}
|
|
|
String path = getFilePath(filename, "postattach", "bussinessCodeImg");
|
|
|
File file = new File(path);
|
|
|
@@ -57,15 +55,45 @@ public class AttachServiceImpl implements AttachService{
|
|
|
bos.close();
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- return "FAILED";//操作失败
|
|
|
}
|
|
|
Attach attach = new Attach();
|
|
|
attach.setAtPath(path);
|
|
|
attach.setAtDescription("客户营业执照复印件或照片");
|
|
|
attach.setAtName(filename);
|
|
|
- Long id = saveAttachPath(attach);
|
|
|
- return id.toString();
|
|
|
+ Attach at = saveAttachPath(attach);
|
|
|
+ return at;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Attach uploadAttach(FileUpload uploadItem) {
|
|
|
+ String filename = uploadItem.getFile().getOriginalFilename();
|
|
|
+ long size = uploadItem.getFile().getSize();
|
|
|
+ if (size > 104857600) {
|
|
|
+ return null;//文件过大,上传失败
|
|
|
+ }
|
|
|
+ String path = getFilePath(filename, "postattach", "bussinessCodeImg");
|
|
|
+ File file = new File(path);
|
|
|
+ BufferedOutputStream bos = null;
|
|
|
+ BufferedInputStream bis = null;
|
|
|
+ try {
|
|
|
+ bos = new BufferedOutputStream(new FileOutputStream(file));
|
|
|
+ bis = new BufferedInputStream(uploadItem.getFile().getInputStream());
|
|
|
+ int c;
|
|
|
+ while ((c = bis.read()) != -1) {
|
|
|
+ bos.write(c);
|
|
|
+ bos.flush();
|
|
|
+ }
|
|
|
+ bis.close();
|
|
|
+ bos.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ Attach attach = new Attach();
|
|
|
+ attach.setAtPath(path);
|
|
|
+ attach.setAtDescription("客户营业执照复印件或照片");
|
|
|
+ attach.setAtName(filename);
|
|
|
+ return attach;
|
|
|
+ };
|
|
|
|
|
|
@Override
|
|
|
public String getFilePath(String fileName, String dirName, String userName) {
|