Exemple #1
0
        public static void DeleteInTrackingLogInfo(string wayBillNumber)
        {
            InTrackingLogInfoRepository inTrackingLogInfoRepository = new InTrackingLogInfoRepository(new LMS_DbContext());

            inTrackingLogInfoRepository.Remove(i => i.WayBillNumber == wayBillNumber);
            inTrackingLogInfoRepository.UnitOfWork.Commit();
        }
Exemple #2
0
        private static void Main(string[] args)
        {
            try
            {
                WayBillInfoRepository wayBillInfoRepository = new WayBillInfoRepository(new LMS_DbContext());
                TotalPackageOutStorageRelationalInfoRepository totalPackageOutStorageRelational =
                    new TotalPackageOutStorageRelationalInfoRepository(new LMS_DbContext());

                InTrackingLogInfoRepository inTrackingLogInfoRepository = new InTrackingLogInfoRepository(new LMS_DbContext());

                //最后的序号
                int lastWayBillEventLogId = 0;

                //获取所有需要处理的,每次取一定数量,往前移动
                List <WayBillEventLogExt> wayBillEventLogExtList;

                while ((wayBillEventLogExtList = wayBillInfoRepository.GetWayBillEventLogExtList(lastWayBillEventLogId, 50)).Any())
                {
                    Console.WriteLine("获取到条数:{0}", wayBillEventLogExtList.Count);
                    Log.Info(string.Format("获取到条数:{0}", wayBillEventLogExtList.Count));

                    //记录最后的序号
                    lastWayBillEventLogId = wayBillEventLogExtList.Last().WayBillEventLogId;

                    try
                    {
                        //所有运输方式ID
                        var shippingMethodIds =
                            wayBillEventLogExtList.Where(p => p.ShippingMethodId.HasValue).GroupBy(p => p.ShippingMethodId.Value).Select(p => p.Key).ToList();

                        //获取运输方式信息
                        var shippingMethodList = GetShippingMethodsByIds(shippingMethodIds);

                        List <InTrackingLogInfo>  inTrackingLogInfoList         = new List <InTrackingLogInfo>();
                        List <WayBillEventLogExt> wayBillEventLogExtChangedList = new List <WayBillEventLogExt>();
                        wayBillEventLogExtList.ForEach(p =>
                        {
                            if (p.EventCode == (int)WayBillEvent.EventCodeEnum.InStorage)
                            {
                                //收货后,删除预报记录
                                inTrackingLogInfoRepository.Remove(i => i.WayBillNumber == p.WayBillNumber);
                                inTrackingLogInfoList.Remove(i => i.WayBillNumber == p.WayBillNumber);
                            }

                            InTrackingLogInfo inTrackingLogInfo = null;

                            var shippingMethod = shippingMethodList.FirstOrDefault(pp => pp.ShippingMethodId == p.ShippingMethodId);
                            if (shippingMethod != null && !shippingMethod.Code.IsNullOrWhiteSpace())
                            {
                                switch (shippingMethod.Code)
                                {
                                case "SPLUS":
                                case "SPLUSZ":
                                    // 中美专线shippingMethod.TrackingUrl.Contains("worldtrack.dhlglobalmail.com")
                                    inTrackingLogInfo = GenerateInTrackingLogInfoGdm(p);
                                    break;

                                case "EUDDPG":
                                case "EUDDP":
                                    inTrackingLogInfo = GenerateInTrackingLogInfoEUD(p, totalPackageOutStorageRelational);
                                    break;

                                case "CNPOST-FYB":
                                    inTrackingLogInfo = GenerateInTrackingLogInfoFUB(p);
                                    break;

                                default:
                                    inTrackingLogInfo = GenerateInTrackingLogInfoCommon(p);
                                    break;
                                }
                            }
                            else
                            {
                                inTrackingLogInfo = GenerateInTrackingLogInfoCommon(p);
                            }

                            if (inTrackingLogInfo != null)
                            {
                                Console.WriteLine("需要更新运单:{0}", inTrackingLogInfo.WayBillNumber);

                                inTrackingLogInfoList.Add(inTrackingLogInfo);
                                wayBillEventLogExtChangedList.Add(p);
                            }
                        });

                        Log.Info(string.Format("需要更新运单数:{0}", inTrackingLogInfoList.Count));

                        if (inTrackingLogInfoList.Any())
                        {
                            Log.Info(string.Format("需要更新运单:{0}", string.Join(",", inTrackingLogInfoList.Select(p => p.WayBillNumber))));

                            using (var transaction = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 5, 0)))
                            {
                                wayBillInfoRepository.BulkInsert("InTrackingLogInfos", inTrackingLogInfoList);
                                UpdateWayBillEventLogExt(wayBillEventLogExtChangedList);
                                inTrackingLogInfoRepository.UnitOfWork.Commit();

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

#if DEBUG
            Console.WriteLine("执行完成,任意键退出...");
            Console.ReadLine();
#endif
        }