/// <summary>
        /// 发送短信,并将已发送的信息写入数据库
        /// </summary>
        /// <param name="smsModel"></param>
        /// <param name="dt"></param>
        private static void SmsSendAndInsert(SmsSendInfo smsModel, DataTable dt)
        {
            try
            {
                SmsSend smssBll = new SmsSend();

                DataRow dr = null;
                if (dt != null && dt.Rows.Count > 0)
                {
                    dr = dt.Rows[0];
                }

                bool isSuccess = SmsHelper.SmsSendByPost(smsModel.MobilePhone, smsModel.SmsContent);

                DateTime currTime = DateTime.Now;
                string[] mobiles  = smsModel.MobilePhone.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string mobile in mobiles)
                {
                    SmsSendInfo model = new SmsSendInfo();
                    model.UserId          = smsModel.UserId;
                    model.OrderCode       = smsModel.OrderCode == null ? "" : smsModel.OrderCode;
                    model.CarScanCode     = smsModel.CarScanCode == null ? "" : smsModel.CarScanCode;
                    model.TranNode        = smsModel.TranNodeText == null ? "" : smsModel.TranNodeText;
                    model.Receiver        = smsModel.Receiver == null ? "" : smsModel.Receiver;
                    model.MobilePhone     = smsModel.MobilePhone = mobile;
                    model.SmsContent      = smsModel.SmsContent;
                    model.SendDate        = currTime;
                    model.LastUpdatedDate = currTime;
                    model.SendStatus      = (short)2;
                    if (isSuccess)
                    {
                        model.SendStatus = (short)1;
                    }
                    model.Customer = "";
                    if (dr != null && dr["Customer"] != DBNull.Value)
                    {
                        model.Customer = dr["Customer"].ToString().Trim();
                    }

                    smssBll.Insert(model);
                }
            }
            catch (Exception ex)
            {
                string error = "";
                error += "手机号:" + smsModel.MobilePhone == null ? "无" : smsModel.MobilePhone + ",";
                error += "订单号:" + smsModel.OrderCode == null ? "无" : smsModel.OrderCode + ",";
                error += "运输节点:" + smsModel.TranNodeText == null ? "无" : smsModel.TranNodeText + ",";
                error += "派车单号:" + smsModel.CarScanCode == null ? "无" : smsModel.CarScanCode + ",";
                error += "短信内容:" + smsModel.SmsContent == null ? "无" : smsModel.SmsContent + ",";
                WriteLog log = new WriteLog();
                log.Write("执行添加短信发送数据到数据库异常(" + ex.Message + "),详情:" + error + "");
            }
        }
Esempio n. 2
0
        public List <SmsSendInfo> GetList(int pageIndex, int pageSize, string sqlWhere, params SqlParameter[] cmdParms)
        {
            int    startIndex = (pageIndex - 1) * pageSize + 1;
            int    endIndex   = pageIndex * pageSize;
            string cmdText    = @"select * from(select row_number() over(order by LastUpdatedDate desc) as RowNumber,
                             Id,UserId,OrderCode,CarScanCode,TranNode,Receiver,MobilePhone,Customer,SmsContent,
                             SendDate,SendStatus,LastUpdatedDate
                             from [Sms_Send] ";

            if (!string.IsNullOrEmpty(sqlWhere))
            {
                cmdText += "where 1=1 " + sqlWhere;
            }
            cmdText += ")as objTable where RowNumber between " + startIndex + " and " + endIndex + " ";

            List <SmsSendInfo> list = new List <SmsSendInfo>();

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, cmdParms))
            {
                if (reader != null && reader.HasRows)
                {
                    while (reader.Read())
                    {
                        SmsSendInfo model = new SmsSendInfo();
                        model.Id              = reader["Id"];
                        model.UserId          = reader["UserId"];
                        model.OrderCode       = reader.GetString(3);
                        model.CarScanCode     = reader.GetString(4);
                        model.TranNode        = reader.GetString(5);
                        model.Receiver        = reader.GetString(6);
                        model.MobilePhone     = reader.GetString(7);
                        model.Customer        = reader.GetString(8);
                        model.SmsContent      = reader.GetString(9);
                        model.SendDate        = reader.GetDateTime(10);
                        model.SendStatus      = reader.GetInt16(11);
                        model.LastUpdatedDate = reader.GetDateTime(12);

                        list.Add(model);
                    }
                }
            }

            return(list);
        }
