Example #1
0
        //[TestMethod]
        //public void TestSequenceNumber()
        //{
        //    int maxCount = 5000;

        //    List<object> list = new List<object>();

        //    for (int i = 0; i < maxCount; i++)
        //    {
        //        list.Add(i);
        //    }

        //WThreadPoll threadPoll = new WThreadPoll(50, GetSequenceNumber, list);

        //threadPoll.StartPoll();

        //threadPoll.WaitAllWorkItemComplete();

        //bool success = listSequenceNumber.Distinct().Count() == listSequenceNumber.Count;

        //Assert.IsTrue(success);

        private void GetSequenceNumber(object obj)
        {
            int per = 2;

            var firstSequenceNumber = SequenceNumberService.GetSequenceNumber(PrefixCode.ReturnGoodsID, per);

            var first =
                firstSequenceNumber.Substring(PrefixCode.ReturnGoodsID.Length,
                                              firstSequenceNumber.Length - PrefixCode.ReturnGoodsID.Length).ConvertTo <long>();

            for (int j = 0; j < per; j++)
            {
                listSequenceNumber.Add(PrefixCode.ReturnGoodsID + (first + j).ToString());
            }
        }
Example #2
0
        public static object MUpdatePrice(object value)
        {
            var    j            = Int32.Parse(value.ToString());
            string customerCode = ConfigurationManager.AppSettings["CustomerCode"];

            Log.Info("开始生成客户编码:" + customerCode + ",第" + j + "批");
            for (int i = 0; i < 1000; i++)
            {
                string waybillnumber = SequenceNumberService.GetWayBillNumber(customerCode);
                Log.Info(waybillnumber);
                if (dictionary.ContainsKey(waybillnumber))
                {
                    Log.Error(waybillnumber);
                }
                else
                {
                    dictionary.Add(waybillnumber, waybillnumber);
                }
                Log.Info(dictionary.Count.ToString());
            }
            Log.Info("完成生成客户编码:" + customerCode + ",第" + j + "批");
            return(true);
        }
