作者 朱兆平

新舱单辅助管理-ffm报文解析主要部分完成

@@ -7,7 +7,7 @@ server: @@ -7,7 +7,7 @@ server:
7 context-path: ${SERVER_CONTEXTPATH:} 7 context-path: ${SERVER_CONTEXTPATH:}
8 spring: 8 spring:
9 profiles: 9 profiles:
10 - active: pro 10 + active: dev
11 mvc: 11 mvc:
12 #静态资源,设置上传文件的访问, 12 #静态资源,设置上传文件的访问,
13 static-path-pattern: /** 13 static-path-pattern: /**
@@ -48,12 +48,12 @@ spring: @@ -48,12 +48,12 @@ spring:
48 type: com.alibaba.druid.pool.DruidDataSource 48 type: com.alibaba.druid.pool.DruidDataSource
49 #oracle 49 #oracle
50 driver-class-name: oracle.jdbc.OracleDriver 50 driver-class-name: oracle.jdbc.OracleDriver
51 - url: jdbc:oracle:thin:@192.168.1.199:10069:CGODB  
52 - username: CGONMS  
53 - password: 1q2w3e4r  
54 -# url: jdbc:oracle:thin:@192.168.1.253:1522:ORCLL 51 +# url: jdbc:oracle:thin:@192.168.1.199:10069:CGODB
55 # username: CGONMS 52 # username: CGONMS
56 -# password: vmvnv1v2 53 +# password: 1q2w3e4r
  54 + url: jdbc:oracle:thin:@192.168.1.253:1522:ORCLL
  55 + username: CGONMS
  56 + password: vmvnv1v2
57 #spring datasource mysql,注意编码配置,缺少数据库编码配置容易引起中文入库乱码 57 #spring datasource mysql,注意编码配置,缺少数据库编码配置容易引起中文入库乱码
58 # url: jdbc:mysql://127.0.0.1:3307/statistics?useUnicode=true&characterEncoding=utf8 58 # url: jdbc:mysql://127.0.0.1:3307/statistics?useUnicode=true&characterEncoding=utf8
59 # username: root 59 # username: root
@@ -115,7 +115,7 @@ pagehelper: @@ -115,7 +115,7 @@ pagehelper:
115 115
116 #debug配置,debug或者为true的时候,logback才会记录和写入日志文件 116 #debug配置,debug或者为true的时候,logback才会记录和写入日志文件
117 trace: false 117 trace: false
118 -debug: false 118 +debug: true
119 119
120 logging: 120 logging:
121 file: 121 file:
@@ -172,12 +172,12 @@ @@ -172,12 +172,12 @@
172 172
173 <!--开发环境:打印控制台--> 173 <!--开发环境:打印控制台-->
174 <springProfile name="dev"> 174 <springProfile name="dev">
175 - <logger name="org.springframework.boot" level="info"/>  
176 - <logger name="org.apache.tomcat" level="info" />  
177 - <logger name="com.tianbo.analysis.dao" level="DEBUG" /> 175 +<!-- <logger name="org.springframework.boot" level="info"/>-->
  176 +<!-- <logger name="org.apache.tomcat" level="info" />-->
  177 + <logger name="com.tianbo.analysis" level="DEBUG" />
178 <root level="INFO"> 178 <root level="INFO">
179 <appender-ref ref="CONSOLE" /> 179 <appender-ref ref="CONSOLE" />
180 - <!--<appender-ref ref="DEBUG_FILE" />--> 180 + <appender-ref ref="DEBUG_FILE" />
181 <!--<appender-ref ref="INFO_FILE" />--> 181 <!--<appender-ref ref="INFO_FILE" />-->
182 <!--<appender-ref ref="WARN_FILE" />--> 182 <!--<appender-ref ref="WARN_FILE" />-->
183 <appender-ref ref="ERROR_FILE" /> 183 <appender-ref ref="ERROR_FILE" />
  1 +package com.tianbo.analysis.controller;
  2 +
  3 +
  4 +import com.tianbo.analysis.model.FFMInfo;
  5 +import com.tianbo.analysis.model.ResultJson;
  6 +import com.tianbo.analysis.service.FFMResolve;
  7 +import org.springframework.beans.factory.annotation.Autowired;
  8 +import org.springframework.web.bind.annotation.*;
  9 +
  10 +import java.util.Map;
  11 +
  12 +@RestController
  13 +@RequestMapping("/ffm")
  14 +public class FFMController {
  15 +
  16 + @Autowired
  17 + FFMResolve ffmResolve;
  18 +
  19 + @PostMapping("resolve")
  20 + public ResultJson resolve(@RequestParam String ffm){
  21 + FFMInfo ffmInfo = new FFMInfo();
  22 + ffmInfo.text = ffm;
  23 + boolean result = ffmResolve.resolve(ffmInfo);
  24 + return result? new ResultJson("200","success"):new ResultJson("400","解析失败");
  25 + }
  26 +}
@@ -39,7 +39,7 @@ public class MT8204Controller { @@ -39,7 +39,7 @@ public class MT8204Controller {
39 @Autowired 39 @Autowired
40 MT8204Service mt8204Service; 40 MT8204Service mt8204Service;
41 41
42 - @GetMapping("/") 42 + @GetMapping("/index")
43 public ResultJson index(@RequestParam(value = "page",defaultValue = "1") int page, 43 public ResultJson index(@RequestParam(value = "page",defaultValue = "1") int page,
44 @RequestParam(value = "limit",defaultValue = "10") int limit, 44 @RequestParam(value = "limit",defaultValue = "10") int limit,
45 @RequestParam(value = "flightno",required = false) String flightNo, 45 @RequestParam(value = "flightno",required = false) String flightNo,
  1 +package com.tianbo.analysis.dao;
  2 +
  3 +import com.tianbo.analysis.model.FFMInfo;
  4 +
  5 +public interface FFMInfoDao {
  6 + int deleteByPrimaryKey(String autoid);
  7 +
  8 + int insert(FFMInfo record);
  9 +
  10 + int insertSelective(FFMInfo record);
  11 +
  12 + FFMInfo selectByPrimaryKey(String autoid);
  13 +
  14 + int updateByPrimaryKeySelective(FFMInfo record);
  15 +
  16 + int updateByPrimaryKey(FFMInfo record);
  17 +}
  1 +package com.tianbo.analysis.dao;
  2 +
  3 +import com.tianbo.analysis.model.TBBaseAirportInfo;
  4 +
  5 +import java.util.List;
  6 +
  7 +public interface TBBaseAirportInfoDao {
  8 + int deleteByPrimaryKey(String airportid);
  9 +
  10 + int insert(TBBaseAirportInfo record);
  11 +
  12 + int insertSelective(TBBaseAirportInfo record);
  13 +
  14 + TBBaseAirportInfo selectByPrimaryKey(String airportid);
  15 +
  16 + List<TBBaseAirportInfo> checkInternal(String airportidOrg, String airportidDes);
  17 +
  18 + int updateByPrimaryKeySelective(TBBaseAirportInfo record);
  19 +
  20 + int updateByPrimaryKey(TBBaseAirportInfo record);
  21 +}
  1 +package com.tianbo.analysis.exception;
  2 +
  3 +public class FFMResolveException extends Exception {
  4 +
  5 + public FFMResolveException(){
  6 + super();
  7 + }
  8 +
  9 + public FFMResolveException(String errMessage){
  10 + super(errMessage);
  11 + }
  12 +
  13 + public FFMResolveException(String message, Throwable cause) {
  14 + super(message, cause);
  15 + }
  16 +
  17 + public FFMResolveException(Throwable cause) {
  18 + super(cause);
  19 + }
  20 +}
  1 +package com.tianbo.analysis.model;
  2 +
  3 +import java.io.BufferedReader;
  4 +import java.io.IOException;
  5 +import java.io.Serializable;
  6 +import java.io.StringReader;
  7 +import java.text.ParseException;
  8 +import java.util.*;
  9 +import java.util.regex.Matcher;
  10 +import java.util.regex.Pattern;
  11 +
  12 +import com.tianbo.analysis.exception.FFMResolveException;
  13 +import com.tianbo.util.Date.DateUtil;
  14 +import lombok.Data;
  15 +import lombok.extern.slf4j.Slf4j;
  16 +import org.apache.commons.lang.StringUtils;
  17 +
  18 +import javax.validation.constraints.NotNull;
  19 +
  20 +/**
  21 + * FFM_INFO
  22 + * @author
  23 + */
  24 +@Data
  25 +@Slf4j
  26 +public class FFMInfo implements Serializable {
  27 + private String autoid;
  28 +
  29 + private Date createdate;
  30 +
  31 + private String flightno;
  32 +
  33 + private Date flightdate;
  34 +
  35 + private String waybillnomaster;
  36 +
  37 + private String originatingstation;
  38 +
  39 + private String destinationstation;
  40 +
  41 + private String manifesttotalpiece;
  42 +
  43 + private String manifesttotalweight;
  44 +
  45 + private String productname;
  46 +
  47 + private String specialgoodscode;
  48 +
  49 + private String customscode;
  50 +
  51 + private String customsstatus;
  52 +
  53 + private String isbatch;
  54 +
  55 + private String pallet;
  56 +
  57 + /**
  58 + * 报文序号
  59 + */
  60 + private String reportorder;
  61 +
  62 + private String islast;
  63 +
  64 + private String originatingstationBill;
  65 +
  66 + private String destinationstationBill;
  67 +
  68 + private String totalpiece;
  69 +
  70 + private String dealstatus;
  71 +
  72 + //报文内容
  73 + public String text;
  74 + public List<String> lineList;
  75 + public String order;
  76 + public String planeNo;
  77 + public int wayBillParseStartLine =0;
  78 + private static final String TEXT_SIGN_LAST = "LAST";
  79 + private static final String TEXT_SIGN_CONT= "CONT";
  80 + private static final String KEY_WORD_3 = "FFM,ULD,OSI,COR,OCI,DEG,DIM";
  81 + private static final String KEY_WORD_4 = "CONT,LAST";
  82 + private static final long serialVersionUID = 1L;
  83 +
  84 + public FFMInfo(){
  85 +
  86 + }
  87 +
  88 + public FFMInfo(String autoid, Date createdate, String flightno, Date flightdate, String waybillnomaster, String originatingstation, String destinationstation, String manifesttotalpiece, String manifesttotalweight, String productname, String specialgoodscode, String customscode, String customsstatus, String isbatch, String pallet, String reportorder, String islast, String originatingstationBill, String destinationstationBill, String totalpiece, String dealstatus) {
  89 + this.autoid = autoid;
  90 + this.createdate = createdate;
  91 + this.flightno = flightno;
  92 + this.flightdate = flightdate;
  93 + this.waybillnomaster = waybillnomaster;
  94 + this.originatingstation = originatingstation;
  95 + this.destinationstation = destinationstation;
  96 + this.manifesttotalpiece = manifesttotalpiece;
  97 + this.manifesttotalweight = manifesttotalweight;
  98 + this.productname = productname;
  99 + this.specialgoodscode = specialgoodscode;
  100 + this.customscode = customscode;
  101 + this.customsstatus = customsstatus;
  102 + this.isbatch = isbatch;
  103 + this.pallet = pallet;
  104 + this.reportorder = reportorder;
  105 + this.islast = islast;
  106 + this.originatingstationBill = originatingstationBill;
  107 + this.destinationstationBill = destinationstationBill;
  108 + this.totalpiece = totalpiece;
  109 + this.dealstatus = dealstatus;
  110 + }
  111 +
  112 +
  113 + @Override
  114 + public String toString() {
  115 + StringBuilder sb = new StringBuilder();
  116 + sb.append(getClass().getSimpleName());
  117 + sb.append(" [");
  118 + sb.append("Hash = ").append(hashCode());
  119 + sb.append(", autoid=").append(autoid);
  120 + sb.append(", createdate=").append(createdate);
  121 + sb.append(", flightno=").append(flightno);
  122 + sb.append(", flightdate=").append(flightdate);
  123 + sb.append(", waybillnomaster=").append(waybillnomaster);
  124 + sb.append(", originatingstation=").append(originatingstation);
  125 + sb.append(", destinationstation=").append(destinationstation);
  126 + sb.append(", manifesttotalpiece=").append(manifesttotalpiece);
  127 + sb.append(", manifesttotalweight=").append(manifesttotalweight);
  128 + sb.append(", productname=").append(productname);
  129 + sb.append(", specialgoodscode=").append(specialgoodscode);
  130 + sb.append(", customscode=").append(customscode);
  131 + sb.append(", customsstatus=").append(customsstatus);
  132 + sb.append(", isbatch=").append(isbatch);
  133 + sb.append(", pallet=").append(pallet);
  134 + sb.append(", reportorder=").append(reportorder);
  135 + sb.append(", islast=").append(islast);
  136 + sb.append(", originatingstationBill=").append(originatingstationBill);
  137 + sb.append(", destinationstationBill=").append(destinationstationBill);
  138 + sb.append(", totalpiece=").append(totalpiece);
  139 + sb.append(", dealstatus=").append(dealstatus);
  140 + sb.append(", serialVersionUID=").append(serialVersionUID);
  141 + sb.append("]");
  142 + return sb.toString();
  143 + }
  144 +
  145 + /**
  146 + * 校验报文结尾标识
  147 + * 将报文字符窜转换成行数组
  148 + * @return
  149 + * @throws IOException
  150 + * @throws FFMResolveException
  151 + */
  152 + public boolean textToStringList() throws IOException,FFMResolveException {
  153 + if (StringUtils.isNotBlank(text)) {
  154 + /**
  155 + * 检查报文是否包含尾部标识
  156 + */
  157 + lineList = new ArrayList<>();
  158 + if (text.contains(TEXT_SIGN_CONT) || text.contains(TEXT_SIGN_LAST)) {
  159 + BufferedReader reader = new BufferedReader(new StringReader(text));
  160 + log.info(this.toString());
  161 + for (String lineStr = reader.readLine();
  162 + lineStr != null;
  163 + lineStr = reader.readLine()) {
  164 + //log.info("已读取行{}-{}",i,lineStr);
  165 + lineList.add(lineStr);
  166 + }
  167 + return true;
  168 + } else {
  169 + throw new FFMResolveException("报文尾部缺少文件结束标识LAST或者CONT");
  170 + }
  171 + }
  172 +
  173 + return false;
  174 + }
  175 +
  176 + /**
  177 + * 寻找FFM/* 开头
  178 + * 根据开头行号 并向下处理 航班信息行
  179 + * 再向下处理航班目的站信息
  180 + * @return
  181 + * @throws FFMResolveException
  182 + */
  183 + public boolean resolveFFMPart() throws FFMResolveException, ParseException{
  184 + int currentLine = 0;
  185 + if (!lineList.isEmpty()){
  186 + int keyword_i = 0;
  187 + for (int i = 0; i < lineList.size(); i++) {
  188 + //根据行关键字走相应的解析逻辑
  189 + String line = lineList.get(i);
  190 + log.debug("[TEXT] 开始处理行[{}]-[{}]",i,line);
  191 + String keyword = keyword(line);
  192 + if (!"NOT_KEYWORD".equals(keyword)){
  193 + log.debug("[TEXT] 行[{}]包含关键字,开始处理",i);
  194 + if ("FFM".equals(keyword)){
  195 + log.debug("[TEXT] 找到FFM开头节点");
  196 + currentLine = i;
  197 + //ffm版本
  198 + String ver = line.split("/")[1];
  199 + log.info("[TEXT] 报文版本{}",ver.trim());
  200 +
  201 + //处理航班信息
  202 + log.debug("[TEXT] 向下行确定航班信息");
  203 + currentLine++;
  204 + flight(lineList.get(currentLine).trim());
  205 +
  206 + /**
  207 + * 取第一目的站
  208 + * 这里注意,有的错误报文的航班节点后面没带或者忘了带目的站节点,
  209 + * 所以这里需要加个校验
  210 + */
  211 + currentLine++;
  212 + destination(lineList.get(currentLine).trim());
  213 + currentLine++;
  214 + wayBillParseStartLine = currentLine;
  215 + }else if ("CONT".equals(keyword) || "LAST".equals(keyword) ){
  216 + keyword_i++;
  217 + }
  218 +
  219 + }
  220 + }
  221 + if (keyword_i==0){
  222 + throw new FFMResolveException("[TEXT] 报文尾部缺少文件结束标识LAST或者CONT");
  223 + }
  224 + }
  225 + return false;
  226 + }
  227 +
  228 + /**
  229 + * 解析航班信息部分
  230 + * @throws FFMResolveException
  231 + * @throws ParseException
  232 + */
  233 + public void flight(String text) throws FFMResolveException, ParseException {
  234 + log.debug("[FLIGHT] 开始处理航班信息");
  235 + String[] flight = text.split("/");
  236 + if (flight.length>3){
  237 + order = flight[0];
  238 + log.info("[FLIGHT] 报文序号为{}",order);
  239 + flightno = flight[1];
  240 + log.info("[FLIGHT] 航班号为[{}]",flightno);
  241 +
  242 +
  243 + //航班日期取出来的格式为10SEP或者10SEP1022,带时间的注意
  244 + String flightDateStr = flight[2];
  245 + log.info("[FLIGHT] 航班日期信息为[{}]",flightDateStr);
  246 +
  247 + String flightDateDay = flightDateStr.substring(0,2);
  248 + String flightDateMonth = flightDateStr.substring(2,5);
  249 +
  250 +
  251 + /**
  252 + * FFM跨年问题
  253 + * FFM报文中的月份为12月,当前服务器时间月份为1月,视为跨年.
  254 + * 跨年问题需要设置FFM报文的航班年份为当前年份-1
  255 + */
  256 + Calendar cal = Calendar.getInstance();
  257 + //当前年份
  258 + int yearNow = cal.get(Calendar.YEAR);
  259 + int monthNow = cal.get(Calendar.MONTH);
  260 +
  261 + if (monthNow == 1 && "DEC".equals(flightDateMonth)){
  262 + log.info("[FLIGHT] 航班日期跨年");
  263 + yearNow = yearNow-1;
  264 + }
  265 +
  266 + flightDateStr = flightDateStr+yearNow;
  267 + flightdate = DateUtil.dateFormatFlight(flightDateStr);
  268 +
  269 + originatingstation = flight[3];
  270 + log.info("[FLIGHT] 航班起始站为[{}]",originatingstation);
  271 + if (flight.length>4){
  272 + planeNo = flight[4];
  273 + log.info("[FLIGHT] 航班飞机号为[{}]",planeNo);
  274 + }
  275 + }else {
  276 + log.error("[FLIGHT] 航班信息节点不正确");
  277 + throw new FFMResolveException("[FLIGHT] 航班信息节点不正确");
  278 + }
  279 + }
  280 + /**
  281 + * 解析航班第一目的站
  282 + *
  283 + */
  284 + public void destination(String text) throws FFMResolveException{
  285 + log.info("4.开始校验处理航班目的站节点信息 -> {}",text);
  286 + if (text.length()>=3){
  287 + //校验是否空货机
  288 + String pattern_nil = "[A-Z]{3}/NIL";
  289 + Pattern r_nil = Pattern.compile(pattern_nil);
  290 + // 现在创建 matcher 对象
  291 + Matcher m_nil = r_nil.matcher(text);
  292 + if (m_nil.find()){
  293 + log.info("4.1 航班目的站货物为空");
  294 + throw new FFMResolveException("航班第一目的站货物为空,解析结束");
  295 + }
  296 +
  297 + //校验是否是目的站节点
  298 + //校验正则1,取前三位验证是否是机场代码
  299 + String pattern = "^[A-Z]{3}$|^[A-Z]{3}/\\d{2}[A-Z]{3}\\d{4}";
  300 + // 创建 Pattern 对象
  301 + Pattern r = Pattern.compile(pattern);
  302 + // 现在创建 matcher 对象
  303 + Matcher m = r.matcher(text);
  304 + if (m.find()){
  305 + log.info("4.1 航班目的站节点校验通过");
  306 +
  307 + destinationstation = text.substring(0,3);
  308 + log.info("4.2 航班目的站一为[{}]",destinationstation);
  309 + }else {
  310 + log.error("4.1[ERROR] !!航班目的站节点校验不通过!!");
  311 + throw new FFMResolveException("航班目的站节点校验不通过.缺少航班目的站节点");
  312 + }
  313 + }else {
  314 + throw new FFMResolveException("航班目的站节点长度不对.");
  315 + }
  316 +
  317 +
  318 + }
  319 +
  320 + /**
  321 + * 判断是否有散舱
  322 + * 有BUP散舱先处理散舱,没有则进入ULD及ULD货物解析阶段
  323 + * 假设默认航班有散舱,将散舱的ULD号默认为 "BUP"
  324 + * 设置当前的ULD 为 散舱ULD "BUP"
  325 + * 那么散舱下的运单直到解析到真正的板箱号后,uld变成真正的货物板箱
  326 + *
  327 + */
  328 + public List<FFMInfo> resolve_ULD_Waybill() throws FFMResolveException{
  329 + log.info("[BILL] 开始解析舱单列表");
  330 + String uld = "BUP";
  331 + List<FFMInfo> ffmInfoList = new ArrayList<>();
  332 + //默认非国际转运
  333 + if (this.wayBillParseStartLine ==0){
  334 + return ffmInfoList;
  335 + }
  336 +
  337 + for (int i = this.wayBillParseStartLine; i < lineList.size(); i++) {
  338 + wayBillParseStartLine++;
  339 + String line = lineList.get(i);
  340 + log.debug("[BILL] 开始解析行[{}]-[{}]",i,line);
  341 + String customStatus = "-1";
  342 + //行尾部结束标识检查
  343 + String keyword = keyword(line);
  344 + if ("CONT".equals(keyword) || "LAST".equals(keyword)){
  345 + log.info("[END] 已解析到文件结束标识[{}],解析完毕",keyword);
  346 + islast = keyword;
  347 + break;
  348 + }
  349 +
  350 + multiDestinationParse(line);
  351 +
  352 + if ("ULD".equals(keyword)){
  353 + uld = ULDParse(line);
  354 + }
  355 + FFMInfo ffmInfoParsed = WayBillParse(line,uld);
  356 + if (ffmInfoParsed!=null){
  357 + ffmInfoList.add(ffmInfoParsed);
  358 + }
  359 +
  360 + //todo:判断下一行是否/开头,是/头则为上面运单的特货操作代码
  361 + //todo:判断下行是否为特殊字符"DIM,OSI,COR,OCI",是则作为上面运单的附加信息继续解析.
  362 + }
  363 + return ffmInfoList;
  364 +
  365 + }
  366 + /**
  367 + * 多航班目的站解析
  368 + */
  369 + private void multiDestinationParse(String line) throws FFMResolveException {
  370 +
  371 + //校验正则1,取前三位验证是否是机场代码
  372 + String pattern_f = "^[A-Z]{3}$|^[A-Z]{3}/\\d{2}[A-Z]{3}\\d{4}";
  373 + // 创建 Pattern 对象
  374 + Pattern r_f = Pattern.compile(pattern_f);
  375 + // 现在创建 matcher 对象
  376 + Matcher mF = r_f.matcher(line);
  377 + if (mF.find()){
  378 + log.debug("5-[FLIGHT] 适配到航班其他目的站");
  379 + String flightDes = line.substring(0,3);
  380 + if (!KEY_WORD_3.contains(flightDes)){
  381 + destinationstation = flightDes;
  382 + log.info("5-[FLIGHT] 新航班目的站为[{}]",destinationstation);
  383 + }
  384 + }
  385 + if (StringUtils.isEmpty(destinationstation)){
  386 + throw new FFMResolveException("航班目的站节点校验不通过.");
  387 + }
  388 + }
  389 +
  390 + /**
  391 + * 解析ULD板箱号部分
  392 + * @param line
  393 + * @return 解析成功返回板箱号
  394 + */
  395 + private String ULDParse(String line) throws FFMResolveException {
  396 +
  397 + log.debug("[ULD] 此行为ULD信息行");
  398 + //板箱格式适配
  399 + String patternULD = "^ULD/([A-Z]{3}\\S{4,5}\\S{2})";
  400 + Pattern rULD = Pattern.compile(patternULD);
  401 + // 现在创建 matcher 对象
  402 + Matcher mULD = rULD.matcher(line);
  403 + if (mULD.find()){
  404 + log.debug("[ULD] ULD查到分组,数量{}",mULD.groupCount());
  405 +// for (int j1 = 1; j1 < mULD.groupCount()+1; j1++) {
  406 +// log.info("5-[ULD] 分组{}内容为:{}",j1,mULD.group(j1));
  407 +// }
  408 + String uld= mULD.group(1);
  409 + log.debug("[ULD] 当前ULD已变更为{}",uld);
  410 + return uld;
  411 + }else {
  412 + throw new FFMResolveException(line+"的ULD节点格式错误,无法适配正则(^ULD/([A-Z]{3})(\\S{5})(\\S{2})");
  413 + }
  414 +
  415 +
  416 + }
  417 +
  418 + private FFMInfo WayBillParse(String line,String uld) throws FFMResolveException {
  419 + //运单格式适配,这里注意空格字符 与连字符"-"
  420 + String pattern = "^(\\d{3}-\\d{8})([A-Z]{3})([A-Z]{3})/(T|P|S|M)(\\d+)(K)([0-9\\.]+)(MC)?([0-9\\.]+)?(DG)?([0-9\\.]+)?(T)?([0-9]+)?/";
  421 + // 创建 Pattern 对象
  422 + Pattern r = Pattern.compile(pattern);
  423 + // 现在创建 matcher 对象
  424 + Matcher m = r.matcher(line);
  425 + if(m.find()){
  426 + log.debug("[AWB] 行[{}]属于运单行,开始解析,当前板箱号为:{}",line,uld);
  427 + log.debug("[AWB] 查到分组,数量{}",m.groupCount());
  428 + String waybillNo = m.group(1);
  429 + String waybillOrigin = m.group(2);
  430 + String waybillDes = m.group(3);
  431 + String waybillSplit = m.group(4);
  432 + String waybillPiece = m.group(5);
  433 + String waybillWeight = m.group(7);
  434 + String waybillVolume = m.group(9);
  435 + String waybillDensity = m.group(11);
  436 + String waybillTotalPiece = m.group(13);
  437 +
  438 +
  439 + /**
  440 + * 考虑到货物描述带空格及其他字符 用split获取
  441 + */
  442 + String waybillGoodsDes = line.split("/")[2];
  443 +
  444 +
  445 +
  446 +// for (int j = 1; j < m.groupCount()+1; j++) {
  447 +// log.info("5-[AWB] 分组{}内容为:{}",j,m.group(j));
  448 +// }
  449 +
  450 + if(model7Check(waybillNo)){
  451 + log.debug("[AWB] 运单-({})模七校验通过",waybillNo);
  452 + }else {
  453 + log.error("{}运单模七校验不通过",waybillNo);
  454 + throw new FFMResolveException(waybillNo+"运单模七校验不通过");
  455 + }
  456 + log.debug("运单的下一行为{}",lineList.get(wayBillParseStartLine));
  457 +
  458 + log.info("[AWB-INFO] 运单信息:报文序号:{} 所属航班:{}/{} 航班起始站/目的站:{}/{} 所属板箱:{} 运单号:{} 起始站/目的站:{}/{} 分批标识:{} 分批件重:{}/{} 体积:{} 密度:{} 总件数:{} 货物描述:{}",
  459 + order,
  460 + flightno,
  461 + flightdate,
  462 + originatingstation,
  463 + destinationstation,
  464 + uld,
  465 + waybillNo,
  466 + waybillOrigin,
  467 + waybillDes,
  468 + waybillSplit,
  469 + waybillPiece,
  470 + waybillWeight,
  471 + waybillVolume,
  472 + waybillDensity,
  473 + waybillTotalPiece,
  474 + waybillGoodsDes);
  475 +
  476 + return new FFMInfo(
  477 + UUID.randomUUID().toString(),
  478 + new Date(),
  479 + flightno,
  480 + flightdate,
  481 + waybillNo,
  482 + originatingstation,
  483 + destinationstation,
  484 + waybillPiece,
  485 + waybillWeight,
  486 + waybillGoodsDes,
  487 + "",
  488 + "4604",
  489 + "-1",
  490 + waybillSplit,
  491 + uld,
  492 + order,
  493 + islast,
  494 + waybillOrigin,
  495 + waybillDes,
  496 + waybillTotalPiece,
  497 + "0");
  498 + }
  499 + return null;
  500 + }
  501 + /**
  502 + * 关键字识别
  503 + * @param text 每行的内容
  504 + * @return 识别为关键字的返回关键字,未被识别为关键字的返回NOT_KEYWORD;
  505 + * 返回的关键字 三字码关键字 机场代码关键字 文件结尾关键字 CONT,LAST
  506 + */
  507 + public String keyword(@NotNull String text){
  508 + //取每行前三位
  509 + if (StringUtils.isNotBlank(text) && text.length()>3){
  510 + String s_3 = text.substring(0,3);
  511 + String s_4 = text.substring(0,4);
  512 + if(KEY_WORD_3.contains(s_3)){
  513 + return s_3;
  514 + }
  515 + if(KEY_WORD_4.contains(s_4)){
  516 + return s_4;
  517 + }
  518 + }else if(text.length()==3){
  519 + log.info("[KEYWORD] {}很大可能是机场目的站",text);
  520 + }
  521 +
  522 + return "NOT_KEYWORD";
  523 + }
  524 + /**
  525 + * 模七校验
  526 + * @param waybillNo
  527 + * @return
  528 + */
  529 + public boolean model7Check(String waybillNo){
  530 + String pattern = "\\d{3}-\\d{8}";
  531 + // 创建 Pattern 对象
  532 + Pattern r = Pattern.compile(pattern);
  533 + // 现在创建 matcher 对象
  534 + Matcher m = r.matcher(waybillNo);
  535 + if (m.find()){
  536 + String num = waybillNo.split("-")[1];
  537 + String num_7 = num.substring(0,7);
  538 + String num_end = num.substring(7,8);
  539 + if (Integer.parseInt(num_7)% 7 == Integer.parseInt(num_end)){
  540 + return true;
  541 + }else {
  542 + log.error("{}模七不通过",waybillNo);
  543 + }
  544 +
  545 + }else {
  546 + log.error("{}运单格式不正确",waybillNo);
  547 + }
  548 +
  549 + return false;
  550 + }
  551 +}
  1 +package com.tianbo.analysis.model;
  2 +
  3 +import java.io.Serializable;
  4 +import lombok.Data;
  5 +
  6 +/**
  7 + * TB_BASE_AIRPORT_INFO
  8 + * @author
  9 + */
  10 +@Data
  11 +public class TBBaseAirportInfo implements Serializable {
  12 + private String airportid;
  13 +
  14 + private String internal;
  15 +
  16 + private String cityid;
  17 +
  18 + private String airportdescchn;
  19 +
  20 + private String airportdesceng;
  21 +
  22 + private static final long serialVersionUID = 1L;
  23 +
  24 + @Override
  25 + public boolean equals(Object that) {
  26 + if (this == that) {
  27 + return true;
  28 + }
  29 + if (that == null) {
  30 + return false;
  31 + }
  32 + if (getClass() != that.getClass()) {
  33 + return false;
  34 + }
  35 + TBBaseAirportInfo other = (TBBaseAirportInfo) that;
  36 + return (this.getAirportid() == null ? other.getAirportid() == null : this.getAirportid().equals(other.getAirportid()))
  37 + && (this.getInternal() == null ? other.getInternal() == null : this.getInternal().equals(other.getInternal()))
  38 + && (this.getCityid() == null ? other.getCityid() == null : this.getCityid().equals(other.getCityid()))
  39 + && (this.getAirportdescchn() == null ? other.getAirportdescchn() == null : this.getAirportdescchn().equals(other.getAirportdescchn()))
  40 + && (this.getAirportdesceng() == null ? other.getAirportdesceng() == null : this.getAirportdesceng().equals(other.getAirportdesceng()));
  41 + }
  42 +
  43 + @Override
  44 + public int hashCode() {
  45 + final int prime = 31;
  46 + int result = 1;
  47 + result = prime * result + ((getAirportid() == null) ? 0 : getAirportid().hashCode());
  48 + result = prime * result + ((getInternal() == null) ? 0 : getInternal().hashCode());
  49 + result = prime * result + ((getCityid() == null) ? 0 : getCityid().hashCode());
  50 + result = prime * result + ((getAirportdescchn() == null) ? 0 : getAirportdescchn().hashCode());
  51 + result = prime * result + ((getAirportdesceng() == null) ? 0 : getAirportdesceng().hashCode());
  52 + return result;
  53 + }
  54 +
  55 + @Override
  56 + public String toString() {
  57 + StringBuilder sb = new StringBuilder();
  58 + sb.append(getClass().getSimpleName());
  59 + sb.append(" [");
  60 + sb.append("Hash = ").append(hashCode());
  61 + sb.append(", airportid=").append(airportid);
  62 + sb.append(", internal=").append(internal);
  63 + sb.append(", cityid=").append(cityid);
  64 + sb.append(", airportdescchn=").append(airportdescchn);
  65 + sb.append(", airportdesceng=").append(airportdesceng);
  66 + sb.append(", serialVersionUID=").append(serialVersionUID);
  67 + sb.append("]");
  68 + return sb.toString();
  69 + }
  70 +}
