koul 6 years ago
commit
afd413cc95

+ 34 - 0
.idea/artifacts/hsl_jar.xml

@@ -0,0 +1,34 @@
+<component name="ArtifactManager">
+  <artifact type="jar" name="hsl:jar">
+    <output-path>$PROJECT_DIR$/classes/artifacts/hsl_jar</output-path>
+    <root id="archive" name="hsl.jar">
+      <element id="directory" name="META-INF">
+        <element id="file-copy" path="$PROJECT_DIR$/META-INF/MANIFEST.MF" />
+      </element>
+      <element id="module-output" name="hsl" />
+      <element id="library" level="module" name="commons-csv-1.4.jar" module-name="hsl" />
+      <element id="library" level="module" name="flexjson-2.1.jar" module-name="hsl" />
+      <element id="extracted-dir" path="$PROJECT_DIR$/lib/commons-csv-1.4.jar" path-in-jar="/" />
+      <element id="extracted-dir" path="$PROJECT_DIR$/lib/ojdbc6-11.2.0.jar" path-in-jar="/" />
+      <element id="extracted-dir" path="$PROJECT_DIR$/lib/commons-net-3.6.jar" path-in-jar="/" />
+      <element id="extracted-dir" path="$PROJECT_DIR$/lib/dom4j-1.6.1.jar" path-in-jar="/" />
+      <element id="extracted-dir" path="$PROJECT_DIR$/lib/flexjson-2.1.jar" path-in-jar="/" />
+      <element id="extracted-dir" path="$PROJECT_DIR$/lib/jackson-core-asl-1.9.13.jar" path-in-jar="/" />
+      <element id="extracted-dir" path="$PROJECT_DIR$/lib/jackson-mapper-asl-1.9.13.jar" path-in-jar="/" />
+      <element id="extracted-dir" path="$PROJECT_DIR$/lib/junit.jar" path-in-jar="/" />
+      <element id="extracted-dir" path="$PROJECT_DIR$/lib/log4j-1.2.15.jar" path-in-jar="/" />
+      <element id="library" level="module" name="ojdbc6-11.2.0.jar" module-name="hsl" />
+      <element id="extracted-dir" path="$PROJECT_DIR$/lib/slf4j-api-1.7.21.jar" path-in-jar="/" />
+      <element id="library" level="module" name="log4j-1.2.15.jar" module-name="hsl" />
+      <element id="library" level="module" name="jackson-core-asl-1.9.13.jar" module-name="hsl" />
+      <element id="library" level="project" name="jsch-0.1.51-sources" />
+      <element id="library" level="module" name="jackson-mapper-asl-1.9.13.jar" module-name="hsl" />
+      <element id="extracted-dir" path="$PROJECT_DIR$/lib/commons-io-1.4.jar" path-in-jar="/" />
+      <element id="extracted-dir" path="$PROJECT_DIR$/lib/jsch-0.1.54.jar" path-in-jar="/" />
+      <element id="library" level="module" name="junit.jar" module-name="hsl" />
+      <element id="library" level="module" name="commons-net-3.6.jar" module-name="hsl" />
+      <element id="extracted-dir" path="$PROJECT_DIR$/lib/javax.servlet.jar" path-in-jar="/" />
+      <element id="library" level="module" name="dom4j-1.6.1.jar" module-name="hsl" />
+    </root>
+  </artifact>
+</component>

+ 7 - 0
.idea/compiler.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="CompilerConfiguration">
+    <option name="BUILD_PROCESS_HEAP_SIZE" value="2048" />
+    <bytecodeTargetLevel target="8" />
+  </component>
+</project>

+ 6 - 0
.idea/encodings.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="Encoding" defaultCharsetForPropertiesFiles="UTF-8" addBOMForNewFiles="with NO BOM">
+    <file url="PROJECT" charset="UTF-8" />
+  </component>
+</project>

+ 17 - 0
.idea/libraries/commons_csv_1_4.xml

@@ -0,0 +1,17 @@
+<component name="libraryTable">
+  <library name="commons-csv-1.4">
+    <CLASSES>
+      <root url="jar://$PROJECT_DIR$/lib/commons-csv-1.4.jar!/" />
+      <root url="jar://$PROJECT_DIR$/lib/ojdbc6-11.2.0.jar!/" />
+      <root url="jar://$PROJECT_DIR$/lib/commons-net-3.6.jar!/" />
+      <root url="jar://$PROJECT_DIR$/lib/dom4j-1.6.1.jar!/" />
+      <root url="jar://$PROJECT_DIR$/lib/flexjson-2.1.jar!/" />
+      <root url="jar://$PROJECT_DIR$/lib/jackson-core-asl-1.9.13.jar!/" />
+      <root url="jar://$PROJECT_DIR$/lib/jackson-mapper-asl-1.9.13.jar!/" />
+      <root url="jar://$PROJECT_DIR$/lib/junit.jar!/" />
+      <root url="jar://$PROJECT_DIR$/lib/log4j-1.2.15.jar!/" />
+    </CLASSES>
+    <JAVADOC />
+    <SOURCES />
+  </library>
+</component>

+ 9 - 0
.idea/libraries/commons_io_1_4.xml

@@ -0,0 +1,9 @@
+<component name="libraryTable">
+  <library name="commons-io-1.4">
+    <CLASSES>
+      <root url="jar://$PROJECT_DIR$/lib/commons-io-1.4.jar!/" />
+    </CLASSES>
+    <JAVADOC />
+    <SOURCES />
+  </library>
+</component>

+ 9 - 0
.idea/libraries/javax_servlet.xml

@@ -0,0 +1,9 @@
+<component name="libraryTable">
+  <library name="javax.servlet">
+    <CLASSES>
+      <root url="jar://$PROJECT_DIR$/lib/javax.servlet.jar!/" />
+    </CLASSES>
+    <JAVADOC />
+    <SOURCES />
+  </library>
+</component>

+ 9 - 0
.idea/libraries/jsch_0_1_51_sources.xml

@@ -0,0 +1,9 @@
+<component name="libraryTable">
+  <library name="jsch-0.1.51-sources">
+    <CLASSES />
+    <JAVADOC />
+    <SOURCES>
+      <root url="jar://$PROJECT_DIR$/lib/jsch-0.1.51-sources.jar!/" />
+    </SOURCES>
+  </library>
+</component>

+ 9 - 0
.idea/libraries/jsch_0_1_54.xml

@@ -0,0 +1,9 @@
+<component name="libraryTable">
+  <library name="jsch-0.1.54">
+    <CLASSES>
+      <root url="jar://$PROJECT_DIR$/lib/jsch-0.1.54.jar!/" />
+    </CLASSES>
+    <JAVADOC />
+    <SOURCES />
+  </library>
+</component>

+ 9 - 0
.idea/libraries/slf4j_api_1_7_21.xml

@@ -0,0 +1,9 @@
+<component name="libraryTable">
+  <library name="slf4j-api-1.7.21">
+    <CLASSES>
+      <root url="jar://$PROJECT_DIR$/lib/slf4j-api-1.7.21.jar!/" />
+    </CLASSES>
+    <JAVADOC />
+    <SOURCES />
+  </library>
+</component>

+ 82 - 0
.idea/misc.xml

@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="AndroidDexCompilerConfiguration">
+    <option name="MAX_HEAP_SIZE" value="2048" />
+  </component>
+  <component name="Kotlin2JsCompilerArguments">
+    <option name="sourceMapEmbedSources" />
+  </component>
+  <component name="ProjectInspectionProfilesVisibleTreeState">
+    <entry key="Project Default">
+      <profile-state>
+        <expanded-state>
+          <State />
+          <State>
+            <id>Class structureJava</id>
+          </State>
+          <State>
+            <id>Code maturityJava</id>
+          </State>
+          <State>
+            <id>Google Web Toolkit</id>
+          </State>
+          <State>
+            <id>JUnitJava</id>
+          </State>
+          <State>
+            <id>Java</id>
+          </State>
+          <State>
+            <id>Java 5Java language level migration aidsJava</id>
+          </State>
+          <State>
+            <id>Java 7Java language level migration aidsJava</id>
+          </State>
+          <State>
+            <id>Java 8Java language level migration aidsJava</id>
+          </State>
+          <State>
+            <id>Java language level migration aidsJava</id>
+          </State>
+          <State>
+            <id>JavadocJava</id>
+          </State>
+          <State>
+            <id>Numeric issuesJava</id>
+          </State>
+          <State>
+            <id>PerformanceJava</id>
+          </State>
+          <State>
+            <id>Spring</id>
+          </State>
+          <State>
+            <id>Spring AOPSpring</id>
+          </State>
+          <State>
+            <id>TestNGJava</id>
+          </State>
+          <State>
+            <id>Threading issuesJava</id>
+          </State>
+        </expanded-state>
+      </profile-state>
+    </entry>
+  </component>
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+    <output url="file://$PROJECT_DIR$/classes" />
+  </component>
+  <component name="SvnBranchConfigurationManager">
+    <option name="myConfigurationMap">
+      <map>
+        <entry key="$PROJECT_DIR$">
+          <value>
+            <SvnBranchConfiguration>
+              <option name="trunkUrl" value="svn+ssh://10.10.101.21/source/uas/hslftp" />
+            </SvnBranchConfiguration>
+          </value>
+        </entry>
+      </map>
+    </option>
+  </component>
+</project>

+ 8 - 0
.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/hsl.iml" filepath="$PROJECT_DIR$/hsl.iml" />
+    </modules>
+  </component>
+</project>

+ 7 - 0
.idea/vcs.xml

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="" vcs="svn" />
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

+ 12 - 0
.settings/org.eclipse.jdt.core.prefs

@@ -0,0 +1,12 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.7

+ 3 - 0
META-INF/MANIFEST.MF

@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Main-Class: com.uas.main.Main
+

+ 113 - 0
hsl.iml

