koul пре 5 година
родитељ
комит
650bf10378

+ 3 - 1
.idea/compiler.xml

@@ -8,15 +8,17 @@
         <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
         <outputRelativeToContentRoot value="true" />
         <module name="hsl" />
+        <module name="warehouse-edi" />
       </profile>
     </annotationProcessing>
     <bytecodeTargetLevel target="8">
       <module name="hsl" target="1.8" />
+      <module name="warehouse-edi" target="1.8" />
     </bytecodeTargetLevel>
   </component>
   <component name="JavacSettings">
     <option name="ADDITIONAL_OPTIONS_OVERRIDE">
-      <module name="hsl" options="-parameters" />
+      <module name="warehouse-edi" options="-parameters" />
     </option>
   </component>
 </project>

+ 1 - 1
.idea/encodings.xml

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

+ 0 - 63
.idea/misc.xml

@@ -1,14 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
-  <component name="AndroidDexCompilerConfiguration">
-    <option name="MAX_HEAP_SIZE" value="2048" />
-  </component>
   <component name="JavaScriptSettings">
     <option name="languageLevel" value="ES6" />
   </component>
-  <component name="Kotlin2JsCompilerArguments">
-    <option name="sourceMapEmbedSources" />
-  </component>
   <component name="MavenProjectsManager">
     <option name="originalFiles">
       <list>
@@ -16,63 +10,6 @@
       </list>
     </option>
   </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" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK">
     <output url="file://$PROJECT_DIR$/bin" />
   </component>

+ 1 - 1
.idea/modules.xml

@@ -2,7 +2,7 @@
 <project version="4">
   <component name="ProjectModuleManager">
     <modules>
-      <module fileurl="file://$PROJECT_DIR$/hsl.iml" filepath="$PROJECT_DIR$/hsl.iml" />
+      <module fileurl="file://$PROJECT_DIR$/.idea/warehouse-edi.iml" filepath="$PROJECT_DIR$/.idea/warehouse-edi.iml" />
     </modules>
   </component>
 </project>

+ 0 - 2
.idea/hsl.iml → .idea/warehouse-edi.iml

@@ -11,12 +11,10 @@
     <content url="file://$MODULE_DIR$">
       <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
       <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
-      <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
       <excludeFolder url="file://$MODULE_DIR$/target" />
     </content>
     <orderEntry type="inheritedJdk" />
     <orderEntry type="sourceFolder" forTests="false" />
-    <orderEntry type="library" name="commons-csv-1.4" level="project" />
     <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:2.3.1.RELEASE" level="project" />
     <orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:2.3.1.RELEASE" level="project" />
     <orderEntry type="library" name="Maven: org.springframework:spring-context:5.2.7.RELEASE" level="project" />

BIN
.mvn/wrapper/maven-wrapper.jar


Разлика између датотеке није приказан због своје велике величине
+ 0 - 2
my.log


+ 1 - 1
pom.xml

@@ -12,7 +12,7 @@
     <artifactId>hsl</artifactId>
     <version>0.0.1-SNAPSHOT</version>
     <name>hsl</name>
-    <description>Demo project for Spring Boot</description>
+    <description>华商龙仓库EDI</description>
 
     <properties>
         <java.version>1.8</java.version>

+ 3 - 42
src/main/java/com/uas/HSLApplication.java

@@ -1,20 +1,14 @@
 package com.uas;
 
-import com.uas.main.DownloadStcockQty;
-import com.uas.util.BaseUtil;
-import com.uas.util.JdbcUtil;
+
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cache.annotation.EnableCaching;
 import org.springframework.scheduling.annotation.EnableScheduling;
-import org.springframework.scheduling.annotation.Scheduled;
-
-import java.util.Date;
 
-import static com.uas.main.Download.downloadRun;
-import static com.uas.main.DownloadFilePath.runDownloadFilePath;
-import static com.uas.main.Upload.uploadRun;
 
 @SpringBootApplication
