作者 朱兆平

运抵解析OK

@@ -49,7 +49,7 @@ spring: @@ -49,7 +49,7 @@ spring:
49 type: com.alibaba.druid.pool.DruidDataSource 49 type: com.alibaba.druid.pool.DruidDataSource
50 #oracle 50 #oracle
51 driver-class-name: oracle.jdbc.OracleDriver 51 driver-class-name: oracle.jdbc.OracleDriver
52 - url: jdbc:oracle:thin:@218.28.199.134:8004banner.txt:CGODB 52 + url: jdbc:oracle:thin:@218.28.199.134:8004:CGODB
53 username: CGONMS 53 username: CGONMS
54 password: 1q2w3e4r 54 password: 1q2w3e4r
55 #spring datasource mysql,注意编码配置,缺少数据库编码配置容易引起中文入库乱码 55 #spring datasource mysql,注意编码配置,缺少数据库编码配置容易引起中文入库乱码
@@ -132,7 +132,7 @@ jwt: @@ -132,7 +132,7 @@ jwt:
132 #自定义配置 132 #自定义配置
133 custom: 133 custom:
134 #进港放行回执读取目录 134 #进港放行回执读取目录
135 - receptDirectory: /Users/mrz/Downloads/rdp_temp 135 + receptDirectory: /Users/mrz/Downloads/rdp_temp/logs/回执报文样例
136 #回执解析成功后的备份目录 136 #回执解析成功后的备份目录
137 receptBakDir: ./success 137 receptBakDir: ./success
138 #解析错误报文的备份目录 138 #解析错误报文的备份目录
@@ -25,7 +25,7 @@ @@ -25,7 +25,7 @@
25 <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> 25 <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
26 <!--此日志appender是为开发使用,只配置最底级别,控制台输出的日志级别是大于或等于此级别的日志信息--> 26 <!--此日志appender是为开发使用,只配置最底级别,控制台输出的日志级别是大于或等于此级别的日志信息-->
27 <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> 27 <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
28 - <level>info</level> 28 + <level>DEBUG</level>
29 </filter> 29 </filter>
30 <encoder> 30 <encoder>
31 <Pattern>${CONSOLE_LOG_PATTERN}</Pattern> 31 <Pattern>${CONSOLE_LOG_PATTERN}</Pattern>
  1 +package com.tianbo.analysis.bean;
  2 +import org.springframework.beans.BeansException;
  3 +import org.springframework.context.ApplicationContext;
  4 +import org.springframework.context.ApplicationContextAware;
  5 +import org.springframework.stereotype.Component;
  6 +
  7 +/**
  8 + * @ProjectName:
  9 + * @Package: com.backstage.config
  10 + * @ClassName: ApplicationContextProvider
  11 + * @Description: 获取bean对象的工具类
  12 + * @Author: wangzhilong
  13 + * @CreateDate: 2018/8/31 13:26
  14 + * @Version: 1.0
  15 + */
  16 +
  17 +/**
  18 + * Author:ZhuShangJin
  19 + * Date:2018/7/3
  20 + */
  21 +@Component
  22 +public class SpringBeanUtitl implements ApplicationContextAware{
  23 +
  24 + private static ApplicationContext applicationContext = null;
  25 + @Override
  26 + public void setApplicationContext(ApplicationContext applicationContext) throws
  27 + BeansException {
  28 + // TODO Auto-generated method stub
  29 + SpringBeanUtitl.applicationContext = applicationContext;
  30 + }
  31 +
  32 + /**
  33 + * 从静态变量applicationContext中得到Bean, 自动转型为所赋值对象的类型.
  34 + */
  35 + @SuppressWarnings("unchecked")
  36 + public static <T> T getBean(String name) {
  37 + if(name == null || applicationContext == null){
  38 + return null;
  39 + }
  40 +
  41 + return (T) applicationContext.getBean(name);
  42 + }
  43 +
  44 + /**
  45 + * 从静态变量applicationContext中得到Bean, 自动转型为所赋值对象的类型.
  46 + */
  47 + public static <T> T getBean(Class<T> clazz) {
  48 + return applicationContext.getBean(clazz);
  49 + }
  50 +
  51 +}
  52 +
1 package com.tianbo.analysis.controller; 1 package com.tianbo.analysis.controller;
2 2
3 -import com.tianbo.analysis.handle.CustomXmlHandle;  
4 -import com.tianbo.util.Date.DateUtil;  
5 import com.tianbo.util.IO.FileTool; 3 import com.tianbo.util.IO.FileTool;
6 import lombok.extern.slf4j.Slf4j; 4 import lombok.extern.slf4j.Slf4j;
7 -import org.apache.commons.io.FileUtils;  
8 import org.springframework.beans.factory.annotation.Value; 5 import org.springframework.beans.factory.annotation.Value;
9 -import org.springframework.stereotype.Controller;  
10 import org.springframework.web.bind.annotation.RequestMapping; 6 import org.springframework.web.bind.annotation.RequestMapping;
11 import org.springframework.web.bind.annotation.RequestParam; 7 import org.springframework.web.bind.annotation.RequestParam;
12 import org.springframework.web.bind.annotation.RestController; 8 import org.springframework.web.bind.annotation.RestController;
13 9
14 import java.io.File; 10 import java.io.File;
15 -import java.util.Iterator;  
16 import java.util.List; 11 import java.util.List;
17 12
18 @RestController 13 @RestController
1 package com.tianbo.analysis.handle; 1 package com.tianbo.analysis.handle;
2 2
3 -import com.fasterxml.jackson.databind.annotation.JsonAppend;  
4 -import com.sun.xml.internal.ws.util.xml.XmlUtil;  
5 import com.tianbo.analysis.model.CustomReception; 3 import com.tianbo.analysis.model.CustomReception;
6 import com.tianbo.analysis.service.*; 4 import com.tianbo.analysis.service.*;
  5 +import com.tianbo.util.Date.DateUtil;
