作者 朱兆平

增加给九州的数据类型CLR类型

... ... @@ -12,6 +12,7 @@ import com.airport.dao.impl.DaoImpl;
import com.airport.util.ConfigUtils;
import com.airport.util.SystemBean;
import com.airport.util.Utils;
import com.airport.util.parse.IMFXMLMaker;
import com.airport.util.parse.XMPParse;
import com.caac.imf.api.IMFClient;
import org.apache.commons.lang.StringUtils;
... ... @@ -46,7 +47,7 @@ public class IMFSender extends TimerTask {
logger.info("lastFID=" + lastFID + " maxFID=" + maxFID);
int is_ok = 0;
if (maxFID > lastFID) {
List<MessageBak> list = this.dao.getRecordByFID(lastFID);
List<MessageBak> list = this.dao.getRecordByFID(lastFID); //查询大于[FID]350的报文
Map<Integer, XMLHeader> map = ConfigUtils.XML_HEADER_MAP;
Iterator var7 = list.iterator();
... ... @@ -60,17 +61,45 @@ public class IMFSender extends TimerTask {
if (m.getContent() != null) {
int times = 0;
//配置文件里面有几个sender 这里循环几次
for(Iterator var10 = map.keySet().iterator(); var10.hasNext(); Thread.sleep((long)ConfigUtils.SEND_MESSAGE_INTERVAL)) {
Integer key = (Integer)var10.next();
XMLHeader header = (XMLHeader)map.get(key);
logger.info("key=" + key + " value=" + ((XMLHeader)map.get(key)).toString());
logger.info("准备发送数据 FID:" + m.getFid() + " XML.length=:" + m.getContent().length());
String sendMsg = Utils.searchReplace(m.getContent(), header.getSndr(), "SNDR");
sendMsg = Utils.searchReplace(sendMsg, header.getType(), "TYPE");
String stype = tranlateXML(m.getContent());
sendMsg = Utils.searchReplace(sendMsg, stype, "STYP");
sendMsg = Utils.searchReplaceSingle(sendMsg, header.getRcvr(), "RCVR");
//初始化最终发布报文内容的存储器
String sendMsg = "";
String xmlStr = m.getContent();
//_____________________________________解析华东的报文-------------------------------------------------------------------------------------------
if (xmlStr.contains("<MessageType>IS1</MessageType>")){
IMFXMLMaker haiguanXml = new IMFXMLMaker("DCKS",Integer.toString(m.getFid()),"DFME","IS1");
haiguanXml.setIMFContent(m.getContent());
sendMsg = haiguanXml.finalXmlStr();
}else if(xmlStr.contains("<MessageType>ES1</MessageType>") ){
IMFXMLMaker haiguanXml = new IMFXMLMaker("DCKS",Integer.toString(m.getFid()),"DFME","ES1");
haiguanXml.setIMFContent(m.getContent());
sendMsg = haiguanXml.finalXmlStr();
}else if(xmlStr.contains("<MessageType>CLR</MessageType>")){
IMFXMLMaker haiguanXml = new IMFXMLMaker("DCKS",Integer.toString(m.getFid()),"DFME","CLR");
haiguanXml.setIMFContent(m.getContent());
sendMsg = haiguanXml.finalXmlStr();
}else if(xmlStr.contains("<MessageType>RSC</MessageType>")){
IMFXMLMaker haiguanXml = new IMFXMLMaker("DCKS",Integer.toString(m.getFid()),"DFME","RSC");
haiguanXml.setIMFContent(m.getContent());
sendMsg = haiguanXml.finalXmlStr();
} else {
//_____________________________________解析天信达的报文-------------------------------------------------------------------------------------------
sendMsg= Utils.searchReplace(m.getContent(), header.getSndr(), "SNDR");
sendMsg = Utils.searchReplace(sendMsg, header.getType(), "TYPE"); //替换报文主类型
String stype = tranlateXML(m.getContent());
sendMsg = Utils.searchReplace(sendMsg, stype, "STYP");
sendMsg = Utils.searchReplaceSingle(sendMsg, header.getRcvr(), "RCVR");
//_____________________________________解析天信达的报文-------------------------------------------------------------------------------------------
}
if (!"".equals(sendMsg)) {
logger.info("开始发送数据 XML:" + sendMsg);
String is_send_ok = this.client.sendMSG(sendMsg);
... ...
... ... @@ -112,11 +112,11 @@ public class DaoImpl implements Dao {
}
public int getMaxFID() {
return this.jdbcTemplate.queryForInt("select max(FID) from MESSAGE_BAK where SNDR='CFPS' OR TYPE='CLR'");
return this.jdbcTemplate.queryForInt("select max(FID) from MESSAGE_BAK where SNDR='CFPS' OR TYPE='CLR' OR TYPE ='RSC' OR TYPE ='ES1' OR TYPE='IS1'");
}
public List<MessageBak> getRecordByFID(int fid) {
String SQL_FMT = "select FID,CONTENT from MESSAGE_BAK where (FID>%s and FID<%s+%s) and (SNDR='CFPS' OR TYPE='CLR') order by FID";
String SQL_FMT = "select FID,CONTENT from MESSAGE_BAK where (FID>%s and FID<%s+%s) and (SNDR='CFPS' OR TYPE='CLR' OR TYPE ='RSC' OR TYPE ='ES1' OR TYPE='IS1') order by FID";
String sql = String.format(SQL_FMT, fid, fid, ConfigUtils.RECORD_COUNT);
logger.info(sql);
final LobHandler lobHandler = new DefaultLobHandler();
... ...
package com.airport.util.parse;
import org.apache.log4j.Logger;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
public class IMFXMLMaker {
private static final Logger logger = Logger.getLogger(IMFXMLMaker.class);
private Document XmlDocument;
private Element RootElement;
private Element SndrElement;
private Element RcvrElement;
private Element SEQNElement;
private Element TYPEElement;
private Element STYPElement;
private String XmlStr;
private String SNDR;
private String RCVR;
private String SEQN;
private String TYPE;
private String STYP;
private String IMFContent;
private String IMFXml;
public String getXmlStr() {
return XmlStr;
}
public void setXmlStr(String xmlStr) {
XmlStr = xmlStr;
}
public String getSNDR() {
return SNDR;
}
public void setSNDR(String SNDR) {
this.SNDR = SNDR;
}
public String getRCVR() {
return RCVR;
}
public void setRCVR(String RCVR) {
this.RCVR = RCVR;
}
public String getSEQN() {
return SEQN;
}
public void setSEQN(String SEQN) {
this.SEQN = SEQN;
}
public String getTYPE() {
return TYPE;
}
public void setTYPE(String TYPE) {
this.TYPE = TYPE;
}
public String getSTYP() {
return STYP;
}
public void setSTYP(String STYP) {
this.STYP = STYP;
}
public String getIMFContent() {
return IMFContent;
}
public void setIMFContent(String IMFContent) {
this.IMFContent = IMFContent;
}
public String getIMFXml() {
return IMFXml;
}
public void setIMFXml(String IMFXml) {
this.IMFXml = IMFXml;
}
//初始化报文头部节点
public IMFXMLMaker(String sndr,String seqn,String type,String styp){
this.SNDR = sndr;
this.SEQN = seqn;
this.TYPE = type;
this.STYP = styp;
this.XmlDocument = new Document();
//跟节点
this.RootElement = new Element("MSG");
this.XmlDocument.addContent(this.RootElement);
//meta节点
Element MetaElement = new Element("META");
this.RootElement.addContent(0,MetaElement);
//meta下的子节点们
SndrElement = new Element("SNDR");
RcvrElement = new Element("RCVR");
SEQNElement = new Element("SEQN");
Element DDTMElement = new Element("DDTM");
TYPEElement = new Element("TYPE");
STYPElement = new Element("STYP");
MetaElement.addContent(0,SndrElement);
MetaElement.addContent(1,RcvrElement);
MetaElement.addContent(2,SEQNElement);
MetaElement.addContent(3,DDTMElement);
MetaElement.addContent(4,TYPEElement);
MetaElement.addContent(5,STYPElement);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String dateString = simpleDateFormat.format(new Date());
DDTMElement.setText(dateString);
SndrElement.setText(this.SNDR);
SEQNElement.setText(this.SEQN);
TYPEElement.setText(this.TYPE);
STYPElement.setText(this.STYP);
}
public String finalXmlStr(){
try{
Document contentDocument = string2Doc(this.IMFContent);
this.RootElement.addContent(1,contentDocument.detachRootElement());
String backXml = doc2String(this.XmlDocument);
return backXml;
}catch (Exception e){
e.printStackTrace();
return this.SEQN+"error";
}
}
/**
* 字符串转换为DOCUMENT
*
* @param xmlStr 字符串
* @return doc JDOM的Document
* @throws Exception
*/
public static Document string2Doc(String xmlStr) throws Exception {
java.io.Reader in = new StringReader(xmlStr);
Document doc = (new SAXBuilder()).build(in);
return doc;
}
/**
* Document转换为字符串
*
* @param doc DOCUMENT对象
* @return xmlStr 字符串
* @throws Exception
*/
public String doc2String(Document doc) throws Exception {
Format format = Format.getPrettyFormat();
format.setEncoding("UTF-8");// 设置xml文件的字符为UTF-8,解决中文问题
XMLOutputter xmlout = new XMLOutputter(format);
ByteArrayOutputStream bo = new ByteArrayOutputStream();
xmlout.output(doc, bo);
return bo.toString();
}
/**
* XML转换为Document
*
* @param xmlFilePath XML文件路径
* @return doc Document对象
* @throws Exception
*/
public static Document xml2Doc(String xmlFilePath) throws Exception {
File file = new File(xmlFilePath);
return (new SAXBuilder()).build(file);
}
public void main(String[] args) throws Exception{
finalXmlStr();
}
}
... ...