作者 朱兆平

技术回执处理

@@ -137,7 +137,10 @@ custom: @@ -137,7 +137,10 @@ custom:
137 receptBakDir: /Users/mrz/Downloads/rdp_temp/logs/success 137 receptBakDir: /Users/mrz/Downloads/rdp_temp/logs/success
138 #解析错误报文的备份目录 138 #解析错误报文的备份目录
139 errBakDir: /Users/mrz/Downloads/rdp_temp/logs/error 139 errBakDir: /Users/mrz/Downloads/rdp_temp/logs/error
  140 + #回执转发目录
140 transmitDir: /Users/mrz/Downloads/rdp_temp/logs/transmit 141 transmitDir: /Users/mrz/Downloads/rdp_temp/logs/transmit
  142 + #匹配技术回执正则
  143 + delTechnologyReceptMatch: CN_MT(.*)_1P0_460470678920X_(.*).xml
141 devops: 144 devops:
142 dir: 145 dir:
143 singlewindow-tcs-recept: D:\TCSSingleWindow\recive 146 singlewindow-tcs-recept: D:\TCSSingleWindow\recive
@@ -21,6 +21,7 @@ import org.xml.sax.SAXParseException; @@ -21,6 +21,7 @@ import org.xml.sax.SAXParseException;
21 import javax.annotation.PostConstruct; 21 import javax.annotation.PostConstruct;
22 import java.io.File; 22 import java.io.File;
23 import java.io.FileNotFoundException; 23 import java.io.FileNotFoundException;
  24 +import java.io.IOException;
24 import java.io.UnsupportedEncodingException; 25 import java.io.UnsupportedEncodingException;
25 import java.util.concurrent.CountDownLatch; 26 import java.util.concurrent.CountDownLatch;
26 27
@@ -43,6 +44,10 @@ public class CustomXmlHandleThread implements Runnable{ @@ -43,6 +44,10 @@ public class CustomXmlHandleThread implements Runnable{
43 @Value("${custom.errBakDir}") 44 @Value("${custom.errBakDir}")
44 private String errBakDir; 45 private String errBakDir;
45 46
  47 + //匹配技术回执正则
  48 + @Value("${custom.delTechnologyReceptMatch}")
  49 + private String delTechnologyReceptMatch;
  50 +
46 private File xmlfile; 51 private File xmlfile;
47 52
48 private static CustomXmlHandleThread customXmlHandle; 53 private static CustomXmlHandleThread customXmlHandle;
@@ -87,30 +92,42 @@ public class CustomXmlHandleThread implements Runnable{ @@ -87,30 +92,42 @@ public class CustomXmlHandleThread implements Runnable{
87 92
88 customXmlHandle.errBakDir = this.errBakDir; 93 customXmlHandle.errBakDir = this.errBakDir;
89 94
  95 + customXmlHandle.delTechnologyReceptMatch = this.delTechnologyReceptMatch;
  96 +
90 // 初使化时将已静态化的testService实例化 97 // 初使化时将已静态化的testService实例化
91 } 98 }
92 99
93 @Override 100 @Override
94 public void run() { 101 public void run() {
95 - log.info("线程:{}开始",xmlfile.getName());  
96 - try{  
97 - int i =handelXmlDocument();  
98 - String today = DateUtil.getTodayBy_yyyyMMdd();  
99 - String backdireByDay = customXmlHandle.bakupDir + "/" + today;  
100 - //操作成功,则转移剪切解析文件到备份目录,否则转移到error目录备份  
101 - if(i>0){  
102 - File bakupDirectory = new File(backdireByDay);  
103 - //解析成功备份一份到备份目录  
104 - FileUtils.moveFileToDirectory(xmlfile,bakupDirectory,true);  
105 - }else { 102 + String filename = xmlfile.getName();
  103 + log.info("线程:{}开始",filename);
  104 + if(filename.matches(customXmlHandle.delTechnologyReceptMatch)){
  105 + log.warn("{}报文为技术回执,剪切到错误备份目录,不解析",filename);
  106 + errBak(xmlfile);
  107 + log.info("{}报文为技术回执,剪切备份成功..开始解析下一文件,当前线程即将结束",filename);
  108 + }
  109 + else
  110 + {
  111 + try{
  112 + int i =handelXmlDocument();
  113 + String today = DateUtil.getTodayBy_yyyyMMdd();
  114 + String backdireByDay = customXmlHandle.bakupDir + "/" + today;
  115 + //操作成功,则转移剪切解析文件到备份目录,否则转移到error目录备份
  116 + if(i>0){
  117 + File bakupDirectory = new File(backdireByDay);
  118 + //解析成功备份一份到备份目录
  119 + FileUtils.moveFileToDirectory(xmlfile,bakupDirectory,true);
  120 + }else {
  121 + errBak(xmlfile);
  122 + }
  123 + }catch (FileExistsException e){
  124 + log.error("错误的解析文件剪切失败,目标目录已存在同名文件");
  125 + }catch (Exception e){
  126 + log.error("错误的解析文件剪切失败,目标目录已存在同名文件",e);
106 errBak(xmlfile); 127 errBak(xmlfile);
  128 + e.printStackTrace();
107 } 129 }
108 - }catch (FileExistsException e){  
109 - log.error("错误的解析文件剪切失败,目标目录已存在同名文件");  
110 - }catch (Exception e){  
111 - log.error("错误的解析文件剪切失败,目标目录已存在同名文件",e);  
112 - errBak(xmlfile);  
113 - e.printStackTrace(); 130 +
114 } 131 }
115 132
116 log.info("线程:{}结束",xmlfile.getName()); 133 log.info("线程:{}结束",xmlfile.getName());
@@ -330,4 +347,5 @@ public class CustomXmlHandleThread implements Runnable{ @@ -330,4 +347,5 @@ public class CustomXmlHandleThread implements Runnable{
330 e.printStackTrace(); 347 e.printStackTrace();
331 } 348 }
332 } 349 }
  350 +
333 } 351 }
@@ -31,6 +31,8 @@ public class TaskAnalysis { @@ -31,6 +31,8 @@ public class TaskAnalysis {
31 @Value("${custom.transmitDir}") 31 @Value("${custom.transmitDir}")
32 private String transmitDir; 32 private String transmitDir;
33 33
  34 +
  35 +
34 /** 36 /**
35 * 线程数量 37 * 线程数量
36 */ 38 */
@@ -45,7 +47,7 @@ public class TaskAnalysis { @@ -45,7 +47,7 @@ public class TaskAnalysis {
45 47
46 //设置转发文件夹 48 //设置转发文件夹
47 String today = DateUtil.getTodayBy_yyyyMMdd(); 49 String today = DateUtil.getTodayBy_yyyyMMdd();
48 - String transToCfps = transmitDir + "/" + today; 50 + String transToCfps = transmitDir;
49 //回执目录 51 //回执目录
50 String readDir = receptDir; 52 String readDir = receptDir;
51 53