Esempio n. 1
0
        public static List <CarObject> GetCarObjectRecordAndBaoYangRecord(int startIndex, int endIndex)
        {
            var result = new List <CarObject>();

            try
            {
                var dt = SuggestDal.GetCarObjectRecordAndBaoYangRecord(startIndex, endIndex).AsEnumerable();
                if (dt.Any())
                {
                    foreach (var row in dt)
                    {
                        var      item = new CarObject();
                        Guid     userId;
                        Guid     carId;
                        DateTime odometerTime;
                        int      kmTotal;
                        int      buyYear;
                        int      buyMonth;
                        DateTime baoYangDateTime;
                        int      distance;
                        int      nian         = 0;
                        bool     isTuhuRecord = false;
                        if (Guid.TryParse(row["UserID"].ToString(), out userId) &&
                            Guid.TryParse(row["CarID"].ToString(), out carId) &&
                            DateTime.TryParse(row["OdometerUpdatedTime"].ToString(), out odometerTime) &&
                            (DateTime.TryParse(row["BaoYangDateTime"].ToString(), out baoYangDateTime) ||
                             row["BaoYangDateTime"].ToString().Equals(string.Empty)) &&
                            (int.TryParse(row["Distance"].ToString(), out distance) ||
                             row["Distance"].ToString().Equals(string.Empty)))
                        {
                            item.UserId          = userId;
                            item.CarId           = carId;
                            item.VehicleId       = (string)(row["u_cartype_pid_vid"].ToString());
                            item.OdometerTime    = odometerTime;
                            item.I_km_total      = int.TryParse(row["i_km_total"].ToString(), out kmTotal)?kmTotal:0;
                            item.BuyYear         = int.TryParse(row["i_buy_year"].ToString(), out buyYear) ? buyYear : 0;
                            item.BuyMonth        = int.TryParse(row["i_buy_month"].ToString(), out buyMonth)? buyMonth:0;
                            item.Nian            = Int32.TryParse(row["u_Nian"].ToString(), out nian)?nian:0;
                            item.BaoyangDateTime = baoYangDateTime;
                            item.BaoYangType     = (string)(row["BaoYangType"].ToString());
                            item.BaoYangDistance = int.TryParse(row["Distance"].ToString(), out distance)?distance:0;
                            item.IsTuhuRecord    = Boolean.TryParse(row["isTuhuRecord"].ToString(), out isTuhuRecord) && isTuhuRecord;
                            result.Add(item);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message, ex);
            }

            return(result);
        }
Esempio n. 2
0
 public static void UpdateBaoYangSuggest(List <SuggestModel> suggestData)
 {
     try
     {
         var dt = PrepareDataTable(suggestData);
         SuggestDal.UpdateBaoYangSuggest(dt);
     }
     catch (Exception ex)
     {
         logger.Error(ex.Message, ex);
     }
 }
Esempio n. 3
0
        public static List <SuggestModel> GetActiveUserSuggestModels(int startIndex, int endIndex)
        {
            List <SuggestModel> result = null;

            try
            {
                result = SuggestDal.GetActiveUserSuggestModels(startIndex, endIndex);
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message, ex);
            }
            return(result);
        }
Esempio n. 4
0
        public static Tuple <bool, int> AddCarObjectRecord()
        {
            Tuple <bool, int> result = null;

            try
            {
                result = SuggestDal.AddCarObjectRecord();
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message, ex);
            }

            return(result);
        }
Esempio n. 5
0
        public static void MaintainBaoYangRecordNewData()
        {
            int maxId = SuggestDal.SelectMaxId();
            int batch = maxId / 10000;
            int index = 1;

            logger.Info($"维护新数据:{batch}");
            while (index <= batch)
            {
                logger.Info($"维护新数据:{index} 批开始");
                SuggestDal.UpdateNewData(index);
                logger.Info($"维护新数据:{index} 批结束");
                index++;
            }
        }
