SFTP上传优化
This commit is contained in:
parent
81a838bc03
commit
cd31ff7833
|
@ -19,59 +19,27 @@ import java.util.Properties;
|
||||||
public class SFTPUtil {
|
public class SFTPUtil {
|
||||||
private static long count = 3;
|
private static long count = 3;
|
||||||
private static long count1 = 0;
|
private static long count1 = 0;
|
||||||
private static long sleepTime = 300000;//5分钟
|
private static long sleepTime = 1800000;//30分钟
|
||||||
private static final Logger logger = LoggerFactory.getLogger(SFTPUtil.class);
|
private static final Logger logger = LoggerFactory.getLogger(SFTPUtil.class);
|
||||||
|
private static Session sshSession = null;
|
||||||
|
private static ChannelSftp sftp = null;
|
||||||
|
|
||||||
public static ChannelSftp connect(SftpConfig sftpConfig){
|
public static void getSession(SftpConfig sftpConfig){
|
||||||
ChannelSftp sftp = null;
|
|
||||||
try {
|
try {
|
||||||
JSch jsch = new JSch();
|
if(sshSession == null ){
|
||||||
Session sshSession = jsch.getSession(sftpConfig.getUsername(), sftpConfig.getHostname(), sftpConfig.getPort());
|
JSch jsch = new JSch();
|
||||||
logger.info("Session created ... host=" + sftpConfig.getHostname() + ";port=" + sftpConfig.getPort()+";UserName=" + sftpConfig.getUsername() + ";Password="+sftpConfig.getPassword());
|
sshSession = jsch.getSession(sftpConfig.getUsername(), sftpConfig.getHostname(), sftpConfig.getPort());
|
||||||
|
logger.info("Session created ... host=" + sftpConfig.getHostname() + ";port=" + sftpConfig.getPort()+";UserName=" + sftpConfig.getUsername() + ";Password="+sftpConfig.getPassword());
|
||||||
// jsch.addIdentity("e:/sftp_keys.ppk","");
|
// jsch.addIdentity("e:/sftp_keys.ppk","");
|
||||||
sshSession.setPassword(sftpConfig.getPassword());
|
sshSession.setPassword(sftpConfig.getPassword());
|
||||||
Properties sshConfig = new Properties();
|
Properties sshConfig = new Properties();
|
||||||
sshConfig.put("StrictHostKeyChecking", "no");
|
sshConfig.put("StrictHostKeyChecking", "no");
|
||||||
sshSession.setConfig(sshConfig);
|
sshSession.setConfig(sshConfig);
|
||||||
sshSession.setTimeout(sftpConfig.getTimeout());
|
sshSession.setTimeout(sftpConfig.getTimeout());
|
||||||
sshSession.connect();
|
sshSession.connect();
|
||||||
logger.info("Session connected ...");
|
logger.info("Session connected ...");
|
||||||
logger.info("Opening Channel ...");
|
logger.info("Opening Channel ...");
|
||||||
Channel channel = sshSession.openChannel("sftp");
|
|
||||||
channel.connect();
|
|
||||||
sftp = (ChannelSftp) channel;
|
|
||||||
logger.info("登录成功");
|
|
||||||
} catch (Exception e){
|
|
||||||
try{
|
|
||||||
count1 += 1;
|
|
||||||
if(count == count1){
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
Thread.sleep(sleepTime);
|
|
||||||
logger.info("重新连接....");
|
|
||||||
connect(sftpConfig);
|
|
||||||
} catch (InterruptedException e1){
|
|
||||||
throw new RuntimeException(e1);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return sftp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Session getSession(SftpConfig sftpConfig){
|
|
||||||
Session sshSession = null;
|
|
||||||
try {
|
|
||||||
JSch jsch = new JSch();
|
|
||||||
sshSession = jsch.getSession(sftpConfig.getUsername(), sftpConfig.getHostname(), sftpConfig.getPort());
|
|
||||||
logger.info("Session created ... host=" + sftpConfig.getHostname() + ";port=" + sftpConfig.getPort()+";UserName=" + sftpConfig.getUsername() + ";Password="+sftpConfig.getPassword());
|
|
||||||
// jsch.addIdentity("e:/sftp_keys.ppk","");
|
|
||||||
sshSession.setPassword(sftpConfig.getPassword());
|
|
||||||
Properties sshConfig = new Properties();
|
|
||||||
sshConfig.put("StrictHostKeyChecking", "no");
|
|
||||||
sshSession.setConfig(sshConfig);
|
|
||||||
sshSession.setTimeout(sftpConfig.getTimeout());
|
|
||||||
sshSession.connect();
|
|
||||||
logger.info("Session connected ...");
|
|
||||||
logger.info("Opening Channel ...");
|
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
try{
|
try{
|
||||||
count1 += 1;
|
count1 += 1;
|
||||||
|
@ -85,10 +53,35 @@ public class SFTPUtil {
|
||||||
throw new RuntimeException(e1);
|
throw new RuntimeException(e1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return sshSession;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void mkdirs(String directory,ChannelSftp sftp) throws SftpException {
|
public static void getChannelSftp(SftpConfig sftpConfig){
|
||||||
|
try {
|
||||||
|
if(sshSession == null){
|
||||||
|
if(sshSession == null){
|
||||||
|
getSession(sftpConfig);
|
||||||
|
}
|
||||||
|
Channel channel = sshSession.openChannel("sftp");
|
||||||
|
channel.connect();
|
||||||
|
sftp = (ChannelSftp) channel;
|
||||||
|
logger.info("登录成功");
|
||||||
|
}
|
||||||
|
} catch (Exception e){
|
||||||
|
try{
|
||||||
|
count1 += 1;
|
||||||
|
if(count == count1){
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
Thread.sleep(sleepTime);
|
||||||
|
logger.info("重新连接....");
|
||||||
|
getChannelSftp(sftpConfig);
|
||||||
|
} catch (InterruptedException e1){
|
||||||
|
throw new RuntimeException(e1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void mkdirs(String directory) throws SftpException {
|
||||||
String[] dics = directory.split("/");
|
String[] dics = directory.split("/");
|
||||||
for(int i=0;i< dics.length;i++){
|
for(int i=0;i< dics.length;i++){
|
||||||
try {
|
try {
|
||||||
|
@ -101,7 +94,7 @@ public class SFTPUtil {
|
||||||
sftp.mkdir(dics[i]);
|
sftp.mkdir(dics[i]);
|
||||||
sftp.cd(dics[i]);
|
sftp.cd(dics[i]);
|
||||||
} catch (SftpException e2) {
|
} catch (SftpException e2) {
|
||||||
throw new RuntimeException("打开文件夹错误,[{}]", e2);
|
throw new RuntimeException("打开文件夹错误,"+e2.getMessage(), e2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,14 +108,23 @@ public class SFTPUtil {
|
||||||
* @param uploadFileName 要上传的文件名称(重新定义的文件名称)
|
* @param uploadFileName 要上传的文件名称(重新定义的文件名称)
|
||||||
* @param
|
* @param
|
||||||
*/
|
*/
|
||||||
public static Map<String,Object> upload(ChannelSftp sftp, SftpConfig sftpConfig,boolean isConcat, String directory, String uploadFilePath, String uploadFileName) {
|
public static Map<String,String> upload(SftpConfig sftpConfig,boolean isConcat, String directory, String uploadFilePath, String uploadFileName) {
|
||||||
Map<String,Object> map = new HashMap<String,Object>();
|
Map<String,String> map = new HashMap<String,String>();
|
||||||
map.put("code","0");
|
map.put("code","0");
|
||||||
map.put("msg","上传成功");
|
map.put("msg","上传成功");
|
||||||
// ChannelSftp sftp = null;
|
|
||||||
try{
|
try{
|
||||||
if(sftp == null){
|
if(sftp == null){
|
||||||
sftp = connect(sftpConfig);
|
getChannelSftp(sftpConfig);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
sftp.cd(sftpConfig.getFullpath());
|
||||||
|
} catch (SftpException e1) {
|
||||||
|
try {
|
||||||
|
mkdirs(sftpConfig.getFullpath());
|
||||||
|
} catch (SftpException e2) {
|
||||||
|
map.put("code", "1");
|
||||||
|
map.put("msg", "sftp创建" + sftpConfig.getUploadpath() + "文件路径失败");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if(isConcat){
|
if(isConcat){
|
||||||
|
@ -131,7 +133,7 @@ public class SFTPUtil {
|
||||||
sftp.cd(directory);
|
sftp.cd(directory);
|
||||||
} catch (SftpException e1) {
|
} catch (SftpException e1) {
|
||||||
try {
|
try {
|
||||||
mkdirs(directory,sftp);
|
mkdirs(directory);
|
||||||
// sftp.mkdir(directory);
|
// sftp.mkdir(directory);
|
||||||
// sftp.cd(directory);
|
// sftp.cd(directory);
|
||||||
} catch (SftpException e2) {
|
} catch (SftpException e2) {
|
||||||
|
@ -156,10 +158,6 @@ public class SFTPUtil {
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
map.put("code","1");
|
map.put("code","1");
|
||||||
map.put("msg","sftp异常:" + e.getMessage());
|
map.put("msg","sftp异常:" + e.getMessage());
|
||||||
}finally {
|
|
||||||
// if(sftp!=null){
|
|
||||||
// disConnect(sftp);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
@ -168,17 +166,25 @@ public class SFTPUtil {
|
||||||
Map<String,String> map = new HashMap<String,String>();
|
Map<String,String> map = new HashMap<String,String>();
|
||||||
map.put("code","0");
|
map.put("code","0");
|
||||||
map.put("msg","上传成功");
|
map.put("msg","上传成功");
|
||||||
ChannelSftp sftp = null;
|
|
||||||
try{
|
try{
|
||||||
sftp = connect(sftpConfig);
|
if(sftp == null){
|
||||||
|
getChannelSftp(sftpConfig);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
sftp.cd(sftpConfig.getFullpath());
|
||||||
|
} catch (SftpException e1) {
|
||||||
|
try {
|
||||||
|
mkdirs(sftpConfig.getFullpath());
|
||||||
|
} catch (SftpException e2) {
|
||||||
|
map.put("code", "1");
|
||||||
|
map.put("msg", "sftp创建" + sftpConfig.getUploadpath() + "文件路径失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
// directory = getDirectory(sftpConfig.getUploadpath(), directory);
|
|
||||||
sftp.cd(directory);
|
sftp.cd(directory);
|
||||||
} catch (SftpException e1) {
|
} catch (SftpException e1) {
|
||||||
try {
|
try {
|
||||||
mkdirs(directory,sftp);
|
mkdirs(directory);
|
||||||
// sftp.mkdir(directory);
|
|
||||||
// sftp.cd(directory);
|
|
||||||
} catch (SftpException e2) {
|
} catch (SftpException e2) {
|
||||||
map.put("code","1");
|
map.put("code","1");
|
||||||
map.put("msg","ftp创建"+directory+"文件路径失败");
|
map.put("msg","ftp创建"+directory+"文件路径失败");
|
||||||
|
@ -208,10 +214,6 @@ public class SFTPUtil {
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
map.put("code","1");
|
map.put("code","1");
|
||||||
map.put("msg","sftp异常:" + e.getMessage());
|
map.put("msg","sftp异常:" + e.getMessage());
|
||||||
}finally {
|
|
||||||
if(sftp!=null){
|
|
||||||
disConnect(sftp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
@ -223,15 +225,13 @@ public class SFTPUtil {
|
||||||
* @param downloadFile 下载的文件
|
* @param downloadFile 下载的文件
|
||||||
* @param saveFile 存在本地的路径
|
* @param saveFile 存在本地的路径
|
||||||
*/
|
*/
|
||||||
public static Map<String,Object> download(ChannelSftp sftp,SftpConfig sftpConfig, String directory, String downloadFile, String saveFile) {
|
public static Map<String,String> download(SftpConfig sftpConfig, String directory, String downloadFile, String saveFile) {
|
||||||
Map<String,Object> map = new HashMap<String,Object>();
|
Map<String,String> map = new HashMap<String,String>();
|
||||||
map.put("code","0");
|
map.put("code","0");
|
||||||
map.put("msg","删除成功");
|
map.put("msg","删除成功");
|
||||||
// ChannelSftp sftp = null;
|
|
||||||
try{
|
try{
|
||||||
if(sftp == null){
|
if(sftp == null){
|
||||||
sftp = connect(sftpConfig);
|
getChannelSftp(sftpConfig);
|
||||||
map.put("sftp",sftp);
|
|
||||||
}
|
}
|
||||||
OutputStream output = null;
|
OutputStream output = null;
|
||||||
try {
|
try {
|
||||||
|
@ -243,14 +243,14 @@ public class SFTPUtil {
|
||||||
if (logger.isInfoEnabled()) {
|
if (logger.isInfoEnabled()) {
|
||||||
logger.info("开始获取远程文件:[{}]---->[{}]", new Object[]{directory, saveFile});
|
logger.info("开始获取远程文件:[{}]---->[{}]", new Object[]{directory, saveFile});
|
||||||
}
|
}
|
||||||
sftp.cd(directory);
|
// sftp.cd(directory);
|
||||||
if (logger.isInfoEnabled()) {
|
if (logger.isInfoEnabled()) {
|
||||||
logger.info("打开远程文件:[{}]", new Object[]{directory});
|
logger.info("打开远程文件:[{}]", new Object[]{directory});
|
||||||
}
|
}
|
||||||
String newName = CommonUtils.getFileName(downloadFile);
|
String newName = CommonUtils.getFileName(downloadFile);
|
||||||
String newDownloadFile = saveFile.concat(File.separator).concat(newName);
|
String newDownloadFile = saveFile.concat(File.separator).concat(newName);
|
||||||
output = new FileOutputStream(new File(newDownloadFile));
|
output = new FileOutputStream(new File(newDownloadFile));
|
||||||
sftp.get(downloadFile, output);
|
sftp.get(directory, output);
|
||||||
if (logger.isInfoEnabled()) {
|
if (logger.isInfoEnabled()) {
|
||||||
logger.info("文件下载成功");
|
logger.info("文件下载成功");
|
||||||
}
|
}
|
||||||
|
@ -266,10 +266,6 @@ public class SFTPUtil {
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
map.put("code","1");
|
map.put("code","1");
|
||||||
map.put("msg","sftp异常:" + e.getMessage());
|
map.put("msg","sftp异常:" + e.getMessage());
|
||||||
}finally {
|
|
||||||
// if(sftp!=null){
|
|
||||||
// disConnect(sftp);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
@ -284,14 +280,15 @@ public class SFTPUtil {
|
||||||
String[] df = getDirectoryAndFileName(downloadFilePath);
|
String[] df = getDirectoryAndFileName(downloadFilePath);
|
||||||
String directory = df[0];
|
String directory = df[0];
|
||||||
String downloadFile = df[1];
|
String downloadFile = df[1];
|
||||||
ChannelSftp sftp = null;
|
|
||||||
try{
|
try{
|
||||||
sftp = connect(sftpConfig);
|
if(sftp == null){
|
||||||
|
getChannelSftp(sftpConfig);
|
||||||
|
}
|
||||||
InputStream inputStream = null;
|
InputStream inputStream = null;
|
||||||
ServletOutputStream outputStream=null;
|
ServletOutputStream outputStream=null;
|
||||||
try {
|
try {
|
||||||
sftp.cd(directory);
|
// sftp.cd(directory);
|
||||||
inputStream = sftp.get(downloadFile);
|
inputStream = sftp.get(downloadFilePath);
|
||||||
byte[] buf = new byte[1024 * 10];
|
byte[] buf = new byte[1024 * 10];
|
||||||
outputStream = response.getOutputStream();
|
outputStream = response.getOutputStream();
|
||||||
response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(downloadFile, "UTF-8"));
|
response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(downloadFile, "UTF-8"));
|
||||||
|
@ -300,76 +297,18 @@ public class SFTPUtil {
|
||||||
outputStream.write(buf, 0, readLength);
|
outputStream.write(buf, 0, readLength);
|
||||||
}
|
}
|
||||||
outputStream.flush();
|
outputStream.flush();
|
||||||
} catch (SftpException e1) {
|
} catch (Exception e1) {
|
||||||
e1.printStackTrace();
|
// e1.printStackTrace();
|
||||||
throw new Exception(StringUtils.format("sftp exception,sftp exception。 ", e1.getMessage()));
|
// throw new Exception(StringUtils.format("sftp exception,sftp exception。 ", e1.getMessage()));
|
||||||
} catch (IOException e2) {
|
} finally {
|
||||||
// e2.printStackTrace();
|
closeStream(inputStream,outputStream);
|
||||||
// throw new Exception(StringUtils.format("io exception,io exception 。 ", e2.getMessage()));
|
|
||||||
}finally {
|
|
||||||
closeStream(null,outputStream);
|
|
||||||
try {
|
|
||||||
if(inputStream!=null) {
|
|
||||||
inputStream.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e3) {
|
|
||||||
e3.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw new Exception(StringUtils.format("sftp exception,sftp exception。 ", e.getMessage()));
|
throw new Exception(StringUtils.format("sftp exception,sftp exception。 ", e.getMessage()));
|
||||||
}finally {
|
|
||||||
if(sftp!=null){
|
|
||||||
disConnect(sftp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * 上传文件
|
|
||||||
// * @param oldpath 原文件路径(文件路径+名称)
|
|
||||||
// * @param directory 目的文件路径
|
|
||||||
// * @param newname 目的文件名称
|
|
||||||
// * @param
|
|
||||||
// */
|
|
||||||
// public static Map<String,String> rename(SftpConfig sftpConfig, String oldpath, String directory, String newname) {
|
|
||||||
// Map<String,String> map = new HashMap<String,String>();
|
|
||||||
// map.put("code","0");
|
|
||||||
// map.put("msg","上传成功");
|
|
||||||
// ChannelSftp sftp = null;
|
|
||||||
// try{
|
|
||||||
// sftp = connect(sftpConfig);
|
|
||||||
// try {
|
|
||||||
// directory = getDirectory(sftpConfig.getUploadpath(),directory);
|
|
||||||
// sftp.cd(directory);
|
|
||||||
// } catch (SftpException e1) {
|
|
||||||
// try {
|
|
||||||
// mkdirs(directory,sftp);
|
|
||||||
// } catch (SftpException e2) {
|
|
||||||
// map.put("code","1");
|
|
||||||
// map.put("msg","ftp创建"+directory+"文件路径失败");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// try {
|
|
||||||
// String newpath = directory.concat(newname);
|
|
||||||
// sftp.rename(oldpath,newpath);
|
|
||||||
// } catch (SftpException e1) {
|
|
||||||
// map.put("code","1");
|
|
||||||
// map.put("msg",e1.getMessage());
|
|
||||||
//// throw new RuntimeException("ftp创建文件路径失败" + directory);
|
|
||||||
// }
|
|
||||||
// }catch (Exception e) {
|
|
||||||
// map.put("code","1");
|
|
||||||
// map.put("msg","sftp异常:" + e.getMessage());
|
|
||||||
// }finally {
|
|
||||||
// if(sftp!=null){
|
|
||||||
// disConnect(sftp);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return map;
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 移动文件
|
* 移动文件
|
||||||
* @param oldpath 原文件路径(文件路径+名称)
|
* @param oldpath 原文件路径(文件路径+名称)
|
||||||
|
@ -377,19 +316,30 @@ public class SFTPUtil {
|
||||||
* @param newname 目的文件名称
|
* @param newname 目的文件名称
|
||||||
* @param
|
* @param
|
||||||
*/
|
*/
|
||||||
public static Map<String,Object> moveFile(SftpConfig sftpConfig, String oldpath, String directory, String newname) {
|
public static Map<String,String> moveFile(SftpConfig sftpConfig, String oldpath, String directory, String newname) {
|
||||||
Map<String,Object> map = new HashMap<String,Object>();
|
Map<String,String> map = new HashMap<String,String>();
|
||||||
map.put("code","0");
|
map.put("code","0");
|
||||||
map.put("msg","上传成功");
|
map.put("msg","上传成功");
|
||||||
ChannelSftp sftp = null;
|
|
||||||
try {
|
try {
|
||||||
sftp = connect(sftpConfig);
|
if(sftp == null){
|
||||||
|
getChannelSftp(sftpConfig);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
sftp.cd(sftpConfig.getFullpath());
|
||||||
|
} catch (SftpException e1) {
|
||||||
|
try {
|
||||||
|
mkdirs(sftpConfig.getFullpath());
|
||||||
|
} catch (SftpException e2) {
|
||||||
|
map.put("code", "1");
|
||||||
|
map.put("msg", "sftp创建" + sftpConfig.getUploadpath() + "文件路径失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
directory = getDirectory(sftpConfig.getUploadpath(), directory);
|
directory = getDirectory(sftpConfig.getUploadpath(), directory);
|
||||||
sftp.cd(directory);
|
sftp.cd(directory);
|
||||||
} catch (SftpException e1) {
|
} catch (SftpException e1) {
|
||||||
try {
|
try {
|
||||||
mkdirs(directory, sftp);
|
mkdirs(directory);
|
||||||
} catch (SftpException e2) {
|
} catch (SftpException e2) {
|
||||||
map.put("code", "1");
|
map.put("code", "1");
|
||||||
map.put("msg", "ftp创建" + directory + "文件路径失败");
|
map.put("msg", "ftp创建" + directory + "文件路径失败");
|
||||||
|
@ -404,8 +354,7 @@ public class SFTPUtil {
|
||||||
String newpath = directory.concat(newname);
|
String newpath = directory.concat(newname);
|
||||||
String newfullpath = sftpConfig.getFullpath().concat(newpath);
|
String newfullpath = sftpConfig.getFullpath().concat(newpath);
|
||||||
String moveCommand = "mv " + oldfullpath + " " + newfullpath; // 移动文件的命令
|
String moveCommand = "mv " + oldfullpath + " " + newfullpath; // 移动文件的命令
|
||||||
Session session = sftp.getSession();
|
channel = sshSession.openChannel("exec");
|
||||||
channel = session.openChannel("exec");
|
|
||||||
((ChannelExec) channel).setCommand(moveCommand);
|
((ChannelExec) channel).setCommand(moveCommand);
|
||||||
channel.setInputStream(null);
|
channel.setInputStream(null);
|
||||||
((ChannelExec) channel).setErrStream(System.err);
|
((ChannelExec) channel).setErrStream(System.err);
|
||||||
|
@ -427,7 +376,7 @@ public class SFTPUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
channel.disconnect();
|
channel.disconnect();
|
||||||
session.disconnect();
|
channel = null;
|
||||||
map.put("data",newpath);
|
map.put("data",newpath);
|
||||||
} catch (Exception e1) {
|
} catch (Exception e1) {
|
||||||
map.put("code","1");
|
map.put("code","1");
|
||||||
|
@ -436,119 +385,46 @@ public class SFTPUtil {
|
||||||
}finally {
|
}finally {
|
||||||
if(channel!=null){
|
if(channel!=null){
|
||||||
channel.disconnect();
|
channel.disconnect();
|
||||||
|
channel = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
map.put("code","1");
|
map.put("code","1");
|
||||||
map.put("msg","sftp异常:" + e.getMessage());
|
map.put("msg","sftp异常:" + e.getMessage());
|
||||||
}finally {
|
|
||||||
if(sftp!=null){
|
|
||||||
disConnect(sftp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<String,Object> moveFiles(SftpConfig sftpConfig, String directory, List<String[]> list) {
|
|
||||||
Map<String,Object> map = new HashMap<String,Object>();
|
|
||||||
map.put("code","0");
|
|
||||||
map.put("msg","上传成功");
|
|
||||||
ChannelSftp sftp = null;
|
|
||||||
try {
|
|
||||||
sftp = connect(sftpConfig);
|
|
||||||
try {
|
|
||||||
directory = getDirectory(sftpConfig.getUploadpath(), directory);
|
|
||||||
sftp.cd(directory);
|
|
||||||
} catch (SftpException e1) {
|
|
||||||
try {
|
|
||||||
mkdirs(directory, sftp);
|
|
||||||
} catch (SftpException e2) {
|
|
||||||
map.put("code", "1");
|
|
||||||
map.put("msg", "ftp创建" + directory + "文件路径失败");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Channel channel = null;
|
|
||||||
try {
|
|
||||||
StringBuffer sb = new StringBuffer();
|
|
||||||
for(int item=0;item<list.size();item++){
|
|
||||||
String oldpath = list.get(item)[0];
|
|
||||||
if(!oldpath.startsWith("/")){
|
|
||||||
oldpath = "/"+oldpath;
|
|
||||||
}
|
|
||||||
String oldfullpath = sftpConfig.getFullpath().concat(oldpath);
|
|
||||||
String newname = list.get(item)[1];
|
|
||||||
String newpath = directory.concat(newname);
|
|
||||||
String newfullpath = sftpConfig.getFullpath().concat(newpath);
|
|
||||||
String moveCommand = "mv " + oldfullpath + " " + newfullpath; // 移动文件的命令
|
|
||||||
Session session = sftp.getSession();
|
|
||||||
channel = session.openChannel("exec");
|
|
||||||
((ChannelExec) channel).setCommand(moveCommand);
|
|
||||||
channel.setInputStream(null);
|
|
||||||
((ChannelExec) channel).setErrStream(System.err);
|
|
||||||
InputStream in = channel.getInputStream();
|
|
||||||
channel.connect();
|
|
||||||
byte[] tmp = new byte[1024];
|
|
||||||
while (true) {
|
|
||||||
while (in.available() > 0) {
|
|
||||||
int i = in.read(tmp, 0, 1024);
|
|
||||||
if (i < 0) break;
|
|
||||||
}
|
|
||||||
if (channel.isClosed()) {
|
|
||||||
System.out.println("exit-status: " + channel.getExitStatus());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Thread.sleep(1000);
|
|
||||||
} catch (Exception ee) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
channel.disconnect();
|
|
||||||
sb.append(newpath);
|
|
||||||
sb.append("|");
|
|
||||||
}
|
|
||||||
String path = sb.toString();
|
|
||||||
path = path.substring(0,path.length()-1);
|
|
||||||
map.put("data",path);
|
|
||||||
} catch (Exception e1) {
|
|
||||||
map.put("code","1");
|
|
||||||
map.put("msg",e1.getMessage());
|
|
||||||
// throw new RuntimeException("ftp创建文件路径失败" + directory);
|
|
||||||
}finally {
|
|
||||||
if(channel!=null){
|
|
||||||
channel.disconnect();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
map.put("code","1");
|
|
||||||
map.put("msg","sftp异常:" + e.getMessage());
|
|
||||||
}finally {
|
|
||||||
if(sftp!=null){
|
|
||||||
disConnect(sftp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String,Object> moveFiles(ChannelSftp sftp,SftpConfig sftpConfig, String directory, List<String[]> list) {
|
public static Map<String,String> moveFiles(SftpConfig sftpConfig, String directory, List<String[]> list) {
|
||||||
Map<String,Object> map = new HashMap<String,Object>();
|
Map<String,String> map = new HashMap<String,String>();
|
||||||
map.put("code","0");
|
map.put("code","0");
|
||||||
map.put("msg","上传成功");
|
map.put("msg","上传成功");
|
||||||
try {
|
try {
|
||||||
if(sftp == null){
|
if(sftp == null){
|
||||||
sftp = connect(sftpConfig);
|
getChannelSftp(sftpConfig);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
sftp.cd(sftpConfig.getFullpath());
|
||||||
|
} catch (SftpException e1) {
|
||||||
|
try {
|
||||||
|
mkdirs(sftpConfig.getFullpath());
|
||||||
|
} catch (SftpException e2) {
|
||||||
|
map.put("code", "1");
|
||||||
|
map.put("msg", "sftp创建" + sftpConfig.getUploadpath() + "文件路径失败");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
directory = getDirectory(sftpConfig.getUploadpath(), directory);
|
directory = getDirectory(sftpConfig.getUploadpath(), directory);
|
||||||
sftp.cd(directory);
|
sftp.cd(directory);
|
||||||
} catch (SftpException e1) {
|
} catch (SftpException e1) {
|
||||||
try {
|
try {
|
||||||
mkdirs(directory, sftp);
|
mkdirs(directory);
|
||||||
} catch (SftpException e2) {
|
} catch (SftpException e2) {
|
||||||
map.put("code", "1");
|
map.put("code", "1");
|
||||||
map.put("msg", "ftp创建" + directory + "文件路径失败");
|
map.put("msg", "sftp创建" + directory + "文件路径失败");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sftp.cd(sftpConfig.getFullpath());
|
||||||
Channel channel = null;
|
Channel channel = null;
|
||||||
try {
|
try {
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
|
@ -560,10 +436,9 @@ public class SFTPUtil {
|
||||||
String oldfullpath = sftpConfig.getFullpath().concat(oldpath);
|
String oldfullpath = sftpConfig.getFullpath().concat(oldpath);
|
||||||
String newname = list.get(item)[1];
|
String newname = list.get(item)[1];
|
||||||
String newpath = directory.concat(newname);
|
String newpath = directory.concat(newname);
|
||||||
String newfullpath = sftpConfig.getFullpath().concat(newpath);
|
String newfullpath = sftpConfig.getFullpath().concat("/").concat(newpath);
|
||||||
String moveCommand = "mv " + oldfullpath + " " + newfullpath; // 移动文件的命令
|
String moveCommand = "mv " + oldfullpath + " " + newfullpath; // 移动文件的命令
|
||||||
Session session = sftp.getSession();
|
channel = sshSession.openChannel("exec");
|
||||||
channel = session.openChannel("exec");
|
|
||||||
((ChannelExec) channel).setCommand(moveCommand);
|
((ChannelExec) channel).setCommand(moveCommand);
|
||||||
channel.setInputStream(null);
|
channel.setInputStream(null);
|
||||||
((ChannelExec) channel).setErrStream(System.err);
|
((ChannelExec) channel).setErrStream(System.err);
|
||||||
|
@ -585,6 +460,7 @@ public class SFTPUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
channel.disconnect();
|
channel.disconnect();
|
||||||
|
channel = null;
|
||||||
sb.append(newpath);
|
sb.append(newpath);
|
||||||
sb.append("|");
|
sb.append("|");
|
||||||
}
|
}
|
||||||
|
@ -598,17 +474,17 @@ public class SFTPUtil {
|
||||||
}finally {
|
}finally {
|
||||||
if(channel!=null){
|
if(channel!=null){
|
||||||
channel.disconnect();
|
channel.disconnect();
|
||||||
|
channel = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
map.put("code","1");
|
map.put("code","1");
|
||||||
map.put("msg","sftp异常:" + e.getMessage());
|
map.put("msg","sftp异常:" + e.getMessage());
|
||||||
}finally {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除文件
|
* 删除文件
|
||||||
* @param directory 要删除文件所在目录
|
* @param directory 要删除文件所在目录
|
||||||
|
@ -618,19 +494,16 @@ public class SFTPUtil {
|
||||||
Map<String,String> map = new HashMap<String,String>();
|
Map<String,String> map = new HashMap<String,String>();
|
||||||
map.put("code","0");
|
map.put("code","0");
|
||||||
map.put("msg","删除成功");
|
map.put("msg","删除成功");
|
||||||
ChannelSftp sftp = null;
|
|
||||||
try{
|
try{
|
||||||
sftp = connect(sftpConfig);
|
if(sftp == null){
|
||||||
|
getChannelSftp(sftpConfig);
|
||||||
|
}
|
||||||
directory = delDiagonalLines(directory);
|
directory = delDiagonalLines(directory);
|
||||||
sftp.cd(directory);
|
sftp.cd(directory);
|
||||||
sftp.rm(deleteFile);
|
sftp.rm(deleteFile);
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
map.put("code","1");
|
map.put("code","1");
|
||||||
map.put("msg","sftp异常:" + e.getMessage());
|
map.put("msg","sftp异常:" + e.getMessage());
|
||||||
}finally {
|
|
||||||
if(sftp!=null){
|
|
||||||
disConnect(sftp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
@ -654,10 +527,23 @@ public class SFTPUtil {
|
||||||
/**
|
/**
|
||||||
* 断掉连接
|
* 断掉连接
|
||||||
*/
|
*/
|
||||||
public static void disConnect(ChannelSftp sftp) {
|
public static void disChannel() {
|
||||||
try {
|
try {
|
||||||
sftp.disconnect();
|
if(sftp!=null){
|
||||||
sftp.getSession().disconnect();
|
sftp.disconnect();
|
||||||
|
sftp=null;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void disSession() {
|
||||||
|
try {
|
||||||
|
if(sshSession!=null) {
|
||||||
|
sshSession.disconnect();
|
||||||
|
sshSession=null;
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -673,6 +559,7 @@ public class SFTPUtil {
|
||||||
outputStream.close();
|
outputStream.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
}finally {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(inputStream != null){
|
if(inputStream != null){
|
||||||
|
@ -680,6 +567,7 @@ public class SFTPUtil {
|
||||||
inputStream.close();
|
inputStream.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
}finally {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.jeecg.modules.kc.zyJxdg.controller;
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.incrementer.DefaultIdentifierGenerator;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
@ -312,6 +313,11 @@ public class ZyJxdgController extends JeecgController<ZyJxdg, IZyJxdgService> {
|
||||||
@ApiOperation(value="教学大纲-上传附件", notes="教学大纲-上传附件")
|
@ApiOperation(value="教学大纲-上传附件", notes="教学大纲-上传附件")
|
||||||
@PostMapping(value = "/jxdgScfj")
|
@PostMapping(value = "/jxdgScfj")
|
||||||
public Result<ZyJxdg> jxdgScfj(@RequestBody ZyJxdg zyJxdg) {
|
public Result<ZyJxdg> jxdgScfj(@RequestBody ZyJxdg zyJxdg) {
|
||||||
|
boolean isAdd = false;
|
||||||
|
if(StringUtils.isEmpty(zyJxdg.getId())){
|
||||||
|
isAdd = true;
|
||||||
|
zyJxdg.setId((new DefaultIdentifierGenerator().nextId(new ZyJxdg())).toString());
|
||||||
|
}
|
||||||
if(StringUtils.isNotEmpty(zyJxdg.getFilePath())){
|
if(StringUtils.isNotEmpty(zyJxdg.getFilePath())){
|
||||||
String nameLast = zyJxdg.getFilePath().substring(zyJxdg.getFilePath().lastIndexOf(".")+1);
|
String nameLast = zyJxdg.getFilePath().substring(zyJxdg.getFilePath().lastIndexOf(".")+1);
|
||||||
if(StringUtils.equals("pdf",nameLast)){
|
if(StringUtils.equals("pdf",nameLast)){
|
||||||
|
@ -334,12 +340,11 @@ public class ZyJxdgController extends JeecgController<ZyJxdg, IZyJxdgService> {
|
||||||
zykInfo.setWjlx(WjlxEnum.JXDG.getType());
|
zykInfo.setWjlx(WjlxEnum.JXDG.getType());
|
||||||
zykInfo.setRwbh(zyJxdg.getRwbh());
|
zykInfo.setRwbh(zyJxdg.getRwbh());
|
||||||
zykInfo.setFileName(zyJxdg.getFilePath());
|
zykInfo.setFileName(zyJxdg.getFilePath());
|
||||||
Map<String,Object> map = zykService.saveToZykJxdg(zykInfo);
|
Map<String,String> map = zykService.saveToZykJxdg(zykInfo);
|
||||||
String fileName = map.get("data").toString();
|
String fileName = map.get("data");
|
||||||
String pdfName = map.get("pdfData").toString();
|
String pdfName = map.get("pdfData");
|
||||||
zyJxdg.setFilePath(fileName);
|
zyJxdg.setFilePath(fileName);
|
||||||
zyJxdg.setPdfPath(pdfName);
|
zyJxdg.setPdfPath(pdfName);
|
||||||
|
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
zyJxdg.setPdfPath(null);
|
zyJxdg.setPdfPath(null);
|
||||||
|
@ -363,8 +368,7 @@ public class ZyJxdgController extends JeecgController<ZyJxdg, IZyJxdgService> {
|
||||||
//--------上传ftp工具---------------
|
//--------上传ftp工具---------------
|
||||||
|
|
||||||
|
|
||||||
|
if(isAdd){
|
||||||
if(StringUtils.isEmpty(zyJxdg.getId())){
|
|
||||||
zyJxdgService.save(zyJxdg);
|
zyJxdgService.save(zyJxdg);
|
||||||
}else{
|
}else{
|
||||||
UpdateWrapper<ZyJxdg> updateWrapper = new UpdateWrapper<>();
|
UpdateWrapper<ZyJxdg> updateWrapper = new UpdateWrapper<>();
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
update_time,
|
update_time,
|
||||||
biz_id,
|
biz_id,
|
||||||
biz_table,
|
biz_table,
|
||||||
|
rwbh,
|
||||||
xqxn,
|
xqxn,
|
||||||
kkdw,
|
kkdw,
|
||||||
kcmc,
|
kcmc,
|
||||||
|
@ -52,6 +53,7 @@
|
||||||
update_time,
|
update_time,
|
||||||
biz_id,
|
biz_id,
|
||||||
biz_table,
|
biz_table,
|
||||||
|
rwbh,
|
||||||
xqxn,
|
xqxn,
|
||||||
kkdw,
|
kkdw,
|
||||||
kcmc,
|
kcmc,
|
||||||
|
@ -74,6 +76,7 @@
|
||||||
create_time,
|
create_time,
|
||||||
biz_id,
|
biz_id,
|
||||||
biz_table,
|
biz_table,
|
||||||
|
rwbh,
|
||||||
xqxn,
|
xqxn,
|
||||||
kkdw,
|
kkdw,
|
||||||
kcmc,
|
kcmc,
|
||||||
|
@ -92,6 +95,7 @@
|
||||||
#{createTime},
|
#{createTime},
|
||||||
#{bizId},
|
#{bizId},
|
||||||
#{bizTable},
|
#{bizTable},
|
||||||
|
#{rwbh},
|
||||||
#{xqxn},
|
#{xqxn},
|
||||||
#{kkdw},
|
#{kkdw},
|
||||||
#{kcmc},
|
#{kcmc},
|
||||||
|
@ -129,6 +133,7 @@
|
||||||
update_time,
|
update_time,
|
||||||
biz_id,
|
biz_id,
|
||||||
biz_table,
|
biz_table,
|
||||||
|
rwbh,
|
||||||
xqxn,
|
xqxn,
|
||||||
kkdw,
|
kkdw,
|
||||||
kcmc,
|
kcmc,
|
||||||
|
|
|
@ -31,7 +31,7 @@ public interface IZykService extends IService<ZykInfo> {
|
||||||
* @param filePath
|
* @param filePath
|
||||||
* @return 下载结果
|
* @return 下载结果
|
||||||
*/
|
*/
|
||||||
Map<String,Object> downloadRemoteFile(String filePath);
|
Map<String,String> downloadRemoteFile(String filePath);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 下载远端文件流(含接口)
|
* 下载远端文件流(含接口)
|
||||||
|
@ -44,9 +44,9 @@ public interface IZykService extends IService<ZykInfo> {
|
||||||
* @param zykInfo
|
* @param zykInfo
|
||||||
* @return 上传结果
|
* @return 上传结果
|
||||||
*/
|
*/
|
||||||
Map<String,Object> saveToZyk(ZykInfo zykInfo);
|
Map<String,String> saveToZyk(ZykInfo zykInfo);
|
||||||
Map<String,Object> saveToZykJxdg(ZykInfo zykInfo);
|
Map<String,String> saveToZykJxdg(ZykInfo zykInfo);
|
||||||
Map<String,Object> uploadFileToSftp(Map<String,Object> map,String filePath);
|
Map<String,String> uploadFileToSftp(String filePath);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除资源库(接口)
|
* 删除资源库(接口)
|
||||||
|
|
|
@ -56,16 +56,16 @@ public class ZykServiceImpl extends ServiceImpl<ZykMapper, ZykInfo> implements I
|
||||||
@Override
|
@Override
|
||||||
public String saveInfo(ZykInfo zykInfo){
|
public String saveInfo(ZykInfo zykInfo){
|
||||||
// Map<String,String> map = fileHandleUtil.uploadFile(zykInfo);
|
// Map<String,String> map = fileHandleUtil.uploadFile(zykInfo);
|
||||||
Map<String,Object> map = fileHandleUtil.moveFiles(null,zykInfo);
|
Map<String,String> map = fileHandleUtil.moveFiles(zykInfo);
|
||||||
if(!map.get("code").equals("0")){
|
if(!map.get("code").equals("0")){
|
||||||
return map.get("msg").toString();
|
return map.get("msg").toString();
|
||||||
}
|
}
|
||||||
if(!StringUtils.isEmpty(map.get("data").toString())){
|
if(StringUtils.isNotNull(map.get("data"))){
|
||||||
String fileName = map.get("data").toString();
|
String fileName = map.get("data");
|
||||||
zykInfo.setFileName(fileName);
|
zykInfo.setFileName(fileName);
|
||||||
}
|
}
|
||||||
if(!StringUtils.isEmpty(map.get("pdfData").toString())){
|
if(StringUtils.isNotNull(map.get("pdfData"))){
|
||||||
String pdfName = map.get("pdfData").toString();
|
String pdfName = map.get("pdfData");
|
||||||
zykInfo.setPdfName(pdfName);
|
zykInfo.setPdfName(pdfName);
|
||||||
}
|
}
|
||||||
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||||
|
@ -80,16 +80,16 @@ public class ZykServiceImpl extends ServiceImpl<ZykMapper, ZykInfo> implements I
|
||||||
@Override
|
@Override
|
||||||
public String modifyInfo(ZykInfo zykInfo){
|
public String modifyInfo(ZykInfo zykInfo){
|
||||||
// Map<String,String> map = fileHandleUtil.uploadFile(zykInfo);
|
// Map<String,String> map = fileHandleUtil.uploadFile(zykInfo);
|
||||||
Map<String,Object> map = fileHandleUtil.moveFiles(null,zykInfo);
|
Map<String,String> map = fileHandleUtil.moveFiles(zykInfo);
|
||||||
if(!map.get("code").equals("0")){
|
if(!map.get("code").equals("0")){
|
||||||
return map.get("msg").toString();
|
return map.get("msg");
|
||||||
}
|
}
|
||||||
if(!StringUtils.isEmpty(map.get("data").toString())){
|
if(StringUtils.isNotNull(map.get("data"))){
|
||||||
String fileName = map.get("data").toString();
|
String fileName = map.get("data");
|
||||||
zykInfo.setFileName(fileName);
|
zykInfo.setFileName(fileName);
|
||||||
}
|
}
|
||||||
if(!StringUtils.isEmpty(map.get("pdfData").toString())){
|
if(StringUtils.isNotNull(map.get("pdfData"))){
|
||||||
String pdfName = map.get("pdfData").toString();
|
String pdfName = map.get("pdfData");
|
||||||
zykInfo.setPdfName(pdfName);
|
zykInfo.setPdfName(pdfName);
|
||||||
}
|
}
|
||||||
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||||
|
@ -114,6 +114,7 @@ public class ZykServiceImpl extends ServiceImpl<ZykMapper, ZykInfo> implements I
|
||||||
fileHandleUtil.delete(df[0],df[1]);
|
fileHandleUtil.delete(df[0],df[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fileHandleUtil.disConnect();
|
||||||
zykMapper.deleteById(id);
|
zykMapper.deleteById(id);
|
||||||
return "删除成功!";
|
return "删除成功!";
|
||||||
}
|
}
|
||||||
|
@ -137,6 +138,7 @@ public class ZykServiceImpl extends ServiceImpl<ZykMapper, ZykInfo> implements I
|
||||||
}
|
}
|
||||||
zykMapper.deleteById(id);
|
zykMapper.deleteById(id);
|
||||||
}
|
}
|
||||||
|
fileHandleUtil.disConnect();
|
||||||
return "批量删除成功!";
|
return "批量删除成功!";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,8 +148,8 @@ public class ZykServiceImpl extends ServiceImpl<ZykMapper, ZykInfo> implements I
|
||||||
* @return 下载结果
|
* @return 下载结果
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Map<String,Object> downloadRemoteFile(String filePath){
|
public Map<String,String> downloadRemoteFile(String filePath){
|
||||||
Map<String,Object> map = new HashMap<String,Object>();
|
Map<String,String> map = new HashMap<String,String>();
|
||||||
map.put("code","0");
|
map.put("code","0");
|
||||||
if(filePath == null || filePath.equals("")){
|
if(filePath == null || filePath.equals("")){
|
||||||
map.put("code","1");
|
map.put("code","1");
|
||||||
|
@ -166,12 +168,11 @@ public class ZykServiceImpl extends ServiceImpl<ZykMapper, ZykInfo> implements I
|
||||||
map.put("code","1");
|
map.put("code","1");
|
||||||
map.put("msg","文件不存在!");
|
map.put("msg","文件不存在!");
|
||||||
}
|
}
|
||||||
Map<String,Object> downloadMap = fileHandleUtil.download(null,df[0],df[1]);
|
Map<String,String> downloadMap = fileHandleUtil.download(filePath,df[1]);
|
||||||
if(!downloadMap.get("code").equals("0")){
|
if(!downloadMap.get("code").equals("0")){
|
||||||
return downloadMap;
|
return downloadMap;
|
||||||
}
|
}
|
||||||
map.put("data",downloadMap.get("fileName"));
|
map.put("data",downloadMap.get("fileName"));
|
||||||
map.put("sftp",downloadMap.get("sftp"));
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,11 +188,7 @@ public class ZykServiceImpl extends ServiceImpl<ZykMapper, ZykInfo> implements I
|
||||||
if(filePath.lastIndexOf("/")==-1){
|
if(filePath.lastIndexOf("/")==-1){
|
||||||
throw new RuntimeException("文件路径不存在!");
|
throw new RuntimeException("文件路径不存在!");
|
||||||
}
|
}
|
||||||
String[] df = fileHandleUtil.getDirectoryAndFileName(filePath);
|
fileHandleUtil.downloadRes(filePath,response);
|
||||||
if(StringUtils.isEmpty(df[0])||StringUtils.isEmpty(df[1])){
|
|
||||||
throw new RuntimeException("文件路径不存在!");
|
|
||||||
}
|
|
||||||
fileHandleUtil.downloadRes(df[0],df[1],response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -200,7 +197,7 @@ public class ZykServiceImpl extends ServiceImpl<ZykMapper, ZykInfo> implements I
|
||||||
* @return 上传结果
|
* @return 上传结果
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Map<String,Object> saveToZyk(ZykInfo zykInfo){
|
public Map<String,String> saveToZyk(ZykInfo zykInfo){
|
||||||
KcKechengbiao kcb = new KcKechengbiao();
|
KcKechengbiao kcb = new KcKechengbiao();
|
||||||
kcb.setRwbh(zykInfo.getRwbh());
|
kcb.setRwbh(zykInfo.getRwbh());
|
||||||
kcb = kcKechengbiaoService.getKcbhByRwbh(kcb);
|
kcb = kcKechengbiaoService.getKcbhByRwbh(kcb);
|
||||||
|
@ -209,16 +206,16 @@ public class ZykServiceImpl extends ServiceImpl<ZykMapper, ZykInfo> implements I
|
||||||
zykInfo.setKcmc(kcb.getKcmc());
|
zykInfo.setKcmc(kcb.getKcmc());
|
||||||
zykInfo.setSkjs(kcb.getSkjs());
|
zykInfo.setSkjs(kcb.getSkjs());
|
||||||
// Map<String,Object> map = fileHandleUtil.uploadFile(zykInfo);
|
// Map<String,Object> map = fileHandleUtil.uploadFile(zykInfo);
|
||||||
Map<String,Object> map = fileHandleUtil.moveFiles(null,zykInfo);
|
Map<String,String> map = fileHandleUtil.moveFiles(zykInfo);
|
||||||
if(!map.get("code").equals("0")){
|
if(!map.get("code").equals("0")){
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
if(!StringUtils.isEmpty(map.get("data").toString())){
|
if(StringUtils.isNotNull(map.get("data"))){
|
||||||
String fileName = map.get("data").toString();
|
String fileName = map.get("data");
|
||||||
zykInfo.setFileName(fileName);
|
zykInfo.setFileName(fileName);
|
||||||
}
|
}
|
||||||
if(!StringUtils.isEmpty(map.get("pdfData").toString())){
|
if(StringUtils.isNotNull(map.get("pdfData"))){
|
||||||
String pdfName = map.get("pdfData").toString();
|
String pdfName = map.get("pdfData");
|
||||||
zykInfo.setPdfName(pdfName);
|
zykInfo.setPdfName(pdfName);
|
||||||
}
|
}
|
||||||
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||||
|
@ -236,7 +233,7 @@ public class ZykServiceImpl extends ServiceImpl<ZykMapper, ZykInfo> implements I
|
||||||
* @return 上传结果
|
* @return 上传结果
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Map<String,Object> saveToZykJxdg(ZykInfo zykInfo){
|
public Map<String,String> saveToZykJxdg(ZykInfo zykInfo){
|
||||||
KcKechengbiao kcb = new KcKechengbiao();
|
KcKechengbiao kcb = new KcKechengbiao();
|
||||||
kcb.setRwbh(zykInfo.getRwbh());
|
kcb.setRwbh(zykInfo.getRwbh());
|
||||||
kcb = kcKechengbiaoService.getKcbhByRwbh(kcb);
|
kcb = kcKechengbiaoService.getKcbhByRwbh(kcb);
|
||||||
|
@ -244,32 +241,37 @@ public class ZykServiceImpl extends ServiceImpl<ZykMapper, ZykInfo> implements I
|
||||||
zykInfo.setKkdw(kcb.getKkdw());
|
zykInfo.setKkdw(kcb.getKkdw());
|
||||||
zykInfo.setKcmc(kcb.getKcmc());
|
zykInfo.setKcmc(kcb.getKcmc());
|
||||||
zykInfo.setSkjs(kcb.getSkjs());
|
zykInfo.setSkjs(kcb.getSkjs());
|
||||||
Map<String,Object> downloadMap = downloadRemoteFile(zykInfo.getFileName());
|
Map<String,String> downloadMap = downloadRemoteFile(zykInfo.getFileName());
|
||||||
|
if(!downloadMap.get("code").equals("0")){
|
||||||
|
return downloadMap;
|
||||||
|
}
|
||||||
Global global = SpringContextHolder.getBean(Global.class);
|
Global global = SpringContextHolder.getBean(Global.class);
|
||||||
String dd = DateUtils.formatDate(new Date(),"yyyyMMddHHmmss");
|
String dd = DateUtils.formatDate(new Date(),"yyyyMMddHHmmss");
|
||||||
String namePath = dd + ".pdf";
|
String namePath = dd + ".pdf";
|
||||||
String pdfPath = global.getContractDickPath() + namePath;
|
String pdfPath = global.getContractDickPath() + namePath;
|
||||||
if(!downloadMap.get("code").equals("0")){
|
|
||||||
return downloadMap;
|
PDFUtil.office2PDF(downloadMap.get("data"),pdfPath);
|
||||||
}
|
Map<String,String> uploadMap = uploadFileToSftp("contract/"+namePath);
|
||||||
PDFUtil.office2PDF(downloadMap.get("data").toString(),pdfPath);
|
|
||||||
Map<String,Object> uploadMap = uploadFileToSftp(downloadMap,"contract/"+namePath);
|
|
||||||
if(!uploadMap.get("code").equals("0")){
|
if(!uploadMap.get("code").equals("0")){
|
||||||
return uploadMap;
|
return uploadMap;
|
||||||
}
|
}
|
||||||
zykInfo.setPdfName(uploadMap.get("data").toString());
|
zykInfo.setPdfName(uploadMap.get("data"));
|
||||||
|
|
||||||
Map<String,Object> map = fileHandleUtil.moveFiles(downloadMap,zykInfo);
|
Map<String,String> map = fileHandleUtil.moveFiles(zykInfo);
|
||||||
if(!map.get("code").equals("0")){
|
if(!map.get("code").equals("0")){
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
if(!StringUtils.isEmpty(map.get("data").toString())){
|
if(StringUtils.isNotNull(map.get("data"))){
|
||||||
String fileName = map.get("data").toString();
|
String fileName = map.get("data");
|
||||||
zykInfo.setFileName(fileName);
|
zykInfo.setFileName(fileName);
|
||||||
|
}else{
|
||||||
|
map.put("data","");
|
||||||
}
|
}
|
||||||
if(!StringUtils.isEmpty(map.get("pdfData").toString())){
|
if(StringUtils.isNotNull(map.get("pdfData"))){
|
||||||
String pdfName = map.get("pdfData").toString();
|
String pdfName = map.get("pdfData");
|
||||||
zykInfo.setPdfName(pdfName);
|
zykInfo.setPdfName(pdfName);
|
||||||
|
}else{
|
||||||
|
map.put("pdfData","");
|
||||||
}
|
}
|
||||||
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||||
zykInfo.setCreateBy(user.getUsername());
|
zykInfo.setCreateBy(user.getUsername());
|
||||||
|
@ -286,8 +288,8 @@ public class ZykServiceImpl extends ServiceImpl<ZykMapper, ZykInfo> implements I
|
||||||
* @return 上传结果
|
* @return 上传结果
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Map<String,Object> uploadFileToSftp(Map<String,Object> downloadMap,String filePath){
|
public Map<String,String> uploadFileToSftp(String filePath){
|
||||||
Map<String,Object> map = fileHandleUtil.uploadFileToSftp(downloadMap,filePath);
|
Map<String,String> map = fileHandleUtil.uploadFileToSftp(filePath);
|
||||||
if(!map.get("code").equals("0")){
|
if(!map.get("code").equals("0")){
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,24 +27,24 @@ public class FileHandleUtil {
|
||||||
@Value(value = "${jeecg.path.webapp}")
|
@Value(value = "${jeecg.path.webapp}")
|
||||||
private String downloadpath;
|
private String downloadpath;
|
||||||
|
|
||||||
public Map<String,Object> uploadFile(ZykInfo zykInfo){
|
public Map<String,String> uploadFile(ZykInfo zykInfo){
|
||||||
Map<String,Object> map = new HashMap<String,Object>();
|
Map<String,String> map = new HashMap<String,String>();
|
||||||
map.put("code","0");
|
map.put("code","0");
|
||||||
Map<String,Object> directoryMap = getDirectory(zykInfo);
|
Map<String,String> directoryMap = getDirectory(zykInfo);
|
||||||
if(!directoryMap.get("code").equals("0")){
|
if(!directoryMap.get("code").equals("0")){
|
||||||
return directoryMap;
|
return directoryMap;
|
||||||
}
|
}
|
||||||
//资源库文件路径
|
//资源库文件路径
|
||||||
String directory = directoryMap.get("directory").toString();
|
String directory = directoryMap.get("directory");
|
||||||
|
|
||||||
if(!StringUtils.isEmpty(zykInfo.getFileName())) {
|
if(!StringUtils.isEmpty(zykInfo.getFileName())) {
|
||||||
//源文件路径
|
//源文件路径
|
||||||
Map<String,Object> fileNameMap = getFileName(zykInfo);
|
Map<String,String> fileNameMap = getFileName(zykInfo);
|
||||||
if(!fileNameMap.get("code").equals("0")){
|
if(!fileNameMap.get("code").equals("0")){
|
||||||
return fileNameMap;
|
return fileNameMap;
|
||||||
}
|
}
|
||||||
//上传文件
|
//上传文件
|
||||||
Map<String,Object> uploadMap = SFTPUtil.upload(null,sftpConfig,true,directory,fileNameMap.get("filePath").toString(),fileNameMap.get("fileName").toString());
|
Map<String,String> uploadMap = SFTPUtil.upload(sftpConfig,true,directory,fileNameMap.get("filePath").toString(),fileNameMap.get("fileName").toString());
|
||||||
if(!uploadMap.get("code").equals("0")){
|
if(!uploadMap.get("code").equals("0")){
|
||||||
return uploadMap;
|
return uploadMap;
|
||||||
}
|
}
|
||||||
|
@ -53,36 +53,40 @@ public class FileHandleUtil {
|
||||||
|
|
||||||
if(!StringUtils.isEmpty(zykInfo.getPdfName())) {
|
if(!StringUtils.isEmpty(zykInfo.getPdfName())) {
|
||||||
//源文件路径
|
//源文件路径
|
||||||
Map<String,Object> fileNameMap = getPdfName(zykInfo);
|
Map<String,String> fileNameMap = getPdfName(zykInfo);
|
||||||
if(!fileNameMap.get("code").equals("0")){
|
if(!fileNameMap.get("code").equals("0")){
|
||||||
return fileNameMap;
|
return fileNameMap;
|
||||||
}
|
}
|
||||||
//上传文件
|
//上传文件
|
||||||
Map<String,Object> uploadMap = SFTPUtil.upload(null,sftpConfig,true,directory,fileNameMap.get("filePath").toString(),fileNameMap.get("pdfName").toString());
|
Map<String,String> uploadMap = SFTPUtil.upload(sftpConfig,true,directory,fileNameMap.get("filePath").toString(),fileNameMap.get("pdfName").toString());
|
||||||
if(!uploadMap.get("code").equals("0")){
|
if(!uploadMap.get("code").equals("0")){
|
||||||
return uploadMap;
|
return uploadMap;
|
||||||
}
|
}
|
||||||
map.put("pdfData",uploadMap.get("data"));
|
map.put("pdfData",uploadMap.get("data"));
|
||||||
}
|
}
|
||||||
|
SFTPUtil.disChannel();
|
||||||
|
SFTPUtil.disSession();
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String,Object> uploadFileToSftp(Map<String,Object> sftpMap, String filePath){
|
public Map<String,String> uploadFileToSftp(String filePath){
|
||||||
Map<String,Object> map = new HashMap<String,Object>();
|
Map<String,String> map = new HashMap<String,String>();
|
||||||
map.put("code","0");
|
map.put("code","0");
|
||||||
if(!StringUtils.isEmpty(filePath)) {
|
if(!StringUtils.isEmpty(filePath)) {
|
||||||
//源文件路径
|
//源文件路径
|
||||||
Map<String,Object> fileNameMap = getFileName(filePath);
|
Map<String,String> fileNameMap = getFileName(filePath);
|
||||||
if(!fileNameMap.get("code").equals("0")){
|
if(!fileNameMap.get("code").equals("0")){
|
||||||
return fileNameMap;
|
return fileNameMap;
|
||||||
}
|
}
|
||||||
//上传文件
|
//上传文件
|
||||||
Map<String,Object> uploadMap = SFTPUtil.upload((ChannelSftp)sftpMap.get("sftp"),sftpConfig,false,"temp/",fileNameMap.get("filePath").toString(),fileNameMap.get("fileName").toString());
|
Map<String,String> uploadMap = SFTPUtil.upload(sftpConfig,false,"temp/",fileNameMap.get("filePath").toString(),fileNameMap.get("fileName").toString());
|
||||||
if(!uploadMap.get("code").equals("0")){
|
if(!uploadMap.get("code").equals("0")){
|
||||||
return uploadMap;
|
return uploadMap;
|
||||||
}
|
}
|
||||||
map.put("data",uploadMap.get("data"));
|
map.put("data",uploadMap.get("data"));
|
||||||
}
|
}
|
||||||
|
SFTPUtil.disChannel();
|
||||||
|
SFTPUtil.disSession();
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,28 +100,33 @@ public class FileHandleUtil {
|
||||||
return ss;
|
return ss;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String,Object> download(ChannelSftp sftp, String directory, String downloadFile){
|
public Map<String,String> download(String directory, String downloadFile){
|
||||||
return SFTPUtil.download(sftp,sftpConfig,directory,downloadFile,getDownloadPath("temp"));
|
Map<String,String> map = SFTPUtil.download(sftpConfig,directory,downloadFile,getDownloadPath("temp"));
|
||||||
|
// SFTPUtil.disChannel();
|
||||||
|
// SFTPUtil.disSession();
|
||||||
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void downloadRes(String directory, String downloadFile,HttpServletResponse response) throws Exception{
|
public void downloadRes(String downloadFile,HttpServletResponse response) throws Exception{
|
||||||
SFTPUtil.writeFileToRes(sftpConfig,downloadFile,response);
|
SFTPUtil.writeFileToRes(sftpConfig,downloadFile,response);
|
||||||
|
SFTPUtil.disChannel();
|
||||||
|
SFTPUtil.disSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String,Object> moveFile(ZykInfo zykInfo){
|
public Map<String,String> moveFile(ZykInfo zykInfo){
|
||||||
Map<String,Object> map = new HashMap<String,Object>();
|
Map<String,String> map = new HashMap<String,String>();
|
||||||
map.put("code","0");
|
map.put("code","0");
|
||||||
Map<String,Object> directoryMap = getDirectory(zykInfo);
|
Map<String,String> directoryMap = getDirectory(zykInfo);
|
||||||
if(!directoryMap.get("code").equals("0")){
|
if(!directoryMap.get("code").equals("0")){
|
||||||
return directoryMap;
|
return directoryMap;
|
||||||
}
|
}
|
||||||
//资源库文件路径
|
//资源库文件路径
|
||||||
String directory = directoryMap.get("directory").toString();
|
String directory = directoryMap.get("directory");
|
||||||
|
|
||||||
if(!StringUtils.isEmpty(zykInfo.getFileName())) {
|
if(!StringUtils.isEmpty(zykInfo.getFileName())) {
|
||||||
//源文件路径
|
//源文件路径
|
||||||
String newname = getName(zykInfo,false);
|
String newname = getName(zykInfo,false);
|
||||||
Map<String,Object> uploadMap = SFTPUtil.moveFile(sftpConfig,zykInfo.getFileName(),directory,newname);
|
Map<String,String> uploadMap = SFTPUtil.moveFile(sftpConfig,zykInfo.getFileName(),directory,newname);
|
||||||
if(!uploadMap.get("code").equals("0")){
|
if(!uploadMap.get("code").equals("0")){
|
||||||
return uploadMap;
|
return uploadMap;
|
||||||
}
|
}
|
||||||
|
@ -126,33 +135,30 @@ public class FileHandleUtil {
|
||||||
|
|
||||||
if(!StringUtils.isEmpty(zykInfo.getPdfName())) {
|
if(!StringUtils.isEmpty(zykInfo.getPdfName())) {
|
||||||
String newname = getName(zykInfo,true);
|
String newname = getName(zykInfo,true);
|
||||||
Map<String,Object> uploadMap = SFTPUtil.moveFile(sftpConfig,zykInfo.getFileName(),directory,newname);
|
Map<String,String> uploadMap = SFTPUtil.moveFile(sftpConfig,zykInfo.getFileName(),directory,newname);
|
||||||
if(!uploadMap.get("code").equals("0")){
|
if(!uploadMap.get("code").equals("0")){
|
||||||
return uploadMap;
|
return uploadMap;
|
||||||
}
|
}
|
||||||
map.put("pdfData",uploadMap.get("data"));
|
map.put("pdfData",uploadMap.get("data"));
|
||||||
}
|
}
|
||||||
|
SFTPUtil.disChannel();
|
||||||
|
SFTPUtil.disSession();
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String,Object> moveFiles(Map<String,Object> sftpMap, ZykInfo zykInfo){
|
public Map<String,String> moveFiles(ZykInfo zykInfo){
|
||||||
Map<String,Object> map = new HashMap<String,Object>();
|
Map<String,String> map = new HashMap<String,String>();
|
||||||
map.put("code","0");
|
map.put("code","0");
|
||||||
Map<String,Object> directoryMap = getDirectory(zykInfo);
|
Map<String,String> directoryMap = getDirectory(zykInfo);
|
||||||
if(!directoryMap.get("code").equals("0")){
|
if(!directoryMap.get("code").equals("0")){
|
||||||
return directoryMap;
|
return directoryMap;
|
||||||
}
|
}
|
||||||
//资源库文件路径
|
//资源库文件路径
|
||||||
String directory = directoryMap.get("directory").toString();
|
String directory = directoryMap.get("directory");
|
||||||
|
|
||||||
if(!StringUtils.isEmpty(zykInfo.getFileName())) {
|
if(!StringUtils.isEmpty(zykInfo.getFileName())) {
|
||||||
List<String[]> list = getPathsAndNames(zykInfo,false);
|
List<String[]> list = getPathsAndNames(zykInfo,false);
|
||||||
Map<String,Object> uploadMap = null;
|
Map<String,String> uploadMap = SFTPUtil.moveFiles(sftpConfig,directory,list);
|
||||||
if(sftpMap!=null){
|
|
||||||
uploadMap = SFTPUtil.moveFiles((ChannelSftp)sftpMap.get("sftp"),sftpConfig,directory,list);
|
|
||||||
}else{
|
|
||||||
uploadMap = SFTPUtil.moveFiles(sftpConfig,directory,list);
|
|
||||||
}
|
|
||||||
if(!uploadMap.get("code").equals("0")){
|
if(!uploadMap.get("code").equals("0")){
|
||||||
return uploadMap;
|
return uploadMap;
|
||||||
}
|
}
|
||||||
|
@ -160,20 +166,14 @@ public class FileHandleUtil {
|
||||||
}
|
}
|
||||||
if(!StringUtils.isEmpty(zykInfo.getPdfName())) {
|
if(!StringUtils.isEmpty(zykInfo.getPdfName())) {
|
||||||
List<String[]> list = getPathsAndNames(zykInfo,true);
|
List<String[]> list = getPathsAndNames(zykInfo,true);
|
||||||
Map<String,Object> uploadMap = null;
|
Map<String,String> uploadMap = SFTPUtil.moveFiles(sftpConfig,directory,list);
|
||||||
if(sftpMap!=null){
|
|
||||||
uploadMap = SFTPUtil.moveFiles((ChannelSftp)sftpMap.get("sftp"),sftpConfig,directory,list);
|
|
||||||
}else{
|
|
||||||
uploadMap = SFTPUtil.moveFiles(sftpConfig,directory,list);
|
|
||||||
}
|
|
||||||
if(!uploadMap.get("code").equals("0")){
|
if(!uploadMap.get("code").equals("0")){
|
||||||
return uploadMap;
|
return uploadMap;
|
||||||
}
|
}
|
||||||
map.put("pdfData",uploadMap.get("data"));
|
map.put("pdfData",uploadMap.get("data"));
|
||||||
}
|
}
|
||||||
if(sftpMap!=null){
|
SFTPUtil.disChannel();
|
||||||
SFTPUtil.disConnect((ChannelSftp)sftpMap.get("sftp"));
|
SFTPUtil.disSession();
|
||||||
}
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,13 +181,18 @@ public class FileHandleUtil {
|
||||||
SFTPUtil.delete(sftpConfig,directory,downloadFile);
|
SFTPUtil.delete(sftpConfig,directory,downloadFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void disConnect(){
|
||||||
|
SFTPUtil.disChannel();
|
||||||
|
SFTPUtil.disSession();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 资源库文件路径
|
* 资源库文件路径
|
||||||
* @param zykInfo
|
* @param zykInfo
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private Map<String,Object> getDirectory(ZykInfo zykInfo){
|
private Map<String,String> getDirectory(ZykInfo zykInfo){
|
||||||
Map<String,Object> map = new HashMap<String,Object>();
|
Map<String,String> map = new HashMap<String,String>();
|
||||||
map.put("code","0");
|
map.put("code","0");
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
if(StringUtils.isEmpty(zykInfo.getXqxn())){
|
if(StringUtils.isEmpty(zykInfo.getXqxn())){
|
||||||
|
@ -234,8 +239,8 @@ public class FileHandleUtil {
|
||||||
* @param zykInfo
|
* @param zykInfo
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private Map<String,Object> getFileName(ZykInfo zykInfo){
|
private Map<String,String> getFileName(ZykInfo zykInfo){
|
||||||
Map<String,Object> map = new HashMap<String,Object>();
|
Map<String,String> map = new HashMap<String,String>();
|
||||||
map.put("code","0");
|
map.put("code","0");
|
||||||
String uploadFileName = getRealFileFullPath(zykInfo.getFileName());
|
String uploadFileName = getRealFileFullPath(zykInfo.getFileName());
|
||||||
if(StringUtils.isEmpty(uploadFileName)){
|
if(StringUtils.isEmpty(uploadFileName)){
|
||||||
|
@ -290,8 +295,8 @@ public class FileHandleUtil {
|
||||||
* @param fileNamePath
|
* @param fileNamePath
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private Map<String,Object> getFileName(String fileNamePath){
|
private Map<String,String> getFileName(String fileNamePath){
|
||||||
Map<String,Object> map = new HashMap<String,Object>();
|
Map<String,String> map = new HashMap<String,String>();
|
||||||
map.put("code","0");
|
map.put("code","0");
|
||||||
String uploadFileName = getRealFileFullPath(fileNamePath);
|
String uploadFileName = getRealFileFullPath(fileNamePath);
|
||||||
if(StringUtils.isEmpty(uploadFileName)){
|
if(StringUtils.isEmpty(uploadFileName)){
|
||||||
|
@ -389,8 +394,8 @@ public class FileHandleUtil {
|
||||||
* @param zykInfo
|
* @param zykInfo
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private Map<String,Object> getPdfName(ZykInfo zykInfo){
|
private Map<String,String> getPdfName(ZykInfo zykInfo){
|
||||||
Map<String,Object> map = new HashMap<String,Object>();
|
Map<String,String> map = new HashMap<String,String>();
|
||||||
map.put("code","0");
|
map.put("code","0");
|
||||||
String uploadFileName = getRealFileFullPath(zykInfo.getPdfName());
|
String uploadFileName = getRealFileFullPath(zykInfo.getPdfName());
|
||||||
if(StringUtils.isEmpty(uploadFileName)){
|
if(StringUtils.isEmpty(uploadFileName)){
|
||||||
|
|
|
@ -215,11 +215,16 @@ public class CommonController {
|
||||||
private String uploadSftp(MultipartFile mf,String bizPath){
|
private String uploadSftp(MultipartFile mf,String bizPath){
|
||||||
try {
|
try {
|
||||||
Map<String,String> uploadMap = SFTPUtil.upload(sftpConfig,mf,bizPath);
|
Map<String,String> uploadMap = SFTPUtil.upload(sftpConfig,mf,bizPath);
|
||||||
|
SFTPUtil.disChannel();
|
||||||
|
SFTPUtil.disSession();
|
||||||
if(uploadMap.get("code").equals("0")){
|
if(uploadMap.get("code").equals("0")){
|
||||||
return uploadMap.get("data");
|
return uploadMap.get("data");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
|
}finally {
|
||||||
|
SFTPUtil.disChannel();
|
||||||
|
SFTPUtil.disSession();
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -463,7 +468,14 @@ public class CommonController {
|
||||||
imgPath = imgPath.substring(0, imgPath.length() - 1);
|
imgPath = imgPath.substring(0, imgPath.length() - 1);
|
||||||
}
|
}
|
||||||
if(CommonConstant.UPLOAD_TYPE_SFTP.equals(uploadType)) {
|
if(CommonConstant.UPLOAD_TYPE_SFTP.equals(uploadType)) {
|
||||||
SFTPUtil.writeFileToRes(sftpConfig,imgPath,response);
|
try{
|
||||||
|
SFTPUtil.writeFileToRes(sftpConfig,imgPath,response);
|
||||||
|
}catch (Exception e){
|
||||||
|
// e.printStackTrace();
|
||||||
|
}finally {
|
||||||
|
SFTPUtil.disChannel();
|
||||||
|
SFTPUtil.disSession();
|
||||||
|
}
|
||||||
}else {
|
}else {
|
||||||
String filePath = uploadpath + File.separator + imgPath;
|
String filePath = uploadpath + File.separator + imgPath;
|
||||||
File file = new File(filePath);
|
File file = new File(filePath);
|
||||||
|
|
Loading…
Reference in New Issue