|
|
package com.tianbo.analysis.handle;
|
|
|
|
|
|
import com.tianbo.analysis.model.ALLOCATEARRIVAL;
|
|
|
import com.tianbo.analysis.model.CustomReception;
|
|
|
import com.tianbo.analysis.service.*;
|
|
|
import com.tianbo.analysis.service.imp.*;
|
|
|
import com.tianbo.analysis.tools.AWBTools;
|
|
|
import com.tianbo.util.Date.DateUtil;
|
|
|
import com.tianbo.util.XML.XMLXPath;
|
|
|
import lombok.Data;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.io.FileExistsException;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.dom4j.Document;
|
|
|
import org.dom4j.DocumentException;
|
|
|
import org.dom4j.Element;
|
|
|
import org.dom4j.io.SAXReader;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.annotation.Scope;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.xml.sax.SAXParseException;
|
|
|
|
...
|
...
|
@@ -21,6 +26,7 @@ import javax.annotation.PostConstruct; |
|
|
import java.io.File;
|
|
|
import java.io.FileNotFoundException;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
import java.util.concurrent.CountDownLatch;
|
|
|
|
|
|
/**
|
|
|
* @author mrz
|
...
|
...
|
@@ -32,6 +38,7 @@ import java.io.UnsupportedEncodingException; |
|
|
@Slf4j
|
|
|
public class CustomXmlHandleThread implements Runnable{
|
|
|
|
|
|
private CountDownLatch latch;
|
|
|
//备份目录
|
|
|
@Value("${custom.receptBakDir}")
|
|
|
private String bakupDir;
|
...
|
...
|
@@ -40,10 +47,6 @@ public class CustomXmlHandleThread implements Runnable{ |
|
|
@Value("${custom.errBakDir}")
|
|
|
private String errBakDir;
|
|
|
|
|
|
//回执转发目录
|
|
|
@Value("${custom.transmit}")
|
|
|
private String transmitDir;
|
|
|
|
|
|
private File xmlfile;
|
|
|
private static CustomXmlHandleThread customXmlHandle;
|
|
|
//海关新舱单回执报头
|
...
|
...
|
@@ -55,66 +58,43 @@ public class CustomXmlHandleThread implements Runnable{ |
|
|
public final static String SendTime = "//Manifest/Head/SendTime";
|
|
|
public final static String Version = "//Manifest/Head/Version";
|
|
|
|
|
|
//海关新舱单回执报体
|
|
|
|
|
|
/**
|
|
|
* 海关普通业务新舱单回执报体
|
|
|
*/
|
|
|
public final static String JourneyID = "//Manifest/Response/BorderTransportMeans/JourneyID";
|
|
|
public final static String WaybillMaster = "//Manifest/Response/Consignment/TransportContractDocument/ID";
|
|
|
public final static String WaybillSecond = "//Manifest/Response/Consignment/AssociatedTransportDocument/ID";
|
|
|
public final static String ResponseCode = "//Manifest/Response/Consignment/ResponseType/Code";
|
|
|
public final static String ResponseText = "//Manifest/Response/Consignment/ResponseType/Text";
|
|
|
|
|
|
@Autowired
|
|
|
private CoustomAnalysisService coustomAnalysisService;
|
|
|
|
|
|
@Autowired
|
|
|
private ARRIVEDMASTERService arrivedmasterService;
|
|
|
|
|
|
@Autowired
|
|
|
private TALLYMASTERService tallymasterService;
|
|
|
|
|
|
@Autowired
|
|
|
private DEPARTURESLOADINGService departuresloadingService;
|
|
|
|
|
|
@Autowired
|
|
|
private PREPAREMASTERService preparemasterService;
|
|
|
|
|
|
@Autowired
|
|
|
private ALLOCATEARRIVALService allocatearrivalService;
|
|
|
|
|
|
@Autowired
|
|
|
private INPORTALLOCATEService inportallocateService;
|
|
|
/**
|
|
|
* 海关国际转运业务回执报体
|
|
|
*/
|
|
|
public final static String ImportJourneyID = "//Manifest/Response/ImportInformation/BorderTransportMeans/JourneyID";
|
|
|
public final static String ImportWaybillMaster = "//Manifest/Response/ImportInformation/Consignment/TransportContractDocument/ID";
|
|
|
public final static String ExportJourneyID = "//Manifest/Response/ExportInformation/BorderTransportMeans/JourneyID";
|
|
|
public final static String ExportWaybillMaster = "//Manifest/Response/ExportInformation/Consignment/TransportContractDocument/ID";
|
|
|
public final static String TransResponseCode = "//Manifest/Response/ResponseType/Code";
|
|
|
public final static String TransResponseText = "//Manifest/Response/ResponseType/Text";
|
|
|
|
|
|
|
|
|
//通过@PostConstruct实现初始化bean之前进行的操作,解决service调用空指针问题
|
|
|
@PostConstruct
|
|
|
public void init() {
|
|
|
customXmlHandle = this;
|
|
|
customXmlHandle.coustomAnalysisService = this.coustomAnalysisService;
|
|
|
|
|
|
customXmlHandle.arrivedmasterService = this.arrivedmasterService;
|
|
|
|
|
|
customXmlHandle.tallymasterService = this.tallymasterService;
|
|
|
|
|
|
customXmlHandle.departuresloadingService = this.departuresloadingService;
|
|
|
|
|
|
customXmlHandle.preparemasterService = this.preparemasterService;
|
|
|
|
|
|
customXmlHandle.allocatearrivalService = this.allocatearrivalService;
|
|
|
|
|
|
customXmlHandle.inportallocateService = this.inportallocateService;
|
|
|
|
|
|
customXmlHandle.bakupDir = this.bakupDir;
|
|
|
|
|
|
customXmlHandle.errBakDir = this.errBakDir;
|
|
|
|
|
|
customXmlHandle.transmitDir = this.transmitDir;
|
|
|
// 初使化时将已静态化的testService实例化
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void run() {
|
|
|
|
|
|
log.info("线程:{}开始",xmlfile.getName());
|
|
|
try{
|
|
|
FileUtils.copyFileToDirectory(xmlfile,new File(customXmlHandle.transmitDir));
|
|
|
int i =handelXmlDocument();
|
|
|
String today = DateUtil.getTodayBy_yyyyMMdd();
|
|
|
String backdireByDay = customXmlHandle.bakupDir + "/" + today;
|
...
|
...
|
@@ -128,12 +108,17 @@ public class CustomXmlHandleThread implements Runnable{ |
|
|
errBak(xmlfile);
|
|
|
}
|
|
|
}catch (FileExistsException e){
|
|
|
log.error("错误的解析文件剪切失败,目标目录已存在同名文件",e);
|
|
|
e.printStackTrace();
|
|
|
log.error("错误的解析文件剪切失败,目标目录已存在同名文件");
|
|
|
}catch (Exception e){
|
|
|
log.error("错误的解析文件剪切失败,目标目录已存在同名文件",e);
|
|
|
errBak(xmlfile);
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
log.info("线程:{}结束",xmlfile.getName());
|
|
|
latch.countDown();
|
|
|
log.info("剩余线程数量{}",latch.getCount());
|
|
|
|
|
|
}
|
|
|
/**
|
|
|
*
|
...
|
...
|
@@ -156,12 +141,11 @@ public class CustomXmlHandleThread implements Runnable{ |
|
|
String flightDate = "";
|
|
|
|
|
|
//开始解析
|
|
|
// fzeFoh.setGrossweightmeasureuc(XMLXPath.getSingleValueByPath(document,GrossWeightMeasureUc));
|
|
|
String msgType = XMLXPath.getSingleValueByPath(document,MessageType);
|
|
|
String journeyid = XMLXPath.getSingleValueByPath(document,JourneyID);
|
|
|
// XMLXPath.getSingleValueByPath(document, )
|
|
|
|
|
|
if(journeyid != null&& !journeyid.isEmpty()){
|
|
|
if(!StringUtils.isEmpty(journeyid)){
|
|
|
|
|
|
String[] flightList = journeyid.split("/");
|
|
|
if(flightList.length > 0){
|
...
|
...
|
@@ -223,15 +207,57 @@ public class CustomXmlHandleThread implements Runnable{ |
|
|
i = customXmlHandle.inportallocateService.insertRecept(customReception);
|
|
|
break;
|
|
|
case "MT3202":
|
|
|
i = customXmlHandle.allocatearrivalService.insertRecept(customReception);
|
|
|
ALLOCATEARRIVAL allocatearrival = new ALLOCATEARRIVAL(customReception);
|
|
|
i= allocatearrival.analysisReception();
|
|
|
break;
|
|
|
case "MT8205":
|
|
|
|
|
|
transXmlHandel(document,customReception);
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
return i;
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 国际转运回执处理
|
|
|
* @param document
|
|
|
* @param customReception
|
|
|
* @return
|
|
|
*/
|
|
|
private int transXmlHandel(Document document,CustomReception customReception){
|
|
|
|
|
|
String importJourneyID = XMLXPath.getSingleValueByPath(document,ImportJourneyID);
|
|
|
String importFlightNo = "UNKONW";
|
|
|
String importFlightDate = "00000000";
|
|
|
if(!StringUtils.isEmpty(importJourneyID)){
|
|
|
importFlightNo = AWBTools.splitFlightAndDate(importJourneyID)[0];
|
|
|
importFlightDate = AWBTools.splitFlightAndDate(importJourneyID)[1];
|
|
|
}
|
|
|
|
|
|
|
|
|
String importWaybillMaster= XMLXPath.getSingleValueByPath(document,ImportWaybillMaster);
|
|
|
String transResponseCode=XMLXPath.getSingleValueByPath(document,TransResponseCode);
|
|
|
String transResponseText=XMLXPath.getSingleValueByPath(document,TransResponseText);
|
|
|
CustomReception transCustomReception = new CustomReception( customReception.getMessageType(),
|
|
|
importFlightNo,
|
|
|
importFlightDate,
|
|
|
importWaybillMaster,
|
|
|
transResponseCode,
|
|
|
transResponseText,
|
|
|
customReception.getMessageID(),
|
|
|
customReception.getSendTime(),
|
|
|
customReception.getSenderID(),
|
|
|
customReception.getReceiverID(),
|
|
|
customReception.getVersion(),
|
|
|
customReception.getFunctionCode());
|
|
|
int i=customXmlHandle.internationaltransitService.insertRecept(transCustomReception);
|
|
|
|
|
|
return i;
|
|
|
|
|
|
}
|
|
|
|
|
|
public void errBak(File file){
|
...
|
...
|
@@ -240,10 +266,9 @@ public class CustomXmlHandleThread implements Runnable{ |
|
|
String errDirByDay = customXmlHandle.errBakDir + "/" + today;
|
|
|
File berrDirectory = new File(errDirByDay);
|
|
|
FileUtils.moveFileToDirectory(file,berrDirectory,true);
|
|
|
log.error("解析或其他错误备份文件:"+File.pathSeparator);
|
|
|
log.info("数据库未找到与回执适配的信息备份文件:{}:"+file.getName());
|
|
|
}catch (FileExistsException e){
|
|
|
log.error("错误的解析文件剪切失败,目标目录已存在同名文件",e);
|
|
|
e.printStackTrace();
|
|
|
log.error("备份解析错误文件失败,目标文件夹存在同名文件{}",file.getName());
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
}
|
...
|
...
|
|