作者 朱兆平

修改后的九州发送的货运和华东的数据,SQL语句从配置文件读取

... ... @@ -90,15 +90,22 @@ public class IMFSender extends TimerTask {
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");
//_____________________________________解析天信达的报文-------------------------------------------------------------------------------------------
}
//_____________________________________给多式联运的航空报文,读取配置文件,生成新的META,并把最原始的报文封装到新报文的content里面--------------------------------------------------------------------
// String sndr = header.getSndr();
// String type = header.getType();
// String styp = header.getStype();
//
// IMFXMLMaker newXml = new IMFXMLMaker(sndr,Integer.toString(m.getFid()),type,styp);
// newXml.setIMFContent(m.getContent());
// sendMsg = newXml.finalXmlStr();
if (!"".equals(sendMsg)) {
logger.info("开始发送数据 XML:" + sendMsg);
... ...
... ... @@ -45,7 +45,7 @@ public class DaoImpl implements Dao {
this.jdbcTemplate.update(new PreparedStatementCreator() {
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
DaoImpl.logger.info("oper=" + oper + " sndr=" + sndr);
String sql = "insert into MESSAGE_BAK(OPER,SNDR,SNTM,content) values(?,?,sysdate,empty_clob())";
String sql = "insert into T_ETL_MESSAGE(OPER,SNDR,SNTM,content) values(?,?,sysdate,empty_clob())";
PreparedStatement ps = connection.prepareStatement(sql, new String[]{"FID"});
ps.setString(1, oper);
ps.setString(2, sndr);
... ... @@ -67,7 +67,7 @@ public class DaoImpl implements Dao {
conn = this.jdbcTemplate.getDataSource().getConnection();
conn.setAutoCommit(false);
stmt = conn.createStatement();
String SQL = "select CONTENT from MESSAGE_BAK where FID=" + fid + " and SNDR='CFPS' for update";
String SQL = "select CONTENT from T_ETL_MESSAGE where FID=" + fid + " and SNDR='FIMS' for update";
rs = stmt.executeQuery(SQL);
while(rs.next()) {
... ... @@ -108,16 +108,20 @@ public class DaoImpl implements Dao {
}
public void delete(int fid) {
this.jdbcTemplate.update("delete from MESSAGE_BAK where fid=" + fid);
this.jdbcTemplate.update("delete from T_ETL_MESSAGE where fid=" + fid);
}
public int getMaxFID() {
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'");
String sqlmax = "select max(fid) from MESSAGE_BAK WHERE (FID>%s and FID<%s+%s) AND (TYPE='CLR' OR TYPE='ES1' OR TYPE='IS1' OR STYP = 'BSTA' OR STYP = 'FZE_RCF' OR STYP = 'FSU_FOH' OR STYP = 'FSU_DEP' OR STYP = 'COST' OR STYP = 'ABME' OR STYP = 'FZE_DEP' OR STYP = 'FSU_RCF') ORDER BY FID\n";
sqlmax = ConfigUtils.SQlMax;
return this.jdbcTemplate.queryForInt(sqlmax);
}
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' OR TYPE ='RSC' OR TYPE ='ES1' OR TYPE='IS1') order by FID";
String sql = String.format(SQL_FMT, fid, fid, ConfigUtils.RECORD_COUNT);
String SQL_FMT = "select FID,CONTENT from MESSAGE_BAK WHERE (FID>%s and FID<%s+%s) AND (TYPE='CLR' OR TYPE='ES1' OR TYPE='IS1' OR STYP = 'BSTA' OR STYP = 'FZE_RCF' OR STYP = 'FSU_FOH' OR STYP = 'FSU_DEP' OR STYP = 'COST' OR STYP = 'ABME' OR STYP = 'FZE_DEP' OR STYP = 'FSU_RCF') ORDER BY FID ";
//从配置文件读取sql语句
String sql_select=ConfigUtils.SQl;
String sql = String.format(sql_select, fid, fid, ConfigUtils.RECORD_COUNT);
logger.info(sql);
final LobHandler lobHandler = new DefaultLobHandler();
final ArrayList xmlList = new ArrayList();
... ... @@ -148,11 +152,11 @@ public class DaoImpl implements Dao {
}
public int getRecordCount() {
return this.jdbcTemplate.queryForInt("select count(*) from MESSAGE_BAK where SNDR='CFPS' ");
return this.jdbcTemplate.queryForInt("select count(*) from T_ETL_MESSAGE where SNDR='FIMS' ");
}
public void update(int fid, int times) {
String sql = String.format("update MESSAGE_BAK set OUTFLAG=%s ,OUTTM=sysdate where FID=%s", times, fid);
String sql = String.format("update T_ETL_MESSAGE set OUTFLAG=%s ,OUTTM=sysdate where FID=%s", times, fid);
logger.info("sql=" + sql);
this.jdbcTemplate.update(sql);
}
... ...
... ... @@ -30,6 +30,8 @@ public class ConfigUtils {
public static String RCVR = "";
public static String APPID = "";
public static String SNDR = "";
public static String SQl="";
public static String SQlMax="";
public static Map<String, String> XTYPE_MAP = new HashMap();
public ConfigUtils() {
... ... @@ -56,6 +58,8 @@ public class ConfigUtils {
ROLE = config.getProperty("role").trim();
IMF_USERNAME = config.getProperty("imf_username").trim();
IMF_PASSWORD = config.getProperty("imf_password").trim();
SQl = config.getProperty("sql");
SQlMax = config.getProperty("sqlmax");
String interval = config.getProperty("interval").trim();
String record_count = config.getProperty("record_count").trim();
logger.info(String.format("role=%s", ROLE));
... ...
... ... @@ -22,7 +22,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
//读取写入已发送的FID
public class Utils {
private static Logger logger = Logger.getLogger(SystemBean.class);
... ...
... ... @@ -20,6 +20,7 @@ public class IMFXMLMaker {
private Element SEQNElement;
private Element TYPEElement;
private Element STYPElement;
private Element originalELEMENT;
private String XmlStr;
private String SNDR;
... ... @@ -111,6 +112,10 @@ public class IMFXMLMaker {
Element MetaElement = new Element("META");
this.RootElement.addContent(0,MetaElement);
//原始内容节点,储存最原始报文内容的节点
this.originalELEMENT = new Element("original");
this.RootElement.addContent(1,this.originalELEMENT);
//meta下的子节点们
SndrElement = new Element("SNDR");
RcvrElement = new Element("RCVR");
... ... @@ -141,7 +146,7 @@ public class IMFXMLMaker {
try{
Document contentDocument = string2Doc(this.IMFContent);
this.RootElement.addContent(1,contentDocument.detachRootElement());
this.originalELEMENT.addContent(0,contentDocument.detachRootElement());
String backXml = doc2String(this.XmlDocument);
return backXml;
... ...