Esempio n. 3
0
        public int Update(SmsSendInfo model)
        {
            if (model == null)
            {
                return(-1);
            }

            //定义查询命令
            string cmdText = @"update [Sms_Send] set UserId = @UserId,OrderCode = @OrderCode,CarScanCode = @CarScanCode,TranNode = @TranNode,
                             Receiver = @Receiver,MobilePhone = @MobilePhone,Customer = @Customer,SmsContent = @SmsContent,SendDate = @SendDate,
                             SendStatus = @SendStatus,LastUpdatedDate = @LastUpdatedDate
                             where Id = @Id";

            SqlParameter[] parms =
            {
                new SqlParameter("@Id",              SqlDbType.UniqueIdentifier),
                new SqlParameter("@UserId",          SqlDbType.UniqueIdentifier),
                new SqlParameter("@OrderCode",       SqlDbType.VarChar,            36),
                new SqlParameter("@CarScanCode",     SqlDbType.VarChar,            36),
                new SqlParameter("@TranNode",        SqlDbType.NVarChar,           20),
                new SqlParameter("@Receiver",        SqlDbType.NVarChar,           20),
                new SqlParameter("@MobilePhone",     SqlDbType.VarChar,            15),
                new SqlParameter("@Customer",        SqlDbType.NVarChar,           20),
                new SqlParameter("@SmsContent",      SqlDbType.NVarChar,          500),
                new SqlParameter("@SendDate",        SqlDbType.DateTime),
                new SqlParameter("@SendStatus",      SqlDbType.TinyInt),
                new SqlParameter("@LastUpdatedDate", SqlDbType.DateTime)
            };
            parms[0].Value  = model.Id;
            parms[1].Value  = model.UserId;
            parms[2].Value  = model.OrderCode;
            parms[3].Value  = model.CarScanCode;
            parms[4].Value  = model.TranNode;
            parms[5].Value  = model.Receiver;
            parms[6].Value  = model.MobilePhone;
            parms[7].Value  = model.Customer;
            parms[8].Value  = model.SmsContent;
            parms[9].Value  = model.SendDate;
            parms[10].Value = model.SendStatus;
            parms[11].Value = model.LastUpdatedDate;

            return(SqlHelper.ExecuteNonQuery(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, parms));
        }
        //号码整合以批次实现发送
        private void QueuedSendSms(dynamic rows, string url, object token, object NodeId)
        {
            //按批次号实现号码整合
            List <SmsSendInfo> sendlist = new List <SmsSendInfo>();

            IDictionary <string, object> tmpdic;
            int         count = 0;
            SmsSendInfo smsSendInfo;

            foreach (var row in rows)
            {
                dynamic list = new ExpandoObject();
                DynamicAdapter.Parse(list, System.Xml.Linq.XElement.Parse(row.ToString()));
                tmpdic      = list.StringObjectDictionary as IDictionary <string, object>;
                smsSendInfo = new SmsSendInfo();
                smsSendInfo.SerialNumber = e0571.web.core.Utils.TypeConverter.ChangeString(tmpdic["BatchNum"]);
                smsSendInfo.ScheduleTime = e0571.web.core.Utils.TypeConverter.ChangeString(tmpdic["ScheduleTime"], "");
                smsSendInfo.SendCatalog  = e0571.web.core.Utils.TypeConverter.ChangeString(tmpdic["SendCatalog"]);
                smsSendInfo.UserNumber   = e0571.web.core.Utils.TypeConverter.ChangeString(tmpdic["Mobile"]);
                if (e0571.web.core.Utils.TypeConverter.ChangeString(tmpdic["SendCatalog"]) == "0")
                {
                    smsSendInfo.MessageContent = e0571.web.core.Utils.TypeConverter.ChangeString(tmpdic["SourceCatalog"]) + ":";
                }
                smsSendInfo.MessageContent += e0571.web.core.Utils.TypeConverter.ChangeString(tmpdic["SendContent"]);

                count = sendlist.Count(s => s.SerialNumber == smsSendInfo.SerialNumber);
                if (sendlist.Count == 0 || count == 0)
                {
                    sendlist.Add(smsSendInfo);
                }
                if (count > 0)
                {
                    sendlist.FirstOrDefault(s => s.SerialNumber == smsSendInfo.SerialNumber).UserNumber += "," + smsSendInfo.UserNumber;
                }
            }

            if (sendlist.Count > 0)
            {
                SendSms(sendlist, url, token, NodeId);
            }
        }
Esempio n. 5
0
        public List <SmsSendInfo> GetList(string sqlWhere, params SqlParameter[] cmdParms)
        {
            string cmdText = @"select Id,UserId,OrderCode,CarScanCode,TranNode,Receiver,MobilePhone,Customer,SmsContent,
                             SendDate,SendStatus,LastUpdatedDate
                             from [Sms_Send] ";

            if (!string.IsNullOrEmpty(sqlWhere))
            {
                cmdText += "where 1=1 " + sqlWhere;
            }

            List <SmsSendInfo> list = new List <SmsSendInfo>();

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, cmdParms))
            {
                if (reader != null && reader.HasRows)
                {
                    while (reader.Read())
                    {
                        SmsSendInfo model = new SmsSendInfo();
                        model.Id              = reader["Id"];
                        model.UserId          = reader["UserId"];
                        model.OrderCode       = reader.GetString(2);
                        model.CarScanCode     = reader.GetString(3);
                        model.TranNode        = reader.GetString(4);
                        model.Receiver        = reader.GetString(5);
                        model.MobilePhone     = reader.GetString(6);
                        model.Customer        = reader.GetString(7);
                        model.SmsContent      = reader.GetString(8);
                        model.SendDate        = reader.GetDateTime(9);
                        model.SendStatus      = reader.GetInt16(10);
                        model.LastUpdatedDate = reader.GetDateTime(11);

                        list.Add(model);
                    }
                }
            }

            return(list);
        }
