?? commondata.java
字號:
package com.wireless.sms.ismp.global;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import org.apache.log4j.Logger;
import com.wireless.sms.ismp.InitHandler;
public class CommonData {
//kk add at 2005-6-15 增加廣東電信根據業務代碼獲取定制、退定指令 map 表
private static Map keymap = null;
private static Logger molog = LoggerConstant.mo_log;
public static boolean reload = false;
//kk add at 2005-6-15 增加根據 MTType 字段匹配相應表 map
private static Map mttypeMap = null;
private static long lastTime = 0;
private static long mttypeLastTime = 0;
//用于測試路由
private static Hashtable testData = new Hashtable();
private static String _gateWayId = InitHandler.GATEWAYID;
public static Hashtable getTestData() {
return testData;
}
public static Map getKeyMap() {
if (keymap == null || reload ||
System.currentTimeMillis() - lastTime > 30 * 60 * 1000) {
molog.info("更新定制、退定指令表");
String gatewayID = InitHandler.GATEWAYID;
Connection conn = null;
Statement stmt = null;
/** sms_pcode表是相關網關業務配置詳表;
* vc2pcode業務代碼,VC2KEYWORDSUB1定制指令1,VC2LONGCODESUB1定制指令1對應的長號碼
* vc2isblurkeywordsub1是否模糊匹配定制指令1(0-不模糊 1-模糊),
* VC2KEYWORDUNSUB1退定指令1,VC2LONGCODEUNSUB1退定指令1對應的長號碼*/
Hashtable tempMap = new Hashtable();
String sql = "select t.vc2pcode, t.VC2KEYWORDSUB1, t.VC2LONGCODESUB1, t.vc2isblurkeywordsub1, " +
"t.VC2KEYWORDUNSUB1, t.VC2LONGCODEUNSUB1 " +
" from smsplatform.sms_pcode t " +
"where t.numgatewayid = " + gatewayID + " " +
"and t.NUMMOBCLASS = 2 " +
"and t.vc2isactive = 1 ";
try {
conn = DBPool.POOL.getConnection();
stmt = conn.createStatement();
ResultSet rst = stmt.executeQuery(sql);
while (rst.next()) {
String pcode = rst.getString("vc2pcode");
if (pcode == null) {//業務代碼不能為空
continue;
}
pcode = pcode == null ? "" : pcode.trim();
String keywordsub1 = rst.getString("VC2KEYWORDSUB1");
keywordsub1 = keywordsub1 == null ? "" : keywordsub1.trim();
molog.info("...定制業務 : " + pcode);
molog.info("定制指令 : " + keywordsub1);
String longcodesub1 = rst.getString("VC2LONGCODESUB1");
longcodesub1 = (longcodesub1 == null || longcodesub1.equals("")) ?
" " : longcodesub1.trim();
String isblurkeywordsub = rst.getString("vc2isblurkeywordsub1");
if (isblurkeywordsub == null) {
isblurkeywordsub = "";
}
if (!isblurkeywordsub.equals("1")) {
isblurkeywordsub = "0";
}
String keywordunsub1 = rst.getString("VC2KEYWORDUNSUB1");
keywordunsub1 = keywordunsub1 == null ? "" : keywordunsub1.trim();
molog.info("退定指令 : " + keywordunsub1);
String longcodeunsub1 = rst.getString("VC2LONGCODEUNSUB1");
longcodeunsub1 = (longcodeunsub1 == null || longcodeunsub1.equals("")) ?
" " : longcodeunsub1.trim();
tempMap.put(pcode,
keywordsub1 + ":" + longcodesub1 + ":" + keywordunsub1 +
":" + longcodeunsub1 + ":" +
isblurkeywordsub);
}
keymap = new Hashtable(tempMap);
molog.info("更新定制、退定指令表完畢");
}
catch (Exception e) {
e.printStackTrace();
molog.error("更新定制、退定指令表異常 : ", e);
SendThread.getInstance().sendmonitor("D000001");
}
finally {
if (stmt != null) {
try {
stmt.close();
stmt = null;
}
catch (SQLException ex) {
}
}
if (conn != null) {
try {
conn.close();
conn = null;
}
catch (SQLException ex1) {
}
}
}
lastTime = System.currentTimeMillis();
}
return keymap;
}
public static Map getCNKeyMap() {
if (keymap == null || reload ||
System.currentTimeMillis() - lastTime > 30 * 60 * 1000) {
molog.info("更新定制、退定指令表");
String gatewayID = InitHandler.GATEWAYID;
Connection conn = null;
Statement stmt = null;
Hashtable tempMap = new Hashtable();
String sql = "select t.vc2pcode, t.VC2KEYWORDSUB1, t.VC2LONGCODESUB1, t.vc2isblurkeywordsub1, " +
"t.VC2KEYWORDUNSUB1, t.VC2LONGCODEUNSUB1 " +
" from smsplatform.sms_pcode t " +
"where t.numgatewayid = " + gatewayID + " " +
"and t.NUMMOBCLASS = 2 " +
"and t.vc2isactive = 1 ";
try {
conn = DBPool.POOL.getConnection();
stmt = conn.createStatement();
ResultSet rst = stmt.executeQuery(sql);
while (rst.next()) {
String pcode = rst.getString("vc2pcode");
if (pcode == null) {
continue;
}
pcode = pcode == null ? "" : pcode.trim();
String keywordsub1 = rst.getString("VC2KEYWORDSUB1");
keywordsub1 = keywordsub1 == null ? "" : keywordsub1.trim();
molog.info("定制指令 : " + keywordsub1);
String longcodesub1 = rst.getString("VC2LONGCODESUB1");
longcodesub1 = (longcodesub1 == null || longcodesub1.equals("")) ?
" " : longcodesub1.trim();
String isblurkeywordsub = rst.getString("vc2isblurkeywordsub1");
if (isblurkeywordsub == null) {
isblurkeywordsub = "";
}
if (!isblurkeywordsub.equals("1")) {
isblurkeywordsub = "0";
}
String keywordunsub1 = rst.getString("VC2KEYWORDUNSUB1");
keywordunsub1 = keywordunsub1 == null ? "" : keywordunsub1.trim();
molog.info("退定指令 : " + keywordunsub1);
String longcodeunsub1 = rst.getString("VC2LONGCODEUNSUB1");
longcodeunsub1 = (longcodeunsub1 == null || longcodeunsub1.equals("")) ?
" " : longcodeunsub1.trim();
tempMap.put(pcode,
keywordsub1 + ":" + longcodesub1 + ":" + keywordunsub1 +
":" + longcodeunsub1 + ":" +
isblurkeywordsub);
}
keymap = new Hashtable(tempMap);
molog.info("更新定制、退定指令表完畢");
}
catch (Exception e) {
e.printStackTrace();
molog.error("更新定制、退定指令表異常 : ", e);
SendThread.getInstance().sendmonitor("D000001");
}
finally {
if (stmt != null) {
try {
stmt.close();
stmt = null;
}
catch (SQLException ex) {
}
}
if (conn != null) {
try {
conn.close();
conn = null;
}
catch (SQLException ex1) {
}
}
}
lastTime = System.currentTimeMillis();
}
return keymap;
}
/**返回匹配上該定制指令的業務代碼
* keyMap.put(pcode,
keywordsub1 + ":" + longcodesub1 + ":" + keywordunsub1 +
":" + longcodeunsub1 + ":" +
isblurkeywordsub)
注釋:pcode業務代碼,keywordsub1定制指令1,longcodesub1定制指令1對應的長號碼
* isblurkeywordsub是否模糊匹配定制指令1(0-不模糊 1-模糊),
* keywordunsub1退定指令1,longcodeunsub1退定指令1對應的長號碼*/
public static String getService(String keyword) {
String service = null;
for (Iterator ite = CommonData.getKeyMap().keySet().iterator(); ite.hasNext(); ) {
String tmpMsgContent = "";
String isblurkey = "";
String serviceTmp = "";
try {
serviceTmp = (String) ite.next();
String[] content = ( (String) CommonData.getKeyMap().get(serviceTmp)).
split(":");
tmpMsgContent = content[0].trim();
isblurkey = content[4].trim();
}
catch (Exception e) {
molog.error("根據指令取業務代碼時異常:\n" + e.getMessage());
tmpMsgContent = "";
}
if ( (tmpMsgContent.equalsIgnoreCase(keyword) && isblurkey.equals("0")) ||
(keyword.toLowerCase().startsWith(tmpMsgContent.toLowerCase()) &&
isblurkey.equals("1")) ||
(keyword.toLowerCase().equalsIgnoreCase(tmpMsgContent.toLowerCase()) &&
isblurkey.equals("0"))) {
service = serviceTmp;
break;//added by mazy
}
}
return service;
}
public static Map getMttypeMapBak() {
if (mttypeMap == null || reload ||
System.currentTimeMillis() - mttypeLastTime > 4 * 60 * 60 * 1000) {
molog.info("更新 MT Type 表");
Connection conn = null;
Statement stmt = null;
Hashtable tempMap = new Hashtable();
String sql = "select * from sms_mtlogparameter t";
try {
conn = DBPool.POOL.getConnection();
stmt = conn.createStatement();
ResultSet rst = stmt.executeQuery(sql);
while (rst.next()) {
String mttype = rst.getString("nummtype");
String issend = rst.getString("vc2isend");
String savetable = rst.getString("vc2savetable");
// molog.info("type : " + mttype + " isSend : " + issend + " table : " + savetable);
tempMap.put(mttype, issend + ":" + savetable);
}
mttypeMap = new Hashtable(tempMap);
molog.info("更新 MT Type 表完畢");
}
catch (Exception e) {
e.printStackTrace();
molog.error(e.getMessage());
molog.error("更新 MT Type 表異常 : ", e);
SendThread.getInstance().sendmonitor("D000001");
}
finally {
if (stmt != null) {
try {
stmt.close();
stmt = null;
}
catch (SQLException ex) {
}
}
if (conn != null) {
try {
conn.close();
conn = null;
}
catch (SQLException ex1) {
}
}
}
mttypeLastTime = System.currentTimeMillis();
}
return mttypeMap;
}
public static Map getMttypeMap() {
if (mttypeMap == null || reload) {
molog.info("加載 MT Type 表");
Hashtable tempMap = new Hashtable();
//2 0 0 sms_mtrecordother
tempMap.put("0", "0" + ":" + "sms_mtrecordother");
tempMap.put("1", "1" + ":" + "sms_mtrecordbill");
tempMap.put("2", "1" + ":" + "sms_mtrecordbz");
tempMap.put("3", "0" + ":" + "sms_mtrecordother");
tempMap.put("4", "1" + ":" + "sms_mtrecordpush");
tempMap.put("5", "1" + ":" + "sms_mtrecordother");
tempMap.put("6", "1" + ":" + "sms_mtrecordother");
tempMap.put("7", "1" + ":" + "sms_mtrecordother");
tempMap.put("8", "1" + ":" + "sms_mtrecordother");
mttypeMap = new Hashtable(tempMap);
}
return mttypeMap;
}
public static void updateTestData() {
testData.clear();
String sql = "select t.VC2SRCTERMID,t.VC2DESTTERMID,t.VC2CONTENT,t.VC2ROUTERIP,t.NUMROUTERPORT" +
" from sms_testservice t where t.NUMGATEWAYID='" + _gateWayId +
"' and t.NUMVALID='1'";
Connection conn = null;
Statement stmt = null;
ResultSet rst = null;
try {
conn = DBPool.POOL.getConnection();
stmt = conn.createStatement();
rst = stmt.executeQuery(sql);
while (rst.next()) {
String srcTermid = rst.getString("VC2SRCTERMID");
if (srcTermid == null) {
continue;
}
molog.info("測試號碼 : " + srcTermid);
srcTermid = srcTermid == null ? "" : srcTermid.trim();
String destTermid = rst.getString("VC2DESTTERMID");
destTermid = destTermid == null ? "" : destTermid.trim();
String content = rst.getString("VC2CONTENT");
content = (content == null) ? "" : content.trim();
String routerip = rst.getString("VC2ROUTERIP");
routerip = (routerip == null) ? "" : routerip.trim();
int routerPort = rst.getInt("NUMROUTERPORT");
molog.info("測試路由 " + routerip + ":" + routerPort);
testData.put(srcTermid,
destTermid + ":" + content + ":" + routerip + ":" +
routerPort);
}
molog.info("更新測試表完畢");
}
catch (Exception e) {
e.printStackTrace();
molog.error("更新測試表異常 : ", e);
SendThread.getInstance().sendmonitor("D000001");
}
finally {
if (rst != null) {
try {
rst.close();
rst = null;
}
catch (SQLException ex2) {
}
}
if (stmt != null) {
try {
stmt.close();
stmt = null;
}
catch (SQLException ex) {
}
}
if (conn != null) {
try {
conn.close();
conn = null;
}
catch (SQLException ex1) {
}
}
}
}
public static void main(String args[]) {
// SmsGWIFGlobal global = SmsGWIFGlobal.getInstance();
// global.initYD_System();
//
// Map tmpMap = getMttypeMap();
// for (Iterator ite = tmpMap.keySet().iterator(); ite.hasNext(); ) {
// String key = (String)ite.next();
// System.out.println("Key : " + key + " value : " + tmpMap.get(key));
// }
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -