public Tuple <bool, bool> DeleteBatteryFastDelivery(int fastDeliveryId, int regionId) { var result = false; var cacheResult = true; try { var products = dbScopeManagerConfigRead.Execute(conn => DalBatteryFastDelivery.GetBatteryFastDeliveryProductsByFastDeliveryId(conn, fastDeliveryId.ToString())) .Select(s => s.ProductPid).ToList(); if (products.Any()) { dbScopeManagerConfig.CreateTransaction(conn => { var delMain = DalBatteryFastDelivery.DeleteBatteryFastDelivery(conn, fastDeliveryId); var delProduct = DalBatteryFastDelivery.DeleteBatteryProductsByFastDeliveryId(conn, fastDeliveryId); if (delMain && delProduct) { cacheResult = RefreshFastDeliveryServiceCache(regionId, products); result = true; } }); } else { result = dbScopeManagerConfig.Execute(conn => DalBatteryFastDelivery.DeleteBatteryFastDelivery(conn, fastDeliveryId)); } } catch (Exception ex) { Logger.Error("DeleteBatteryFastDelivery", ex); } return(Tuple.Create(result, cacheResult)); }
public List <BatteryFastDeliveryForViewModel> GetAllBatteryForView(int fastDeliveryId) { List <BatteryFastDeliveryForViewModel> allBattery = null; try { var sort = new List <string> { "风帆", "瓦尔塔" }; var batteries = dbScopeManagerProductRead.Execute(conn => DalBatteryFastDelivery.GetAllBattery(conn)//获取所有的蓄电池信息 ); allBattery = batteries.OrderBy(x => { var index = sort.FindIndex(o => x.Brand.Contains(o)); if (index < 0) { index = int.MaxValue; } return(index); }).ToList(); if (fastDeliveryId > 0) { var existBattery = dbScopeManagerConfigRead.Execute(conn => DalBatteryFastDelivery.GetBatteryFastDeliveryProductsByFastDeliveryId(conn, fastDeliveryId.ToString()) ).Select(s => s.ProductPid).ToList();//勾选已选中的蓄电池 allBattery.ForEach(s => s.IsChecked = existBattery.Contains(s.PID)); } } catch (Exception ex) { Logger.Error("GetAllBatteryForView", ex); } return(allBattery); }
/// <summary> /// 更新蓄电池极速达配置 /// </summary> /// <param name="model"></param> /// <param name="productModels"></param> /// <returns></returns> public Tuple <bool, bool> UpdateBatteryFastDelivery(BatteryFastDeliveryModel model, List <BatteryFastDeliveryProductsModel> productModels) { var result = false; var cacheResult = true; try { var existProducts = dbScopeManagerConfigRead.Execute(conn => DalBatteryFastDelivery.GetBatteryFastDeliveryProductsByFastDeliveryId(conn, model.PKID.ToString())); if ((productModels == null || !productModels.Any()) && (existProducts == null || !existProducts.Any())) { result = dbScopeManagerConfig.Execute(conn => DalBatteryFastDelivery.UpdateBatteryFastDelivery(conn, model)); } else { dbScopeManagerConfig.CreateTransaction(conn => { var updateMain = DalBatteryFastDelivery.UpdateBatteryFastDelivery(conn, model); productModels = productModels ?? new List <BatteryFastDeliveryProductsModel>(); existProducts = existProducts ?? new List <BatteryFastDeliveryProductsModel>(); var updateProducts = UpdateBatteryFastDeliveryProducts(conn, model.RegionId, productModels, existProducts); if (updateMain && updateProducts) { var refreshPids = productModels.Select(s => s.ProductPid).Union(existProducts.Select(e => e.ProductPid)).ToList(); cacheResult = RefreshFastDeliveryServiceCache(model.RegionId, refreshPids); result = true; } }); } } catch (Exception ex) { Logger.Error("UpdateBatteryFastDelivery", ex); } return(Tuple.Create(result, cacheResult)); }
public List <BatteryFastDeliveryProductsModel> GetBatteryFastDeliveryProductsByFastDeliveryId(int fastDeliveryId) { List <BatteryFastDeliveryProductsModel> batteryList = null; try { batteryList = dbScopeManagerConfigRead.Execute(conn => DalBatteryFastDelivery.GetBatteryFastDeliveryProductsByFastDeliveryId(conn, fastDeliveryId.ToString())); } catch (Exception ex) { Logger.Error("GetBatteryFastDeliveryProductsByFastDeliveryId", ex); } return(batteryList ?? new List <BatteryFastDeliveryProductsModel>()); }
public bool ChangeBatteryFastDeliveryStatus(int pkid, bool isEnabled, string user) { var success = false; try { List <string> products = null; BatteryFastDeliveryModel config = null; dbScopeManagerConfigRead.Execute(conn => { config = DalBatteryFastDelivery.SelectBatteryFastDeliveryById(conn, pkid); if (config != null) { var list = DalBatteryFastDelivery.GetBatteryFastDeliveryProductsByFastDeliveryId(conn, pkid.ToString()); products = list.Select(x => x.ProductPid).ToList(); } products = products ?? new List <string>(); }); if (config != null && config.IsEnabled != isEnabled) { success = dbScopeManagerConfig.Execute(conn => DalBatteryFastDelivery.UpdateBatteryFastDeliveryStatus(conn, pkid, isEnabled)); } if (success) { RecordOperationLog(new BaoYangOprLog { LogType = "BatteryFastDelivery", Remarks = $"{(isEnabled ? "启用配置" : "禁用配置")}", OldValue = JsonConvert.SerializeObject(new { PKID = pkid, IsEnabled = !isEnabled }), NewValue = JsonConvert.SerializeObject(new { PKID = pkid, IsEnabled = isEnabled }), IdentityID = pkid.ToString(), OperateUser = user, }); RefreshFastDeliveryServiceCache(config.RegionId, products); } } catch (Exception ex) { Logger.Error("ChangeBatteryFastDeliveryStatus", ex); } return(success); }
public Tuple <List <BatteryFastDeliveryModel>, int> SelectBatteryFastDelivery(string serviceTypePid, int pageIndex, int pageSize) { int totalCount = 0; List <BatteryFastDeliveryModel> fastDeliveryInfos = null; List <BatteryFastDeliveryProductsModel> batteryList = null; try { fastDeliveryInfos = dbScopeManagerConfigRead.Execute(conn => DalBatteryFastDelivery.SelectBatteryFastDelivery(conn, serviceTypePid, pageIndex, pageSize, out totalCount)); var fastDeliveryIdsStr = string.Join(",", fastDeliveryInfos.Select(s => s.PKID).ToList()); batteryList = dbScopeManagerConfigRead.Execute(conn => DalBatteryFastDelivery.GetBatteryFastDeliveryProductsByFastDeliveryId(conn, fastDeliveryIdsStr)); var batteryDic = batteryList.GroupBy(item => item.FastDeliveryId) .ToDictionary(i => i.Key, i => i.ToList().GroupBy(t => t.Brand).ToDictionary(j => j.Key, j => j.Select(s => s.ProductPid).Take(5).ToList())); using (var client = new RegionClient()) { foreach (var fastDeliveryInfo in fastDeliveryInfos) { fastDeliveryInfo.Products = batteryDic.ContainsKey(fastDeliveryInfo.PKID) ? batteryDic[fastDeliveryInfo.PKID] : null; var serviceResult = client.GetSimpleRegionByRegionId(fastDeliveryInfo.RegionId); serviceResult.ThrowIfException(true); if (serviceResult?.Result != null) { fastDeliveryInfo.ProvinceName = serviceResult.Result.ProvinceName; fastDeliveryInfo.CityName = serviceResult.Result.CityName; fastDeliveryInfo.DistrictName = serviceResult.Result.DistrictName; } } return(new Tuple <List <BatteryFastDeliveryModel>, int>(fastDeliveryInfos, totalCount)); } } catch (Exception ex) { Logger.Error("SelectBatteryFastDelivery", ex); return(new Tuple <List <BatteryFastDeliveryModel>, int>(null, 0)); } }