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

📄 objectdequeue.java

📁 中国联通短信通信协议
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.wireless.sms.gwif.smsagent.workthread;

/**
 * <p>Title: WVAS-PLATFORM-SMS-GWIF</p>
 * <p>Description: 无线增值业务平台-----短信接口机</p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: moon</p>
 * @author: tech team
 * @version 1.0
 * @content 记录MT,STAT到数据库
 */
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Calendar;

import org.apache.log4j.Logger;

import com.wireless.sms.gwif.smsagent.global.LoggerConstant;
import com.wireless.sms.gwif.smsagent.global.SmsGWIFGlobal;
import com.wireless.sms.pub.db.ConnectionPool;
import com.wireless.sms.pub.entity.MT;
import com.wireless.sms.pub.entity.Stat;
import com.wireless.sms.pub.mq.ObjectQueue;
import com.wireless.sms.pub.util.CTime;

public class ObjectDeQueue implements Runnable {

    private static Logger statlog = LoggerConstant.stat_log;
    private static Logger sqllog = LoggerConstant.sql_log;
//    private SmsGWIFGlobal smsagent = SmsGWIFGlobal.getInstance();
    private ObjectQueue statqueue = ObjectQueue.getInstance();
    //wtg 引用SmsGWIFGlobal中的连接
    private ConnectionPool pool = SmsGWIFGlobal.getInstance().POOL;//ConnectionPool.getInstance();
    private static boolean linkflag = true;

    public ObjectDeQueue() {
    }

    public static void stopThread() {
        linkflag = false;
    }

    public void run() {
        statlog.info("Stat ObjectQueue Start");
        while (linkflag) {
            String temptime = CTime.getTime(10).substring(6, 10);
            if (temptime.equals("1201") || temptime.equals("0001")) {
                sqllog.info("");
            }

            try {
                    Object obj = statqueue.removeNoWait();

                    if (obj != null) {
                        if (obj instanceof Stat) {
                            statlog.debug("process stat object ");
                            Stat stat = (Stat)obj;
                            String update = "";
                            String status = stat.getStat().trim().equalsIgnoreCase("DELIVRD") ?
                                            "R" : "O:" + stat.getStat();
                            if(stat.getStat().indexOf("DELIVRD")!=-1){
                                status = "R";
                            }
                            if (stat.getSubmitTime() != null && stat.getDoneTime().length() > 0)
                                update = "update SMS_MTRECORD set VC2STATUS='" + status +
                                         "',DATREPORT=to_date('" +
                                         "20" + stat.getDoneTime() +
                                         "','yyyymmddhh24=mi') where VC2MSGID2='" + stat.getMsgID() +
                                         "'";
                            else
                                update =
                                    "update SMS_MTRECORD set VC2STATUS='" + status +
                                    "',DATREPORT=sysdate where VC2MSGID2='" +
                                    stat.getMsgID() + "'";

                            if( this.executeUpdate(update) <= 0 ){
                                SaveFalStatus(stat);
                            }
                            statlog.debug("finished to process STAT object ");
                        }
                        else if (obj instanceof MT) {
                            statlog.debug("process MT object ");
                            MT mt = (MT)obj;
//                            boolean flag = SaveMT_JDBC(mt);
                            SaveMT_JDBC(mt);
                            statlog.debug("finished to process MT object ");
                        }
                    }
            }
            catch (Exception ex) {
                statlog.error("MODeQueue exception ,msg:" + ex.getMessage());
            }
            try {
                Thread.sleep(50);
            } catch (InterruptedException ex2) {
            }
        }
    }