Example #3
0
        public void CreateOutStorage(CreateOutStorageExt createOutStorageExt)
        {
            Check.Argument.IsNotNull(createOutStorageExt, "createOutStorageExt");
            Check.Argument.IsNotNull(createOutStorageExt.OutStorage, "createOutStorageExt.OutStorage");
            Check.Argument.IsNotNull(createOutStorageExt.WayBillInfos, "createOutStorageExt.WayBillInfos");

            DateTime      outStorageCreatedOn = DateTime.Now;
            List <string> waybillinfoIds      = new List <string>();

            createOutStorageExt.WayBillInfos.Each(p => waybillinfoIds.Add(p.WayBillNumber));
            var wayBills = _wayBillInfoRepository.GetList(p => waybillinfoIds.Contains(p.WayBillNumber));

            List <WayBillEventLog>     listWayBillEventLog     = new List <WayBillEventLog>();
            List <OutStorageInfo>      listOutStorageInfo      = new List <OutStorageInfo>();
            List <CustomerOrderStatus> listCustomerOrderStatus = new List <CustomerOrderStatus>();
            List <string> listWaybillSend      = new List <string>();
            List <string> listWaybillWaitOrder = new List <string>();
            List <int>    listCustomerOrderId  = new List <int>();

            var outShippingMethodId   = createOutStorageExt.WayBillInfos.First().OutShippingMethodID;
            var outShippingMethodName = createOutStorageExt.WayBillInfos.First().OutShippingMethodName;

            createOutStorageExt.WayBillInfos.Each(p =>
            {
                #region 修改运单资料信息和订单状态

                var oldstatus   = WayBill.StatusToValue(WayBill.StatusEnum.Have);
                var wayBillInfo = wayBills.Find(w => w.WayBillNumber == p.WayBillNumber && w.Status == oldstatus);

                if (wayBillInfo == null)
                {
                    throw new ArgumentException("该运单号\"{0}\"不存在,或则是当前状态不是已收货!".FormatWith(p.WayBillNumber));
                }

                //有跟踪号
                if (p.HaveTrackingNum)
                {
                    if (p.TrackingNumber == "null" || string.IsNullOrEmpty(p.TrackingNumber))
                    {
                        //修改运单状态  待转单
                        listWaybillWaitOrder.Add(p.WayBillNumber);
                    }
                    else
                    {
                        //修改运单状态  已发货
                        listWaybillSend.Add(p.WayBillNumber);
                    }
                }
                else
                {
                    //修改运单状态  已发货
                    listWaybillSend.Add(p.WayBillNumber);
                }


                //插入订单状态记录
                listCustomerOrderStatus.Add(new CustomerOrderStatus
                {
                    CustomerOrderID = wayBillInfo.CustomerOrderID.Value,
                    CreatedOn       = DateTime.Now,
                    Status          = CustomerOrder.StatusToValue(CustomerOrder.StatusEnum.Send)
                });

                listCustomerOrderId.Add(wayBillInfo.CustomerOrderID.Value);

                #region 录入内部信息

                var wayBillEventLog = new WayBillEventLog()
                {
                    WayBillNumber = wayBillInfo.WayBillNumber,
                    EventCode     = (int)WayBillEvent.EventCodeEnum.OutStorage,
                    Description   = WayBillEvent.GetEventCodeDescription((int)WayBillEvent.EventCodeEnum.OutStorage),
                    EventDate     = outStorageCreatedOn,
                    LastUpdatedOn = outStorageCreatedOn,
                    Operator      = _workContext.User.UserUame,
                };
                listWayBillEventLog.Add(wayBillEventLog);

                #endregion

                #endregion
            });


            //createOutStorageExt.WayBillInfos.Each(p =>
            //    {
            //        #region 修改运单资料信息和订单状态

            //        var oldstatus = WayBill.StatusToValue(WayBill.StatusEnum.Have);
            //        var wayBillInfo = wayBills.Find(w => w.WayBillNumber == p.WayBillNumber && w.Status == oldstatus);

            //        if (wayBillInfo == null)
            //        {
            //            throw new ArgumentException("该运单号\"{0}\"不存在,或则是当前状态不是已收货!".FormatWith(p.WayBillNumber));
            //        }
            //        wayBillInfo.OutShippingMethodID = p.OutShippingMethodID;
            //        wayBillInfo.OutShippingMethodName = p.OutShippingMethodName;
            //        wayBillInfo.OutStorageID = createOutStorageExt.OutStorage.OutStorageID;
            //        wayBillInfo.VenderCode = createOutStorageExt.OutStorage.VenderCode;

            //        //有跟踪号
            //        if (p.HaveTrackingNum)
            //        {
            //            if (p.TrackingNumber == "null" || string.IsNullOrEmpty(p.TrackingNumber))
            //            {
            //                //修改运单状态  待转单
            //                wayBillInfo.Status = WayBill.StatusToValue(WayBill.StatusEnum.WaitOrder);
            //            }
            //            else
            //            {
            //                //修改运单状态  已发货
            //                wayBillInfo.Status = WayBill.StatusToValue(WayBill.StatusEnum.Send);
            //            }
            //        }
            //        else
            //        {
            //            //修改运单状态  已发货
            //            wayBillInfo.Status = WayBill.StatusToValue(WayBill.StatusEnum.Send);
            //        }


            //        if (wayBillInfo.CustomerOrderID.HasValue)
            //        {
            //            //修改订单状态
            //            wayBillInfo.CustomerOrderInfo.Status =
            //                CustomerOrder.StatusToValue(CustomerOrder.StatusEnum.Send);
            //            wayBillInfo.CustomerOrderInfo.LastUpdatedBy = _workContext.User.UserUame;
            //            wayBillInfo.CustomerOrderInfo.LastUpdatedOn = DateTime.Now;

            //            //插入订单状态记录
            //            listCustomerOrderStatus.Add(new CustomerOrderStatus
            //            {
            //                CustomerOrderID = wayBillInfo.CustomerOrderID.Value,
            //                CreatedOn = DateTime.Now,
            //                Status = CustomerOrder.StatusToValue(CustomerOrder.StatusEnum.Send)
            //            });

            //        }
            //        wayBillInfo.LastUpdatedBy = _workContext.User.UserUame;
            //        wayBillInfo.LastUpdatedOn = DateTime.Now;
            //        wayBillInfo.OutStorageCreatedOn = outStorageCreatedOn;
            //        _wayBillInfoRepository.Modify(wayBillInfo);

            //        #endregion

            //        #region 录入内部信息

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

            //        #endregion
            //    });

            //生成出仓资料
            var outStorage = new OutStorageInfo();
            outStorage = createOutStorageExt.OutStorage;
            outStorage.DeliveryStaff = outStorage.CreatedBy = outStorage.LastUpdatedBy = _workContext.User.UserUame;
            outStorage.CreatedOn     = outStorage.LastUpdatedOn = outStorageCreatedOn;
            outStorage.Status        = 1;

            if (createOutStorageExt.WayBillInfos.First().OutShippingMethodName == "国际小包优+")
            {
                var    countryCode    = createOutStorageExt.WayBillInfos.First().CountryCode;
                string sequenceNumber = SequenceNumberService.GetSequenceNumber("U-");
                _mailPostBagInfoRepository.Add(new MailPostBagInfo()
                {
                    CountryCode   = countryCode,
                    OutStorageID  = outStorage.OutStorageID,
                    IsBattery     = createOutStorageExt.WayBillInfos.First().IsBattery,
                    PostBagNumber = sequenceNumber.Replace("-", "-" + countryCode + "-"),
                    TotalWeight   = createOutStorageExt.WayBillInfos.Sum(p => p.Weight),
                    CreatedBy     = outStorage.LastUpdatedBy,
                    CreatedOn     = DateTime.Now,
                    LastUpdatedBy = outStorage.LastUpdatedBy,
                    LastUpdatedOn = DateTime.Now,
                });
            }
            //_outStorageInfoRepository.Add(outStorage);

            listOutStorageInfo.Add(outStorage);

            using (var transaction = new TransactionScope())
            {
                _wayBillInfoRepository.BulkInsert("WayBillEventLogs", listWayBillEventLog);
                _wayBillInfoRepository.BulkInsert("OutStorageInfos", listOutStorageInfo);
                _wayBillInfoRepository.BulkInsert("CustomerOrderStatuses", listCustomerOrderStatus);

                if (listWaybillSend.Any())
                {
                    _wayBillInfoRepository.Modify(w => new WayBillInfo()
                    {
                        OutShippingMethodID   = outShippingMethodId,
                        OutShippingMethodName = outShippingMethodName,
                        OutStorageID          = createOutStorageExt.OutStorage.OutStorageID,
                        VenderCode            = createOutStorageExt.OutStorage.VenderCode,
                        LastUpdatedBy         = _workContext.User.UserUame,
                        LastUpdatedOn         = outStorageCreatedOn,
                        OutStorageCreatedOn   = outStorageCreatedOn,
                        Status = WayBill.StatusToValue(WayBill.StatusEnum.Send),
                    }, w => listWaybillSend.Contains(w.WayBillNumber));
                }


                if (listWaybillWaitOrder.Any())
                {
                    _wayBillInfoRepository.Modify(w => new WayBillInfo()
                    {
                        OutShippingMethodID   = outShippingMethodId,
                        OutShippingMethodName = outShippingMethodName,
                        OutStorageID          = createOutStorageExt.OutStorage.OutStorageID,
                        VenderCode            = createOutStorageExt.OutStorage.VenderCode,
                        LastUpdatedBy         = _workContext.User.UserUame,
                        LastUpdatedOn         = outStorageCreatedOn,
                        OutStorageCreatedOn   = outStorageCreatedOn,
                        Status = WayBill.StatusToValue(WayBill.StatusEnum.WaitOrder),
                    }, w => listWaybillWaitOrder.Contains(w.WayBillNumber));
                }

                if (listCustomerOrderId.Any())
                {
                    _customerOrderInfoRepository.Modify(c => new CustomerOrderInfo()
                    {
                        Status        = CustomerOrder.StatusToValue(CustomerOrder.StatusEnum.Send),
                        LastUpdatedBy = _workContext.User.UserUame,
                        LastUpdatedOn = outStorageCreatedOn,
                    }, c => listCustomerOrderId.Contains(c.CustomerOrderID));
                }
                //_wayBillInfoRepository.UnitOfWork.Commit();

                _mailPostBagInfoRepository.UnitOfWork.Commit();

                transaction.Complete();
            }
            //创建总包号
            if (createOutStorageExt.IsCreateTotalPackageNumber.HasValue)
            {
                if (createOutStorageExt.IsCreateTotalPackageNumber.Value)
                {
                    //创建新的
                    var totalPackageInfo = new TotalPackageInfo
                    {
                        CreatedBy          = _workContext.User.UserUame,
                        LastUpdatedBy      = _workContext.User.UserUame,
                        CreatedOn          = outStorageCreatedOn,
                        LastUpdatedOn      = outStorageCreatedOn,
                        TotalPackageNumber = createOutStorageExt.TotalPackageNumber,
                        Remark             = createOutStorageExt.Remark,
                        TotalQty           = createOutStorageExt.TotalQty,
                        TotalVotes         = createOutStorageExt.TotalVotes,
                        TotalWeight        = createOutStorageExt.TotalWeight,
                        VenderCode         = createOutStorageExt.OutStorage.VenderCode,
                        VenderName         = createOutStorageExt.OutStorage.VenderName
                    };
                    _totalPackageInfoRepository.Add(totalPackageInfo);

                    var relational = new TotalPackageOutStorageRelationalInfo
                    {
                        OutStorageID       = createOutStorageExt.OutStorage.OutStorageID,
                        TotalPackageNumber = createOutStorageExt.TotalPackageNumber,
                        CreatedOn          = DateTime.Now
                    };
                    _totalPackageOutStorageRelationalInfoRepository.Add(relational);
                }
                else
                {
                    ////追加到已存在的总包号里面
                    var totalPackageInfo =
                        _totalPackageInfoRepository.Single(
                            p =>
                            p.TotalPackageNumber == createOutStorageExt.TotalPackageNumber &&
                            p.VenderCode == createOutStorageExt.OutStorage.VenderCode);
                    if (totalPackageInfo != null)
                    {
                        totalPackageInfo.TotalQty     += createOutStorageExt.TotalQty;
                        totalPackageInfo.TotalVotes   += createOutStorageExt.TotalVotes;
                        totalPackageInfo.TotalWeight  += createOutStorageExt.TotalWeight;
                        totalPackageInfo.LastUpdatedBy = _workContext.User.UserUame;
                        totalPackageInfo.LastUpdatedOn = outStorageCreatedOn;
                        _totalPackageInfoRepository.Modify(totalPackageInfo);
                        var relational = new TotalPackageOutStorageRelationalInfo
                        {
                            OutStorageID       = createOutStorageExt.OutStorage.OutStorageID,
                            TotalPackageNumber = createOutStorageExt.TotalPackageNumber,
                            CreatedOn          = DateTime.Now
                        };
                        _totalPackageOutStorageRelationalInfoRepository.Add(relational);
                    }
                }
                using (var transaction = new TransactionScope())
                {
                    _totalPackageInfoRepository.UnitOfWork.Commit();
                    _totalPackageOutStorageRelationalInfoRepository.UnitOfWork.Commit();
                    transaction.Complete();
                }
            }
        }
