/// <summary> /// 添加或更新选车攻略配置 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool UpSertVehicleArticle(VehicleArticleModel model) { var result = false; try { var oldValue = dbScopeManagerConfigurationRead.Execute(conn => DalVehicleArticle.GetVehicleArticle(conn, model)); if (oldValue == null) { model.CreateDateTime = DateTime.Now; var pkid = dbScopeManagerConfiguration.Execute (conn => DalVehicleArticle.AddVehicleArticle(conn, model)); result = pkid > 0; if (result) { model.PKID = pkid; model.LastUpdateDateTime = DateTime.Now; var log = new VehicleArticleOprLogModel { LogType = "VehicleArticle", IdentityId = $"{model.VehicleId}_{model.PaiLiang}_{model.Nian}", OperationType = "Add", OldValue = null, NewValue = JsonConvert.SerializeObject(model), Remarks = $"添加选车攻略:{model.VehicleId}_{model.PaiLiang}_{model.Nian}的配置", Operator = _user, }; LoggerManager.InsertLog("VehicleArticleOprLog", log); } } else { model.CreateDateTime = oldValue.CreateDateTime; model.LastUpdateDateTime = DateTime.Now; result = dbScopeManagerConfiguration.Execute(conn => DalVehicleArticle.UpdateVehicleArticle(conn, model)); if (result) { var log = new VehicleArticleOprLogModel { LogType = "VehicleArticle", IdentityId = $"{model.VehicleId}_{model.PaiLiang}_{model.Nian}", OperationType = "Update", OldValue = JsonConvert.SerializeObject(oldValue), NewValue = JsonConvert.SerializeObject(model), Remarks = $"更新选车攻略:{ model.VehicleId }_{ model.PaiLiang }_{ model.Nian }的配置", Operator = _user, }; LoggerManager.InsertLog("VehicleArticleOprLog", log); } } } catch (Exception ex) { Logger.Error("UpSertVehicleArticle", ex); } return(result); }
/// <summary> /// 批量删除选车攻略配置 /// </summary> /// <param name="models"></param> /// <returns></returns> public bool MultDeleteVehicleArticle(List <VehicleArticleModel> models) { var result = true; try { var delList = new List <VehicleArticleModel>(); var logs = new List <VehicleArticleOprLogModel>(); foreach (var model in models) { var oldValue = dbScopeManagerConfigurationRead.Execute(conn => DalVehicleArticle.GetVehicleArticle(conn, model)); if (oldValue != null) { delList.Add(oldValue); var log = new VehicleArticleOprLogModel { LogType = "VehicleArticle", IdentityId = $"{model.VehicleId}_{model.PaiLiang}_{model.Nian}", OperationType = "Delete", OldValue = JsonConvert.SerializeObject(oldValue), NewValue = null, Remarks = $"删除选车攻略:{ model.VehicleId }_{ model.PaiLiang }_{ model.Nian }的配置", Operator = _user }; logs.Add(log); } } if (delList.Any()) { dbScopeManagerConfiguration.CreateTransaction(conn => { foreach (var model in delList) { var delResult = DalVehicleArticle.DeleteVehicleArticle(conn, model.PKID); if (!delResult) { throw new Exception($"DeleteVehicleArticle失败," + $"待删除数据:{JsonConvert.SerializeObject(model)}"); } } result = true; }); } if (result && logs.Any()) { logs.ForEach(s => LoggerManager.InsertLog("VehicleArticleOprLog", s)); } } catch (Exception ex) { result = false; Logger.Error("MultDeleteVehicleArticle", ex); } return(result); }
/// <summary> /// 删除选车攻略配置 /// </summary> /// <param name="model"></param> /// <param name="user"></param> /// <returns></returns> public bool DeleteVehicleArticle(VehicleArticleModel model) { var result = false; try { var oldValue = dbScopeManagerConfigurationRead.Execute(conn => DalVehicleArticle.GetVehicleArticleByPkid(conn, model.PKID)); if (oldValue != null) { result = dbScopeManagerConfiguration.Execute(conn => DalVehicleArticle.DeleteVehicleArticle(conn, oldValue.PKID)); var log = new VehicleArticleOprLogModel { LogType = "VehicleArticle", IdentityId = $"{model.VehicleId}_{model.PaiLiang}_{model.Nian}", OperationType = "Delete", OldValue = JsonConvert.SerializeObject(oldValue), NewValue = null, Remarks = $"删除选车攻略:{ model.VehicleId }_{ model.PaiLiang }_{ model.Nian }的配置", Operator = _user }; LoggerManager.InsertLog("VehicleArticleOprLog", log); } else { result = true; } } catch (Exception ex) { result = false; Logger.Error("DeleteVehicleArticle", ex); } return(result); }
/// <summary> /// 批量添加或更新选车攻略配置 /// </summary> /// <param name="models"></param> /// <returns></returns> public bool MultUpsertVehicleArticle(List <VehicleArticleModel> models) { var result = false; try { var addList = new List <VehicleArticleModel>(); var updateList = new List <VehicleArticleModel>(); var logs = new List <VehicleArticleOprLogModel>(); foreach (var model in models) { var oldValue = dbScopeManagerConfigurationRead.Execute(conn => DalVehicleArticle.GetVehicleArticle(conn, model)); if (oldValue != null) { model.PKID = oldValue.PKID; model.CreateDateTime = oldValue.CreateDateTime; model.LastUpdateDateTime = DateTime.Now; updateList.Add(model); var log = new VehicleArticleOprLogModel { LogType = "VehicleArticle", IdentityId = $"{model.VehicleId}_{model.PaiLiang}_{model.Nian}", OperationType = "Update", OldValue = JsonConvert.SerializeObject(oldValue), NewValue = JsonConvert.SerializeObject(model), Remarks = $"更新选车攻略:{ model.VehicleId }_{ model.PaiLiang }_{ model.Nian }的配置", Operator = _user, }; logs.Add(log); } else { addList.Add(model); } } dbScopeManagerConfiguration.CreateTransaction(conn => { foreach (var model in addList) { var pkid = DalVehicleArticle.AddVehicleArticle(conn, model); if (pkid < 1) { throw new Exception($"AddVehicleArticle失败," + $"待添加数据:{JsonConvert.SerializeObject(model)}"); } model.PKID = pkid; model.CreateDateTime = DateTime.Now; model.LastUpdateDateTime = DateTime.Now; var log = new VehicleArticleOprLogModel { LogType = "VehicleArticle", IdentityId = $"{model.VehicleId}_{model.PaiLiang}_{model.Nian}", OperationType = "Add", OldValue = null, NewValue = JsonConvert.SerializeObject(model), Remarks = $"添加选车攻略:{model.VehicleId}_{model.PaiLiang}_{model.Nian}的配置", Operator = _user, }; logs.Add(log); } foreach (var model in updateList) { var updateResult = DalVehicleArticle.UpdateVehicleArticle(conn, model); if (!updateResult) { throw new Exception($"UpdateVehicleArticle失败," + $"待更新数据:{JsonConvert.SerializeObject(model)}"); } } result = true; }); if (result) { logs.ForEach(s => LoggerManager.InsertLog("VehicleArticleOprLog", s)); } } catch (Exception ex) { Logger.Error("MultUpsertVehicleArticle", ex); } return(result); }