作者 朱兆平

解析优化

@@ -24,7 +24,7 @@ public class FHLController { @@ -24,7 +24,7 @@ public class FHLController {
24 public ResultJson resolve(@RequestParam String ffm){ 24 public ResultJson resolve(@RequestParam String ffm){
25 Originmanifestsecondary fhlInfo = new Originmanifestsecondary(); 25 Originmanifestsecondary fhlInfo = new Originmanifestsecondary();
26 fhlInfo.text = ffm; 26 fhlInfo.text = ffm;
27 - boolean result = resolve.resolve(fhlInfo);  
28 - return result? new ResultJson("200","success"):new ResultJson("400","解析失败"); 27 + ResultJson result = resolve.resolve(fhlInfo);
  28 + return result;
29 } 29 }
30 } 30 }
@@ -459,7 +459,7 @@ public class FFMInfo implements Serializable { @@ -459,7 +459,7 @@ public class FFMInfo implements Serializable {
459 459
460 private FFMInfo WayBillParse(String line,String uld) throws FFMResolveException { 460 private FFMInfo WayBillParse(String line,String uld) throws FFMResolveException {
461 //运单格式适配,这里注意空格字符 与连字符"-" 461 //运单格式适配,这里注意空格字符 与连字符"-"
462 - String pattern = "^(\\d{3}-\\d{8})([A-Z]{3})([A-Z]{3})/(T|P|S|M|D)(\\d+)(K)([0-9\\.]+)(MC)?([0-9\\.]+)?(DG)?([0-9\\.]+)?(T)?([0-9]+)?/"; 462 + String pattern = "^(\\d{3}-\\d{8})([A-Z]{3})([A-Z]{3})/(T|P|S|M|D)(\\d+)(K)([0-9\\.]+)(MC)?([0-9\\.]+)?(DG)?([0-9\\.]+)?(T)?([0-9]+)?/.{1,15}";
463 // 创建 Pattern 对象 463 // 创建 Pattern 对象
464 Pattern r = Pattern.compile(pattern); 464 Pattern r = Pattern.compile(pattern);
465 // 现在创建 matcher 对象 465 // 现在创建 matcher 对象
@@ -542,6 +542,9 @@ public class FFMInfo implements Serializable { @@ -542,6 +542,9 @@ public class FFMInfo implements Serializable {
542 waybillTotalPiece, 542 waybillTotalPiece,
543 "0"); 543 "0");
544 } 544 }
  545 +// else {
  546 +// throw new FFMResolveException(line+"-的运单节点格式错误,无法适配正则-"+pattern);
  547 +// }
545 return null; 548 return null;
546 } 549 }
547 550
@@ -593,6 +596,7 @@ public class FFMInfo implements Serializable { @@ -593,6 +596,7 @@ public class FFMInfo implements Serializable {
593 /** 596 /**
594 * 进来这个方法的,处理完毕后行,都不再是运单行 597 * 进来这个方法的,处理完毕后行,都不再是运单行
595 * 解析完毕,缓存重置 598 * 解析完毕,缓存重置
  599 + * todo:这里有BUG
596 */ 600 */
597 601
598 temp.put("ISAWB","no"); 602 temp.put("ISAWB","no");
@@ -976,7 +976,7 @@ public class Originmanifestsecondary { @@ -976,7 +976,7 @@ public class Originmanifestsecondary {
976 * CVD 计费声明节点解析 976 * CVD 计费声明节点解析
977 * @param line 977 * @param line
978 */ 978 */
979 - public void cvdParse(String line){ 979 + public void cvdParse(String line) throws FFMResolveException {
980 String keyword = "^CVD/([A-Z]{3})/([PC]{2})/([0-9\\.]{1,12}|NVD)/(NCV|[0-9\\.]{1,12})/(XXX|[0-9\\.]{1,11})"; 980 String keyword = "^CVD/([A-Z]{3})/([PC]{2})/([0-9\\.]{1,12}|NVD)/(NCV|[0-9\\.]{1,12})/(XXX|[0-9\\.]{1,11})";
981 // 创建 Pattern 对象 981 // 创建 Pattern 对象
982 Pattern r = Pattern.compile(keyword); 982 Pattern r = Pattern.compile(keyword);
@@ -990,6 +990,8 @@ public class Originmanifestsecondary { @@ -990,6 +990,8 @@ public class Originmanifestsecondary {
990 String Declared_Value_for_Insurance = m.group(5); 990 String Declared_Value_for_Insurance = m.group(5);
991 log.info("[CVD]-计费声明:货币代码[{}]-付费模式[{}]-运输申报价值[{}]-海关申报价值[{}]-保险申报价值[{}]", 991 log.info("[CVD]-计费声明:货币代码[{}]-付费模式[{}]-运输申报价值[{}]-海关申报价值[{}]-保险申报价值[{}]",
992 ISO_Currency_Code,paymode,Declared_Value_for_Carriage,Declared_Value_for_Customs,Declared_Value_for_Insurance); 992 ISO_Currency_Code,paymode,Declared_Value_for_Carriage,Declared_Value_for_Customs,Declared_Value_for_Insurance);
  993 + }else{
  994 + throw new FFMResolveException("CVD节点格式校验错误");
993 } 995 }
994 } 996 }
995 997
@@ -2,7 +2,8 @@ package com.tianbo.analysis.service; @@ -2,7 +2,8 @@ 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.Originmanifestsecondary; 4 import com.tianbo.analysis.model.Originmanifestsecondary;
  5 +import com.tianbo.analysis.model.ResultJson;
5 6
6 public interface FHLResolve { 7 public interface FHLResolve {
7 - boolean resolve(Originmanifestsecondary var1); 8 + ResultJson resolve(Originmanifestsecondary var1);
8 } 9 }
@@ -3,6 +3,7 @@ package com.tianbo.analysis.service.imp; @@ -3,6 +3,7 @@ package com.tianbo.analysis.service.imp;
3 import com.tianbo.analysis.dao.OriginmanifestsecondaryMapper; 3 import com.tianbo.analysis.dao.OriginmanifestsecondaryMapper;
4 import com.tianbo.analysis.dao.TBBaseAirportInfoDao; 4 import com.tianbo.analysis.dao.TBBaseAirportInfoDao;
5 import com.tianbo.analysis.model.Originmanifestsecondary; 5 import com.tianbo.analysis.model.Originmanifestsecondary;
  6 +import com.tianbo.analysis.model.ResultJson;
6 import com.tianbo.analysis.service.FHLResolve; 7 import com.tianbo.analysis.service.FHLResolve;
7 import org.springframework.stereotype.Service; 8 import org.springframework.stereotype.Service;
8 9
@@ -18,14 +19,21 @@ public class FHLResolveImpl implements FHLResolve { @@ -18,14 +19,21 @@ public class FHLResolveImpl implements FHLResolve {
18 OriginmanifestsecondaryMapper mapper; 19 OriginmanifestsecondaryMapper mapper;
19 20
20 @Override 21 @Override
21 - public boolean resolve(Originmanifestsecondary fhl) { 22 + public ResultJson resolve(Originmanifestsecondary fhl) {
  23 + ResultJson resultJson = new ResultJson();
22 try{ 24 try{
23 fhl.textToStringList(); 25 fhl.textToStringList();
24 - fhl.startParse(); 26 + if(fhl.startParse()){
  27 + resultJson.setMsg("解析报文成功");
  28 + resultJson.setCode("200");
  29 + }
25 }catch (Exception e){ 30 }catch (Exception e){
26 e.printStackTrace(); 31 e.printStackTrace();
  32 + resultJson.setMsg("解析报文失败");
  33 + resultJson.setCode("400");
  34 + resultJson.setError(e.toString());
27 } 35 }
28 - return false; 36 + return resultJson;
29 } 37 }
30 38
31 39