作者 朱兆平

批量申报的回执解析适配

@@ -13,6 +13,7 @@ import org.apache.commons.lang.StringUtils; @@ -13,6 +13,7 @@ import org.apache.commons.lang.StringUtils;
13 import org.dom4j.Document; 13 import org.dom4j.Document;
14 import org.dom4j.DocumentException; 14 import org.dom4j.DocumentException;
15 import org.dom4j.Element; 15 import org.dom4j.Element;
  16 +import org.dom4j.Node;
16 import org.dom4j.io.SAXReader; 17 import org.dom4j.io.SAXReader;
17 import org.springframework.beans.factory.annotation.Value; 18 import org.springframework.beans.factory.annotation.Value;
18 import org.springframework.stereotype.Component; 19 import org.springframework.stereotype.Component;
@@ -23,6 +24,7 @@ import java.io.File; @@ -23,6 +24,7 @@ import java.io.File;
23 import java.io.FileNotFoundException; 24 import java.io.FileNotFoundException;
24 import java.io.IOException; 25 import java.io.IOException;
25 import java.io.UnsupportedEncodingException; 26 import java.io.UnsupportedEncodingException;
  27 +import java.util.List;
26 import java.util.concurrent.CountDownLatch; 28 import java.util.concurrent.CountDownLatch;
27 29
28 /** 30 /**
@@ -66,6 +68,15 @@ public class CustomXmlHandleThread implements Runnable{ @@ -66,6 +68,15 @@ public class CustomXmlHandleThread implements Runnable{
66 68
67 69
68 /** 70 /**
  71 + * 批量发送时的回执解析,运单节点
  72 + */
  73 + public final static String Consignment = "//Manifest/Response/Consignment";
  74 + public final static String WaybillMaster_NODE = "TransportContractDocument/ID";
  75 + public final static String WaybillSecond_NODE = "AssociatedTransportDocument/ID";
  76 + public final static String ResponseCode_NODE = "ResponseType/Code";
  77 + public final static String ResponseText_NODE = "ResponseType/Text";
  78 +
  79 + /**
69 * 海关普通业务新舱单回执报体 80 * 海关普通业务新舱单回执报体
70 */ 81 */
71 public final static String JourneyID = "//Manifest/Response/BorderTransportMeans/JourneyID"; 82 public final static String JourneyID = "//Manifest/Response/BorderTransportMeans/JourneyID";
@@ -154,9 +165,7 @@ public class CustomXmlHandleThread implements Runnable{ @@ -154,9 +165,7 @@ public class CustomXmlHandleThread implements Runnable{
154 * @throws FileNotFoundException 165 * @throws FileNotFoundException
155 */ 166 */
156 private int handelXmlDocument() throws DocumentException,UnsupportedEncodingException,SAXParseException,FileNotFoundException { 167 private int handelXmlDocument() throws DocumentException,UnsupportedEncodingException,SAXParseException,FileNotFoundException {
157 -  
158 int i = 0; 168 int i = 0;
159 - String secondSplit = "_";  
160 SAXReader saxReader = new SAXReader(); 169 SAXReader saxReader = new SAXReader();
161 Document document = saxReader.read(xmlfile); 170 Document document = saxReader.read(xmlfile);
162 Element contentRoot = document.getRootElement(); 171 Element contentRoot = document.getRootElement();
@@ -164,26 +173,96 @@ public class CustomXmlHandleThread implements Runnable{ @@ -164,26 +173,96 @@ public class CustomXmlHandleThread implements Runnable{
164 String flightNo = "UNKONW"; 173 String flightNo = "UNKONW";
165 String flightDate = "20101010"; 174 String flightDate = "20101010";
166 175
167 - //开始解析  
168 - String msgType = XMLXPath.getSingleValueByPath(document,MessageType);  
169 - String journeyid = XMLXPath.getSingleValueByPath(document,JourneyID);  
170 -// XMLXPath.getSingleValueByPath(document, )  
171 -  
172 -  
173 - String awbA = XMLXPath.getSingleValueByPath(document,WaybillMaster);  
174 - //全格式的分单 如 17212345678_ADBD  
175 - String awbH = XMLXPath.getSingleValueByPath(document,WaybillSecond);  
176 - String resCode = XMLXPath.getSingleValueByPath(document,ResponseCode);  
177 - String resText = XMLXPath.getSingleValueByPath(document,ResponseText);  
178 String messageId = XMLXPath.getSingleValueByPath(document, MessageID); 176 String messageId = XMLXPath.getSingleValueByPath(document, MessageID);
179 String sendTime = XMLXPath.getSingleValueByPath(document,SendTime); 177 String sendTime = XMLXPath.getSingleValueByPath(document,SendTime);
180 String sendId = XMLXPath.getSingleValueByPath(document,SenderID); 178 String sendId = XMLXPath.getSingleValueByPath(document,SenderID);
181 String reciveId = XMLXPath.getSingleValueByPath(document,ReceiverID); 179 String reciveId = XMLXPath.getSingleValueByPath(document,ReceiverID);
182 String version = XMLXPath.getSingleValueByPath(document,Version); 180 String version = XMLXPath.getSingleValueByPath(document,Version);
  181 +
183 String functionCode = XMLXPath.getSingleValueByPath(document,FunctionCode); 182 String functionCode = XMLXPath.getSingleValueByPath(document,FunctionCode);
  183 + //开始解析
  184 + String msgType = XMLXPath.getSingleValueByPath(document,MessageType);
  185 + String journeyid = XMLXPath.getSingleValueByPath(document,JourneyID);
  186 +
  187 + List<Node> ConsignmentNodes = XMLXPath.getPathValues(document,Consignment);
  188 +
  189 + String awbA = "",awbH="",resCode="",resText="";
  190 +
  191 + //说明有带运单的回执
  192 + if (!ConsignmentNodes.isEmpty()){
  193 + for (Node node: ConsignmentNodes ) {
  194 + awbA = node.selectSingleNode(WaybillMaster_NODE).getStringValue();
  195 + //全格式的分单 如 17212345678_ADBD
  196 + awbH = node.selectSingleNode(WaybillSecond_NODE).getStringValue();
  197 + resCode = node.selectSingleNode(ResponseCode_NODE).getStringValue();
  198 + resText = node.selectSingleNode(ResponseText_NODE).getStringValue();
  199 + log.info("主单:{}-分单:{}-回执代码:{}-回执内容:{}",awbA,awbH,resCode,resText);
  200 + i =+ normalXmlHandel(msgType,
  201 + flightNo,
  202 + flightDate,
  203 + awbA,
  204 + awbH,
  205 + resCode,
  206 + resText,
  207 + messageId,
  208 + sendTime,
  209 + sendId,
  210 + reciveId,
  211 + version,
  212 + functionCode,
  213 + journeyid,
  214 + document);
  215 + }
  216 + return i;
  217 + }else{//国际转运回执在这里处理
  218 + awbA = XMLXPath.getSingleValueByPath(document,WaybillMaster);
  219 + //全格式的分单 如 17212345678_ADBD
  220 + awbH = XMLXPath.getSingleValueByPath(document,WaybillSecond);
  221 + resCode = XMLXPath.getSingleValueByPath(document,ResponseCode);
  222 + resText = XMLXPath.getSingleValueByPath(document,ResponseText);
  223 + i =+ normalXmlHandel(msgType,
  224 + flightNo,
  225 + flightDate,
  226 + awbA,
  227 + awbH,
  228 + resCode,
  229 + resText,
  230 + messageId,
  231 + sendTime,
  232 + sendId,
  233 + reciveId,
  234 + version,
  235 + functionCode,
  236 + journeyid,
  237 + document);
  238 + return i;
  239 +
  240 + }
  241 +
184 242
185 243
186 244
  245 +
  246 + }
  247 +
  248 + private int normalXmlHandel(String msgType,
  249 + String flightNo,
  250 + String flightDate,
  251 + String awbA,
  252 + String awbH,
  253 + String resCode,
  254 + String resText,
  255 + String messageId,
  256 + String sendTime,
  257 + String sendId,
  258 + String reciveId,
  259 + String version,
  260 + String functionCode,
  261 + String journeyid,
  262 + Document document
  263 + ){
  264 + String secondSplit = "_";
  265 + int i = 0;
187 CustomReception customReception = new CustomReception( msgType, 266 CustomReception customReception = new CustomReception( msgType,
188 flightNo, 267 flightNo,
189 flightDate, 268 flightDate,
@@ -332,7 +411,6 @@ public class CustomXmlHandleThread implements Runnable{ @@ -332,7 +411,6 @@ public class CustomXmlHandleThread implements Runnable{
332 411
333 updateCustomMessage(customReception); 412 updateCustomMessage(customReception);
334 return i; 413 return i;
335 -  
336 } 414 }
337 415
338 /** 416 /**
@@ -356,7 +434,7 @@ public class CustomXmlHandleThread implements Runnable{ @@ -356,7 +434,7 @@ public class CustomXmlHandleThread implements Runnable{
356 String importWaybillSecond= XMLXPath.getSingleValueByPath(document,ImportWaybillSecond); 434 String importWaybillSecond= XMLXPath.getSingleValueByPath(document,ImportWaybillSecond);
357 String transResponseCode=XMLXPath.getSingleValueByPath(document,TransResponseCode); 435 String transResponseCode=XMLXPath.getSingleValueByPath(document,TransResponseCode);
358 String transResponseText=XMLXPath.getSingleValueByPath(document,TransResponseText); 436 String transResponseText=XMLXPath.getSingleValueByPath(document,TransResponseText);
359 - CustomReception transCustomReception = new CustomReception( customReception.getMessageType(), 437 + CustomReception transCustomReception = new CustomReception(customReception.getMessageType(),
360 importFlightNo, 438 importFlightNo,
361 importFlightDate, 439 importFlightDate,
362 importWaybillMaster, 440 importWaybillMaster,