Esempio n. 6
0
        public SmsSendInfo GetModel(object Id)
        {
            SmsSendInfo model = null;

            string       cmdText = @"select top 1 Id,UserId,OrderCode,CarScanCode,TranNode,Receiver,MobilePhone,Customer,SmsContent,
                            SendDate,SendStatus,LastUpdatedDate 
                            from [Sms_Send] where Id = @Id ";
            SqlParameter parm    = new SqlParameter("@Id", SqlDbType.UniqueIdentifier);

            parm.Value = Guid.Parse(Id.ToString());

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, parm))
            {
                if (reader != null)
                {
                    while (reader.Read())
                    {
                        model                 = new SmsSendInfo();
                        model.Id              = reader["Id"];
                        model.UserId          = reader["UserId"];
                        model.OrderCode       = reader.GetString(2);
                        model.CarScanCode     = reader.GetString(3);
                        model.TranNode        = reader.GetString(4);
                        model.Receiver        = reader.GetString(5);
                        model.MobilePhone     = reader.GetString(6);
                        model.Customer        = reader.GetString(7);
                        model.SmsContent      = reader.GetString(8);
                        model.SendDate        = reader.GetDateTime(9);
                        model.SendStatus      = reader.GetInt16(10);
                        model.LastUpdatedDate = reader.GetDateTime(11);
                    }
                }
            }

            return(model);
        }
