/// <summary>
        /// 删除内容
        /// </summary>
        /// <param name="id">内容表id</param>
        /// <returns></returns>
        private void DeleteContent(string id)
        {
            string delsql = string.Format("delete from t_sendsms where id={0} and CMSubmitStatus='1' and CUSubmitStatus='1' and CTSubmitStatus='1' ", id);
            int    result = MySqlDBExec.ExecuteNonQuery(delsql, null);

            if (result == 0)
            {
                SMSLog.Debug("SmsService==>DeleteContent[FailSql]:" + delsql);
            }
        }
        /// <summary>
        /// 修改ct提交状态,待下次读取
        /// </summary>
        /// <param name="id">内容表id</param>
        /// <param name="cTSubmitStatus">状态0 可读取,1已发完</param>
        /// <returns></returns>
        private void UpdateSMSContentSubmitStatu(string id, int cTSubmitStatus)
        {
            string sql    = string.Format("update  t_sendsms set CTSubmitStatus={0} where Id={1} ", cTSubmitStatus, id);
            int    result = MySqlDBExec.ExecuteNonQuery(sql, null);

            if (result == 0)
            {
                SMSLog.Debug("SmsService==>UpdateSMSContentSubmitStatu[FailSql]:" + sql);
            }
        }
        /// <summary>
        /// 根据批次号修改手机号码表状态
        /// </summary>
        /// <param name="state">状态:0未提交,-1失败,1成功</param>
        /// <param name="batchnum">批次号</param>
        /// <param name="errorCode">错误码</param>
        /// <param name="errMsg">错误说明</param>
        /// <returns></returns>
        private void UpdateMobileByBatchNum(int state, string batchnum, string errorCode, string errMsg)
        {
            string sql    = string.Format("update t_smsmobile_t set SubmitStatus={0},ErrorCode='{1}',Remark='{2}' where BatchNum='{3}'", state, errorCode, errMsg, batchnum);
            int    result = MySqlDBExec.ExecuteNonQuery(sql, null);

            if (result == 0)
            {
                SMSLog.Debug("SmsService==>UpdateSMSContentSubmitStatu[FailSql]:" + sql);
            }
        }
        /// <summary>
        /// 加载待发短信内容sql
        /// </summary>
        /// <returns></returns>
        protected string GetLoadMessageSql()
        {
            string rand      = GetTimesTamp(DateTime.Now).ToString();
            string updatesql = "update t_sendsms set CTSubmitStatus='" + rand + "'  where SendTime < NOW() and CheckStatus='1' and CTSubmitStatus='0' and (CTGatewayNum ='" + lp.GateWayNum + "' or CTGatewayNum='1001') order by Priority,SendTime limit " + lp.ReadContentNum + " ";
            int    result    = MySqlDBExec.ExecuteNonQuery(updatesql, null);

            if (result > 0)
            {
                string selecesql = "select * from t_sendsms where CTSubmitStatus='" + rand + "' and (CTGatewayNum ='" + lp.GateWayNum + "' or CTGatewayNum='1001') order by Priority,SendTime ";
                return(selecesql);
            }

            return("");
        }
        /// <summary>
        /// 更新手机号码提交状态、MSGID
        /// </summary>
        /// <param name="id">id</param>
        /// <param name="state">提交结果</param>
        /// <param name="msgid">msgid</param>
        /// <param name="srcno">发送号码</param>
        /// <returns></returns>
        private void UpdateMobileSubmitState(string id, string state, string msgid, string remark, string srcno)
        {
            int submitstatu = 0;

            if (state.Equals("0"))
            {
                submitstatu = 1;
                remark      = "成功";
            }
            string sql = string.Format("update t_smsmobile_t set MsgId='{0}',SubmitStatus='{1}',ErrorCode='{2}',Remark='{3}',SrcNo='{4}' where  id='{5}' ", msgid, submitstatu, state, remark, srcno, id);
            int    re  = 0;
            int    i   = 0;

            do
            {
                re = MySqlDBExec.ExecuteNonQuery(sql, null);
                i++;
            } while (re <= 0 && i < 3);

            if (re < 1)
            {
                SMSLog.Debug("SmsService==>UpdateMobileSubmitState[FailSql]:" + sql);
            }

            //重新加入缓存
            SmsModel sm = this.GetFormCache(id);

            if (sm != null)
            {
                this.AddCache(msgid, sm);
            }
            //失败状态,写入状态流水表
            if (submitstatu == 0)
            {
                if (sm != null)
                {
                    object[]          obj      = { sm.eprId, sm.userId, sm.mobile, sm.clientMsgId, submitstatu };
                    string            sqlstate = string.Format("insert into t_pushsmsmsg(EprId,UserId,Mobile,ClientMsgId,Status,AddTime) values('{0}','{1}','{2}','{3}','{4}',now())", obj);
                    Random            rand     = new Random();
                    int               ii       = rand.Next(0, _reportQueueNum + 1);
                    SqlStatementModel seq      = new SqlStatementModel();
                    seq.MySqlCmdParms = null;
                    seq.CmdTxt        = sqlstate;
                    seq.CmdType       = CommandType.Text;
                    seq.ExecTimer     = 1;
                    ReportSeqQueue[ii].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);
        }
示例#7
0
        public bool AddSql(SqlStatementModel sm)
        {
            bool ret = false;

            try
            {
                lock (((ICollection)sqlueue).SyncRoot)
                {
                    sqlueue.Enqueue(sm);
                }
                ret = true;
            }
            catch (Exception ex)
            {
                MySqlDBExec.ExecuteNonQuery(sm.CmdTxt, sm.MySqlCmdParms);
                SMSLog.Error("SMDQueue::addSql", "=================>Exception:" + ex.Message);
                ret = false;
            }
            return(ret);
        }
        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);
            }
        }
        public bool Start()
        {
            lp = new LocalParams();
            if (!dbexec.IsConn(lp.SqlConnStr))
            {
                SMSLog.Debug("SmsService==>Init=>sql登录失败[" + lp.SqlConnStr + "]");
                return(false);
            }
            MySqlDBExec.ConnectionstringLocalTransaction = lp.SqlConnStr;
            _cstDic         = new Dictionary <int, SendThread>();
            _cmppAccountDic = new Dictionary <int, AccountInfoModel>();
            //初始数据标识
            string sql1 = "update t_sendsms set CTSubmitStatus=0 Where  CTGatewayNum='" + lp.GateWayNum + "'";
            string sql2 = "update t_smsmobile_t set  smsFlag='0' where SubmitStatus='0' and GatewayNum='" + lp.GateWayNum + "'";
            int    re1  = MySqlDBExec.ExecuteNonQuery(sql1, null);

            SMSLog.Debug("SmsService==>Init初始内容表:" + re1);
            int re2 = MySqlDBExec.ExecuteNonQuery(sql2, null);

            SMSLog.Debug("SmsService==>Init初始手机号码表:" + re2);


            cache          = new TimeoutCache(60 * 30);//缓存
            ReportQueue    = new SMDQueue[_reportQueueNum];
            ReportSeqQueue = new SMDQueue[_reportQueueNum];
            for (int i = 0; i < _reportQueueNum; i++)
            {
                string title = "Report_" + i;
                ReportQueue[i] = new SMDQueue(title);
                ReportQueue[i].Start(3000);

                string seqt = "ReportSeq_" + i;
                ReportSeqQueue[i] = new SMDQueue(seqt);
                ReportSeqQueue[i].Start(4000);
            }

            /*
             * GlobalModel.UpdateMobileSubmitStateHandler = this.UpdateMobileSubmitState;
             * GlobalModel.UpdateReportStateHandler = this.UpdateReportState;
             * GlobalModel.UpdateMobileByBatchNumHandler = this.UpdateMobileByBatchNum;
             * GlobalModel.UpdateSMSContentSubmitStatuHandler = this.UpdateSMSContentSubmitStatu;
             * GlobalModel.DeleteContentHandler = this.DeleteContent;
             * GlobalModel.SaveMoHandler = this.SaveMo;
             * */

            //读取企业CMPP账号信息
            List <AccountInfoModel> accountLst = LoadCmppAccount();

            if (accountLst != null && accountLst.Count > 0)
            {
                foreach (AccountInfoModel m in accountLst)
                {
                    SendThread cmpp = new SendThread(m);

                    if (cmpp.Login())
                    {
                        _cstDic.Add(m.eprId, cmpp);
                        _cmppAccountDic.Add(m.eprId, m);
                        cmpp.IsSend = true;
                        cmpp.Start();
                    }
                    else
                    {
                        SMSLog.Debug("SmsService==>Init[" + m.eprId + "]登录失败");
                    }
                    Thread.Sleep(10);
                }
            }
            else
            {
                SMSLog.Debug("SmsService==>[Init]读取cmpp账号失败");
                return(false);
            }

            GlobalModel.IsStopCollect = false;
            CollectObject_Business co = new CollectObject_Business();

            _collDataTimer = new Timer(new TimerCallback(CollectThread), co, lp.ReadContentDealy, lp.ReadContentDealy);
            SMSLog.Debug("SmsService==>[Init]启动成功");
            return(true);
        }