Пример #1
0
        /// <summary>
        /// 计算快递进度明细对应的状态
        /// </summary>
        /// <param name="info">快递进度信息</param>
        /// <param name="isFirst">是否第一条进度信息 如果为第一条则状态为1(揽件,货物已由快递公司揽收并且产生了第一条跟踪信息)</param>
        /// <returns>快递状态</returns>
        private static int GetExpressDetailState(ExpressProcessDetail info, bool isFirst = false)
        {
            int State = 0;

            if (isFirst)
            {
                State = 1;
            }
            else
            {
                if (info.Context.Contains("派件人"))
                {
                    State = 5;
                }
                else if (info.Context.Contains("签收人"))
                {
                    State = 3;
                }
            }
            return(State);
        }
Пример #2
0
 /// <summary>
 /// 计算快递进度明细对应的状态
 /// </summary>
 /// <param name="info">快递进度信息</param>
 /// <param name="isFirst">是否第一条进度信息 如果为第一条则状态为1(揽件,货物已由快递公司揽收并且产生了第一条跟踪信息)</param>
 /// <returns>快递状态</returns>
 private static int GetExpressDetailState(ExpressProcessDetail info, bool isFirst = false)
 {
     int State = 0;
     if (isFirst)
     {
         State = 1;
     }
     else
     {
         if (info.Context.Contains("派件人"))
         {
             State = 5;
         }
         else if (info.Context.Contains("签收人"))
         {
             State = 3;
         }
     }
     return State;
 }
