|
@@ -1,21 +1,15 @@
|
|
|
package com.uas.main;
|
|
|
|
|
|
import java.io.File;
|
|
|
-import java.io.FileInputStream;
|
|
|
import java.sql.Connection;
|
|
|
import java.sql.SQLException;
|
|
|
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){
|
|
|
boolean bool = false;
|
|
@@ -33,8 +27,6 @@ public class Download {
|
|
|
downloadByDepotAndSob("YHND_SZ");
|
|
|
downloadByDepotAndSob("YHND_HK");
|
|
|
downloadByDepotAndSob("YITOA_ZX");
|
|
|
- downloadBySob();
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
@@ -47,7 +39,6 @@ public class Download {
|
|
|
boolean bol = false;
|
|
|
if(con==null) return;
|
|
|
for(String key:set){
|
|
|
- if(!"local".equals(key)&&!"12".equals(key)&&!"13".equals(key)){
|
|
|
Map<String,Object> ftpMap = (Map<String,Object>)servMap.get(key);
|
|
|
FTPClient client = null;
|
|
|
try {
|
|
@@ -90,8 +81,7 @@ public class Download {
|
|
|
if(client!=null){
|
|
|
FtpUtil.closeFtpClient(client);
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
try{
|
|
|
if(con!=null){
|
|
@@ -103,128 +93,4 @@ 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;
|
|
|
- }
|
|
|
- }
|
|
|
}
|