@@ -0,0 +1,113 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4">
+  <component name="EclipseModuleManager">
+    <libelement value="file://D:/Documents/Tencent Files/396996717/FileRecv/jar/commons-csv-1.4.jar" />
+    <libelement value="file://D:/Documents/Tencent Files/396996717/FileRecv/jar/commons-net-3.6.jar" />
+    <libelement value="file://D:/Documents/Tencent Files/396996717/FileRecv/jar/dom4j-1.6.1.jar" />
+    <libelement value="file://D:/Documents/Tencent Files/396996717/FileRecv/jar/flexjson-2.1.jar" />
+    <libelement value="file://D:/Documents/Tencent Files/396996717/FileRecv/jar/jackson-core-asl-1.9.13.jar" />
+    <libelement value="file://D:/Documents/Tencent Files/396996717/FileRecv/jar/jackson-mapper-asl-1.9.13.jar" />
+    <libelement value="file://D:/Documents/Tencent Files/396996717/FileRecv/jar/junit.jar" />
+    <libelement value="file://D:/Documents/Tencent Files/396996717/FileRecv/jar/log4j-1.2.15.jar" />
+    <libelement value="file://D:/Documents/Tencent Files/396996717/FileRecv/jar/ojdbc6-11.2.0.jar" />
+    <src_description expected_position="1">
+      <src_folder value="file://$MODULE_DIR$/src" expected_position="1" />
+    </src_description>
+  </component>
+  <component name="NewModuleRootManager">
+    <output url="file://$MODULE_DIR$/bin" />
+    <exclude-output />
+    <content url="file://$MODULE_DIR$">
+      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="module-library">
+      <library name="commons-csv-1.4.jar">
+        <CLASSES>
+          <root url="file://D:/Documents/Tencent Files/396996717/FileRecv/jar/commons-csv-1.4.jar" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library name="commons-net-3.6.jar">
+        <CLASSES>
+          <root url="file://D:/Documents/Tencent Files/396996717/FileRecv/jar/commons-net-3.6.jar" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library name="dom4j-1.6.1.jar">
+        <CLASSES>
+          <root url="file://D:/Documents/Tencent Files/396996717/FileRecv/jar/dom4j-1.6.1.jar" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library name="flexjson-2.1.jar">
+        <CLASSES>
+          <root url="file://D:/Documents/Tencent Files/396996717/FileRecv/jar/flexjson-2.1.jar" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library name="jackson-core-asl-1.9.13.jar">
+        <CLASSES>
+          <root url="file://D:/Documents/Tencent Files/396996717/FileRecv/jar/jackson-core-asl-1.9.13.jar" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library name="jackson-mapper-asl-1.9.13.jar">
+        <CLASSES>
+          <root url="file://D:/Documents/Tencent Files/396996717/FileRecv/jar/jackson-mapper-asl-1.9.13.jar" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library name="junit.jar">
+        <CLASSES>
+          <root url="file://D:/Documents/Tencent Files/396996717/FileRecv/jar/junit.jar" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library name="log4j-1.2.15.jar">
+        <CLASSES>
+          <root url="file://D:/Documents/Tencent Files/396996717/FileRecv/jar/log4j-1.2.15.jar" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library name="ojdbc6-11.2.0.jar">
+        <CLASSES>
+          <root url="file://D:/Documents/Tencent Files/396996717/FileRecv/jar/ojdbc6-11.2.0.jar" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
+    <orderEntry type="library" name="commons-csv-1.4" level="project" />
+    <orderEntry type="library" name="jsch-0.1.51-sources" level="project" />
+    <orderEntry type="library" name="jsch-0.1.54" level="project" />
+    <orderEntry type="library" name="commons-io-1.4" level="project" />
+    <orderEntry type="library" name="slf4j-api-1.7.21" level="project" />
+    <orderEntry type="library" name="javax.servlet" level="project" />
+  </component>
+</module>

BIN
lib/commons-csv-1.4.jar


BIN
lib/commons-io-1.4.jar


BIN
lib/commons-net-3.6.jar


BIN
lib/dom4j-1.6.1.jar


BIN
lib/flexjson-2.1.jar


BIN
lib/jackson-core-asl-1.9.13.jar


BIN
lib/jackson-mapper-asl-1.9.13.jar


BIN
lib/javax.servlet.jar


BIN
lib/jsch-0.1.54.jar


BIN
lib/junit.jar


BIN
lib/log4j-1.2.15.jar


BIN
lib/ojdbc6-11.2.0.jar


BIN
lib/slf4j-api-1.7.21.jar


File diff suppressed because it is too large
+ 2 - 0
my.log


+ 549 - 0
src/com/uas/main/Download.java