Esempio n. 6
0
 public static void UpsertCache()
 {
     try
     {
         var result = SuggestDal.TemporarySaveActiveUserSuggest();
         if (result)
         {
             var index = 0;
             List <SuggestModel> suggestModels = null;
             do
             {
                 var startIndex = index * 1000 + 1;
                 var endIndex   = (index + 1) * 1000;
                 suggestModels = GetActiveUserSuggestModels(startIndex, endIndex);
                 if (suggestModels != null && suggestModels.Any())
                 {
                     foreach (var sugggest in suggestModels)
                     {
                         UpsertCache(sugggest.UserId.ToString(), sugggest.CarId, sugggest.SuggestNum,
                                     sugggest.UrgentNum, sugggest.VeryUrgentNum);
                     }
                     index++;
                     logger.Info("成功向缓存 upsert第" + index + "批数据");
                 }
             } while (suggestModels != null && suggestModels.Any());
         }
         else
         {
             logger.Info("没有活跃用户在今天的推荐里");
         }
     }
     catch (Exception ex)
     {
         logger.Error(ex.Message, ex);
     }
 }
Esempio n. 7
0
        public static bool UpdateBaoYangRecord(bool isHalfYear = false)
        {
            bool result = false;

            try
            {
                var caneledIds = new List <int>();
                int pageIndex  = 1;

                logger.Info("开始更新用户保养记录!");

                logger.Info($"删除取消订单相关的保养记录, 开始!");
                do
                {
                    logger.Info($"第{pageIndex}批");
                    caneledIds = SuggestDal.SelectCanceledOrderIds(pageIndex, 500);
                    if (caneledIds != null && caneledIds.Any())
                    {
                        logger.Info($"删除取消订单相关的保养记录, 共{caneledIds.Count()}条!");
                        SuggestDal.DeleteBaoYangRecord(caneledIds);
                        logger.Info($"删除取消订单相关的保养记录, 共{caneledIds.Count()}条结束!");
                    }

                    pageIndex++;
                }while (caneledIds != null && caneledIds.Any());

                logger.Info($"删除取消订单相关的保养记录, 结束!");

                logger.Info($"更新订单相关的保养记录, 开始!");
                var updateIds = new List <int>();
                pageIndex = 1;
                var config     = SuggestDal.SelectUserBaoYangRecordConfig();
                var minOrderId = SuggestDal.SelectMinOrderIdInHalfYear();
                logger.Info($"历史订单id:{minOrderId}");
                do
                {
                    logger.Info($"第{pageIndex}批");

                    if (isHalfYear)
                    {
                        updateIds = SuggestDal.SelectUpdatedOrderIdsInHalfYear(minOrderId, pageIndex, 500);
                    }
                    else
                    {
                        updateIds = SuggestDal.SelectUpdatedOrderIds(pageIndex, 500);
                    }

                    List <UserBaoYangRecordModel> newData = new List <UserBaoYangRecordModel>();
                    var noVehicleData = SuggestDal.SelectBaoYangRecordsFromOrder(updateIds);    //从订单中获取用户保养记录(不含里程)

                    var oldData = SuggestDal.SelectBaoYangRecordsFromMaintainedData(updateIds); //根据订单获取用户保养档案中数据
                    var cars    = SuggestDal.SelectCarsFormOrder(updateIds);                    //从订单车型表中获取车型里程信息
                    if (noVehicleData != null && cars != null)
                    {
                        foreach (var data in noVehicleData)
                        {
                            var car = cars.Where(o => o.OrderId == data.RelatedOrderID).OrderBy(o => o.UserCreated)
                                      .FirstOrDefault();
                            if (car != null && !string.IsNullOrEmpty(car.VehicleId))
                            {
                                newData.Add(new UserBaoYangRecordModel()
                                {
                                    UserID          = data.UserID,
                                    UserCarID       = data.UserCarID,
                                    BaoYangDateTime = data.BaoYangDateTime,
                                    PID             = data.PID,
                                    Category        = data.Category,
                                    RelatedOrderID  = data.RelatedOrderID,
                                    RelatedOrderNo  = data.RelatedOrderNo,
                                    Status          = data.Status,
                                    IsTuhuRecord    = data.IsTuhuRecord,
                                    OrderPrice      = data.OrderPrice,
                                    InstallShopId   = data.InstallShopId,
                                    InstallShopName = data.InstallShopName,
                                    VechileID       = car.VehicleId,
                                    Distance        = car.Distance
                                });
                            }
                        }
                    }

                    var operationResult = CompareData(ConvertOrderData(newData, config), oldData);

                    var toDelete = operationResult.Item1;
                    if (toDelete != null && toDelete.Any())
                    {
                        logger.Info($"更新订单相关的保养记录, 共{operationResult.Item1.Count}条待删除!");
                        SuggestDal.DeleteBaoYangRecordByPkids(toDelete);
                        logger.Info($"更新订单相关的保养记录, 共{operationResult.Item1.Count}条待删除结束!");
                    }

                    var toUpdate = operationResult.Item2;
                    if (toUpdate != null && toUpdate.Any())
                    {
                        logger.Info($"更新订单相关的保养记录, 共{operationResult.Item2.Count}条待更新!");
                        SuggestDal.UpdateBaoYangRecord(toUpdate);
                        logger.Info($"更新订单相关的保养记录, 共{operationResult.Item2.Count}条待更新结束!");
                    }

                    var toInsert = operationResult.Item3;
                    if (toInsert != null && toInsert.Any())
                    {
                        logger.Info($"更新订单相关的保养记录, 共{operationResult.Item3.Count}条待插入!");
                        SuggestDal.InsertBaoYangRecords(toInsert);
                        logger.Info($"更新订单相关的保养记录, 共{operationResult.Item3.Count}条待插入结束!");
                    }

                    pageIndex++;
                }while (updateIds != null && updateIds.Any());

                logger.Info($"更新订单相关的保养记录, 完成!");

                result = true;
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message, ex);
            }

            return(result);
        }
