Prechádzať zdrojové kódy

增加签收单回传附件功能

koul 5 rokov pred
rodič
commit
0d4dab0c91

+ 2 - 2
src/main/java/com/uas/HSLApplication.java

@@ -36,11 +36,11 @@ public class HSLApplication {
     }
 
 
-    /*@Scheduled(fixedRate=1000*60*60)
+    @Scheduled(fixedRate=1000*60*60)
     public void filePath() {
         runDownloadFilePath();
         closeJDBC();
-     }*/
+     }
 
     private void closeJDBC(){
         try{ //关闭数据库连接

+ 2 - 2
src/main/java/com/uas/main/DownloadFilePath.java

@@ -25,7 +25,7 @@ import java.util.Map;
 public class DownloadFilePath {
     public static void runDownloadFilePath(){
         //香港华商龙-富森-回签单扫描回传
-        downloadFilePath("N_HUASL-FSFILE","N_HUASL");
+        downloadFilePath("N_HUASL-FS","N_HUASL");
     }
     @SuppressWarnings("unchecked")
     public static void downloadFilePath(String depot,String sob){
@@ -38,7 +38,7 @@ public class DownloadFilePath {
             client = FtpUtil.connect(ftpMap);
             if(client!=null) {
                 String fileName = "";
-                List<File> files = FtpUtil.downloadAllFileByType(client);
+                List<File> files = FtpUtil.downloadFileByDirectory(client,ftpMap.get("file").toString());
                 if (files != null && files.size() > 0) {
                     connect = JdbcUtil.getConnectBySob(sob);
                     if (connect != null) {

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

@@ -231,12 +231,56 @@ public class FtpUtil {
 	}
 
 
+	/**
+ *
+ * @param ftpClient
+ * @return 获取连接到的ftp站点下的文件夹所有文件
+ */
+public static List<File> downloadFileByDirectory(FTPClient ftpClient,String directory,String fileType) {
+	List<File> files = new ArrayList<File>();
+	try {
+		ftpClient.enterLocalPassiveMode();
+		ftpClient.changeWorkingDirectory("/" + directory);// 转移到FTP服务器目录
+		FTPFile[] ftpFiles = ftpClient.listFiles();
+		if (ftpFiles != null && ftpFiles.length > 0) {
+			ArrayList<FTPFile> list = new ArrayList<FTPFile>(Arrays.asList(ftpFiles));
+			Collections.sort(list, new Comparator<FTPFile>() {
+				@Override
+				public int compare(FTPFile o1, FTPFile o2) {
+					long time = o1.getTimestamp().getTime().getTime();
+					long time1 = o2.getTimestamp().getTime().getTime();
+					if (time > time1) {
+						return 1;
+					}
+					if (time == time1) {
+						return 0;
+					}
+					return -1;
+				}
+			});
+			for (FTPFile file : list) {
+				if (file.getName().toUpperCase().endsWith("." + fileType)) {
+					File localFile = new File(System.getProperty("java.io.tmpdir") + File.separator + file.getName());
+					OutputStream os = new FileOutputStream(localFile);
+					ftpClient.retrieveFile(file.getName(), os);
+					os.close();
+					files.add(localFile);
+				}
+			}
+		}
+	} catch (Exception e) {
+		BaseUtil.getLogger().error(e.toString());
+		e.printStackTrace();
+	}
+	return files;
+}
+
 	/**
 	 *
 	 * @param ftpClient
 	 * @return 获取连接到的ftp站点下的文件夹所有文件
 	 */
-	public static List<File> downloadFileByDirectory(FTPClient ftpClient,String directory,String fileType) {
+	public static List<File> downloadFileByDirectory(FTPClient ftpClient,String directory) {
 		List<File> files = new ArrayList<File>();
 		try {
 			ftpClient.enterLocalPassiveMode();
@@ -259,7 +303,7 @@ public class FtpUtil {
 					}
 				});
 				for (FTPFile file : list) {
-					if (file.getName().toUpperCase().endsWith("." + fileType)) {
+					if(!".".equals(file.getName()) && !"..".equals(file.getName())&& !"bak".equals(file.getName())) {
 						File localFile = new File(System.getProperty("java.io.tmpdir") + File.separator + file.getName());
 						OutputStream os = new FileOutputStream(localFile);
 						ftpClient.retrieveFile(file.getName(), os);

+ 3 - 10
src/main/resources/properties/ftpconfig.properties

@@ -66,7 +66,8 @@
         "user":"b2b_ftp",
         "password":"24g777sW",
         "downloadpath":"postback",
-        "in":"normal"
+        "in":"normal",
+        "file":"hsl/hkhsl/file"
     },
     "N_HUASL-XN":{
         "ip":"218.4.62.135",
@@ -99,13 +100,5 @@
 		"password":"Ytzh)@2018",
 		"downloadpath":"From_QF",
 		"in":"TO_QF"
-	},
-    "N_HUASL-FSFILE":{
-        "ip":"113.100.137.106",
-        "port":21,
-        "user":"b2b_ftp",
-        "password":"24g777sW",
-        "downloadpath":"hsl/hkhsl/file",
-        "in":""
-    }
+	}
 }