public void AddNLPOST(NetherlandsParcelRespons netherlandsParcelRespons, WayBillInfo wayBillInfo)
        {
            if (netherlandsParcelRespons == null)
            {
                throw new BusinessLogicException("数据不能为空!");
            }
            var result = _netherlandsParcelResponsRepository.Exists(p => p.WayBillNumber == netherlandsParcelRespons.WayBillNumber);

            if (result)
            {
                throw new BusinessLogicException("该数据已存在!");
            }
            netherlandsParcelRespons.LastUpdatedBy = _workContext.User.UserUame;
            netherlandsParcelRespons.LastUpdatedOn = DateTime.Now;
            netherlandsParcelRespons.CreatedBy     = _workContext.User.UserUame;
            netherlandsParcelRespons.CreatedOn     = DateTime.Now;
            _netherlandsParcelResponsRepository.Add(netherlandsParcelRespons);

            wayBillInfo.LastUpdatedBy = _workContext.User.UserUame;
            wayBillInfo.LastUpdatedOn = DateTime.Now;
            wayBillInfo.CustomerOrderInfo.LastUpdatedBy = _workContext.User.UserUame;
            wayBillInfo.CustomerOrderInfo.LastUpdatedOn = DateTime.Now;
            _wayBillInfoRepository.Modify(wayBillInfo);

            using (var tran = new TransactionScope())
            {
                _netherlandsParcelResponsRepository.UnitOfWork.Commit();
                _wayBillInfoRepository.UnitOfWork.Commit();
                AddDeliveryChannelChangeLog(wayBillInfo.WayBillNumber, wayBillInfo.OutShippingMethodID.Value, wayBillInfo.VenderCode);
                tran.Complete();
            }
        }
Exemple #2
0
        //修改运单信息
        public void UpdateWayBillInfo(string waybillNumber)
        {
            WayBillInfo getWayBillInfo = _wayBillInfoRepository.First(p => p.WayBillNumber == waybillNumber);

            getWayBillInfo.Status = WayBill.StatusToValue(WayBill.StatusEnum.Delivered);
            _wayBillInfoRepository.Modify(getWayBillInfo);
            _wayBillInfoRepository.UnitOfWork.Commit();
        }
