示例#1
0
        /// <summary>
        /// 根据ExpRouteId删除物流详细信息
        /// </summary>
        /// <returns></returns>
        public ResultDTO DelExpressTraceExt(Guid ExpRouteId)
        {
            ResultDTO dto = null;

            try
            {
                ContextSession contextSession = ContextFactory.CurrentThreadContext;
                var            expressTrace   = ExpressTrace.ObjectSet().Where(p => p.ExpRouteId == ExpRouteId).ToList();
                if (expressTrace.Count() > 0)
                {
                    foreach (var item in expressTrace)
                    {
                        item.EntityState = EntityState.Deleted;
                        contextSession.Delete(item);
                    }
                    contextSession.SaveChanges();
                }
                dto = new ResultDTO()
                {
                    ResultCode = 0, Message = "删除物流信息成功", isSuccess = true
                };
            }
            catch (Exception ex)
            {
                LogHelper.Error(string.Format("佣金信息删除异常。MallApply:{0}", ex.Message));
                dto = new ResultDTO()
                {
                    ResultCode = 1, Message = ex.Message, isSuccess = false
                };
            }
            return(dto);
        }
示例#2
0
        /// <summary>
        /// 根据ExpRouteId查询物流详细信息
        /// </summary>
        /// <param name="search">查询类</param>
        /// <returns>结果</returns>
        public List <ExpressTraceDTO> GetExpressTraceListExt(ExpressTraceDTO search)
        {
            var expressTracelist = ExpressTrace.ObjectSet().ToList();

            if (search.ExpRouteId != Guid.Empty)
            {
                expressTracelist = expressTracelist.Where(p => p.ExpRouteId == search.ExpRouteId).ToList();
            }
            List <ExpressTraceDTO> searchlist = new List <ExpressTraceDTO>();

            if (expressTracelist.Count() > 0)
            {
                foreach (var item in expressTracelist)
                {
                    ExpressTraceDTO model = new ExpressTraceDTO();
                    model.Id            = item.Id;
                    model.ExpRouteId    = item.ExpRouteId;
                    model.AcceptTime    = item.AcceptTime;
                    model.AcceptStation = item.AcceptStation;
                    model.Remark        = item.Remark;
                    searchlist.Add(model);
                }
            }
            return(searchlist);
        }
        /// <summary>
        /// 删除极光物流数据信息
        /// </summary>
        private ResultDTO DeleteExpressTrace(Guid orderExpressRouteId)
        {
            ResultDTO dto = null;

            try
            {
                string sql = " delete from ExpressTrace where ExpRouteId='" + orderExpressRouteId + "'";
                ExpressTrace.ObjectSet().Context.ExecuteStoreCommand(sql);
                dto = new ResultDTO()
                {
                    ResultCode = 0, Message = "删除成功", isSuccess = true
                };
            }
            catch (Exception ex)
            {
                LogHelper.Debug(string.Format("OTMSJob删除急速物流异常信息:{0}", ex));
                dto = new ResultDTO()
                {
                    ResultCode = 1, Message = ex.Message, isSuccess = false
                };
            }
            return(dto);
        }
