作者 朱兆平

理货回执解析入库OK

... ... @@ -43,4 +43,21 @@
* 配合微信前端定时监控3个回执目录的文件数量,超过警戒值 微信发出提醒
* path = /devops/watchdir?dir=tcs
参数dir,可以是指定目录值,也可以是stcs、tcs、cfps 分别代表单一窗口回执目录、商务节点回执目录、CFPS数据订阅目录
\ No newline at end of file
参数dir,可以是指定目录值,也可以是stcs、tcs、cfps 分别代表单一窗口回执目录、商务节点回执目录、CFPS数据订阅目录
* 回执解析code设置
* 01代表可自动发送
* 02代表已发送
* 入库03代表收到回执但是非正常,对应回执报文中的02、03、12、13
* 入库04代表回执正常,对应回执报文中的01、11
* 08代表发送删除报
* 12代表发送修改报
* 17代表未发送可人工发送/未发送
* 海关返回code说明
* 01-接受申报;
* 02-待人工审核;
* 03-退单;
* 11-放行;
* 12-拒装;
* 13-禁卸。
... ...
... ... @@ -196,10 +196,10 @@ public class CustomXmlHandleThread implements Runnable{
i= customXmlHandle.arrivedmasterService.insertRecept(customReception);
break;
case "MT5202":
i = customXmlHandle.tallymasterService.insertRecept(customReception, "MT5202");
i = customXmlHandle.tallymasterService.insertRecept(customReception);
break;
case "MT5201":
i = customXmlHandle.tallymasterService.insertRecept(customReception, "MT5201");
i = customXmlHandle.tallymasterService.insertRecept(customReception);
break;
case "MT4201":
i = customXmlHandle.departuresloadingService.insertRecept(customReception);
... ...
package com.tianbo.analysis.service;
import com.tianbo.analysis.model.CustomReception;
import com.tianbo.analysis.service.imp.CoustomAnalysisServiceImp;
import com.tianbo.analysis.service.imp.ShareServiceImp;
import com.tianbo.analysis.tools.AWBTools;
public class NmmsBaseService {
public ShareServiceImp shareServiceImp;
public CoustomAnalysisServiceImp coustomAnalysisServiceImp;
public String awbA ;
public String awbH ;
public String rspCode;
public String nmsStatusCode;
public String reception;
public String flightDateStr;
public CustomReception customReception;
public int insertRecept(CustomReception customReception){
this.shareServiceImp = new ShareServiceImp();
// 发送日志 插入
this.coustomAnalysisServiceImp = new CoustomAnalysisServiceImp();
this.customReception = customReception;
// 主单号;处理主单格式,将海关回执的主单号58019316861,变为580-19316861
this.awbA = AWBTools.awbFormat(customReception.getWayBillMaster());
this.awbH = customReception.getWayBillSecond();
this.rspCode = customReception.getResponseCode();
this.nmsStatusCode = AWBTools.transCusRspCode(rspCode);
this.reception = customReception.getResponseText();
this.flightDateStr = customReception.getFlightDate();
return 0;
}
}
... ...
... ... @@ -8,5 +8,5 @@ import com.tianbo.analysis.model.CustomReception;
*/
public interface TALLYMASTERService {
int insertRecept(CustomReception customReception, String mt);
int insertRecept(CustomReception customReception);
}
... ...
... ... @@ -6,6 +6,7 @@ import com.tianbo.analysis.model.ARRIVEDMASTER;
import com.tianbo.analysis.model.ARRIVEDSECONDARY;
import com.tianbo.analysis.model.CustomReception;
import com.tianbo.analysis.service.ARRIVEDMASTERService;
import com.tianbo.analysis.service.NmmsBaseService;
import com.tianbo.analysis.tools.AWBTools;
import com.tianbo.util.Date.DateUtil;
import lombok.extern.slf4j.Slf4j;
... ... @@ -22,7 +23,7 @@ import java.util.List;
*/
@Service
@Slf4j
public class ARRIVEDMASTERServiceImp implements ARRIVEDMASTERService {
public class ARRIVEDMASTERServiceImp extends NmmsBaseService implements ARRIVEDMASTERService{
@Autowired
... ... @@ -36,18 +37,6 @@ public class ARRIVEDMASTERServiceImp implements ARRIVEDMASTERService {
// 货物接收运抵主分单
public int insertRecept(CustomReception customReception) {
ShareServiceImp shareServiceImp = new ShareServiceImp();
// 发送日志 插入
CoustomAnalysisServiceImp coustomAnalysisServiceImp = new CoustomAnalysisServiceImp();
// 主单号
String awbA = customReception.getWayBillMaster();
String awbH = customReception.getWayBillSecond();
//回执内容
String reception = customReception.getResponseText();
String flightDateStr = customReception.getFlightDate();
if (!StringUtils.isEmpty(flightDateStr)) {
Date flightDate = DateUtil.formatByyyyyMMdd(flightDateStr);
... ...
... ... @@ -31,7 +31,7 @@ public class CoustomAnalysisServiceImp implements CoustomAnalysisService {
@Autowired
OriginmanifestsecondaryMapper originmanifestsecondaryMapper;
CoustomAnalysisServiceImp(){
public CoustomAnalysisServiceImp(){
//处理多线程时 springboot 无法注入bean的问题
if (this.sendlogMapper==null){
this.sendlogMapper = SpringBeanUtitl.getBean(SENDLOGMapper.class);
... ...
... ... @@ -49,7 +49,7 @@ public class ShareServiceImp {
@Autowired
CUSTOMSMESSAGEMapper customsmessageMapper;
ShareServiceImp(){
public ShareServiceImp(){
customsmessageMapper = SpringBeanUtitl.getBean(CUSTOMSMESSAGEMapper.class);
}
... ...
... ... @@ -5,6 +5,7 @@ import com.tianbo.analysis.dao.TALLYSECONDARYMapper;
import com.tianbo.analysis.model.CustomReception;
import com.tianbo.analysis.model.TALLYMASTER;
import com.tianbo.analysis.model.TALLYSECONDARY;
import com.tianbo.analysis.service.NmmsBaseService;
import com.tianbo.analysis.service.TALLYMASTERService;
import com.tianbo.util.Date.DateUtil;
import lombok.extern.slf4j.Slf4j;
... ... @@ -16,13 +17,14 @@ import java.util.Date;
import java.util.List;
/**
* 进出港理货回执解析入库
* @Auther: shenhl
* @Date: 2019/8/23 17:17
*/
@Service
@Slf4j
public class TALLYMASTERServiceImp implements TALLYMASTERService{
public class TALLYMASTERServiceImp extends NmmsBaseService implements TALLYMASTERService{
@Autowired
TALLYMASTERMapper tallymasterMapper;
... ... @@ -30,99 +32,111 @@ public class TALLYMASTERServiceImp implements TALLYMASTERService{
@Autowired
TALLYSECONDARYMapper tallysecondaryMapper;
private Date flightDate;
@Override
// 进出港理货
public int insertRecept(CustomReception customReception, String mt) {
ShareServiceImp shareServiceImp = new ShareServiceImp();
// 发送日志 插入
CoustomAnalysisServiceImp coustomAnalysisServiceImp = new CoustomAnalysisServiceImp();
// 主单号
String awbA = customReception.getWayBillMaster();
String awbH = customReception.getWayBillSecond();
//回执内容
String reception = customReception.getResponseText();
String flightDateStr = customReception.getFlightDate();
public int insertRecept(CustomReception customReception) {
super.insertRecept(customReception);
if (!StringUtils.isEmpty(flightDateStr)) {
Date flightDate = DateUtil.formatByyyyyMMdd(flightDateStr);
// 设置 进出港理货 回执
TALLYSECONDARY tallysecondary = new TALLYSECONDARY();
tallysecondary.setReceiptinformation(reception);
//设置进出港理货回执、航班号、航班日期
TALLYMASTER tallymaster = new TALLYMASTER();
tallymaster.setReceiptinformation(reception);
tallymaster.setFlightno(customReception.getFlightNo());
tallymaster.setFlightdate(flightDate);
flightDate = DateUtil.formatByyyyyMMdd(flightDateStr);
// 判断航班号 航班日期 是否为空
if (flightDate != null && customReception.getFlightNo() != null){
if (awbA!=null && awbA.length()>0){
StringBuffer stringBuffer = new StringBuffer(awbA);
stringBuffer.insert(3,"-");
awbA = stringBuffer.toString();
//设置主分单的 主单号
tallysecondary.setWaybillnomaster(awbA);
tallymaster.setWaybillnomaster(awbA);
}
//有分单号 更新分单
if(awbA!=null && awbA.length()>0 && awbH!=null && awbH.length()> 0){
//取分单号
String[] awbhArr = awbH.split("_");
String awbh = awbhArr[1];
tallysecondary.setWaybillnosecondary(awbh);
//更新分单回执
int i = tallysecondaryMapper.updateRECEIPTION(tallysecondary);
//获取分单autoid
List<TALLYSECONDARY> tallysecondaryList = tallysecondaryMapper.selectAutoIdByawbAawbH(tallysecondary);
if(!tallysecondaryList.isEmpty()){
TALLYSECONDARY arrivedSecond = tallysecondaryList.get(0);
String autoId = arrivedSecond.getAutoid();
//插入sendlog记录表
log.info("即将插入日志运单号为:"+awbH+"->autoid="+autoId);
int ii = coustomAnalysisServiceImp.insertSendlog(mt,reception,autoId);
int iii = shareServiceImp.updateMessages(customReception);
if (i>0 && ii>0 && iii > 0){
return 1;
}
}
return 0;
if(!StringUtils.isEmpty(awbH)){
second();
}
//处理主单格式,将海关回执的主单号58019316861,变为580-19316861
if (awbA!=null && awbA.length()>0){
//更新主单回执
int i = tallymasterMapper.updateRECEIPTION(tallymaster);
//获取分单autoid
List<TALLYMASTER> arrivedmasterList = tallymasterMapper.selectAutoIdByAwb(tallymaster);
if(!arrivedmasterList.isEmpty()){
TALLYMASTER originMaster = arrivedmasterList.get(0);
String autoId = originMaster.getAutoid();
//插入sendlog记录表
log.info("即将插入日志运单号为:"+awbA+"->autoid="+autoId);
int ii =coustomAnalysisServiceImp.insertSendlog(mt,reception,autoId);
int iii = shareServiceImp.updateMessages(customReception);
if (i>0 && ii>0 && iii > 0){
return 1;
}
}
return 0;
if (!StringUtils.isEmpty(awbA)){
master();
}
}else {
return shareServiceImp.share("MT5202", customReception);
return shareServiceImp.share(customReception.getMessageType(), customReception);
}
}
//未进入主分单解析 返回0 失败
return 0;
}
/**
* 入库主单回执信息
* @return 成功返回1,失败返回0。
*/
public int master(){
String mt = customReception.getMessageType();
//设置进出港理货回执、航班号、航班日期
TALLYMASTER tallymaster = new TALLYMASTER();
tallymaster.setWaybillnomaster(awbA);
tallymaster.setReceiptinformation(reception);
tallymaster.setFlightno(customReception.getFlightNo());
tallymaster.setFlightdate(flightDate);
tallymaster.setTalltype(mt);
tallymaster.setStatus(nmsStatusCode);
//更新主单回执
int i = tallymasterMapper.updateRECEIPTION(tallymaster);
//获取主单autoid
List<TALLYMASTER> arrivedmasterList = tallymasterMapper.selectAutoIdByAwb(tallymaster);
if(!arrivedmasterList.isEmpty()){
TALLYMASTER originMaster = arrivedmasterList.get(0);
String autoId = originMaster.getAutoid();
int ii =coustomAnalysisServiceImp.insertSendlog(mt,reception,autoId);
int iii = shareServiceImp.updateMessages(customReception);
if (i>0 && ii>0 ){
log.info("运单号 {} 理货回执更新成功",awbA);
return 1;
}
if (iii > 0){
return 1;
}
}
return 0;
}
/**
* 入库分单回执信息
* @return
*/
public int second(){
TALLYSECONDARY tallysecondary = new TALLYSECONDARY();
tallysecondary.setReceiptinformation(reception);
tallysecondary.setStatus(nmsStatusCode);
//设置主分单的 主单号
tallysecondary.setWaybillnomaster(awbA);
//取分单号
String[] awbhArr = awbH.split("_");
String awbh = awbhArr[1];
tallysecondary.setWaybillnosecondary(awbh);
//更新分单回执
int i = tallysecondaryMapper.updateRECEIPTION(tallysecondary);
//获取分单autoid
List<TALLYSECONDARY> tallysecondaryList = tallysecondaryMapper.selectAutoIdByawbAawbH(tallysecondary);
if(!tallysecondaryList.isEmpty()){
TALLYSECONDARY arrivedSecond = tallysecondaryList.get(0);
String autoId = arrivedSecond.getAutoid();
//插入sendlog记录表
log.info("即将插入理货分单回执,运单号为:{},autoid:{}",awbH,autoId);
int ii = coustomAnalysisServiceImp.insertSendlog(customReception.getMessageType(),reception,autoId);
//通过messageid适配发送日志表并更新
int iii = shareServiceImp.updateMessages(customReception);
if (i>0 && ii>0){
log.info("运单号 {} 理货回执更新成功",awbH);
return 1;
}
if (iii > 0){
return 1;
}
}
return 0;
}
}
... ...
package com.tianbo.analysis.tools;
import org.apache.commons.lang.StringUtils;
public class AWBTools {
public static String awbFormat(String awbNo) {
if (awbNo != null && awbNo.length() > 0) {
if (!StringUtils.isEmpty(awbNo)) {
StringBuffer stringBuffer = new StringBuffer(awbNo);
stringBuffer.insert(3, "-");
awbNo = stringBuffer.toString();
... ... @@ -18,4 +20,37 @@ public class AWBTools {
flight[1] = flightNo.substring(2);
return flight;
}
/**
* 将海关回执中的response code 转换成新舱单1.0数据库中的相关状态,相关状态码参考readme.md
* @param rspCode
* @return
*/
public static String transCusRspCode(String rspCode){
String nmsCode = "03";
switch (rspCode){
case "01":
nmsCode="04";
break;
case "02":
nmsCode="03";
break;
case "03":
nmsCode="03";
break;
case "11":
nmsCode="04";
break;
case "12":
nmsCode="03";
break;
case "13":
nmsCode="03";
break;
default:
nmsCode="03";
break;
}
return nmsCode;
}
}
... ...
... ... @@ -7,7 +7,7 @@
<result column="TCD_NAME" property="tcdName" jdbcType="VARCHAR" />
<result column="TCD_TYPECODE" property="tcdTypecode" jdbcType="VARCHAR" />
<result column="FLIGHTNO" property="flightno" jdbcType="VARCHAR" />
<result column="FLIGHTDATE" property="flightdate" jdbcType="TIMESTAMP" />
<result column="FLIGHTDATE" property="flightDate" jdbcType="DATE" />
<result column="CARRIER" property="carrier" jdbcType="VARCHAR" />
<result column="ORIGINATINGSTATION" property="originatingstation" jdbcType="VARCHAR" />
<result column="O_NAME" property="oName" jdbcType="VARCHAR" />
... ... @@ -349,13 +349,14 @@
UPDATE
ARRIVEDMASTER
SET
RECEIPTINFORMATION= #{receiptinformation,jdbcType=VARCHAR}
RECEIPTINFORMATION= #{receiptinformation,jdbcType=VARCHAR},
STATUS = #{status,jdbcType=VARCHAR}
WHERE
FLIGHTNO = #{flightno,jdbcType=VARCHAR}
AND
CARRIER = #{carrier,jdbcType=VARCHAR}
AND
FLIGHTDATE= #{flightDate,jdbcType=TIMESTAMP}
FLIGHTDATE= #{flightDate,jdbcType=DATE}
AND
WAYBILLNOMASTER = #{waybillnomaster,jdbcType=VARCHAR}
</update>
... ... @@ -366,7 +367,7 @@
WHERE
FLIGHTNO= #{flightno,jdbcType=VARCHAR}
AND
FLIGHTDATE= #{flightDate,jdbcType=TIMESTAMP}
FLIGHTDATE= #{flightDate,jdbcType=DATE}
AND
WAYBILLNOMASTER = #{waybillnomaster,jdbcType=VARCHAR}
</select>
... ...
... ... @@ -233,7 +233,7 @@
<update id="updateRECEIPTION" parameterType="com.tianbo.analysis.model.ARRIVEDSECONDARY" >
UPDATE ARRIVEDSECONDARY
SET RECEIPTION= #{receiption,jdbcType=VARCHAR}
SET RECEIPTION= #{receiption,jdbcType=VARCHAR},STATUS = #{status,jdbcType=VARCHAR}
WHERE WAYBILLNOMASTER = #{waybillnomaster,jdbcType=VARCHAR}
AND WAYBILLNOSECONDARY = #{waybillnosecondary,jdbcType=VARCHAR}
</update>
... ...
... ... @@ -249,10 +249,12 @@
<update id="updateRECEIPTION" parameterType="com.tianbo.analysis.model.TALLYMASTER" >
UPDATE TALLYMASTER
SET RECEIPTINFORMATION= #{receiptinformation,jdbcType=VARCHAR}
SET RECEIPTINFORMATION= #{receiptinformation,jdbcType=VARCHAR},
STATUS = #{status,jdbcType=VARCHAR}
WHERE WAYBILLNOMASTER = #{waybillnomaster,jdbcType=VARCHAR}
AND FLIGHTNO = #{flghtno, jdbcType=VARCHAR}
AND FLIGHTDATE = #{flightdate, jdbcType=TIMESTAMP}
AND FLIGHTNO = #{flightno, jdbcType=VARCHAR}
AND FLIGHTDATE = #{flightdate, jdbcType=DATE}
AND TALLTYPE = #{talltype,jdbcType=VARCHAR }
</update>
<select id="selectAutoIdByAwb" parameterType="com.tianbo.analysis.model.TALLYMASTER" resultType="com.tianbo.analysis.model.TALLYMASTER">
... ... @@ -260,8 +262,9 @@
FROM TALLYMASTER
WHERE
WAYBILLNOMASTER = #{waybillnomaster,jdbcType=VARCHAR}
AND FLIGHTNO = #{flghtno, jdbcType=VARCHAR}
AND FLIGHTDATE = #{flightdate, jdbcType=TIMESTAMP}
AND FLIGHTNO = #{flightno, jdbcType=VARCHAR}
AND FLIGHTDATE = #{flightdate, jdbcType=DATE}
AND TALLTYPE = #{talltype,jdbcType=VARCHAR }
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -162,7 +162,8 @@
<update id="updateRECEIPTION" parameterType="com.tianbo.analysis.model.TALLYSECONDARY" >
UPDATE TALLYSECONDARY
SET RECEIPTINFORMATION= #{receiptinformation,jdbcType=VARCHAR}
SET RECEIPTINFORMATION= #{receiptinformation,jdbcType=VARCHAR},
STATUS = #{status,jdbcType=VARCHAR}
WHERE WAYBILLNOMASTER = #{waybillnomaster,jdbcType=VARCHAR}
AND WAYBILLNOSECONDARY = #{waybillnosecondary,jdbcType=VARCHAR}
</update>
... ...