⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commondata.java

📁 中国联通短信通信协议
💻 JAVA
字号:
package com.wireless.sms.gwif.smsagent.func;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

import java.util.*;
import java.sql.*;
//import java.io.*;
import org.apache.log4j.Logger;

import com.wireless.sms.gwif.smsagent.global.*;
import com.wireless.sms.gwif.smsagent.entity.CT;
import com.wireless.sms.gwif.smsagent.entity.CN;

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 = SmsGWIFGlobal.getInstance().GATEWAY;

  public static Hashtable getTestData() {
    return testData;
  }

  public static Map getKeyMap() {

    if (keymap == null || reload ||
        System.currentTimeMillis() - lastTime > 30 * 60 * 1000) {
      molog.info("更新定制、退定指令表");

      String gatewayID = CT.getInstance().getGatewayID();

      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 = SmsGWIFGlobal.getInstance().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);
        SmsGWIFGlobal.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 = CN.getInstance().getGatewayID();

      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 = SmsGWIFGlobal.getInstance().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);
        SmsGWIFGlobal.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 = SmsGWIFGlobal.getInstance().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);
        SmsGWIFGlobal.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 = SmsGWIFGlobal.getInstance().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);
      SmsGWIFGlobal.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 + -