Просмотр исходного кода

增加日志检测断点问题

koul 5 лет назад
Родитель
Сommit
6ef446e6bb

+ 4 - 1
src/main/java/com/uas/service/Impl/DownloadFilePathServiceImpl.java

@@ -38,10 +38,12 @@ public class DownloadFilePathServiceImpl implements DownloadFilePathService{
     @Override
     @Async("taskExecutor")
     public  void downloadFilePath(String depot,String sob){
+        BaseUtil.getLogger().info("downloadFilePath():"+sob+"开始");
         FTPClient client = null;
         Connection connect = null;
 
         try {
+            BaseUtil.getLogger().info("downloadFilePath():connect:"+connect);
             Map<String,Object> servMap = JdbcUtil.getFtpConfigs();
             Map<String,Object> ftpMap = (Map<String,Object>)servMap.get(depot);
             client = FtpUtil.connect(ftpMap);
@@ -67,8 +69,8 @@ public class DownloadFilePathServiceImpl implements DownloadFilePathService{
                                 }
                                 statement.close();
                             } catch (Exception e) {
+                                BaseUtil.getLogger().error("downloadFilePath():"+e.toString());
                                 e.printStackTrace();
-                                BaseUtil.getLogger().error(e.toString());
                                 continue;
                             }
                         }
@@ -79,6 +81,7 @@ public class DownloadFilePathServiceImpl implements DownloadFilePathService{
                     BaseUtil.logDownload(fileName.substring(1), ftpMap.get("ip").toString(), ftpMap.get("file").toString());
                 }
             }
+            BaseUtil.getLogger().info("downloadFilePath():"+sob+"结束");
         } catch (Exception e) {
             BaseUtil.getLogger().error(e.toString());
             e.printStackTrace();

+ 88 - 78
src/main/java/com/uas/service/Impl/DownloadServiceImpl.java

@@ -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;
-			}
-		}
-	}
  }

+ 4 - 1
src/main/java/com/uas/service/Impl/DownloadStcockQtyServiceImpl.java

@@ -42,9 +42,11 @@ public class DownloadStcockQtyServiceImpl implements DownloadStcockQtyService {
     @Override
     @Async("taskExecutor")
     public void downloadStcockQty(String depot,String sob) {
+        BaseUtil.getLogger().info("downloadStcockQty():"+sob+"开始");
         FTPClient client = null;
         Connection connect = null;
         try {
+            BaseUtil.getLogger().info("downloadStcockQty():connect:"+connect);
             Map<String,Object> servMap = getFtpConfigs();
             Map<String,Object> ftpMap = (Map<String,Object>)servMap.get(depot);
             client = connect(ftpMap);
@@ -79,8 +81,9 @@ public class DownloadStcockQtyServiceImpl implements DownloadStcockQtyService {
                     }
                 }
             }
+            BaseUtil.getLogger().info("downloadStcockQty():"+sob+"结束");
         } catch (Exception e) {
-            BaseUtil.getLogger().error(e.toString());
+            BaseUtil.getLogger().info("downloadStcockQty():"+e.getMessage());
             e.printStackTrace();
         }finally{
             if(client!=null){

+ 75 - 71
src/main/java/com/uas/service/Impl/UploadServiceImpl.java

@@ -47,80 +47,11 @@ public class UploadServiceImpl implements UploadService {
         uploadBySob("HSL_BJ");
     }
 
-    private File createXmlFile(String data, String id, String type, String fileprefix, String date){ //生成xml文件
-        File xmlFile = null;
-        try{
-            String xml =data;
-            xmlFile = new File( System.getProperty("java.io.tmpdir")+File.separator +fileprefix+date + "_" + id +".xml");
-            if(!xmlFile.exists()){
-                if(!xmlFile.getParentFile().exists()){
-                    xmlFile.mkdir();
-                }
-                xmlFile.createNewFile();
-            }
-            FileWriter fw = new FileWriter(xmlFile.getAbsoluteFile());
-            OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(xmlFile.getAbsoluteFile()),"UTF-8");
-            out.write(xml);
-            out.flush();
-            out.close();
-            fw.close();
-        }catch(Exception e){
-            BaseUtil.getLogger().error(e.toString());
-            e.printStackTrace();
-        }
-        return xmlFile;
-    }
-
-
-    private void turnToFormal(Connection connection, String id, String fileName){ //临时表数据转入正式
-        Statement statement = null;
-        try{
-            connection.setAutoCommit(false);
-            statement = connection.createStatement();
-            statement.setQueryTimeout(180);
-            statement.execute("insert into xmldatalog(xl_id,xl_data,xl_date,xl_depot,xl_caller,xl_code,xl_from,xl_status,xl_sourceid,xl_filename) "
-                    + "select XMLDATALOG_SEQ.NEXTVAL,xl_data,sysdate,xl_depot,xl_caller,xl_code,'upload','success',xl_sourceid,'"+fileName+"' from xmldatalogtemp where xl_id=" + id);
-            statement.execute("delete from xmldatalogtemp where xl_id=" + id);
-            connection.commit();
-        }catch(Exception e){
-            try {
-                connection.rollback();
-            } catch (SQLException e1) {
-                BaseUtil.getLogger().error(e1.toString());
-                e1.printStackTrace();
-            }
-            BaseUtil.getLogger().error(e.toString());
-            e.printStackTrace();
-        }finally{
-            try{
-                if(statement!=null){
-                    statement.close();
-                }
-            }catch(Exception e){
-                BaseUtil.getLogger().error(e.toString());
-            }
-            statement = null;
-        }
-    }
-
-    private boolean upload(FTPClient client, String ip, String folder, File file){
-        boolean flag = false;
-        if(client!=null){
-            flag = FtpUtil.uploadFile(client, folder,file);
-        }
-        BaseUtil.getLogger().info("upload " + file.getName() + " to " + ip + ":" + folder + " " + (flag?"success":"fail")+"");
-        return flag;
-    }
-
-    private ResultSet getXmlData(Statement statement) throws SQLException{
-        return statement.executeQuery("select xl_id,xl_data,xl_fileprefix,to_char(xl_date,'yyyymmddhh24miss') xl_date,xl_depot from xmldatalogtemp where xl_data is not null order by xl_depot desc");
-    }
-
-
     @SuppressWarnings({ "unchecked"})
     @Override
     @Async("taskExecutor")
     public void uploadBySob(String sob) {
+        BaseUtil.getLogger().info("uploadBySob():"+sob+"开始");
         Statement statement = null;
         FTPClient client = null;
         String xldata = null;
@@ -132,6 +63,7 @@ public class UploadServiceImpl implements UploadService {
         Map<String,Object> config = null;
         Connection connect = null;
         try{
+            BaseUtil.getLogger().info("uploadBySob():connect:"+connect);
             connect = JdbcUtil.getConnectBySob(sob);
             if(connect!=null){
                 statement = connect.createStatement();
@@ -179,13 +111,14 @@ public class UploadServiceImpl implements UploadService {
                             }
                         }
                     }catch(Exception e){
-                        e.printStackTrace();
                         BaseUtil.getLogger().error(e.toString());
+                        e.printStackTrace();
                         continue;
                     }
                 }
                 rs.close();
             }
+            BaseUtil.getLogger().info("uploadBySob():"+sob+"结束");
         }catch(Exception e){
             BaseUtil.getLogger().error(e.toString());
             e.printStackTrace();
@@ -212,4 +145,75 @@ public class UploadServiceImpl implements UploadService {
         }
 
     }
