private PrinterViewModel GetQuickPrintModel(string templateName, string number)
        {
            if (string.IsNullOrWhiteSpace(templateName) || string.IsNullOrWhiteSpace(number))
            {
                throw new Exception("模板名称或单号为空");
            }

            var wayBillInfo = _wayBillInfoRepository.GetWayBill(number);

            if (wayBillInfo == null || wayBillInfo.CustomerOrderID == null)
            {
                throw new Exception("没有找到该运单号或订单未提交");
            }

            if (wayBillInfo.CustomerOrderInfo.Status == (int)CustomerOrder.StatusEnum.Delete)
            {
                throw new Exception("订单已删除");
            }

            //转为充血模型
            var customerOrderInfoModel = DecorateCustomerOrderInfo(wayBillInfo.CustomerOrderInfo);



            PrinterViewModel model = new PrinterViewModel()
            {
                CustomerOrderInfoModels = new List <CustomerOrderInfoModel>()
                {
                    customerOrderInfoModel
                },
                Type = 2,
            };

            var wayBillTemplate = _wayBillTemplateService.GetWayBillTemplate(wayBillInfo.InShippingMethodID.Value,
                                                                             templateName);

            if (wayBillTemplate == null)
            {
                throw new Exception("没有找到相应模板");
            }

            if (!wayBillTemplate.Countries.Contains(customerOrderInfoModel.CountryCode))
            {
                throw new Exception("模板不支持该国家");
            }

            model.WayBillTemplates = new List <WayBillTemplateExt> {
                wayBillTemplate
            };

            //Update:zhengsong
            //如果是广州小包,并且是地址标签的 系统分配 发件人信息
            var shippingMethodList = _freightService.GetShippingMethods(null, false);

            model.CustomerOrderInfoModels.ForEach(p =>
            {
                var shipp = shippingMethodList.FirstOrDefault(z => z.ShippingMethodId == customerOrderInfoModel.ShippingMethodId);

                if (shipp != null && wayBillTemplate.TemplateTypeId == "DT1308100021" && (shipp.Code == "CNPOST-GZ" || shipp.Code == "CNPOSTP-GZ"))
                {
                    var gzPacketAddressInfo = _wayBillTemplateService.GetGZPacketAddressInfo().FirstOrDefault();
                    if (gzPacketAddressInfo != null)
                    {
                        p.Address = gzPacketAddressInfo.Address;
                        p.Name    = gzPacketAddressInfo.Name;
                        gzPacketAddressInfo.Number = (gzPacketAddressInfo.Number + 1);
                        _wayBillTemplateService.UpdateGZPacketAddressInfo(gzPacketAddressInfo);
                    }
                }
            });

            return(model);
        }
Example #2
0
        private void ForecastDHLandEUB()
        {
            string     errorWayBills        = "";
            List <int> inShippingMethodIds  = new List <int>();
            List <int> dhlShippingMethodIds = new List <int>();
            List <int> eubShippingMethodIds = new List <int>();
            var        dhlcodes             = dhlshippingMethodCode.Split(',').ToList();
            var        eubcodes             = eubshippingMethodCode.Split(',').ToList();
            var        shippingMethod       = _freightService.GetShippingMethods("", true);

            shippingMethod.ForEach(p =>
            {
                if (dhlcodes.Contains(p.Code))
                {
                    inShippingMethodIds.Add(p.ShippingMethodId);
                    dhlShippingMethodIds.Add(p.ShippingMethodId);
                }
                else if (eubcodes.Contains(p.Code))
                {
                    inShippingMethodIds.Add(p.ShippingMethodId);
                    eubShippingMethodIds.Add(p.ShippingMethodId);
                }
            });
            int number = 0;

            while (true)
            {
                var wayBillList = _orderService.GetDHLandEUBWayBillInfos(inShippingMethodIds, number);
                if (wayBillList.Count < 1)
                {
                    break;
                }
                List <WayBillInfo> dhlwayBills = new List <WayBillInfo>();
                List <WayBillInfo> eubWayBills = new List <WayBillInfo>();
                wayBillList.ForEach(p =>
                {
                    if (dhlShippingMethodIds.Contains(p.InShippingMethodID.Value))
                    {
                        dhlwayBills.Add(p);
                    }
                    else if (eubShippingMethodIds.Contains(p.InShippingMethodID.Value))
                    {
                        eubWayBills.Add(p);
                    }
                });
                //DHL预报
                if (dhlwayBills.Count > 0)
                {
                    var errors = PostDHLShipment(dhlwayBills);
                    errorWayBills = errors.Aggregate(errorWayBills, (current, error) => current + ("[" + error.Key + "]"));
                    UpdateWayBillInfo(errors);
                }
                //EUB预报
                if (eubWayBills.Count > 0)
                {
                    EubWayBillParam param = new EubWayBillParam()
                    {
                        WayBillInfos     = eubWayBills,
                        PrintFormat      = 2,
                        PrintFormatValue = "01"
                    };
                    var errors = _customerOrderService.ForecastEubWayBillInfo(param, true);
                    if (errors.Count > 0)
                    {
                        errorWayBills = errors.Aggregate(errorWayBills, (current, error) => current + ("[" + error.Key + "]"));

                        UpdateWayBillInfo(errors);
                        //errors.ForEach(p=> errorWayBills+="["+p+"]");
                    }
                }
                number += wayBillList.Count;
            }
            Log.Info("预报失败运单:" + errorWayBills);
        }
Example #3
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;
            }
        }