示例#4
0
        /// <summary>
        ///  获取物流跟踪信息
        /// </summary>
        public void GetOrderExpressForJobExt()
        {
            ContextSession contextSession = ContextFactory.CurrentThreadContext;

            try
            {
                Guid EsAppId        = Guid.Parse("8B4D3317-6562-4D51-BEF1-0C05694AC3A6");
                var  commodityOrder = CommodityOrder.ObjectSet().Where(p => (p.State == 1 || p.State == 2) && p.EsAppId == EsAppId).AsQueryable();
                if (commodityOrder.Count() > 0)
                {
                    LogHelper.Info(string.Format("commodityOrder中的Count:{0}", commodityOrder));
                    foreach (var item in commodityOrder)
                    {
                        //当表中存在这个订单式撤销
                        var exEntity = LongisticsTrack.ObjectSet().FirstOrDefault(p => p.Code == item.Code);
                        if (exEntity == null)
                        {
                            LongisticsTrack model = new LongisticsTrack();
                            model.Id           = Guid.NewGuid();
                            model.Code         = item.Code;
                            model.AppName      = item.AppName;
                            model.SupplierName = item.SupplierName;
                            model.SupplierCode = item.SupplierCode;
                            model.AppId        = item.AppId;
                            model.EsAppId      = item.EsAppId ?? Guid.Empty;
                            model.SupplierType = item.SupplierType.ToString();
                            var orderitem = OrderItem.ObjectSet().FirstOrDefault(p => p.CommodityOrderId == item.Id);
                            if (orderitem != null)
                            {
                                model.CommodityDetail = orderitem.Name + "(数量:" + orderitem.Number + ",属性:" + orderitem.CommodityAttributes + ")";
                            }
                            //下订单时间
                            model.Ordertime = item.SubTime;
                            //上传订单时间
                            model.UploadExpresstime = item.ShipmentsTime;

                            var commodityOrderId = item.Id.ToString();
                            var jdOrderitem      = JdOrderItem.ObjectSet().FirstOrDefault(p => p.CommodityOrderId.Contains(commodityOrderId));
                            if (jdOrderitem != null)
                            {
                                //查询京东物流的订单信息
                                var jdwuliu = JdHelper.orderTrack(jdOrderitem.JdOrderId);
                                if (jdwuliu != null)
                                {
                                    JArray objson = JArray.Parse(jdwuliu);
                                    LogHelper.Info(string.Format("obj京东信息:{0}", objson.ToString()));
                                    int count = 0;
                                    foreach (var _item in objson)
                                    {
                                        if (count == 0)
                                        {
                                            model.Expressdeliverytime = DateTime.Parse(_item["msgTime"].ToString());
                                        }
                                        if (count == 1)
                                        {
                                            model.ExpressSdtime = DateTime.Parse(_item["msgTime"].ToString());
                                        }
                                        count++;
                                    }
                                }
                            }
                            else
                            {
                                if (!string.IsNullOrEmpty(item.ExpOrderNo))
                                {
                                    var result = (from a in ExpressTrace.ObjectSet()
                                                  join b in OrderExpressRoute.ObjectSet()
                                                  on a.ExpRouteId equals b.Id
                                                  where b.ExpOrderNo == item.ExpOrderNo
                                                  select a).ToList();

                                    if (result.Count() == 1)
                                    {
                                        model.Expressdeliverytime = result[0].AcceptTime;
                                        model.ExpressSdtime       = result[0].AcceptTime;
                                    }
                                    if (result.Count() > 2)
                                    {
                                        model.Expressdeliverytime = result[0].AcceptTime;
                                        model.ExpressSdtime       = result[1].AcceptTime;
                                    }
                                }
                            }
                            model.Confirmtime = item.ConfirmTime;
                            model.SubTime     = DateTime.Now;
                            model.IsDel       = false;
                            model.EntityState = System.Data.EntityState.Added;
                            contextSession.SaveObject(model);
                        }
                    }
                    contextSession.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(string.Format("OTMSJob错误信息:{0}", ex.Message));
            }
        }
示例#5
0
        /// <summary>
        /// 按快递单号获取快递路由信息。
        /// </summary>
        /// <returns></returns>
        public ResultDTO <OrderExpressRouteExtendDTO> GetExpressRouteByExpNoExt(Jinher.AMP.BTP.Deploy.OrderExpressRouteDTO express)
        {
            ResultDTO <OrderExpressRouteExtendDTO> result = new ResultDTO <OrderExpressRouteExtendDTO>();

            try
            {
                if (express == null)
                {
                    result.ResultCode = 1;
                    result.Message    = "参数错误,参数不能为空!";
                    return(result);
                }
                else if (string.IsNullOrWhiteSpace(express.ShipExpCo))
                {
                    result.ResultCode = 2;
                    result.Message    = "参数错误,物流公司名称不能为空!";
                    return(result);
                }
                else if (string.IsNullOrWhiteSpace(express.ExpOrderNo))
                {
                    result.ResultCode = 3;
                    result.Message    = "参数错误,运单号不能为空!";
                    return(result);
                }

                var cname  = express.ShipExpCo.Replace("快递", "").Replace("速递", "").Replace("物流", "").Replace("配送", "").Replace("货运", "").Replace("快运", "").Replace("速运", "").ToUpper();
                var ocInfo = ExpressCode.AllExpCodes.Where(ec => ec.ExpCompanyName.ToUpper().Contains(cname));
                if (!ocInfo.Any())
                {
                    result.ResultCode = 4;
                    result.Message    = "暂不支持该物流公司的快递单号查询!";
                    return(result);
                }
                express.ShipperCode = ocInfo.First().ExpCode;

                var oerQuery = (from oer in OrderExpressRoute.ObjectSet()
                                where oer.ShipperCode == express.ShipperCode && oer.ExpOrderNo == express.ExpOrderNo
                                select oer).FirstOrDefault();
                if (oerQuery == null)
                {
                    return(result);
                }
                OrderExpressRouteExtendDTO oerDto = new OrderExpressRouteExtendDTO();
                oerDto.FillWith(oerQuery);
                var etQuery = (from et in ExpressTrace.ObjectSet()
                               where et.ExpRouteId == oerQuery.Id
                               orderby et.AcceptTime descending
                               select et).ToList();
                if (etQuery.Any())
                {
                    List <ExpressTraceDTO> oerList = etQuery.ConvertAll <ExpressTraceDTO>(exp => exp.ToEntityData());
                    oerDto.Traces = oerList;
                }
                result.Data = oerDto;
            }
            catch (Exception ex)
            {
                result.ResultCode = -1;
                result.Message    = string.Format("按快递单号获取快递路由信息异常,异常信息:{0}", ex);
                return(result);
            }
            return(result);
        }
        /*
         * private void GetWuliu(OrderExpressRoute orderExpressRoute,Guid AppId)
         * {
         *  JObject obj = null;
         *  string json = null;
         *  try
         *  {
         *      if (string.IsNullOrWhiteSpace(orderExpressRoute.Deliverystatus))
         *      {
         #region 当没有物流信息时添加数据
         *          json = GetWuliuJson(orderExpressRoute, AppId);
         *          obj = JObject.Parse(json);
         *          if (obj["status"].ToString() != null && obj["status"].ToString() == "0")
         *          {
         *              //先删除数据然后添加
         *              var res = DeleteExpressTrace(orderExpressRoute.Id);
         *              if (res.isSuccess==true)
         *              {
         *                  JArray arr = (JArray)JsonConvert.DeserializeObject(obj["result"]["list"].ToString());
         *                  if (arr.Count() > 0)
         *                  {
         *                      StringBuilder sb = new StringBuilder();
         *                      sb.Append("insert into ExpressTrace (Id,ExpRouteId,AcceptTime,AcceptStation,Remark) values");
         *                      foreach (var item in arr)
         *                      {
         *                          sb.Append("(");
         *                          sb.Append("'" + Guid.NewGuid() + "','" + orderExpressRoute.Id + "','" + Convert.ToDateTime(item["time"].ToString()) + "','" + item["status"].ToString().Trim() + "',''");
         *                          sb.Append("),");
         *                      }
         *                      sb.Remove(sb.Length - 1, 1);
         *                      ExpressTrace.ObjectSet().Context.ExecuteStoreCommand(sb.ToString());
         *                  }
         *                  int deliverystatus = Convert.ToInt32(obj["result"]["deliverystatus"].ToString());
         *                  if (deliverystatus == 1)
         *                  {
         *                      orderExpressRoute.Deliverystatus = new EnumHelper().GetDescription(DeliverystatusEnum.ZTZ);
         *                  }
         *                  if (deliverystatus == 2)
         *                  {
         *                      orderExpressRoute.Deliverystatus = new EnumHelper().GetDescription(DeliverystatusEnum.PJZ);
         *                  }
         *                  if (deliverystatus == 3)
         *                  {
         *                      orderExpressRoute.Deliverystatus = new EnumHelper().GetDescription(DeliverystatusEnum.YQS);
         *                  }
         *                  if (deliverystatus == 4)
         *                  {
         *                      orderExpressRoute.Deliverystatus = new EnumHelper().GetDescription(DeliverystatusEnum.PSSB);
         *                  }
         *                  string sql = "update OrderExpressRoute set Deliverystatus='" + orderExpressRoute.Deliverystatus + "' where Id='" + orderExpressRoute.Id + "'";
         *                  OrderExpressRoute.ObjectSet().Context.ExecuteStoreCommand(sql);
         *              }
         *
         *          }
         *
         #endregion
         *      }
         *      else
         *      {
         *          //不存在下面两种情况时更新状态
         *          if (!orderExpressRoute.Deliverystatus.Contains("已签收") && !orderExpressRoute.Deliverystatus.Contains("派送失败"))
         *          {
         #region 当物流信息存在时
         *              json = GetWuliuJson(orderExpressRoute, AppId);
         *              obj = JObject.Parse(json);
         *              if (obj["status"].ToString() != null && obj["status"].ToString() == "0")
         *              {
         *                  //先删除数据然后添加
         *                  var res = DeleteExpressTrace(orderExpressRoute.Id);
         *                  if (res.isSuccess == true)
         *                  {
         *                      JArray arr = (JArray)JsonConvert.DeserializeObject(obj["result"]["list"].ToString());
         *                      if (arr.Count() > 0)
         *                      {
         *                          StringBuilder sb = new StringBuilder();
         *                          sb.Append("insert into ExpressTrace (Id,ExpRouteId,AcceptTime,AcceptStation,Remark) values");
         *
         *                          foreach (var item in arr)
         *                          {
         *                              sb.Append("(");
         *                              sb.Append("'" + Guid.NewGuid() + "','" + orderExpressRoute.Id + "','" + Convert.ToDateTime(item["time"].ToString()) + "','" + item["status"].ToString() + "',''");
         *                              sb.Append("),");
         *                          }
         *                          sb.Remove(sb.Length - 1, 1);
         *                          ExpressTrace.ObjectSet().Context.ExecuteStoreCommand(sb.ToString());
         *                      }
         *                      int deliverystatus = Convert.ToInt32(obj["result"]["deliverystatus"].ToString());
         *                      if (deliverystatus == 1)
         *                      {
         *                          orderExpressRoute.Deliverystatus = new EnumHelper().GetDescription(DeliverystatusEnum.ZTZ);
         *                      }
         *                      if (deliverystatus == 2)
         *                      {
         *                          orderExpressRoute.Deliverystatus = new EnumHelper().GetDescription(DeliverystatusEnum.PJZ);
         *                      }
         *                      if (deliverystatus == 3)
         *                      {
         *                          orderExpressRoute.Deliverystatus = new EnumHelper().GetDescription(DeliverystatusEnum.YQS);
         *                      }
         *                      if (deliverystatus == 4)
         *                      {
         *                          orderExpressRoute.Deliverystatus = new EnumHelper().GetDescription(DeliverystatusEnum.PSSB);
         *                      }
         *                      string sql = "update OrderExpressRoute set Deliverystatus='" + orderExpressRoute.Deliverystatus + "' where Id='" + orderExpressRoute.Id + "'";
         *                      OrderExpressRoute.ObjectSet().Context.ExecuteStoreCommand(sql);
         *                  }
         *
         *              }
         #endregion
         *          }
         *
         *      }
         *  }
         *  catch (Exception ex)
         *  {
         *      LogHelper.Debug(string.Format("OTMSJob急速数据物流快递异常信息:{0}", ex.Message));
         *  }
         *
         * }
         */
        /// <summary>
        /// 获取快递100物流信息
        /// </summary>
        /// <param name="orderExpressRoute"></param>
        /// <param name="AppId"></param>
        /// <param name="shipExpCo"></param>
        private void GetExpress100Wuliu(OrderExpressRoute orderExpressRoute, Guid AppId, string shipExpCo)
        {
            JObject obj  = null;
            string  json = null;

            try
            {
                #region 当没有物流信息时添加数据


                json = Express100SV.GetExpressFromKD100(orderExpressRoute.ExpOrderNo, shipExpCo);
                //LogHelper.Info("【获取快递100】AppId=[" + AppId + "]shipExpCo=[" + shipExpCo + "]====返回-->[" + json + "]");
                obj = JObject.Parse(json);
                if (obj["message"].ToString().ToLower().Equals("ok"))
                {
                    //先删除数据然后添加
                    var res = DeleteExpressTrace(orderExpressRoute.Id);
                    if (res.isSuccess == true)
                    {
                        string data = obj["data"].ToString();
                        JArray arr  = JArray.Parse(data);
                        //JArray arr = (JArray)JsonConvert.DeserializeObject(obj["result"]["list"].ToString());
                        if (arr.Count() > 0)
                        {
                            JToken first = arr[arr.Count() - 1];
                            JToken end   = arr[0];


                            StringBuilder sb = new StringBuilder();
                            sb.Append("insert into ExpressTrace (Id,ExpRouteId,AcceptTime,AcceptStation,Remark) values");

                            if (first != null)
                            {
                                sb.Append("(");
                                sb.Append("'" + Guid.NewGuid() + "','" + orderExpressRoute.Id + "','" + Convert.ToDateTime(first["ftime"].ToString()) + "','" + first["context"].ToString().Trim() + "',''");
                                sb.Append("),");
                            }
                            if (end != null)
                            {
                                sb.Append("(");
                                sb.Append("'" + Guid.NewGuid() + "','" + orderExpressRoute.Id + "','" + Convert.ToDateTime(end["ftime"].ToString()) + "','" + end["context"].ToString().Trim() + "',''");
                                sb.Append("),");
                            }

                            sb.Remove(sb.Length - 1, 1);
                            ExpressTrace.ObjectSet().Context.ExecuteStoreCommand(sb.ToString());
                            //LogHelper.Info("【获取快递100】Job 同步成功Sql--->[" + sb.ToString() + "]");
                        }
                        //快递单当前签收状态,包括0在途中、1已揽收、2疑难、3已签收、4退签、5同城派送中、6退回、7转单等7个状态,其中4-7需要另外开通才有效
                        int deliverystatus = Convert.ToInt32(obj["state"].ToString());
                        if (deliverystatus == 3)
                        {
                            orderExpressRoute.Deliverystatus = new EnumHelper().GetDescription(DeliverystatusEnum.YQS);

                            string sql = "update OrderExpressRoute set Deliverystatus='" + orderExpressRoute.Deliverystatus + "' where Id='" + orderExpressRoute.Id + "'";
                            OrderExpressRoute.ObjectSet().Context.ExecuteStoreCommand(sql);
                        }
                        else if (deliverystatus == 6)
                        {
                            orderExpressRoute.Deliverystatus = new EnumHelper().GetDescription(DeliverystatusEnum.PSSB);

                            string sql = "update OrderExpressRoute set Deliverystatus='" + orderExpressRoute.Deliverystatus + "' where Id='" + orderExpressRoute.Id + "'";
                            OrderExpressRoute.ObjectSet().Context.ExecuteStoreCommand(sql);
                        }
                    }
                }

                #endregion
            }
            catch (Exception ex)
            {
                LogHelper.Error(string.Format("GetExpress100Wuliu 快递100接口调用错误:{0}", ex.Message));
            }
        }
        /// <summary>
        /// 接收快递鸟推送的物流路由信息。  base.Do(false);
        /// </summary>
        public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO ReceiveKdniaoExpressRouteExt(System.Collections.Generic.List <Jinher.AMP.BTP.Deploy.CustomDTO.OrderExpressRouteExtendDTO> oerList)
        {
            ResultDTO result = new ResultDTO {
                ResultCode = 0, Message = "Success"
            };

            try
            {
                if (oerList == null || !oerList.Any())
                {
                    result.ResultCode = 1;
                    result.Message    = "参数错误,物流路由信息不能为空!";
                    return(result);
                }
                ContextSession           contextSession = ContextFactory.CurrentThreadContext;
                List <OrderExpressRoute> oerReadyList   = new List <OrderExpressRoute>();
                var distinctOEList = (from oe in oerList select new { oe.ShipperCode, oe.ExpOrderNo }).Distinct();
                foreach (var oe in distinctOEList)
                {
                    var oerQuery = (from oer in OrderExpressRoute.ObjectSet()
                                    where oer.ShipperCode == oe.ShipperCode && oer.ExpOrderNo == oe.ExpOrderNo
                                    select oer).ToList();
                    if (!oerQuery.Any())
                    {
                        continue;
                    }
                    oerReadyList.AddRange(oerQuery);

                    //清理同一运单已有路由信息。
                    var erids   = (from oer in oerQuery select oer.Id).Distinct();
                    var etQuery = (from et in ExpressTrace.ObjectSet()
                                   where erids.Contains(et.ExpRouteId)
                                   select et).ToList();
                    foreach (var etq in etQuery)
                    {
                        etq.EntityState = System.Data.EntityState.Deleted;
                    }
                }
                //将运单路由信息保存到db.

                foreach (var oere in oerList)
                {
                    OrderExpressRoute oerNew = (from oerr in oerReadyList
                                                where oerr.ShipperCode == oere.ShipperCode && oerr.ExpOrderNo == oere.ExpOrderNo
                                                select oerr).FirstOrDefault();
                    if (oerNew == null)
                    {
                        continue;
                    }
                    oerNew.ModifiedOn  = DateTime.Now;
                    oerNew.EntityState = System.Data.EntityState.Modified;

                    if (oere.Traces != null && oere.Traces.Any())
                    {
                        foreach (ExpressTraceDTO etDto in oere.Traces)
                        {
                            ExpressTrace et = ExpressTrace.CreateExpressTrace();
                            et.FillWith(etDto);
                            et.ExpRouteId  = oerNew.Id;
                            et.Id          = Guid.NewGuid();
                            et.EntityState = System.Data.EntityState.Added;
                            contextSession.SaveObject(et);
                        }
                    }
                }
                contextSession.SaveChanges();
            }
            catch (Exception ex)
            {
                string s = string.Format("保存快递鸟推送的物流路由信息异常,异常信息:{0}", ex);
                LogHelper.Error(s);
                return(new ResultDTO {
                    ResultCode = 1, Message = "Error"
                });
            }
            return(result);
        }