@@ -17,4 +17,12 @@ public interface ArriveMasterService { @@ -17,4 +17,12 @@ public interface ArriveMasterService {
17 boolean importFromPreplan(@NotNull PREPAREMASTER preparemasterFirst); 17 boolean importFromPreplan(@NotNull PREPAREMASTER preparemasterFirst);
18 18
19 int updatePremasterArrivedHeadStatus(AdvanceArrive preArrivedWaybillList); 19 int updatePremasterArrivedHeadStatus(AdvanceArrive preArrivedWaybillList);
  20 +
  21 + /**
  22 + * 校验提前运抵运单所属申请人是否可以申报提前运抵
  23 + * @param wayBillno
  24 + * @return
  25 + * todo: 提前运抵货代管理
  26 + */
  27 + boolean checkSender(String wayBillno);
20 } 28 }
  1 +package com.tianbo.analysis.service;
  2 +
  3 +import com.tianbo.analysis.model.FFMInfo;
  4 +
  5 +public interface FFMResolve {
  6 + boolean resolve(FFMInfo ffmInfo);
  7 +}
@@ -229,4 +229,9 @@ public class ArriveMasterServiceImpl implements ArriveMasterService { @@ -229,4 +229,9 @@ public class ArriveMasterServiceImpl implements ArriveMasterService {
229 } 229 }
230 return 0; 230 return 0;
231 } 231 }
  232 +
  233 + @Override
  234 + public boolean checkSender(String wayBillno) {
  235 + return false;
  236 + }
232 } 237 }
  1 +package com.tianbo.analysis.service.imp;
  2 +
  3 +import com.tianbo.analysis.dao.FFMInfoDao;
  4 +import com.tianbo.analysis.dao.TBBaseAirportInfoDao;
  5 +import com.tianbo.analysis.exception.FFMResolveException;
  6 +import com.tianbo.analysis.model.FFMInfo;
  7 +import com.tianbo.analysis.model.TBBaseAirportInfo;
  8 +import com.tianbo.analysis.service.FFMResolve;
  9 +import com.tianbo.util.Date.DateUtil;
  10 +import lombok.extern.slf4j.Slf4j;
  11 +import org.apache.commons.lang.StringUtils;
  12 +import org.springframework.stereotype.Service;
  13 +
  14 +import javax.annotation.Resource;
  15 +import javax.validation.constraints.NotNull;
  16 +import java.io.BufferedReader;
  17 +import java.io.IOException;
  18 +import java.io.StringReader;
  19 +import java.text.ParseException;
  20 +import java.util.*;
  21 +import java.util.regex.Matcher;
  22 +import java.util.regex.Pattern;
  23 +
  24 +@Slf4j
  25 +@Service
  26 +public class FFMResolveImpl implements FFMResolve {
  27 +
  28 + @Resource
  29 + TBBaseAirportInfoDao airportInfoDao;
  30 +
  31 + @Resource
  32 + FFMInfoDao ffmInfoDao;
  33 +
  34 + @Override
  35 + public boolean resolve(FFMInfo ffmInfo) {
  36 + try{
  37 + ffmInfo.textToStringList();
  38 + ffmInfo.resolveFFMPart();
  39 + List<FFMInfo> ffmInfoList = ffmInfo.resolve_ULD_Waybill();
  40 + if (!ffmInfoList.isEmpty()){
  41 + log.info("解析了{}个舱单",ffmInfoList.size());
  42 + for (FFMInfo ffm : ffmInfoList) {
  43 + //todo:国际转运判定,需要维护机场代码静态表
  44 + List<TBBaseAirportInfo> airportInfoList= airportInfoDao.checkInternal(ffm.getOriginatingstationBill(),ffm.getDestinationstationBill());
  45 + if (!airportInfoList.isEmpty() && airportInfoList.get(0).getInternal().equals(airportInfoList.get(1).getInternal()) && "1".equals(airportInfoList.get(1).getInternal())){
  46 + ffm.setCustomsstatus("002");
  47 + log.info("运单{}为国际转运货物",ffm.getWaybillnomaster());
  48 + }
  49 +// int result = ffmInfoDao.insertSelective(ffm);
  50 +// if (result <=0){
  51 +// log.error("{}入库失败",ffm.getWaybillnomaster());
  52 +// }
  53 + //todo:重复报文入库逻辑将以删除旧报文插入新报文为准
  54 + }
  55 + return true;
  56 + }
  57 + } catch (Exception e){
  58 + e.printStackTrace();
  59 + log.error(e.toString());
  60 + }
  61 +
  62 + return false;
  63 + }
  64 +}
