作者 朱兆平

JSON格式的回执解析。

... ... @@ -3,7 +3,7 @@
web:
upload-path: upload/
server:
port: 11112
port: 11113
servlet:
context-path: ${SERVER_CONTEXTPATH:}
spring:
... ... @@ -53,10 +53,10 @@ spring:
#username=CGOETL
#password=1q2w3e4r
#spring datasource mysql,注意编码配置,缺少数据库编码配置容易引起中文入库乱码
# url: jdbc:mysql://118.31.66.166:3306/station?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
url: jdbc:mysql://8.131.245.248:3306/zz_logistics?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
username: root
password: ZZdsly123
url: jdbc:mysql://118.31.66.166:3306/WLPT_NMMS?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
# url: jdbc:mysql://8.131.245.248:3306/zz_logistics?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
username: 110
password: QAHqCJf2kFYCLirM
driver-class-name: com.mysql.cj.jdbc.Driver
#配置初始化大小/最小/最大
druid:
... ... @@ -118,7 +118,7 @@ management:
mybatis:
mapper-locations: classpath:mapping/*.xml
type-aliases-package: com.sunyo.usercenter.heartbeat.model
type-aliases-package: com.tianbo.messagebus.model
pagehelper:
#auto-dialect: true
#auto-runtime-dialect: true
... ... @@ -157,7 +157,7 @@ message-bus:
#报文接收地址
get-url: http://36.134.143.171:8083/api/kafka-server-consumer/kafka/receive
auth:
username: yangyucheng
username: CETC
password: 111111
#心跳间隔时间默认10秒,单位毫秒
heartbit-interval: 10000
... ...
... ... @@ -144,6 +144,32 @@
</filter>
</appender>
<!-- 时间滚动输出 level为 trace 日志 -->
<appender name="TRACE_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 正在记录的日志文件的路径及文件名 -->
<file>${log.path}/log_trace.log</file>
<!--日志文件输出格式-->
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
<charset>UTF-8</charset> <!-- 此处设置字符集 -->
</encoder>
<!-- 日志记录器的滚动策略,按日期,按大小记录 -->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log.path}/trace/log-trace-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>100MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<!--日志文件保留天数-->
<maxHistory>15</maxHistory>
</rollingPolicy>
<!-- 此日志文件只记录trace级别的 -->
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>TRACE</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!--
<logger>用来设置某一个包或者具体的某一个类的日志打印级别、
以及指定<appender>。<logger>仅有一个name属性,
... ... @@ -169,17 +195,17 @@
不能设置为INHERITED或者同义词NULL。默认是DEBUG
可以包含零个或多个元素,标识这个appender将会添加到这个logger。
-->
<logger name="com.sunyo.usercenter.heartbeat.dao" level="debug" />
<!--开发环境:打印控制台-->
<springProfile name="dev">
<logger name="org.apache.tomcat" level="info" />
<logger name="com.sunyo.usercenter.heartbeat" level="debug" />
<logger name="com.tianbo.messagebus.service.MessageBusProcessor" level="ALL" />
<logger name="com.tianbo.messagebus.dao" level="DEBUG" />
<root level="INFO">
<appender-ref ref="CONSOLE" />
<appender-ref ref="DEBUG_FILE" />
<appender-ref ref="INFO_FILE" />
<appender-ref ref="WARN_FILE" />
<appender-ref ref="ERROR_FILE" />
<appender-ref ref="TRACE_FILE" />
</root>
</springProfile>
... ... @@ -194,4 +220,4 @@
</root>
</springProfile>
</configuration>
\ No newline at end of file
</configuration>
... ...
... ... @@ -6,7 +6,7 @@
<packaging>jar</packaging>
<groupId>com.tianbo</groupId>
<artifactId>messagebus-trans-message</artifactId>
<version>1.0-feign</version>
<version>1.0-parse</version>
<description>消息转发服务</description>
<parent>
... ... @@ -21,7 +21,8 @@
<spring-cloud.version>Hoxton.SR9</spring-cloud.version>
<swagger2_version>2.9.2</swagger2_version>
<fastjson_version>1.2.73</fastjson_version>
<lombok_sersion>1.18.6</lombok_sersion>
<lombok_sersion>1.18.16</lombok_sersion>
<druid.version>1.1.9</druid.version>
</properties>
<dependencies>
... ... @@ -48,21 +49,49 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<!--数据库相关-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
<version>8.0.15</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>${druid.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.6</version>
</dependency>
<!--数据库相关-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson_version}</version>
</dependency>
<dependency>
<groupId>com.tianbo</groupId>
<artifactId>util</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<dependencyManagement>
... ... @@ -82,6 +111,17 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- mybatis generator 自动生成代码插件 -->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile>
<overwrite>true</overwrite>
<verbose>true</verbose>
</configuration>
</plugin>
</plugins>
</build>
</project>
... ...
package com.tianbo.messagebus;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
... ... @@ -15,6 +16,7 @@ import org.springframework.web.client.RestTemplate;
@EnableEurekaClient
@EnableFeignClients
@EnableScheduling
@MapperScan("com.tianbo.messagebus.dao")
public class MessageTransApplication {
public static void main(String[] args) {
... ...
... ... @@ -3,6 +3,8 @@ package com.tianbo.messagebus.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.tianbo.messagebus.controller.response.ResultJson;
import com.tianbo.messagebus.dao.CUSTOM_RESPONSEMapper;
import com.tianbo.messagebus.model.CUSTOM_RESPONSE;
import com.tianbo.messagebus.model.HEADER;
import com.tianbo.messagebus.model.MSG;
import com.tianbo.messagebus.model.MSGS;
... ... @@ -30,9 +32,15 @@ public class HeartbeatController implements Serializable {
@Autowired
KafkaReciveApi kafkaReciveApi;
@Resource
public CUSTOM_RESPONSEMapper custom_responseMapper_nmms20;
@Autowired
KafkaSendApi kafkaSendApi;
@Resource
CUSTOM_RESPONSEMapper custom_responseMapper;
@Autowired
private HttpServletRequest request;
... ... @@ -82,4 +90,10 @@ public class HeartbeatController implements Serializable {
log.info(response.toString());
}
@PostMapping("parse")
public void parse(@RequestBody CUSTOM_RESPONSE custom_response){
int i = custom_responseMapper.insertSelective(custom_response);
log.info("插入数据为{}",i);
}
}
... ...
package com.tianbo.messagebus.dao;
import com.tianbo.messagebus.model.CUSTOM_RESPONSE;
import java.util.List;
public interface CUSTOM_RESPONSEMapper {
int deleteByPrimaryKey(String id);
int insert(CUSTOM_RESPONSE record);
int insertSelective(CUSTOM_RESPONSE record);
CUSTOM_RESPONSE selectByPrimaryKey(String id);
List<CUSTOM_RESPONSE> selectByCustomMsgId(String cusmsgid);
int updateByPrimaryKeySelective(CUSTOM_RESPONSE record);
int updateByPrimaryKeyWithBLOBs(CUSTOM_RESPONSE record);
int updateByPrimaryKey(CUSTOM_RESPONSE record);
}
... ...
package com.tianbo.messagebus.model;
import com.tianbo.messagebus.dao.CUSTOM_RESPONSEMapper;
import com.tianbo.messagebus.tools.AWBTools;
import com.tianbo.util.Date.DateUtil;
import lombok.Data;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.UUID;
public class CUSTOM_RESPONSE {
private String id;
private Date flightdate;
private String flightno;
private String carrier;
private String awbano;
private String awbhno;
private String bustype;
private Date busdate;
private BigDecimal busweight;
private Integer buspiece;
private String opertype;
private String cusmsgid;
private String cussenderid;
private String cusreciverid;
private String cusversion;
private String cusfunctioncode;
private Date cusresrcvtime;
private Date cusressendtime;
private String cusrescode;
private String cusresstatus;
private String operusername;
private String opersystemname;
private String operreason;
private String operperson;
private String opertel;
private String cusrestext;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id == null ? null : id.trim();
}
public Date getFlightdate() {
return flightdate;
}
public void setFlightdate(Date flightdate) {
this.flightdate = flightdate;
}
public String getFlightno() {
return flightno;
}
public void setFlightno(String flightno) {
this.flightno = flightno == null ? null : flightno.trim();
}
public String getCarrier() {
return carrier;
}
public void setCarrier(String carrier) {
this.carrier = carrier == null ? null : carrier.trim();
}
public String getAwbano() {
return awbano;
}
public void setAwbano(String awbano) {
this.awbano = awbano == null ? null : awbano.trim();
}
public String getAwbhno() {
return awbhno;
}
public void setAwbhno(String awbhno) {
this.awbhno = awbhno == null ? null : awbhno.trim();
}
public String getBustype() {
return bustype;
}
public void setBustype(String bustype) {
this.bustype = bustype == null ? null : bustype.trim();
}
public Date getBusdate() {
return busdate;
}
public void setBusdate(Date busdate) {
this.busdate = busdate;
}
public BigDecimal getBusweight() {
return busweight;
}
public void setBusweight(BigDecimal busweight) {
this.busweight = busweight;
}
public Integer getBuspiece() {
return buspiece;
}
public void setBuspiece(Integer buspiece) {
this.buspiece = buspiece;
}
public String getOpertype() {
return opertype;
}
public void setOpertype(String opertype) {
this.opertype = opertype == null ? null : opertype.trim();
}
public String getCusmsgid() {
return cusmsgid;
}
public void setCusmsgid(String cusmsgid) {
this.cusmsgid = cusmsgid == null ? null : cusmsgid.trim();
}
public String getCussenderid() {
return cussenderid;
}
public void setCussenderid(String cussenderid) {
this.cussenderid = cussenderid == null ? null : cussenderid.trim();
}
public String getCusreciverid() {
return cusreciverid;
}
public void setCusreciverid(String cusreciverid) {
this.cusreciverid = cusreciverid == null ? null : cusreciverid.trim();
}
public String getCusversion() {
return cusversion;
}
public void setCusversion(String cusversion) {
this.cusversion = cusversion == null ? null : cusversion.trim();
}
public String getCusfunctioncode() {
return cusfunctioncode;
}
public void setCusfunctioncode(String cusfunctioncode) {
this.cusfunctioncode = cusfunctioncode == null ? null : cusfunctioncode.trim();
}
public Date getCusresrcvtime() {
return cusresrcvtime;
}
public void setCusresrcvtime(Date cusresrcvtime) {
this.cusresrcvtime = cusresrcvtime;
}
public Date getCusressendtime() {
return cusressendtime;
}
public void setCusressendtime(Date cusressendtime) {
this.cusressendtime = cusressendtime;
}
public String getCusrescode() {
return cusrescode;
}
public void setCusrescode(String cusrescode) {
this.cusrescode = cusrescode == null ? null : cusrescode.trim();
}
public String getCusresstatus() {
return cusresstatus;
}
public void setCusresstatus(String cusresstatus) {
this.cusresstatus = cusresstatus == null ? null : cusresstatus.trim();
}
public String getOperusername() {
return operusername;
}
public void setOperusername(String operusername) {
this.operusername = operusername == null ? null : operusername.trim();
}
public String getOpersystemname() {
return opersystemname;
}
public void setOpersystemname(String opersystemname) {
this.opersystemname = opersystemname == null ? null : opersystemname.trim();
}
public String getOperreason() {
return operreason;
}
public void setOperreason(String operreason) {
this.operreason = operreason == null ? null : operreason.trim();
}
public String getOperperson() {
return operperson;
}
public void setOperperson(String operperson) {
this.operperson = operperson == null ? null : operperson.trim();
}
public String getOpertel() {
return opertel;
}
public void setOpertel(String opertel) {
this.opertel = opertel == null ? null : opertel.trim();
}
public String getCusrestext() {
return cusrestext;
}
public void setCusrestext(String cusrestext) {
this.cusrestext = cusrestext == null ? null : cusrestext.trim();
}
public CUSTOM_RESPONSE() {
}
/**
* 海关回执实体与系统回执实体转换
* @param customReception
*/
public CUSTOM_RESPONSE(CustomReception customReception) {
this.id = UUID.randomUUID().toString();
this.awbano = AWBTools.awbFormat(customReception.getWayBillMaster());
//取分单号
if (!StringUtils.isEmpty(customReception.getWayBillSecond())){
String[] awbhArr = customReception.getWayBillSecond().split("_");
this.awbhno = awbhArr[1];
}
String[] flightInfo = AWBTools.splitFlight(customReception.getFlightNo());
this.setFlightno(flightInfo[1]);
this.setCarrier(flightInfo[0]);
if (!StringUtils.isEmpty(customReception.getFlightDate())) {
this.setFlightdate(DateUtil.formatByyyyyMMdd(customReception.getFlightDate()));
}
this.cusrestext = customReception.getResponseText();
this.cusrescode = customReception.getResponseCode();
this.bustype = customReception.getMessageType();
this.cusfunctioncode = customReception.getFunctionCode();
this.operusername = "SYSTEM";
this.cusmsgid = customReception.getMessageID();
this.opertype = "回执";
this.cussenderid = customReception.getSenderID();
this.cusreciverid = customReception.getReceiverID();
this.cusresrcvtime = new Date();
this.cusressendtime = DateUtil.formatByyyyyMMddHHmmss(customReception.getSendTime());
this.cusversion = customReception.getVersion();
//单独存储下回执内容中的回执业务代码
if(this.cusrescode!= "0" && this.cusrestext!= null && this.cusrestext.length()>5){
this.cusresstatus = customReception.getResponseText().substring(0,5);
}
}
@Override
public String toString() {
return "CUSTOM_RESPONSE{" +
"id='" + id + '\'' +
", flightdate=" + flightdate +
", flightno='" + flightno + '\'' +
", carrier='" + carrier + '\'' +
", awbano='" + awbano + '\'' +
", awbhno='" + awbhno + '\'' +
", bustype='" + bustype + '\'' +
", busdate=" + busdate +
", busweight=" + busweight +
", buspiece=" + buspiece +
", opertype='" + opertype + '\'' +
", cusmsgid='" + cusmsgid + '\'' +
", cussenderid='" + cussenderid + '\'' +
", cusreciverid='" + cusreciverid + '\'' +
", cusversion='" + cusversion + '\'' +
", cusfunctioncode='" + cusfunctioncode + '\'' +
", cusresrcvtime=" + cusresrcvtime +
", cusressendtime=" + cusressendtime +
", cusrescode='" + cusrescode + '\'' +
", cusresstatus='" + cusresstatus + '\'' +
", operusername='" + operusername + '\'' +
", opersystemname='" + opersystemname + '\'' +
", operreason='" + operreason + '\'' +
", operperson='" + operperson + '\'' +
", opertel='" + opertel + '\'' +
", cusrestext='" + cusrestext + '\'' +
'}';
}
}
... ...
package com.tianbo.messagebus.model;
import lombok.Data;
@Data
public class CustomReception {
//回执报头
private String messageID;
private String functionCode;
private String messageType;
private String senderID;
private String receiverID;
private String sendTime;
private String version;
//一般业务回执
private String flightNo;
private String flightDate;
private String wayBillMaster;
private String wayBillSecond;
private String responseCode;
private String responseText;
//国际转运回执
private String importFlightDate;
private String importFlightNo;
private String importWaybillMaster;
private String exportFlightDate;
private String exportFlightNo;
private String exportWaybillMaster;
public CustomReception(String messageType,
String flightNo,
String flightDate,
String wayBillMaster,
String wayBillSecond,
String responseCode,
String responseText,
String messageID,
String sendTime,
String senderID,
String receiverID,
String version,
String functionCode){
this.messageType = messageType;
this.flightNo = flightNo;
this.flightDate = flightDate;
this.wayBillMaster = wayBillMaster;
this.wayBillSecond = wayBillSecond;
this.responseCode = responseCode;
this.responseText = responseText;
this.messageID = messageID;
this.sendTime = sendTime;
this.senderID =senderID;
this.receiverID = receiverID;
this.version = version;
this.functionCode = functionCode;
}
public CustomReception(String messageType,
String importFlightNo,
String importFlightDate,
String importWaybillMaster,
String transResponseCode,
String transResponseText,
String messageID,
String sendTime,
String senderID,
String receiverID,
String version,
String functionCode){
this.messageType = messageType;
this.importFlightNo = importFlightNo;
this.importFlightDate = importFlightDate;
this.importWaybillMaster = importWaybillMaster;
this.responseCode = transResponseCode;
this.responseText = transResponseText;
this.messageID = messageID;
this.sendTime = sendTime;
this.senderID =senderID;
this.receiverID = receiverID;
this.version = version;
this.functionCode = functionCode;
}
}
... ...
package com.tianbo.messagebus.service;
import com.tianbo.messagebus.dao.CUSTOM_RESPONSEMapper;
import com.tianbo.messagebus.model.CUSTOM_RESPONSE;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class Custom_Response_Service {
@Resource
public CUSTOM_RESPONSEMapper custom_responseMapper_nmms20;
/**
* 回执入库
* @return
*/
public int secondAnalysisReception(CUSTOM_RESPONSE custom_response) {
//更新分单回执
int i = custom_responseMapper_nmms20.insertSelective(custom_response);
return i;
}
/**
* 出错报文的适配问题,
* @return
*/
public CUSTOM_RESPONSE getWaybillInfoByCutomResponse(CUSTOM_RESPONSE custom_response){
List<CUSTOM_RESPONSE> res_list = custom_responseMapper_nmms20.selectByCustomMsgId(custom_response.getCusmsgid());
if (res_list.size()>0){
CUSTOM_RESPONSE result = res_list.get(0);
custom_response.setAwbano(result.getAwbano());
custom_response.setAwbhno(result.getAwbhno());
custom_response.setFlightdate(result.getFlightdate());
custom_response.setCarrier(result.getCarrier());
custom_response.setFlightno( result.getFlightno());
}
return custom_response;
}
public CUSTOM_RESPONSE selectByPrimaryKey(String id){
return custom_responseMapper_nmms20.selectByPrimaryKey(id);
}
}
... ...
... ... @@ -4,17 +4,13 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.tianbo.messagebus.controller.response.ResultJson;
import com.tianbo.messagebus.model.HEADER;
import com.tianbo.messagebus.model.MSG;
import com.tianbo.messagebus.model.MSGS;
import com.tianbo.messagebus.model.*;
import com.tianbo.messagebus.myinterface.KafkaReciveApi;
import com.tianbo.messagebus.myinterface.KafkaSendApi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.*;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
... ... @@ -94,6 +90,9 @@ public class MessageBusProcessor {
@Autowired
KafkaSendApi kafkaSendApi;
@Autowired
Custom_Response_Service custom_response_service;
/**
* 发起登录,存储token
*
... ... @@ -398,39 +397,138 @@ public class MessageBusProcessor {
/**
* feigin从服务直接获取消息
*/
@Scheduled(fixedRate = 1000)
@Scheduled(fixedRate = 5000)
public void getDataFromFeigin(){
log.info("1-开始执行获取任务");
ResultJson<List<String>> listResultJson = kafkaReciveApi.recive("HYYW");
log.info("2-获取结果为:{},数量为:{}",listResultJson.toString(),listResultJson.getData().size());
if ("200".equals(listResultJson.getCode()) && listResultJson.getData()!=null && listResultJson.getData().size()>0){
log.info("3-开始处理获取数据");
List<String> dataList = listResultJson.getData();
for (int i = 0; i <dataList.size() ; i++) {
String msg = dataList.get(i);
log.info("4-循环处理消息[{}]--->{}<---",i,msg);
JSONObject rootJson = JSON.parseObject(msg);
JSONObject msgJson = rootJson.getJSONObject("MSG");
JSONObject body = msgJson.getJSONObject("BODY");
HEADER msgHeader = msgJson.getObject("HEADER",HEADER.class);
MSG transMsg= new MSG();
String transBody = body.toJSONString();
transMsg.setHEADER(msgHeader);
transMsg.setBODY(transBody);
log.info("5-开始转发消息");
boolean sendResult = sendMsgByFeign(transMsg);
if(!sendResult){
log.error("!!!!!!消息--->{}<---转发失败!!!!!!,尝试重发",transMsg.toString());
//todo:消息备份或者重发?
reTrySend(transMsg);
try{
//初始化数据库
CUSTOM_RESPONSE test = custom_response_service.selectByPrimaryKey("111");
log.info("1-开始执行获取任务,获取账号为:{}",USER_NAME);
if(!StringUtils.isEmpty(USER_NAME)){
ResultJson<List<String>> listResultJson = kafkaReciveApi.recive(USER_NAME);
log.info("2-获取结果为:{},数量为:{}",listResultJson.toString(),listResultJson.getData().size());
if ("200".equals(listResultJson.getCode()) && listResultJson.getData()!=null && listResultJson.getData().size()>0){
log.info("3-开始处理获取数据");
List<String> dataList = listResultJson.getData();
for (int i = 0; i <dataList.size() ; i++) {
String msg = dataList.get(i);
log.info("4-循环处理消息[{}]--->{}<---",i,msg);
JSONObject rootJson = JSON.parseObject(msg);
JSONObject msgJson = rootJson.getJSONObject("MSG");
//回执实体
JSONObject body = msgJson.getJSONObject("BODY");
//报头
HEADER msgHeader = msgJson.getObject("HEADER",HEADER.class);
//判断类型
if ("CDHZ".equals(msgHeader.getSTYPE())){
log.info("@[一]@消息为舱单回执");
CUSTOM_RESPONSE custom_response_nmms2 = new CUSTOM_RESPONSE();
//判断回执类型
JSONObject Manifest = body.getJSONObject("Manifest");
JSONObject head = Manifest.getJSONObject("Head");
String messageType = head.getString("MessageType");
String messageID = head.getString("MessageID");
String sendTime = head.getString("SendTime");
String senderID = head.getString("SenderID");
String receiverID = head.getString("ReceiverID");
Integer version = head.getInteger("Version");
Integer functionCode = head.getInteger("FunctionCode");
if("MT2201".equals(messageType) || "MT9999".equals(messageType)){
log.info("@[二]@开始解析:{}",messageType);
// 航班信息
JSONObject response = Manifest.getJSONObject("Response");
JSONObject borderTransportMeans = response.getJSONObject("BorderTransportMeans");
String flightNo = "UNKONW";
String flightDate = "20101010";
String journeyid = borderTransportMeans.getString("JourneyID");
//运单信息
JSONObject consignment = response.getJSONObject("Consignment");
JSONObject responseType = consignment.getJSONObject("ResponseType");
JSONObject transportContractDocument = consignment.getJSONObject("TransportContractDocument");
JSONObject associatedTransportDocument = consignment.getJSONObject("AssociatedTransportDocument");
//回执代码
Integer responseCode = responseType.getIntValue("Code");
//回执内容
String responseText = responseType.getString("Text");
Long waybillMaster = transportContractDocument.getLong("ID");
String waybillSecond="";
if (associatedTransportDocument!=null){
waybillSecond = associatedTransportDocument.getString("ID");
}
CustomReception customReception = new CustomReception( messageType,
flightNo,
flightDate,
waybillMaster.toString(),
waybillSecond,
responseCode.toString(),
responseText,
messageID,
sendTime,
senderID,
receiverID,
version.toString(),
functionCode.toString());
/**
* 如果回执中没有携带航班信息节点,说明是出错报文
* 到发送日志表根据messageid 找到相应的发送日志报文的航班及运单信息,再进行解析
*/
if(!org.apache.commons.lang.StringUtils.isEmpty(journeyid)){
String[] flightList = journeyid.split("/");
if(flightList.length > 0){
flightNo = flightList[0];
flightDate = flightList[1];
log.info("@[三]@航班信息为:{}",journeyid);
customReception.setFlightNo(flightNo);
customReception.setFlightDate(flightDate);
}
custom_response_nmms2 = new CUSTOM_RESPONSE(customReception);
}else {
custom_response_nmms2 = new CUSTOM_RESPONSE(customReception);
custom_response_nmms2 = custom_response_service.getWaybillInfoByCutomResponse(custom_response_nmms2);
}
log.info("[(三.一)]{{}",custom_response_nmms2);
int ii = custom_response_service.secondAnalysisReception(custom_response_nmms2);
log.info("@[四]@回执解析完毕[{}]\n@@^PARSE SUCCESS^@@",ii);
}
}
}
}
}
}catch (Exception e){
log.error("!!!处理消息出错:{}!!!",e.toString());
e.printStackTrace();
}
}
/**
... ...
package com.tianbo.messagebus.tools;
import org.apache.commons.lang.StringUtils;
public class AWBTools {
public static String awbFormat(String awbNo) {
if (!StringUtils.isEmpty(awbNo)) {
StringBuffer stringBuffer = new StringBuffer(awbNo);
stringBuffer.insert(3, "-");
awbNo = stringBuffer.toString();
return awbNo;
}
return "";
}
/**
* 将航班号拆分成承运人及航班
* @param flightNo
* @return 返回数组 [0]为承运人 [1]为航班号
*/
public static String[] splitFlight(String flightNo){
String[] flight = {"UNKONW","UNKONW"};
if (!StringUtils.isEmpty(flightNo) && flightNo.length()>2){
flight[0] = flightNo.substring(0,2);
flight[1] = flightNo.substring(2);
}
return flight;
}
/**
* 拆分航班号与航班日期 CV7302/20190826
* @param flightNoAndDate
* @return [0] CV7302 [1]20190826
*/
public static String[] splitFlightAndDate(String flightNoAndDate){
String[] flight = {"UNKONW","UNKONW"};
if(!StringUtils.isEmpty(flightNoAndDate)){
String[] flightList = flightNoAndDate.split("/");
if(flightList.length > 0){
flight[0] = flightList[0];
flight[1] = flightList[1];
}
}
return flight;
}
/**
* 将海关回执中的response code 转换成新舱单1.0数据库中的相关状态,相关状态码参考readme.md
* @param rspCode
* @return
*/
public static String transCusRspCode(String rspCode){
String nmsCode = "03";
switch (rspCode){
case "01":
nmsCode="04";
break;
case "02":
nmsCode="03";
break;
case "03":
nmsCode="03";
break;
case "11":
nmsCode="04";
break;
case "12":
nmsCode="03";
break;
case "13":
nmsCode="03";
break;
default:
nmsCode="03";
break;
}
return nmsCode;
}
}
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.tianbo.messagebus.dao.CUSTOM_RESPONSEMapper" >
<resultMap id="BaseResultMap" type="com.tianbo.messagebus.model.CUSTOM_RESPONSE" >
<id column="id" property="id" jdbcType="VARCHAR" />
<result column="flightDate" property="flightdate" jdbcType="DATE" />
<result column="flightNo" property="flightno" jdbcType="VARCHAR" />
<result column="carrier" property="carrier" jdbcType="VARCHAR" />
<result column="awbaNo" property="awbano" jdbcType="VARCHAR" />
<result column="awbhNo" property="awbhno" jdbcType="VARCHAR" />
<result column="busType" property="bustype" jdbcType="VARCHAR" />
<result column="busDate" property="busdate" jdbcType="TIMESTAMP" />
<result column="busWeight" property="busweight" jdbcType="DECIMAL" />
<result column="busPiece" property="buspiece" jdbcType="INTEGER" />
<result column="operType" property="opertype" jdbcType="VARCHAR" />
<result column="cusMsgId" property="cusmsgid" jdbcType="VARCHAR" />
<result column="cusSenderId" property="cussenderid" jdbcType="VARCHAR" />
<result column="cusReciverId" property="cusreciverid" jdbcType="VARCHAR" />
<result column="cusVersion" property="cusversion" jdbcType="VARCHAR" />
<result column="cusFunctionCode" property="cusfunctioncode" jdbcType="VARCHAR" />
<result column="cusResRcvTime" property="cusresrcvtime" jdbcType="TIMESTAMP" />
<result column="cusResSendTime" property="cusressendtime" jdbcType="TIMESTAMP" />
<result column="cusResCode" property="cusrescode" jdbcType="VARCHAR" />
<result column="cusResStatus" property="cusresstatus" jdbcType="VARCHAR" />
<result column="operUserName" property="operusername" jdbcType="VARCHAR" />
<result column="operSystemName" property="opersystemname" jdbcType="VARCHAR" />
<result column="operReason" property="operreason" jdbcType="VARCHAR" />
<result column="operPerson" property="operperson" jdbcType="VARCHAR" />
<result column="operTel" property="opertel" jdbcType="VARCHAR" />
</resultMap>
<resultMap id="ResultMapWithBLOBs" type="com.tianbo.messagebus.model.CUSTOM_RESPONSE" extends="BaseResultMap" >
<result column="cusResText" property="cusrestext" jdbcType="LONGVARCHAR" />
</resultMap>
<sql id="Base_Column_List" >
id, flightDate, flightNo, carrier, awbaNo, awbhNo, busType, busDate, busWeight, busPiece,
operType, cusMsgId, cusSenderId, cusReciverId, cusVersion, cusFunctionCode, cusResRcvTime,
cusResSendTime, cusResCode, cusResStatus, operUserName, operSystemName, operReason,
operPerson, operTel
</sql>
<sql id="Blob_Column_List" >
cusResText
</sql>
<select id="selectByPrimaryKey" resultMap="ResultMapWithBLOBs" parameterType="java.lang.String" >
select
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from CUSTOM_RESPONSE
where id = #{id,jdbcType=VARCHAR}
</select>
<select id="selectByCustomMsgId" resultMap="ResultMapWithBLOBs" parameterType="java.lang.String" >
select
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from CUSTOM_RESPONSE
where cusMsgId = #{cusmsgid,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
delete from CUSTOM_RESPONSE
where id = #{id,jdbcType=VARCHAR}
</delete>
<insert id="insert" parameterType="com.tianbo.messagebus.model.CUSTOM_RESPONSE" >
insert into CUSTOM_RESPONSE (id, flightDate, flightNo,
carrier, awbaNo, awbhNo,
busType, busDate, busWeight,
busPiece, operType, cusMsgId,
cusSenderId, cusReciverId, cusVersion,
cusFunctionCode, cusResRcvTime, cusResSendTime,
cusResCode, cusResStatus, operUserName,
operSystemName, operReason, operPerson,
operTel, cusResText)
values (#{id,jdbcType=VARCHAR}, #{flightdate,jdbcType=DATE}, #{flightno,jdbcType=VARCHAR},
#{carrier,jdbcType=VARCHAR}, #{awbano,jdbcType=VARCHAR}, #{awbhno,jdbcType=VARCHAR},
#{bustype,jdbcType=VARCHAR}, #{busdate,jdbcType=TIMESTAMP}, #{busweight,jdbcType=DECIMAL},
#{buspiece,jdbcType=INTEGER}, #{opertype,jdbcType=VARCHAR}, #{cusmsgid,jdbcType=VARCHAR},
#{cussenderid,jdbcType=VARCHAR}, #{cusreciverid,jdbcType=VARCHAR}, #{cusversion,jdbcType=VARCHAR},
#{cusfunctioncode,jdbcType=VARCHAR}, #{cusresrcvtime,jdbcType=TIMESTAMP}, #{cusressendtime,jdbcType=TIMESTAMP},
#{cusrescode,jdbcType=VARCHAR}, #{cusresstatus,jdbcType=VARCHAR}, #{operusername,jdbcType=VARCHAR},
#{opersystemname,jdbcType=VARCHAR}, #{operreason,jdbcType=VARCHAR}, #{operperson,jdbcType=VARCHAR},
#{opertel,jdbcType=VARCHAR}, #{cusrestext,jdbcType=LONGVARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.tianbo.messagebus.model.CUSTOM_RESPONSE" >
insert into CUSTOM_RESPONSE
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="flightdate != null" >
flightDate,
</if>
<if test="flightno != null" >
flightNo,
</if>
<if test="carrier != null" >
carrier,
</if>
<if test="awbano != null" >
awbaNo,
</if>
<if test="awbhno != null" >
awbhNo,
</if>
<if test="bustype != null" >
busType,
</if>
<if test="busdate != null" >
busDate,
</if>
<if test="busweight != null" >
busWeight,
</if>
<if test="buspiece != null" >
busPiece,
</if>
<if test="opertype != null" >
operType,
</if>
<if test="cusmsgid != null" >
cusMsgId,
</if>
<if test="cussenderid != null" >
cusSenderId,
</if>
<if test="cusreciverid != null" >
cusReciverId,
</if>
<if test="cusversion != null" >
cusVersion,
</if>
<if test="cusfunctioncode != null" >
cusFunctionCode,
</if>
<if test="cusresrcvtime != null" >
cusResRcvTime,
</if>
<if test="cusressendtime != null" >
cusResSendTime,
</if>
<if test="cusrescode != null" >
cusResCode,
</if>
<if test="cusresstatus != null" >
cusResStatus,
</if>
<if test="operusername != null" >
operUserName,
</if>
<if test="opersystemname != null" >
operSystemName,
</if>
<if test="operreason != null" >
operReason,
</if>
<if test="operperson != null" >
operPerson,
</if>
<if test="opertel != null" >
operTel,
</if>
<if test="cusrestext != null" >
cusResText,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=VARCHAR},
</if>
<if test="flightdate != null" >
#{flightdate,jdbcType=DATE},
</if>
<if test="flightno != null" >
#{flightno,jdbcType=VARCHAR},
</if>
<if test="carrier != null" >
#{carrier,jdbcType=VARCHAR},
</if>
<if test="awbano != null" >
#{awbano,jdbcType=VARCHAR},
</if>
<if test="awbhno != null" >
#{awbhno,jdbcType=VARCHAR},
</if>
<if test="bustype != null" >
#{bustype,jdbcType=VARCHAR},
</if>
<if test="busdate != null" >
#{busdate,jdbcType=TIMESTAMP},
</if>
<if test="busweight != null" >
#{busweight,jdbcType=DECIMAL},
</if>
<if test="buspiece != null" >
#{buspiece,jdbcType=INTEGER},
</if>
<if test="opertype != null" >
#{opertype,jdbcType=VARCHAR},
</if>
<if test="cusmsgid != null" >
#{cusmsgid,jdbcType=VARCHAR},
</if>
<if test="cussenderid != null" >
#{cussenderid,jdbcType=VARCHAR},
</if>
<if test="cusreciverid != null" >
#{cusreciverid,jdbcType=VARCHAR},
</if>
<if test="cusversion != null" >
#{cusversion,jdbcType=VARCHAR},
</if>
<if test="cusfunctioncode != null" >
#{cusfunctioncode,jdbcType=VARCHAR},
</if>
<if test="cusresrcvtime != null" >
#{cusresrcvtime,jdbcType=TIMESTAMP},
</if>
<if test="cusressendtime != null" >
#{cusressendtime,jdbcType=TIMESTAMP},
</if>
<if test="cusrescode != null" >
#{cusrescode,jdbcType=VARCHAR},
</if>
<if test="cusresstatus != null" >
#{cusresstatus,jdbcType=VARCHAR},
</if>
<if test="operusername != null" >
#{operusername,jdbcType=VARCHAR},
</if>
<if test="opersystemname != null" >
#{opersystemname,jdbcType=VARCHAR},
</if>
<if test="operreason != null" >
#{operreason,jdbcType=VARCHAR},
</if>
<if test="operperson != null" >
#{operperson,jdbcType=VARCHAR},
</if>
<if test="opertel != null" >
#{opertel,jdbcType=VARCHAR},
</if>
<if test="cusrestext != null" >
#{cusrestext,jdbcType=LONGVARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.tianbo.messagebus.model.CUSTOM_RESPONSE" >
update CUSTOM_RESPONSE
<set >
<if test="flightdate != null" >
flightDate = #{flightdate,jdbcType=DATE},
</if>
<if test="flightno != null" >
flightNo = #{flightno,jdbcType=VARCHAR},
</if>
<if test="carrier != null" >
carrier = #{carrier,jdbcType=VARCHAR},
</if>
<if test="awbano != null" >
awbaNo = #{awbano,jdbcType=VARCHAR},
</if>
<if test="awbhno != null" >
awbhNo = #{awbhno,jdbcType=VARCHAR},
</if>
<if test="bustype != null" >
busType = #{bustype,jdbcType=VARCHAR},
</if>
<if test="busdate != null" >
busDate = #{busdate,jdbcType=TIMESTAMP},
</if>
<if test="busweight != null" >
busWeight = #{busweight,jdbcType=DECIMAL},
</if>
<if test="buspiece != null" >
busPiece = #{buspiece,jdbcType=INTEGER},
</if>
<if test="opertype != null" >
operType = #{opertype,jdbcType=VARCHAR},
</if>
<if test="cusmsgid != null" >
cusMsgId = #{cusmsgid,jdbcType=VARCHAR},
</if>
<if test="cussenderid != null" >
cusSenderId = #{cussenderid,jdbcType=VARCHAR},
</if>
<if test="cusreciverid != null" >
cusReciverId = #{cusreciverid,jdbcType=VARCHAR},
</if>
<if test="cusversion != null" >
cusVersion = #{cusversion,jdbcType=VARCHAR},
</if>
<if test="cusfunctioncode != null" >
cusFunctionCode = #{cusfunctioncode,jdbcType=VARCHAR},
</if>
<if test="cusresrcvtime != null" >
cusResRcvTime = #{cusresrcvtime,jdbcType=TIMESTAMP},
</if>
<if test="cusressendtime != null" >
cusResSendTime = #{cusressendtime,jdbcType=TIMESTAMP},
</if>
<if test="cusrescode != null" >
cusResCode = #{cusrescode,jdbcType=VARCHAR},
</if>
<if test="cusresstatus != null" >
cusResStatus = #{cusresstatus,jdbcType=VARCHAR},
</if>
<if test="operusername != null" >
operUserName = #{operusername,jdbcType=VARCHAR},
</if>
<if test="opersystemname != null" >
operSystemName = #{opersystemname,jdbcType=VARCHAR},
</if>
<if test="operreason != null" >
operReason = #{operreason,jdbcType=VARCHAR},
</if>
<if test="operperson != null" >
operPerson = #{operperson,jdbcType=VARCHAR},
</if>
<if test="opertel != null" >
operTel = #{opertel,jdbcType=VARCHAR},
</if>
<if test="cusrestext != null" >
cusResText = #{cusrestext,jdbcType=LONGVARCHAR},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKeyWithBLOBs" parameterType="com.tianbo.messagebus.model.CUSTOM_RESPONSE" >
update CUSTOM_RESPONSE
set flightDate = #{flightdate,jdbcType=DATE},
flightNo = #{flightno,jdbcType=VARCHAR},
carrier = #{carrier,jdbcType=VARCHAR},
awbaNo = #{awbano,jdbcType=VARCHAR},
awbhNo = #{awbhno,jdbcType=VARCHAR},
busType = #{bustype,jdbcType=VARCHAR},
busDate = #{busdate,jdbcType=TIMESTAMP},
busWeight = #{busweight,jdbcType=DECIMAL},
busPiece = #{buspiece,jdbcType=INTEGER},
operType = #{opertype,jdbcType=VARCHAR},
cusMsgId = #{cusmsgid,jdbcType=VARCHAR},
cusSenderId = #{cussenderid,jdbcType=VARCHAR},
cusReciverId = #{cusreciverid,jdbcType=VARCHAR},
cusVersion = #{cusversion,jdbcType=VARCHAR},
cusFunctionCode = #{cusfunctioncode,jdbcType=VARCHAR},
cusResRcvTime = #{cusresrcvtime,jdbcType=TIMESTAMP},
cusResSendTime = #{cusressendtime,jdbcType=TIMESTAMP},
cusResCode = #{cusrescode,jdbcType=VARCHAR},
cusResStatus = #{cusresstatus,jdbcType=VARCHAR},
operUserName = #{operusername,jdbcType=VARCHAR},
operSystemName = #{opersystemname,jdbcType=VARCHAR},
operReason = #{operreason,jdbcType=VARCHAR},
operPerson = #{operperson,jdbcType=VARCHAR},
operTel = #{opertel,jdbcType=VARCHAR},
cusResText = #{cusrestext,jdbcType=LONGVARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="com.tianbo.messagebus.model.CUSTOM_RESPONSE" >
update CUSTOM_RESPONSE
set flightDate = #{flightdate,jdbcType=DATE},
flightNo = #{flightno,jdbcType=VARCHAR},
carrier = #{carrier,jdbcType=VARCHAR},
awbaNo = #{awbano,jdbcType=VARCHAR},
awbhNo = #{awbhno,jdbcType=VARCHAR},
busType = #{bustype,jdbcType=VARCHAR},
busDate = #{busdate,jdbcType=TIMESTAMP},
busWeight = #{busweight,jdbcType=DECIMAL},
busPiece = #{buspiece,jdbcType=INTEGER},
operType = #{opertype,jdbcType=VARCHAR},
cusMsgId = #{cusmsgid,jdbcType=VARCHAR},
cusSenderId = #{cussenderid,jdbcType=VARCHAR},
cusReciverId = #{cusreciverid,jdbcType=VARCHAR},
cusVersion = #{cusversion,jdbcType=VARCHAR},
cusFunctionCode = #{cusfunctioncode,jdbcType=VARCHAR},
cusResRcvTime = #{cusresrcvtime,jdbcType=TIMESTAMP},
cusResSendTime = #{cusressendtime,jdbcType=TIMESTAMP},
cusResCode = #{cusrescode,jdbcType=VARCHAR},
cusResStatus = #{cusresstatus,jdbcType=VARCHAR},
operUserName = #{operusername,jdbcType=VARCHAR},
operSystemName = #{opersystemname,jdbcType=VARCHAR},
operReason = #{operreason,jdbcType=VARCHAR},
operPerson = #{operperson,jdbcType=VARCHAR},
operTel = #{opertel,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>
... ...