@@ -0,0 +1,549 @@
+package com.uas.main;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.*;
+
+import com.jcraft.jsch.ChannelSftp;
+import com.jcraft.jsch.JSchException;
+import com.uas.util.SFTPUtil;
+import org.apache.commons.net.ftp.FTPClient;
+import org.codehaus.jackson.JsonGenerationException;
+import org.codehaus.jackson.map.JsonMappingException;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.dom4j.Document;
+import org.dom4j.Element;
+import org.dom4j.io.SAXReader;
+
+import com.uas.util.BaseUtil;
+import com.uas.util.FtpUtil;
+import com.uas.util.JdbcUtil;
+
+public class Download{
+
+	public static Boolean checkXmlFileToSqlToEnterprise(File file,String enterprise){
+		String ent = null;
+		Element root = getElementRoot(file);  //获取根节点
+		Map<String, String> mainData = getMainData(root); //获取主表数据 {tag:data}
+		ent = mainData.get("ENTERPRISE");
+		if (ent==null) {
+			return true;
+		}else {
+			return ent.equals(enterprise);
+		}
+	}
+	
+	/*
+	 * 通过配置解析xml为sql语句
+	 */
+	public static List<String> parseXmlFileToSqls(File file,Statement statement){
+		List<String> sqls = new ArrayList<String>();
+		Statement stm=statement;
+		String mainTableUpdateSql = null;
+		String updateDetailConditon = null;
+		List<Map<String,String>> detailXmlConfig = null;
+		List<Map<String,String>> detailData = null;
+		
+		String fileName = file.getName().substring(0, file.getName().indexOf(".")) + ".xml";
+		String filePrefix = fileName.substring(0,fileName.indexOf("_")+1); //获取文件名前缀
+		String docType = null;
+		List<String> logSql = new ArrayList<String>();
+		
+		Element root = getElementRoot(file);  //获取根节点
+		Map<String, String> mainData = getMainData(root); //获取主表数据 {tag:data}
+		Element detail = root.element("Detail");  //获取明细节点
+		if(detail!=null){
+			detailData = getDetailData(root);  //获取明细数据
+		}
+		
+		docType = mainData.get("DOC_TYPE"); //文件类型
+		Map<String,String> xmlConfig = getXmlConfig(statement,docType,filePrefix); //通过文件名前缀查找相应配置
+		if(xmlConfig.keySet().size()==0){
+			return null;
+		}
+		String caller=xmlConfig.get("xd_caller");
+		List<Map<String,String>> mainXmlConfig = getXmlConfigDetail(statement,xmlConfig.get("xd_id"),"0",xmlConfig.get("xd_main_conditiontag")); //获取主表的配置
+		if(xmlConfig.get("xd_detail_conditiontag")!=null&&detailData!=null){
+			if("Packing".equals(caller)||"Invoice".equals(caller)){
+			detailXmlConfig = getXmlConfigDetail(statement,xmlConfig.get("xd_id"),"1"); //获取明细表的配置	
+			}else
+				detailXmlConfig = getXmlConfigDetail(statement,xmlConfig.get("xd_id"),"1",xmlConfig.get("xd_detail_conditiontag")); //获取明细表的配置	
+		}		
+		
+		String updateMainConditon = getUpdateMainCondtion(mainData,xmlConfig); //主表更新条件
+		String maincode = mainData.get(xmlConfig.get("xd_main_conditiontag"));
+		if(mainXmlConfig.size()>0){
+			mainTableUpdateSql = getUpdateMainFields(mainData,xmlConfig,mainXmlConfig); //主表更新字段
+			mainTableUpdateSql += " where " + updateMainConditon;
+			sqls.add(mainTableUpdateSql);
+		}
+		if(detailXmlConfig!=null&&detailXmlConfig.size()>0){
+			updateDetailConditon = getUpdateDetailConditionByMainTable(mainData,xmlConfig); //明细表跟主表关联更新条件
+			for(Map<String,String> data:detailData){
+				String sql = null;
+				if("Packing".equals(caller)||"Invoice".equals(caller)){
+					sql = getInsertDetailSql(maincode,data,xmlConfig,detailXmlConfig);
+				}else{
+					sql = getUpdateDetailSql(data,xmlConfig,detailXmlConfig) + " and " + updateDetailConditon;
+				}
+				sqls.add(sql);
+			}
+		}
+		
+		//记录json数据
+		logSql = getLogXmlDataAndInterceptorSql(mainData,detailData,xmlConfig,statement,fileName);
+		sqls.addAll(logSql);
+		try {
+			stm.close();
+		} catch (SQLException e1) {
+			e1.printStackTrace();
+		}
+
+		return sqls;
+	}
+
+	@SuppressWarnings("finally")
+	private static List<String> getLogXmlDataAndInterceptorSql(Map<String, String> mainData,List<Map<String,String>> detailData,Map<String,String> xmlConfig,Statement statement,String fileName){
+		ObjectMapper mapper = new ObjectMapper();
+		String jsonData = null;
+		String log = null;
+		String caller = null;
+		int id = 0;
+		ResultSet rs = null;
+		
+		List<String> sqls = new ArrayList<String>();
+		
+		try {
+			jsonData = mapper.writeValueAsString(mainData);
+			
+			if(detailData!=null){
+				String detailJsonData = mapper.writeValueAsString(detailData);
+				jsonData = jsonData.substring(0,jsonData.length()-1) + ",DETAIL:" + detailJsonData + "}";
+			}
+
+			String code = null;
+			code = mainData.get(xmlConfig.get("xd_main_codexmltag"));
+			caller = xmlConfig.get("xd_caller");
+			
+			
+			id = JdbcUtil.getIdBySeq("xmldatalog_seq");
+			if(!("Packing".equals(caller)||"Invoice".equals(caller))){
+				log = "insert into xmldatalog(xl_id,xl_data,xl_date,xl_caller,xl_code,xl_from,xl_filename) values ("
+						+ id + ",'"+jsonData.replaceAll("'", "''")+"',sysdate,'"+caller
+						+ "','"+code+"','download','"+fileName+"')";
+				sqls.add(log);				
+			}else{
+				//由于packing和invoice回复文件可能字段串过长,暂不存入xl_data
+				log = "insert into xmldatalog(xl_id,xl_data,xl_date,xl_caller,xl_code,xl_from,xl_filename) values ("
+						+ id + ",null,sysdate,'"+caller
+						+ "','"+code+"','download','"+fileName+"')";
+				sqls.add(log);					
+			}
+
+			if(!("Packing".equals(caller)||"Invoice".equals(caller))){
+				//common interceptors 主要用于自动过账
+				rs = statement.executeQuery("select id from interceptors where caller='"+caller+"' "
+						+ "and class_='com.uas.erp.service.common.impl.CommonHandler' "
+						+ "and method='exec_handler' and type='xmltrans' and enable=1");
+				while(rs.next()){
+					sqls.add("declare out varchar2(500);begin SP_COMMONHANDLER("+id+"," + rs.getString("id") + ",out);end;");
+				}	
+			}else {
+				sqls.add("declare out varchar2(500);begin SP_XMLTEMPPARSE("+id+",'" + caller + "',out);end;");
+			}
+		} catch (IOException e) {
+			e.printStackTrace();
+		}finally{
+			return sqls;
+		}
+	}
+	
+	/*
+	 * 获取明细表更新sql
+	 */
+	public static String getUpdateDetailSql(Map<String, String> data,Map<String,String> xmlConfig,List<Map<String,String>> detailXmlConfig){
+		StringBuffer sb = new StringBuffer();
+		String sql = null;
+		String condition = null;
+		String resSql = null;
+		sql = "update " + xmlConfig.get("xd_detailtable") + " set ";
+		for(Map<String,String> map:detailXmlConfig){
+			if ("D".equals(map.get("fieldtype"))) {
+				sb.append("," + map.get("uasfield") + "=to_date('" + data.get(map.get("xmltag"))+ "'," + "'YYYY-MM-DD HH24:mi:ss'" + ")");
+			} else{
+				sb.append("," + map.get("uasfield") + "='" + data.get(map.get("xmltag")) + "'");
+			}
+		}
+		condition = getUpdateDetailCondition(data,xmlConfig);
+		resSql = sql + sb.substring(1,sb.length()) + " where " + condition;
+		return resSql;
+	}
+	
+	/*
+	 * 获取添加临时表数据sql
+	 */
+	public static String getInsertDetailSql(String maincode,Map<String, String> data,Map<String,String> xmlConfig,List<Map<String,String>> detailXmlConfig){
+		StringBuffer sb = new StringBuffer();
+		StringBuffer sb2 =new StringBuffer();
+		String sql = null;
+		String resSql = null;
+		String caller=xmlConfig.get("xd_caller");
+			sql = "insert into "+xmlConfig.get("xd_detailtable")+" (";
+			for(Map<String,String> map:detailXmlConfig){
+				sb.append("," + map.get("uasfield"));
+			}
+			if("Packing".equals(caller)){
+				sb.append(",pdt_piid,pdt_id,pdt_status,pdt_indate) values (");
+			}else if ("Invoice".equals(caller)){
+				sb.append(",idt_inid,idt_id,idt_status,idt_indate) values (");
+			}
+			sql=sql+sb.substring(1,sb.length());
+			for(Map<String,String> map:detailXmlConfig){
+				if ("D".equals(map.get("fieldtype"))) {
+					sb2.append("," + "=to_date('" + data.get(map.get("xmltag"))+ "'," + "'YYYY-MM-DD HH24:mi:ss'" + ")");
+				} else if("N".equals(map.get("fieldtype"))){
+					sb2.append("," + data.get(map.get("xmltag")));
+				}	else{
+					if (data.get(map.get("xmltag"))==null){
+						data.put(map.get("xmltag")," ");
+					}
+					sb2.append(",'" + data.get(map.get("xmltag")) + "'");
+				}
+			}
+			sb2.append(",(select "+xmlConfig.get("xd_keyfield")+" from "+xmlConfig.get("xd_table")
+					+" where "+xmlConfig.get("xd_main_conditionfield")+"='"+maincode+"')");
+			sb2.append(","+xmlConfig.get("xd_detailtable")+"_seq.nextval,'UNPARSE',sysdate)");
+			resSql=sql+sb2.substring(1,sb2.length());
+		return resSql;
+	}
+	
+	/*
+	 * 获取明细表和主表关联的更新条件
+	 */
+	public static String getUpdateDetailConditionByMainTable(Map<String, String> mainData,Map<String,String> xmlConfig){
+		String mainConditionField = xmlConfig.get("xd_main_conditionfield");
+		String mainConditionTag = xmlConfig.get("xd_main_conditiontag");
+		String[] fields = mainConditionField.split(",");
+		String[] tags = mainConditionTag.split(",");
+		StringBuffer sql = new StringBuffer();
+		StringBuffer sb = new StringBuffer();
+		sql.append(xmlConfig.get("xd_detail_foreignkey") + "=(select "+xmlConfig.get("xd_keyfield")+" from "+xmlConfig.get("xd_table")+" where ");
+		for(int i=0;i<fields.length;i++){
+			if(mainData.get(tags[i])!=null){
+				if(sb.length()>0){
+					sb.append(" and " + fields[i] + "='" + mainData.get(tags[i]) + "'");
+				}else{
+					sb.append(" " + fields[i] + "='" + mainData.get(tags[i]) + "'");
+				}				
+			}
+		}
+		sql.append(sb + ")");
+		return sql.toString();
+	}
+	
+	/*
+	 * 获取更新主表字段的sql
+	 */
+	public static String getUpdateMainFields(Map<String, String> mainData,Map<String,String> xmlConfig,List<Map<String,String>> mainXmlConfig){
+		StringBuffer sb = new StringBuffer();
+		String update = "update " + xmlConfig.get("xd_table") + " set ";
+		for(Map<String,String> map:mainXmlConfig){
+			if ("D".equals(map.get("fieldtype"))) {
+				sb.append("," + map.get("uasfield") + "=to_date('" + mainData.get(map.get("xmltag"))+ "'," + "'YYYY-MM-DD HH24:mi:ss'" + ")");
+			} else{
+				sb.append("," + map.get("uasfield") + "='" + mainData.get(map.get("xmltag")) + "'");
+			}
+		}
+		return update + sb.substring(1);
+	}	
+	
+	/*
+	 * 获取主表更新条件
+	 */
+	public static String getUpdateMainCondtion(Map<String, String> mainData,Map<String,String> xmlConfig){
+		String mainConditionField = xmlConfig.get("xd_main_conditionfield");
+		String mainConditionTag = xmlConfig.get("xd_main_conditiontag");
+		String[] fields = mainConditionField.split(",");
+		String[] tags = mainConditionTag.split(",");
+		StringBuffer sb = new StringBuffer();
+		for(int i=0;i<fields.length;i++){
+			if(mainData.get(tags[i])!=null){
+				if(sb.length()>0){
+					sb.append(" and " + fields[i] + "='" + mainData.get(tags[i]) + "'");
+				}else{
+					sb.append(" " + fields[i] + "='" + mainData.get(tags[i]) + "'");
+				}				
+			}
+		}
+		return sb.toString();
+	}
+	
+	/*
+	 * 获取更新明细表的条件
+	 */
+	public static String getUpdateDetailCondition(Map<String, String> mainData,Map<String,String> xmlConfig){
+		String mainConditionField = xmlConfig.get("xd_detail_conditionfield");
+		String mainConditionTag = xmlConfig.get("xd_detail_conditiontag");
+		String[] fields = mainConditionField.split(",");
+		String[] tags = mainConditionTag.split(",");
+		StringBuffer sb = new StringBuffer();
+		for(int i=0;i<fields.length;i++){
+			if(mainData.get(tags[i])!=null){
+				if(sb.length()>0){
+					sb.append(" and " + fields[i] + "='" + mainData.get(tags[i]) + "'");
+				}else{
+					sb.append(" " + fields[i] + "='" + mainData.get(tags[i]) + "'");
+				}				
+			}
+		}
+		return sb.toString();
+	}
+	
+	/*
+	 * 获取xmldataconfigdetail配置
+	 */
+	public static List<Map<String,String>> getXmlConfigDetail(Statement statement,String id,String type,String conditiontag){
+		List<Map<String,String>> list = new ArrayList<Map<String,String>>();
+		
+		ResultSet rs = null;
+		try{
+			rs = statement.executeQuery("select * from xmldataconfigdetail where nvl(uasfield,' ')<>' ' and isdetail="+type+" and xdid=" + id + " and xmltag not in ('" + conditiontag.replaceAll(",", "','") + "')");
+			while(rs.next()){
+				Map<String,String> map = new HashMap<String,String>();
+				map.put("xmltag", rs.getString("xmltag"));
+				map.put("uasfield", rs.getString("uasfield"));
+				map.put("fieldtype", rs.getString("fieldtype"));
+				list.add(map);
+			}
+			rs.close();
+		}catch(SQLException e){
+			e.printStackTrace();
+		}
+		return list;		
+	}
+	
+	/*
+	 * 获取xmldataconfigdetail配置
+	 */
+	public static List<Map<String,String>> getXmlConfigDetail(Statement statement,String id,String type){
+		List<Map<String,String>> list = new ArrayList<Map<String,String>>();
+		
+		ResultSet rs = null;
+		try{
+			rs = statement.executeQuery("select * from xmldataconfigdetail where nvl(uasfield,' ')<>' ' and isdetail="+type+" and xdid=" + id);
+			while(rs.next()){
+				Map<String,String> map = new HashMap<String,String>();
+				map.put("xmltag", rs.getString("xmltag"));
+				map.put("uasfield", rs.getString("uasfield"));
+				map.put("fieldtype", rs.getString("fieldtype"));
+				list.add(map);
+			}
+			rs.close();
+		}catch(SQLException e){
+			e.printStackTrace();
+		}
+		return list;		
+	}
+	
+	/*
+	 * 获取xmldataconfig配置
+	 */
+	public static Map<String,String> getXmlConfig(Statement statement,String docType,String filePrefix){
+		Map<String,String> map = new HashMap<String,String>();
+		ResultSet rs = null;
+		try{
+			if(docType==null){
+				rs = statement.executeQuery("select * from xmldataconfig  where xd_fileprefix='"+ filePrefix + "' and xd_type='DOWNLOAD'");
+			}else{
+				rs = statement.executeQuery("select * from xmldataconfig  where xd_doctype='"+ docType + "' and xd_type='DOWNLOAD' and xd_fileprefix='"+ filePrefix + "'");
+			}
+			if(rs.next()){
+				map.put("xd_id", rs.getString("xd_id"));
+				map.put("xd_table", rs.getString("xd_table"));
+				map.put("xd_detailtable", rs.getString("xd_detailtable"));
+				map.put("xd_caller", rs.getString("xd_caller"));
+				map.put("xd_keyfield", rs.getString("xd_keyfield"));
+				map.put("xd_main_conditiontag", rs.getString("xd_main_conditiontag"));
+				map.put("xd_main_conditionfield", rs.getString("xd_main_conditionfield"));
+				map.put("xd_detail_conditiontag", rs.getString("xd_detail_conditiontag"));
+				map.put("xd_detail_conditionfield", rs.getString("xd_detail_conditionfield"));
+				map.put("xd_detail_foreignkey", rs.getString("xd_detail_foreignkey"));
+				map.put("xd_main_codexmltag",rs.getString("xd_main_codexmltag"));
+			}
+			rs.close();
+		}catch(SQLException e){
+			e.printStackTrace();
+		}
+		return map;
+	}
+	
+	/*
+	 * 获取根节点
+	 */
+	public static Element getElementRoot(File file){
+        Element element = null;
+		try {
+			InputStream in = new FileInputStream(file);
+            SAXReader reader = new SAXReader();
+            Document doc = reader.read(in);
+            in.close();
+            element = doc.getRootElement();
+        } catch (Exception e) {
+			e.printStackTrace();
+		}
+        return element;
+	}
+	
+
+	/*
+	 * 获取主表数据
+	 */
+	@SuppressWarnings("unchecked")
+	private static Map<String, String> getMainData(Element root) {
+		Map<String, String> data=new HashMap<String,String>();
+	    List<Element> e = root.element("Header").elements();
+		for(Element el:e){
+			data.put(el.getName(),el.getData()==null?"":el.getData().toString());
+    	}
+		return data;
+	}
+	
+	/*
+	 * 获取明细表数据
+	 */
+	@SuppressWarnings("unchecked")
+	private static List<Map<String, String>> getDetailData(Element root) {
+		List<Map<String, String>> data=new ArrayList<Map<String,String>>();
+	    List<Element> items  = root.element("Detail").elements("Item");
+		for(Element el:items){
+			Map<String, String> detail = new HashMap<String,String>();
+			List<Element> e= el.elements();
+			for(Element i:e){
+				detail.put(i.getName(),i.getData()==null?"":i.getData().toString());
+			}
+			data.add(detail);
+    	}
+		return data;
+	}			
+    public static void run(){
+		downloadByDepotAndSob("N_YITOA_LHCT-SF","N_YITOA_LHCT","聯合創泰科技有限公司"); //联合创泰-顺丰
+		downloadByDepotAndSob("N_YITOA_LHCT-QF","N_YITOA_LHCT","聯合創泰科技有限公司"); //联合创泰-旗丰
+    	downloadByDepotAndSob("N_HUASL-XN","N_HUASL","香港华商龙"); //华商龙-新宁
+    	downloadByDepotAndSob("N_HUASL-QF","N_HUASL","香港华商龙");//华商龙-旗丰
+    	downloadByDepotAndSob("N_WILICHK-QF","N_WILICHK","(华商龙)威尔电子");//威尔电子-旗丰
+    	downloadByDepotAndSob("N_BJKG-QF","N_BJKG","柏建控股");//柏建控股-旗丰    	
+    	
+    	
+    	
+//    	downloadByDepotAndSob("N_HUASL-JS","N_HUASL"); //华商龙-嘉晟
+//    	downloadByDepotAndSob("N_WILICHK-JS","N_WILICHK"); //威尔电子-嘉晟
+//    	downloadByDepotAndSob("N_BJKG-JS","N_BJKG"); //柏建控股-嘉晟
+//    	downloadByDepotAndSob("USOFT_MALL_HK-JS","USOFT_MALL_HK"); //优软商城香港-嘉晟
+//    	downloadByDepotAndSob("t_n_huasl-QF","t_n_huasl");
+
+	}
+	
+	@SuppressWarnings("unchecked")
+	public static void downloadByDepotAndSob(String depot,String sob,String enterprise){
+		FTPClient client = null;
+		SFTPUtil sftp = null;
+		List<String> sqls = new ArrayList<String>();
+		boolean executeRes = false;
+		Connection connect = null;
+		
+    	try {
+    		Map<String,Object> servMap = JdbcUtil.getFtpConfigs();
+			Map<String,Object> ftpMap = (Map<String,Object>)servMap.get(depot);
+			if ("N_YITOA_LHCT-SF".equals(depot)){
+				sftp = new SFTPUtil(ftpMap.get("user").toString(),ftpMap.get("password").toString(),
+						ftpMap.get("ip").toString(),
+						Integer.parseInt(ftpMap.get("port").toString()));
+				try {
+					sftp.login();
+				} catch (JSchException e) {
+					e.printStackTrace();
+				}
+			}else {
+				client = FtpUtil.connect(ftpMap);
+			}
+			if(client!=null||sftp!=null){
+				List<File> files = null;
+				if ("N_YITOA_LHCT-SF".equals(depot)){
+					files = sftp.download(ftpMap.get("downloadpath").toString());
+
+				}else {
+					files = FtpUtil.downloadAllFileByType(client,"XML");
+				}
+				String fileName = "";
+				if(files!=null&&files.size()>0){
+					connect = JdbcUtil.getConnectBySob(sob);
+					if(connect!=null){
+						for (File file:files)
+							try {
+								fileName += "," + file.getName();
+								Statement statement = connect.createStatement();
+								System.err.println(statement);
+								//判断当前帐套和文件是否一致
+								if (!checkXmlFileToSqlToEnterprise(file, enterprise)) {
+									continue;
+								}
+								sqls = parseXmlFileToSqls(file, statement);
+								if (sqls == null) {
+									continue;
+								}
+
+								executeRes = JdbcUtil.executeSqls(connect, sqls);
+
+								if (executeRes) {
+									if ("N_YITOA_LHCT-SF".equals(depot)) {
+										String s = file.getName().substring(0, file.getName().indexOf(".")) + ".xml";
+										Boolean rename = sftp.rename(ftpMap.get("downloadpath").toString()+"/"+s, "goodsreceipt/backup/"+s);
+										//System.err.println(rename);
+									} else {
+										client.rename(file.getName(), "bak/" + file.getName()); //移动处理完的文件到bak文件夹下
+									}
+								}
+								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){
+				FtpUtil.closeFtpClient(client);		
+				client = null;
+			}
+			if (sftp!=null){
+				sftp.logout();
+			}
+			//把当前的连接关闭
+			try {
+				if(connect!=null){
+					connect.close();
+				}
+			} catch (SQLException e) {
+				e.printStackTrace();
+			}finally{
+				connect = null;
+			}
+		}
+	}
+ }

+ 70 - 0
src/com/uas/main/Main.java

@@ -0,0 +1,70 @@
+package com.uas.main;
+import com.uas.util.BaseUtil;
+import com.uas.util.FtpUtil;
+import com.uas.util.JdbcUtil;
+
+import static com.uas.main.Upload.*;
+
+public class Main {
+	
+	public static void main(String[] args) {
+		/*boolean connect = false;
+		try {
+			connect = FtpUtil.connect("/TO_QF/", "112.74.205.182",
+					21, "YTZH02", "Ytzh)@2018");
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		System.err.println(connect);*/
+		 
+	   final long timeInterval =5*60*1000;
+	        Runnable runnable = new Runnable() {  
+	            public void run() {  
+	                while (true) {  
+	                    // ------- code for task to run  
+	                    a();
+	                    // ------- ends here  
+	                    try {  
+	                        Thread.sleep(timeInterval);  
+	                    } catch (InterruptedException e) {  
+	                        e.printStackTrace();  
+	                    }  
+	                }  
+	            }  
+	        };  
+	        Thread thread = new Thread(runnable);  
+	        thread.start();
+/*
+        boolean connect = false;
+        try {
+            connect = FtpUtil.connect("/stockin/data/", "218.17.248.243",
+                    45301, "wms_ufct", "ZjJ05GFV");
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        System.err.println(connect);*/
+	/*String sob = "N_YITOA_LHCT";
+	Upload.uploadBySob(sob);*/
+    }
+	
+	
+	
+	public static  void a() {
+		run();
+		System.out.println("begin");
+		Download.run();	
+		
+		try{ //关闭数据库连接
+			if(JdbcUtil.connection!=null){
+				JdbcUtil.connection.close();
+			}
+		}catch(Exception e){
+			BaseUtil.getLogger().error(e.toString());
+			e.printStackTrace();
+		}finally{
+			JdbcUtil.connection = null;
+		}
+		System.out.println("run over!");
+	}
+
+}

+ 213 - 0
src/com/uas/main/Upload.java

@@ -0,0 +1,213 @@
+package com.uas.main;
+
+import java.io.*;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+import com.jcraft.jsch.JSchException;
+import com.uas.util.SFTPUtil;
+import org.apache.commons.net.ftp.FTPClient;
+import org.codehaus.jackson.map.ObjectMapper;
+
+import com.uas.util.BaseUtil;
+import com.uas.util.FtpUtil;
+import com.uas.util.JdbcUtil;
+
+public class Upload {
+	public static Pattern pat = Pattern.compile("\\{(.*?)\\}");	
+	
+	public static 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;
+	}
+	
+	
+	public static 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;
+		}
+	}
+	
+	public static 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;
+	}
+	
+	public static 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");	
+	}
+	
+	public static void run() {
+		uploadBySob("N_HUASL"); //华商龙
+		uploadBySob("N_YITOA_LHCT");//联合创泰
+		uploadBySob("N_WILICHK"); //威尔电子
+		uploadBySob("N_BJKG"); //柏建控股
+		uploadBySob("USOFT_MALL_HK"); //优软商城香港
+	}
+	
+	@SuppressWarnings({ "unchecked"})
+	public static void uploadBySob(String sob) {		
+		Statement statement = null;
+		FTPClient client = null;
+		SFTPUtil sftp = null;
+		String xldata = null;
+		String fileprefix = null;
+		String xldate = null;
+		String xlid = null;
+		String xldepot = null;
+		Map<String,Object> ftpConfig = JdbcUtil.getFtpConfigs();			
+		Map<String,Object> config = null;
+		Connection connect = null;
+		try{
+			connect = JdbcUtil.getConnectBySob(sob);
+			if(connect!=null){
+				statement = connect.createStatement();
+				ResultSet rs = 	getXmlData(statement);	
+				String depot = "";	
+				while(rs.next()){	
+					try{
+						xldata = rs.getString("xl_data");
+						fileprefix = rs.getString("xl_fileprefix");
+						xldate = rs.getString("xl_date");
+						xlid = rs.getString("xl_id");
+						xldepot = rs.getString("xl_depot");
+
+						if(xldata!=null&&xldate!=null){
+							if(!depot.equals(xldepot)){ //连接ftp站点
+								if(client!=null){
+									FtpUtil.closeFtpClient(client);
+								}
+								depot = xldepot;
+								config = (Map<String,Object>)ftpConfig.get(sob + "-" + depot); //注意上传位置是数据库名+xl_depot
+								if(config==null){
+									continue;
+								}
+								System.out.println(config);
+								if ("SF".equals(depot)){
+									sftp = new SFTPUtil(config.get("user").toString(),config.get("password").toString(),config.get("ip").toString(),
+											Integer.parseInt(config.get("port").toString()));
+									try {
+										sftp.login();
+									} catch (JSchException e) {
+										e.printStackTrace();
+									}
+								}else {
+									client = FtpUtil.connect(config,config.get("in").toString());
+								}
+								if(client==null&&sftp==null){
+									continue;
+								}
+							}
+							
+							if(config==null){
+								continue;
+							}
+							
+							String folder = config.get("in").toString();
+							if(xldata==null||"".equals(xldata)){ 
+								continue;
+							}
+
+							boolean uploadSuccess = false;
+							File file = createXmlFile(xldata,xlid,folder,fileprefix,xldate); //生成文件
+							if (client!=null) {
+								uploadSuccess = upload(client, config.get("ip").toString(), folder, file);
+							}
+							if (sftp!=null){
+								InputStream is = new FileInputStream(file);
+								uploadSuccess = sftp.upload("/", folder, file.getName(), is);
+							}
+							if(uploadSuccess){ //如果文件上传成功,则转入正式数据记录表
+								turnToFormal(JdbcUtil.getConnect(),xlid,file.getName()); //转入正式
+							}														
+						}						
+					}catch(Exception e){
+						e.printStackTrace();
+						BaseUtil.getLogger().error(e.toString());
+						continue;
+					}
+				}	
+				rs.close();
+			}
+		}catch(Exception e){
+			BaseUtil.getLogger().error(e.toString());
+			e.printStackTrace();
+		}finally{
+			if(statement!=null){
+				try {
+					statement.close();
+				} catch (SQLException e1) {
+					BaseUtil.getLogger().error(e1.toString());
+					e1.printStackTrace();
+				}
+				statement = null;				
+			}
+			/*if(client!=null){
+				FtpUtil.closeFtpClient(client);
+			}*/
+			//把当前的连接关闭
+			try {
+				if(connect!=null){
+					connect.close();
+				}
+			} catch (SQLException e) {
+				e.printStackTrace();
+			}finally{
+				connect = null;
+			}
+		}
+
+	}
+}

+ 35 - 0
src/com/uas/util/BaseUtil.java

@@ -0,0 +1,35 @@
+package com.uas.util;
+
+import java.io.IOException;
+import java.util.Properties;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+
+
+public class BaseUtil {
+	public static Logger logger;
+	
+	/**
+	 * 获取日志类
+	 * @return 日志类
+	 */
+	public static Logger getLogger(){
+		if(logger==null){
+			logger = Logger.getLogger(BaseUtil.class);
+		    //loger所需的配置文件路径   
+			Properties prop = new Properties();
+		    try {
+				prop.load(BaseUtil.class.getResourceAsStream("/properties/log4j.properties"));
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+		    PropertyConfigurator.configure(prop); 
+		}
+		return logger;
+	}
+	
+	public static void logDownload(String fileName,String ip,String downloadpath){
+		getLogger().info("download " + fileName + " from " + ip + " path:" + downloadpath);
+	}
+}

+ 199 - 0
src/com/uas/util/FtpUtil.java

@@ -0,0 +1,199 @@
+package com.uas.util;
+
+import java.io.File;
+import java.io.FileInputStream;
+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 com.jcraft.jsch.JSchException;
+import org.apache.commons.net.ftp.FTP;
+import org.apache.commons.net.ftp.FTPClient;
+import org.apache.commons.net.ftp.FTPFile;
+import org.apache.commons.net.ftp.FTPReply;
+
+public class FtpUtil {
+	/**
+	 * 连接到ftp站点,判断是否可以连接
+	 * @param path  要连接到的目录
+	 * @param addr  站点地址
+	 * @param port  端口
+	 * @param username 用户名
+	 * @param password 密码
+	 * @return
+	 * @throws Exception
+	 */
+	public static boolean connect(String path, String addr, int port, String username,
+			String password) {
+		boolean result = false;
+		try {
+			FTPClient ftp = new FTPClient();
+			int reply;
+			ftp.connect(addr, port);
+			ftp.login(username, password);
+			ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
+			reply = ftp.getReplyCode();
+			if (!FTPReply.isPositiveCompletion(reply)) {
+				ftp.disconnect();
+				return result;
+			}
+			ftp.changeWorkingDirectory(path);
+			result = true;
+			return result;
+		}catch (Exception e){
+			SFTPUtil sftp = new SFTPUtil(username, password, addr, port);
+			try {
+				sftp.login();
+				result = true;
+			} catch (JSchException e1) {
+				e1.printStackTrace();
+			}
+			return result;
+		}
+	}
+	
+	/**
+	 * 获取ftp连接,该连接指向ftp配置中的downloadpath文件夹
+	 * @param map 包含ftp连接配置的map
+	 */
+	public static FTPClient connect(Map<String,Object> map) throws Exception {
+		return connect(map,map.get("downloadpath").toString());
+	}
+
+	/**
+	 * 获取ftp连接,该连接指向ftp配置中的downloadpath文件夹
+	 * @param map 包含ftp连接配置的map
+	 */
+	public static FTPClient connect(Map<String,Object> map,String path){
+		FTPClient ftp = null;
+		String addr = null;
+		try{
+			addr = map.get("ip").toString();
+			int port = Integer.parseInt(map.get("port").toString());
+			String username = map.get("user").toString();
+			String password = map.get("password").toString();
+			ftp = new FTPClient();
+			int reply;
+			ftp.connect(addr, port);
+			if(!ftp.login(username, password)){
+				return null;
+			}
+			ftp.setFileType(FTPClient.BINARY_FILE_TYPE);
+			reply = ftp.getReplyCode();
+			if (!FTPReply.isPositiveCompletion(reply)) {
+				ftp.disconnect();
+				return null;
+			}
+			ftp.changeWorkingDirectory(path);
+			return ftp;			
+		}catch(Exception e){ 
+			e.printStackTrace();
+			BaseUtil.getLogger().error("ip:" + addr + e.toString());
+			return null;
+		}
+	}
+
+	/**
+	 * 上传文件
+	 * @param ftpClient 已连接的ftp客户端
+	 * @param pathname 路径
+	 * @param file 待上传的文件
+	 * @return 上传结果
+	 */
+	public static boolean uploadFile(FTPClient ftpClient, String pathname, File file) {
+		boolean flag = false;
+		ftpClient.setControlEncoding("UTF-8");
+		try {
+			ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
+			boolean change = ftpClient.changeWorkingDirectory("/"+pathname);
+			if(!change){
+				BaseUtil.getLogger().info("change to " + pathname + " fail");
+				return false;
+			}
+			InputStream inputStream = new FileInputStream(file);
+			ftpClient.enterLocalPassiveMode();
+			ftpClient.storeFile(file.getName(), inputStream);
+			inputStream.close();
+			//ftpClient.logout();
+			flag = true;
+		} catch (Exception e) {
+			e.printStackTrace();
+			BaseUtil.getLogger().error(e.toString());
+			if (ftpClient.isConnected()) {
+				try {
+					ftpClient.disconnect();
+				} catch (IOException e1) {
+					BaseUtil.getLogger().error(e1.toString());
+					e1.printStackTrace();
+				}
+			}
+		}
+		return flag;
+	}
+	
+	/**
+	 * 删除后关闭ftp连接
+	 * @param ftpClient 
+	 * @param filename 要删除的文件名
+	 * @return 删除结果
+	 */
+	public static boolean deleteFile(FTPClient ftpClient,String filename) {
+		boolean flag = false;
+		try {
+			ftpClient.dele(filename);
+			flag = true;
+		} catch (Exception e) {
+			BaseUtil.getLogger().error(e.toString());
+			e.printStackTrace();
+		}
+		return flag;
+	}
+
+	/**
+	 * 
+	 * @param ftpClient
+	 * fileType 需要下载的文件类型
+	 * @return 获取连接到的ftp站点下的文件夹所有文件
+	 */
+	public static List<File> downloadAllFileByType(FTPClient ftpClient,String fileType) {
+		List<File> files = new ArrayList<File>();	
+		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);					
+				}
+			}
+		} catch (Exception e) {
+			BaseUtil.getLogger().error(e.toString());
+			e.printStackTrace();
+		}
+		return files;
+	}
+	
+	/**
+	 * 关闭ftp连接
+	 * @param ftpClient
+	 */
+	public static void closeFtpClient(FTPClient ftpClient){
+		if (ftpClient.isConnected()) {
+			try {
+				ftpClient.logout();
+			} catch (IOException e) {
+				BaseUtil.getLogger().error(e.toString());
+			}
+		}		
+	}
+	
+}

