Пример #1
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);
        }
Пример #2
0
        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);
        }