@@ -47,6 +47,6 @@ @@ -47,6 +47,6 @@
47 <property name="enableSubPackages" value="false"/> 47 <property name="enableSubPackages" value="false"/>
48 </javaClientGenerator> 48 </javaClientGenerator>
49 <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名--> 49 <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-->
50 - <table schema="CGONMS" tableName="MANIFEST_AIR_CHANGE" domainObjectName="MANIFEST_AIR_CHANGE" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table> 50 + <table schema="CGONMS" tableName="FFM_INFO" domainObjectName="FFM_INFO" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
51 </context> 51 </context>
52 </generatorConfiguration> 52 </generatorConfiguration>
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3 +<mapper namespace="com.tianbo.analysis.dao.FFMInfoDao">
  4 + <resultMap id="BaseResultMap" type="com.tianbo.analysis.model.FFMInfo">
  5 + <id column="AUTOID" jdbcType="VARCHAR" property="autoid" />
  6 + <result column="CREATEDATE" jdbcType="TIMESTAMP" property="createdate" />
  7 + <result column="FLIGHTNO" jdbcType="VARCHAR" property="flightno" />
  8 + <result column="FLIGHTDATE" jdbcType="TIMESTAMP" property="flightdate" />
  9 + <result column="WAYBILLNOMASTER" jdbcType="VARCHAR" property="waybillnomaster" />
  10 + <result column="ORIGINATINGSTATION" jdbcType="VARCHAR" property="originatingstation" />
  11 + <result column="DESTINATIONSTATION" jdbcType="VARCHAR" property="destinationstation" />
  12 + <result column="MANIFESTTOTALPIECE" jdbcType="VARCHAR" property="manifesttotalpiece" />
  13 + <result column="MANIFESTTOTALWEIGHT" jdbcType="VARCHAR" property="manifesttotalweight" />
  14 + <result column="PRODUCTNAME" jdbcType="VARCHAR" property="productname" />
  15 + <result column="SPECIALGOODSCODE" jdbcType="VARCHAR" property="specialgoodscode" />
  16 + <result column="CUSTOMSCODE" jdbcType="VARCHAR" property="customscode" />
  17 + <result column="CUSTOMSSTATUS" jdbcType="VARCHAR" property="customsstatus" />
  18 + <result column="ISBATCH" jdbcType="VARCHAR" property="isbatch" />
  19 + <result column="PALLET" jdbcType="VARCHAR" property="pallet" />
  20 + <result column="REPORTORDER" jdbcType="VARCHAR" property="reportorder" />
  21 + <result column="ISLAST" jdbcType="VARCHAR" property="islast" />
  22 + <result column="ORIGINATINGSTATION_BILL" jdbcType="VARCHAR" property="originatingstationBill" />
  23 + <result column="DESTINATIONSTATION_BILL" jdbcType="VARCHAR" property="destinationstationBill" />
  24 + <result column="TOTALPIECE" jdbcType="VARCHAR" property="totalpiece" />
  25 + <result column="DEALSTATUS" jdbcType="VARCHAR" property="dealstatus" />
  26 + </resultMap>
  27 + <sql id="Base_Column_List">
  28 + AUTOID, CREATEDATE, FLIGHTNO, FLIGHTDATE, WAYBILLNOMASTER, ORIGINATINGSTATION, DESTINATIONSTATION,
  29 + MANIFESTTOTALPIECE, MANIFESTTOTALWEIGHT, PRODUCTNAME, SPECIALGOODSCODE, CUSTOMSCODE,
  30 + CUSTOMSSTATUS, ISBATCH, PALLET, REPORTORDER, ISLAST, ORIGINATINGSTATION_BILL, DESTINATIONSTATION_BILL,
  31 + TOTALPIECE, DEALSTATUS
  32 + </sql>
  33 + <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
  34 + select
  35 + <include refid="Base_Column_List" />
  36 + from FFM_INFO
  37 + where AUTOID = #{autoid,jdbcType=VARCHAR}
  38 + </select>
  39 + <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
  40 + delete from FFM_INFO
  41 + where AUTOID = #{autoid,jdbcType=VARCHAR}
  42 + </delete>
  43 + <insert id="insert" keyColumn="AUTOID" keyProperty="autoid" parameterType="com.tianbo.analysis.model.FFMInfo" useGeneratedKeys="true">
  44 + insert into FFM_INFO (CREATEDATE, FLIGHTNO, FLIGHTDATE,
  45 + WAYBILLNOMASTER, ORIGINATINGSTATION, DESTINATIONSTATION,
  46 + MANIFESTTOTALPIECE, MANIFESTTOTALWEIGHT,
  47 + PRODUCTNAME, SPECIALGOODSCODE, CUSTOMSCODE,
  48 + CUSTOMSSTATUS, ISBATCH, PALLET,
  49 + REPORTORDER, ISLAST, ORIGINATINGSTATION_BILL,
  50 + DESTINATIONSTATION_BILL, TOTALPIECE, DEALSTATUS
  51 + )
  52 + values (#{createdate,jdbcType=TIMESTAMP}, #{flightno,jdbcType=VARCHAR}, #{flightdate,jdbcType=TIMESTAMP},
  53 + #{waybillnomaster,jdbcType=VARCHAR}, #{originatingstation,jdbcType=VARCHAR}, #{destinationstation,jdbcType=VARCHAR},
  54 + #{manifesttotalpiece,jdbcType=VARCHAR}, #{manifesttotalweight,jdbcType=VARCHAR},
  55 + #{productname,jdbcType=VARCHAR}, #{specialgoodscode,jdbcType=VARCHAR}, #{customscode,jdbcType=VARCHAR},
  56 + #{customsstatus,jdbcType=VARCHAR}, #{isbatch,jdbcType=VARCHAR}, #{pallet,jdbcType=VARCHAR},
  57 + #{reportorder,jdbcType=VARCHAR}, #{islast,jdbcType=VARCHAR}, #{originatingstationBill,jdbcType=VARCHAR},
  58 + #{destinationstationBill,jdbcType=VARCHAR}, #{totalpiece,jdbcType=VARCHAR}, #{dealstatus,jdbcType=VARCHAR}
  59 + )
  60 + </insert>
  61 + <insert id="insertSelective" keyColumn="AUTOID" keyProperty="autoid" parameterType="com.tianbo.analysis.model.FFMInfo" useGeneratedKeys="true">
  62 + insert into FFM_INFO
  63 + <trim prefix="(" suffix=")" suffixOverrides=",">
  64 + <if test="autoid != null">
  65 + AUTOID,
  66 + </if>
  67 + <if test="createdate != null">
  68 + CREATEDATE,
  69 + </if>
  70 + <if test="flightno != null">
  71 + FLIGHTNO,
  72 + </if>
  73 + <if test="flightdate != null">
  74 + FLIGHTDATE,
  75 + </if>
  76 + <if test="waybillnomaster != null">
  77 + WAYBILLNOMASTER,
  78 + </if>
  79 + <if test="originatingstation != null">
  80 + ORIGINATINGSTATION,
  81 + </if>
  82 + <if test="destinationstation != null">
  83 + DESTINATIONSTATION,
  84 + </if>
  85 + <if test="manifesttotalpiece != null">
  86 + MANIFESTTOTALPIECE,
  87 + </if>
  88 + <if test="manifesttotalweight != null">
  89 + MANIFESTTOTALWEIGHT,
  90 + </if>
  91 + <if test="productname != null">
  92 + PRODUCTNAME,
  93 + </if>
  94 + <if test="specialgoodscode != null">
  95 + SPECIALGOODSCODE,
  96 + </if>
  97 + <if test="customscode != null">
  98 + CUSTOMSCODE,
  99 + </if>
  100 + <if test="customsstatus != null">
  101 + CUSTOMSSTATUS,
  102 + </if>
  103 + <if test="isbatch != null">
  104 + ISBATCH,
  105 + </if>
  106 + <if test="pallet != null">
  107 + PALLET,
  108 + </if>
  109 + <if test="reportorder != null">
  110 + REPORTORDER,
  111 + </if>
  112 + <if test="islast != null">
  113 + ISLAST,
  114 + </if>
  115 + <if test="originatingstationBill != null">
  116 + ORIGINATINGSTATION_BILL,
  117 + </if>
  118 + <if test="destinationstationBill != null">
  119 + DESTINATIONSTATION_BILL,
  120 + </if>
  121 + <if test="totalpiece != null">
  122 + TOTALPIECE,
  123 + </if>
  124 + <if test="dealstatus != null">
  125 + DEALSTATUS,
  126 + </if>
  127 + </trim>
  128 + <trim prefix="values (" suffix=")" suffixOverrides=",">
  129 + <if test="autoid != null">
  130 + #{autoid,jdbcType=VARCHAR},
  131 + </if>
  132 + <if test="createdate != null">
  133 + #{createdate,jdbcType=TIMESTAMP},
  134 + </if>
  135 + <if test="flightno != null">
  136 + #{flightno,jdbcType=VARCHAR},
  137 + </if>
  138 + <if test="flightdate != null">
  139 + #{flightdate,jdbcType=TIMESTAMP},
  140 + </if>
  141 + <if test="waybillnomaster != null">
  142 + #{waybillnomaster,jdbcType=VARCHAR},
  143 + </if>
  144 + <if test="originatingstation != null">
  145 + #{originatingstation,jdbcType=VARCHAR},
  146 + </if>
  147 + <if test="destinationstation != null">
  148 + #{destinationstation,jdbcType=VARCHAR},
  149 + </if>
  150 + <if test="manifesttotalpiece != null">
  151 + #{manifesttotalpiece,jdbcType=VARCHAR},
  152 + </if>
  153 + <if test="manifesttotalweight != null">
  154 + #{manifesttotalweight,jdbcType=VARCHAR},
  155 + </if>
  156 + <if test="productname != null">
  157 + #{productname,jdbcType=VARCHAR},
  158 + </if>
  159 + <if test="specialgoodscode != null">
  160 + #{specialgoodscode,jdbcType=VARCHAR},
  161 + </if>
  162 + <if test="customscode != null">
  163 + #{customscode,jdbcType=VARCHAR},
  164 + </if>
  165 + <if test="customsstatus != null">
  166 + #{customsstatus,jdbcType=VARCHAR},
  167 + </if>
  168 + <if test="isbatch != null">
  169 + #{isbatch,jdbcType=VARCHAR},
  170 + </if>
  171 + <if test="pallet != null">
  172 + #{pallet,jdbcType=VARCHAR},
  173 + </if>
  174 + <if test="reportorder != null">
  175 + #{reportorder,jdbcType=VARCHAR},
  176 + </if>
  177 + <if test="islast != null">
  178 + #{islast,jdbcType=VARCHAR},
  179 + </if>
  180 + <if test="originatingstationBill != null">
  181 + #{originatingstationBill,jdbcType=VARCHAR},
  182 + </if>
  183 + <if test="destinationstationBill != null">
  184 + #{destinationstationBill,jdbcType=VARCHAR},
  185 + </if>
  186 + <if test="totalpiece != null">
  187 + #{totalpiece,jdbcType=VARCHAR},
  188 + </if>
  189 + <if test="dealstatus != null">
  190 + #{dealstatus,jdbcType=VARCHAR},
  191 + </if>
  192 + </trim>
  193 + </insert>
  194 + <update id="updateByPrimaryKeySelective" parameterType="com.tianbo.analysis.model.FFMInfo">
  195 + update FFM_INFO
  196 + <set>
  197 + <if test="createdate != null">
  198 + CREATEDATE = #{createdate,jdbcType=TIMESTAMP},
  199 + </if>
  200 + <if test="flightno != null">
  201 + FLIGHTNO = #{flightno,jdbcType=VARCHAR},
  202 + </if>
  203 + <if test="flightdate != null">
  204 + FLIGHTDATE = #{flightdate,jdbcType=TIMESTAMP},
  205 + </if>
  206 + <if test="waybillnomaster != null">
  207 + WAYBILLNOMASTER = #{waybillnomaster,jdbcType=VARCHAR},
  208 + </if>
  209 + <if test="originatingstation != null">
  210 + ORIGINATINGSTATION = #{originatingstation,jdbcType=VARCHAR},
  211 + </if>
  212 + <if test="destinationstation != null">
  213 + DESTINATIONSTATION = #{destinationstation,jdbcType=VARCHAR},
  214 + </if>
  215 + <if test="manifesttotalpiece != null">
  216 + MANIFESTTOTALPIECE = #{manifesttotalpiece,jdbcType=VARCHAR},
  217 + </if>
  218 + <if test="manifesttotalweight != null">
  219 + MANIFESTTOTALWEIGHT = #{manifesttotalweight,jdbcType=VARCHAR},
  220 + </if>
  221 + <if test="productname != null">
  222 + PRODUCTNAME = #{productname,jdbcType=VARCHAR},
  223 + </if>
  224 + <if test="specialgoodscode != null">
  225 + SPECIALGOODSCODE = #{specialgoodscode,jdbcType=VARCHAR},
  226 + </if>
  227 + <if test="customscode != null">
  228 + CUSTOMSCODE = #{customscode,jdbcType=VARCHAR},
  229 + </if>
  230 + <if test="customsstatus != null">
  231 + CUSTOMSSTATUS = #{customsstatus,jdbcType=VARCHAR},
  232 + </if>
  233 + <if test="isbatch != null">
  234 + ISBATCH = #{isbatch,jdbcType=VARCHAR},
  235 + </if>
  236 + <if test="pallet != null">
  237 + PALLET = #{pallet,jdbcType=VARCHAR},
  238 + </if>
  239 + <if test="reportorder != null">
  240 + REPORTORDER = #{reportorder,jdbcType=VARCHAR},
  241 + </if>
  242 + <if test="islast != null">
  243 + ISLAST = #{islast,jdbcType=VARCHAR},
  244 + </if>
  245 + <if test="originatingstationBill != null">
  246 + ORIGINATINGSTATION_BILL = #{originatingstationBill,jdbcType=VARCHAR},
  247 + </if>
  248 + <if test="destinationstationBill != null">
  249 + DESTINATIONSTATION_BILL = #{destinationstationBill,jdbcType=VARCHAR},
  250 + </if>
  251 + <if test="totalpiece != null">
  252 + TOTALPIECE = #{totalpiece,jdbcType=VARCHAR},
  253 + </if>
  254 + <if test="dealstatus != null">
  255 + DEALSTATUS = #{dealstatus,jdbcType=VARCHAR},
  256 + </if>
  257 + </set>
  258 + where AUTOID = #{autoid,jdbcType=VARCHAR}
  259 + </update>
  260 + <update id="updateByPrimaryKey" parameterType="com.tianbo.analysis.model.FFMInfo">
  261 + update FFM_INFO
  262 + set CREATEDATE = #{createdate,jdbcType=TIMESTAMP},
  263 + FLIGHTNO = #{flightno,jdbcType=VARCHAR},
  264 + FLIGHTDATE = #{flightdate,jdbcType=TIMESTAMP},
  265 + WAYBILLNOMASTER = #{waybillnomaster,jdbcType=VARCHAR},
  266 + ORIGINATINGSTATION = #{originatingstation,jdbcType=VARCHAR},
  267 + DESTINATIONSTATION = #{destinationstation,jdbcType=VARCHAR},
  268 + MANIFESTTOTALPIECE = #{manifesttotalpiece,jdbcType=VARCHAR},
  269 + MANIFESTTOTALWEIGHT = #{manifesttotalweight,jdbcType=VARCHAR},
  270 + PRODUCTNAME = #{productname,jdbcType=VARCHAR},
  271 + SPECIALGOODSCODE = #{specialgoodscode,jdbcType=VARCHAR},
  272 + CUSTOMSCODE = #{customscode,jdbcType=VARCHAR},
  273 + CUSTOMSSTATUS = #{customsstatus,jdbcType=VARCHAR},
  274 + ISBATCH = #{isbatch,jdbcType=VARCHAR},
  275 + PALLET = #{pallet,jdbcType=VARCHAR},
  276 + REPORTORDER = #{reportorder,jdbcType=VARCHAR},
  277 + ISLAST = #{islast,jdbcType=VARCHAR},
  278 + ORIGINATINGSTATION_BILL = #{originatingstationBill,jdbcType=VARCHAR},
  279 + DESTINATIONSTATION_BILL = #{destinationstationBill,jdbcType=VARCHAR},
  280 + TOTALPIECE = #{totalpiece,jdbcType=VARCHAR},
  281 + DEALSTATUS = #{dealstatus,jdbcType=VARCHAR}
  282 + where AUTOID = #{autoid,jdbcType=VARCHAR}
  283 + </update>
  284 +</mapper>
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3 +<mapper namespace="com.tianbo.analysis.dao.TBBaseAirportInfoDao">
  4 + <resultMap id="BaseResultMap" type="com.tianbo.analysis.model.TBBaseAirportInfo">
  5 + <id column="AIRPORTID" jdbcType="VARCHAR" property="airportid" />
  6 + <result column="INTERNAL" jdbcType="VARCHAR" property="internal" />
  7 + <result column="CITYID" jdbcType="VARCHAR" property="cityid" />
  8 + <result column="AIRPORTDESCCHN" jdbcType="VARCHAR" property="airportdescchn" />
  9 + <result column="AIRPORTDESCENG" jdbcType="VARCHAR" property="airportdesceng" />
  10 + </resultMap>
  11 + <sql id="Base_Column_List">
  12 + AIRPORTID, INTERNAL, CITYID, AIRPORTDESCCHN, AIRPORTDESCENG
  13 + </sql>
  14 + <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
  15 + select
  16 + <include refid="Base_Column_List" />
  17 + from TB_BASE_AIRPORT_INFO
  18 + where AIRPORTID = #{airportid,jdbcType=VARCHAR}
  19 + </select>
  20 + <select id="checkInternal" resultMap="BaseResultMap">
  21 + select internal
  22 + from tb_base_airport_info
  23 + where airportid = #{airportidOrg,jdbcType=VARCHAR}
  24 + union all
  25 + select internal
  26 + from tb_base_airport_info
  27 + where airportid = #{airportidDes,jdbcType=VARCHAR}
  28 + </select>
  29 + <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
  30 + delete from TB_BASE_AIRPORT_INFO
  31 + where AIRPORTID = #{airportid,jdbcType=VARCHAR}
  32 + </delete>
  33 + <insert id="insert" keyColumn="AIRPORTID" keyProperty="airportid" parameterType="com.tianbo.analysis.model.TBBaseAirportInfo" useGeneratedKeys="true">
  34 + insert into TB_BASE_AIRPORT_INFO (INTERNAL, CITYID, AIRPORTDESCCHN,
  35 + AIRPORTDESCENG)
  36 + values (#{internal,jdbcType=VARCHAR}, #{cityid,jdbcType=VARCHAR}, #{airportdescchn,jdbcType=VARCHAR},
  37 + #{airportdesceng,jdbcType=VARCHAR})
  38 + </insert>
  39 + <insert id="insertSelective" keyColumn="AIRPORTID" keyProperty="airportid" parameterType="com.tianbo.analysis.model.TBBaseAirportInfo" useGeneratedKeys="true">
  40 + insert into TB_BASE_AIRPORT_INFO
  41 + <trim prefix="(" suffix=")" suffixOverrides=",">
  42 + <if test="internal != null">
  43 + INTERNAL,
  44 + </if>
  45 + <if test="cityid != null">
  46 + CITYID,
  47 + </if>
  48 + <if test="airportdescchn != null">
  49 + AIRPORTDESCCHN,
  50 + </if>
  51 + <if test="airportdesceng != null">
  52 + AIRPORTDESCENG,
  53 + </if>
  54 + </trim>
  55 + <trim prefix="values (" suffix=")" suffixOverrides=",">
  56 + <if test="internal != null">
  57 + #{internal,jdbcType=VARCHAR},
  58 + </if>
  59 + <if test="cityid != null">
  60 + #{cityid,jdbcType=VARCHAR},
  61 + </if>
  62 + <if test="airportdescchn != null">
  63 + #{airportdescchn,jdbcType=VARCHAR},
  64 + </if>
  65 + <if test="airportdesceng != null">
  66 + #{airportdesceng,jdbcType=VARCHAR},
  67 + </if>
  68 + </trim>
  69 + </insert>
  70 + <update id="updateByPrimaryKeySelective" parameterType="com.tianbo.analysis.model.TBBaseAirportInfo">
  71 + update TB_BASE_AIRPORT_INFO
  72 + <set>
  73 + <if test="internal != null">
  74 + INTERNAL = #{internal,jdbcType=VARCHAR},
  75 + </if>
  76 + <if test="cityid != null">
  77 + CITYID = #{cityid,jdbcType=VARCHAR},
  78 + </if>
  79 + <if test="airportdescchn != null">
  80 + AIRPORTDESCCHN = #{airportdescchn,jdbcType=VARCHAR},
  81 + </if>
  82 + <if test="airportdesceng != null">
  83 + AIRPORTDESCENG = #{airportdesceng,jdbcType=VARCHAR},
  84 + </if>
  85 + </set>
  86 + where AIRPORTID = #{airportid,jdbcType=VARCHAR}
  87 + </update>
  88 + <update id="updateByPrimaryKey" parameterType="com.tianbo.analysis.model.TBBaseAirportInfo">
  89 + update TB_BASE_AIRPORT_INFO
  90 + set INTERNAL = #{internal,jdbcType=VARCHAR},
  91 + CITYID = #{cityid,jdbcType=VARCHAR},
  92 + AIRPORTDESCCHN = #{airportdescchn,jdbcType=VARCHAR},
  93 + AIRPORTDESCENG = #{airportdesceng,jdbcType=VARCHAR}
  94 + where AIRPORTID = #{airportid,jdbcType=VARCHAR}
  95 + </update>
  96 +</mapper>
  1 +
  2 +import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;
  3 +import com.tianbo.analysis.NmmsAdminApplication;
  4 +import com.tianbo.analysis.exception.FFMResolveException;
  5 +import com.tianbo.util.Date.DateUtil;
  6 +import lombok.extern.slf4j.Slf4j;
  7 +import org.junit.platform.commons.util.StringUtils;
  8 +import org.springframework.boot.test.context.SpringBootTest;
  9 +
  10 +import javax.validation.constraints.NotNull;
  11 +import java.io.BufferedReader;
  12 +import java.io.IOException;
  13 +import java.io.StringReader;
  14 +import java.text.ParseException;
  15 +import java.text.SimpleDateFormat;
  16 +import java.util.*;
  17 +import java.util.regex.Matcher;
  18 +import java.util.regex.Pattern;
  19 +
  20 +@SpringBootTest(classes = NmmsAdminApplication.class)
  21 +@Slf4j
  22 +public class FFMTest {
  23 + private String ffm = "ZCZC\n" +
  24 + "QD SELKTCR SELKTCR ICNKO5X \n" +
  25 + ".CGOFD1E 101732\n" +
  26 + "FFM/5 \n" +
  27 + "5/5X173/10SEP/CGO/N328UP \n" +
  28 + "ICN/13SEP2249/13SEP0712 \n" +
  29 + "406-66666666CGOICN/T1K1MC0.01/CONSOLIDATED/EXP \n" +
  30 + "ULD/AAY569135X \n" +
  31 + "406-91567416CGOICN/T1K1MC0.01/CONSOLIDATED/EXP \n" +
  32 + "ULD/AAZ298885X \n" +
  33 + "406-77806864CGOONT/T34K286MC2.12/CONSOLIDATED \n" +
  34 + "406-77806890CGOONT/T1K1MC0.01/CONSOLIDATED \n" +
  35 + "406-77807472CGOONT/T11K125MC0.99/CONSOLIDATED \n" +
  36 + "406-81801020CGOONT/T45K17MC0.14/CONSOLIDATED \n" +
  37 + "406-81804962CGOONT/T1K11.8MC0.08/CONSOLIDATED \n" +
  38 + "406-87761446CGOONT/T2K73.5MC0.42/CONSOLIDATED \n" +
  39 + "406-87762021CGOONT/T1K11.3MC0.03/CONSOLIDATED \n" +
  40 + "406-87762824CGOONT/T1K9MC0.07/CONSOLIDATED \n" +
  41 + "406-92753124CGOONT/S10K145.7MC0.94T33/CONSOLIDATED \n" +
  42 + "406-92753275CGOONT/T1K1MC0.01/CONSOLIDATED \n" +
  43 + "ULD/AMJ522515X \n" +
  44 + "406-91567383CGOSDF/S180K2635.5MC2.31T309/CONSOLIDATED/EXP \n" +
  45 + "ULD/AMJ586525X \n" +
  46 + "406-77804355CGOSDF/T9K202MC0.86/CONSOLIDATED \n" +
  47 + "406-77806341CGOSDF/T2K25MC0.17/CONSOLIDATED \n" +
  48 + "406-77807100CGOSDF/T2K3MC0.01/CONSOLIDATED \n" +
  49 + "406-81376315CGOSDF/T12K176.5MC0.90/CONSOLIDATED \n" +
  50 + "406-81804951CGOSDF/T6K98.3MC0.45/CONSOLIDATED \n" +
  51 + "406-87762732CGOSDF/T1K2.5MC0.08/CONSOLIDATED \n" +
  52 + "PVG/12SEP0250 \n" +
  53 + "ULD/AMJ609925X \n" +
  54 + "406-77806842CGOSDF/T3K18MC0.03/CONSOLIDATED \n" +
  55 + "406-77806853CGOSDF/T6K17MC0.06/CONSOLIDATED \n" +
  56 + "406-77806960CGOSDF/T1K4MC0.02/CONSOLIDATED \n" +
  57 + "406-77807133CGOSDF/T3K45MC0.28/CONSOLIDATED \n" +
  58 + "406-77807273CGOSDF/T3K13MC0.18/CONSOLIDATED \n" +
  59 + "406-77807516CGOSDF/T8K13MC0.19/CONSOLIDATED \n" +
  60 + "406-91567383CGOSDF/S129K1568MC1.65T309/CONSOLIDATED/EXP \n" +
  61 + "406-92753161CGOSDF/T47K850MC4.51/CONSOLIDATED \n" +
  62 + "ULD/AMP652205X \n" +
  63 + "406-77806923CGOONT/T4K36MC0.12/CONSOLIDATED \n" +
  64 + "406-77806971CGOICN/T8K92MC1.16/CONSOLIDATED/ELI \n" +
  65 + "CONT \n" +
  66 + "\n" +
  67 + "=\n" +
  68 + "NNNN";
  69 + private String flightNo;
  70 + private Date flightDate;
  71 + private String order;
  72 + private String originStation;
  73 + private String destinationStation="UNKONW";
  74 + private String planeNo;
  75 + private int currentLine = 0;
  76 + private static final String KEY_WORD_3 = "FFM,ULD,OSI,COR,OCI,DEG,DIM";
  77 + private static final String KEY_WORD_4 = "CONT,LAST";
  78 + private List<String> lineList = new ArrayList<>();
  79 +
  80 +
  81 +
  82 + @org.junit.jupiter.api.Test
  83 + public void send(){
  84 + try{
  85 +
  86 + if (StringUtils.isNotBlank(ffm)){
  87 + /**
  88 + * 检查报文是否包含尾部标识
  89 + */
  90 +
  91 + if(ffm.contains("CONT")|| ffm.contains("LAST")){
  92 + BufferedReader reader = new BufferedReader(new StringReader(ffm));
  93 + for ( String lineStr = reader.readLine();
  94 + lineStr != null;
  95 + lineStr = reader.readLine()){
  96 +// log.info("已读取行{}-{}",i,lineStr);
  97 + lineList.add(lineStr);
  98 + }
  99 + }else {
  100 + throw new FFMResolveException("报文尾部缺少文件结束标识LAST或者CONT");
  101 + }
  102 +
  103 +
  104 + resolve();
  105 + }
  106 + }catch (IOException ignored){
  107 + log.error(ignored.toString());
  108 + ignored.printStackTrace();
  109 + }catch (FFMResolveException ex){
  110 + log.error(ex.toString());
  111 + ex.printStackTrace();
  112 + }catch (ParseException e){
  113 + log.error("航班日期解析错误");
  114 + }
  115 + }
  116 +
  117 + /**
  118 + * 寻找FFM节点并解析航班信息以及航班第一目的站信息
  119 + * 找到FFM节点后,开始根据currentLine的值逐步一行一行解析
  120 + */
  121 + public void resolve() throws FFMResolveException,ParseException{
  122 + if (!lineList.isEmpty()){
  123 + int keyword_i = 0;
  124 + for (int i = 0; i < lineList.size(); i++) {
  125 + //根据行关键字走相应的解析逻辑
  126 + String line = lineList.get(i);
  127 + log.info("1.开始处理行[{}]-[{}]",i,line);
  128 + String keyword = keyword(line);
  129 + if (!"NOT_KEYWORD".equals(keyword)){
  130 + log.info("2.行[{}]包含关键字,开始处理",i);
  131 + if ("FFM".equals(keyword)){
  132 + currentLine = i;
  133 + //ffm版本
  134 + String ver = line.split("/")[1];
  135 + log.info("报文版本{}",ver.trim());
  136 +
  137 + //处理航班信息
  138 + currentLine++;
  139 + flight(lineList.get(currentLine).trim());
  140 +
  141 + /**
  142 + * 取第一目的站
  143 + * 这里注意,有的错误报文的航班节点后面没带或者忘了带目的站节点,
  144 + * 所以这里需要加个校验
  145 + */
  146 + currentLine++;
  147 + destination(lineList.get(currentLine).trim());
  148 + currentLine++;
  149 + }else if ("CONT".equals(keyword) || "LAST".equals(keyword) ){
  150 + keyword_i++;
  151 + }
  152 +
  153 + }
  154 + }
  155 + if (keyword_i==0){
  156 + throw new FFMResolveException("报文尾部缺少文件结束标识LAST或者CONT");
  157 + }
  158 + resolve_ULD_Waybill();
  159 + }
  160 +
  161 + }
  162 +
  163 + /**
  164 + * 判断是否有散舱
  165 + * 有BUP散舱先处理散舱,没有则进入ULD及ULD货物解析阶段
  166 + * 假设默认航班有散舱,将散舱的ULD号默认为 "BUP"
  167 + * 设置当前的ULD 为 散舱ULD "BUP"
  168 + * 那么散舱下的运单直到解析到真正的板箱号后,uld变成真正的货物板箱
  169 + */
  170 + public void resolve_ULD_Waybill() throws FFMResolveException{
  171 + log.info("5. 开始解析舱单列表");
  172 + String uld = "BUP";
  173 + for (int i = currentLine; i < lineList.size(); i++) {
  174 + String line = lineList.get(i);
  175 + log.info("5.1 开始解析行[{}]-[{}]",i,line);
  176 +
  177 + //行尾部结束标识检查
  178 + String keyword = keyword(line);
  179 + if ("CONT".equals(keyword) || "LAST".equals(keyword)){
  180 + log.info("[END] 已解析到文件结束标识[{}],解析完毕",keyword);
  181 + break;
  182 + }
  183 +
  184 + /**
  185 + * 多航班目的站解析
  186 + */
  187 + //校验正则1,取前三位验证是否是机场代码
  188 + String pattern_f = "^[A-Z]{3}$|^[A-Z]{3}/\\d{2}[A-Z]{3}\\d{4}";
  189 + // 创建 Pattern 对象
  190 + Pattern r_f = Pattern.compile(pattern_f);
  191 + // 现在创建 matcher 对象
  192 + Matcher mF = r_f.matcher(line);
  193 + if (mF.find()){
  194 + log.info("5-[FLIGHT] 适配到航班其他目的站");
  195 + String flightDes = line.substring(0,3);
  196 + if (!KEY_WORD_3.contains(flightDes)){
  197 + destinationStation = flightDes;
  198 + log.info("5-[FLIGHT] 新航班目的站为[{}]",destinationStation);
  199 + }
  200 + }
  201 + if ("UNKONW".equals(destinationStation)){
  202 + throw new FFMResolveException("航班目的站节点校验不通过.");
  203 + }
  204 +
  205 + if ("ULD".equals(keyword)){
  206 + log.info("5-[ULD] 此行为ULD信息行");
  207 + //板箱格式适配
  208 + String patternULD = "^ULD/([A-Z]{3}\\S{5}\\S{2})";
  209 + Pattern rULD = Pattern.compile(patternULD);
  210 + // 现在创建 matcher 对象
  211 + Matcher mULD = rULD.matcher(line);
  212 + if (mULD.find()){
  213 + log.info("5-[ULD] 查到分组{}",mULD.groupCount());
  214 +// for (int j1 = 1; j1 < mULD.groupCount()+1; j1++) {
  215 +// log.info("5-[ULD] 分组{}内容为:{}",j1,mULD.group(j1));
  216 +// }
  217 + uld= mULD.group(1);
  218 + log.info("5-[ULD] 当前ULD已变更为{}",uld);
  219 +
  220 + }else {
  221 + throw new FFMResolveException("ULD节点格式错误,无法适配正则(^ULD/([A-Z]{3})(\\S{5})(\\S{2})");
  222 + }
  223 + }
  224 +
  225 + //运单格式适配
  226 + String pattern = "^(\\d{3}-\\d{8})([A-Z]{3})([A-Z]{3})/(T|P|S|M)(\\d+)(K)([0-9\\.]+)(MC)?([0-9\\.]+)?(T)?([0-9]+)?/(\\S+)";
  227 + // 创建 Pattern 对象
  228 + Pattern r = Pattern.compile(pattern);
  229 + // 现在创建 matcher 对象
  230 + Matcher m = r.matcher(line);
  231 + if(m.find()){
  232 + log.info("5-[AWB] 行[{}]属于运单行,开始解析,当前板箱号为:{}",i,uld);
  233 + log.info("5-[AWB] 查到分组{}",m.groupCount());
  234 + String waybillNo = m.group(1);
  235 + String waybillOrigin = m.group(2);
  236 + String waybillDes = m.group(3);
  237 + String waybillSplit = m.group(4);
  238 + String waybillPiece = m.group(5);
  239 + String waybillWeight = m.group(7);
  240 + String waybillVolume = m.group(9);
  241 + String waybillTotalPiece = m.group(11);
  242 + String waybillGoodsDes = m.group(12);
  243 +
  244 +// for (int j = 1; j < m.groupCount()+1; j++) {
  245 +// log.info("5-[AWB] 分组{}内容为:{}",j,m.group(j));
  246 +// }
  247 +
  248 + if(model7Check(waybillNo)){
  249 + log.info("5-[AWB] 运单-({})模七校验通过",waybillNo);
  250 + }else {
  251 + log.error("{}运单模七校验不通过",waybillNo);
  252 + throw new FFMResolveException(waybillNo+"运单模七校验不通过");
  253 + }
  254 +
  255 + log.info("5-[AWB-INFO] 运单信息:报文序号:{} 所属航班:{}/{} 航班起始站/目的站:{}/{} 所属板箱:{} 运单号:{} 起始站/目的站:{}/{} 分批标识:{} 分批件重:{}/{} 体积:{} 总件数:{} 货物描述:{}",
  256 + order,
  257 + flightNo,
  258 + flightDate,
  259 + originStation,
  260 + destinationStation,
  261 + uld,
  262 + waybillNo,
  263 + waybillOrigin,
  264 + waybillDes,
  265 + waybillSplit,
  266 + waybillPiece,
  267 + waybillWeight,
  268 + waybillVolume,
  269 + waybillTotalPiece,
  270 + waybillGoodsDes);
  271 + }
  272 + }
  273 +
  274 + }
  275 +
  276 + /**
  277 + * 关键字识别
  278 + * @param text 每行的内容
  279 + * @return 识别为关键字的返回关键字,未被识别为关键字的返回NOT_KEYWORD;
  280 + * 返回的关键字 三字码关键字 机场代码关键字 文件结尾关键字 CONT,LAST
  281 + */
  282 + public String keyword(@NotNull String text){
  283 + //取每行前三位
  284 + if (StringUtils.isNotBlank(text) && text.length()>3){
  285 + String s_3 = text.substring(0,3);
  286 + String s_4 = text.substring(0,4);
  287 + if(KEY_WORD_3.contains(s_3)){
  288 + return s_3;
  289 + }
  290 + if(KEY_WORD_4.contains(s_4)){
  291 + return s_4;
  292 + }
  293 + }else if(text.length()==3){
  294 + log.info("{}很大可能是机场目的站",text);
  295 + }
  296 +
  297 + return "NOT_KEYWORD";
  298 + }
  299 +
  300 + /**
  301 + * 解析航班第一目的站
  302 + *
  303 + */
  304 + public void destination(String text) throws FFMResolveException{
  305 + log.info("4.开始校验处理航班目的站节点信息");
  306 + if (text.length()>=3){
  307 + //校验是否空货机
  308 + String pattern_nil = "[A-Z]{3}/NIL";
  309 + Pattern r_nil = Pattern.compile(pattern_nil);
  310 + // 现在创建 matcher 对象
  311 + Matcher m_nil = r_nil.matcher(text);
  312 + if (m_nil.find()){
  313 + log.info("4.1 航班目的站货物为空");
  314 + throw new FFMResolveException("航班第一目的站货物为空,解析结束");
  315 + }
  316 +
  317 + //校验是否是目的站节点
  318 + //校验正则1,取前三位验证是否是机场代码
  319 + String pattern = "^[A-Z]{3}$|^[A-Z]{3}/\\d{2}[A-Z]{3}\\d{4}";
  320 + // 创建 Pattern 对象
  321 + Pattern r = Pattern.compile(pattern);
  322 + // 现在创建 matcher 对象
  323 + Matcher m = r.matcher(text);
  324 + if (m.find()){
  325 + log.info("4.1 航班目的站节点校验通过");
  326 +
  327 + destinationStation = text.substring(0,3);
  328 + log.info("4.2 航班目的站一为[{}]",destinationStation);
  329 + }else {
  330 + log.error("4.1[ERROR] !!航班目的站节点校验不通过!!");
  331 + throw new FFMResolveException("航班目的站节点校验不通过.");
  332 + }
  333 + }else {
  334 + throw new FFMResolveException("航班目的站节点长度不对.");
  335 + }
  336 +
  337 +
  338 + }
  339 +
  340 +
  341 + public void flight(String text) throws FFMResolveException, ParseException {
  342 + log.info("3.开始处理航班信息");
  343 + String[] flight = text.split("/");
  344 + if (flight.length>3){
  345 + order = flight[0];
  346 + log.info("3.1 报文序号为{}",order);
  347 + flightNo = flight[1];
  348 + log.info("3.2 航班号为[{}]",flightNo);
  349 +
  350 +
  351 + //航班日期取出来的格式为10SEP或者10SEP1022,带时间的注意
  352 + String flightDateStr = flight[2];
  353 + log.info("3.3 航班日期信息为[{}]",flightDate);
  354 + String flightDateDay = flightDateStr.substring(0,2);
  355 + String flightDateMonth = flightDateStr.substring(2,5);
  356 +
  357 +
  358 + /**
  359 + * FFM跨年问题
  360 + * FFM报文中的月份为12月,当前服务器时间月份为1月,视为跨年.
  361 + * 跨年问题需要设置FFM报文的航班年份为当前年份-1
  362 + */
  363 + Calendar cal = Calendar.getInstance();
  364 + //当前年份
  365 + int yearNow = cal.get(Calendar.YEAR);
  366 + int monthNow = cal.get(Calendar.MONTH);
  367 +
  368 + if (monthNow == 1 && "DEC".equals(flightDateMonth)){
  369 + log.info("3.3.1 航班日期跨年");
  370 + yearNow = yearNow-1;
  371 + }
  372 +
  373 + flightDateStr = flightDateStr+yearNow;
  374 + flightDate = DateUtil.dateFormatFlight(flightDateStr);
  375 +
  376 +
  377 + originStation = flight[3];
  378 + log.info("3.4 航班起始站为[{}]",originStation);
  379 + if (flight.length>4){
  380 + planeNo = flight[4];
  381 + log.info("3.4 航班飞机号为[{}]",planeNo);
  382 + }
  383 + }else {
  384 + log.error("航班信息节点不正确");
  385 + throw new FFMResolveException("航班信息节点不正确");
  386 + }
  387 + }
  388 +
  389 +
  390 + /**
  391 + * 模七校验
  392 + * @param waybillNo
  393 + * @return
  394 + */
  395 + public boolean model7Check(String waybillNo){
  396 + String pattern = "\\d{3}-\\d{8}";
  397 + // 创建 Pattern 对象
  398 + Pattern r = Pattern.compile(pattern);
  399 + // 现在创建 matcher 对象
  400 + Matcher m = r.matcher(waybillNo);
  401 + if (m.find()){
  402 + String num = waybillNo.split("-")[1];
  403 + String num_7 = num.substring(0,7);
  404 + String num_end = num.substring(7,8);
  405 + if (Integer.parseInt(num_7)% 7 == Integer.parseInt(num_end)){
  406 + return true;
  407 + }else {
  408 + log.error("{}模七不通过",waybillNo);
  409 + }
  410 +
  411 + }else {
  412 + log.error("{}运单格式不正确",waybillNo);
  413 + }
  414 +
  415 + return false;
  416 + }
  417 +}