private List <AccountInfoModel> LoadCmppAccount()
        {
            List <AccountInfoModel> lst = null;
            string    sql = "select * from t_spaccountinfo";
            DataTable dt  = MySqlDBExec.GetDateTable(sql, null);

            if (dt != null && dt.Rows.Count > 0)
            {
                lst = new List <AccountInfoModel>();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    AccountInfoModel aim = new AccountInfoModel();
                    aim.eprId        = int.Parse(dt.Rows[i]["EprId"].ToString());
                    aim.loginname    = dt.Rows[i]["LoginName"].ToString();
                    aim.password     = dt.Rows[i]["Password"].ToString();
                    aim.senddelay    = int.Parse(dt.Rows[i]["SendDelay"].ToString());
                    aim.serviceid    = dt.Rows[i]["ServiceId"].ToString();
                    aim.spid         = dt.Rows[i]["Pid"].ToString();
                    aim.protocolType = dt.Rows[i]["ProtocolType"].ToString();
                    aim.serviceIp    = dt.Rows[i]["ServiceIp"].ToString();
                    aim.servicePort  = int.Parse(dt.Rows[i]["ServicePort"].ToString());
                    aim.spnumber     = dt.Rows[i]["Spnumber"].ToString();
                    lst.Add(aim);
                }
            }
            return(lst);
        }
        /// <summary>
        /// 更新状态回执
        /// </summary>
        /// <param name="msgid">msgid</param>
        /// <param name="reportstatus">状态</param>
        /// <returns></returns>
        private void UpdateReportState(string msgid, string srcnumber, string reportstatus)
        {
            string status = reportstatus;

            if (reportstatus.Equals("DELIVRD"))
            {
                status = "1";
            }
            else
            {
                status = "-1";
            }
            SmsModel sm = this.GetFormCache(msgid);

            string sql = string.Format("update t_smsmobile_t set ReportStatus='{0}' ,ErrorCode='{1}',SrcNo='{2}' where  MsgId='{3}' ", status, reportstatus, srcnumber, msgid);

            if (sm != null)
            {
                sql = string.Format("update t_smsmobile_t set ReportStatus='{0}' ,ErrorCode='{1}',SrcNo='{2}' where  Id='{3}' ", status, reportstatus, srcnumber, sm.id);
            }
            Random            rand = new Random();
            int               i    = rand.Next(0, _reportQueueNum + 1);
            SqlStatementModel sqlm = new SqlStatementModel();

            sqlm.MySqlCmdParms = null;
            sqlm.CmdTxt        = sql;
            sqlm.CmdType       = CommandType.Text;
            sqlm.ExecTimer     = 1;
            ReportQueue[i].AddSql(sqlm);

            string sqlstate = "";

            if (sm != null)
            {
                object[] obj = { sm.eprId, sm.userId, sm.mobile, sm.clientMsgId, status };
                sqlstate = string.Format("insert into t_pushsmsmsg(EprId,UserId,Mobile,ClientMsgId,Status,AddTime) values('{0}','{1}','{2}','{3}','{4}',now())", obj);
            }
            else
            {
                string    sel = string.Format("select * from t_smsmobile_t where MsgId='{0}'", msgid);
                DataTable dt  = MySqlDBExec.GetDateTable(sel, null);
                if (dt != null && dt.Rows.Count > 0)
                {
                    object[] obj = { dt.Rows[0]["EprId"], dt.Rows[0]["UserId"], dt.Rows[0]["Mobile"], dt.Rows[0]["ClientMsgId"], status };
                    sqlstate = string.Format("insert into t_pushsmsmsg(EprId,UserId,Mobile,ClientMsgId,Status,AddTime) values('{0}','{1}','{2}','{3}','{4}',now())", obj);
                }
            }
            if (!string.IsNullOrEmpty(sqlstate))
            {
                SqlStatementModel seq = new SqlStatementModel();
                seq.MySqlCmdParms = null;
                seq.CmdTxt        = sqlstate;
                seq.CmdType       = CommandType.Text;
                seq.ExecTimer     = 1;
                ReportSeqQueue[i].AddSql(seq);
            }
        }
        /// <summary>
        /// 读取手机号码
        /// </summary>
        /// <param name="batchnum">批次号</param>
        /// <returns></returns>
        public DataTable LoadMobile(string batchnum)
        {
            string gwno = lp.GateWayNum + "";
            string rand = GetTimesTamp(DateTime.Now).ToString();
            //string sendtime = DateTime.Now.AddHours(-1).ToString();
            string updatecondition = " where GatewayNum ='" + gwno + "' and smsFlag='0' and SubmitStatus='0' and SendTime>date_add(now(),interval -1 hour) and BatchNum='" + batchnum + "'";
            string updatesql       = "update t_smsmobile_t set smsFlag=" + rand + " where GatewayNum ='" + gwno + "' and smsFlag='0' and SubmitStatus='0'  and BatchNum='" + batchnum + "' order by SendTime  limit " + lp.ReadMobileNum;

            if (MySqlDBExec.ExecuteNonQuery(updatesql, null) > 0)
            {
                string    selectsql = "select * from t_smsmobile_t where SendTime>date_add(now(),interval -1 hour)  and smsFlag='" + rand + "' and GatewayNum ='" + gwno + "'  and SubmitStatus='0' and BatchNum='" + batchnum + "'";
                DataTable dt        = MySqlDBExec.GetDateTable(selectsql, null);
                return(dt);
            }
            return(null);
        }
        private AccountInfoModel GetAccountInfo(int eprId)
        {
            string    sql = "select * from t_accountInfo where EprId=" + eprId;
            DataTable dt  = MySqlDBExec.GetDateTable(sql, null);

            if (dt != null && dt.Rows.Count > 0)
            {
                AccountInfoModel aim = new AccountInfoModel();
                aim.eprId        = int.Parse(dt.Rows[0]["EprId"].ToString());
                aim.loginname    = dt.Rows[0]["LoginName"].ToString();
                aim.password     = dt.Rows[0]["Password"].ToString();
                aim.senddelay    = int.Parse(dt.Rows[0]["SendDelay"].ToString());
                aim.serviceid    = dt.Rows[0]["ServiceId"].ToString();
                aim.spid         = dt.Rows[0]["Pid"].ToString();
                aim.protocolType = dt.Rows[0]["ProtocolType"].ToString();
                aim.serviceIp    = dt.Rows[0]["ServiceIp"].ToString();
                aim.servicePort  = int.Parse(dt.Rows[0]["ServicePort"].ToString());
                return(aim);
            }
            return(null);
        }
        private void SaveMo(int eprId, string mobile, string recvnumber, string content)
        {
            string    userId       = "";
            string    client_msgid = "";
            int       IsPush       = 0;
            string    sel          = string.Format("select * from t_smsmobile_t where EprId='{0}' and Mobile='{1}' order by SendTime desc limit 1", eprId, mobile);
            DataTable dt           = MySqlDBExec.GetDateTable(sel, null);

            if (dt != null && dt.Rows.Count > 0)
            {
                userId       = dt.Rows[0]["UserID"].ToString();
                client_msgid = dt.Rows[0]["ClientMsgId"].ToString();
            }
            object[] obj =
            {
                eprId,
                userId,
                "",
                mobile,
                recvnumber,
                DateTime.Now.ToString(),
                content,
                1,
                IsPush,
                DateTime.Now.ToString(),
                0,
                client_msgid
            };
            string insql = string.Format("insert into t_morecord(EprId,UserId,Name,SendNum,RecvNum,RecvTime,Content,IsNew,IsPush,AddTime,IsDel,ClientMsgId) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')", obj);
            int    re    = MySqlDBExec.ExecuteNonQuery(insql, null);

            if (re < 1)
            {
                SMSLog.Debug("SmsService==>SaveMo[FailSql]:" + insql);
            }
        }
        private void CollectThread(object obj)
        {
            if (GlobalModel.IsStopCollect)
            {
                return;
            }
            string sql = GetLoadMessageSql();

            if (!string.IsNullOrEmpty(sql))
            {
                DataTable dt = MySqlDBExec.GetDateTable(sql, null);
                if (dt != null && dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        string CTGatewayNum = dt.Rows[i]["CTGatewayNum"].ToString();
                        string id           = dt.Rows[i]["Id"].ToString();
                        string batchnum     = dt.Rows[i]["BatchNum"].ToString();
                        string eprId        = dt.Rows[i]["EprId"].ToString();
                        string con          = dt.Rows[i]["Content"].ToString();//短信内容
                        int    mobileCount  = 0;
                        int.TryParse(dt.Rows[i]["MobileCount"].ToString(), out mobileCount);
                        if (CTGatewayNum.Equals("1001"))
                        {
                            SMSLog.Debug("SMDDatabase==>该批次号[" + batchnum + "]1001不发送,修改tcsubmitstate状态为1 并试图删除");
                            UpdateSMSContentSubmitStatu(id, 1);
                            this.DeleteContent(id);
                            UpdateMobileByBatchNum(-1, batchnum, "1001", "限制网关");
                            continue;
                        }

                        DataTable dt_mobile = this.LoadMobile(batchnum);//根据批次号取发送号码
                        if (dt_mobile != null && dt_mobile.Rows.Count > 0)
                        {
                            for (int j = 0; j < dt_mobile.Rows.Count; j++)
                            {
                                SmsModel msg = new SmsModel();
                                msg.content   = con; //短信内容
                                msg.contentId = id;  //内容表ID
                                if (FillMessage(dt_mobile.Rows[j], msg))
                                {
                                    AddQueue(msg.eprId, msg);   //加入待发队列
                                    AddCache(msg.id + "", msg); //加入缓存
                                }
                            }
                            if (dt_mobile.Rows.Count <= mobileCount)
                            {
                                SMSLog.Debug("SMDDatabase==>该批次号[" + batchnum + "]已读取完,修改tcsubmitstate状态为1 并试图删除");
                                UpdateSMSContentSubmitStatu(id, 1);
                                this.DeleteContent(id);
                            }
                            else
                            {
                                UpdateSMSContentSubmitStatu(id, 0);//改变状态,待下次读取
                            }
                        }
                        else
                        {
                            try
                            {
                                SMSLog.Debug("SMDDatabase==>无该批次号[" + batchnum + "]手机号码,修改tcsubmitstate状态为1 并试图删除");
                                UpdateSMSContentSubmitStatu(id, 1);
                                this.DeleteContent(id);
                            }
                            catch (Exception ex)
                            {
                                SMSLog.Error("SMDDatabase::CollectThread", "删除异常: " + ex.Message);
                            }
                        }
                    }//for
                }
            }
        }