|
@@ -1,19 +1,20 @@
|
|
|
package com.uas.main;
|
|
|
|
|
|
import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
import java.sql.Connection;
|
|
|
import java.sql.SQLException;
|
|
|
-import java.sql.Statement;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
|
|
|
+import com.uas.fileUtil.FileUtil;
|
|
|
import org.apache.commons.net.ftp.FTPClient;
|
|
|
|
|
|
import com.uas.util.BaseUtil;
|
|
|
import com.uas.util.FtpUtil;
|
|
|
import com.uas.util.JdbcUtil;
|
|
|
+import org.apache.http.entity.ContentType;
|
|
|
+import org.springframework.mock.web.MockMultipartFile;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
public class Download {
|
|
|
public static boolean updateAndLog(Connection connection,Map<String,Object> map,String depot,File file){
|
|
@@ -32,6 +33,7 @@ public class Download {
|
|
|
downloadByDepotAndSob("YHND_SZ");
|
|
|
downloadByDepotAndSob("YHND_HK");
|
|
|
downloadByDepotAndSob("YITOA_ZX");
|
|
|
+ downloadBySob();
|
|
|
|
|
|
}
|
|
|
|
|
@@ -45,7 +47,7 @@ public class Download {
|
|
|
boolean bol = false;
|
|
|
if(con==null) return;
|
|
|
for(String key:set){
|
|
|
- if(!"local".equals(key)){
|
|
|
+ if(!"local".equals(key)&&!"12".equals(key)&&!"13".equals(key)){
|
|
|
Map<String,Object> ftpMap = (Map<String,Object>)servMap.get(key);
|
|
|
FTPClient client = null;
|
|
|
try {
|
|
@@ -61,9 +63,9 @@ public class Download {
|
|
|
bol = updateAndLog(con,map,key,file);
|
|
|
if(bol){
|
|
|
if("1".equals(key)||"2".equals(key)||"3".equals(key)){
|
|
|
- client.rename(file.getName(),".."+ File.separator + "reply_bak"+ File.separator + file.getName());
|
|
|
+ client.rename(file.getName(),"/reply_bak/"+file.getName());
|
|
|
}else{
|
|
|
- client.rename(file.getName(),".."+ File.separator + "reply_bak"+ File.separator + file.getName());
|
|
|
+ client.rename(file.getName(),"/reply_bak/"+file.getName());
|
|
|
|
|
|
}
|
|
|
}
|
|
@@ -101,4 +103,128 @@ public class Download {
|
|
|
con = null;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public static void downloadBySob(){
|
|
|
+ Map<String,Object> servMap = JdbcUtil.getFtpConfigs();
|
|
|
+ Set<String> set = servMap.keySet();
|
|
|
+ Map<String, Object> map = null;
|
|
|
+ Connection con = null;
|
|
|
+ boolean bol = false;
|
|
|
+ for(String key:set){
|
|
|
+ if("12".equals(key)||"13".equals(key)){
|
|
|
+ Map<String,Object> ftpMap = (Map<String,Object>)servMap.get(key);
|
|
|
+ String directory = ftpMap.get("downloadpath").toString();
|
|
|
+ FTPClient client = null;
|
|
|
+ try {
|
|
|
+ client = FtpUtil.connect(ftpMap);
|
|
|
+ if(client!=null){
|
|
|
+ List<File> files = FtpUtil.downloadAllFile(client,directory);
|
|
|
+ String fileName = "";
|
|
|
+ if(files!=null&&files.size()>0){
|
|
|
+ for(File file:files){
|
|
|
+ try{
|
|
|
+ fileName += "," + file.getName();
|
|
|
+ FileInputStream fileInputStream = new FileInputStream(file);
|
|
|
+ MultipartFile file1 = new MockMultipartFile(file.getName(), file.getName(),
|
|
|
+ ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
|
|
|
+
|
|
|
+ String s = file.getName().substring(0, 4);
|
|
|
+ if ("SZCK".equals(s)){
|
|
|
+ String sob = "YHND_SZ";
|
|
|
+ con = JdbcUtil.getConnectBySob(sob);
|
|
|
+ bol =FileUtil.fileUp(con,file1,sob);
|
|
|
+ }else if ("HKCK".equals(s)){
|
|
|
+ String sob = "YHND_HK";
|
|
|
+ con = JdbcUtil.getConnectBySob(sob);
|
|
|
+ bol =FileUtil.fileUp(con,file1,sob);
|
|
|
+ }else if("YTCK".equals(s)){
|
|
|
+ String sob = "YITOA_ZX";
|
|
|
+ con = JdbcUtil.getConnectBySob(sob);
|
|
|
+ bol =FileUtil.fileUp(con,file1,sob);
|
|
|
+ }else {
|
|
|
+ client.rename(file.getName(),"/PakingL_error/" + file.getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ if(bol){
|
|
|
+ client.rename(file.getName(),"/PakingL_bak/PL_" + file.getName());
|
|
|
+ }
|
|
|
+ }catch(Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ BaseUtil.getLogger().error(e.toString());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ System.out.println("download " + file.getName() + " from " + ftpMap.get("ip") + " path:" + ftpMap.get("downloadpath"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!"".equals(fileName)){
|
|
|
+ System.out.println("download " + fileName.substring(1) + " from " + ftpMap.get("ip") + " path:" + ftpMap.get("downloadpath"));
|
|
|
+ BaseUtil.getLogger().info("download " + fileName.substring(1) + " from " + ftpMap.get("ip") + " path:" + ftpMap.get("downloadpath"));
|
|
|
+ }
|
|
|
+ String directory1 = ftpMap.get("out").toString();
|
|
|
+ List<File> files1 = FtpUtil.downloadAllFile(client,directory1);
|
|
|
+ String fileName1 = "";
|
|
|
+ if(files1!=null&&files1.size()>0){
|
|
|
+ for(File file:files1){
|
|
|
+ try{
|
|
|
+ fileName += "," + file.getName();
|
|
|
+
|
|
|
+ FileInputStream fileInputStream = new FileInputStream(file);
|
|
|
+ MultipartFile file1 = new MockMultipartFile(file.getName(), file.getName(),
|
|
|
+ ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
|
|
|
+ String s = file.getName().substring(0, 4);
|
|
|
+ if ("SZCK".equals(s)){
|
|
|
+ String sob = "YHND_SZ";
|
|
|
+ con = JdbcUtil.getConnectBySob(sob);
|
|
|
+ bol =FileUtil.fileUp(con,file1,sob);
|
|
|
+ }else if ("HKCK".equals(s)){
|
|
|
+ String sob = "YHND_HK";
|
|
|
+ con = JdbcUtil.getConnectBySob(sob);
|
|
|
+ bol =FileUtil.fileUp(con,file1,sob);
|
|
|
+ }else if("YTCK".equals(s)){
|
|
|
+ String sob = "YITOA_ZX";
|
|
|
+ con = JdbcUtil.getConnectBySob(sob);
|
|
|
+ bol =FileUtil.fileUp(con,file1,sob);
|
|
|
+ }else {
|
|
|
+ client.rename(file.getName(), "/RT_error/" + file.getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ if(bol){
|
|
|
+ client.rename(file.getName(), "/RT_bak/RT_" + file.getName());
|
|
|
+ }
|
|
|
+ }catch(Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ BaseUtil.getLogger().error(e.toString());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ System.out.println("download " + file.getName() + " from " + ftpMap.get("ip") + " " +
|
|
|
+ "path:" + ftpMap.get("out"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!"".equals(fileName1)){
|
|
|
+ System.out.println("download " + fileName.substring(1) + " from " + ftpMap.get("ip") + " " +
|
|
|
+ "path:" + ftpMap.get("out"));
|
|
|
+ BaseUtil.getLogger().info("download " + fileName.substring(1) + " from " + ftpMap.get("ip") + " path:" + ftpMap.get("out"));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ BaseUtil.getLogger().error(e.toString());
|
|
|
+ e.printStackTrace();
|
|
|
+ }finally{
|
|
|
+ if(client!=null){
|
|
|
+ FtpUtil.closeFtpClient(client);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ try{
|
|
|
+ if(con!=null){
|
|
|
+ con.close();
|
|
|
+ }
|
|
|
+ }catch(SQLException e){
|
|
|
+ BaseUtil.getLogger().error(e.toString());
|
|
|
+ }finally{
|
|
|
+ con = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|