作者 朱兆平

电报解析优化

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