Exemple #1
0
        /// <summary>
        /// 批量新增或更新保养活动车型配置
        /// </summary>
        /// <param name="vehicleIds"></param>
        /// <param name="activityId"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public Tuple <bool, bool> MultiAddOrEditBaoYangActivityVehicle(List <string> vehicleIds, string activityId, string user)
        {
            bool result      = false;
            var  cacheResult = false;

            try
            {
                if (vehicleIds != null && vehicleIds.Any() && !string.IsNullOrWhiteSpace(activityId))
                {
                    var insertModels = new List <BaoYangActivityVehicleAndRegionModel>();
                    var updateValues = new List <BaoYangActivityVehicleAndRegionModel>();
                    var logData      = new List <BaoYangOprLog>();
                    foreach (var vehicleId in vehicleIds)
                    {
                        var oldValue = GetBaoYangActivityVehicleByVehicleId(vehicleId);
                        if (oldValue == null)
                        {
                            var insertModel = new BaoYangActivityVehicleAndRegionModel
                            {
                                VehicleId          = vehicleId,
                                ActivityId         = activityId,
                                RegionId           = 0,
                                Type               = "Vehicle",
                                CreateDateTime     = DateTime.Now,
                                LastUpdateDateTime = DateTime.Now
                            };
                            insertModels.Add(insertModel);
                        }
                        else
                        {
                            updateValues.Add(oldValue);
                        }
                    }
                    dbScopeManagerGungnir.CreateTransaction(conn =>
                    {
                        foreach (var insertModel in insertModels)
                        {
                            var pkid = DalBaoYangActivitySetting.AddBaoYangActivityVehicle(conn, insertModel);
                            if (pkid < 1)
                            {
                                throw new Exception($"AddBaoYangActivityVehicle失败,{JsonConvert.SerializeObject(insertModel)}");
                            }
                            insertModel.PKID = pkid;
                            var log          = new BaoYangOprLog
                            {
                                LogType     = "BaoYangActivityVehicle",
                                IdentityID  = insertModel.VehicleId,
                                OldValue    = null,
                                NewValue    = JsonConvert.SerializeObject(insertModel),
                                Remarks     = "Add",
                                OperateUser = user,
                            };
                            logData.Add(log);
                        }
                        foreach (var oldValue in updateValues)
                        {
                            var updateModel = new BaoYangActivityVehicleAndRegionModel
                            {
                                VehicleId          = oldValue.VehicleId,
                                ActivityId         = activityId,
                                RegionId           = oldValue.RegionId,
                                Type               = oldValue.Type,
                                CreateDateTime     = oldValue.CreateDateTime,
                                LastUpdateDateTime = DateTime.Now
                            };
                            var updateResult = DalBaoYangActivitySetting.UpdateBaoYangActivityVehicle(conn, updateModel);
                            if (!updateResult)
                            {
                                throw new Exception($"UpdateBaoYangActivityVehicle失败,{JsonConvert.SerializeObject(updateModel)}");
                            }
                            var log = new BaoYangOprLog
                            {
                                LogType     = "BaoYangActivityVehicle",
                                IdentityID  = updateModel.VehicleId,
                                OldValue    = JsonConvert.SerializeObject(oldValue),
                                NewValue    = JsonConvert.SerializeObject(updateModel),
                                Remarks     = "Update",
                                OperateUser = user,
                            };
                            logData.Add(log);
                        }
                        result = true;
                    });
                    foreach (var log in logData)
                    {
                        LoggerManager.InsertLog("BYOprLog", log);
                    }
                    cacheResult = CleanBaoYangActivityVehicleCache(vehicleIds);
                }
            }
            catch (Exception ex)
            {
                Logger.Error("MultiAddOrEditBaoYangActivityVehicle", ex);
            }
            return(Tuple.Create(result, cacheResult));
        }