作者 朱兆平

解析PFFM优化

@@ -11,13 +11,15 @@ import com.example.demo.util.XML.XML2ENTITY; @@ -11,13 +11,15 @@ import com.example.demo.util.XML.XML2ENTITY;
11 import org.dom4j.Document; 11 import org.dom4j.Document;
12 import org.dom4j.DocumentException; 12 import org.dom4j.DocumentException;
13 import org.dom4j.DocumentHelper; 13 import org.dom4j.DocumentHelper;
  14 +import org.dom4j.Element;
14 import org.slf4j.Logger; 15 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory; 16 import org.slf4j.LoggerFactory;
16 17
17 public class XmlToMapDemo { 18 public class XmlToMapDemo {
  19 + protected static final Logger logger = LoggerFactory.getLogger(XmlToMapDemo.class);
18 public static void main(String[] args) throws IOException, 20 public static void main(String[] args) throws IOException,
19 DocumentException { 21 DocumentException {
20 - final Logger logger = LoggerFactory.getLogger(XmlToMapDemo.class); 22 +
21 23
22 // FileInputStream fis = new FileInputStream("d://a.xml"); 24 // FileInputStream fis = new FileInputStream("d://a.xml");
23 // byte[] b = new byte[fis.available()]; 25 // byte[] b = new byte[fis.available()];
@@ -1176,43 +1178,67 @@ public class XmlToMapDemo { @@ -1176,43 +1178,67 @@ public class XmlToMapDemo {
1176 1178
1177 Map<String, Object> map = XML2ENTITY.Dom2Map(doc); 1179 Map<String, Object> map = XML2ENTITY.Dom2Map(doc);
1178 1180
  1181 + // 头部解析
1179 Map metamap = (Map) map.get("META"); 1182 Map metamap = (Map) map.get("META");
1180 String SEDR = (String) metamap.get("SNDR"); 1183 String SEDR = (String) metamap.get("SNDR");
1181 logger.info(SEDR); 1184 logger.info(SEDR);
1182 1185
  1186 + //报体解析入口
1183 Map LogisticsTransportManifest = (Map) map.get("LogisticsTransportManifest"); 1187 Map LogisticsTransportManifest = (Map) map.get("LogisticsTransportManifest");
1184 - List<Map> event = (List<Map>) LogisticsTransportManifest.get("ArrivalEvent");  
1185 - for (Map everyEvent : event){  
1186 - String ScheduledArrivalOccurrenceDateTime = (String) everyEvent.get("ScheduledArrivalOccurrenceDateTime");  
1187 - String FirstArrivalCountryID = ((Map) everyEvent.get("OccurrenceArrivalLocation")).get("FirstArrivalCountryID").toString(); 1188 + //LogisticsTransportMovement 航班节点解析入口
  1189 + Map Map_LogisticsTransportMovement = (Map) LogisticsTransportManifest.get("LogisticsTransportMovement");
  1190 + String StageCode = Map_LogisticsTransportMovement.get("StageCode").toString();//航班号/航班日期
1188 1191
1189 - Object AssociatedTransportCargoList = everyEvent.get("AssociatedTransportCargo"); 1192 + //ArrivalEvent多节点解析入口
  1193 + Object Obj_ArrivalEvent = LogisticsTransportManifest.get("ArrivalEvent");
  1194 + if (Obj_ArrivalEvent.getClass().getName().equals("java.util.ArrayList")){//多个ArrivalEvent,多个装载目的地
  1195 + List<Map> event = (List<Map>) LogisticsTransportManifest.get("ArrivalEvent");
  1196 + for (Map everyEvent : event){
  1197 + ArrivalEventHandle(everyEvent);
  1198 + }
  1199 + }else if (Obj_ArrivalEvent.getClass().getName().equals("java.util.HashMap")){ //一个报文,一个ArrivalEvent代表装载只有一个目的地
  1200 + Map map_ArrivalEvent = (Map) LogisticsTransportManifest.get("ArrivalEvent");
  1201 + ArrivalEventHandle(map_ArrivalEvent);
  1202 + }
1190 1203
1191 - if (AssociatedTransportCargoList.getClass().getName().equals("java.util.ArrayList")){ //这里是为了判断 只发一票装载的情况,实际上上面event节点也要这样判断返回的是LIST还是MAP  
1192 - List<Map> AssociatedTransportCargo = (List<Map>) everyEvent.get("AssociatedTransportCargo");  
1193 - for(Map AssociatedTransportCargoMap : AssociatedTransportCargo){  
1194 - String uldType = AssociatedTransportCargoMap.get("TypeCode").toString();  
1195 - String uldNumber = ((Map) AssociatedTransportCargoMap.get("UtilizedUnitLoadTransportEquipment")).get("ID").toString();  
1196 - String PositioningEvent_OccurrencePositioningLocation_ID = ((Map)(((Map)(((Map) AssociatedTransportCargoMap.get("UtilizedUnitLoadTransportEquipment")).get("PositioningEvent"))).get("OccurrencePositioningLocation"))).get("ID").toString();  
1197 1204
1198 - Object IncludedMasterConsignmentList = AssociatedTransportCargoMap.get("IncludedMasterConsignment");  
1199 - if (IncludedMasterConsignmentList.getClass().getName().equals("java.util.ArrayList")){  
1200 1205
1201 - }else if (IncludedMasterConsignmentList.getClass().getName().equals("java.util.HashMap")){ //这里为MAP代表一个板里面装一件货  
1202 - Map IncludedMasterConsignmentMap = (Map)IncludedMasterConsignmentList;  
1203 - String awbNumber = ((Map)IncludedMasterConsignmentMap.get("TransportContractDocument")).get("ID").toString();  
1204 - logger.info(awbNumber);  
1205 - }  
1206 - }  
1207 - }else if (AssociatedTransportCargoList.getClass().getName().equals("java.util.HashMap")){//是MAP单取下面节点就行,只发一票装载 报文中是一个航班,一个板箱,一个运单 1206 + System.out.println(map.toString());
1208 1207
1209 - } 1208 + System.out.println("Use time:"+(System.currentTimeMillis()-beginTime));
1210 1209
1211 - } 1210 + }
1212 1211
1213 - System.out.println(map.toString()); 1212 + static public void ArrivalEventHandle(Map ArrivalEvent){
  1213 + Map Map_ArrivalEvent = ArrivalEvent;
  1214 + String ScheduledArrivalOccurrenceDateTime = (String) Map_ArrivalEvent.get("ScheduledArrivalOccurrenceDateTime");
  1215 + String FirstArrivalCountryID = ((Map) Map_ArrivalEvent.get("OccurrenceArrivalLocation")).get("FirstArrivalCountryID").toString();
1214 1216
1215 - System.out.println("Use time:"+(System.currentTimeMillis()-beginTime)); 1217 + Object AssociatedTransportCargoList = Map_ArrivalEvent.get("AssociatedTransportCargo");
  1218 +
  1219 + if (AssociatedTransportCargoList.getClass().getName().equals("java.util.ArrayList")){ //这里是为了判断 只发一票装载的情况,实际上上面event节点也要这样判断返回的是LIST还是MAP
  1220 + List<Map> AssociatedTransportCargo = (List<Map>) Map_ArrivalEvent.get("AssociatedTransportCargo");
  1221 + for(Map AssociatedTransportCargoMap : AssociatedTransportCargo){
  1222 + String uldType = AssociatedTransportCargoMap.get("TypeCode").toString();
  1223 + String uldNumber = ((Map) AssociatedTransportCargoMap.get("UtilizedUnitLoadTransportEquipment")).get("ID").toString();
  1224 + String PositioningEvent_OccurrencePositioningLocation_ID = ((Map)(((Map)(((Map) AssociatedTransportCargoMap.get("UtilizedUnitLoadTransportEquipment")).get("PositioningEvent"))).get("OccurrencePositioningLocation"))).get("ID").toString();
  1225 +
  1226 + Object IncludedMasterConsignmentList = AssociatedTransportCargoMap.get("IncludedMasterConsignment");
  1227 + if (IncludedMasterConsignmentList.getClass().getName().equals("java.util.ArrayList")){
  1228 + List<Map> IncludedMasterConsignmentMaps = (List<Map>) AssociatedTransportCargoMap.get("IncludedMasterConsignment");
  1229 + for (Map IncludedMasterConsignment : IncludedMasterConsignmentMaps){
  1230 + String awbNumber = ((Map)IncludedMasterConsignment.get("TransportContractDocument")).get("ID").toString();
  1231 + logger.info("一板多运单-"+awbNumber);
  1232 + }
1216 1233
  1234 + }else if (IncludedMasterConsignmentList.getClass().getName().equals("java.util.HashMap")){ //这里为MAP代表一个板里面装一件货
  1235 + Map IncludedMasterConsignmentMap = (Map)IncludedMasterConsignmentList;
  1236 + String awbNumber = ((Map)IncludedMasterConsignmentMap.get("TransportContractDocument")).get("ID").toString();
  1237 + logger.info(awbNumber);
  1238 + }
  1239 + }
  1240 + }else if (AssociatedTransportCargoList.getClass().getName().equals("java.util.HashMap")){//是MAP单取下面节点就行,只发一票装载 报文中是一个航班,一个板箱,一个运单
  1241 +
  1242 + }
1217 } 1243 }
1218 } 1244 }