+@EnableCaching
 @EnableScheduling
 public class HSLApplication {
 
@@ -22,37 +16,4 @@ public class HSLApplication {
         SpringApplication.run(HSLApplication.class, args);
     }
 
-    @Scheduled(fixedRate=1000*60*5)
-    public void ediSendAndReceive() {
-        uploadRun();
-        downloadRun();
-        closeJDBC();
-    }
-
-    @Scheduled(fixedRate=1000*60*60)
-    public void downloadStcockQty() {
-        DownloadStcockQty.downloadQty();
-        closeJDBC();
-    }
-
-
-    @Scheduled(fixedRate=1000*60*60)
-    public void filePath() {
-        runDownloadFilePath();
-        closeJDBC();
-     }
-
-    private void closeJDBC(){
-        try{ //关闭数据库连接
-            if(JdbcUtil.connection!=null){
-                JdbcUtil.connection.close();
-            }
-        }catch(Exception e){
-            BaseUtil.getLogger().error(e.toString());
-            e.printStackTrace();
-        }finally{
-            JdbcUtil.connection = null;
-        }
-    }
-
 }

+ 39 - 0
src/main/java/com/uas/config/AsyncConfig.java

@@ -0,0 +1,39 @@
+package com.uas.config;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+import java.util.concurrent.Executor;
+import java.util.concurrent.ThreadPoolExecutor;
+
+/**
+ * @Author: zhouy
+ * @Date: 2020/5/22 13:43
+ */
+@Configuration
+@EnableAsync  // 启用异步任务
+public class AsyncConfig {
+    // 声明一个线程池(并指定线程池的名字)
+    @Bean("taskExecutor")
+    public Executor asyncExecutor() {
+        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+        //核心线程数5:线程池创建时候初始化的线程数
+        executor.setCorePoolSize(5);
+        //最大线程数20:线程池最大的线程数,只有在缓冲队列满了之后才会申请超过核心线程数的线程
+        executor.setMaxPoolSize(20);
+        //缓冲队列500:用来缓冲执行任务的队列
+        executor.setQueueCapacity(1000);
+        //允许线程的空闲时间60秒:当超过了核心线程出之外的线程在空闲时间到达之后会被销毁
+        executor.setKeepAliveSeconds(60);
+        //线程池名的前缀:设置好了之后可以方便我们定位处理任务所在的线程池
+        executor.setThreadNamePrefix("DailyAsync-");
+        //所有任务处理完毕开始关闭线程池
+        executor.setWaitForTasksToCompleteOnShutdown(true);
+        // rejection-policy:当pool已经达到max size的时候,如何处理新任务
+        // CALLER_RUNS:不在新线程中执行任务,而是有调用者所在的线程来执行
+        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
+        executor.initialize();
+        return executor;
+    }
+}

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

@@ -1,222 +0,0 @@
-package com.uas.main;
-
-import com.jcraft.jsch.JSchException;
-import com.uas.util.BaseUtil;
-import com.uas.util.FtpUtil;
-import com.uas.util.JdbcUtil;
-import com.uas.util.SFTPUtil;
-import org.apache.commons.net.ftp.FTPClient;
-
-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;
-
-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 uploadRun() {
-        //香港华商龙
-		uploadBySob("N_HUASL");
-        //威尔电子
-		uploadBySob("N_WILICHK");
-        //柏建控股
-		uploadBySob("N_BJKG");
-		//深圳华商龙
-		uploadBySob("N_HUASL_SZ");
-		//上海宇声
-		uploadBySob("N_E_SHINE_SH");
-        //青岛华商龙
-        uploadBySob("N_HUASL_QD");
-        //重庆华商龙
-        uploadBySob("HSL_CQ");
-        //北京华商龙
-        uploadBySob("HSL_BJ");
-	}
-	
-	@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;
-			}
-		}
-
-	}
-}

+ 13 - 0
src/main/java/com/uas/service/DownloadFilePathService.java

@@ -0,0 +1,13 @@
+package com.uas.service;
+
+/**
+ * @author koul
+ * @email koul@usoftchina.com
+ * @date 2020-11-27 10:14
+ */
+public interface DownloadFilePathService {
+
+    void runDownloadFilePath();
+
+    void downloadFilePath(String depot,String sob);
+}

+ 13 - 0
src/main/java/com/uas/service/DownloadService.java

@@ -0,0 +1,13 @@
+package com.uas.service;
+
+/**
+ * @author koul
+ * @email koul@usoftchina.com
+ * @date 2020-11-27 8:59
+ */
+public interface DownloadService {
+
+    void downloadRun();
+
+    void downloadByDepotAndSob(String depot,String sob,String enterprise);
+}

+ 14 - 0
src/main/java/com/uas/service/DownloadStcockQtyService.java