Esempio n. 8
0
        public static List <UserBaoYangRecordModel> ConvertOrderData(List <UserBaoYangRecordModel> records, List <Model.UserBaoYangRecordConfig> config)
        {
            foreach (var record in records)
            {
                if (config.Any(o => string.Equals(o.ServiceId, record.PID)))
                {
                    record.BaoYangType = config.First(o => string.Equals(o.ServiceId, record.PID)).PackageType;
                }

                if (config.Any(o => string.Equals(o.ProductCategory, record.Category)))
                {
                    record.BaoYangType = config.First(o => string.Equals(o.ProductCategory, record.Category)).PackageType;
                }
            }

            foreach (var orderId in records.Select(o => o.RelatedOrderID).Distinct().ToList())
            {
                var current = records.Where(o => o.RelatedOrderID == orderId);

                if (current.Any(o => string.Equals(o.BaoYangType, "xby")) && current.Any(o => string.Equals(o.BaoYangType, "dby")))
                {
                    records.RemoveAll(o => o.RelatedOrderID == orderId && string.Equals(o.BaoYangType, "xby"));
                }
            }

            records = records.Where(o => !string.IsNullOrEmpty(o.BaoYangType)).
                      GroupBy(o => $"{o.RelatedOrderID}/{o.BaoYangType}").Select(o => o.First()).ToList();
            var orderDistances = SuggestDal.SelectBaoYangRecordOrderDistance(records.Select(o => o.RelatedOrderID).ToList()) ?? new List <OrderCarModel>();//从订单里程关联表中获取里程信息
            List <MileageInfo> distanceInfos = new List <MileageInfo>();

            using (var client = new WorkShopClient())
            {
                var IdStr         = string.Join(",", records.Where(o => o.Status == 1).Select(o => o.RelatedOrderID)); //已安装订单
                var serviceResult = client.QueryMileageInfoByMultipleOrder(IdStr);                                     //从门店安装单获取里程
                if (serviceResult.Success && serviceResult.Result != null && serviceResult.Result.Any())
                {
                    distanceInfos = serviceResult.Result;
                }
            }
            foreach (var record in records)
            {
                var orderDistance = orderDistances.FirstOrDefault(s => s.OrderId == record.RelatedOrderID);//手动修改过订单里程
                if (orderDistance != null)
                {
                    record.Distance = orderDistance.Distance;
                }
                else
                {
                    var distanceInfo = distanceInfos?.FirstOrDefault(s =>
                                                                     string.Equals(s.Order.Trim(), record.RelatedOrderID.ToString()));//从门店安装单中获取里程
                    if (distanceInfo != null)
                    {
                        int orderId  = 0;
                        int distance = 0;
                        if (Int32.TryParse(distanceInfo.Mileage, out distance) &&
                            Int32.TryParse(distanceInfo.Order, out orderId) &&
                            record.RelatedOrderID == orderId)
                        {
                            record.Distance = distance;
                        }
                    }
                }
            }

            return(records);
        }
        public static bool UpdateBaoYangRecord()
        {
            bool result = false;

            try
            {
                var caneledIds = new List <int>();
                int pageIndex  = 1;

                logger.Info("开始更新用户保养记录!");

                logger.Info($"删除取消订单相关的保养记录, 开始!");
                do
                {
                    logger.Info($"第{pageIndex}批");
                    caneledIds = SuggestDal.SelectCanceledOrderIds(pageIndex, 500);
                    if (caneledIds != null && caneledIds.Any())
                    {
                        logger.Info($"删除取消订单相关的保养记录, 共{caneledIds.Count()}条!");
                        SuggestDal.DeleteBaoYangRecord(caneledIds);
                        logger.Info($"删除取消订单相关的保养记录, 共{caneledIds.Count()}条结束!");
                    }

                    pageIndex++;
                }while (caneledIds != null && caneledIds.Any());

                logger.Info($"删除取消订单相关的保养记录, 结束!");

                logger.Info($"更新订单相关的保养记录, 开始!");
                var updateIds = new List <int>();
                pageIndex = 1;
                var config = SuggestDal.SelectUserBaoYangRecordConfig();
                do
                {
                    logger.Info($"第{pageIndex}批");
                    updateIds = SuggestDal.SelectUpdateddOrderIds(pageIndex, 500);
                    var newData = SuggestDal.SelectBaoYangRecordsFromOrder(updateIds);
                    var oldData = SuggestDal.SelectBaoYangRecordsFromMaintainedData(updateIds);

                    var operationResult = CompareData(ConvertOrderData(newData, config), oldData);

                    var toDelete = operationResult.Item1;
                    if (toDelete != null && toDelete.Any())
                    {
                        logger.Info($"更新订单相关的保养记录, 共{operationResult.Item1.Count()}条待删除!");
                        SuggestDal.DeleteBaoYangRecordByPkids(toDelete);
                        logger.Info($"更新订单相关的保养记录, 共{operationResult.Item1.Count()}条待删除结束!");
                    }

                    var toUpdate = operationResult.Item2;
                    if (toUpdate != null && toUpdate.Any())
                    {
                        logger.Info($"更新订单相关的保养记录, 共{operationResult.Item2.Count()}条待更新!");
                        SuggestDal.UpdateBaoYangRecord(toUpdate);
                        logger.Info($"更新订单相关的保养记录, 共{operationResult.Item2.Count()}条待更新结束!");
                    }

                    var toInsert = operationResult.Item3;
                    if (toInsert != null && toInsert.Any())
                    {
                        logger.Info($"更新订单相关的保养记录, 共{operationResult.Item3.Count()}条待插入!");
                        SuggestDal.InsertBaoYangRecords(toInsert);
                        logger.Info($"更新订单相关的保养记录, 共{operationResult.Item3.Count()}条待插入结束!");
                    }

                    pageIndex++;
                }while (updateIds != null && updateIds.Any());

                logger.Info($"更新订单相关的保养记录, 完成!");

                result = true;
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message, ex);
            }

            return(result);
        }