+ 257 - 0
src/com/uas/util/JdbcUtil.java

@@ -0,0 +1,257 @@
+package com.uas.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.codehaus.jackson.map.ObjectMapper;
+
+public class JdbcUtil {
+	public static Map<String,Object> ftpConfigs;
+	public static Map<String,Object> dbConfigs;
+	public static Connection connection;	
+	
+	/**
+	 * 从ftpconfigs配置文件中获取ftp站点配置信息
+	 * @return Map<String,Object>
+	 */
+	@SuppressWarnings("unchecked")
+	public static Map<String,Object> getFtpConfigs(){
+		if(ftpConfigs==null){
+			try {
+				ftpConfigs = new ObjectMapper().readValue(JdbcUtil.class.getResourceAsStream("/properties/ftpconfig.properties"), HashMap.class);
+			}catch (Exception e) {
+				BaseUtil.getLogger().error(e.toString());
+				e.printStackTrace();
+			}			
+		}
+		return ftpConfigs;
+	}
+	
+	/**
+	 * 从dbconfig配置文件中获取数据库配置信息
+	 * @return Map<String,Object>
+	 */
+	@SuppressWarnings("unchecked")
+	public static Map<String,Object> getDBConfigs(){
+		if(dbConfigs==null){
+			try {
+				dbConfigs = new ObjectMapper().readValue(JdbcUtil.class.getResourceAsStream("/properties/dbconfig.properties"), HashMap.class);
+			}catch (Exception e) {
+				BaseUtil.getLogger().error(e.toString());
+				e.printStackTrace();
+			}			
+		}
+		return dbConfigs;
+	}
+	
+	/**
+	 * 连接到数据库
+	 * @param url 地址
+	 * @param user 用户名
+	 * @param password 密码
+	 * @return 返回一个连接
+	 * @throws Exception
+	 */
+	public static Connection getConnect(String url,String user,String password) throws Exception{
+        Class.forName("oracle.jdbc.driver.OracleDriver");// 加载Oracle驱动程序
+        connection = DriverManager.getConnection(url, user, password);// 获取连接
+        return connection;	       
+	}
+	
+	/**
+	 * 从dbconfig配置文件中获取数据库连接
+	 * @return 返回数据库连接
+	 */
+	public static Connection getConnect(){
+		if(connection==null){
+		    try{
+				InputStream dbinput = JdbcUtil.class.getResourceAsStream("/properties/dbconfig.properties");
+				Properties prop = new Properties();
+				prop.load(dbinput);
+				connection = JdbcUtil.getConnect(prop.getProperty("url"), prop.getProperty("user"), prop.getProperty("password"));
+		    }catch (Exception e){
+		    	try {
+					System.in.read();
+				} catch (IOException e2) {
+					// TODO Auto-generated catch block
+					e2.printStackTrace();
+				}
+		    	BaseUtil.getLogger().error(e.toString());
+		    	try {
+		    		if(connection!=null){
+		    			connection.close();
+		    		}				
+				} catch (SQLException e1) {
+					BaseUtil.getLogger().error(e1.toString());
+					e1.printStackTrace();
+				}finally{
+					connection = null;
+				}
+		        e.printStackTrace();
+		    } 			
+		}
+		return connection;
+	}
+	
+	/**
+	 * 从dbconfig配置文件中获取数据库连接
+	 * @return 返回数据库连接
+	 */
+	@SuppressWarnings("unchecked")
+	public static Connection getConnectBySob(String sob){
+		Map<String,Object> dbServMaps = getDBConfigs();
+		Map<String,Object> dbServMap = (Map<String,Object>)dbServMaps.get(sob);
+		//先把当前的连接关闭
+		try {
+			if(connection!=null){
+				connection.close();
+			}
+		} catch (SQLException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}finally{
+			connection = null;
+		}
+		
+	    try{
+			connection = JdbcUtil.getConnect(dbServMap.get("url").toString(), dbServMap.get("user").toString(), dbServMap.get("password").toString());
+	    }catch (Exception e){
+	    	try {
+				System.in.read();
+			} catch (IOException e2) {
+				// TODO Auto-generated catch block
+				e2.printStackTrace();
+			}
+	    	BaseUtil.getLogger().error(e.toString());
+	    	try {
+	    		if(connection!=null){
+	    			connection.close();
+	    		}				
+			} catch (SQLException e1) {
+				BaseUtil.getLogger().error(e1.toString());
+				e1.printStackTrace();
+			}finally{
+				connection = null;
+			}
+	        e.printStackTrace();
+	    } 
+		
+		return connection;
+	}
+	
+	/**
+	 * 关闭连接
+	 * @param con
+	 * @param pre
+	 * @param result
+	 * @return
+	 */
+	public static boolean closeCn(Connection con,PreparedStatement pre,ResultSet result){
+        try{
+            if (result != null)
+                result.close();
+            	result = null;
+            if (pre != null)
+                pre.close();
+            	pre = null;
+            if (con != null)
+                con.close();
+        }
+        catch (Exception e){
+        	BaseUtil.getLogger().error(e.toString());
+            e.printStackTrace();
+        }
+		return true;
+	}
+	
+	/**
+	 * 执行多条sql语句
+	 * @param connection 连接
+	 * @param str 多条sqls语句
+	 * @return
+	 */
+	@SuppressWarnings("finally")
+	public static boolean executeSqls(Connection connection,List<String> str){
+		Statement statement = null;
+		boolean bol = true;
+		try{		
+			statement = connection.createStatement();		
+			for(String sql:str){
+				statement.addBatch(sql);
+			}
+			try {
+				statement.setQueryTimeout(180);
+				statement.executeBatch();
+			} catch (SQLException e) {
+				bol = false;
+				BaseUtil.getLogger().error(e.toString());
+				try {
+					statement.close();
+				} catch (SQLException e1) {
+					BaseUtil.getLogger().error(e1.toString());
+					e1.printStackTrace();
+				}
+				e.printStackTrace();
+			}
+			statement.close();
+		}catch(Exception e){
+			bol = false;
+			BaseUtil.getLogger().error(e.toString());
+			try {
+				if(connection!=null){
+					connection.rollback();
+				}				
+			} catch (SQLException e1) {
+				BaseUtil.getLogger().error(e1.toString());
+				e1.printStackTrace();
+			}
+			e.printStackTrace();
+		}finally{
+			statement = null;
+			return bol;
+		}
+	}
+	
+	@SuppressWarnings("finally")
+	public static int getIdBySeq(String seq){
+		connection = getConnect();
+		Statement statement = null;
+		int id = 0;
+		if(seq!=null&!"".equals(seq)){
+			try{			
+				statement = connection.createStatement();		
+				ResultSet rs = statement.executeQuery("select " + seq + ".nextval id from dual");
+				if(rs.next()){
+					id = rs.getInt("id");
+				}
+				rs.close();
+				statement.close();
+			}catch(Exception e){
+				BaseUtil.getLogger().error(e.toString());
+				try {
+					if(connection!=null){
+						connection.rollback();
+					}				
+				} catch (SQLException e1) {
+					BaseUtil.getLogger().error(e1.toString());
+					e1.printStackTrace();
+				}
+				e.printStackTrace();
+			}finally{
+				statement = null;
+				return id;
+			}			
+		}
+		return id;
+	}
+}

