作者 朱兆平

电报解析优化

... ... @@ -20,7 +20,7 @@ public class FFMController {
public ResultJson resolve(@RequestParam String ffm){
FFMInfo ffmInfo = new FFMInfo();
ffmInfo.text = ffm;
boolean result = ffmResolve.resolve(ffmInfo);
return result? new ResultJson("200","success"):new ResultJson("400","解析失败");
ResultJson result = ffmResolve.resolve(ffmInfo);
return result;
}
}
... ...
package com.tianbo.analysis.controller.bean;
import com.tianbo.analysis.service.FFMResolve;
public enum ResponseReason {
MT8204_SUCCESS("200","直接改配申请操作成功"),
MT8204_ADD_ERR("8204400","直接改配申请添加失败,存在重复申请,请检查后重试"),
... ... @@ -7,7 +9,8 @@ public enum ResponseReason {
MT8204_DEL_ERR("8204402","直接改配申请更新失败"),
MT8204_SEND_ERR("8204404","直接改配发送失败"),
REAPET_SUBMIT_ERR("400001","请勿重复提交,请于5秒后尝试"),
MT8204_BATCH_SUCCESS("200","直接改配批量申请操作成功");
MT8204_BATCH_SUCCESS("200","直接改配批量申请操作成功"),
FFM_RESOLVE_FAILD("400","FFM报文解析失败");
private String code;
private String msg;
... ...
... ... @@ -495,7 +495,7 @@ public class FWBinfo implements Serializable {
public boolean rtgparse(String verlLine)throws FFMResolveException{
log.debug("[TEXT] 找到RTG信息行");
//校验正则1,取前三位验证是否是机场代码
String pattern = "^RTG(/[A-Z0-9]{5}/[A-Z0-9]{5})+";
String pattern = "^RTG(/[A-Z0-9]{5}){0,3}";
// 创建 Pattern 对象
Pattern r = Pattern.compile(pattern);
// 现在创建 matcher 对象
... ... @@ -503,7 +503,7 @@ public class FWBinfo implements Serializable {
//格式正则校验
if(m.find()){
String strList[]=verlLine.split("/");
if(strList.length>1){
if(strList.length>2){
arrivalstation1=strList[1].substring(0,3);
arrivalstation2=strList[2].substring(0,3);
}else{
... ...
... ... @@ -50,4 +50,14 @@ public class ResultJson<T> implements Serializable{
this.msg = responseReason.getMsg();
}
public ResponseReason getResponseReason() {
return responseReason;
}
public void setResponseReason(ResponseReason responseReason) {
this.responseReason = responseReason;
this.code = responseReason.getCode();
this.msg = responseReason.getMsg();
}
}
... ...
package com.tianbo.analysis.service;
import com.tianbo.analysis.model.FFMInfo;
import com.tianbo.analysis.model.ResultJson;
import java.util.List;
public interface FFMResolve {
boolean resolve(FFMInfo ffmInfo);
ResultJson resolve(FFMInfo ffmInfo);
List<FFMInfo> unresolvedFlightnoList();
List<FFMInfo> unresolvedFFMList(FFMInfo record);
... ...
package com.tianbo.analysis.service.imp;
import com.tianbo.analysis.controller.bean.ResponseReason;
import com.tianbo.analysis.dao.FFMInfoDao;
import com.tianbo.analysis.dao.TBBaseAirportInfoDao;
import com.tianbo.analysis.exception.FFMResolveException;
import com.tianbo.analysis.model.FFMInfo;
import com.tianbo.analysis.model.ResultJson;
import com.tianbo.analysis.model.TBBaseAirportInfo;
import com.tianbo.analysis.service.FFMResolve;
import com.tianbo.util.Date.DateUtil;
... ... @@ -32,7 +34,8 @@ public class FFMResolveImpl implements FFMResolve {
FFMInfoDao ffmInfoDao;
@Override
public boolean resolve(FFMInfo ffmInfo) {
public ResultJson resolve(FFMInfo ffmInfo) {
ResultJson resultJson = new ResultJson();
try{
ffmInfo.textToStringList();
ffmInfo.resolveFFMPart();
... ... @@ -56,14 +59,15 @@ public class FFMResolveImpl implements FFMResolve {
}
//todo:重复报文入库逻辑将以删除旧报文插入新报文为准
}
return true;
return new ResultJson("200","报文解析成功");
}
} catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
log.error(e.toString());
resultJson.setError(e.toString());
resultJson.setResponseReason(ResponseReason.FFM_RESOLVE_FAILD);
}
return false;
return resultJson;
}
@Override
... ...
... ... @@ -134,7 +134,7 @@ public class TransArriveExportImpl implements TransArriveExportService {
if (valied) {
FileUtils.writeStringToFile(file, xmlStr, StandardCharsets.UTF_8);
//发送报文到MQ
mq.send(xmlStr);
// mq.send(xmlStr);
//更新发送状态
record.setDstatus("001");
mapper.updateStatusByPrimaryKey(record);
... ...
... ... @@ -2,10 +2,14 @@ import com.tianbo.analysis.NmmsAdminApplication;
import com.tianbo.analysis.config.CustomsProperties;
import com.tianbo.analysis.model.TRANSTOARRIVEEXPORT;
import com.tianbo.analysis.service.TransArriveExportService;
import com.tianbo.analysis.tools.TransArriveTools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@SpringBootTest(classes = NmmsAdminApplication.class)
... ... @@ -22,35 +26,73 @@ public class TransAriiveTest {
public void send(){
TRANSTOARRIVEEXPORT t = new TRANSTOARRIVEEXPORT();
//海关信息及IC卡相关部分
t.setApplycode(customsProperties.getApplyCode());
t.setApplyname(customsProperties.getApplyName());
t.setCopcode(customsProperties.getCopCode());
// t.setApplycode(customsProperties.getApplyCode());
// t.setApplyname(customsProperties.getApplyName());
// t.setCopcode(customsProperties.getCopCode());
t.setCustomscode("4604");
//操作员IC卡号
t.setInputopid(customsProperties.getInputOpId());
t.setInputopname(customsProperties.getInputOpName());
t.setCertno("21212321321321");
// t.setInputopid(customsProperties.getInputOpId());
// t.setInputopname(customsProperties.getInputOpName());
t.setSeqno("");
//货物承运运输信息部分
/**
* 运抵编号(北方模式必填
* 南方模式免填
* 水运中转模式选填
* 运抵编号规则:4位申报地海关代码+2位卸货地代码+6位编号生成日期〔顺序为年(2位)、月(2位)、日(2位)〕+6位流水号';)
*/
t.setArriveno("460443220210000002");
//货物承运运输信息部分
// 集装箱编号
t.setContaid("");
// 运单号
t.setBillno("78464757722");
// 进出境运输方式代码:2-江海运输;3-铁路运输;4-汽车运输;5-航空运输;6-邮件运输
t.setTrafmode("5");
t.setTrnmode("2");
t.setTrafway("4");
t.setUnloadcode("CGO");
t.setArrivetime(new Date());
/**
* 北方模式选填
* 南方模式填写“@”+13位载货清单号
* 水运中转模式:境内水路运输填报驳船船名;
* 境内铁路运输填报车名(主管海关4位关别代码+“TRAIN”);
* 境内公路运输填报车名(主管海关4位关别代码+“TRUCK”)
*/
t.setTrafname("");
/**
* 境内运输工具航(班)次:北方模式选填
* 南方模式免填
* 水运中转模式:境内水路运输填报驳船航次号;
* 境内铁路、公路运输填报6位启运日期〔顺序为年(2位)、月(2位)、日(2位)
*/
t.setVoyageno("");
// 境内运输方式:2-江海运输;3-铁路运输;4-汽车运输;5-航空运输;6-邮件运输
t.setTrafway("5");
//货物信息部分
t.setGrosswt("42.00");
t.setPackno("2");
t.setGrosswt("16");
t.setUnloadcode("460043");
t.setArrivetime(new Date());
// t.setContatype("");
/**
* 转关方式:0-非转关运抵模式;1-南方转关运抵模式;2-北方转关运抵模式;3-水运中转运抵模式
*/
t.setTrnmode("2");
//申报签名部分
t.setOpertype("A");
t.setSign("kUNHDHVG1b72ZIrN8voIGUr+2JRITIo5FlusuSQCMerhV5GEGg9Z42L5F28MM+4gFL6CQgH2JPmdRdHAYIKJa89fdxGnHE3QSVd8dDUxx7q7AUUDzOg25OVB3ULywb8ruivj6tAR0daYkU3ACzWMYZoH4BNEMh4Za6DI7lBNf04=");
t.setOpertype("C");
// t.setSign("kUNHDHVG1b72ZIrN8voIGUr+2JRITIo5FlusuSQCMerhV5GEGg9Z42L5F28MM+4gFL6CQgH2JPmdRdHAYIKJa89fdxGnHE3QSVd8dDUxx7q7AUUDzOg25OVB3ULywb8ruivj6tAR0daYkU3ACzWMYZoH4BNEMh4Za6DI7lBNf04=");
t.setSigndate(new Date());
// t.setClientseqno("000000000000905006");
// t.setClientseqno("000000000000057246");
t.setClientseqno("000000000000002050");
t.setHostid("2012062600");
//t.setClientseqno("000000000000905006");
// t.setClientseqno(customsProperties.getTransarrive().getClientSeqno());
// t.setClientseqno(TransArriveTools.getClientseqno());
// t.setHostid("");
// t.setHostid(customsProperties.getTransarrive().getHostId());
//操作员签名证书号 暂时为空
// t.setCertno("");
transArriveExportService.send(t);
// transArriveExportService.addTransArriveExport(t);
List<String> ids = new ArrayList<>();
ids.add("202202101755010651");
transArriveExportService.batchSend(ids);
}
}
... ...