Exemple #3
0
        //是否取到运单信息
        public bool IsGetWayBillInfo(string waybillNumber)
        {
            WayBillInfo getWayBillInfo = _wayBillInfoRepository.First(p => p.WayBillNumber == waybillNumber || p.CustomerOrderNumber == waybillNumber || p.TrackingNumber == waybillNumber);

            if (getWayBillInfo == null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public bool UpdateTrackingNumberInfoDetailAndWayBillInfo(WayBillInfo wayBillInfo)
        {
            bool bResult = false;

            if (wayBillInfo == null)
            {
                return(bResult);
            }

            if (wayBillInfo.InShippingMethodID.HasValue)
            {
                var trackingNumberDetail = TrackNumberAssignStandard(wayBillInfo.InShippingMethodID.Value, 1, wayBillInfo.CountryCode);

                //_trackingNumberDetailInfoRepository.GetTrackingNumberDetailInfo(wayBillInfo.InShippingMethodID.Value, wayBillInfo.CountryCode);
                if (null != trackingNumberDetail && trackingNumberDetail.Any())
                {
                    //trackingNumberDetail.Status = (short)TrackingNumberDetailInfo.StatusEnum.Used;
                    //trackingNumberDetail.WayBillNumber = wayBillInfo.WayBillNumber;
                    // _trackingNumberDetailInfoRepository.Modify(trackingNumberDetail);

                    wayBillInfo.TrackingNumber = trackingNumberDetail[0];
                    wayBillInfo.LastUpdatedOn  = DateTime.Now;
                    wayBillInfo.LastUpdatedBy  = _workContext.User.UserUame;
                    wayBillInfo.LastUpdatedOn  = DateTime.Now;

                    using (var transaction = new TransactionScope())
                    {
                        _wayBillInfoRepository.Modify(wayBillInfo);

                        //_trackingNumberDetailInfoRepository.UnitOfWork.Commit();
                        _wayBillInfoRepository.UnitOfWork.Commit();
                        transaction.Complete();
                        bResult = true;
                    }
                }
            }

            return(bResult);
        }
        /// <summary>
        /// 添加快递服务响应的数据,并更新运单的物流商、发货运输方式ID和跟踪号
        /// </summary>
        /// <param name="expressResponse">快递响应实例</param>
        /// <param name="wayBillInfo">运单实例</param>
        public void AddExpressResponse(ExpressRespons expressResponse, WayBillInfo wayBillInfo, bool isNologin = false)
        {
            if (null == expressResponse)
            {
                throw new BusinessLogicException("数据不能为空!");
            }
            var result = _expressResponsRepository.Exists(p => p.WayBillNumber == expressResponse.WayBillNumber);

            if (result)
            {
                throw new BusinessLogicException("该数据已存在!");
            }
            var wayBill = _wayBillInfoRepository.Get(wayBillInfo.WayBillNumber);

            expressResponse.LastUpdatedBy = isNologin ? "System" : _workContext.User.UserUame;
            expressResponse.LastUpdatedOn = DateTime.Now;
            expressResponse.CreatedBy     = isNologin ? "System" : _workContext.User.UserUame;
            expressResponse.CreatedOn     = DateTime.Now;
            _expressResponsRepository.Add(expressResponse);
            wayBill.VenderCode          = wayBillInfo.VenderCode;
            wayBill.OutShippingMethodID = wayBillInfo.InShippingMethodID;
            wayBill.TrackingNumber      = wayBillInfo.TrackingNumber;
            wayBill.CustomerOrderInfo.TrackingNumber = wayBillInfo.TrackingNumber;
            wayBill.LastUpdatedBy = isNologin ? "System" : _workContext.User.UserUame;
            wayBill.LastUpdatedOn = DateTime.Now;
            wayBill.CustomerOrderInfo.LastUpdatedBy = isNologin ? "System" : _workContext.User.UserUame;
            wayBill.CustomerOrderInfo.LastUpdatedOn = DateTime.Now;
            _wayBillInfoRepository.Modify(wayBill);

            using (var tran = new TransactionScope())
            {
                _expressResponsRepository.UnitOfWork.Commit();
                _wayBillInfoRepository.UnitOfWork.Commit();
                AddDeliveryChannelChangeLog(wayBillInfo.WayBillNumber, wayBillInfo.OutShippingMethodID.Value, wayBillInfo.VenderCode, isNologin);
                tran.Complete();
            }
        }
Exemple #6
0
        /// <summary>
        /// 客户订单提交(批量)
        /// </summary>
        private void CustomerOrderSubmitBatch(List <OrderSubmitResult> listOrderSubmitResult)
        {
            _lmsDbContext = new LMS_DbContext();
            _customerOrderInfoRepository        = new CustomerOrderInfoRepository(_lmsDbContext);
            _wayBillInfoRepository              = new WayBillInfoRepository(_lmsDbContext);
            _trackingNumberInfoRepository       = new TrackingNumberInfoRepository(_lmsDbContext);
            _wayBillEventLogRepository          = new WayBillEventLogRepository(_lmsDbContext);
            _trackingNumberDetailInfoRepository = new TrackingNumberDetailInfoRepository(_lmsDbContext);
            _applicationInfoRepository          = new ApplicationInfoRepository(_lmsDbContext);
            _trackNumberService = new TrackNumberService();

            //重试次数加1
            listOrderSubmitResult.ForEach(p =>
            {
                p.RetryTimes++;
                p.Result.Success = true;
            });

            try
            {
                var customerOrderIds = listOrderSubmitResult.Select(p => p.CustomerOrderId).ToList();

                //获取要提交的订单信息
                var listCustomerOrderInfos = GetListByCustomerOrderId(customerOrderIds);

                listCustomerOrderInfos.ForEach(p =>
                {
                    //不是提交中的状态,视为已提交成功
                    if (p.Status != (int)CustomerOrder.StatusEnum.Submiting)
                    {
                        var orderSubmitResult =
                            listOrderSubmitResult.First(s => s.CustomerOrderId == p.CustomerOrderID);
                        orderSubmitResult.Result.Success = true;
                        orderSubmitResult.Result.Message = string.Format("{0}不是提交中的状态", p.CustomerOrderID);
                    }
                });

                listCustomerOrderInfos.RemoveAll(p => p.Status != (int)CustomerOrder.StatusEnum.Submiting);

                if (listCustomerOrderInfos.Count == 0)
                {
                    return;                                    //全部不是提交中的单,直接退出
                }
                List <int> failureShippingMethodId = new List <int>();

                //本次提交涉及到的运输方式
                List <int> shippingMethodIds = new List <int>();
                foreach (var info in listCustomerOrderInfos)
                {
                    var shippingMethodId = info.ShippingMethodId.HasValue ? info.ShippingMethodId.Value : 0;
                    if (shippingMethodIds.Contains(shippingMethodId) || shippingMethodId == 0)
                    {
                        continue;
                    }
                    shippingMethodIds.Add(shippingMethodId);
                }

                int getShippingMethodRetry = 3;

                var shippingMethodList = GetShippingMethodsByIds(shippingMethodIds);

                while (shippingMethodList == null && --getShippingMethodRetry > 0)
                {
                    Thread.Sleep(1000 * 2);
                    shippingMethodList = GetShippingMethodsByIds(shippingMethodIds);
                }

                if (shippingMethodList == null)
                {
                    throw new BusinessLogicException("获取订单运输方式信息失败,请稍后重试");
                }


                List <ApplicationInfo> applicationInfos = new List <ApplicationInfo>();
                applicationInfos =
                    _applicationInfoRepository.GetList(a => customerOrderIds.Contains(a.CustomerOrderID ?? 0));
                List <string> customerOrderNumbers = new List <string>();


                #region 遍历每一个订单

                //需要添加的运单
                List <WayBillInfo> listWayBillInfoAdd = new List <WayBillInfo>();

                //需要修改的订单
                List <CustomerOrderInfo> listCustomerOrderInfoModify = new List <CustomerOrderInfo>();

                foreach (var info in listCustomerOrderInfos)
                {
                    try
                    {
                        #region 生成运单基本信息

                        string wayBillNumber = SequenceNumberService.GetWayBillNumber(info.CustomerCode);
                        Log.Info(string.Format("订单:{0}所在线程:{1}申请到单号:{2}", info.CustomerOrderNumber,
                                               Thread.CurrentThread.Name, wayBillNumber));
                        var wayBillInfo = new WayBillInfo
                        {
                            //WayBillNumber = PrefixCode.OrderID + currentWayBillNumber++,
                            WayBillNumber        = wayBillNumber,
                            CustomerOrderID      = info.CustomerOrderID,
                            CustomerOrderNumber  = info.CustomerOrderNumber,
                            CustomerCode         = info.CustomerCode,
                            InShippingMethodID   = info.ShippingMethodId,
                            InShippingMethodName = info.ShippingMethodName,
                            ShippingInfoID       = info.ShippingInfoID,
                            SenderInfoID         = info.SenderInfoID,
                            GoodsTypeID          = info.GoodsTypeID,
                            TrackingNumber       = info.TrackingNumber,
                            IsReturn             = info.IsReturn,
                            IsHold             = false,
                            IsBattery          = info.IsBattery,
                            Status             = WayBill.StatusEnum.Submitted.GetStatusValue(),
                            CountryCode        = info.ShippingInfo.CountryCode.ToUpperInvariant(),
                            InsuredID          = info.InsuredID,
                            Weight             = info.Weight,
                            Length             = info.Length,
                            Width              = info.Width,
                            Height             = info.Height,
                            CreatedOn          = info.LastUpdatedOn,
                            CreatedBy          = info.LastUpdatedBy,
                            LastUpdatedBy      = info.LastUpdatedBy,
                            LastUpdatedOn      = info.LastUpdatedOn,
                            EnableTariffPrepay = info.EnableTariffPrepay,
                        };

                        #endregion

                        #region 插入内部操作信息


                        //Add By zxq
                        //Time:2014-09-15
                        var wayBillEventLog = new WayBillEventLog()
                        {
                            WayBillNumber = wayBillInfo.WayBillNumber,
                            EventCode     = (int)WayBillEvent.EventCodeEnum.Submit,
                            Description   =
                                WayBillEvent.GetEventCodeDescription((int)WayBillEvent.EventCodeEnum.Submit),
                            EventDate     = DateTime.Now,
                            LastUpdatedOn = DateTime.Now,
                            Operator      = info.LastUpdatedBy,
                        };

                        _wayBillEventLogRepository.Add(wayBillEventLog);


                        #endregion

                        #region 分配跟踪号

                        if (string.IsNullOrWhiteSpace(info.TrackingNumber))
                        {
                            var shippingMethodId = info.ShippingMethodId.HasValue ? info.ShippingMethodId.Value : 0;
                            var model            = shippingMethodList.Find(p => p.ShippingMethodId == shippingMethodId);
                            if (failureShippingMethodId.Contains(shippingMethodId))
                            {
                                throw new BusinessLogicException("分配跟踪号失败");
                            }
                            if (model != null && model.IsSysTrackNumber)
                            {
                                while (true)
                                {
                                    var trackingNumberList =
                                        _trackNumberService.TrackNumberAssignStandard(shippingMethodId, 1,
                                                                                      wayBillInfo.CountryCode);

                                    if (!trackingNumberList.Any())
                                    {
                                        if (!failureShippingMethodId.Contains(shippingMethodId))
                                        {
                                            failureShippingMethodId.Add(shippingMethodId);
                                        }
                                        throw new BusinessLogicException("分配跟踪号失败");
                                    }
                                    else
                                    {
                                        var trackNumber = trackingNumberList[0];
                                        if (!listCustomerOrderInfos.Any(t => t.TrackingNumber == trackNumber))
                                        {
                                            wayBillInfo.TrackingNumber = trackNumber;
                                            info.TrackingNumber        = wayBillInfo.TrackingNumber;

                                            //分配跟踪号成功 , 跳出循环
                                            break;
                                        }
                                        else
                                        {
                                            //[分配的跟踪号] 与 [上传的跟踪号] 有重复
                                            //进入下一次分配
                                        }
                                    }
                                }
                            }
                        }

                        #endregion

                        #region 修改运单状态

                        info.LastUpdatedBy = info.LastUpdatedBy;
                        info.LastUpdatedOn = DateTime.Now;
                        info.Status        = CustomerOrder.StatusEnum.Submitted.GetStatusValue();
                        info.CustomerOrderStatuses.Add(new CustomerOrderStatus
                        {
                            CreatedOn       = info.LastUpdatedOn,
                            CustomerOrderID = info.CustomerOrderID,
                            Status          = info.Status,
                            Remark          = "客户提交"
                        });

                        //更新ApplicationInfo表的WayBillNumber字段
                        foreach (var appInfo in applicationInfos)
                        {
                            if (info.CustomerOrderID == appInfo.CustomerOrderID)
                            {
                                appInfo.WayBillNumber = wayBillInfo.WayBillNumber;
                                appInfo.LastUpdatedBy = info.LastUpdatedBy;
                                appInfo.LastUpdatedOn = DateTime.Now;
                                _applicationInfoRepository.Modify(appInfo);
                            }
                        }
                        listWayBillInfoAdd.Add(wayBillInfo);
                        listCustomerOrderInfoModify.Add(info);
                        customerOrderNumbers.Add(info.CustomerOrderNumber);

                        #endregion
                    }
                    catch (Exception ex)
                    {
                        OrderSubmitResult orderSubmitResult =
                            listOrderSubmitResult.Find(p => p.CustomerOrderId == info.CustomerOrderID);
                        orderSubmitResult.Result.Success = false;
                        orderSubmitResult.Result.Message = ex.Message;
                        orderSubmitResult.ContinueRetry  = ex is System.Data.DataException;
                    }
                }

                #endregion

                try
                {
                    //能够提交的订单号
                    var listCanSubmitCustomerOrderNumber =
                        listCustomerOrderInfos.Where(
                            p =>
                            listOrderSubmitResult.Find(t => t.CustomerOrderId == p.CustomerOrderID && t.Result.Success) !=
                            null).Select(p => p.CustomerOrderNumber).ToList();

                    //获取已经存在运单的订单
                    var listWayBillInfoExist =
                        _wayBillInfoRepository.GetExistCustomerOrderNumber(listCanSubmitCustomerOrderNumber);

                    //过滤掉已经存在运单的订单
                    listWayBillInfoExist.ForEach(p =>
                    {
                        OrderSubmitResult orderSubmitResult = listOrderSubmitResult.Find(t => t.CustomerOrderId == p);
                        if (orderSubmitResult != null)
                        {
                            orderSubmitResult.Result.Success = false;
                            orderSubmitResult.Result.Message = "已存在该订单对应的运单";
                        }
                    });

                    //最终需要修改的订单
                    listCustomerOrderInfoModify.ForEach(p =>
                    {
                        if (
                            listOrderSubmitResult.Find(
                                t => t.CustomerOrderId == p.CustomerOrderID && t.Result.Success) != null)
                        {
                            _customerOrderInfoRepository.Modify(p);
                        }
                    });

                    //最终需要提交的运单
                    listWayBillInfoAdd.ForEach(p =>
                    {
                        if (
                            listOrderSubmitResult.Find(
                                t => t.CustomerOrderId == p.CustomerOrderID && t.Result.Success) != null)
                        {
                            _wayBillInfoRepository.Add(p);

                            #region 操作日志

                            //yungchu
                            //敏感字-无
                            //BizLog bizlog = new BizLog()
                            //{
                            //    Summary = "订单批量提交",
                            //    KeywordType = KeywordType.WayBillNumber,
                            //    Keyword = p.WayBillNumber,
                            //    UserCode = _workContext.User.UserUame??"admin",
                            //    UserRealName = _workContext.User.UserUame??"admin",
                            //    UserType = UserType.LMS_User,
                            //    SystemCode = SystemType.LMS,
                            //    ModuleName = "订单批量提交"
                            //};

                            //_operateLogServices.WriteLog(bizlog, p);

                            #endregion
                        }
                    });

                    using (var transaction = new TransactionScope(TransactionScopeOption.RequiresNew, TimeSpan.MaxValue)
                           )
                    {
                        _wayBillInfoRepository.UnitOfWork.Commit();
                        _customerOrderInfoRepository.UnitOfWork.Commit();
                        _applicationInfoRepository.UnitOfWork.Commit();
                        _wayBillEventLogRepository.UnitOfWork.Commit();
                        _trackingNumberDetailInfoRepository.UnitOfWork.Commit();

                        transaction.Complete();
                    }
                }
                catch (Exception ex)
                {
                    Log.Exception(ex);

                    listOrderSubmitResult.ForEach(p =>
                    {
                        if (p.Result.Success)
                        {
                            p.Result.Success = false;
                            p.ContinueRetry  = ex is System.Data.DataException;
                            p.Result.Message = p.ContinueRetry ? "系统错误,请稍后再试" : ex.Message;
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                Log.Exception(ex);

                listOrderSubmitResult.ForEach(p =>
                {
                    if (p.Result.Success)
                    {
                        p.Result.Success = false;
                        p.ContinueRetry  = ex is System.Data.DataException;
                        p.Result.Message = p.ContinueRetry ? "系统错误,请稍后再试" : ex.Message;
                    }
                });
            }
        }
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(WayBillInfo model, IDbTransaction transaction = null)
 {
     return(_WayBillInfoRepository.Update(model, transaction));
 }
 /// <summary>
 ///  新增
 /// </summary>
 public int Add(WayBillInfo model, IDbTransaction transaction = null)
 {
     return(_WayBillInfoRepository.Insert(model, transaction));
 }
        //DHL Api 预报信息
        //Add By zhengsong
        public ExpressRespons AddExpressResponseToAPI(ExpressRespons expressResponse, WayBillInfo wayBillInfo)
        {
            if (null == expressResponse)
            {
                throw new BusinessLogicException("数据不能为空!");
            }
            var result = _expressResponsRepository.Exists(p => p.WayBillNumber == expressResponse.WayBillNumber);

            if (result)
            {
                throw new BusinessLogicException("该数据已存在!");
            }

            expressResponse.LastUpdatedBy = wayBillInfo.CreatedBy;
            expressResponse.LastUpdatedOn = DateTime.Now;
            expressResponse.CreatedBy     = wayBillInfo.CreatedBy;
            expressResponse.CreatedOn     = DateTime.Now;
            //_expressResponsRepository.Add(expressResponse);

            //wayBillInfo.LastUpdatedBy = _workContext.User.UserUame;
            //wayBillInfo.LastUpdatedOn = DateTime.Now;
            //wayBillInfo.CustomerOrderInfo.LastUpdatedBy = _workContext.User.UserUame;
            //wayBillInfo.CustomerOrderInfo.LastUpdatedOn = DateTime.Now;
            //_wayBillInfoRepository.Modify(wayBillInfo);
            //using (var tran = new TransactionScope())
            //{
            //    //_expressResponsRepository.UnitOfWork.Commit();
            //    //_wayBillInfoRepository.UnitOfWork.Commit();
            //    AddDeliveryChannelChangeLog(wayBillInfo.WayBillNumber, wayBillInfo.OutShippingMethodID.Value, wayBillInfo.VenderCode, wayBillInfo.CreatedBy);
            //    tran.Complete();
            //}
            return(expressResponse);
        }