Browse Source

新增测试仓库信息修改及读取文件顺序排列

koul 5 years ago
parent
commit
18bd72b461
3 changed files with 44 additions and 23 deletions
  1. 13 4
      src/com/uas/util/BaseUtil.java
  2. 27 15
      src/com/uas/util/FtpUtil.java
  3. 4 4
      src/properties/ftpconfig.properties

+ 13 - 4
src/com/uas/util/BaseUtil.java

@@ -70,7 +70,7 @@ public class BaseUtil {
 			e1.printStackTrace();
 		}  
 		Element root = doc.getRootElement();
-    	
+
 		List<Element> e = root.elements();
     	for(Element el:e){
         	 String name = el.getName();
@@ -83,8 +83,8 @@ public class BaseUtil {
         		 json += ",\"PI_LOGISTICSSTATUS:\":\"" + el.getData() + "\"";
         		 sql += "PI_LOGISTICSSTATUS='" + el.getData() + "',";
         	 }else if(name=="TrackingNo"){
-        		 json += ",\"PI_LOGISTICSCODE:\":\"" + el.getData() + "\"";
-        		 sql += "PI_LOGISTICSCODE='" + el.getData() + "',";
+        		 json += ",\"PI_LISTCODE:\":\"" + el.getData() + "\"";
+        		 sql += "PI_LISTCODE='" + el.getData() + "',";
         	 }else if(name=="FreightCost"){
         		 json += ",\"PI_FREIGHT:\":\"" + el.getData() + "\"";
         		 sql += "PI_FREIGHT='" + el.getData() + "',";
@@ -99,7 +99,16 @@ public class BaseUtil {
 				 }
         		 json += ",\"PI_INOUTNO:\":\"" + code + "\"";
         		 condition = "PI_INOUTNO='"+code+"'";
-        	 }
+        	 }else if (name == "ExType"){
+				 json += ",\"PI_TRANSPORT:\":\"" + el.getData() + "\"";
+				 sql += "PI_TRANSPORT='" + el.getData() + "',";
+			 }else if(name == "ExNumber"){
+				 json += ",\"PI_LOGISTICSCODE:\":\"" + el.getData() + "\"";
+				 sql += "PI_LOGISTICSCODE='" + el.getData() + "',";
+			 }else if(name == "ExTime"){
+				 json += ",\"PI_GOODSDATE:\":\"" + el.getData() + "\"";
+				 sql += "PI_GOODSDATE=to_date('" + el.getData() + "','yyyymmddHH24:mi'),";
+			 }
     	}
     	if(!"".equals(json)){
     		json = "{" + json.substring(1) + "}";

+ 27 - 15
src/com/uas/util/FtpUtil.java

@@ -6,14 +6,9 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.net.SocketException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
+import java.util.*;
 
 import org.apache.commons.net.ftp.FTPClient;
-import org.apache.commons.net.ftp.FTPClientConfig;
 import org.apache.commons.net.ftp.FTPFile;
 import org.apache.commons.net.ftp.FTPReply;
 
@@ -48,7 +43,7 @@ public class FtpUtil {
 	
 	/**
 	 * 获取ftp连接,该连接指向ftp配置中的downloadpath文件夹
-	 * @param map包含ftp连接配置的map
+	 * @param map //包含ftp连接配置的map
 	 */
 	public static FTPClient connect(Map<String,Object> map) throws Exception {
 		return connect(map,map.get("downloadpath").toString());
@@ -56,7 +51,7 @@ public class FtpUtil {
 
 	/**
 	 * 获取ftp连接,该连接指向ftp配置中的downloadpath文件夹
-	 * @param map包含ftp连接配置的map
+	 * @param map  //包含ftp连接配置的map
 	 */
 	public static FTPClient connect(Map<String,Object> map,String path){
 		FTPClient ftp = null;
@@ -157,13 +152,30 @@ public class FtpUtil {
 		try {
 			ftpClient.enterLocalPassiveMode();
 			FTPFile[] ftpFiles = ftpClient.listFiles();
-			for (FTPFile file : ftpFiles) {
-				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);					
+			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) {

+ 4 - 4
src/properties/ftpconfig.properties

@@ -137,10 +137,10 @@
 		"remark":"上海WGQ新仓库DCL"
 	},
 	"14":{
-		"ip":"120.197.180.245",
-		"port":33321,
-		"user":"YHNDTEST",
-		"password":"5pLf1SKV",
+		"ip":"ftp.roadsimple.net",
+		"port":13321,
+		"user":"yhnd",
+		"password":"442t78Mw",
 		"downloadpath":"reply",
 		"in":"appointment_in",
 		"out":"distribute_in",