|
|
@@ -62,6 +62,88 @@ public class DownloadServiceImpl implements DownloadService {
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ @Override
|
|
|
+ @Async("taskExecutor")
|
|
|
+ public void downloadByDepotAndSob(String depot,String sob,String enterprise){
|
|
|
+ BaseUtil.getLogger().info("downloadByDepotAndSob():"+enterprise+"开始");
|
|
|
+ FTPClient client = null;
|
|
|
+ List<String> sqls = new ArrayList<String>();
|
|
|
+ boolean executeRes = false;
|
|
|
+ Connection connect = null;
|
|
|
+ try {
|
|
|
+ BaseUtil.getLogger().info("downloadByDepotAndSob():connect:"+connect);
|
|
|
+ Map<String,Object> servMap = getFtpConfigs();
|
|
|
+ Map<String,Object> ftpMap = (Map<String,Object>)servMap.get(depot);
|
|
|
+ client = connect(ftpMap);
|
|
|
+ if(client!=null) {
|
|
|
+ List<File> files = null;
|
|
|
+ files = downloadAllFileByType(client, "XML");
|
|
|
+ String fileName = "";
|
|
|
+ if (files != null && files.size() > 0) {
|
|
|
+ connect = getConnectBySob(sob);
|
|
|
+ if (connect != null) {
|
|
|
+ for (File file : files) {
|
|
|
+ try {
|
|
|
+ fileName += "," + file.getName();
|
|
|
+ Statement statement = connect.createStatement();
|
|
|
+ //判断当前帐套和文件是否一致
|
|
|
+ if (!checkXmlFileToSqlToEnterprise(file, enterprise)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ sqls = parseXmlFileToSqls(file, statement);
|
|
|
+ if (sqls == null) {
|
|
|
+ //移动处理失败的文件到failed文件夹下
|
|
|
+ client.rename(file.getName(), "failed/" + file.getName());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ executeRes = executeSqls(connect, sqls);
|
|
|
+
|
|
|
+ if (executeRes) {
|
|
|
+ //移动处理完的文件到bak文件夹下
|
|
|
+ client.rename(file.getName(), "bak/" + file.getName());
|
|
|
+ }else {
|
|
|
+ //移动处理失败的文件到failed文件夹下
|
|
|
+ client.rename(file.getName(), "failed/" + file.getName());
|
|
|
+ }
|
|
|
+ statement.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ BaseUtil.getLogger().error("downloadByDepotAndSob():"+e.toString());
|
|
|
+ e.printStackTrace();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if (!"".equals(fileName)) {
|
|
|
+ BaseUtil.logDownload(fileName.substring(1), ftpMap.get("ip").toString(), ftpMap.get("downloadpath").toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ BaseUtil.getLogger().error("downloadByDepotAndSob():"+enterprise+"结束");
|
|
|
+ } catch (Exception e) {
|
|
|
+ BaseUtil.getLogger().error(e.toString());
|
|
|
+ e.printStackTrace();
|
|
|
+ }finally{
|
|
|
+ if(client!=null){
|
|
|
+ closeFtpClient(client);
|
|
|
+ client = null;
|
|
|
+ }
|
|
|
+ //把当前的连接关闭
|
|
|
+ try {
|
|
|
+ if(connect!=null){
|
|
|
+ connect.close();
|
|
|
+ }
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }finally{
|
|
|
+ connect = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public static Boolean checkXmlFileToSqlToEnterprise(File file,String enterprise){
|
|
|
String ent = null;
|
|
|
Element root = getElementRoot(file); //获取根节点
|
|
|
@@ -139,6 +221,7 @@ public class DownloadServiceImpl implements DownloadService {
|
|
|
try {
|
|
|
stm.close();
|
|
|
} catch (SQLException e1) {
|
|
|
+ BaseUtil.getLogger().info("parseXmlFileToSqls():"+e1.getMessage());
|
|
|
e1.printStackTrace();
|
|
|
}
|
|
|
|
|
|
@@ -195,6 +278,7 @@ public class DownloadServiceImpl implements DownloadService {
|
|
|
sqls.add("declare out varchar2(500);begin SP_XMLTEMPPARSE("+id+",'" + caller + "',out);end;");
|
|
|
}
|
|
|
} catch (IOException e) {
|
|
|
+ BaseUtil.getLogger().info("getLogXmlDataAndInterceptorSql():"+e.getMessage());
|
|
|
e.printStackTrace();
|
|
|
}finally{
|
|
|
return sqls;
|
|
|
@@ -360,6 +444,7 @@ public class DownloadServiceImpl implements DownloadService {
|
|
|
}
|
|
|
rs.close();
|
|
|
}catch(SQLException e){
|
|
|
+ BaseUtil.getLogger().info("getXmlConfigDetail():"+e.getMessage());
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return list;
|
|
|
@@ -383,6 +468,7 @@ public class DownloadServiceImpl implements DownloadService {
|
|
|
}
|
|
|
rs.close();
|
|
|
}catch(SQLException e){
|
|
|
+ BaseUtil.getLogger().info("getXmlConfigDetail():"+e.getMessage());
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return list;
|
|
|
@@ -415,6 +501,7 @@ public class DownloadServiceImpl implements DownloadService {
|
|
|
}
|
|
|
rs.close();
|
|
|
}catch(SQLException e){
|
|
|
+ BaseUtil.getLogger().info("getXmlConfig():"+e.getMessage());
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return map;
|
|
|
@@ -432,6 +519,7 @@ public class DownloadServiceImpl implements DownloadService {
|
|
|
in.close();
|
|
|
element = doc.getRootElement();
|
|
|
} catch (Exception e) {
|
|
|
+ BaseUtil.getLogger().info("getElementRoot():"+e.getMessage());
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return element;
|
|
|
@@ -468,82 +556,4 @@ public class DownloadServiceImpl implements DownloadService {
|
|
|
}
|
|
|
return data;
|
|
|
}
|
|
|
-
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- @Override
|
|
|
- @Async("taskExecutor")
|
|
|
- public void downloadByDepotAndSob(String depot,String sob,String enterprise){
|
|
|
- FTPClient client = null;
|
|
|
- List<String> sqls = new ArrayList<String>();
|
|
|
- boolean executeRes = false;
|
|
|
- Connection connect = null;
|
|
|
- try {
|
|
|
- Map<String,Object> servMap = getFtpConfigs();
|
|
|
- Map<String,Object> ftpMap = (Map<String,Object>)servMap.get(depot);
|
|
|
- client = connect(ftpMap);
|
|
|
- if(client!=null) {
|
|
|
- List<File> files = null;
|
|
|
- files = downloadAllFileByType(client, "XML");
|
|
|
- String fileName = "";
|
|
|
- if (files != null && files.size() > 0) {
|
|
|
- connect = getConnectBySob(sob);
|
|
|
- if (connect != null) {
|
|
|
- for (File file : files) {
|
|
|
- try {
|
|
|
- fileName += "," + file.getName();
|
|
|
- Statement statement = connect.createStatement();
|
|
|
- //判断当前帐套和文件是否一致
|
|
|
- if (!checkXmlFileToSqlToEnterprise(file, enterprise)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- sqls = parseXmlFileToSqls(file, statement);
|
|
|
- if (sqls == null) {
|
|
|
- //移动处理失败的文件到failed文件夹下
|
|
|
- client.rename(file.getName(), "failed/" + file.getName());
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- executeRes = executeSqls(connect, sqls);
|
|
|
-
|
|
|
- if (executeRes) {
|
|
|
- //移动处理完的文件到bak文件夹下
|
|
|
- client.rename(file.getName(), "bak/" + file.getName());
|
|
|
- }else {
|
|
|
- //移动处理失败的文件到failed文件夹下
|
|
|
- client.rename(file.getName(), "failed/" + file.getName());
|
|
|
- }
|
|
|
- statement.close();
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- BaseUtil.getLogger().error(e.toString());
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- if (!"".equals(fileName)) {
|
|
|
- BaseUtil.logDownload(fileName.substring(1), ftpMap.get("ip").toString(), ftpMap.get("downloadpath").toString());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- BaseUtil.getLogger().error(e.toString());
|
|
|
- e.printStackTrace();
|
|
|
- }finally{
|
|
|
- if(client!=null){
|
|
|
- closeFtpClient(client);
|
|
|
- client = null;
|
|
|
- }
|
|
|
- //把当前的连接关闭
|
|
|
- try {
|
|
|
- if(connect!=null){
|
|
|
- connect.close();
|
|
|
- }
|
|
|
- } catch (SQLException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }finally{
|
|
|
- connect = null;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
}
|