+
+    private File createXmlFile(String data, String id, String type, String fileprefix, String date){ //生成xml文件
+        File xmlFile = null;
+        try{
+            String xml =data;
+            xmlFile = new File( System.getProperty("java.io.tmpdir")+File.separator +fileprefix+date + "_" + id +".xml");
+            if(!xmlFile.exists()){
+                if(!xmlFile.getParentFile().exists()){
+                    xmlFile.mkdir();
+                }
+                xmlFile.createNewFile();
+            }
+            FileWriter fw = new FileWriter(xmlFile.getAbsoluteFile());
+            OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(xmlFile.getAbsoluteFile()),"UTF-8");
+            out.write(xml);
+            out.flush();
+            out.close();
+            fw.close();
+        }catch(Exception e){
+            BaseUtil.getLogger().error(e.toString());
+            e.printStackTrace();
+        }
+        return xmlFile;
+    }
+
+
+    private void turnToFormal(Connection connection, String id, String fileName){ //临时表数据转入正式
+        Statement statement = null;
+        try{
+            connection.setAutoCommit(false);
+            statement = connection.createStatement();
+            statement.setQueryTimeout(180);
+            statement.execute("insert into xmldatalog(xl_id,xl_data,xl_date,xl_depot,xl_caller,xl_code,xl_from,xl_status,xl_sourceid,xl_filename) "
+                    + "select XMLDATALOG_SEQ.NEXTVAL,xl_data,sysdate,xl_depot,xl_caller,xl_code,'upload','success',xl_sourceid,'"+fileName+"' from xmldatalogtemp where xl_id=" + id);
+            statement.execute("delete from xmldatalogtemp where xl_id=" + id);
+            connection.commit();
+        }catch(Exception e){
+            try {
+                connection.rollback();
+            } catch (SQLException e1) {
+                BaseUtil.getLogger().error(e1.toString());
+                e1.printStackTrace();
+            }
+            BaseUtil.getLogger().error(e.toString());
+            e.printStackTrace();
+        }finally{
+            try{
+                if(statement!=null){
+                    statement.close();
+                }
+            }catch(Exception e){
+                BaseUtil.getLogger().error(e.toString());
+                e.printStackTrace();
+            }
+            statement = null;
+        }
+    }
+
+    private boolean upload(FTPClient client, String ip, String folder, File file){
+        boolean flag = false;
+        if(client!=null){
+            flag = FtpUtil.uploadFile(client, folder,file);
+        }
+        BaseUtil.getLogger().info("upload " + file.getName() + " to " + ip + ":" + folder + " " + (flag?"success":"fail")+"");
+        return flag;
+    }
+
+    private ResultSet getXmlData(Statement statement) throws SQLException{
+        return statement.executeQuery("select xl_id,xl_data,xl_fileprefix,to_char(xl_date,'yyyymmddhh24miss') xl_date,xl_depot from xmldatalogtemp where xl_data is not null order by xl_depot desc");
+    }
+
 }