Example #4
0
 public string CreateTotalPackageNumber()
 {
     return(SequenceNumberService.GetSequenceNumber(PrefixCode.TotalPackageID));
 }
Example #5
0
        //收货页面运单出仓运输方式,修改出仓信息
        public ResponseResult UpdateOutStorageInfoAll(string wayBillLists, int outshippingMethodId, string outshippingMethodName, string venderCode, string remark, out List <string> outStorageIds)
        {
            var result = new ResponseResult();

            result.Result = false;
            List <string> aList = new List <string>();

            try
            {
                var wayBillList    = wayBillLists.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                var newwayBillList = _wayBillInfoRepository.GetList(p => wayBillList.Contains(p.WayBillNumber));
                var vender         = _freightService.GetVender(venderCode);

                //修改之前出仓Id
                newwayBillList.ForEach(p =>
                {
                    if (!aList.Contains(p.OutStorageID))
                    {
                        aList.Add(p.OutStorageID);
                    }
                });
                //判断是否配置了相应的出仓渠道
                var        deliveryChannelConfiguration = _deliveryChannelConfigurationRepository.GetList(p => p.VenderId == vender.VenderId && p.OutShippingMethodId == outshippingMethodId);
                List <int> inShippingMethodIds          = new List <int>();
                deliveryChannelConfiguration.ForEach(p => inShippingMethodIds.Add(p.InShippingMethodId));
                List <string> errorinShippingMethod = new List <string>();
                newwayBillList.ForEach(p =>
                {
                    if (p.InShippingMethodID == null || !inShippingMethodIds.Contains(p.InShippingMethodID.Value))
                    {
                        if (!errorinShippingMethod.Contains(p.InShippingMethodName))
                        {
                            errorinShippingMethod.Add(p.InShippingMethodName);
                        }
                    }
                });
                if (errorinShippingMethod.Count > 0)
                {
                    result.Result = false;
                    errorinShippingMethod.ForEach(p =>
                    {
                        result.Message += "[" + p + "]";
                    });
                    result.Message += "未配置相应的发货运输渠道!";
                    outStorageIds   = null;
                    return(result);
                }
                //创建新出仓信息
                OutStorageInfo outStorage = new OutStorageInfo();
                outStorage.OutStorageID = SequenceNumberService.GetSequenceNumber(PrefixCode.OutStorageID);
                outStorage.VenderCode   = venderCode;
                if (vender != null)
                {
                    outStorage.VenderName = vender.Name;
                }
                outStorage.Freight    = 0;
                outStorage.FuelCharge = 0;
                outStorage.Register   = 0;
                outStorage.TotalFee   = 0;

                outStorage.TotalQty = newwayBillList.Count;
                newwayBillList.ForEach(p =>
                {
                    outStorage.TotalWeight += p.SettleWeight ?? 0;
                });
                outStorage.Surcharge     = 0;
                outStorage.Status        = 1;
                outStorage.Remark        = remark;
                outStorage.CreatedBy     = _workContext.User.UserUame;
                outStorage.CreatedOn     = DateTime.Now;
                outStorage.LastUpdatedBy = _workContext.User.UserUame;
                outStorage.LastUpdatedOn = DateTime.Now;

                _outStorageInfoRepository.Add(outStorage);
                _outStorageInfoRepository.UnitOfWork.Commit();


                //修改运单出仓运输方式
                newwayBillList.ForEach(p =>
                {
                    p.OutShippingMethodID   = outshippingMethodId;
                    p.OutShippingMethodName = outshippingMethodName;
                    p.OutStorageID          = outStorage.OutStorageID;
                    p.VenderCode            = venderCode;
                    p.OutStorageCreatedOn   = DateTime.Now;
                    p.LastUpdatedBy         = _workContext.User.UserUame;
                    p.LastUpdatedOn         = DateTime.Now;
                    _wayBillInfoRepository.Modify(p);
                });
                _wayBillInfoRepository.UnitOfWork.Commit();
                result.Result = true;
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
                result.Result = false;
            }
            outStorageIds = aList;
            return(result);
        }
        public void BatchAddReturnGoods(List <ReturnGoodsExt> list)
        {
            var returnList = list.FindAll(p => p.IsDirectReturnGoods).Where(returnGoods =>
                                                                            !_returnGoodsRepository.Exists(p => p.WayBillNumber == returnGoods.WayBillNumber)).ToList();

            if (returnList.Any())
            {
                //直接退货操作
                foreach (var returnGoods in returnList)
                {
                    #region 修改订单、运单状态

                    var wayBillInfo = _wayBillInfoRepository.Get(returnGoods.WayBillNumber);
                    if (wayBillInfo != null)
                    {
                        if (wayBillInfo.Status != (int)WayBill.StatusEnum.Send && wayBillInfo.Status != (int)WayBill.StatusEnum.WaitOrder)
                        {
                            throw new Exception(string.Format("运单{0}的状态不是已发货或待转单", returnGoods.WayBillNumber));
                        }

                        wayBillInfo.Status                   = WayBill.StatusToValue(WayBill.StatusEnum.ReGoodsInStorage);
                        wayBillInfo.LastUpdatedOn            = DateTime.Now;
                        wayBillInfo.LastUpdatedBy            = returnGoods.UserName;
                        wayBillInfo.CustomerOrderInfo.Status =
                            CustomerOrder.StatusToValue(CustomerOrder.StatusEnum.ReGoodsInStorage);
                        wayBillInfo.CustomerOrderInfo.LastUpdatedBy = returnGoods.UserName;
                        wayBillInfo.CustomerOrderInfo.LastUpdatedOn = DateTime.Now;
                        _wayBillInfoRepository.Modify(wayBillInfo);
                    }
                    #endregion

                    #region 录入内部信息

                    if (wayBillInfo != null)
                    {
                        //Add By zxq
                        //Time:2014-09-15
                        var wayBillEventLog = new WayBillEventLog()
                        {
                            WayBillNumber = wayBillInfo.WayBillNumber,
                            EventCode     = (int)WayBillEvent.EventCodeEnum.OutStorage,
                            Description   = WayBillEvent.GetEventCodeDescription((int)WayBillEvent.EventCodeEnum.OutStorage),
                            EventDate     = DateTime.Now,
                            LastUpdatedOn = DateTime.Now,
                            Operator      = returnGoods.UserName,
                        };

                        _wayBillEventLogRepository.Add(wayBillEventLog);
                    }

                    #endregion

                    //退货详细
                    if (wayBillInfo != null)
                    {
                        ReceivingExpensesEditExt receivingExpensesEditExt = new ReceivingExpensesEditExt();
                        receivingExpensesEditExt =
                            _financialService.GetReceivingExpensesEditExt(wayBillInfo.WayBillNumber);
                        ReturnGoods rgGoods = new ReturnGoods()
                        {
                            WayBillNumber    = returnGoods.WayBillNumber,
                            Weight           = returnGoods.Weight != 0 ? returnGoods.Weight : wayBillInfo.Weight.Value,
                            CreatedBy        = returnGoods.UserName,
                            CreatedOn        = DateTime.Now,
                            IsReturnShipping = returnGoods.IsReturnShipping,
                            LastUpdatedBy    = returnGoods.UserName,
                            LastUpdatedOn    = DateTime.Now,
                            Reason           = returnGoods.Reason,
                            ReasonRemark     = returnGoods.ReasonRemark,
                            ReGoodsId        = SequenceNumberService.GetSequenceNumber(PrefixCode.ReturnGoodsID),
                            Type             = returnGoods.Type,
                            Status           = (int)ReturnGood.ReturnStatusEnum.UnAudited,
                            ReturnSource     = (int)ReturnGood.ReturnSourceStatusEnum.CSReturn
                        };


                        //是否退运费
                        if (returnGoods.IsReturnShipping)
                        {
                            if (receivingExpensesEditExt != null)
                            {
                                if (receivingExpensesEditExt.TotalFeeFinal.HasValue)
                                {
                                    rgGoods.ShippingFee = receivingExpensesEditExt.TotalFeeFinal ?? 0;
                                }
                                else if (receivingExpensesEditExt.TotalFeeOriginal.HasValue)
                                {
                                    rgGoods.ShippingFee = receivingExpensesEditExt.TotalFeeOriginal ?? 0;
                                }
                            }
                            else
                            {
                                rgGoods.ShippingFee = 0;
                            }
                        }
                        else
                        {
                            rgGoods.ShippingFee = 0;
                        }
                        _returnGoodsRepository.Add(rgGoods);
                    }
                    using (var transaction = new TransactionScope())
                    {
                        _returnGoodsRepository.UnitOfWork.Commit();
                        _wayBillInfoRepository.UnitOfWork.Commit();
                        _wayBillEventLogRepository.UnitOfWork.Commit();
                        _receivingExpensRepository.UnitOfWork.Commit();
                        transaction.Complete();
                    }
                }
            }
        }