Esempio n. 7
0
        public string SmsSendByImport(SmsSendInfo model)
        {
            if (string.IsNullOrEmpty(model.SmsContent.Trim()))
            {
                return("发送失败,短信内容不能为空");
            }
            if (string.IsNullOrWhiteSpace(model.MobilePhone))
            {
                return("请导入手机号码");
            }

            List <string> mobileList = new List <string>();

            try
            {
                model.MobilePhone = model.MobilePhone.Trim();
                string[] mobilePhoneArr = model.MobilePhone.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (string item in mobilePhoneArr)
                {
                    if (Regex.IsMatch(item, @"(\d+){11,15}"))
                    {
                        if (!mobileList.Contains(item))
                        {
                            mobileList.Add(item);
                        }
                    }
                }

                if (mobileList.Count == 0)
                {
                    return("无任何正确的手机号码,无法发送短信");
                }

                Guid templateId = Guid.Empty;
                if (model.SmsTemplateId != null)
                {
                    Guid.TryParse(model.SmsTemplateId.ToString(), out templateId);
                }

                try
                {
                    if (!templateId.Equals(Guid.Empty))
                    {
                        SmsTemplate smstBll   = new SmsTemplate();
                        var         smstModel = smstBll.GetModel(model.SmsTemplateId);
                        if (smstModel == null)
                        {
                            return("发送失败,原因:模板不存在或已被删除");
                        }
                        if (smstModel.TemplateType == "auto")
                        {
                            return("发送失败,原因:不能选择自动类型的模板");
                        }

                        model.SmsContent = smstModel.SmsContent;
                    }
                    else
                    {
                        model.SmsContent = string.Format(model.SmsContent, model.ParamsValue.Trim().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
                    }
                }
                catch
                {
                    return("发送失败,原因:已选参数与短信内容匹配有错,请正确操作");
                }

                SmsSend ssBll = new SmsSend();

                if (mobileList.Count > 100)
                {
                    while (mobileList.Count > 0)
                    {
                        var q = mobileList.Take(100);

                        if (q.Count() > 0)
                        {
                            var currList = q.ToList <string>();

                            SmsSendInfo ssiModel = new SmsSendInfo();
                            ssiModel.MobilePhone = string.Join(",", currList);
                            ssiModel.MobilePhone = model.MobilePhone;
                            ssiModel.SmsContent  = model.SmsContent.Trim();

                            ssBll.InsertByStrategy(ssiModel);

                            foreach (var item in currList)
                            {
                                mobileList.Remove(item);
                            }
                        }
                    }
                }
                else
                {
                    SmsSendInfo ssiModel = new SmsSendInfo();
                    ssiModel.MobilePhone = model.MobilePhone;
                    ssiModel.SmsContent  = model.SmsContent.Trim();

                    ssBll.InsertByStrategy(ssiModel);
                }

                return("1");
            }
            catch (Exception ex)
            {
                return("异常:" + ex.Message);
            }
        }
Esempio n. 8
0
        public string SmsSend(SmsSendInfo model)
        {
            if (string.IsNullOrEmpty(model.SmsContent.Trim()))
            {
                return("发送失败,短信内容不能为空");
            }
            try
            {
                model.TemplateType  = model.TemplateType.Trim();
                model.SmsTemplateId = model.SmsTemplateId.ToString().Trim();
                model.SmsContent    = model.SmsContent.Trim();
                model.NumberType    = model.NumberType.Trim();
                model.NumberCode    = model.NumberCode.Trim();
                model.ParamsCode    = model.ParamsCode.Trim();
                model.ParamsName    = model.ParamsName.Trim();
                model.ParamsValue   = model.ParamsValue.Trim();
                model.TranNode      = model.TranNode.Trim();

                #region 短信内容与参数对应检查

                try
                {
                    if (model.SmsTemplateId.ToString() != "")
                    {
                        Guid templateId = Guid.Empty;
                        Guid.TryParse(model.SmsTemplateId.ToString(), out templateId);
                        if (templateId.Equals(Guid.Empty))
                        {
                            return(MessageContent.GetString(MessageContent.Request_Data_Invalid, "当前模板"));
                        }
                        SmsTemplate smstBll   = new SmsTemplate();
                        var         smstModel = smstBll.GetModel(templateId);
                        if (smstModel == null)
                        {
                            return(MessageContent.GetString(MessageContent.Request_Data_Invalid, "当前模板"));
                        }
                        if (smstModel.TemplateType == "auto")
                        {
                            if (model.NumberType == "MobilePhone")
                            {
                                return("发送失败,原因:当号码类型为手机号码时,则不能选择自动类型的模板");
                            }
                            string content = string.Format(model.SmsContent, model.ParamsCode.Trim().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
                        }
                        else if (model.TemplateType == "custom")
                        {
                            string content = string.Format(model.SmsContent, model.ParamsValue.Trim().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
                        }
                    }
                    else
                    {
                        if (model.TemplateType == "auto")
                        {
                            if (model.NumberType == "MobilePhone")
                            {
                                return("发送失败,原因:当号码类型为手机号码时,则不能选择自动类型的模板");
                            }
                            string content = string.Format(model.SmsContent, model.ParamsCode.Trim().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
                        }
                        else if (model.TemplateType == "custom")
                        {
                            string content = string.Format(model.SmsContent, model.ParamsValue.Trim().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
                        }
                    }
                }
                catch
                {
                    return("发送失败,原因:已选参数与短信内容匹配有错,请正确操作");
                }

                #endregion

                SmsSendInfo ssiModel = new SmsSendInfo();
                ssiModel.TemplateType  = model.TemplateType;
                ssiModel.TranNode      = model.TranNode.Trim();
                ssiModel.TranNodeText  = model.TranNodeText.Trim();
                ssiModel.ParamsCode    = model.ParamsCode;
                ssiModel.ParamsName    = model.ParamsName;
                ssiModel.ParamsValue   = model.ParamsValue;
                ssiModel.SmsContent    = model.SmsContent.Trim();
                ssiModel.SmsTemplateId = model.SmsTemplateId;

                switch (model.NumberType)
                {
                case "MobilePhone":
                    ssiModel.MobilePhone = model.NumberCode;
                    if (!Regex.IsMatch(ssiModel.MobilePhone, @"^(\d+){11,15}$"))
                    {
                        return(MessageContent.GetString(MessageContent.Request_InvalidValue, "手机号码"));
                    }
                    break;

                case "OrderCode":
                    ssiModel.OrderCode = model.NumberCode;
                    break;

                case "CarScanCode":
                    ssiModel.CarScanCode = model.NumberCode;
                    break;

                default:
                    break;
                }

                SmsSend ssBll = new SmsSend();
                ssBll.InsertByStrategy(ssiModel);

                return("1");
            }
            catch (Exception ex)
            {
                return("异常:" + ex.Message);
            }
        }
Esempio n. 9
0
        public string PreviewSmsSend(SmsSendInfo model)
        {
            try
            {
                model.NumberType    = model.NumberType.Trim();
                model.SmsTemplateId = model.SmsTemplateId.ToString().Trim();
                model.NumberCode    = model.NumberCode.Trim();
                model.ParamsCode    = model.ParamsCode.Trim();

                if (model.SmsTemplateId.ToString() != "")
                {
                    #region 使用模板

                    Guid templateId = Guid.Empty;
                    Guid.TryParse(model.SmsTemplateId.ToString(), out templateId);
                    if (templateId.Equals(Guid.Empty))
                    {
                        return(MessageContent.GetString(MessageContent.Request_InvalidArgument, "模板ID"));
                    }

                    SmsTemplate smstBll   = new SmsTemplate();
                    var         smstModel = smstBll.GetModel(templateId);
                    if (smstModel == null)
                    {
                        return(MessageContent.GetString(MessageContent.Request_Data_Invalid, "当前模板"));
                    }
                    if (smstModel.TemplateType == "auto")
                    {
                        if (model.NumberType != "OrderCode")
                        {
                            return("当选择的模板类型为自动类型时,号码类型必须是订单号才能预览");
                        }

                        return(smstBll.GetTemplateContent(model.SmsTemplateId, model.NumberCode));
                    }
                    else if (model.TemplateType == "custom")
                    {
                        return(string.Format(model.SmsContent, model.ParamsValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)));
                    }
                    else
                    {
                        return(model.SmsContent);
                    }

                    #endregion
                }
                else if (model.TemplateType == "auto")
                {
                    if (model.NumberType != "OrderCode" || model.ParamsCode == "")
                    {
                        return("当选择的模板类型为自动类型时,号码类型必须是订单号,且必须选择参数才能预览,");
                    }
                    SmsSend ssBll = new SmsSend();
                    return(ssBll.GetSmsContent(model.NumberCode, model.SmsContent, model.ParamsCode));
                }
                else if (model.TemplateType == "custom")
                {
                    return(string.Format(model.SmsContent, model.ParamsValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)));
                }
                else
                {
                    return(model.SmsContent);
                }
            }
            catch (Exception ex)
            {
                return("异常:" + ex.Message);
            }
        }
        private static List <string> GetSmsContent(SmsSendInfo smsModel, DataTable dt)
        {
            List <string> list    = new List <string>();
            string        content = "";

            try
            {
                Guid templateId = Guid.Empty;
                if (smsModel.SmsTemplateId != null)
                {
                    Guid.TryParse(smsModel.SmsTemplateId.ToString(), out templateId);
                }
                if (!templateId.Equals(Guid.Empty))
                {
                    SmsTemplate smstBll = new SmsTemplate();
                    content = smstBll.GetTemplateContent(templateId, dt);
                    list.Add(content);
                }
                else if (!string.IsNullOrEmpty(smsModel.TemplateType))
                {
                    if (smsModel.TemplateType == "auto")
                    {
                        DataRow dr = dt.Rows[0];
                        DataColumnCollection dcc = dt.Columns;

                        string[] paramsCodeArr = smsModel.ParamsCode.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        string[] tParmsValues  = new string[paramsCodeArr.Length];
                        for (int i = 0; i < paramsCodeArr.Length; i++)
                        {
                            if (dcc.Contains(paramsCodeArr[i]))
                            {
                                if (dr[paramsCodeArr[i]] != DBNull.Value)
                                {
                                    tParmsValues[i] = dr[paramsCodeArr[i]].ToString();
                                }
                                else
                                {
                                    tParmsValues[i] = "";
                                }
                            }
                            else
                            {
                                tParmsValues[i] = "";
                            }
                        }

                        content = string.Format(smsModel.SmsContent, tParmsValues);
                        list.Add(content);
                    }
                    else if (smsModel.TemplateType == "custom")
                    {
                        content = string.Format(smsModel.SmsContent, smsModel.ParamsValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
                        list.Add(content);
                    }
                }
                else if (!string.IsNullOrEmpty(smsModel.SmsContent))
                {
                    content = smsModel.SmsContent;
                    list.Add(content);
                }
                else
                {
                    SmsTemplate smstBll = new SmsTemplate();
                    return(smstBll.GetTemplateContentByTranNode(dt, smsModel.TranNode));
                }
            }
            catch (Exception ex)
            {
                string error = "";
                error += "手机号:" + smsModel.MobilePhone == null ? "无" : smsModel.MobilePhone + ",";
                error += "订单号:" + smsModel.OrderCode == null ? "无" : smsModel.OrderCode + ",";
                error += "运输节点:" + smsModel.TranNodeText == null ? "无" : smsModel.TranNodeText + ",";
                error += "派车单号:" + smsModel.CarScanCode == null ? "无" : smsModel.CarScanCode + ",";
                error += "模板ID:" + smsModel.SmsTemplateId == null ? "无" : smsModel.SmsTemplateId.ToString() + ",";
                error += "参数代码:" + smsModel.ParamsCode == null ? "无" : smsModel.ParamsCode + ",";
                error += "参数名称:" + smsModel.ParamsName == null ? "无" : smsModel.ParamsName + ",";
                error += "参数值:" + smsModel.ParamsValue == null ? "无" : smsModel.ParamsValue + ",";
                error += "短信内容:" + smsModel.SmsContent == null ? "无" : smsModel.SmsContent;
                WriteLog log = new WriteLog();
                log.Write("执行获取短信内容时异常(" + ex.Message + "),详情:" + error + "");
            }

            return(list);
        }
        /// <summary>
        /// 新增PDA扫描数据
        /// </summary>
        /// <param name="opType">操作类型</param>
        /// <param name="barCode">单号条码</param>
        /// <param name="scanTime">扫描时间</param>
        /// <param name="userName">用户名</param>
        /// <returns>返回:包含“成功”,则调用成功,否则返回调用失败原因</returns>
        public string Insert(string opType, string barCode, DateTime scanTime, string userName)
        {
            #region 参数合法性检查

            if (string.IsNullOrEmpty(opType))
            {
                return("操作类型不能为空");
            }
            opType = opType.Trim();
            if (string.IsNullOrEmpty(barCode))
            {
                return("单号条码不能为空");
            }
            barCode = barCode.Trim();
            //if (barCode.Length != 13)
            //{
            //    return "单号条码不正确";
            //}

            if (scanTime == DateTime.MinValue)
            {
                return("扫描时间格式不正确");
            }

            if (string.IsNullOrEmpty(userName))
            {
                return("用户不能为空");
            }

            #endregion

            try
            {
                MembershipUser user = Membership.GetUser(userName);
                if (user == null)
                {
                    return("不存在用户:" + userName);
                }

                SysEnum seBll  = new SysEnum();
                var     seList = seBll.GetList("and t2.EnumCode = 'SendReceiveType'", null);
                if (seList == null || seList.Count == 0)
                {
                    return("服务端的操作类型未设定,请先完成设定");
                }

                var firstModel  = seList.OrderBy(m => m.Sort).First();
                var currSeModel = seList.Find(m => m.EnumValue.Trim() == opType);
                if (currSeModel == null)
                {
                    return("当前操作类型“" + opType + "”不存在");
                }

                object nextNodeId  = Guid.Empty;
                var    nextSeModel = seList.FindAll(m => m.Sort > currSeModel.Sort).OrderBy(m => m.Sort).FirstOrDefault();
                if (nextSeModel == null)
                {
                    nextNodeId = currSeModel.Id;
                }
                else
                {
                    nextNodeId = nextSeModel.Id;
                }

                bool isOsdExists = false;

                PDAOrderScanInfo currOsModel = new PDAOrderScanInfo();
                currOsModel.OrderCode       = barCode;
                currOsModel.CurrNodeId      = currSeModel.Id;
                currOsModel.NextNodeId      = nextNodeId;
                currOsModel.IsFinish        = false;
                currOsModel.LastUpdatedDate = DateTime.Now;

                PDAOrderScanDetailInfo currOsdModel = new PDAOrderScanDetailInfo();
                currOsdModel.OrderCode       = barCode;
                currOsdModel.CurrNodeId      = currOsModel.CurrNodeId;
                currOsdModel.ScanTime        = scanTime;
                currOsdModel.UserId          = user.ProviderUserKey;
                currOsdModel.LastUpdatedDate = currOsModel.LastUpdatedDate;

                Order              oBll   = new Order();
                PDAOrderScan       osBll  = new PDAOrderScan();
                PDAOrderScanDetail osdBll = new PDAOrderScanDetail();
                TyUser             tyuBll = new TyUser();
                SmsSend            smsBll = new SmsSend();

                string     sRemark  = "";
                TyUserInfo tyuModel = tyuBll.GetModelByUser(user.UserName);
                if (tyuModel != null && !string.IsNullOrWhiteSpace(tyuModel.OrganizationName))
                {
                    sRemark = string.Format(currSeModel.Remark, tyuModel.OrganizationName);
                }
                else
                {
                    sRemark = currSeModel.Remark.Replace(@"{0}", "");
                }
                sRemark = currSeModel.EnumValue + ":" + sRemark;

                currOsdModel.Remark = sRemark;

                if (opType == "干线发运" || opType == "干线到达")
                {
                    var orders = oBll.GetOrderByCarcode(barCode);
                    if (orders == null || orders.Count() == 0)
                    {
                        return("操作类型:" + barCode + "找不到订单号,有错误");
                    }

                    foreach (var currOrderCode in orders)
                    {
                        currOsModel.OrderCode  = currOrderCode;
                        currOsdModel.OrderCode = currOrderCode;

                        var oldOsdList = osdBll.GetList(currOrderCode);
                        if (oldOsdList != null)
                        {
                            isOsdExists = oldOsdList.Exists(m => m.CurrNodeId.Equals(currSeModel.Id));
                        }

                        if (isOsdExists)
                        {
                            return("订单号:" + currOrderCode + " 操作类型:" + opType + "已存在,不能重复提交");
                        }

                        //发短信
                        SmsSendInfo ssiModel = new SmsSendInfo();
                        ssiModel.OrderCode    = currOrderCode;
                        ssiModel.TranNode     = currSeModel.EnumCode;
                        ssiModel.TranNodeText = currSeModel.EnumValue;

                        using (TransactionScope scope = new TransactionScope())
                        {
                            if (osBll.GetModel(currOrderCode) == null)
                            {
                                osBll.Insert(currOsModel);
                            }
                            else
                            {
                                osBll.Update(currOsModel);
                            }

                            osdBll.Insert(currOsdModel);

                            scope.Complete();
                        }

                        smsBll.InsertByStrategy(ssiModel);
                    }
                }

                else if (currSeModel.Sort == firstModel.Sort)
                {
                    var oldOsModel = osBll.GetModel(barCode);
                    if (oldOsModel != null)
                    {
                        return("订单号:" + barCode + ",操作类型:" + opType + "已存在,不能重复提交");
                    }

                    SmsSendInfo ssiModel = new SmsSendInfo();
                    ssiModel.OrderCode    = barCode;
                    ssiModel.TranNode     = currSeModel.EnumCode;
                    ssiModel.TranNodeText = currSeModel.EnumValue;

                    using (TransactionScope scope = new TransactionScope())
                    {
                        osBll.Insert(currOsModel);
                        osdBll.Insert(currOsdModel);

                        scope.Complete();
                    }

                    smsBll.InsertByStrategy(ssiModel);
                }
                else
                {
                    var oldOsModel = osBll.GetModel(barCode);
                    if (oldOsModel == null)
                    {
                        return("订单号:" + barCode + ",操作类型:" + opType + "未取货,有错误");
                    }

                    var oldOsdList = osdBll.GetList(barCode);
                    if (oldOsdList != null)
                    {
                        isOsdExists = oldOsdList.Exists(m => m.CurrNodeId.Equals(currSeModel.Id));

                        currOsModel.IsFinish = oldOsdList.Count == 5;
                    }

                    if (currOsModel.IsFinish)
                    {
                        return("订单号:" + barCode + "已完成所有操作");
                    }

                    if (isOsdExists)
                    {
                        return("订单号:" + barCode + ",操作类型:" + opType + "已存在,不能重复提交");
                    }

                    SmsSendInfo ssiModel = new SmsSendInfo();
                    ssiModel.OrderCode    = barCode;
                    ssiModel.TranNode     = currSeModel.EnumCode;
                    ssiModel.TranNodeText = currSeModel.EnumValue;

                    using (TransactionScope scope = new TransactionScope())
                    {
                        osBll.Update(currOsModel);

                        osdBll.Insert(currOsdModel);

                        scope.Complete();
                    }

                    smsBll.InsertByStrategy(ssiModel);
                }

                Console.WriteLine("request: opType:{0},barCode:{1},scanTime:{3},user:{2}", opType, barCode, scanTime, userName);

                return("保存成功");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
        /// <summary>
        /// 批量提交PDA扫描数据
        /// </summary>
        /// <param name="dt">应包含opType、barCode、scanTime、userName等列</param>
        /// <returns>返回:包含“成功”,则调用成功,否则返回调用失败原因</returns>
        public string InsertByBatch(DataTable dt)
        {
            if (dt == null || dt.Rows.Count == 0)
            {
                return("无任何可保存的数据");
            }

            string[] colNames = { "opType", "barCode", "scanTime", "userName" };

            DataColumnCollection cols = dt.Columns;

            foreach (DataColumn col in cols)
            {
                if (!colNames.Contains(col.ColumnName))
                {
                    return("检测到提交的数据集中未包含" + col.ColumnName + "列");
                }
            }

            DataRowCollection rows = dt.Rows;

            List <PDAOrderScanDetailInfo> osdList = new List <PDAOrderScanDetailInfo>();

            //定义非重复的用户名、用户ID
            Dictionary <string, object> dicUser = new Dictionary <string, object>();

            try
            {
                SysEnum seBll  = new SysEnum();
                var     seList = seBll.GetList("and t2.EnumCode = 'SendReceiveType'", null);
                if (seList == null || seList.Count == 0)
                {
                    return("服务端的操作类型未设定,请先完成设定");
                }
                var firstModel = seList.OrderBy(m => m.Sort).First();

                foreach (DataRow row in rows)
                {
                    string opType = "";
                    if (row["opType"] != DBNull.Value)
                    {
                        opType = row["opType"].ToString();
                    }
                    else
                    {
                        return("操作类型不能为空");
                    }

                    var seModel = seList.Find(m => m.EnumValue.Trim() == opType.Trim());
                    if (seModel == null)
                    {
                        return("不存在操作类型:" + opType);
                    }

                    string barCode = "";
                    if (row["barCode"] != DBNull.Value)
                    {
                        barCode = row["barCode"].ToString();
                    }
                    DateTime scanTime = DateTime.MinValue;
                    if (row["scanTime"] != DBNull.Value)
                    {
                        DateTime.TryParse(row["scanTime"].ToString(), out scanTime);
                    }
                    if (scanTime == DateTime.MinValue)
                    {
                        return("数据集中包含不合法数据:scanTime值格式不正确");
                    }

                    string userName = "";
                    if (row["userName"] != DBNull.Value)
                    {
                        userName = row["userName"].ToString();
                    }
                    if (string.IsNullOrEmpty(userName))
                    {
                        return("数据集中包含用户名为空");
                    }

                    if (!dicUser.ContainsKey(userName))
                    {
                        dicUser.Add(userName, Guid.Empty);
                    }

                    osdList.Add(new PDAOrderScanDetailInfo {
                        OrderCode = barCode, CurrNodeId = seModel.Id, ScanTime = scanTime, Remark = seModel.Remark, Sort = seModel.Sort, LastUpdatedDate = DateTime.Now, UserName = userName, SysEnumValue = opType
                    });
                }

                TyUser tyuBll = new TyUser();

                foreach (KeyValuePair <string, object> kvp in dicUser)
                {
                    MembershipUser user = Membership.GetUser(kvp.Key, false);
                    if (user == null)
                    {
                        return("不存在用户:" + kvp.Key);
                    }

                    TyUserInfo tyuModel = tyuBll.GetModelByUser(user.UserName);

                    var currList = osdList.FindAll(m => m.UserName == kvp.Key);
                    foreach (var item in currList)
                    {
                        item.UserId = user.ProviderUserKey;

                        string sRemark = "";
                        if (tyuModel != null && !string.IsNullOrWhiteSpace(tyuModel.OrganizationName))
                        {
                            sRemark = string.Format(item.Remark, tyuModel.OrganizationName);
                        }
                        else
                        {
                            sRemark = item.Remark.Replace(@"{0}", "");
                        }
                        sRemark = item.SysEnumValue + ":" + sRemark;

                        item.Remark = sRemark;
                    }
                }

                PDAOrderScan       osBll  = new PDAOrderScan();
                PDAOrderScanDetail osdBll = new PDAOrderScanDetail();
                Order   oBll   = new Order();
                SmsSend smsBll = new SmsSend();

                var q = osdList.OrderBy(m => m.Sort);
                foreach (var item in q)
                {
                    object nextNodeId  = Guid.Empty;
                    var    currSeModel = seList.Find(m => m.EnumValue.Trim() == item.SysEnumValue);
                    var    nextSeModel = seList.FindAll(m => m.Sort > item.Sort).OrderBy(m => m.Sort).FirstOrDefault();
                    if (nextSeModel == null)
                    {
                        nextNodeId = item.CurrNodeId;
                    }
                    else
                    {
                        nextNodeId = nextSeModel.Id;
                    }
                    var  lastSeModel = seList.OrderByDescending(m => m.Sort).First();
                    bool isFinish    = lastSeModel.EnumValue.Trim() == item.SysEnumValue;

                    bool isOsdExists = false;

                    PDAOrderScanInfo currOsModel = new PDAOrderScanInfo();
                    currOsModel.OrderCode       = item.OrderCode;
                    currOsModel.CurrNodeId      = item.CurrNodeId;
                    currOsModel.NextNodeId      = nextNodeId;
                    currOsModel.IsFinish        = isFinish;
                    currOsModel.LastUpdatedDate = DateTime.Now;

                    PDAOrderScanDetailInfo currOsdModel = new PDAOrderScanDetailInfo();
                    currOsdModel.OrderCode       = item.OrderCode;
                    currOsdModel.CurrNodeId      = item.CurrNodeId;
                    currOsdModel.ScanTime        = item.ScanTime;
                    currOsdModel.UserId          = item.UserId;
                    currOsdModel.LastUpdatedDate = currOsModel.LastUpdatedDate;
                    currOsdModel.Remark          = item.Remark;

                    if (item.SysEnumValue == "干线发运" || item.SysEnumValue == "干线到达")
                    {
                        var orders = oBll.GetOrderByCarcode(item.OrderCode);
                        if (orders == null || orders.Count() == 0)
                        {
                            return("操作类型:" + item.SysEnumValue + "找不到订单号,有错误");
                        }

                        foreach (var currOrderCode in orders)
                        {
                            currOsModel.OrderCode  = currOrderCode;
                            currOsdModel.OrderCode = currOrderCode;

                            var oldOsdList = osdBll.GetList(currOrderCode);
                            if (oldOsdList != null)
                            {
                                isOsdExists = oldOsdList.Exists(m => m.CurrNodeId.Equals(item.CurrNodeId));
                            }

                            if (!isOsdExists)
                            {
                                SmsSendInfo ssiModel = new SmsSendInfo();
                                ssiModel.OrderCode    = currOrderCode;
                                ssiModel.TranNode     = currSeModel.EnumCode;
                                ssiModel.TranNodeText = currSeModel.EnumValue;

                                using (TransactionScope scope = new TransactionScope())
                                {
                                    if (osBll.GetModel(currOrderCode) == null)
                                    {
                                        osBll.Insert(currOsModel);
                                    }
                                    else
                                    {
                                        osBll.Update(currOsModel);
                                    }

                                    osdBll.Insert(currOsdModel);

                                    scope.Complete();
                                }

                                smsBll.InsertByStrategy(ssiModel);
                            }
                        }
                    }
                    else if (item.Sort == firstModel.Sort)
                    {
                        var oldOsModel = osBll.GetModel(item.OrderCode);
                        if (oldOsModel == null)
                        {
                            SmsSendInfo ssiModel = new SmsSendInfo();
                            ssiModel.OrderCode    = item.OrderCode;
                            ssiModel.TranNode     = currSeModel.EnumCode;
                            ssiModel.TranNodeText = currSeModel.EnumValue;

                            using (TransactionScope scope = new TransactionScope())
                            {
                                osBll.Insert(currOsModel);
                                osdBll.Insert(currOsdModel);

                                scope.Complete();
                            }

                            smsBll.InsertByStrategy(ssiModel);
                        }
                    }
                    else
                    {
                        var oldOsModel = osBll.GetModel(item.OrderCode);
                        if (oldOsModel == null)
                        {
                            return("订单号:" + item.OrderCode + ",操作类型:" + item.SysEnumValue + "未取货,有错误");
                        }

                        var oldOsdList = osdBll.GetList(item.OrderCode);
                        if (oldOsdList != null)
                        {
                            isOsdExists = oldOsdList.Exists(m => m.CurrNodeId.Equals(item.CurrNodeId));

                            currOsModel.IsFinish = oldOsdList.Count == 5;
                        }

                        if (currOsModel.IsFinish)
                        {
                            continue;
                        }

                        if (!isOsdExists)
                        {
                            SmsSendInfo ssiModel = new SmsSendInfo();
                            ssiModel.OrderCode    = currOsModel.OrderCode;
                            ssiModel.TranNode     = currSeModel.EnumCode;
                            ssiModel.TranNodeText = currSeModel.EnumValue;

                            using (TransactionScope scope = new TransactionScope())
                            {
                                osBll.Update(currOsModel);

                                osdBll.Insert(currOsdModel);

                                scope.Complete();
                            }

                            smsBll.InsertByStrategy(ssiModel);
                        }
                    }

                    Console.WriteLine("request: opType:{0},barCode:{1},scanTime:{3},user:{2}", item.SysEnumValue, item.OrderCode, item.ScanTime, item.UserName);
                }

                return("保存成功");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
 /// <summary>
 /// 修改数据
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Update(SmsSendInfo model)
 {
     return(dal.Update(model));
 }
 /// <summary>
 /// 添加数据到数据库
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Insert(SmsSendInfo model)
 {
     return(dal.Insert(model));
 }
 /// <summary>
 /// 使用异步或同步
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public void InsertByStrategy(SmsSendInfo model)
 {
     smsInsertStrategy.Insert(model);
 }
 public void Insert(SmsSendInfo model)
 {
     dal.Insert(model);
 }
 public void Insert(SmsSendInfo model)
 {
     asynchDal.Send(model);
 }
 public void Send(SmsSendInfo model)
 {
     base.transactionType = MessageQueueTransactionType.Single;
     base.Send(model);
 }