|
@@ -5,7 +5,6 @@ import java.io.FileInputStream;
|
|
|
import java.io.FileNotFoundException;
|
|
|
import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
-import java.io.InputStream;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
@@ -23,10 +22,11 @@ import com.xt.jygl.accessory.entity.AccessoryEntity;
|
|
|
import com.xt.jygl.accessory.service.AccessoryService;
|
|
|
import com.xt.jygl.common.GlobalData;
|
|
|
import com.xt.jygl.common.service.JyglBaseService;
|
|
|
+import com.xt.jygl.ftp.Ftp;
|
|
|
+import com.xt.jygl.ftp.FtpUtil;
|
|
|
import com.xt.jygl.gkjygl.gkjyr.jyrjbxx.vo.GkjyrVo;
|
|
|
import com.xtframe.core.support.SecurityMgr;
|
|
|
import com.xtframe.sec.common.SecRepository;
|
|
|
-import com.xtframe.sec.user.entity.UserEntity;
|
|
|
import com.xtframe.util.StringUtils;
|
|
|
|
|
|
/**
|
|
@@ -58,7 +58,7 @@ public class AccessoryServiceImpl extends JyglBaseService<AccessoryEntity, Strin
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public AccessoryEntity saveFile(MultipartFile file, String sstype) {
|
|
|
- UserEntity user = securityMgr.getCurrUser();
|
|
|
+ // UserEntity user = securityMgr.getCurrUser();
|
|
|
if (file.getSize() > GlobalData.UPLOAD_FILE_SIZE * 1024 * 1024) {
|
|
|
return null;
|
|
|
}
|
|
@@ -71,13 +71,16 @@ public class AccessoryServiceImpl extends JyglBaseService<AccessoryEntity, Strin
|
|
|
// 判断文件是否为空
|
|
|
String filename = "";
|
|
|
String filePath = "";
|
|
|
+ String path = "";
|
|
|
+ boolean flag = false;
|
|
|
if (!file.isEmpty()) {
|
|
|
try {
|
|
|
SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
Date today = new Date();
|
|
|
filename = dateTimeFormat.format(today) + "." + suffix;
|
|
|
// 文件保存路径
|
|
|
- filePath = GlobalData.UPLOAD_FILE_PATH + File.separator + sstype +File.separator;
|
|
|
+ path = File.separator + sstype + File.separator;
|
|
|
+ filePath = GlobalData.UPLOAD_FILE_PATH + path;
|
|
|
File newfile = new File(filePath);
|
|
|
|
|
|
// 如果文件夹不存在则创建
|
|
@@ -86,18 +89,41 @@ public class AccessoryServiceImpl extends JyglBaseService<AccessoryEntity, Strin
|
|
|
}
|
|
|
// 转存文件
|
|
|
file.transferTo(new File(filePath + filename));
|
|
|
+
|
|
|
+ /*if (!"jsjdcbsj".equals(sstype)) {
|
|
|
+ // ftp 上传
|
|
|
+ Ftp f = new Ftp();
|
|
|
+ f.setIpAddr("127.0.0.1");
|
|
|
+ f.setPort(21);
|
|
|
+ f.setUserName(GlobalData.DSJC);
|
|
|
+ f.setPwd(GlobalData.DSJC);
|
|
|
+ // f.setPath(GlobalData.FTP_UPLOAD_PATH);
|
|
|
+ if (FtpUtil.connectFtp(f)) {
|
|
|
+ FtpUtil.makeDirFile(filePath);
|
|
|
+ File ftpFile = new File(filePath + filename);
|
|
|
+ if (ftpFile != null) {
|
|
|
+ flag = FtpUtil.upload(ftpFile);// 把文件上传在ftp上
|
|
|
+ System.out.println("ok");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ flag =true;
|
|
|
+ }*/
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
AccessoryEntity accessoryEntity = new AccessoryEntity();
|
|
|
+ if (flag) {
|
|
|
+ accessoryEntity.setFjbz("1");
|
|
|
+ }
|
|
|
accessoryEntity.setSstype(sstype);
|
|
|
accessoryEntity.setLength(file.getSize());
|
|
|
accessoryEntity.setName(fileName);
|
|
|
accessoryEntity.setSuffix(suffix);
|
|
|
accessoryEntity.setFilename(filename);
|
|
|
- accessoryEntity.setFilepath(filePath);
|
|
|
+ accessoryEntity.setFilepath(path);
|
|
|
accessoryEntity = this.save(accessoryEntity);
|
|
|
return accessoryEntity;
|
|
|
}
|
|
@@ -119,7 +145,7 @@ public class AccessoryServiceImpl extends JyglBaseService<AccessoryEntity, Strin
|
|
|
|
|
|
@Override
|
|
|
public AccessoryEntity saveFz(MultipartFile file, GkjyrVo jyr, String sstype) {
|
|
|
- UserEntity user = securityMgr.getCurrUser();
|
|
|
+ // UserEntity user = securityMgr.getCurrUser();
|
|
|
if (file.getSize() > GlobalData.UPLOAD_FILE_SIZE * 1024 * 1024) {
|
|
|
return null;
|
|
|
}
|
|
@@ -132,13 +158,16 @@ public class AccessoryServiceImpl extends JyglBaseService<AccessoryEntity, Strin
|
|
|
// 判断文件是否为空
|
|
|
String filename = "";
|
|
|
String filePath = "";
|
|
|
+ String path = "";
|
|
|
+ boolean flag = false;
|
|
|
if (!file.isEmpty()) {
|
|
|
try {
|
|
|
SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
Date today = new Date();
|
|
|
filename = dateTimeFormat.format(today) + "." + suffix;
|
|
|
// 文件保存路径
|
|
|
- filePath = GlobalData.VIEW_FILE_PATH + File.separator + jyr.getSzd() +File.separator + jyr.getSzgk() + File.separator + jyr.getSzgq() + File.separator + jyr.getId() + File.separator;
|
|
|
+ path = File.separator + jyr.getSzd() + File.separator + jyr.getSzgk() + File.separator + jyr.getSzgq() + File.separator + jyr.getId() + File.separator;
|
|
|
+ filePath = GlobalData.VIEW_FILE_PATH + path;
|
|
|
File newfile = new File(filePath);
|
|
|
|
|
|
// 如果文件夹不存在则创建
|
|
@@ -147,18 +176,48 @@ public class AccessoryServiceImpl extends JyglBaseService<AccessoryEntity, Strin
|
|
|
}
|
|
|
// 转存文件
|
|
|
file.transferTo(new File(filePath + filename));
|
|
|
+
|
|
|
+ /*// ftp 上传
|
|
|
+ Ftp f = new Ftp();
|
|
|
+ f.setIpAddr("127.0.0.1");
|
|
|
+ f.setPort(21);
|
|
|
+ f.setUserName(GlobalData.FTP_VIEW_USER);
|
|
|
+ f.setPwd(GlobalData.FTP_VIEW_USER);
|
|
|
+ // f.setPath(GlobalData.FTP_VIEW_PATH);
|
|
|
+ if (FtpUtil.connectFtp(f)) {
|
|
|
+ String ftppath = GlobalData.VIEW_FILE_PATH + File.separator + jyr.getSzd();
|
|
|
+ FtpUtil.makeDirFile(ftppath);
|
|
|
+ ftppath = ftppath + File.separator + jyr.getSzgk();
|
|
|
+ FtpUtil.makeDirFile(ftppath);
|
|
|
+ ftppath = ftppath + File.separator + jyr.getSzgq();
|
|
|
+ FtpUtil.makeDirFile(ftppath);
|
|
|
+ ftppath = ftppath + File.separator + jyr.getId();
|
|
|
+ FtpUtil.makeDirFile(ftppath);
|
|
|
+
|
|
|
+ File ftpFile = new File(ftppath + File.separator + filename);
|
|
|
+ if (ftpFile != null) {
|
|
|
+ flag = FtpUtil.upload(ftpFile);// 把文件上传在ftp上
|
|
|
+ System.out.println("ok");
|
|
|
+ }
|
|
|
+ }
|
|
|
+*/
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ FtpUtil.closeFtp();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
AccessoryEntity accessoryEntity = new AccessoryEntity();
|
|
|
+ if (flag) {
|
|
|
+ accessoryEntity.setFjbz("1");
|
|
|
+ }
|
|
|
accessoryEntity.setSstype(sstype);
|
|
|
accessoryEntity.setLength(file.getSize());
|
|
|
accessoryEntity.setName(fileName);
|
|
|
accessoryEntity.setSuffix(suffix);
|
|
|
accessoryEntity.setFilename(filename);
|
|
|
- accessoryEntity.setFilepath(filePath);
|
|
|
+ accessoryEntity.setFilepath(path);
|
|
|
accessoryEntity = this.save(accessoryEntity);
|
|
|
return accessoryEntity;
|
|
|
|
|
@@ -176,7 +235,7 @@ public class AccessoryServiceImpl extends JyglBaseService<AccessoryEntity, Strin
|
|
|
if (file.exists()) {
|
|
|
// 新目录
|
|
|
FileInputStream inStream = null;
|
|
|
- FileOutputStream fs= null;
|
|
|
+ FileOutputStream fs = null;
|
|
|
String newurl = entity.getFilepath().replace(oldtype, sstype);
|
|
|
File newfile = new File(newurl);
|
|
|
// 如果文件夹不存在则创建
|
|
@@ -185,7 +244,7 @@ public class AccessoryServiceImpl extends JyglBaseService<AccessoryEntity, Strin
|
|
|
}
|
|
|
try {
|
|
|
inStream = new FileInputStream(file);
|
|
|
- fs = new FileOutputStream(newurl+filename);
|
|
|
+ fs = new FileOutputStream(newurl + filename);
|
|
|
byte[] buffer = new byte[1024 * 1024];
|
|
|
int len;
|
|
|
while ((len = inStream.read(buffer)) != -1) {
|