    private synchronized boolean SaveMT_JDBC(MT mt) {
        boolean flag = false;
        String sql = "";
        //形成sql记录
        try {
            String mtId = mt.getMtID();
            String MsgId = "";
            int subtype = mt.getSubType();
            String sffs = mt.getRemark1();
            try {
                if (mt.getMsgID().length() > 0) {
                    MsgId = mt.getMsgID();
                } else {
                    MsgId = mt.getMtID();
                }
            } catch (Exception e) {
                MsgId = mt.getMtID();
            }
            if(MsgId == null){
                MsgId = "1";
            }
            int gatewayId = 0;
            try{
                gatewayId = Integer.parseInt(mt.getGatewayID());
            } catch (Exception e) {
                gatewayId = 0;
            }
            String content = mt.getMsgContent();
            try {
                content = content.replaceAll("'", " ");
            } catch (Exception w) {
                content = "";
            }

            String srcTermId = "";
            try {
                srcTermId = mt.getSrcTermID();
            } catch (Exception w) {
                srcTermId = "";
            }

            String destTermId = "";
            try {
                destTermId = mt.getDestTermID();
            } catch (Exception w) {
                destTermId = "";
            }
            String feeTermId = "";
            try {
                feeTermId = mt.getFeeTermID();
            } catch (Exception w) {
                feeTermId = "";
            }
            String feeUserType = "";
            try {
                feeUserType = mt.getFeeUserType();
            } catch (Exception w) {
                feeUserType = "";
            }
            String feeValue =  mt.getFeeType();

            String sendTime = "";
            try {
                sendTime = mt.getSendTime();
            } catch (Exception w) {
                sendTime = "20041001000000";
            }
//            if(sendTime.equals("")){
//                sendTime = "20041001000000";
//            }

            String respTime = "";
            try {
                respTime = mt.getRespTime();
            } catch (Exception w) {
                respTime = "20041001000000";
            }
//            if(respTime.equals("")){
//                respTime = "20041001000000";
//            }

            String agentFlag = "0";
            String moreLateMtFlag = "";
            try {
                if (!mt.getMoreLateToMTFlag().trim().equalsIgnoreCase("")) //联通
                    moreLateMtFlag = mt.getMoreLateToMTFlag();
                else
                    moreLateMtFlag = mt.getIsImBalance();
            } catch (Exception w) {
                moreLateMtFlag = "0";
            }

            int cityID = 0;
            try {
                cityID = Integer.parseInt(mt.getCityID());
            } catch (Exception e) {
                cityID = 0;
            }
            String status = mt.getStatus();
            java.util.Calendar cal = java.util.Calendar.getInstance();
//            int partionId = cal.get(cal.MONTH) + 1;
            int partionId = cal.get(java.util.Calendar.MONTH) + 1;

            int mtType = 0;
            try {
                mtType = Integer.parseInt(mt.getMtType());
            } catch (Exception e) {
                mtType = 2;
            }
            int serviceId = 0;
            try {
                serviceId = Integer.parseInt(mt.getServiceID());
            } catch (Exception e) {
                serviceId = 0;
            }
            String isImBalance = mt.getIsImBalance();
            int smTypeId = 0;
            try {
                smTypeId = Integer.parseInt(mt.getSmTypeID());
            } catch (Exception w) {
                smTypeId = 0;
            }

            String feecode = mt.getFeeCode();

            String pcode = mt.getServiceCode();
            String className = mt.getProcessClass();
            int mouseId = 0;
            try {
                mouseId = Integer.parseInt(mt.getMouseID());
            } catch (Exception e) {
                mouseId = 0;
            }

            int provinceId = 0;
            try {
                provinceId = Integer.parseInt(mt.getProvinceID());
            } catch (Exception e) {
                provinceId = 0;
            }

            int mspackageId = 0;
            try {
                mspackageId = Integer.parseInt(mt.getMousePackageID());
            } catch (Exception e) {
                mspackageId = 0;
            }

//            String mouseGroup = mt.getMouseGroupID();
//            try {
//                Integer.parseInt(mt.getMouseGroupID());
//            } catch (Exception e) {
//                mouseGroup = "0";
//            }

            int msgFormat = 0;
            try {
                msgFormat = Integer.parseInt(mt.getMsgFormat());
            } catch (Exception e) {
                msgFormat = 0;
            }
            String moId = "";
            if (mt.getMoID().length() > 0) {
                moId = mt.getMoID();
            }
            //包月业务非扣费话单
            if ((!mt.getMtType().equals("1")) && mt.getFeeType().equals("3")) {
                feecode = "0";
            } else if (mt.getFeeType().equals("1")) {
                feecode = "0";
            }
            sql = "insert into sms_mtrecord(" +
                  "NUMMTID,VC2MSGID,VC2MSGID2,NUMGATEWAYID,VC2CONTENT," +
                  "VC2SRCTERMID,VC2DESTTERMID,VC2FEETERMID,VC2FEEUSERTYPE,VC2FEEVALUE," +
                  "DATSENDTIME,DATRESPONSE,VC2AGENTFLAG,VC2MORELATETOMTFLAG,NUMCITYID," +
                  "VC2STATUS,NUMPARTIONID,NUMMTTYPE,NUMSRVID,VC2ISIMBALANCE," +
                  "NUMSMTYPEID,VC2FEECODE,VC2PCODE,VC2CLASSNAME,NUMMOUSEID," +
                  "NUMPROVINCEID,NUMMSPACKAGEID,NUMMSGFORMAT,NUMMOUSEGROUP,VC2MOID,numsubtype,vc2sffs)" +
                  "values(" + "SMS_MTRECORD_SEQ.nextval" + ",'" + mtId + "','" + MsgId + "'," + gatewayId + ",'" + content +
                  "','" + srcTermId + "','" + destTermId + "','" + feeTermId + "','" + feeUserType + "','" + feeValue +
                  "',to_date('" + sendTime + "','YYYY-MM-DD HH24:MI:SS')," + "to_date('" + respTime + "','YYYY-MM-DD HH24:MI:SS'),'" + agentFlag +
                  "','" + moreLateMtFlag + "'," + cityID + ",'" + status + "'," + partionId + "," + mtType +
                  "," + serviceId + ",'" + isImBalance + "'," + smTypeId + ",'" + feecode + "','" + pcode +
                  "','" + className + "'," + mouseId + "," + provinceId + "," + mspackageId + "," + msgFormat +
                  "," + 0 + ",'" + moId + "'," + subtype + ",'" + sffs + "')";

            //取得数据库连接,执行sql语句
            if ( this.executeUpdate(sql) > 0) {
                flag = true;
            }

        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -