public int AddOutTrackingInfo(OrderTrackingRequestModel orderTrackingRequests) { List <OrderTrackingRequestModel> models = new List <OrderTrackingRequestModel>(); models.Add(orderTrackingRequests); return(_freightService.AddOutTrackingInfo(models)); }
public void TestTrackingInfo() { OrderTrackingRequestModel orderTrackingRequest = new OrderTrackingRequestModel() { ShipmentID = 1, CustomerCode = "admin", TrackingNumber = "4329091572" }; var success = HttpHelper.DoRequest <int>("http://localhost:18736/api/Tracking/AddOutTrackingInfo", EnumHttpMethod.POST, EnumContentType.Json, orderTrackingRequest); Assert.IsTrue(success.Value != 0); }
public int Add() { var shippingMehtod = _freightService.GetShippingMethods("", true); const string dhlUrl = "WWW.DHL.COM"; const string upsUrl = "WWW.UPS.COM"; const string equickUrl = "WWW.EQUICK.CN"; const string dhlGlobalMailUrl = "WORLDTRACK.DHLGLOBALMAIL.COM"; List <int> dhlshippingMehtods = new List <int>(); List <int> upsshippingMehtods = new List <int>(); List <int> equickshippingMehtods = new List <int>(); List <int> dhlGlobalMailMehtods = new List <int>(); List <int> shippingMehtods = new List <int>(); string result = ""; if (shippingMehtod.Count > 0) { shippingMehtod.ForEach(p => { if (p.TrackingUrl != null) { bool need = false; if (dhlUrl.Contains(p.TrackingUrl.ToUpperInvariant())) { dhlshippingMehtods.Add(p.ShippingMethodId); need = true; } else if (upsUrl.Contains(p.TrackingUrl.ToUpperInvariant())) { upsshippingMehtods.Add(p.ShippingMethodId); need = true; } else if (equickUrl.Contains(p.TrackingUrl.ToUpperInvariant())) { equickshippingMehtods.Add(p.ShippingMethodId); need = true; } else if (p.TrackingUrl.ToUpperInvariant().Contains(dhlGlobalMailUrl)) { dhlGlobalMailMehtods.Add(p.ShippingMethodId); need = true; } if (need) { shippingMehtods.Add(p.ShippingMethodId); result += "抓取的运输方式" + "[ID:" + p.ShippingMethodId + ",中文名" + p.FullName + "]"; } } }); } //获取时间 DateTime dtLastUpdatedOn = GetLastUpdatedOn(); var wayBillList = _orderService.GetWayBillTakeList(shippingMehtods, dtLastUpdatedOn); var wayBillInfos = wayBillList as IList <WayBillInfo> ?? wayBillList.ToList(); result += "抓取的运单数(" + wayBillInfos.Count().ToString() + ")"; List <OrderTrackingRequestModel> trackingNubmerList = new List <OrderTrackingRequestModel>(); //string temp = string.Join(",", wayBillInfos.Select(p => p.WayBillNumber)); wayBillInfos.ToList().ForEach(p => { OrderTrackingRequestModel model = new OrderTrackingRequestModel(); if (dhlshippingMehtods.Contains(p.InShippingMethodID ?? -1)) { model.ShipmentID = 1; } else if (upsshippingMehtods.Contains(p.InShippingMethodID ?? -1)) { model.ShipmentID = 2; } else if (equickshippingMehtods.Contains(p.InShippingMethodID ?? -1)) { model.ShipmentID = 3; } else if (dhlGlobalMailMehtods.Contains(p.InShippingMethodID ?? -1)) { model.ShipmentID = 4; } model.CustomerCode = "admin"; var sm = shippingMehtod.Find(s => s.ShippingMethodId == (p.InShippingMethodID ?? -1)); if (sm != null && sm.IsHideTrackingNumber) { model.TrackingNumber = p.TrueTrackingNumber; } else { model.TrackingNumber = p.TrackingNumber; } if (model.ShipmentID != 0 && !string.IsNullOrWhiteSpace(model.TrackingNumber)) { trackingNubmerList.Add(model); } }); try { //string temp2 = string.Join(",", trackingNubmerList.Select(p => p.TrackingNumber)); var total = AddOutTrackingInfoList(trackingNubmerList); result += "请求的运单数量:" + trackingNubmerList.Count.ToString() + "," + "返回的成功数量:" + total.ToString(); if (trackingNubmerList.Any() && total == trackingNubmerList.Count()) { //记录最后时间 DateTime lastLastUpdatedOn = wayBillInfos.OrderByDescending(p => p.LastUpdatedOn).FirstOrDefault().LastUpdatedOn; Log.Info(string.Format("记录最后时间:{0},在{1}", lastLastUpdatedOn.ToString("yyyy-MM-dd hh:mm:ss.fff"), S_LastUpdatedOnFilePath)); WriteLastUpdatedOn(lastLastUpdatedOn); } Log.Info(result); return(total); } catch (Exception ex) { Log.Exception(ex); throw; } }