正在显示
4 个修改的文件
包含
52 行增加
和
17 行删除
@@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
6 | package com.airport; | 6 | package com.airport; |
7 | 7 | ||
8 | import com.airport.core.IMFReader; | 8 | import com.airport.core.IMFReader; |
9 | -import com.airport.core.SendMessageTask; | 9 | +import com.airport.core.IMFSender; |
10 | import com.airport.util.ConfigUtils; | 10 | import com.airport.util.ConfigUtils; |
11 | import com.airport.util.SystemBean; | 11 | import com.airport.util.SystemBean; |
12 | import com.caac.imf.api.IMFClient; | 12 | import com.caac.imf.api.IMFClient; |
@@ -41,8 +41,10 @@ public class Main { | @@ -41,8 +41,10 @@ public class Main { | ||
41 | if (LOGIN_OK && client != null) { | 41 | if (LOGIN_OK && client != null) { |
42 | logger.info("start run Timer,client hasocde=" + client.hashCode()); | 42 | logger.info("start run Timer,client hasocde=" + client.hashCode()); |
43 | Timer timer = new Timer(); | 43 | Timer timer = new Timer(); |
44 | - SendMessageTask sender = new SendMessageTask(client, "data/fid_index.txt"); | ||
45 | - timer.schedule(sender, 30000L, 1200000L); | 44 | +// SendMessageTask sender = new SendMessageTask(client, "data/fid_index.txt"); |
45 | + IMFSender imfSender = new IMFSender(client,"data/fid_index.txt"); | ||
46 | +// timer.schedule(sender, 30000L, 1200000L); | ||
47 | + timer.schedule(imfSender,30000L,1200000L); | ||
46 | } | 48 | } |
47 | } | 49 | } |
48 | 50 |
@@ -12,20 +12,23 @@ import com.airport.dao.impl.DaoImpl; | @@ -12,20 +12,23 @@ import com.airport.dao.impl.DaoImpl; | ||
12 | import com.airport.util.ConfigUtils; | 12 | import com.airport.util.ConfigUtils; |
13 | import com.airport.util.SystemBean; | 13 | import com.airport.util.SystemBean; |
14 | import com.airport.util.Utils; | 14 | import com.airport.util.Utils; |
15 | +import com.airport.util.parse.XMPParse; | ||
15 | import com.caac.imf.api.IMFClient; | 16 | import com.caac.imf.api.IMFClient; |
17 | +import org.apache.commons.lang.StringUtils; | ||
18 | +import org.apache.log4j.Logger; | ||
19 | + | ||
16 | import java.util.Iterator; | 20 | import java.util.Iterator; |
17 | import java.util.List; | 21 | import java.util.List; |
18 | import java.util.Map; | 22 | import java.util.Map; |
19 | import java.util.TimerTask; | 23 | import java.util.TimerTask; |
20 | -import org.apache.log4j.Logger; | ||
21 | 24 | ||
22 | -public class SendMessageTask extends TimerTask { | ||
23 | - private static final Logger logger = Logger.getLogger(SendMessageTask.class); | 25 | +public class IMFSender extends TimerTask { |
26 | + private static final Logger logger = Logger.getLogger(IMFSender.class); | ||
24 | private Dao dao = (DaoImpl)SystemBean.getBean("dao"); | 27 | private Dao dao = (DaoImpl)SystemBean.getBean("dao"); |
25 | private IMFClient client; | 28 | private IMFClient client; |
26 | private String indexFileName; | 29 | private String indexFileName; |
27 | 30 | ||
28 | - public SendMessageTask(IMFClient client, String fileName) { | 31 | + public IMFSender(IMFClient client, String fileName) { |
29 | this.indexFileName = fileName; | 32 | this.indexFileName = fileName; |
30 | this.client = client; | 33 | this.client = client; |
31 | } | 34 | } |
@@ -65,7 +68,8 @@ public class SendMessageTask extends TimerTask { | @@ -65,7 +68,8 @@ public class SendMessageTask extends TimerTask { | ||
65 | logger.info("准备发送数据 FID:" + m.getFid() + " XML.length=:" + m.getContent().length()); | 68 | logger.info("准备发送数据 FID:" + m.getFid() + " XML.length=:" + m.getContent().length()); |
66 | String sendMsg = Utils.searchReplace(m.getContent(), header.getSndr(), "SNDR"); | 69 | String sendMsg = Utils.searchReplace(m.getContent(), header.getSndr(), "SNDR"); |
67 | sendMsg = Utils.searchReplace(sendMsg, header.getType(), "TYPE"); | 70 | sendMsg = Utils.searchReplace(sendMsg, header.getType(), "TYPE"); |
68 | - sendMsg = Utils.searchReplace(sendMsg, header.getStype(), "STYP"); | 71 | + String stype = tranlateXML(m.getContent()); |
72 | + sendMsg = Utils.searchReplace(sendMsg, stype, "STYP"); | ||
69 | sendMsg = Utils.searchReplaceSingle(sendMsg, header.getRcvr(), "RCVR"); | 73 | sendMsg = Utils.searchReplaceSingle(sendMsg, header.getRcvr(), "RCVR"); |
70 | if (!"".equals(sendMsg)) { | 74 | if (!"".equals(sendMsg)) { |
71 | logger.info("开始发送数据 XML:" + sendMsg); | 75 | logger.info("开始发送数据 XML:" + sendMsg); |
@@ -79,7 +83,7 @@ public class SendMessageTask extends TimerTask { | @@ -79,7 +83,7 @@ public class SendMessageTask extends TimerTask { | ||
79 | } | 83 | } |
80 | } | 84 | } |
81 | 85 | ||
82 | - this.dao.update(m.getFid(), times); | 86 | +// this.dao.update(m.getFid(), times); |
83 | } else { | 87 | } else { |
84 | logger.info("FID=" + m.getFid() + "XML is null "); | 88 | logger.info("FID=" + m.getFid() + "XML is null "); |
85 | } | 89 | } |
@@ -96,4 +100,20 @@ public class SendMessageTask extends TimerTask { | @@ -96,4 +100,20 @@ public class SendMessageTask extends TimerTask { | ||
96 | } | 100 | } |
97 | 101 | ||
98 | } | 102 | } |
103 | + | ||
104 | + private static String tranlateXML(String xml) throws Exception { | ||
105 | + String stype = XMPParse.getNodeValueFromXmlString(xml, "/MSG/META/STYP"); | ||
106 | + if (!StringUtils.isBlank(stype)) { | ||
107 | + if (ConfigUtils.XTYPE_MAP.containsKey(stype)) { | ||
108 | + stype = (String)ConfigUtils.XTYPE_MAP.get(stype); | ||
109 | + } else { | ||
110 | + logger.info("stype=" + stype + " 在对应关系里找不到这个KEY"); | ||
111 | + } | ||
112 | + } else { | ||
113 | + logger.info(" 在XML找不到STYPE这个节点"); | ||
114 | + stype = ""; | ||
115 | + } | ||
116 | + | ||
117 | + return stype; | ||
118 | + } | ||
99 | } | 119 | } |
@@ -45,7 +45,7 @@ public class DaoImpl implements Dao { | @@ -45,7 +45,7 @@ public class DaoImpl implements Dao { | ||
45 | this.jdbcTemplate.update(new PreparedStatementCreator() { | 45 | this.jdbcTemplate.update(new PreparedStatementCreator() { |
46 | public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { | 46 | public PreparedStatement createPreparedStatement(Connection connection) throws SQLException { |
47 | DaoImpl.logger.info("oper=" + oper + " sndr=" + sndr); | 47 | DaoImpl.logger.info("oper=" + oper + " sndr=" + sndr); |
48 | - String sql = "insert into T_ETL_MESSAGE(OPER,SNDR,SNTM,content) values(?,?,sysdate,empty_clob())"; | 48 | + String sql = "insert into MESSAGE_BAK(OPER,SNDR,SNTM,content) values(?,?,sysdate,empty_clob())"; |
49 | PreparedStatement ps = connection.prepareStatement(sql, new String[]{"FID"}); | 49 | PreparedStatement ps = connection.prepareStatement(sql, new String[]{"FID"}); |
50 | ps.setString(1, oper); | 50 | ps.setString(1, oper); |
51 | ps.setString(2, sndr); | 51 | ps.setString(2, sndr); |
@@ -67,7 +67,7 @@ public class DaoImpl implements Dao { | @@ -67,7 +67,7 @@ public class DaoImpl implements Dao { | ||
67 | conn = this.jdbcTemplate.getDataSource().getConnection(); | 67 | conn = this.jdbcTemplate.getDataSource().getConnection(); |
68 | conn.setAutoCommit(false); | 68 | conn.setAutoCommit(false); |
69 | stmt = conn.createStatement(); | 69 | stmt = conn.createStatement(); |
70 | - String SQL = "select CONTENT from T_ETL_MESSAGE where FID=" + fid + " and SNDR='FIMS' for update"; | 70 | + String SQL = "select CONTENT from MESSAGE_BAK where FID=" + fid + " and SNDR='CFPS' for update"; |
71 | rs = stmt.executeQuery(SQL); | 71 | rs = stmt.executeQuery(SQL); |
72 | 72 | ||
73 | while(rs.next()) { | 73 | while(rs.next()) { |
@@ -108,15 +108,15 @@ public class DaoImpl implements Dao { | @@ -108,15 +108,15 @@ public class DaoImpl implements Dao { | ||
108 | } | 108 | } |
109 | 109 | ||
110 | public void delete(int fid) { | 110 | public void delete(int fid) { |
111 | - this.jdbcTemplate.update("delete from T_ETL_MESSAGE where fid=" + fid); | 111 | + this.jdbcTemplate.update("delete from MESSAGE_BAK where fid=" + fid); |
112 | } | 112 | } |
113 | 113 | ||
114 | public int getMaxFID() { | 114 | public int getMaxFID() { |
115 | - return this.jdbcTemplate.queryForInt("select max(FID) from T_ETL_MESSAGE where SNDR='FIMS'"); | 115 | + return this.jdbcTemplate.queryForInt("select max(FID) from MESSAGE_BAK where SNDR='CFPS'"); |
116 | } | 116 | } |
117 | 117 | ||
118 | public List<MessageBak> getRecordByFID(int fid) { | 118 | public List<MessageBak> getRecordByFID(int fid) { |
119 | - String SQL_FMT = "select FID,CONTENT from T_ETL_MESSAGE where (FID>%s and FID<%s+%s) and SNDR='FIMS' order by FID"; | 119 | + String SQL_FMT = "select FID,CONTENT from MESSAGE_BAK where (FID>%s and FID<%s+%s) and (SNDR='CFPS') order by FID"; |
120 | String sql = String.format(SQL_FMT, fid, fid, ConfigUtils.RECORD_COUNT); | 120 | String sql = String.format(SQL_FMT, fid, fid, ConfigUtils.RECORD_COUNT); |
121 | logger.info(sql); | 121 | logger.info(sql); |
122 | final LobHandler lobHandler = new DefaultLobHandler(); | 122 | final LobHandler lobHandler = new DefaultLobHandler(); |
@@ -148,11 +148,11 @@ public class DaoImpl implements Dao { | @@ -148,11 +148,11 @@ public class DaoImpl implements Dao { | ||
148 | } | 148 | } |
149 | 149 | ||
150 | public int getRecordCount() { | 150 | public int getRecordCount() { |
151 | - return this.jdbcTemplate.queryForInt("select count(*) from T_ETL_MESSAGE where SNDR='FIMS' "); | 151 | + return this.jdbcTemplate.queryForInt("select count(*) from MESSAGE_BAK where SNDR='CFPS' "); |
152 | } | 152 | } |
153 | 153 | ||
154 | public void update(int fid, int times) { | 154 | public void update(int fid, int times) { |
155 | - String sql = String.format("update T_ETL_MESSAGE set OUTFLAG=%s ,OUTTM=sysdate where FID=%s", times, fid); | 155 | + String sql = String.format("update MESSAGE_BAK set OUTFLAG=%s ,OUTTM=sysdate where FID=%s", times, fid); |
156 | logger.info("sql=" + sql); | 156 | logger.info("sql=" + sql); |
157 | this.jdbcTemplate.update(sql); | 157 | this.jdbcTemplate.update(sql); |
158 | } | 158 | } |
@@ -27,13 +27,26 @@ public class ConfigUtils { | @@ -27,13 +27,26 @@ public class ConfigUtils { | ||
27 | public static String XML_HEADER_STYPE = ""; | 27 | public static String XML_HEADER_STYPE = ""; |
28 | public static String XML_HEADER_RCVR = ""; | 28 | public static String XML_HEADER_RCVR = ""; |
29 | public static Map<Integer, XMLHeader> XML_HEADER_MAP = new HashMap(); | 29 | public static Map<Integer, XMLHeader> XML_HEADER_MAP = new HashMap(); |
30 | + public static String RCVR = ""; | ||
31 | + public static String APPID = ""; | ||
32 | + public static String SNDR = ""; | ||
33 | + public static Map<String, String> XTYPE_MAP = new HashMap(); | ||
30 | 34 | ||
31 | public ConfigUtils() { | 35 | public ConfigUtils() { |
32 | } | 36 | } |
33 | - | 37 | + private void initMap() { |
38 | + XTYPE_MAP.put("FSU_DEP", "UDEP"); | ||
39 | + XTYPE_MAP.put("FSU_RCF", "URCF"); | ||
40 | + XTYPE_MAP.put("FSU_FOH", "UFOH"); | ||
41 | + XTYPE_MAP.put("FZE_DEP", "EDEP"); | ||
42 | + XTYPE_MAP.put("FZE_RCF", "ERCF"); | ||
43 | + XTYPE_MAP.put("FZE_FOH", "EFOH"); | ||
44 | + XTYPE_MAP.put("CARGO_SERV", "CARG"); | ||
45 | + } | ||
34 | public void Initialize() throws LteException { | 46 | public void Initialize() throws LteException { |
35 | logger.debug("Loading all the config parameters..."); | 47 | logger.debug("Loading all the config parameters..."); |
36 | this.loadParameter(); | 48 | this.loadParameter(); |
49 | + this.initMap(); | ||
37 | } | 50 | } |
38 | 51 | ||
39 | private final void loadParameter() throws LteException { | 52 | private final void loadParameter() throws LteException { |
-
请 注册 或 登录 后发表评论