Browse Source

增加FTP服务器链接超时问题处理

koul 5 years ago
parent
commit
53d48811ad

+ 0 - 2
src/main/java/com/uas/service/Impl/DownloadFilePathServiceImpl.java

@@ -41,9 +41,7 @@ public class DownloadFilePathServiceImpl implements DownloadFilePathService{
         BaseUtil.getLogger().info("downloadFilePath():"+sob+"开始");
         BaseUtil.getLogger().info("downloadFilePath():"+sob+"开始");
         FTPClient client = null;
         FTPClient client = null;
         Connection connect = null;
         Connection connect = null;
-
         try {
         try {
-            BaseUtil.getLogger().info("downloadFilePath():connect:"+connect);
             Map<String,Object> servMap = JdbcUtil.getFtpConfigs();
             Map<String,Object> servMap = JdbcUtil.getFtpConfigs();
             Map<String,Object> ftpMap = (Map<String,Object>)servMap.get(depot);
             Map<String,Object> ftpMap = (Map<String,Object>)servMap.get(depot);
             client = FtpUtil.connect(ftpMap);
             client = FtpUtil.connect(ftpMap);

+ 1 - 2
src/main/java/com/uas/service/Impl/DownloadServiceImpl.java

@@ -73,7 +73,6 @@ public class DownloadServiceImpl implements DownloadService {
 		boolean executeRes = false;
 		boolean executeRes = false;
 		Connection connect = null;
 		Connection connect = null;
 		try {
 		try {
-			BaseUtil.getLogger().info("downloadByDepotAndSob():connect:"+connect);
 			Map<String,Object> servMap = getFtpConfigs();
 			Map<String,Object> servMap = getFtpConfigs();
 			Map<String,Object> ftpMap = (Map<String,Object>)servMap.get(depot);
 			Map<String,Object> ftpMap = (Map<String,Object>)servMap.get(depot);
 			client = connect(ftpMap);
 			client = connect(ftpMap);
@@ -122,7 +121,7 @@ public class DownloadServiceImpl implements DownloadService {
 					}
 					}
 				}
 				}
 			}
 			}
-			BaseUtil.getLogger().error("downloadByDepotAndSob():"+enterprise+"结束");
+			BaseUtil.getLogger().info("downloadByDepotAndSob():"+enterprise+"结束");
 		} catch (Exception e) {
 		} catch (Exception e) {
 			BaseUtil.getLogger().error(e.toString());
 			BaseUtil.getLogger().error(e.toString());
 			e.printStackTrace();
 			e.printStackTrace();

+ 1 - 2
src/main/java/com/uas/service/Impl/DownloadStcockQtyServiceImpl.java

@@ -46,7 +46,6 @@ public class DownloadStcockQtyServiceImpl implements DownloadStcockQtyService {
         FTPClient client = null;
         FTPClient client = null;
         Connection connect = null;
         Connection connect = null;
         try {
         try {
-            BaseUtil.getLogger().info("downloadStcockQty():connect:"+connect);
             Map<String,Object> servMap = getFtpConfigs();
             Map<String,Object> servMap = getFtpConfigs();
             Map<String,Object> ftpMap = (Map<String,Object>)servMap.get(depot);
             Map<String,Object> ftpMap = (Map<String,Object>)servMap.get(depot);
             client = connect(ftpMap);
             client = connect(ftpMap);
@@ -83,7 +82,7 @@ public class DownloadStcockQtyServiceImpl implements DownloadStcockQtyService {
             }
             }
             BaseUtil.getLogger().info("downloadStcockQty():"+sob+"结束");
             BaseUtil.getLogger().info("downloadStcockQty():"+sob+"结束");
         } catch (Exception e) {
         } catch (Exception e) {
-            BaseUtil.getLogger().info("downloadStcockQty():"+e.getMessage());
+            BaseUtil.getLogger().error("downloadStcockQty():"+e.getMessage());
             e.printStackTrace();
             e.printStackTrace();
         }finally{
         }finally{
             if(client!=null){
             if(client!=null){

+ 0 - 1
src/main/java/com/uas/service/Impl/UploadServiceImpl.java

@@ -63,7 +63,6 @@ public class UploadServiceImpl implements UploadService {
         Map<String,Object> config = null;
         Map<String,Object> config = null;
         Connection connect = null;
         Connection connect = null;
         try{
         try{
-            BaseUtil.getLogger().info("uploadBySob():connect:"+connect);
             connect = JdbcUtil.getConnectBySob(sob);
             connect = JdbcUtil.getConnectBySob(sob);
             if(connect!=null){
             if(connect!=null){
                 statement = connect.createStatement();
                 statement = connect.createStatement();

+ 7 - 2
src/main/java/com/uas/util/FtpUtil.java

@@ -70,6 +70,11 @@ public class FtpUtil {
 			String password = map.get("password").toString();
 			String password = map.get("password").toString();
 			ftp = new FTPClient();
 			ftp = new FTPClient();
 			int reply;
 			int reply;
+			ftp.setDefaultTimeout(30*1000);
+			ftp.setConnectTimeout(30*1000);
+			ftp.setDataTimeout(30*1000);
+			//设置ftp为被动模式,解决有时候ftp会卡住问题
+			ftp.enterLocalPassiveMode();
 			ftp.connect(addr, port);
 			ftp.connect(addr, port);
 			if(!ftp.login(username, password)){
 			if(!ftp.login(username, password)){
 				return null;
 				return null;
@@ -82,9 +87,9 @@ public class FtpUtil {
 			}
 			}
 			ftp.changeWorkingDirectory(path);
 			ftp.changeWorkingDirectory(path);
 			return ftp;			
 			return ftp;			
-		}catch(Exception e){ 
-			e.printStackTrace();
+		}catch(Exception e){
 			BaseUtil.getLogger().error("ip:" + addr + e.toString());
 			BaseUtil.getLogger().error("ip:" + addr + e.toString());
+			e.printStackTrace();
 			return null;
 			return null;
 		}
 		}
 	}
 	}

+ 1 - 1
src/main/java/com/uas/util/JdbcUtil.java

@@ -121,7 +121,7 @@ public class JdbcUtil {
 	    try{
 	    try{
 			connection = JdbcUtil.getConnect(dbServMap.get("url").toString(), dbServMap.get("user").toString(), dbServMap.get("password").toString());
 			connection = JdbcUtil.getConnect(dbServMap.get("url").toString(), dbServMap.get("user").toString(), dbServMap.get("password").toString());
 	    }catch (Exception e){
 	    }catch (Exception e){
-			System.err.println(e.getMessage());
+			BaseUtil.getLogger().error("数据库:"+sob+",链接异常:"+e.getMessage());
 	    	try {
 	    	try {
 				System.in.read();
 				System.in.read();
 			} catch (IOException e2) {
 			} catch (IOException e2) {

+ 17 - 7
src/main/resources/properties/ftpconfig.properties

@@ -6,7 +6,8 @@
         "password":"yitoa@2020",
         "password":"yitoa@2020",
         "downloadpath":"Ack/SZHSL",
         "downloadpath":"Ack/SZHSL",
         "in":"Order/SZHSL",
         "in":"Order/SZHSL",
-        "qty":"Inv/SZHSL"
+        "qty":"Inv/SZHSL",
+        "file":""
     },
     },
     "N_E_SHINE_SH-DRD":{
     "N_E_SHINE_SH-DRD":{
         "ip":"58.211.24.196",
         "ip":"58.211.24.196",
@@ -15,7 +16,8 @@
         "password":"yitoa@2020",
         "password":"yitoa@2020",
         "downloadpath":"Ack/SHYS",
         "downloadpath":"Ack/SHYS",
         "in":"Order/SHYS",
         "in":"Order/SHYS",
-        "qty":"Inv/SHYS"
+        "qty":"Inv/SHYS",
+        "file":""
     },
     },
     "N_HUASL_QD-DRD":{
     "N_HUASL_QD-DRD":{
         "ip":"58.211.24.196",
         "ip":"58.211.24.196",
@@ -24,7 +26,8 @@
         "password":"yitoa@2020",
         "password":"yitoa@2020",
         "downloadpath":"Ack/QDHSL",
         "downloadpath":"Ack/QDHSL",
         "in":"Order/QDHSL",
         "in":"Order/QDHSL",
-        "qty":"Inv/QDHSL"
+        "qty":"Inv/QDHSL",
+        "file":""
     },
     },
     "HSL_BJ-DRD":{
     "HSL_BJ-DRD":{
         "ip":"58.211.24.196",
         "ip":"58.211.24.196",
@@ -33,7 +36,8 @@
         "password":"yitoa@2020",
         "password":"yitoa@2020",
         "downloadpath":"Ack/BJHSL",
         "downloadpath":"Ack/BJHSL",
         "in":"Order/BJHSL",
         "in":"Order/BJHSL",
-        "qty":"Inv/BJHSL"
+        "qty":"Inv/BJHSL",
+        "file":""
     },
     },
     "HSL_CQ-DRD":{
     "HSL_CQ-DRD":{
         "ip":"58.211.24.196",
         "ip":"58.211.24.196",
@@ -42,7 +46,8 @@
         "password":"yitoa@2020",
         "password":"yitoa@2020",
         "downloadpath":"Ack/CQHSL",
         "downloadpath":"Ack/CQHSL",
         "in":"Order/CQHSL",
         "in":"Order/CQHSL",
-        "qty":"Inv/CQHSL"
+        "qty":"Inv/CQHSL",
+        "file":""
     },
     },
     "N_BJKG-FS":{
     "N_BJKG-FS":{
         "ip":"113.100.137.106",
         "ip":"113.100.137.106",
@@ -50,7 +55,9 @@
         "user":"b2b_ftp",
         "user":"b2b_ftp",
         "password":"24g777sW",
         "password":"24g777sW",
         "downloadpath":"baij_postback",
         "downloadpath":"baij_postback",
-        "in":"baij_normal"
+        "in":"baij_normal",
+        "qty":"",
+        "file":""
     },
     },
     "N_WILICHK-FS":{
     "N_WILICHK-FS":{
         "ip":"113.100.137.106",
         "ip":"113.100.137.106",
@@ -58,7 +65,9 @@
         "user":"b2b_ftp",
         "user":"b2b_ftp",
         "password":"24g777sW",
         "password":"24g777sW",
         "downloadpath":"weier_postback",
         "downloadpath":"weier_postback",
-        "in":"weier_normal"
+        "in":"weier_normal",
+        "qty":"",
+        "file":""
     },
     },
     "N_HUASL-FS":{
     "N_HUASL-FS":{
         "ip":"113.100.137.106",
         "ip":"113.100.137.106",
@@ -67,6 +76,7 @@
         "password":"24g777sW",
         "password":"24g777sW",
         "downloadpath":"postback",
         "downloadpath":"postback",
         "in":"normal",
         "in":"normal",
+        "qty":"",
         "file":"signback"
         "file":"signback"
     }
     }
 }
 }