作者 申海龙

正则工具类 添加回执解析入库 字段

@@ -13,7 +13,7 @@ public interface CUSTOM_RESPONSEMapper { @@ -13,7 +13,7 @@ public interface CUSTOM_RESPONSEMapper {
13 13
14 int updateByPrimaryKeySelective(CUSTOM_RESPONSE record); 14 int updateByPrimaryKeySelective(CUSTOM_RESPONSE record);
15 15
16 - int updateAwbhReceiption(CUSTOM_RESPONSE record); 16 + int updateByPrimaryKeyWithBLOBs(CUSTOM_RESPONSE record);
17 17
18 - int updateAwbReceiption(CUSTOM_RESPONSE record); 18 + int updateByPrimaryKey(CUSTOM_RESPONSE record);
19 } 19 }
@@ -4,6 +4,7 @@ package com.tianbo.analysis.handle; @@ -4,6 +4,7 @@ package com.tianbo.analysis.handle;
4 import com.tianbo.analysis.model.CustomReception; 4 import com.tianbo.analysis.model.CustomReception;
5 import com.tianbo.analysis.service.*; 5 import com.tianbo.analysis.service.*;
6 import com.tianbo.util.XML.XMLXPath; 6 import com.tianbo.util.XML.XMLXPath;
  7 +import org.apache.commons.lang.StringUtils;
7 import org.dom4j.Document; 8 import org.dom4j.Document;
8 import org.dom4j.DocumentException; 9 import org.dom4j.DocumentException;
9 import org.dom4j.Element; 10 import org.dom4j.Element;
@@ -77,14 +78,18 @@ public class CustomXmlHandle{ @@ -77,14 +78,18 @@ public class CustomXmlHandle{
77 //开始解析 78 //开始解析
78 String journeyid = XMLXPath.getSingleValueByPath(document,JourneyID); 79 String journeyid = XMLXPath.getSingleValueByPath(document,JourneyID);
79 80
80 -// if(journeyid != null){  
81 -//  
82 -// String[] flightList = journeyid.split("/");  
83 -// if(flightList.length > 0){  
84 -// flightNo = flightList[0];  
85 -// flightDate = flightList[1];  
86 -// }  
87 -// } 81 + if(!StringUtils.isEmpty(journeyid)){
  82 + if (journeyid.contains("/")){
  83 + String[] flightList = journeyid.split("/");
  84 + if(flightList.length > 0){
  85 + flightNo = flightList[0];
  86 + flightDate = flightList[1];
  87 + }
  88 + }else {
  89 + flightNo = journeyid;
  90 + }
  91 +
  92 + }
88 String functionCode = XMLXPath.getSingleValueByPath(document, FunctionCode); 93 String functionCode = XMLXPath.getSingleValueByPath(document, FunctionCode);
89 94
90 String senderId = XMLXPath.getSingleValueByPath(document, SenderID); 95 String senderId = XMLXPath.getSingleValueByPath(document, SenderID);
@@ -9,6 +9,8 @@ public class CUSTOM_RESPONSE { @@ -9,6 +9,8 @@ public class CUSTOM_RESPONSE {
9 9
10 private String flightno; 10 private String flightno;
11 11
  12 + private String carrier;
  13 +
12 private String awbano; 14 private String awbano;
13 15
14 private String awbhno; 16 private String awbhno;
@@ -71,6 +73,14 @@ public class CUSTOM_RESPONSE { @@ -71,6 +73,14 @@ public class CUSTOM_RESPONSE {
71 this.flightno = flightno == null ? null : flightno.trim(); 73 this.flightno = flightno == null ? null : flightno.trim();
72 } 74 }
73 75
  76 + public String getCarrier() {
  77 + return carrier;
  78 + }
  79 +
  80 + public void setCarrier(String carrier) {
  81 + this.carrier = carrier == null ? null : carrier.trim();
  82 + }
  83 +
74 public String getAwbano() { 84 public String getAwbano() {
75 return awbano; 85 return awbano;
76 } 86 }
@@ -5,13 +5,16 @@ import com.tianbo.analysis.model.CUSTOM_RESPONSE; @@ -5,13 +5,16 @@ import com.tianbo.analysis.model.CUSTOM_RESPONSE;
5 import com.tianbo.analysis.model.CustomReception; 5 import com.tianbo.analysis.model.CustomReception;
6 import com.tianbo.analysis.service.CoustomAnalysisService; 6 import com.tianbo.analysis.service.CoustomAnalysisService;
7 import com.tianbo.util.Date.DateUtil; 7 import com.tianbo.util.Date.DateUtil;
  8 +import com.tianbo.util.regular.RegularUtil;
8 import lombok.extern.slf4j.Slf4j; 9 import lombok.extern.slf4j.Slf4j;
9 import org.apache.commons.lang.StringUtils; 10 import org.apache.commons.lang.StringUtils;
10 import org.springframework.beans.factory.annotation.Autowired; 11 import org.springframework.beans.factory.annotation.Autowired;
11 import org.springframework.stereotype.Service; 12 import org.springframework.stereotype.Service;
12 13
13 import java.text.ParseException; 14 import java.text.ParseException;
  15 +import java.text.SimpleDateFormat;
14 import java.util.Date; 16 import java.util.Date;
  17 +import java.util.TimeZone;
15 import java.util.UUID; 18 import java.util.UUID;
16 19
17 @Service 20 @Service
@@ -26,8 +29,52 @@ public class CoustomAnalysisServiceImp implements CoustomAnalysisService { @@ -26,8 +29,52 @@ public class CoustomAnalysisServiceImp implements CoustomAnalysisService {
26 @Override 29 @Override
27 public int insertRecept(CustomReception cus, String errorCodes, String errorTexts) throws ParseException { 30 public int insertRecept(CustomReception cus, String errorCodes, String errorTexts) throws ParseException {
28 31
  32 + RegularUtil regularUtil = new RegularUtil();
  33 +
29 CUSTOM_RESPONSE custom_response = new CUSTOM_RESPONSE(); 34 CUSTOM_RESPONSE custom_response = new CUSTOM_RESPONSE();
30 custom_response.setId(UUID.randomUUID().toString()); 35 custom_response.setId(UUID.randomUUID().toString());
  36 +
  37 + String awb = "";
  38 + String awbh = "";
  39 + if (cus.getWayBillMaster()!=null && cus.getWayBillMaster().length()>0){
  40 + StringBuffer stringBuffer = new StringBuffer(cus.getWayBillMaster());
  41 + StringBuffer insert = stringBuffer.insert(3, "-");
  42 + String s = insert.toString();
  43 + //设置 主单号
  44 + awb = s;
  45 + }
  46 +
  47 +
  48 + if (cus.getWayBillSecond()!=null && cus.getWayBillSecond().length()>0){
  49 + //取分单号
  50 + String[] awbhArr = cus.getWayBillSecond().split("_");
  51 + awbh = awbhArr[1];
  52 + }
  53 +
  54 +
  55 + // 主单号
  56 + custom_response.setAwbano(awb);
  57 + // 分单号
  58 + custom_response.setAwbhno(awbh);
  59 + // 判断日期是否为空
  60 + String flightDate = cus.getFlightDate();
  61 + if (!StringUtils.isEmpty(flightDate)){
  62 +
  63 + Date date = DateUtil.formatByyyyyMMdd(flightDate);
  64 + // 航班日期
  65 + custom_response.setFlightdate(date);
  66 + }
  67 +
  68 + String flightNo = cus.getFlightNo();
  69 + if (!StringUtils.isEmpty(flightNo)){
  70 +
  71 + // 承运人代码
  72 + custom_response.setCarrier(flightNo.substring(0, 2));
  73 +
  74 + // 航班号
  75 + custom_response.setFlightno(flightNo.substring(2));
  76 + }
  77 +
31 // 报文发送序号 78 // 报文发送序号
32 custom_response.setCusmsgid(cus.getMessageID()); 79 custom_response.setCusmsgid(cus.getMessageID());
33 // 回执发送者id 80 // 回执发送者id
@@ -38,9 +85,18 @@ public class CoustomAnalysisServiceImp implements CoustomAnalysisService { @@ -38,9 +85,18 @@ public class CoustomAnalysisServiceImp implements CoustomAnalysisService {
38 custom_response.setCusversion(cus.getVersion()); 85 custom_response.setCusversion(cus.getVersion());
39 // 对应海关的functioncode业务代码 86 // 对应海关的functioncode业务代码
40 custom_response.setCusfunctioncode(cus.getFunctionCode()); 87 custom_response.setCusfunctioncode(cus.getFunctionCode());
  88 + // 报文类型
  89 + custom_response.setBustype(cus.getMessageType());
  90 +
  91 +
  92 + // 设置时区
  93 +// SimpleDateFormat bjSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  94 +// bjSdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
  95 +// String format = bjSdf.format(new Date());
41 // 回执接受时间 96 // 回执接受时间
42 custom_response.setCusresrcvtime(new Date()); 97 custom_response.setCusresrcvtime(new Date());
43 - 98 + // 业务发生时间
  99 + custom_response.setBusdate(new Date());
44 // 判断日期是否为空 100 // 判断日期是否为空
45 String sendTime = cus.getSendTime(); 101 String sendTime = cus.getSendTime();
46 if (!StringUtils.isEmpty(sendTime)){ 102 if (!StringUtils.isEmpty(sendTime)){
@@ -57,8 +113,8 @@ public class CoustomAnalysisServiceImp implements CoustomAnalysisService { @@ -57,8 +113,8 @@ public class CoustomAnalysisServiceImp implements CoustomAnalysisService {
57 // 判断是否为空 113 // 判断是否为空
58 if (responseText != null && responseCode != null){ 114 if (responseText != null && responseCode != null){
59 // 回执状态 115 // 回执状态
60 - String substring = responseText.substring(0, 5);  
61 - custom_response.setCusresstatus(substring); 116 + String cusText = regularUtil.cusText(responseText);
  117 + custom_response.setCusresstatus(cusText);
62 // 回执Code代码 118 // 回执Code代码
63 custom_response.setCusrescode(responseCode); 119 custom_response.setCusrescode(responseCode);
64 // 回执内容 120 // 回执内容
@@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
5 <id column="id" property="id" jdbcType="VARCHAR" /> 5 <id column="id" property="id" jdbcType="VARCHAR" />
6 <result column="flightDate" property="flightdate" jdbcType="DATE" /> 6 <result column="flightDate" property="flightdate" jdbcType="DATE" />
7 <result column="flightNo" property="flightno" jdbcType="VARCHAR" /> 7 <result column="flightNo" property="flightno" jdbcType="VARCHAR" />
  8 + <result column="carrier" property="carrier" jdbcType="VARCHAR" />
8 <result column="awbaNo" property="awbano" jdbcType="VARCHAR" /> 9 <result column="awbaNo" property="awbano" jdbcType="VARCHAR" />
9 <result column="awbhNo" property="awbhno" jdbcType="VARCHAR" /> 10 <result column="awbhNo" property="awbhno" jdbcType="VARCHAR" />
10 <result column="busType" property="bustype" jdbcType="VARCHAR" /> 11 <result column="busType" property="bustype" jdbcType="VARCHAR" />
@@ -28,7 +29,7 @@ @@ -28,7 +29,7 @@
28 <result column="cusResText" property="cusrestext" jdbcType="LONGVARCHAR" /> 29 <result column="cusResText" property="cusrestext" jdbcType="LONGVARCHAR" />
29 </resultMap> 30 </resultMap>
30 <sql id="Base_Column_List" > 31 <sql id="Base_Column_List" >
31 - id, flightDate, flightNo, awbaNo, awbhNo, busType, busDate, busWeight, busPiece, 32 + id, flightDate, flightNo, carrier, awbaNo, awbhNo, busType, busDate, busWeight, busPiece,
32 operType, cusMsgId, cusSenderId, cusReciverId, cusVersion, cusFunctionCode, cusResRcvTime, 33 operType, cusMsgId, cusSenderId, cusReciverId, cusVersion, cusFunctionCode, cusResRcvTime,
33 cusResSendTime, cusResCode, cusResStatus, operUserName, operSystemName 34 cusResSendTime, cusResCode, cusResStatus, operUserName, operSystemName
34 </sql> 35 </sql>
@@ -49,21 +50,21 @@ @@ -49,21 +50,21 @@
49 </delete> 50 </delete>
50 <insert id="insert" parameterType="com.tianbo.analysis.model.CUSTOM_RESPONSE" > 51 <insert id="insert" parameterType="com.tianbo.analysis.model.CUSTOM_RESPONSE" >
51 insert into CUSTOM_RESPONSE (id, flightDate, flightNo, 52 insert into CUSTOM_RESPONSE (id, flightDate, flightNo,
52 - awbaNo, awbhNo, busType,  
53 - busDate, busWeight, busPiece,  
54 - operType, cusMsgId, cusSenderId,  
55 - cusReciverId, cusVersion, cusFunctionCode,  
56 - cusResRcvTime, cusResSendTime, cusResCode,  
57 - cusResStatus, operUserName, operSystemName,  
58 - cusResText) 53 + carrier, awbaNo, awbhNo,
  54 + busType, busDate, busWeight,
  55 + busPiece, operType, cusMsgId,
  56 + cusSenderId, cusReciverId, cusVersion,
  57 + cusFunctionCode, cusResRcvTime, cusResSendTime,
  58 + cusResCode, cusResStatus, operUserName,
  59 + operSystemName, cusResText)
59 values (#{id,jdbcType=VARCHAR}, #{flightdate,jdbcType=DATE}, #{flightno,jdbcType=VARCHAR}, 60 values (#{id,jdbcType=VARCHAR}, #{flightdate,jdbcType=DATE}, #{flightno,jdbcType=VARCHAR},
60 - #{awbano,jdbcType=VARCHAR}, #{awbhno,jdbcType=VARCHAR}, #{bustype,jdbcType=VARCHAR},  
61 - #{busdate,jdbcType=TIMESTAMP}, #{busweight,jdbcType=DECIMAL}, #{buspiece,jdbcType=INTEGER},  
62 - #{opertype,jdbcType=VARCHAR}, #{cusmsgid,jdbcType=VARCHAR}, #{cussenderid,jdbcType=VARCHAR},  
63 - #{cusreciverid,jdbcType=VARCHAR}, #{cusversion,jdbcType=VARCHAR}, #{cusfunctioncode,jdbcType=VARCHAR},  
64 - #{cusresrcvtime,jdbcType=TIMESTAMP}, #{cusressendtime,jdbcType=TIMESTAMP}, #{cusrescode,jdbcType=VARCHAR},  
65 - #{cusresstatus,jdbcType=VARCHAR}, #{operusername,jdbcType=VARCHAR}, #{opersystemname,jdbcType=VARCHAR},  
66 - #{cusrestext,jdbcType=LONGVARCHAR}) 61 + #{carrier,jdbcType=VARCHAR}, #{awbano,jdbcType=VARCHAR}, #{awbhno,jdbcType=VARCHAR},
  62 + #{bustype,jdbcType=VARCHAR}, #{busdate,jdbcType=TIMESTAMP}, #{busweight,jdbcType=DECIMAL},
  63 + #{buspiece,jdbcType=INTEGER}, #{opertype,jdbcType=VARCHAR}, #{cusmsgid,jdbcType=VARCHAR},
  64 + #{cussenderid,jdbcType=VARCHAR}, #{cusreciverid,jdbcType=VARCHAR}, #{cusversion,jdbcType=VARCHAR},
  65 + #{cusfunctioncode,jdbcType=VARCHAR}, #{cusresrcvtime,jdbcType=TIMESTAMP}, #{cusressendtime,jdbcType=TIMESTAMP},
  66 + #{cusrescode,jdbcType=VARCHAR}, #{cusresstatus,jdbcType=VARCHAR}, #{operusername,jdbcType=VARCHAR},
  67 + #{opersystemname,jdbcType=VARCHAR}, #{cusrestext,jdbcType=LONGVARCHAR})
67 </insert> 68 </insert>
68 <insert id="insertSelective" parameterType="com.tianbo.analysis.model.CUSTOM_RESPONSE" > 69 <insert id="insertSelective" parameterType="com.tianbo.analysis.model.CUSTOM_RESPONSE" >
69 insert into CUSTOM_RESPONSE 70 insert into CUSTOM_RESPONSE
@@ -77,6 +78,9 @@ @@ -77,6 +78,9 @@
77 <if test="flightno != null" > 78 <if test="flightno != null" >
78 flightNo, 79 flightNo,
79 </if> 80 </if>
  81 + <if test="carrier != null" >
  82 + carrier,
  83 + </if>
80 <if test="awbano != null" > 84 <if test="awbano != null" >
81 awbaNo, 85 awbaNo,
82 </if> 86 </if>
@@ -145,6 +149,9 @@ @@ -145,6 +149,9 @@
145 <if test="flightno != null" > 149 <if test="flightno != null" >
146 #{flightno,jdbcType=VARCHAR}, 150 #{flightno,jdbcType=VARCHAR},
147 </if> 151 </if>
  152 + <if test="carrier != null" >
  153 + #{carrier,jdbcType=VARCHAR},
  154 + </if>
148 <if test="awbano != null" > 155 <if test="awbano != null" >
149 #{awbano,jdbcType=VARCHAR}, 156 #{awbano,jdbcType=VARCHAR},
150 </if> 157 </if>
@@ -213,6 +220,9 @@ @@ -213,6 +220,9 @@
213 <if test="flightno != null" > 220 <if test="flightno != null" >
214 flightNo = #{flightno,jdbcType=VARCHAR}, 221 flightNo = #{flightno,jdbcType=VARCHAR},
215 </if> 222 </if>
  223 + <if test="carrier != null" >
  224 + carrier = #{carrier,jdbcType=VARCHAR},
  225 + </if>
216 <if test="awbano != null" > 226 <if test="awbano != null" >
217 awbaNo = #{awbano,jdbcType=VARCHAR}, 227 awbaNo = #{awbano,jdbcType=VARCHAR},
218 </if> 228 </if>
@@ -273,28 +283,55 @@ @@ -273,28 +283,55 @@
273 </set> 283 </set>
274 where id = #{id,jdbcType=VARCHAR} 284 where id = #{id,jdbcType=VARCHAR}
275 </update> 285 </update>
276 - <update id="updateAwbhReceiption" parameterType="com.tianbo.analysis.model.CUSTOM_RESPONSE" > 286 + <update id="updateByPrimaryKeyWithBLOBs" parameterType="com.tianbo.analysis.model.CUSTOM_RESPONSE" >
277 update CUSTOM_RESPONSE 287 update CUSTOM_RESPONSE
278 - set 288 + set flightDate = #{flightdate,jdbcType=DATE},
  289 + flightNo = #{flightno,jdbcType=VARCHAR},
  290 + carrier = #{carrier,jdbcType=VARCHAR},
  291 + awbaNo = #{awbano,jdbcType=VARCHAR},
  292 + awbhNo = #{awbhno,jdbcType=VARCHAR},
  293 + busType = #{bustype,jdbcType=VARCHAR},
  294 + busDate = #{busdate,jdbcType=TIMESTAMP},
  295 + busWeight = #{busweight,jdbcType=DECIMAL},
  296 + busPiece = #{buspiece,jdbcType=INTEGER},
  297 + operType = #{opertype,jdbcType=VARCHAR},
  298 + cusMsgId = #{cusmsgid,jdbcType=VARCHAR},
  299 + cusSenderId = #{cussenderid,jdbcType=VARCHAR},
  300 + cusReciverId = #{cusreciverid,jdbcType=VARCHAR},
  301 + cusVersion = #{cusversion,jdbcType=VARCHAR},
  302 + cusFunctionCode = #{cusfunctioncode,jdbcType=VARCHAR},
  303 + cusResRcvTime = #{cusresrcvtime,jdbcType=TIMESTAMP},
  304 + cusResSendTime = #{cusressendtime,jdbcType=TIMESTAMP},
  305 + cusResCode = #{cusrescode,jdbcType=VARCHAR},
  306 + cusResStatus = #{cusresstatus,jdbcType=VARCHAR},
  307 + operUserName = #{operusername,jdbcType=VARCHAR},
  308 + operSystemName = #{opersystemname,jdbcType=VARCHAR},
279 cusResText = #{cusrestext,jdbcType=LONGVARCHAR} 309 cusResText = #{cusrestext,jdbcType=LONGVARCHAR}
280 - where  
281 - flightDate = #{flightdate,jdbcType=DATE}  
282 - and  
283 - flightNo = #{flightno,jdbcType=VARCHAR}  
284 - and  
285 - awbhNo = #{awbhno,jdbcType=VARCHAR} 310 + where id = #{id,jdbcType=VARCHAR}
286 </update> 311 </update>
287 -  
288 - <!--主单 修改-->  
289 - <update id="updateAwbReceiption" parameterType="com.tianbo.analysis.model.CUSTOM_RESPONSE" > 312 + <update id="updateByPrimaryKey" parameterType="com.tianbo.analysis.model.CUSTOM_RESPONSE" >
290 update CUSTOM_RESPONSE 313 update CUSTOM_RESPONSE
291 - set  
292 - cusResText = #{cusrestext,jdbcType=LONGVARCHAR}  
293 - where  
294 - flightDate = #{flightdate,jdbcType=DATE}  
295 - and  
296 - flightNo = #{flightno,jdbcType=VARCHAR}  
297 - and  
298 - awbaNo = #{awbano,jdbcType=VARCHAR} 314 + set flightDate = #{flightdate,jdbcType=DATE},
  315 + flightNo = #{flightno,jdbcType=VARCHAR},
  316 + carrier = #{carrier,jdbcType=VARCHAR},
  317 + awbaNo = #{awbano,jdbcType=VARCHAR},
  318 + awbhNo = #{awbhno,jdbcType=VARCHAR},
  319 + busType = #{bustype,jdbcType=VARCHAR},
  320 + busDate = #{busdate,jdbcType=TIMESTAMP},
  321 + busWeight = #{busweight,jdbcType=DECIMAL},
  322 + busPiece = #{buspiece,jdbcType=INTEGER},
  323 + operType = #{opertype,jdbcType=VARCHAR},
  324 + cusMsgId = #{cusmsgid,jdbcType=VARCHAR},
  325 + cusSenderId = #{cussenderid,jdbcType=VARCHAR},
  326 + cusReciverId = #{cusreciverid,jdbcType=VARCHAR},
  327 + cusVersion = #{cusversion,jdbcType=VARCHAR},
  328 + cusFunctionCode = #{cusfunctioncode,jdbcType=VARCHAR},
  329 + cusResRcvTime = #{cusresrcvtime,jdbcType=TIMESTAMP},
  330 + cusResSendTime = #{cusressendtime,jdbcType=TIMESTAMP},
  331 + cusResCode = #{cusrescode,jdbcType=VARCHAR},
  332 + cusResStatus = #{cusresstatus,jdbcType=VARCHAR},
  333 + operUserName = #{operusername,jdbcType=VARCHAR},
  334 + operSystemName = #{opersystemname,jdbcType=VARCHAR}
  335 + where id = #{id,jdbcType=VARCHAR}
299 </update> 336 </update>
300 </mapper> 337 </mapper>