Пример #3
0
        /// <summary>
        /// 解析快递信息
        /// </summary>
        /// <param name="json">服务器返回json数据</param>
        /// <param name="ExpressInfo">快递单号信息</param>
        /// <returns>是否成功</returns>
        private static bool ParseExpressInfo(string json, ExpressInfo ExpressInfo)
        {
            try
            {
                JObject jo    = JObject.Parse(json);
                JToken  value = null;

                //快递单当前的状态
                string state = string.Empty;
                if (jo.TryGetValue("state", out value))
                {
                    state = value.ToString();
                }

                //查询结果状态
                if (jo.TryGetValue("status", out value))
                {
                    if (value.ToString().Equals("200"))
                    {
                        //快递单号
                        string ExpressNo = string.Empty;

                        if (jo.TryGetValue("nu", out value))
                        {
                            ExpressNo = value.ToString();
                        }
                        if (string.IsNullOrEmpty(ExpressNo))
                        {
                            return(false);
                        }
                        if (state.Equals("3") || state.Equals("4") || state.Equals("6"))
                        {
                            //3:签收,收件人已签收;4:退签,即货物由于用户拒签、超区等原因退回,而且发件人已经签收;
                            //6:退回,货物正处于退回发件人的途中;
                            //快递周期已结束,则将当前快递单号移入到历史表中,不在产生任何短信信息
                            SaveExpressHistoryInfo(ExpressNo, state);
                        }

                        if (jo.TryGetValue("data", out value))
                        {
                            List <ExpressProcessDetail> list = JsonConvert.DeserializeObject <List <ExpressProcessDetail> >(value.ToString());
                            if (list != null && list.Count > 0)
                            {
                                list.Reverse();
                                int length                = list.Count;
                                int maxGroupNo            = GetExpressDetailMaxGroupNo(ExpressNo);
                                ExpressProcessDetail item = null;
                                for (int i = maxGroupNo; i < length; i++)
                                {
                                    item           = list[i];
                                    item.ExpressNo = ExpressNo;
                                    item.GroupNo   = i + 1;
                                }


                                //产生了新的快递进度信息,准备发送短信通知
                                if (length > maxGroupNo)
                                {
                                    //保存新的进度信息
                                    SQLHelper.BatchSaveData(list.Where(e => e.GroupNo > maxGroupNo).ToList(), "p_ExpressProcessDetail");
                                    //插入短信通知,等待任务轮训时发送短信
                                    var      lastDetail = list[length - 1];
                                    string[] Receivers  = ExpressInfo.Receiver.Split(new char[] { ',' });
                                    foreach (string Receiver in Receivers)
                                    {
                                        if (RegexHelper.IsMobile(Receiver))
                                        {
                                            //短信最大长度为40字节,20汉字
                                            string content = string.Format("亲快件*{0}!{1}", ExpressNo.Substring(ExpressNo.Length - 4 > 0 ? ExpressNo.Length - 4 : 0), lastDetail.Context.Replace(" ", ""));
                                            //由于短信接口只有20条免费短信的限制,所以改为邮件提醒
                                            //MessageHelper.AddMessage(Receiver, content.FormatStringLength(40), "");
                                        }
                                        else if (RegexHelper.IsEmail(Receiver))
                                        {
                                            Hashtable             ht = new Hashtable();
                                            List <ExpressCompany> listExpressCompany = GetAllExpressCompany();
                                            string ExpressCompany = listExpressCompany.FirstOrDefault(e => e.CompanyCode == ExpressInfo.ExpressCompanyCode).CompanyName;
                                            ht["TotalTime"]      = lastDetail.Time.GetDayAndHours(list[0].Time);
                                            ht["T"]              = list;
                                            ht["V"]              = ExpressInfo;
                                            ht["ExpressCompany"] = ExpressCompany;
                                            ht["Status"]         = state;
                                            string content = FileGen.GetFileText(FileHelper.GetAbsolutePath("Temples/ExpressDetail.vm"), ht).ToString();
                                            //添加邮件消息提醒
                                            MessageHelper.AddMessage(Receiver, content, "快递进度变更", MessageType.EMAIL);
                                        }
                                    }
                                }
                            }
                        }
                        return(true);
                    }
                }
                return(false);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #4
0
        /// <summary>
        /// 解析快递信息
        /// </summary>
        /// <param name="json">服务器返回json数据</param>
        /// <param name="ExpressInfo">快递单号信息</param>
        /// <returns>是否成功</returns>
        private static bool ParseExpressInfo(string json, ExpressInfo ExpressInfo)
        {
            try
            {
                JObject jo    = JObject.Parse(json);
                JToken  value = null;

                //快递单当前的状态
                int state = -1;
                if (jo.TryGetValue("state", out value))
                {
                    if (!Int32.TryParse(value.ToString(), out state))
                    {
                        return(false);
                    }
                }

                //查询结果状态
                if (jo.TryGetValue("status", out value))
                {
                    if (value.ToString().Equals("200"))
                    {
                        //快递单号
                        string ExpressNo = string.Empty;

                        if (jo.TryGetValue("nu", out value))
                        {
                            ExpressNo = value.ToString();
                        }
                        if (string.IsNullOrEmpty(ExpressNo))
                        {
                            return(false);
                        }
                        if (state == 3 || state == 4 || state == 6)
                        {
                            //3:签收,收件人已签收;4:退签,即货物由于用户拒签、超区等原因退回,而且发件人已经签收;
                            //6:退回,货物正处于退回发件人的途中;
                            //快递周期已结束,则将当前快递单号移入到历史表中,不在产生任何短信信息
                            SaveExpressHistoryInfo(ExpressNo, state);
                        }

                        if (jo.TryGetValue("data", out value))
                        {
                            List <ExpressProcessDetail> list = JsonConvert.DeserializeObject <List <ExpressProcessDetail> >(value.ToString());
                            if (list != null && list.Count > 0)
                            {
                                list.Reverse();
                                int length                = list.Count;
                                int maxGroupNo            = GetExpressDetailMaxGroupNo(ExpressNo);
                                ExpressProcessDetail item = null;
                                for (int i = maxGroupNo; i < length; i++)
                                {
                                    item           = list[i];
                                    item.ExpressNo = ExpressNo;
                                    item.GroupNo   = i + 1;
                                    //相对准确,但不是完全准确的一个状态
                                    item.State = GetExpressDetailState(item, maxGroupNo == 0 && i == 0);
                                }


                                //产生了新的快递进度信息,准备发送短信通知
                                if (length > maxGroupNo)
                                {
                                    var saveList = list.Where(e => e.GroupNo > maxGroupNo).ToList();
                                    //保存新的进度信息
                                    SQLHelper.BatchSaveData(saveList, "p_ExpressProcessDetail");
                                    //插入短信通知,等待任务轮训时发送短信
                                    var      lastDetail = list[length - 1];
                                    string[] Receivers  = ExpressInfo.Receiver.Split(new char[] { ',' });
                                    foreach (string Receiver in Receivers)
                                    {
                                        if (RegexHelper.IsMobile(Receiver))
                                        {
                                            //短信最大长度为40字节,20汉字
                                            string content = string.Format("亲快件*{0}!{1}", ExpressNo.Substring(ExpressNo.Length - 4 > 0 ? ExpressNo.Length - 4 : 0), lastDetail.Context.Replace(" ", ""));
                                            //由于短信接口只有20条免费短信的限制,所以改为邮件提醒
                                            //MessageHelper.AddMessage(Receiver, content.FormatStringLength(40), "");
                                        }
                                        else if (RegexHelper.IsEmail(Receiver))
                                        {
                                            bool isAddMessage = false;
                                            //修改消息添加规则,有变更就添加可能一天收很多邮件,让人厌烦
                                            //现在规则修改为快递状态为1:揽件 3:签收 5:派件 这几种状态必发
                                            //然后每天其它状态的最多发送一条
                                            var importantDetail = saveList.Where(e => e.State == 1 || e.State == 3 || e.State == 5);
                                            if (importantDetail != null && importantDetail.Count() > 0)
                                            {
                                                isAddMessage = true;
                                            }
                                            else
                                            {
                                                if (!HasSendMessage(ExpressInfo.ExpressGUID))
                                                {
                                                    isAddMessage = true;
                                                }
                                            }
                                            if (isAddMessage)
                                            {
                                                Hashtable             ht = new Hashtable();
                                                List <ExpressCompany> listExpressCompany = GetAllExpressCompany();
                                                string ExpressCompany = listExpressCompany.FirstOrDefault(e => e.CompanyCode == ExpressInfo.ExpressCompanyCode).CompanyName;
                                                ht["TotalTime"]      = lastDetail.Time.GetDayAndHours(list[0].Time);
                                                ht["T"]              = list;
                                                ht["V"]              = ExpressInfo;
                                                ht["ExpressCompany"] = ExpressCompany;
                                                ht["Status"]         = state;
                                                string content = FileGen.GetFileText(FileHelper.GetAbsolutePath("Temples/ExpressDetail.vm"), ht).ToString();
                                                //添加邮件消息提醒
                                                MessageHelper.AddMessage(Receiver, content, "快递进度变更", "快递进度", ExpressInfo.ExpressGUID, MessageType.EMAIL);
                                            }
                                        }
                                        else
                                        {
                                            TaskLog.ExpressProgressLogInfo.WriteLogE(string.Format("快递单号“{0}”的接收人“{1}”无法识别,不为邮件/手机号任何一种,请检查!", ExpressInfo.ExpressNo, ExpressInfo.Receiver));
                                        }
                                    }
                                }
                            }
                        }
                        return(true);
                    }
                }
                return(false);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }