|
|
|
@ -13,7 +13,6 @@ import com.jcraft.jsch.Channel;
|
|
|
|
|
import com.jcraft.jsch.ChannelSftp;
|
|
|
|
|
import com.jcraft.jsch.JSch;
|
|
|
|
|
import com.jcraft.jsch.Session;
|
|
|
|
|
import com.sun.deploy.net.URLEncoder;
|
|
|
|
|
import org.apache.commons.net.ftp.FTPClient;
|
|
|
|
|
import org.apache.commons.net.ftp.FTPFile;
|
|
|
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
|
@ -49,6 +48,9 @@ public class FileController {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
public DrawingFtpClient ftpClient;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private DrawingFtpClient drawingFtpClient;
|
|
|
|
|
@Autowired
|
|
|
|
|
public WorkmanshipCardFtpClient workmanshipCardFtpClient;
|
|
|
|
|
|
|
|
|
@ -127,6 +129,7 @@ public class FileController {
|
|
|
|
|
String path = request.getParameter("Path");
|
|
|
|
|
String type = request.getParameter("Type");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
//服务器发布
|
|
|
|
|
//String coderPath = new String(path.getBytes("ISO8859_1"));
|
|
|
|
@ -138,9 +141,11 @@ public class FileController {
|
|
|
|
|
// }
|
|
|
|
|
if (null == in) {
|
|
|
|
|
if (type.equals("DRAWING")){
|
|
|
|
|
jSchClient = new JSchClient(drawingFtpClient.getAddress(), drawingFtpClient.getUserName(),
|
|
|
|
|
drawingFtpClient.getPassword(), drawingFtpClient.getPort());
|
|
|
|
|
jSchClient.connectSFTP();
|
|
|
|
|
in = jSchClient.getSFTP(path);
|
|
|
|
|
//in = fileService.getSFTP(path);
|
|
|
|
|
in = jSchClient.getSFTP(path);
|
|
|
|
|
// in = fileService.getSFTP(path);
|
|
|
|
|
}else {
|
|
|
|
|
in = workmanshipCardFtpClient.getFtp(new String(path.getBytes("GBK"), FTPClient.DEFAULT_CONTROL_ENCODING));
|
|
|
|
|
}
|
|
|
|
@ -179,7 +184,6 @@ public class FileController {
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return R.failed("获取文件失败:文件路径为" + path + ":" + e.getMessage());
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (null != out) {
|
|
|
|
|
out.close();
|
|
|
|
@ -190,10 +194,10 @@ public class FileController {
|
|
|
|
|
if (null != outStream){
|
|
|
|
|
outStream.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (jSchClient != null ){
|
|
|
|
|
jSchClient.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (Exception e1) {
|
|
|
|
|
return R.failed("获取文件失败:关闭文件流处理异常" + e1.getMessage());
|
|
|
|
|
}
|
|
|
|
@ -206,51 +210,51 @@ public class FileController {
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@ResponseBody
|
|
|
|
|
@RequestMapping(method = RequestMethod.GET, value = "/LabelPrintPdf/{fileName}")
|
|
|
|
|
public R getLabelPrintPdf(HttpServletRequest request, HttpServletResponse response, @PathVariable("fileName") String fileName) {
|
|
|
|
|
InputStream in = null;
|
|
|
|
|
OutputStream out = null;
|
|
|
|
|
String path = request.getParameter("Path").replace('-', '/');
|
|
|
|
|
;
|
|
|
|
|
try {
|
|
|
|
|
//服务器发布
|
|
|
|
|
in = ftpClient.getFtp(path);
|
|
|
|
|
if (null == in) {
|
|
|
|
|
in = ftpClient.getFtp(new String(path.getBytes("GBK"), FTPClient.DEFAULT_CONTROL_ENCODING));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (null == in) {
|
|
|
|
|
throw new BaseException("获取FTP文件路径为:【" + path + "】的文件流失败!");
|
|
|
|
|
}
|
|
|
|
|
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
|
|
|
|
int nRead;
|
|
|
|
|
byte[] data = new byte[16384];
|
|
|
|
|
while ((nRead = in.read(data, 0, data.length)) != -1) {
|
|
|
|
|
buffer.write(data, 0, nRead);
|
|
|
|
|
}
|
|
|
|
|
byte[] data2 = buffer.toByteArray();
|
|
|
|
|
out = response.getOutputStream();
|
|
|
|
|
out.write(data2);
|
|
|
|
|
out.flush();
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return R.failed("下载文件失败:文件路径为" + path + ":" + e.getMessage());
|
|
|
|
|
} finally {
|
|
|
|
|
try {
|
|
|
|
|
if (null != out) {
|
|
|
|
|
out.close();
|
|
|
|
|
}
|
|
|
|
|
if (null != in) {
|
|
|
|
|
in.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (Exception e1) {
|
|
|
|
|
return R.failed("下载文件失败:关闭文件流处理异常" + e1.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return R.ok(null, "下载文件成功!");
|
|
|
|
|
}
|
|
|
|
|
// @ResponseBody
|
|
|
|
|
// @RequestMapping(method = RequestMethod.GET, value = "/LabelPrintPdf/{fileName}")
|
|
|
|
|
// public R getLabelPrintPdf(HttpServletRequest request, HttpServletResponse response, @PathVariable("fileName") String fileName) {
|
|
|
|
|
// InputStream in = null;
|
|
|
|
|
// OutputStream out = null;
|
|
|
|
|
// String path = request.getParameter("Path").replace('-', '/');
|
|
|
|
|
// ;
|
|
|
|
|
// try {
|
|
|
|
|
// //服务器发布
|
|
|
|
|
// in = ftpClient.getFtp(path);
|
|
|
|
|
// if (null == in) {
|
|
|
|
|
// in = ftpClient.getFtp(new String(path.getBytes("GBK"), FTPClient.DEFAULT_CONTROL_ENCODING));
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// if (null == in) {
|
|
|
|
|
// throw new BaseException("获取FTP文件路径为:【" + path + "】的文件流失败!");
|
|
|
|
|
// }
|
|
|
|
|
// ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
|
|
|
|
// int nRead;
|
|
|
|
|
// byte[] data = new byte[16384];
|
|
|
|
|
// while ((nRead = in.read(data, 0, data.length)) != -1) {
|
|
|
|
|
// buffer.write(data, 0, nRead);
|
|
|
|
|
// }
|
|
|
|
|
// byte[] data2 = buffer.toByteArray();
|
|
|
|
|
// out = response.getOutputStream();
|
|
|
|
|
// out.write(data2);
|
|
|
|
|
// out.flush();
|
|
|
|
|
//
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// return R.failed("下载文件失败:文件路径为" + path + ":" + e.getMessage());
|
|
|
|
|
// } finally {
|
|
|
|
|
// try {
|
|
|
|
|
// if (null != out) {
|
|
|
|
|
// out.close();
|
|
|
|
|
// }
|
|
|
|
|
// if (null != in) {
|
|
|
|
|
// in.close();
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// } catch (Exception e1) {
|
|
|
|
|
// return R.failed("下载文件失败:关闭文件流处理异常" + e1.getMessage());
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// return R.ok(null, "下载文件成功!");
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
public static char byteToChar(byte[] b) {
|
|
|
|
|
int hi = (b[0] & 0xFF) << 8;
|
|
|
|
|