7 import com.tianbo.util.XML.XMLXPath; 6 import com.tianbo.util.XML.XMLXPath;
  7 +import lombok.Data;
  8 +import lombok.extern.slf4j.Slf4j;
  9 +import org.apache.commons.io.FileExistsException;
8 import org.apache.commons.io.FileUtils; 10 import org.apache.commons.io.FileUtils;
9 import org.dom4j.Document; 11 import org.dom4j.Document;
10 import org.dom4j.DocumentException; 12 import org.dom4j.DocumentException;
11 -import org.dom4j.DocumentHelper;  
12 import org.dom4j.Element; 13 import org.dom4j.Element;
13 import org.dom4j.io.SAXReader; 14 import org.dom4j.io.SAXReader;
14 import org.springframework.beans.factory.annotation.Autowired; 15 import org.springframework.beans.factory.annotation.Autowired;
  16 +import org.springframework.beans.factory.annotation.Value;
15 import org.springframework.stereotype.Component; 17 import org.springframework.stereotype.Component;
16 import org.xml.sax.SAXParseException; 18 import org.xml.sax.SAXParseException;
17 19
18 import javax.annotation.PostConstruct; 20 import javax.annotation.PostConstruct;
19 import java.io.File; 21 import java.io.File;
  22 +import java.io.FileNotFoundException;
20 import java.io.UnsupportedEncodingException; 23 import java.io.UnsupportedEncodingException;
21 -import java.util.List;  
22 24
23 /** 25 /**
24 * @author mrz 26 * @author mrz
25 * @e 27 * @e
26 * 海关新舱单回执解析xml文件 28 * 海关新舱单回执解析xml文件
27 */ 29 */
  30 +@Data
