|
|
@@ -15,63 +15,35 @@ import com.uas.platform.b2b.model.Attach;
|
|
|
import com.uas.platform.b2b.model.FileUpload;
|
|
|
import com.uas.platform.b2b.service.AttachService;
|
|
|
|
|
|
-
|
|
|
@Service
|
|
|
-public class AttachServiceImpl implements AttachService{
|
|
|
+public class AttachServiceImpl implements AttachService {
|
|
|
|
|
|
@Autowired
|
|
|
private AttachDao attachDao;
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
- public Attach getAttachById(Long id) {
|
|
|
- return attachDao.findAttachByAtId(id);
|
|
|
+ public Attach getAttach(Long id) {
|
|
|
+ return attachDao.findOne(id);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Attach saveAttachPath(Attach attach) {
|
|
|
+ public Attach save(Attach attach) {
|
|
|
return attachDao.save(attach);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Attach uploadAndSaveAttach(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);
|
|
|
- Attach at = saveAttachPath(attach);
|
|
|
- return at;
|
|
|
+ public Attach uploadAndSave(FileUpload uploadItem, String parentDir, String description) {
|
|
|
+ return save(upload(uploadItem, parentDir, description));
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@Override
|
|
|
- public Attach uploadAttach(FileUpload uploadItem) {
|
|
|
+ public Attach upload(FileUpload uploadItem, String parentDir, String description) {
|
|
|
String filename = uploadItem.getFile().getOriginalFilename();
|
|
|
long size = uploadItem.getFile().getSize();
|
|
|
if (size > 104857600) {
|
|
|
- return null;//文件过大,上传失败
|
|
|
+ return null;// 文件过大,上传失败
|
|
|
}
|
|
|
- String path = getFilePath(filename, "postattach", "bussinessCodeImg");
|
|
|
+ String path = getFilePath(filename, parentDir);
|
|
|
File file = new File(path);
|
|
|
BufferedOutputStream bos = null;
|
|
|
BufferedInputStream bis = null;
|
|
|
@@ -88,26 +60,20 @@ public class AttachServiceImpl implements AttachService{
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- Attach attach = new Attach();
|
|
|
- attach.setAtPath(path);
|
|
|
- attach.setAtDescription("客户营业执照复印件或照片");
|
|
|
- attach.setAtName(filename);
|
|
|
- return attach;
|
|
|
- };
|
|
|
+ return new Attach(filename, path, description, size);
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public String getFilePath(String fileName, String dirName, String userName) {
|
|
|
+ private String getFilePath(String fileName, String parentDir) {
|
|
|
String uuid = UUID.randomUUID().toString().replaceAll("\\-", "");
|
|
|
- String suffix = fileName.indexOf(".") != -1 ? fileName.substring(fileName.lastIndexOf("."), fileName.length())
|
|
|
- : "";
|
|
|
- String path = BaseUtil.FILEPATH + dirName;
|
|
|
+ String suffix = fileName.indexOf(".") != -1 ? fileName.substring(fileName.lastIndexOf("."), fileName.length()) : "";
|
|
|
+ String path = BaseUtil.FILEPATH + "postattach";
|
|
|
File file = new File(path);
|
|
|
if (!file.isDirectory()) {
|
|
|
file.mkdir();
|
|
|
- path = path + File.separator + userName;
|
|
|
+ path = path + File.separator + parentDir;
|
|
|
new File(path).mkdir();
|
|
|
} else {
|
|
|
- path = path + File.separator + userName;
|
|
|
+ path = path + File.separator + parentDir;
|
|
|
file = new File(path);
|
|
|
if (!file.isDirectory()) {
|
|
|
file.mkdir();
|