|
|
@@ -1,9 +1,11 @@
|
|
|
package com.uas.service.Impl;
|
|
|
|
|
|
+import com.jcraft.jsch.JSchException;
|
|
|
import com.uas.service.DownloadService;
|
|
|
import com.uas.util.BaseUtil;
|
|
|
import com.uas.util.FtpUtil;
|
|
|
import com.uas.util.JdbcUtil;
|
|
|
+import com.uas.util.SFTPUtil;
|
|
|
import org.apache.commons.net.ftp.FTPClient;
|
|
|
import org.codehaus.jackson.map.ObjectMapper;
|
|
|
import org.dom4j.Document;
|
|
|
@@ -30,7 +32,7 @@ public class DownloadServiceImpl implements DownloadService {
|
|
|
|
|
|
@Override
|
|
|
public void downloadRun(){
|
|
|
- //联合创泰-准时达
|
|
|
+ //博思达-准时达
|
|
|
downloadByDepotAndSob("BSD_HK-ZSD","BSD_HK","Upstar Technology (HK) Limited");
|
|
|
|
|
|
|
|
|
@@ -42,15 +44,34 @@ public class DownloadServiceImpl implements DownloadService {
|
|
|
public void downloadByDepotAndSob(String depot,String sob,String enterprise){
|
|
|
BaseUtil.getLogger().info("download xml" + " from "+depot);
|
|
|
FTPClient client = null;
|
|
|
+ SFTPUtil sftp = null;
|
|
|
List<String> sqls = new ArrayList<String>();
|
|
|
boolean executeRes = false;
|
|
|
Connection connect = null;
|
|
|
+
|
|
|
try {
|
|
|
Map<String,Object> servMap = JdbcUtil.getFtpConfigs();
|
|
|
Map<String,Object> ftpMap = (Map<String,Object>)servMap.get(depot);
|
|
|
- client = FtpUtil.connect(ftpMap);
|
|
|
- if(client!=null) {
|
|
|
- List<File> files = FtpUtil.downloadAllFileByType(client, "XML");
|
|
|
+ if ("BSD_HK-ZSD".equals(depot)){
|
|
|
+ sftp = new SFTPUtil(ftpMap.get("user").toString(),ftpMap.get("password").toString(),
|
|
|
+ ftpMap.get("ip").toString(),
|
|
|
+ Integer.parseInt(ftpMap.get("port").toString()));
|
|
|
+ try {
|
|
|
+ sftp.login();
|
|
|
+ } catch (JSchException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ client = FtpUtil.connect(ftpMap);
|
|
|
+ }
|
|
|
+ if(client!=null||sftp!=null) {
|
|
|
+ List<File> files = null;
|
|
|
+ if ("BSD_HK-ZSD".equals(depot)) {
|
|
|
+ files = sftp.download(ftpMap.get("downloadpath").toString());
|
|
|
+
|
|
|
+ }else{
|
|
|
+ files = FtpUtil.downloadAllFileByType(client, "XML");
|
|
|
+ }
|
|
|
String fileName = "";
|
|
|
if (files != null && files.size() > 0) {
|
|
|
connect = JdbcUtil.getConnectBySob(sob);
|
|
|
@@ -64,18 +85,28 @@ public class DownloadServiceImpl implements DownloadService {
|
|
|
}
|
|
|
Statement statement = connect.createStatement();
|
|
|
sqls = parseXmlFileToSqls(file, statement);
|
|
|
+ String s = file.getName().substring(0, file.getName().indexOf(".")) + ".xml";
|
|
|
if (sqls == null) {
|
|
|
+ sftp.rename(ftpMap.get("downloadpath").toString() + "/" + s, "goodsreceipt/backup/" + s);
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
executeRes = JdbcUtil.executeSqls(connect, sqls);
|
|
|
|
|
|
if (executeRes) {
|
|
|
- //移动处理完的文件到bak文件夹下
|
|
|
- client.rename(file.getName(), "/HKHub/UPSTAR/reply_bak/" + file.getName());
|
|
|
+ if ("BSD_HK-ZSD".equals(depot)) {
|
|
|
+ Boolean rename = sftp.rename(ftpMap.get("downloadpath").toString() + "/" + s, "bosidahkhub/reply_bak/" + s);
|
|
|
+ } else {
|
|
|
+ //移动处理完的文件到bak文件夹下
|
|
|
+ client.rename(file.getName(), "bak/" + file.getName());
|
|
|
+ }
|
|
|
}else{
|
|
|
- //移动处理完的文件到failed文件夹下
|
|
|
- client.rename(file.getName(), "/HKHub/UPSTAR/erro_reply/" + file.getName());
|
|
|
+ if ("BSD_HK-ZSD".equals(depot)) {
|
|
|
+ Boolean rename = sftp.rename(ftpMap.get("downloadpath").toString() + "/" + s, "bosidahkhub/erro_reply/" + s);
|
|
|
+ } else {
|
|
|
+ //移动处理完的文件到failed文件夹下
|
|
|
+ client.rename(file.getName(), "failed/" + file.getName());
|
|
|
+ }
|
|
|
}
|
|
|
statement.close();
|
|
|
} catch (Exception e) {
|
|
|
@@ -99,6 +130,9 @@ public class DownloadServiceImpl implements DownloadService {
|
|
|
FtpUtil.closeFtpClient(client);
|
|
|
client = null;
|
|
|
}
|
|
|
+ if (sftp!=null){
|
|
|
+ sftp.logout();
|
|
|
+ }
|
|
|
//把当前的连接关闭
|
|
|
try {
|
|
|
if(connect!=null){
|