28 @Component 31 @Component
29 -public class CustomXmlHandle{ 32 +@Slf4j
  33 +public class CustomXmlHandleThread implements Runnable{
30 34
31 - private static CustomXmlHandle customXmlHandle; 35 + //备份目录
  36 + @Value("${custom.receptBakDir}")
  37 + private String bakupDir;
  38 +
  39 + //解析出错转移目录
  40 + @Value("${custom.errBakDir}")
  41 + private String errBakDir;
  42 +
  43 + private File xmlfile;
  44 + private static CustomXmlHandleThread customXmlHandle;
32 //海关新舱单回执报头 45 //海关新舱单回执报头
33 public final static String MessageID = "//Manifest/Head/MessageID"; 46 public final static String MessageID = "//Manifest/Head/MessageID";
34 public final static String FunctionCode = "//Manifest/Head/FunctionCode"; 47 public final static String FunctionCode = "//Manifest/Head/FunctionCode";
@@ -40,10 +53,10 @@ public class CustomXmlHandle{ @@ -40,10 +53,10 @@ public class CustomXmlHandle{
40 53
41 //海关新舱单回执报体 54 //海关新舱单回执报体
42 public final static String JourneyID = "//Manifest/Response/BorderTransportMeans/JourneyID"; 55 public final static String JourneyID = "//Manifest/Response/BorderTransportMeans/JourneyID";
43 - public final static String waybillMaster = "//Manifest/Response/Consignment/TransportContractDocument/ID";  
44 - public final static String waybillSecond = "//Manifest/Response/Consignment/AssociatedTransportDocument/ID";  
45 - public final static String responseCode = "//Manifest/Response/Consignment/ResponseType/Code";  
46 - public final static String responseText = "//Manifest/Response/Consignment/ResponseType/Text"; 56 + public final static String WaybillMaster = "//Manifest/Response/Consignment/TransportContractDocument/ID";
  57 + public final static String WaybillSecond = "//Manifest/Response/Consignment/AssociatedTransportDocument/ID";
  58 + public final static String ResponseCode = "//Manifest/Response/Consignment/ResponseType/Code";
  59 + public final static String ResponseText = "//Manifest/Response/Consignment/ResponseType/Text";
47 60
48 @Autowired 61 @Autowired
49 private CoustomAnalysisService coustomAnalysisService; 62 private CoustomAnalysisService coustomAnalysisService;
@@ -66,6 +79,7 @@ public class CustomXmlHandle{ @@ -66,6 +79,7 @@ public class CustomXmlHandle{
66 @Autowired 79 @Autowired
67 private INPORTALLOCATEService inportallocateService; 80 private INPORTALLOCATEService inportallocateService;
68 81
  82 +
69 //通过@PostConstruct实现初始化bean之前进行的操作,解决service调用空指针问题 83 //通过@PostConstruct实现初始化bean之前进行的操作,解决service调用空指针问题
70 @PostConstruct 84 @PostConstruct
71 public void init() { 85 public void init() {
@@ -83,28 +97,52 @@ public class CustomXmlHandle{ @@ -83,28 +97,52 @@ public class CustomXmlHandle{
83 customXmlHandle.allocatearrivalService = this.allocatearrivalService; 97 customXmlHandle.allocatearrivalService = this.allocatearrivalService;
84 98
85 customXmlHandle.inportallocateService = this.inportallocateService; 99 customXmlHandle.inportallocateService = this.inportallocateService;
  100 +
  101 + customXmlHandle.bakupDir = this.bakupDir;
  102 +
  103 + customXmlHandle.errBakDir = this.errBakDir;
86 // 初使化时将已静态化的testService实例化 104 // 初使化时将已静态化的testService实例化
87 } 105 }
88 106
  107 + @Override
  108 + public void run() {
  109 +
  110 + try{
  111 + int i =handelXmlDocument();
  112 + String today = DateUtil.getTodayBy_yyyyMMdd();
  113 + String backdireByDay = customXmlHandle.bakupDir + "/" + today;
  114 + //操作成功,则转移剪切解析文件到备份目录,否则转移到error目录备份
  115 + if(i>0){
  116 + File bakupDirectory = new File(backdireByDay);
  117 + FileUtils.moveFileToDirectory(xmlfile,bakupDirectory,true);
  118 + }else {
  119 + errBak(xmlfile);
  120 + }
  121 + }catch (FileExistsException e){
  122 + log.error("错误的解析文件剪切失败,目标目录已存在同名文件",e);
  123 + e.printStackTrace();
  124 + }catch (Exception e){
  125 + e.printStackTrace();
  126 + }
  127 +
  128 + }
89 /** 129 /**
90 * 130 *
91 - * @param file 回执目录的文件 131 + *
92 * @return 132 * @return
93 * @throws DocumentException 133 * @throws DocumentException
94 * @throws UnsupportedEncodingException 134 * @throws UnsupportedEncodingException
95 * @throws SAXParseException 135 * @throws SAXParseException
  136 + * @throws FileNotFoundException
96 */ 137 */
97 - public int handelXmlDocument(File file) throws DocumentException,UnsupportedEncodingException,SAXParseException { 138 + public int handelXmlDocument() throws DocumentException,UnsupportedEncodingException,SAXParseException,FileNotFoundException {
98 139
99 int i = 0; 140 int i = 0;
100 141
101 SAXReader saxReader = new SAXReader(); 142 SAXReader saxReader = new SAXReader();
102 - Document document = saxReader.read(file); 143 + Document document = saxReader.read(xmlfile);
103 Element contentRoot = document.getRootElement(); 144 Element contentRoot = document.getRootElement();
104 145
105 - //要解析的回执类型  
106 - String type= "MT9999";  
107 -  
108 String flightNo = ""; 146 String flightNo = "";
109 String flightDate = ""; 147 String flightDate = "";
110 148
@@ -114,7 +152,7 @@ public class CustomXmlHandle{ @@ -114,7 +152,7 @@ public class CustomXmlHandle{
114 String journeyid = XMLXPath.getSingleValueByPath(document,JourneyID); 152 String journeyid = XMLXPath.getSingleValueByPath(document,JourneyID);
115 // XMLXPath.getSingleValueByPath(document, ) 153 // XMLXPath.getSingleValueByPath(document, )
116 154
117 - if(journeyid != null){ 155 + if(journeyid != null&& !journeyid.isEmpty()){
118 156
119 String[] flightList = journeyid.split("/"); 157 String[] flightList = journeyid.split("/");
120 if(flightList.length > 0){ 158 if(flightList.length > 0){
@@ -125,13 +163,31 @@ public class CustomXmlHandle{ @@ -125,13 +163,31 @@ public class CustomXmlHandle{
125 163
126 } 164 }
127 165
128 - String awbA = XMLXPath.getSingleValueByPath(document,waybillMaster); 166 + String awbA = XMLXPath.getSingleValueByPath(document,WaybillMaster);
129 //全格式的分单 如 17212345678_ADBD 167 //全格式的分单 如 17212345678_ADBD
130 - String awbH = XMLXPath.getSingleValueByPath(document,waybillSecond);  
131 - String resCode = XMLXPath.getSingleValueByPath(document,responseCode);  
132 - String resText = XMLXPath.getSingleValueByPath(document,responseText); 168 + String awbH = XMLXPath.getSingleValueByPath(document,WaybillSecond);
  169 + String resCode = XMLXPath.getSingleValueByPath(document,ResponseCode);
  170 + String resText = XMLXPath.getSingleValueByPath(document,ResponseText);
133 String messageId = XMLXPath.getSingleValueByPath(document, MessageID); 171 String messageId = XMLXPath.getSingleValueByPath(document, MessageID);
134 - CustomReception customReception = new CustomReception(msgType,flightNo,flightDate,awbA,awbH,resText, messageId); 172 + String sendTime = XMLXPath.getSingleValueByPath(document,SendTime);
  173 + String sendId = XMLXPath.getSingleValueByPath(document,SenderID);
  174 + String reciveId = XMLXPath.getSingleValueByPath(document,ReceiverID);
  175 + String version = XMLXPath.getSingleValueByPath(document,Version);
  176 + String functionCode = XMLXPath.getSingleValueByPath(document,FunctionCode);
  177 +
  178 + CustomReception customReception = new CustomReception( msgType,
  179 + flightNo,
  180 + flightDate,
  181 + awbA,
  182 + awbH,
  183 + resCode,
  184 + resText,
  185 + messageId,
  186 + sendTime,
  187 + sendId,
  188 + reciveId,
  189 + version,
  190 + functionCode);
135 switch (msgType){ 191 switch (msgType){
136 case "MT9999": 192 case "MT9999":
137 i = customXmlHandle.coustomAnalysisService.insertRecept(customReception); 193 i = customXmlHandle.coustomAnalysisService.insertRecept(customReception);
@@ -168,4 +224,19 @@ public class CustomXmlHandle{ @@ -168,4 +224,19 @@ public class CustomXmlHandle{
168 224
169 return i; 225 return i;
170 } 226 }
  227 +
  228 + public void errBak(File file){
  229 + try {
  230 + String today = DateUtil.getTodayBy_yyyyMMdd();
  231 + String errDirByDay = customXmlHandle.errBakDir + "/" + today;
  232 + File berrDirectory = new File(errDirByDay);
  233 + FileUtils.moveFileToDirectory(file,berrDirectory,true);
  234 + log.error("解析或其他错误备份文件:"+File.pathSeparator);
  235 + }catch (FileExistsException e){
  236 + log.error("错误的解析文件剪切失败,目标目录已存在同名文件",e);
  237 + e.printStackTrace();
  238 + }catch (Exception e){
  239 + e.printStackTrace();
  240 + }
  241 + }
171 } 242 }
1 package com.tianbo.analysis.model; 1 package com.tianbo.analysis.model;
2 2
  3 +import lombok.Data;
  4 +
3 import java.util.Date; 5 import java.util.Date;
4 6
  7 +@Data
5 public class ARRIVEDMASTER { 8 public class ARRIVEDMASTER {
6 private String autoid; 9 private String autoid;
7 10
@@ -13,7 +16,7 @@ public class ARRIVEDMASTER { @@ -13,7 +16,7 @@ public class ARRIVEDMASTER {
13 16
14 private String flightno; 17 private String flightno;
15 18
16 - private Date flightdate; 19 + private Date flightDate;
17 20
18 private String carrier; 21 private String carrier;
19 22
@@ -54,212 +57,4 @@ public class ARRIVEDMASTER { @@ -54,212 +57,4 @@ public class ARRIVEDMASTER {
54 private String receiptinformation; 57 private String receiptinformation;
55 58
56 private Date createdate; 59 private Date createdate;
57 -  
58 - public String getAutoid() {  
59 - return autoid;  
60 - }  
61 -  
62 - public void setAutoid(String autoid) {  
63 - this.autoid = autoid == null ? null : autoid.trim();  
64 - }  
65 -  
66 - public String getWaybillnomaster() {  
67 - return waybillnomaster;  
68 - }  
69 -  
70 - public void setWaybillnomaster(String waybillnomaster) {  
71 - this.waybillnomaster = waybillnomaster == null ? null : waybillnomaster.trim();  
72 - }  
73 -  
74 - public String getTcdName() {  
75 - return tcdName;  
76 - }  
77 -  
78 - public void setTcdName(String tcdName) {  
79 - this.tcdName = tcdName == null ? null : tcdName.trim();  
80 - }  
81 -  
82 - public String getTcdTypecode() {  
83 - return tcdTypecode;  
84 - }  
85 -  
86 - public void setTcdTypecode(String tcdTypecode) {  
87 - this.tcdTypecode = tcdTypecode == null ? null : tcdTypecode.trim();  
88 - }  
89 -  
90 - public String getFlightno() {  
91 - return flightno;  
92 - }  
93 -  
94 - public void setFlightno(String flightno) {  
95 - this.flightno = flightno == null ? null : flightno.trim();  
96 - }  
97 -  
98 - public Date getFlightdate() {  
99 - return flightdate;  
100 - }  
101 -  
102 - public void setFlightdate(Date flightdate) {  
103 - this.flightdate = flightdate;  
104 - }  
105 -  
106 - public String getCarrier() {  
107 - return carrier;  
108 - }  
109 -  
110 - public void setCarrier(String carrier) {  
111 - this.carrier = carrier == null ? null : carrier.trim();  
112 - }  
113 -  
114 - public String getOriginatingstation() {  
115 - return originatingstation;  
116 - }  
117 -  
118 - public void setOriginatingstation(String originatingstation) {  
119 - this.originatingstation = originatingstation == null ? null : originatingstation.trim();  
120 - }  
121 -  
122 - public String getoName() {  
123 - return oName;  
124 - }  
125 -  
126 - public void setoName(String oName) {  
127 - this.oName = oName == null ? null : oName.trim();  
128 - }  
129 -  
130 - public String getDestinationstation() {  
131 - return destinationstation;  
132 - }  
133 -  
134 - public void setDestinationstation(String destinationstation) {  
135 - this.destinationstation = destinationstation == null ? null : destinationstation.trim();  
136 - }  
137 -  
138 - public String getFdName() {  
139 - return fdName;  
140 - }  
141 -  
142 - public void setFdName(String fdName) {  
143 - this.fdName = fdName == null ? null : fdName.trim();  
144 - }  
145 -  
146 - public String getArrivedtotalpiece() {  
147 - return arrivedtotalpiece;  
148 - }  
149 -  
150 - public void setArrivedtotalpiece(String arrivedtotalpiece) {  
151 - this.arrivedtotalpiece = arrivedtotalpiece == null ? null : arrivedtotalpiece.trim();  
152 - }  
153 -  
154 - public String getTotalpiecequantity() {  
155 - return totalpiecequantity;  
156 - }  
157 -  
158 - public void setTotalpiecequantity(String totalpiecequantity) {  
159 - this.totalpiecequantity = totalpiecequantity == null ? null : totalpiecequantity.trim();  
160 - }  
161 -  
162 - public String getArrivedtotalweight() {  
163 - return arrivedtotalweight;  
164 - }  
165 -  
166 - public void setArrivedtotalweight(String arrivedtotalweight) {  
167 - this.arrivedtotalweight = arrivedtotalweight == null ? null : arrivedtotalweight.trim();  
168 - }  
169 -  
170 - public String getGrossweightmeasureuc() {  
171 - return grossweightmeasureuc;  
172 - }  
173 -  
174 - public void setGrossweightmeasureuc(String grossweightmeasureuc) {  
175 - this.grossweightmeasureuc = grossweightmeasureuc == null ? null : grossweightmeasureuc.trim();  
176 - }  
177 -  
178 - public String getTotalgrossweightmeasure() {  
179 - return totalgrossweightmeasure;  
180 - }  
181 -  
182 - public void setTotalgrossweightmeasure(String totalgrossweightmeasure) {  
183 - this.totalgrossweightmeasure = totalgrossweightmeasure == null ? null : totalgrossweightmeasure.trim();  
184 - }  
185 -  
186 - public String getTotalgrossweightmeasureuc() {  
187 - return totalgrossweightmeasureuc;  
188 - }  
189 -  
190 - public void setTotalgrossweightmeasureuc(String totalgrossweightmeasureuc) {  
191 - this.totalgrossweightmeasureuc = totalgrossweightmeasureuc == null ? null : totalgrossweightmeasureuc.trim();  
192 - }  
193 -  
194 - public String getChargeableweightmeasure() {  
195 - return chargeableweightmeasure;  
196 - }  
197 -  
198 - public void setChargeableweightmeasure(String chargeableweightmeasure) {  
199 - this.chargeableweightmeasure = chargeableweightmeasure == null ? null : chargeableweightmeasure.trim();  
200 - }  
201 -  
202 - public String getChargeableweightmeasureuc() {  
203 - return chargeableweightmeasureuc;  
204 - }  
205 -  
206 - public void setChargeableweightmeasureuc(String chargeableweightmeasureuc) {  
207 - this.chargeableweightmeasureuc = chargeableweightmeasureuc == null ? null : chargeableweightmeasureuc.trim();  
208 - }  
209 -  
210 - public Date getArriveddate() {  
211 - return arriveddate;  
212 - }  
213 -  
214 - public void setArriveddate(Date arriveddate) {  
215 - this.arriveddate = arriveddate;  
216 - }  
217 -  
218 - public String getTransportsplitdescription() {  
219 - return transportsplitdescription;  
220 - }  
221 -  
222 - public void setTransportsplitdescription(String transportsplitdescription) {  
223 - this.transportsplitdescription = transportsplitdescription == null ? null : transportsplitdescription.trim();  
224 - }  
225 -  
226 - public String getCustomscode() {  
227 - return customscode;  
228 - }  
229 -  
230 - public void setCustomscode(String customscode) {  
231 - this.customscode = customscode == null ? null : customscode.trim();  
232 - }  
233 -  
234 - public String getProductname() {  
235 - return productname;  
236 - }  
237 -  
238 - public void setProductname(String productname) {  
239 - this.productname = productname == null ? null : productname.trim();  
240 - }  
241 -  
242 - public String getStatus() {  
243 - return status;  
244 - }  
245 -  
246 - public void setStatus(String status) {  
247 - this.status = status == null ? null : status.trim();  
248 - }  
249 -  
250 - public String getReceiptinformation() {  
251 - return receiptinformation;  
252 - }  
253 -  
254 - public void setReceiptinformation(String receiptinformation) {  
255 - this.receiptinformation = receiptinformation == null ? null : receiptinformation.trim();  
256 - }  
257 -  
258 - public Date getCreatedate() {  
259 - return createdate;  
260 - }  
261 -  
262 - public void setCreatedate(Date createdate) {  
263 - this.createdate = createdate;  
264 - }  
265 } 60 }
@@ -23,14 +23,26 @@ public class CustomReception { @@ -23,14 +23,26 @@ public class CustomReception {
23 String flightDate, 23 String flightDate,
24 String wayBillMaster, 24 String wayBillMaster,
25 String wayBillSecond, 25 String wayBillSecond,
  26 + String responseCode,
26 String responseText, 27 String responseText,
27 - String messageID){ 28 + String messageID,
  29 + String sendTime,
  30 + String senderID,
  31 + String receiverID,
  32 + String version,
  33 + String functionCode){
28 this.messageType = messageType; 34 this.messageType = messageType;
29 this.flightNo = flightNo; 35 this.flightNo = flightNo;
30 this.flightDate = flightDate; 36 this.flightDate = flightDate;
31 this.wayBillMaster = wayBillMaster; 37 this.wayBillMaster = wayBillMaster;
32 this.wayBillSecond = wayBillSecond; 38 this.wayBillSecond = wayBillSecond;
  39 + this.responseCode = responseCode;
33 this.responseText = responseText; 40 this.responseText = responseText;
34 this.messageID = messageID; 41 this.messageID = messageID;
  42 + this.sendTime = sendTime;
  43 + this.senderID =senderID;
  44 + this.receiverID = receiverID;
  45 + this.version = version;
  46 + this.functionCode = functionCode;
35 } 47 }
36 } 48 }
@@ -6,6 +6,7 @@ import com.tianbo.analysis.model.ARRIVEDMASTER; @@ -6,6 +6,7 @@ import com.tianbo.analysis.model.ARRIVEDMASTER;
6 import com.tianbo.analysis.model.ARRIVEDSECONDARY; 6 import com.tianbo.analysis.model.ARRIVEDSECONDARY;
7 import com.tianbo.analysis.model.CustomReception; 7 import com.tianbo.analysis.model.CustomReception;
8 import com.tianbo.analysis.service.ARRIVEDMASTERService; 8 import com.tianbo.analysis.service.ARRIVEDMASTERService;
  9 +import com.tianbo.analysis.tools.AWBTools;
9 import com.tianbo.util.Date.DateUtil; 10 import com.tianbo.util.Date.DateUtil;
10 import lombok.extern.slf4j.Slf4j; 11 import lombok.extern.slf4j.Slf4j;
11 import org.apache.commons.lang.StringUtils; 12 import org.apache.commons.lang.StringUtils;
@@ -57,23 +58,24 @@ public class ARRIVEDMASTERServiceImp implements ARRIVEDMASTERService { @@ -57,23 +58,24 @@ public class ARRIVEDMASTERServiceImp implements ARRIVEDMASTERService {
57 //设置主单回执、航班号、航班日期 58 //设置主单回执、航班号、航班日期
58 ARRIVEDMASTER arrivedmaster = new ARRIVEDMASTER(); 59 ARRIVEDMASTER arrivedmaster = new ARRIVEDMASTER();
59 arrivedmaster.setReceiptinformation(reception); 60 arrivedmaster.setReceiptinformation(reception);
60 - arrivedmaster.setFlightno(customReception.getFlightNo());  
61 - arrivedmaster.setFlightdate(flightDate); 61 + //拆分航班号和承运人
  62 + String[] flightInfo = AWBTools.splitFlight(customReception.getFlightNo());
  63 + arrivedmaster.setFlightno(flightInfo[1]);
  64 + arrivedmaster.setCarrier(flightInfo[0]);
  65 + arrivedmaster.setFlightDate(flightDate);
62 66
63 // 判断航班号 航班日期 是否为空 67 // 判断航班号 航班日期 是否为空
64 if (flightDate != null && customReception.getFlightNo() != null){ 68 if (flightDate != null && customReception.getFlightNo() != null){
65 - if (awbA!=null && awbA.length()>0){  
66 - StringBuffer stringBuffer = new StringBuffer(awbA);  
67 - stringBuffer.insert(3,"-");  
68 - awbA = stringBuffer.toString(); 69 + //处理主单格式,将海关回执的主单号58019316861,变为580-19316861
  70 + awbA = AWBTools.awbFormat(awbA);
69 71
70 //设置主分单的 主单号 72 //设置主分单的 主单号
71 arrivedsecondary.setWaybillnomaster(awbA); 73 arrivedsecondary.setWaybillnomaster(awbA);
72 arrivedmaster.setWaybillnomaster(awbA); 74 arrivedmaster.setWaybillnomaster(awbA);
73 - }  
74 75
75 - //有分单号 更新分单  
76 - if(awbA!=null && awbA.length()>0 && awbH!=null && awbH.length()> 0){ 76 +
  77 + //有分单号 更新分单回执
  78 + if(awbA!=null && !awbA.isEmpty() && awbH!=null && !awbH.isEmpty()){
77 //取分单号 79 //取分单号
78 String[] awbhArr = awbH.split("_"); 80 String[] awbhArr = awbH.split("_");
79 String awbh = awbhArr[1]; 81 String awbh = awbhArr[1];
@@ -90,14 +92,17 @@ public class ARRIVEDMASTERServiceImp implements ARRIVEDMASTERService { @@ -90,14 +92,17 @@ public class ARRIVEDMASTERServiceImp implements ARRIVEDMASTERService {
90 int ii = coustomAnalysisServiceImp.insertSendlog("MT3201",reception,autoId); 92 int ii = coustomAnalysisServiceImp.insertSendlog("MT3201",reception,autoId);
91 93
92 int iii = shareServiceImp.updateMessages(customReception); 94 int iii = shareServiceImp.updateMessages(customReception);
93 - if (i>0 && ii>0 && iii > 0){ 95 + if (i>0 && ii>0 ){
  96 + return 1;
  97 + }
  98 + if ( iii > 0){
94 return 1; 99 return 1;
95 } 100 }
96 } 101 }
97 return 0; 102 return 0;
98 } 103 }
99 104
100 - //处理主单格式,将海关回执的主单号58019316861,变为580-19316861 105 +
101 if (awbA!=null && awbA.length()>0){ 106 if (awbA!=null && awbA.length()>0){
102 //更新主单回执 107 //更新主单回执
103 int i = arrivedmasterMapper.updateRECEIPTION(arrivedmaster); 108 int i = arrivedmasterMapper.updateRECEIPTION(arrivedmaster);
@@ -112,14 +117,19 @@ public class ARRIVEDMASTERServiceImp implements ARRIVEDMASTERService { @@ -112,14 +117,19 @@ public class ARRIVEDMASTERServiceImp implements ARRIVEDMASTERService {
112 int ii =coustomAnalysisServiceImp.insertSendlog("MT3201",reception,autoId); 117 int ii =coustomAnalysisServiceImp.insertSendlog("MT3201",reception,autoId);
113 118
114 int iii = shareServiceImp.updateMessages(customReception); 119 int iii = shareServiceImp.updateMessages(customReception);
115 - if (i>0 && ii>0 && iii > 0){ 120 +
  121 + if (i>0 && ii>0){
  122 + return 1;
  123 + }
  124 + if ( iii > 0){
116 return 1; 125 return 1;
117 } 126 }
  127 +
118 } 128 }
119 return 0; 129 return 0;
120 } 130 }
121 }else { 131 }else {
122 - 132 + //从发送日志表查找发送MESSAGEID进行二次入库
123 return shareServiceImp.share("MT3201", customReception); 133 return shareServiceImp.share("MT3201", customReception);
124 } 134 }
125 } 135 }
@@ -127,4 +137,6 @@ public class ARRIVEDMASTERServiceImp implements ARRIVEDMASTERService { @@ -127,4 +137,6 @@ public class ARRIVEDMASTERServiceImp implements ARRIVEDMASTERService {
127 //未进入主分单解析 返回0 失败 137 //未进入主分单解析 返回0 失败
128 return 0; 138 return 0;
129 } 139 }
  140 +
  141 +
130 } 142 }
1 package com.tianbo.analysis.service.imp; 1 package com.tianbo.analysis.service.imp;
2 2
  3 +import com.tianbo.analysis.bean.SpringBeanUtitl;
3 import com.tianbo.analysis.dao.ORIGINMANIFESTMASTERMapper; 4 import com.tianbo.analysis.dao.ORIGINMANIFESTMASTERMapper;
4 import com.tianbo.analysis.dao.OriginmanifestsecondaryMapper; 5 import com.tianbo.analysis.dao.OriginmanifestsecondaryMapper;
5 import com.tianbo.analysis.dao.SENDLOGMapper; 6 import com.tianbo.analysis.dao.SENDLOGMapper;
@@ -30,6 +31,12 @@ public class CoustomAnalysisServiceImp implements CoustomAnalysisService { @@ -30,6 +31,12 @@ public class CoustomAnalysisServiceImp implements CoustomAnalysisService {
30 @Autowired 31 @Autowired
31 OriginmanifestsecondaryMapper originmanifestsecondaryMapper; 32 OriginmanifestsecondaryMapper originmanifestsecondaryMapper;
32 33
  34 + CoustomAnalysisServiceImp(){
  35 + //处理多线程时 springboot 无法注入bean的问题
  36 + if (this.sendlogMapper==null){
  37 + this.sendlogMapper = SpringBeanUtitl.getBean(SENDLOGMapper.class);
  38 + }
  39 + }
33 40
34 @Override 41 @Override
35 public int insertRecept(CustomReception customReception){ 42 public int insertRecept(CustomReception customReception){
@@ -134,6 +141,8 @@ public class CoustomAnalysisServiceImp implements CoustomAnalysisService { @@ -134,6 +141,8 @@ public class CoustomAnalysisServiceImp implements CoustomAnalysisService {
134 sendlog.setReceiption(reception); 141 sendlog.setReceiption(reception);
135 sendlog.setSendpeice(new Long(0)); 142 sendlog.setSendpeice(new Long(0));
136 sendlog.setSendweight(new BigDecimal(0)); 143 sendlog.setSendweight(new BigDecimal(0));
  144 +
  145 +
137 int i = sendlogMapper.insertSelective(sendlog); 146 int i = sendlogMapper.insertSelective(sendlog);
138 if (i>0){ 147 if (i>0){
139 log.info("插入日志成功,插入数据量为:"+i); 148 log.info("插入日志成功,插入数据量为:"+i);
1 package com.tianbo.analysis.service.imp; 1 package com.tianbo.analysis.service.imp;
2 2
  3 +import com.tianbo.analysis.bean.SpringBeanUtitl;
3 import com.tianbo.analysis.dao.*; 4 import com.tianbo.analysis.dao.*;
4 import com.tianbo.analysis.model.*; 5 import com.tianbo.analysis.model.*;
5 import lombok.extern.slf4j.Slf4j; 6 import lombok.extern.slf4j.Slf4j;
@@ -48,6 +49,10 @@ public class ShareServiceImp { @@ -48,6 +49,10 @@ public class ShareServiceImp {
48 @Autowired 49 @Autowired
49 CUSTOMSMESSAGEMapper customsmessageMapper; 50 CUSTOMSMESSAGEMapper customsmessageMapper;
50 51
  52 + ShareServiceImp(){
  53 + customsmessageMapper = SpringBeanUtitl.getBean(CUSTOMSMESSAGEMapper.class);
  54 + }
  55 +
51 public int share(String type, CustomReception customReception){ 56 public int share(String type, CustomReception customReception){
52 // 发送日志 插入 57 // 发送日志 插入
53 CoustomAnalysisServiceImp coustomAnalysisServiceImp = new CoustomAnalysisServiceImp(); 58 CoustomAnalysisServiceImp coustomAnalysisServiceImp = new CoustomAnalysisServiceImp();
@@ -84,7 +89,7 @@ public class ShareServiceImp { @@ -84,7 +89,7 @@ public class ShareServiceImp {
84 89
85 ARRIVEDMASTER arrivedmaster = new ARRIVEDMASTER(); 90 ARRIVEDMASTER arrivedmaster = new ARRIVEDMASTER();
86 arrivedmaster.setFlightno(cus.getFlightno()); 91 arrivedmaster.setFlightno(cus.getFlightno());
87 - arrivedmaster.setFlightdate(cus.getFlightdate()); 92 + arrivedmaster.setFlightDate(cus.getFlightdate());
88 arrivedmaster.setReceiptinformation(customReception.getResponseText()); 93 arrivedmaster.setReceiptinformation(customReception.getResponseText());
89 arrivedmaster.setAutoid(cus.getMasterautoid()); 94 arrivedmaster.setAutoid(cus.getMasterautoid());
90 arrivedmaster.setWaybillnomaster(waybill); 95 arrivedmaster.setWaybillnomaster(waybill);
@@ -2,9 +2,8 @@ package com.tianbo.analysis.task; @@ -2,9 +2,8 @@ package com.tianbo.analysis.task;
2 2
3 import com.tianbo.util.Date.DateUtil; 3 import com.tianbo.util.Date.DateUtil;
4 import com.tianbo.util.IO.FileTool; 4 import com.tianbo.util.IO.FileTool;
5 -import com.tianbo.analysis.handle.CustomXmlHandle; 5 +import com.tianbo.analysis.handle.CustomXmlHandleThread;
6 import lombok.extern.slf4j.Slf4j; 6 import lombok.extern.slf4j.Slf4j;
7 -import org.apache.commons.io.FileUtils;  
8 import org.springframework.beans.factory.annotation.Value; 7 import org.springframework.beans.factory.annotation.Value;
9 import org.springframework.scheduling.annotation.Scheduled; 8 import org.springframework.scheduling.annotation.Scheduled;
10 import org.springframework.stereotype.Component; 9 import org.springframework.stereotype.Component;
@@ -24,24 +23,10 @@ public class TaskAnalysis { @@ -24,24 +23,10 @@ public class TaskAnalysis {
24 @Value("${custom.receptDirectory}") 23 @Value("${custom.receptDirectory}")
25 private String receptDir; 24 private String receptDir;
26 25
27 - //备份目录  
28 - @Value("${custom.receptBakDir}")  
29 - private String bakupDir;  
30 -  
31 - //解析出错转移目录  
32 - @Value("${custom.errBakDir}")  
33 - private String errBakDir;  
34 -  
35 -  
36 -  
37 - @Scheduled(fixedDelay = 5000) 26 + @Scheduled(fixedDelay = 500000)
38 public void startTask(){ 27 public void startTask(){
39 - String today = DateUtil.getTodayBy_yyyyMMdd();  
40 - String readDir = receptDir + "/" + today;  
41 -  
42 -  
43 - String backdireByDay = bakupDir + "/" + today;  
44 - 28 + //回执目录
  29 + String readDir = receptDir;
45 try{ 30 try{
46 File fileDirectory = new File(readDir); 31 File fileDirectory = new File(readDir);
47 List<File> files = FileTool.readDirectoryFiles(fileDirectory); 32 List<File> files = FileTool.readDirectoryFiles(fileDirectory);
@@ -49,19 +34,14 @@ public class TaskAnalysis { @@ -49,19 +34,14 @@ public class TaskAnalysis {
49 while(it.hasNext()){ 34 while(it.hasNext()){
50 File file = it.next(); 35 File file = it.next();
51 try { 36 try {
52 - //解析  
53 - int i = new CustomXmlHandle().handelXmlDocument(file);  
54 - //操作成功,则转移剪切解析文件到备份目录,否则转移到error目录备份  
55 - if(i>0){  
56 - File bakupDirectory = new File(backdireByDay);  
57 - FileUtils.moveFileToDirectory(file,bakupDirectory,true);  
58 - }else {  
59 - errBak(file);  
60 - } 37 + CustomXmlHandleThread customXmlHandleThread = new CustomXmlHandleThread();
  38 + customXmlHandleThread.setXmlfile(file);
  39 + Thread thread = new Thread(customXmlHandleThread);
  40 + thread.start();
  41 +
61 }catch (Exception e){ 42 }catch (Exception e){
62 e.printStackTrace(); 43 e.printStackTrace();
63 log.error("解析回执出错",e); 44 log.error("解析回执出错",e);
64 - errBak(file);  
65 } 45 }
66 } 46 }
67 }catch (Exception e){ 47 }catch (Exception e){
@@ -70,16 +50,4 @@ public class TaskAnalysis { @@ -70,16 +50,4 @@ public class TaskAnalysis {
70 } 50 }
71 51
72 } 52 }
73 -  
74 - public void errBak(File file){  
75 - try {  
76 - String today = DateUtil.getTodayBy_yyyyMMdd();  
77 - String errDirByDay = errBakDir + "/" + today;  
78 - File berrDirectory = new File(errDirByDay);  
79 - FileUtils.moveFileToDirectory(file,berrDirectory,true);  
80 - log.error("解析或其他错误备份文件:"+File.pathSeparator);  
81 - }catch (Exception e){  
82 - e.printStackTrace();  
83 - }  
84 - }  
85 } 53 }
  1 +package com.tianbo.analysis.tools;
  2 +
  3 +public class AWBTools {
  4 +
  5 + public static String awbFormat(String awbNo) {
  6 + if (awbNo != null && awbNo.length() > 0) {
  7 + StringBuffer stringBuffer = new StringBuffer(awbNo);
  8 + stringBuffer.insert(3, "-");
  9 + awbNo = stringBuffer.toString();
  10 + return awbNo;
  11 + }
  12 + return null;
  13 + }
  14 +
  15 + public static String[] splitFlight(String flightNo){
  16 + String[] flight = {"1","2"};
  17 + flight[0] = flightNo.substring(0,2);
  18 + flight[1] = flightNo.substring(2);
  19 + return flight;
  20 + }
  21 +}
@@ -346,9 +346,14 @@ @@ -346,9 +346,14 @@
346 346
347 347
348 <update id="updateRECEIPTION" parameterType="com.tianbo.analysis.model.ARRIVEDMASTER" > 348 <update id="updateRECEIPTION" parameterType="com.tianbo.analysis.model.ARRIVEDMASTER" >
349 - UPDATE ARRIVEDMASTER  
350 - SET RECEIPTINFORMATION= #{receiptinformation,jdbcType=VARCHAR}  
351 - WHERE FLIGHTNO = #{flightno,jdbcType=VARCHAR} 349 + UPDATE
  350 + ARRIVEDMASTER
  351 + SET
  352 + RECEIPTINFORMATION= #{receiptinformation,jdbcType=VARCHAR}
  353 + WHERE
  354 + FLIGHTNO = #{flightno,jdbcType=VARCHAR}
  355 + AND
  356 + CARRIER = #{carrier,jdbcType=VARCHAR}
352 AND 357 AND
353 FLIGHTDATE= #{flightDate,jdbcType=TIMESTAMP} 358 FLIGHTDATE= #{flightDate,jdbcType=TIMESTAMP}
354 AND 359 AND