Example #7
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;
                    }
                });
            }
        }
Example #8
0
        public string CreateSettlement(string customerCode, string[] inStorageIDs)
        {
            var listInStorageInfo = _inStorageInfoRepository.GetList(p => inStorageIDs.Contains(p.InStorageID) && p.CustomerCode == customerCode && !p.InStorageOrSettlementRelationals.Any() && (p.PaymentTypeID == 3 || p.PaymentTypeID == 4));

            if (!listInStorageInfo.Any())
            {
                throw new BusinessLogicException("该客户下没有未生成结算单的入仓单");
            }

            //获取结算单号
            string settlementNumber = SequenceNumberService.GetSequenceNumber(PrefixCode.SettlementID);

            List <ReceivingExpensesEditExt> listReceivingExpenses = new List <ReceivingExpensesEditExt>();
            List <WayBillInfo> listWayBillInfo = new List <WayBillInfo>();

            foreach (InStorageInfo inStorageInfo in listInStorageInfo)
            {
                _inStorageOrSettlementRelationalRepository.Add(new InStorageOrSettlementRelational()
                {
                    InStorageID      = inStorageInfo.InStorageID,
                    SettlementNumber = settlementNumber,
                });


                foreach (WayBillInfo wayBillInfo in inStorageInfo.WayBillInfos)
                {
                    listWayBillInfo.Add(wayBillInfo);
                    listReceivingExpenses.Add(_receivingExpensRepository.GetReceivingExpensesEditEx(wayBillInfo.WayBillNumber));
                }
            }

            var customer             = _customerRepository.GetFiltered(c => c.CustomerCode == customerCode).FirstOrDefault();
            var customerManagerInfos = _customerManagerInfoRepository.GetFiltered(c => c.Name == customer.CustomerManager).FirstOrDefault();

            SettlementInfo settlementInfo = new SettlementInfo()
            {
                SettlementNumber  = settlementNumber,
                CustomerCode      = customerCode,
                TotalNumber       = listInStorageInfo.Select(s => s.TotalQty.Value).Sum(),
                TotalWeight       = listInStorageInfo.Select(s => s.PhysicalTotalWeight).Sum(),
                TotalSettleWeight = listInStorageInfo.Select(s => s.TotalWeight.Value).Sum(),
                TotalFee          = listReceivingExpenses.Select(s => s.TotalFeeOriginal.Value).Sum(),
                Status            = 1,
                SalesMan          = customer.CustomerManager,
                SalesManTel       = customerManagerInfos == null?"":(customerManagerInfos.Tel ?? customerManagerInfos.Mobile),
                CreatedBy         = _workContext.User.UserUame,
                CreatedOn         = DateTime.Now,
                LastUpdatedBy     = _workContext.User.UserUame,
                LastUpdatedOn     = DateTime.Now,
            };

            _settlementInfoRepository.Add(settlementInfo);

            var query =
                from w in listWayBillInfo
                join r in listReceivingExpenses on w.WayBillNumber equals r.WayBillNumber
                group w by w.InShippingMethodID;

            var listSettlementDetailsInfo = from q in query
                                            select
                                            new SettlementDetailsInfo
            {
                SettlementNumber   = settlementNumber,
                ShippingMethodID   = q.Key,
                ShippingMethodName = q.Select(w => w.InShippingMethodName).FirstOrDefault(),
                TotalNumber        = q.Count(),
                TotalWeight        = q.Select(w => w.Weight.Value).Sum(),
                TotalSettleWeight  = q.Select(w => w.SettleWeight.Value).Sum(),
                TotalFee           = listReceivingExpenses.Where(r => q.Select(w => w.WayBillNumber).Contains(r.WayBillNumber)).Select(r => r.TotalFeeOriginal.Value).Sum()
            };

            foreach (SettlementDetailsInfo settlementDetailsInfo in listSettlementDetailsInfo)
            {
                _settlementDetailsInfoRepository.Add(settlementDetailsInfo);
            }

            using (var transaction = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 5, 0)))
            {
                _settlementInfoRepository.UnitOfWork.Commit();
                _inStorageOrSettlementRelationalRepository.UnitOfWork.Commit();
                _settlementDetailsInfoRepository.UnitOfWork.Commit();

                transaction.Complete();

                return(settlementNumber);
            }
        }
        /// <summary>
        /// CS版,快递入仓 add by huhaiyou 2014-4-25
        /// </summary>
        /// <param name="model"></param>
        /// <param name="wayBilllist"></param>
        /// <returns></returns>
        public ResponseResult CreateInStorageCS(InStorageSaveModel model)
        {
            var responseResult = new ResponseResult();

            if (model != null && model.WayBillInfoSaveList != null && model.WayBillInfoSaveList.Count > 0)
            {
                var inStorage = new CreateInStorageExtCS
                {
                    InStorage =
                    {
                        CustomerCode  = model.CustomerCode,
                        InStorageID   = SequenceNumberService.GetSequenceNumber(PrefixCode.InStorageID),
                        TotalQty      =                                                               0,
                        TotalWeight   =                                                               0,
                        CreatedBy     = model.OperatorUserName,
                        ReceivingDate = model.ReceivingDate,
                    }
                };

                model.WayBillInfoSaveList.ForEach(w =>
                {
                    var shippingMethod = _freightService.GetShippingMethod(w.ShippingMethodId);

                    if (!string.IsNullOrWhiteSpace(w.WayBillNumber))
                    {
                        //根据转换重量转换成文件类型 Add by zhengsong
                        #region
                        if (shippingMethod != null)
                        {
                            if (shippingMethod.Enabled && shippingMethod.ShippingMethodTypeId == 4)//4-代表EMS
                            {
                                if (w.Weight <= shippingMethod.PackageTransformFileWeight)
                                {
                                    w.GoodsTypeID = 2;//2-代表文件类型
                                }
                            }
                        }
                        #endregion
                        var extmodel               = new LMS.Data.Entity.ExtModel.WayBillInfoExt();
                        extmodel.CustomerCode      = model.CustomerCode.Trim();
                        extmodel.CustomerType      = model.CustomerType;
                        extmodel.GoodsTypeID       = w.GoodsTypeID;
                        extmodel.Length            = w.Length;
                        extmodel.Height            = w.Height;
                        extmodel.Width             = w.Width;
                        extmodel.Weight            = w.Weight;
                        extmodel.ShippingMethodId  = w.ShippingMethodId;
                        extmodel.TrackingNumber    = w.TrackingNumber;
                        extmodel.SettleWeight      = w.SettleWeight;
                        extmodel.WayBillNumber     = w.WayBillNumber.Trim();
                        extmodel.PriceResult       = w.PriceResult;
                        extmodel.IsBusinessExpress = w.IsBusinessExpress;
                        extmodel.IsBattery         = w.IsBattery;
                        extmodel.SensitiveType     = w.SensitiveType;

                        foreach (var package in w.waybillPackageDetailList)
                        {
                            WaybillPackageDetailExt packageModel = new WaybillPackageDetailExt();
                            packageModel.WayBillNumber           = w.WayBillNumber;
                            packageModel.Weight       = package.Weight.Value;
                            packageModel.AddWeight    = package.AddWeight.Value;
                            packageModel.SettleWeight = package.SettleWeight.Value;
                            packageModel.Length       = package.Length.Value;
                            packageModel.Width        = package.Width.Value;
                            packageModel.Height       = package.Height.Value;
                            packageModel.LengthFee    = package.LengthFee.Value;
                            packageModel.WeightFee    = package.WeightFee.Value;
                            extmodel.WaybillPackageDetailList.Add(packageModel);
                        }

                        inStorage.WayBillInfos.Add(extmodel);
                        inStorage.InStorage.TotalWeight += w.SettleWeight;
                        inStorage.InStorage.TotalQty++;
                    }
                });
                try
                {
                    _inStorageService.CreateInStorageCS(inStorage);
                    responseResult.Result  = true;
                    responseResult.Message = inStorage.InStorage.InStorageID;
                }
                catch (Exception ex)
                {
                    Log.Exception(ex);
                    responseResult.Result  = false;
                    responseResult.Message = ex.Message;
                }
            }
            return(responseResult);
        }