+ 579 - 0
src/com/uas/util/SFTPUtil.java

@@ -0,0 +1,579 @@
+package com.uas.util;
+
+import java.io.*;
+import java.util.*;
+
+import com.jcraft.jsch.*;
+import org.apache.commons.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * 类说明 sftp工具类
+ */
+public class SFTPUtil {
+    private transient Logger log = LoggerFactory.getLogger(this.getClass());
+
+    private ChannelSftp sftp;
+
+    private Session session;
+    /** SFTP 登录用户名*/
+    private String username;
+    /** SFTP 登录密码*/
+    private String password;
+    /** 私钥 */
+    private String privateKey;
+    /** SFTP 服务器地址IP地址*/
+    private String host;
+    /** SFTP 端口*/
+    private int port;
+
+
+    /**
+     * 构造基于密码认证的sftp对象
+     */
+    public SFTPUtil(String username, String password, String host, int port) {
+        this.username = username;
+        this.password = password;
+        this.host = host;
+        this.port = port;
+    }
+
+    /**
+     * 构造基于秘钥认证的sftp对象
+     */
+    public SFTPUtil(String username, String host, int port, String privateKey) {
+        this.username = username;
+        this.host = host;
+        this.port = port;
+        this.privateKey = privateKey;
+    }
+
+    public SFTPUtil(){}
+
+    /**
+     * 连接sftp服务器
+     */
+    public boolean login() throws JSchException {
+        boolean result = false;
+        JSch jsch = new JSch();
+        if (privateKey != null) {
+            jsch.addIdentity(privateKey);// 设置私钥
+        }
+
+        session = jsch.getSession(username, host, port);
+
+        if (password != null) {
+            session.setPassword(password);
+        }
+        Properties config = new Properties();
+        config.put("StrictHostKeyChecking", "no");
+
+        session.setConfig(config);
+        session.connect();
+
+        Channel channel = session.openChannel("sftp");
+        channel.connect();
+
+        sftp = (ChannelSftp) channel;
+        result = true;
+        return result;
+    }
+
+    /**
+     * 关闭连接 server
+     */
+    public void logout(){
+        if (sftp != null) {
+            if (sftp.isConnected()) {
+                sftp.disconnect();
+            }
+        }
+        if (session != null) {
+            if (session.isConnected()) {
+                session.disconnect();
+            }
+        }
+    }
+
+
+    /**
+     * 将输入流的数据上传到sftp作为文件。文件完整路径=basePath+directory
+     * @param basePath  服务器的基础路径
+     * @param directory  上传到该目录
+     * @param sftpFileName  sftp端文件名
+     * @param input   输入流
+     */
+    public boolean upload(String basePath,String directory, String sftpFileName, InputStream input) throws SftpException{
+        boolean flag =false;
+        try {
+            sftp.cd(basePath);
+            sftp.cd(directory);
+            flag = true;
+            sftp.put(input, sftpFileName);  //上传文件
+        } catch (SftpException e) {
+            //目录不存在,则创建文件夹
+           /* String [] dirs=directory.split("/");
+            String tempPath=basePath;
+            for(String dir:dirs){
+                if(null== dir || "".equals(dir)) continue;
+                tempPath+="/"+dir;
+                try{
+                    sftp.cd(tempPath);
+                }catch(SftpException ex){
+                    sftp.mkdir(tempPath);
+                    sftp.cd(tempPath);
+                }
+            }*/
+            flag = false;
+        }
+        return flag;
+    }
+
+
+    /**
+     * 下载文件。
+     * @param directory 下载目录
+     * @param downloadFile 下载的文件
+     * @param saveFile 存在本地的路径
+     */
+    public void download(String directory, String downloadFile, String saveFile) throws SftpException, FileNotFoundException{
+        if (directory != null && !"".equals(directory)) {
+            sftp.cd(directory);
+        }
+        File file = new File(saveFile);
+        sftp.get(downloadFile, new FileOutputStream(file));
+    }
+
+    /**
+     * 下载文件
+     * @param directory 下载目录
+     * @param downloadFile 下载的文件名
+     * @return 字节数组
+     */
+    public byte[] download(String directory, String downloadFile) throws SftpException, IOException{
+        if (directory != null && !"".equals(directory)) {
+            sftp.cd(directory);
+        }
+        InputStream is = sftp.get(downloadFile);
+
+        byte[] fileData = IOUtils.toByteArray(is);
+
+        return fileData;
+    }
+
+
+    /**
+     * 删除文件
+     * @param directory 要删除文件所在目录
+     * @param deleteFile 要删除的文件
+     */
+    public void delete(String directory, String deleteFile) throws SftpException{
+        sftp.cd(directory);
+        sftp.rm(deleteFile);
+    }
+
+
+    /**
+     * 列出目录下的文件
+     * @param
+     * @param directory 要列出的目录
+     */
+    public List<File> listFiles(String directory) throws SftpException {
+        Vector<ChannelSftp.LsEntry> list = sftp.ls(directory);
+        List<File> files = new ArrayList<>();
+        if (list.size()>0&&list!=null) {
+            for (ChannelSftp.LsEntry entry : list) {
+                if (!".".equals(entry.getFilename()) && !"..".equals(entry.getFilename())) {
+                    File file = new File("/"+directory+"/");
+                    files.add(file);
+                }
+            }
+        }
+        return files;
+    }
+
+    /**
+     * 下载流
+     * @param
+     * @param directory 下载目录
+     */
+    public List<File> download(String directory) {
+        try {
+            Vector<ChannelSftp.LsEntry> list = sftp.ls(directory);
+            List<File> ls = new ArrayList<File>();
+            if (list.size()>0&&list!=null) {
+                for (ChannelSftp.LsEntry entry : list) {
+                    if (!".".equals(entry.getFilename()) && !"..".equals(entry.getFilename())) {
+                        if (entry.getFilename().endsWith(".xml")) {
+                            InputStream is = sftp.get(directory+"/"+entry.getFilename());
+                            File temp= File.createTempFile(entry.getFilename(),"");
+                            OutputStream os = new FileOutputStream(temp);
+                            int bytesRead = 0;
+                            byte[] buffer = new byte[102400];
+                            while ((bytesRead = is.read(buffer, 0, 102400)) != -1) {
+                                os.write(buffer, 0, bytesRead);
+                            }
+                            is.close();
+                            os.close();
+                            ls.add(temp);
+                        }
+                    }
+                }
+            }
+            return ls;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    /**
+     * 根目录
+     *
+     * @return String
+     */
+    private String homeDir()
+    {
+        try {
+            return sftp.getHome();
+        } catch (Exception e) {
+            return "/";
+        }
+    }
+
+    public String currentDir()
+   {
+        try {
+            String pwd = sftp.pwd();
+            System.err.println(pwd);
+            return pwd;
+
+        } catch (Exception e) {
+           log.error("failed to get current dir", e);
+            return homeDir();
+         }
+    }
+
+    /**
+     * 切换工作目录
+     *
+     * @param pathName 路径
+     * @return boolean
+     */
+   public boolean changeDir(String pathName)
+   {
+       if (pathName == null || pathName.trim().equals("")) {
+           log.debug("invalid pathName");
+           return false;
+       }
+       try {
+           sftp.cd(pathName.replaceAll("\\\\", "/"));
+           log.debug("directory successfully changed,current dir=" + sftp.pwd());
+           return true;
+       } catch (SftpException e) {
+           log.error("failed to change directory", e);
+           return false;
+       }
+   }
+
+    /**
+     * 列出当前目录下的文件及文件夹
+     *
+     * @param filter 过滤参数
+     * @return String[]
+     */
+    @SuppressWarnings("unchecked")
+    private String[] list(String filter)
+    {
+        Vector<ChannelSftp.LsEntry> list = null;
+        try {
+            //ls方法会返回两个特殊的目录,当前目录(.)和父目录(..)
+            list = sftp.ls(sftp.pwd());
+        } catch (SftpException e) {
+            log.error("can not list directory", e);
+            return new String[0];
+        }
+        List<String> resultList = new ArrayList<String>();
+        for (ChannelSftp.LsEntry entry : list) {
+            resultList.add(entry.getFilename());
+        }
+        return resultList.toArray(new String[0]);
+    }
+    /**
+     * 指定目录下文件名称列表
+     *
+     * @return String[]
+     */
+    public String[] lsFiles(String pathName) {
+        String currentDir = currentDir();
+         if (!changeDir(pathName)) {
+             return new String[0];
+         }
+        String[] result = list("File");
+         if (!changeDir(currentDir)) {
+             return new String[0];
+        }
+        return result;
+    }
+
+
+    /**
+     * 批量下载文件
+     * @param remotePath:远程下载目录(以路径符号结束,可以为相对路径eg:/assess/sftp/jiesuan_2/2014/)
+     * @param localPath:本地保存目录(以路径符号结束,D:\Duansha\sftp\)
+     * @param fileFormat:下载文件格式(以特定字符开头,为空不做检验)
+     * @param fileEndFormat:下载文件格式(文件格式)
+     * @param del:下载后是否删除sftp文件
+     * @return
+     */
+    public List<String> batchDownLoadFile(String remotePath, String localPath,
+                                          String fileFormat, String fileEndFormat, boolean del)
+    {
+        List<String> filenames = new ArrayList<String>();
+        try
+        {
+            // connect();
+            Vector v = sftp.ls(remotePath);
+            // sftp.cd(remotePath);
+            if (v.size() > 0)
+            {
+                System.out.println("本次处理文件个数不为零,开始下载...fileSize=" + v.size());
+                Iterator it = v.iterator();
+                while (it.hasNext())
+                {
+                    ChannelSftp.LsEntry entry = (ChannelSftp.LsEntry) it.next();
+                    String filename = entry.getFilename();
+                    SftpATTRS attrs = entry.getAttrs();
+                    if (!attrs.isDir())
+                    {
+                        boolean flag = false;
+                        String localFileName = localPath + filename;
+                        fileFormat = fileFormat == null ? "" : fileFormat
+                                .trim();
+                        fileEndFormat = fileEndFormat == null ? ""
+                                : fileEndFormat.trim();
+                        // 三种情况
+                        if (fileFormat.length() > 0 && fileEndFormat.length() > 0)
+                        {
+                            if (filename.startsWith(fileFormat) && filename.endsWith(fileEndFormat))
+                            {
+                                flag = downloadFile(remotePath, filename,localPath, filename);
+                                if (flag)
+                                {
+                                    filenames.add(localFileName);
+                                    if (flag && del)
+                                    {
+                                        //deleteSFTP(remotePath, filename);
+                                    }
+                                }
+                            }
+                        }
+                        else if (fileFormat.length() > 0 && "".equals(fileEndFormat))
+                        {
+                            if (filename.startsWith(fileFormat))
+                            {
+                                flag = downloadFile(remotePath, filename, localPath, filename);
+                                if (flag)
+                                {
+                                    filenames.add(localFileName);
+                                    if (flag && del)
+                                    {
+                                        //sftp.deleteSFTP(remotePath, filename);
+                                    }
+                                }
+                            }
+                        }
+                        else if (fileEndFormat.length() > 0 && "".equals(fileFormat))
+                        {
+                            if (filename.endsWith(fileEndFormat))
+                            {
+                                flag = downloadFile(remotePath, filename,localPath, filename);
+                                if (flag)
+                                {
+                                    filenames.add(localFileName);
+                                    if (flag && del)
+                                    {
+                                        //deleteSFTP(remotePath, filename);
+                                    }
+                                }
+                            }
+                        }
+                        else
+                        {
+                            flag = downloadFile(remotePath, filename,localPath, filename);
+                            if (flag)
+                            {
+                                filenames.add(localFileName);
+                                if (flag && del)
+                                {
+                                    //deleteSFTP(remotePath, filename);
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            if (log.isInfoEnabled())
+            {
+                log.info("download file is success:remotePath=" + remotePath
+                        + "and localPath=" + localPath + ",file size is"
+                        + v.size());
+            }
+        }
+        catch (SftpException e)
+        {
+            e.printStackTrace();
+        }
+        finally
+        {
+            // this.disconnect();
+        }
+        return filenames;
+    }
+
+    /**
+     * 下载单个文件
+     * @param remotePath:远程下载目录(以路径符号结束)
+     * @param remoteFileName:下载文件名
+     * @param localPath:本地保存目录(以路径符号结束)
+     * @param localFileName:保存文件名
+     * @return
+     */
+    public boolean downloadFile(String remotePath, String remoteFileName,String localPath, String localFileName)
+    {
+        FileOutputStream fieloutput = null;
+        try
+        {
+            // sftp.cd(remotePath);
+            File file = new File(localPath + localFileName);
+            // mkdirs(localPath + localFileName);
+            fieloutput = new FileOutputStream(file);
+            sftp.get(remotePath + remoteFileName, fieloutput);
+            if (log.isInfoEnabled())
+            {
+                log.info("===DownloadFile:" + remoteFileName + " success from sftp.");
+            }
+            return true;
+        }
+        catch (FileNotFoundException e)
+        {
+            e.printStackTrace();
+        }
+        catch (SftpException e)
+        {
+            e.printStackTrace();
+        }
+        finally
+        {
+            if (null != fieloutput)
+            {
+                try
+                {
+                    fieloutput.close();
+                }
+                catch (IOException e)
+                {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return false;
+    }
+
+    public Boolean rename(String name, String path) {
+        Boolean result = false;
+        try {
+            sftp.rename(name, path);
+            result = true;
+        } catch (SftpException e) {
+            e.printStackTrace();
+        }
+        return result;
+    }
+
+    public boolean copyfile(String src, String path){
+        boolean result = false;
+        try {
+            InputStream tInputStream = null;
+
+            //tChannelSftp.mkdir(路径);
+            System.err.println(src);
+            tInputStream = sftp.get(src);
+
+            //拷贝读取到的文件流
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+            byte[] buffer = new byte[1024];
+            int len;
+            while ((len = tInputStream.read(buffer)) > -1 ) {
+                baos.write(buffer, 0, len);
+            }
+            baos.flush();
+
+            InputStream nInputStream = new ByteArrayInputStream(baos.toByteArray());
+
+            sftp.put(nInputStream, path);
+
+            nInputStream.close();
+            baos.close();
+            tInputStream.close();
+            result = true;
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+       return result;
+    }
+
+    //上传文件测试
+    /*public static void main(String[] args) throws SftpException, IOException {
+        SFTPUtil sftp = new SFTPUtil("wms_ufct", "ZjJ05GFV", "218.17.248.243", 45301);
+       //FtpUtil.connect("/To_XN_TEST/","218.4.62.135",21,"hsltoxn", "HtxN527%#");
+        try {
+            sftp.login();
+        } catch (JSchException e) {
+            e.printStackTrace();
+        }
+        /*File file = new File("C:\\Users\\usoft\\Downloads\\视图字段.xls");
+        InputStream is = new FileInputStream(file);
+
+        sftp.upload("/","To_XN_TEST", "uas_sftp.xls", is);*//*
+        //sftp.listFiles("/stockout/data/");
+        String ss = "/stockout/data/";
+        String addr = "D:/BaiduNetdiskDownload\\";
+        *//*String[] strings = sftp.lsFiles(ss);
+        for (String s:strings) {
+            System.err.println(s);
+            if (!".".equals(s)&&!"..".equals(s)) {
+                *//**//*sftp.download(ss,s,addr);
+                File file = new File(ss+s);
+                InputStream inputStream = new FileInputStream(file);*//**//*
+                boolean bat = sftp.downloadFile(ss, s, "D:/", s);
+                System.err.println(bat);
+            }
+        }
+
+        sftp.logout();*//*
+        String sss = "GR_20190521121137B.xml";
+        String str = "\\stockout\\data\\";
+        String str1= str.replace("\\","/");
+        System.err.println(str);
+        *//*try {
+            InputStream in = new FileInputStream(sss);
+            SAXReader reader = new SAXReader();
+            Document doc = reader.read(in);
+            in.close();
+            Element element = doc.getRootElement();
+            System.err.println(element);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }*//*
+        //String src = "/stockout/data/GR_20190521121137B.xml";
+        //sftp.copyfile(src,"/stockout/backup/GR_20190521121137B.xml");
+        //sftp.logout();
+        boolean connect = FtpUtil.connect("From_QF", "112.74.205.182", 21, "YTZH02", "Ytzh)@2018");
+        System.err.println(connect);
+        FtpUtil.closeFtpClient(new FTPClient());
+    }*/
+}

+ 37 - 0
src/properties/dbconfig.properties

@@ -0,0 +1,37 @@
+{
+	"N_YITOA_LHCT":{
+		"url":"jdbc:oracle:thin:@183.60.22.166:1521:orcl",
+		"user":"N_YITOA_LHCT",
+		"password":"select!#%*("
+	},
+    "t_n_huasl":{
+		"url":"jdbc:oracle:thin:@183.60.22.166:1521:orcl",
+		"user":"t_n_huasl",
+		"password":"select!#%*("
+    },
+	"N_HUASL":{
+		"url":"jdbc:oracle:thin:@183.60.22.166:1521:orcl",
+		"user":"N_HUASL",
+		"password":"select!#%*("
+	},
+	"N_WILICHK":{
+		"url":"jdbc:oracle:thin:@183.60.22.166:1521:orcl",
+		"user":"N_WILICHK",
+		"password":"select!#%*("
+	},
+	"N_BJKG":{
+		"url":"jdbc:oracle:thin:@183.60.22.166:1521:orcl",
+		"user":"N_BJKG",
+		"password":"select!#%*("
+	},
+	"USOFT_MALL_HK":{
+		"url":"jdbc:oracle:thin:@218.18.115.198:1523:orcl",
+		"user":"USOFT_MALL_HK",
+		"password":"select!#%*("
+	},
+	"UAS_DEV":{
+		"url":"jdbc:oracle:thin:@192.168.253.6:1521:orcl",
+		"user":"UAS_DEV",
+		"password":"select!#%*("
+	}
+}

+ 27 - 0
src/properties/dbconfig3.properties

@@ -0,0 +1,27 @@
+{
+    "t_n_huasl":{
+		"url":"jdbc:oracle:thin:@127.0.0.1:1521:orcl",
+		"user":"t_n_huasl",
+		"password":"select!#%*("    
+    },
+	"N_HUASL":{
+		"url":"jdbc:oracle:thin:@127.0.0.1:1521:orcl",
+		"user":"N_HUASL",
+		"password":"select!#%*("
+	},
+	"N_WILICHK":{
+		"url":"jdbc:oracle:thin:@127.0.0.1:1521:orcl",
+		"user":"N_WILICHK",
+		"password":"select!#%*("
+	},
+	"N_BJKG":{
+		"url":"jdbc:oracle:thin:@127.0.0.1:1521:orcl",
+		"user":"N_BJKG",
+		"password":"select!#%*("
+	},
+	"USOFT_MALL_HK":{
+		"url":"jdbc:oracle:thin:@127.0.0.1:1521:orcl",
+		"user":"USOFT_MALL_HK",
+		"password":"select!#%*("
+	}
+}

+ 58 - 0
src/properties/ftpconfig.properties

@@ -0,0 +1,58 @@
+{
+	"N_YITOA_LHCT-SF":{
+		"ip":"mcs-cas-api-sftp.sf-express.com",
+		"port":3022,
+		"user":"wms_ufct",
+		"password":"g9Y0Op7K",
+		"downloadpath":"goodsreceipt/data",
+		"in":"stockin/data"
+	},
+	"t_n_huasl-QF":{
+		"ip":"183.47.46.130",
+		"port":21,
+		"user":"YTZH02",
+		"password":"Ytzh#@!2018",
+		"downloadpath":"From_QF",
+		"in":"TO_QF"
+	},
+	"N_YITOA_LHCT-QF":{
+		"ip":"112.74.205.182",
+		"port":21,
+		"user":"YTZH02",
+		"password":"Ytzh)@2018",
+		"downloadpath":"From_QF",
+		"in":"TO_QF"
+	},
+    "N_HUASL-QF":{
+		"ip":"112.74.205.182",
+		"port":21,
+		"user":"YTZH02",
+		"password":"Ytzh)@2018",
+		"downloadpath":"From_QF",
+		"in":"TO_QF"
+	},
+	"N_WILICHK-QF":{
+		"ip":"112.74.205.182",
+		"port":21,
+		"user":"YTZH02",
+		"password":"Ytzh)@2018",
+		"downloadpath":"From_QF",
+		"in":"TO_QF"
+	},
+	"N_BJKG-QF":{
+		"ip":"112.74.205.182",
+		"port":21,
+		"user":"YTZH02",
+		"password":"Ytzh)@2018",
+		"downloadpath":"From_QF",
+		"in":"TO_QF"
+	},
+	"N_HUASL-XN":{
+		"ip":"218.4.62.135",
+		"port":21,
+		"user":"hsltoxn",
+		"password":"HtxN527%#",
+		"downloadpath":"From_XN",
+		"in":"To_XN"
+	}
+}

+ 6 - 0
src/properties/log4j.properties

@@ -0,0 +1,6 @@
+log4j.rootLogger=DEBUG, R     
+log4j.appender.R=org.apache.log4j.FileAppender   
+log4j.appender.R.file=my.log     
+log4j.appender.R.Append=true   
+log4j.appender.R.layout=org.apache.log4j.PatternLayout   
+log4j.appender.R.layout.ConversionPattern=%n%n%d%p[%c]-%m%n   

Some files were not shown because too many files changed in this diff