@@ -0,0 +1,14 @@
+package com.uas.service;
+
+/**
+ * @author koul
+ * @email koul@usoftchina.com
+ * @date 2020-11-27 9:50
+ * 仓库库存回传
+ */
+public interface DownloadStcockQtyService {
+
+    void downloadQty();
+
+    void downloadStcockQty(String depot,String sob);
+}

+ 19 - 7
src/main/java/com/uas/main/DownloadFilePath.java → src/main/java/com/uas/service/Impl/DownloadFilePathServiceImpl.java

@@ -1,5 +1,6 @@
-package com.uas.main;
+package com.uas.service.Impl;
 
+import com.uas.service.DownloadFilePathService;
 import com.uas.util.BaseUtil;
 import com.uas.util.FileUtil;
 import com.uas.util.FtpUtil;
@@ -7,6 +8,8 @@ import com.uas.util.JdbcUtil;
 import org.apache.commons.net.ftp.FTPClient;
 import org.apache.http.entity.ContentType;
 import org.springframework.mock.web.MockMultipartFile;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.File;
@@ -18,17 +21,23 @@ import java.util.List;
 import java.util.Map;
 
 /**
- * @author kl
+ * @author koul
  * @email koul@usoftchina.com
- * @date 2020-06-29 8:49
+ * @date 2020-11-27 10:13
  */
-public class DownloadFilePath {
-    public static void runDownloadFilePath(){
+@Service
+public class DownloadFilePathServiceImpl implements DownloadFilePathService{
+    @Override
+    public void runDownloadFilePath(){
         //香港华商龙-富森-回签单扫描回传
         downloadFilePath("N_HUASL-FS","N_HUASL");
     }
+
+
     @SuppressWarnings("unchecked")
-    public static void downloadFilePath(String depot,String sob){
+    @Override
+    @Async("taskExecutor")
+    public  void downloadFilePath(String depot,String sob){
         FTPClient client = null;
         Connection connect = null;
 
@@ -52,6 +61,9 @@ public class DownloadFilePath {
                                 boolean bol = FileUtil.fileUp(statement, file1, sob);
                                 if (bol) {
                                     client.rename(file.getName(), "bak/" + file.getName()); //移动处理完的文件到bak文件夹下
+                                }else {
+                                    //移动处理失败的文件到failed文件夹下
+                                    client.rename(file.getName(), "failed/" + file.getName());
                                 }
                                 statement.close();
                             } catch (Exception e) {
@@ -64,7 +76,7 @@ public class DownloadFilePath {
                     }
                 }
                 if (!"".equals(fileName)) {
-                    BaseUtil.logDownload(fileName.substring(1), ftpMap.get("ip").toString(), ftpMap.get("downloadpath").toString());
+                    BaseUtil.logDownload(fileName.substring(1), ftpMap.get("ip").toString(), ftpMap.get("file").toString());
                 }
             }
         } catch (Exception e) {

+ 47 - 40
src/main/java/com/uas/main/Download.java → src/main/java/com/uas/service/Impl/DownloadServiceImpl.java

@@ -1,5 +1,6 @@
-package com.uas.main;
+package com.uas.service.Impl;
 
+import com.uas.service.DownloadService;
 import com.uas.util.BaseUtil;
 import com.uas.util.SFTPUtil;
 import org.apache.commons.net.ftp.FTPClient;
@@ -7,6 +8,8 @@ import org.codehaus.jackson.map.ObjectMapper;
 import org.dom4j.Document;
 import org.dom4j.Element;
 import org.dom4j.io.SAXReader;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Service;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -24,7 +27,40 @@ import java.util.Map;
 import static com.uas.util.FtpUtil.*;
 import static com.uas.util.JdbcUtil.*;
 
-public class Download{
+@Service
+public class DownloadServiceImpl implements DownloadService {
+
+    @Override
+	public void downloadRun(){
+		//香港华商龙-富森
+		downloadByDepotAndSob("N_HUASL-FS","N_HUASL","香港华商龙");
+		//威尔电子-富森
+		downloadByDepotAndSob("N_WILICHK-FS","N_WILICHK","(华商龙)威尔电子");
+		//柏建控股-富森
+		downloadByDepotAndSob("N_BJKG-FS","N_BJKG","柏建控股");
+		//深圳华商龙-准时达
+		downloadByDepotAndSob("N_HUASL_SZ-DRD","N_HUASL_SZ","深圳华商龙");
+		//上海宇声-准时达
+		downloadByDepotAndSob("N_E_SHINE_SH-DRD","N_E_SHINE_SH","上海宇声");
+		//重庆华商龙-准时达
+		downloadByDepotAndSob("HSL_CQ-DRD","HSL_CQ","重庆华商龙");
+		//北京华商龙-准时达
+		downloadByDepotAndSob("HSL_BJ-DRD","HSL_BJ","北京华商龙");
+		//青岛华商龙-准时达
+		downloadByDepotAndSob("N_HUASL_QD-DRD","N_HUASL_QD","青岛华商龙");
+        //香港华商龙-新宁
+        //downloadByDepotAndSob("N_HUASL-XN","N_HUASL","香港华商龙");
+
+		//downloadByDepotAndSob("N_BJKG-QF","N_BJKG","柏建控股");//柏建控股-旗丰
+		//downloadByDepotAndSob("N_WILICHK-QF","N_WILICHK","(华商龙)威尔电子");//威尔电子-旗丰
+		//downloadByDepotAndSob("N_HUASL-QF","N_HUASL","香港华商龙");//华商龙-旗丰
+//    	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");
+
+	}
 
 	public static Boolean checkXmlFileToSqlToEnterprise(File file,String enterprise){
 		String ent = null;
@@ -431,51 +467,21 @@ public class Download{
 			data.add(detail);
     	}
 		return data;
-	}			
-    public static void downloadRun(){
-		//香港华商龙-富森
-		downloadByDepotAndSob("N_HUASL-FS","N_HUASL","香港华商龙");
-		//香港华商龙-新宁
-    	downloadByDepotAndSob("N_HUASL-XN","N_HUASL","香港华商龙");
-		//威尔电子-富森
-		downloadByDepotAndSob("N_WILICHK-FS","N_WILICHK","(华商龙)威尔电子");
-		//柏建控股-富森
-		downloadByDepotAndSob("N_BJKG-FS","N_BJKG","柏建控股");
-		//深圳华商龙-准时达
-		downloadByDepotAndSob("N_HUASL_SZ-DRD","N_HUASL_SZ","深圳华商龙");
-		//上海宇声-准时达
-		downloadByDepotAndSob("N_E_SHINE_SH-DRD","N_E_SHINE_SH","上海宇声");
-		//重庆华商龙-准时达
-		downloadByDepotAndSob("HSL_CQ-DRD","HSL_CQ","重庆华商龙");
-		//北京华商龙-准时达
-		downloadByDepotAndSob("HSL_BJ-DRD","HSL_BJ","北京华商龙");
-		//青岛华商龙-准时达
-		downloadByDepotAndSob("N_HUASL_QD-DRD","N_HUASL_QD","青岛华商龙");
-
-		//downloadByDepotAndSob("N_BJKG-QF","N_BJKG","柏建控股");//柏建控股-旗丰
-		//downloadByDepotAndSob("N_WILICHK-QF","N_WILICHK","(华商龙)威尔电子");//威尔电子-旗丰
-		//downloadByDepotAndSob("N_HUASL-QF","N_HUASL","香港华商龙");//华商龙-旗丰
-//    	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){
+	@Override
+	@Async("taskExecutor")
+	public 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 = getFtpConfigs();
 			Map<String,Object> ftpMap = (Map<String,Object>)servMap.get(depot);
 			client = connect(ftpMap);
-			if(client!=null||sftp!=null) {
+			if(client!=null) {
 				List<File> files = null;
 				files = downloadAllFileByType(client, "XML");
 				String fileName = "";
@@ -486,13 +492,14 @@ public class Download{
 							try {
 								fileName += "," + file.getName();
 								Statement statement = connect.createStatement();
-								System.err.println(statement);
 								//判断当前帐套和文件是否一致
 								if (!checkXmlFileToSqlToEnterprise(file, enterprise)) {
 									continue;
 								}
 								sqls = parseXmlFileToSqls(file, statement);
 								if (sqls == null) {
+                                    //移动处理失败的文件到failed文件夹下
+                                    client.rename(file.getName(), "failed/" + file.getName());
 									continue;
 								}
 
@@ -501,6 +508,9 @@ public class Download{
 								if (executeRes) {
 									//移动处理完的文件到bak文件夹下
 									client.rename(file.getName(), "bak/" + file.getName());
+								}else {
+									//移动处理失败的文件到failed文件夹下
+									client.rename(file.getName(), "failed/" + file.getName());
 								}
 								statement.close();
 							} catch (Exception e) {
@@ -524,9 +534,6 @@ public class Download{
 				closeFtpClient(client);
 				client = null;
 			}
-			if (sftp!=null){
-				sftp.logout();
-			}
 			//把当前的连接关闭
 			try {
 				if(connect!=null){

+ 19 - 11
src/main/java/com/uas/main/DownloadStcockQty.java → src/main/java/com/uas/service/Impl/DownloadStcockQtyServiceImpl.java

@@ -1,28 +1,32 @@
-package com.uas.main;
+package com.uas.service.Impl;
 
+import com.uas.service.DownloadStcockQtyService;
 import com.uas.util.BaseUtil;
 import com.uas.util.FileUtil;
-import com.uas.util.SFTPUtil;
 import org.apache.commons.net.ftp.FTPClient;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Service;
 
 import java.io.File;
 import java.sql.Connection;
 import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
 import static com.uas.util.FtpUtil.*;
-import static com.uas.util.JdbcUtil.*;
+import static com.uas.util.JdbcUtil.getConnectBySob;
+import static com.uas.util.JdbcUtil.getFtpConfigs;
 
 /**
  * @author koul
  * @email koul@usoftchina.com
- * @date 2020-10-19 15:06
+ * @date 2020-11-27 9:51
  */
-public class DownloadStcockQty {
-    public static void downloadQty() {
+@Service
+public class DownloadStcockQtyServiceImpl implements DownloadStcockQtyService {
+
+    @Override
+    public void downloadQty() {
         //深圳华商龙-准时达
         downloadStcockQty("N_HUASL_SZ-DRD", "N_HUASL_SZ");
         //上海宇声-准时达
@@ -35,7 +39,9 @@ public class DownloadStcockQty {
         downloadStcockQty("N_HUASL_QD-DRD", "N_HUASL_QD");
     }
 
-    public static void downloadStcockQty(String depot,String sob) {
+    @Override
+    @Async("taskExecutor")
+    public void downloadStcockQty(String depot,String sob) {
         FTPClient client = null;
         Connection connect = null;
         try {
@@ -56,6 +62,9 @@ public class DownloadStcockQty {
                                 if (b) {
                                     //移动处理完的文件到bak文件夹下
                                     client.rename(file.getName(), "bak/" + file.getName());
+                                }else {
+                                    //移动处理失败的文件到failed文件夹下
+                                    client.rename(file.getName(), "failed/" + file.getName());
                                 }
                             } catch (Exception e) {
                                 e.printStackTrace();
@@ -66,7 +75,7 @@ public class DownloadStcockQty {
 
                     }
                     if (!"".equals(fileName)) {
-                        BaseUtil.logDownload(fileName.substring(1), ftpMap.get("ip").toString(), ftpMap.get("downloadpath").toString());
+                        BaseUtil.logDownload(fileName.substring(1), ftpMap.get("ip").toString(), ftpMap.get("qty").toString());
                     }
                 }
             }
@@ -90,5 +99,4 @@ public class DownloadStcockQty {
             }
         }
     }
-
 }

+ 215 - 0
src/main/java/com/uas/service/Impl/UploadServiceImpl.java

@@ -0,0 +1,215 @@
+package com.uas.service.Impl;
+
+import com.jcraft.jsch.JSchException;
+import com.uas.service.UploadService;
+import com.uas.util.BaseUtil;
+import com.uas.util.FtpUtil;
+import com.uas.util.JdbcUtil;
+import com.uas.util.SFTPUtil;
+import org.apache.commons.net.ftp.FTPClient;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Service;
+
+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;
+
+/**
+ * @author koul
+ * @email koul@usoftchina.com
+ * @date 2020-11-26 19:15
+ */
+@Service
+public class UploadServiceImpl implements UploadService {
+    public static Pattern pat = Pattern.compile("\\{(.*?)\\}");
+
+    @Override
+    public void uploadRun() {
+        //香港华商龙
+        uploadBySob("N_HUASL");
+        //威尔电子
+        uploadBySob("N_WILICHK");
+        //柏建控股
+        uploadBySob("N_BJKG");
+        //深圳华商龙
+        uploadBySob("N_HUASL_SZ");
+        //上海宇声
+        uploadBySob("N_E_SHINE_SH");
+        //青岛华商龙
+        uploadBySob("N_HUASL_QD");
+        //重庆华商龙
+        uploadBySob("HSL_CQ");
+        //北京华商龙
+        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) {
+        Statement statement = null;
+        FTPClient client = 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;
+                                }
+                                client = FtpUtil.connect(config,config.get("in").toString());
+                                if(client==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(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;
+            }
+            //把当前的连接关闭
+            try {
+                if(connect!=null){
+                    connect.close();
+                }
+            } catch (SQLException e) {
+                e.printStackTrace();
+            }finally{
+                connect = null;
+            }
+        }
+
+    }
+}

+ 13 - 0
src/main/java/com/uas/service/UploadService.java

@@ -0,0 +1,13 @@
+package com.uas.service;
+
+/**
+ * @author koul
+ * @email koul@usoftchina.com
+ * @date 2020-11-26 19:13
+ */
+public interface UploadService {
+
+    void uploadRun();
+
+    void uploadBySob(String sob);
+}

+ 49 - 0
src/main/java/com/uas/task/ScheduleTask.java

@@ -0,0 +1,49 @@
+package com.uas.task;
+
+
+import com.uas.service.DownloadFilePathService;
+import com.uas.service.DownloadService;
+import com.uas.service.DownloadStcockQtyService;
+import com.uas.service.UploadService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+
+/**
+ * @author koul
+ * @email koul@usoftchina.com
+ * @date 2020-11-27 09:42
+ */
+@Component("scheduleTask")
+public class ScheduleTask {
+
+    @Autowired
+    private UploadService uploadService;
+    @Autowired
+    private DownloadService downloadService;
+
+    @Autowired
+    private DownloadStcockQtyService downloadStcockQtyService;
+
+    @Autowired
+    private DownloadFilePathService downloadFilePathService;
+
+   @Scheduled(fixedRate=1000*60*5)
+    public void ediSendAndReceive() {
+        uploadService.uploadRun();
+        downloadService.downloadRun();
+    }
+
+    @Scheduled(fixedRate=1000*60*60)
+    public void downloadStcockQty() {
+        downloadStcockQtyService.downloadQty();
+    }
+
+
+    @Scheduled(fixedRate=1000*60*60)
+    public void filePath() {
+        downloadFilePathService.runDownloadFilePath();
+     }
+
+}

+ 3 - 2
src/main/java/com/uas/util/FtpUtil.java

@@ -284,7 +284,8 @@ public static List<File> downloadFileByDirectory(FTPClient ftpClient,String dire
 		List<File> files = new ArrayList<File>();
 		try {
 			ftpClient.enterLocalPassiveMode();
-			ftpClient.changeWorkingDirectory("/" + directory);// 转移到FTP服务器目录
+			// 转移到FTP服务器目录
+			ftpClient.changeWorkingDirectory("/" + directory);
 			FTPFile[] ftpFiles = ftpClient.listFiles();
 			if (ftpFiles != null && ftpFiles.length > 0) {
 				ArrayList<FTPFile> list = new ArrayList<FTPFile>(Arrays.asList(ftpFiles));
@@ -303,7 +304,7 @@ public static List<File> downloadFileByDirectory(FTPClient ftpClient,String dire
 					}
 				});
 				for (FTPFile file : list) {
-					if(!".".equals(file.getName()) && !"..".equals(file.getName())&& !"bak".equals(file.getName())) {
+					if(!".".equals(file.getName()) && !"..".equals(file.getName())&& !"bak".equals(file.getName())&& !"failed".equals(file.getName())) {
 						File localFile = new File(System.getProperty("java.io.tmpdir") + File.separator + file.getName());
 						OutputStream os = new FileOutputStream(localFile);
 						ftpClient.retrieveFile(file.getName(), os);

+ 2 - 34
src/main/resources/properties/ftpconfig.properties

@@ -67,38 +67,6 @@
         "password":"24g777sW",
         "downloadpath":"postback",
         "in":"normal",
-        "file":"hsl/hkhsl/file"
-    },
-    "N_HUASL-XN":{
-        "ip":"218.4.62.135",
-        "port":21,
-        "user":"hsltoxn",
-        "password":"HtxN527%#",
-        "downloadpath":"From_XN",
-        "in":"To_XN"
-    },
-    "N_HUASL-QF":{
-		"ip":"omsftp.icorebuy.com",
-		"port":21,
-		"user":"YTZH02",
-		"password":"Ytzh)@2018",
-		"downloadpath":"From_QF",
-		"in":"TO_QF"
-	},
-	"N_WILICHK-QF":{
-		"ip":"omsftp.icorebuy.com",
-		"port":21,
-		"user":"YTZH02",
-		"password":"Ytzh)@2018",
-		"downloadpath":"From_QF",
-		"in":"TO_QF"
-	},
-	"N_BJKG-QF":{
-		"ip":"omsftp.icorebuy.com",
-		"port":21,
-		"user":"YTZH02",
-		"password":"Ytzh)@2018",
-		"downloadpath":"From_QF",
-		"in":"TO_QF"
-	}
+        "file":"signback"
+    }
 }

+ 104 - 0
src/main/resources/properties/ftpconfig3.properties

@@ -0,0 +1,104 @@
+{
+    "N_HUASL_SZ-DRD":{
+        "ip":"58.211.24.196",
+        "port":21,
+        "user":"yitoa",
+        "password":"yitoa@2020",
+        "downloadpath":"Ack/SZHSL",
+        "in":"Order/SZHSL",
+        "qty":"Inv/SZHSL"
+    },
+    "N_E_SHINE_SH-DRD":{
+        "ip":"58.211.24.196",
+        "port":21,
+        "user":"yitoa",
+        "password":"yitoa@2020",
+        "downloadpath":"Ack/SHYS",
+        "in":"Order/SHYS",
+        "qty":"Inv/SHYS"
+    },
+    "N_HUASL_QD-DRD":{
+        "ip":"58.211.24.196",
+        "port":21,
+        "user":"yitoa",
+        "password":"yitoa@2020",
+        "downloadpath":"Ack/QDHSL",
+        "in":"Order/QDHSL",
+        "qty":"Inv/QDHSL"
+    },
+    "HSL_BJ-DRD":{
+        "ip":"58.211.24.196",
+        "port":21,
+        "user":"yitoa",
+        "password":"yitoa@2020",
+        "downloadpath":"Ack/BJHSL",
+        "in":"Order/BJHSL",
+        "qty":"Inv/BJHSL"
+    },
+    "HSL_CQ-DRD":{
+        "ip":"58.211.24.196",
+        "port":21,
+        "user":"yitoa",
+        "password":"yitoa@2020",
+        "downloadpath":"Ack/CQHSL",
+        "in":"Order/CQHSL",
+        "qty":"Inv/CQHSL"
+    },
+    "N_BJKG-FS":{
+        "ip":"113.100.137.106",
+        "port":21,
+        "user":"b2b_ftp",
+        "password":"24g777sW",
+        "downloadpath":"baij_postback",
+        "in":"baij_normal"
+    },
+    "N_WILICHK-FS":{
+        "ip":"113.100.137.106",
+        "port":21,
+        "user":"b2b_ftp",
+        "password":"24g777sW",
+        "downloadpath":"weier_postback",
+        "in":"weier_normal"
+    },
+    "N_HUASL-FS":{
+        "ip":"113.100.137.106",
+        "port":21,
+        "user":"b2b_ftp",
+        "password":"24g777sW",
+        "downloadpath":"postback",
+        "in":"normal",
+        "file":"hsl/hkhsl/file"
+    },
+    "N_HUASL-XN":{
+        "ip":"218.4.62.135",
+        "port":21,
+        "user":"hsltoxn",
+        "password":"HtxN527%#",
+        "downloadpath":"From_XN",
+        "in":"To_XN"
+    },
+    "N_HUASL-QF":{
+		"ip":"omsftp.icorebuy.com",
+		"port":21,
+		"user":"YTZH02",
+		"password":"Ytzh)@2018",
+		"downloadpath":"From_QF",
+		"in":"TO_QF"
+	},
+	"N_WILICHK-QF":{
+		"ip":"omsftp.icorebuy.com",
+		"port":21,
+		"user":"YTZH02",
+		"password":"Ytzh)@2018",
+		"downloadpath":"From_QF",
+		"in":"TO_QF"
+	},
+	"N_BJKG-QF":{
+		"ip":"omsftp.icorebuy.com",
+		"port":21,
+		"user":"YTZH02",
+		"password":"Ytzh)@2018",
+		"downloadpath":"From_QF",
+		"in":"TO_QF"
+	}
+}

Неке датотеке нису приказане због велике количине промена