/// <summary> /// 批量操作 /// </summary> /// <param name="models"></param> /// <returns></returns> public JsonResult SaveCityAgingBulk(List <CityAgingModel> models) { var result = new MJsonResult() { Status = true }; try { if (models == null) { result.Status = false; result.Msg = "数据不能为空!"; return(Json(result)); } var returnValue = 0; var operatorsUserName = ThreadIdentity.Operator.Name; //批量查询修改前的历史数据 var tableDatas = CityAgingManage.SelectCityAgingInfoByIds(models.Select(t => t.PKid).ToList()); foreach (CityAgingModel model in models) { if (model.PKid == -1) //还没有修改过时效性 { returnValue = CityAgingManage.CreateSelectCityAging(model.CityId, model.CityName, model.IsShow, model.Title, model.Content, operatorsUserName); } else { model.UpdateUser = operatorsUserName; returnValue = CityAgingManage.UpdateSelectCityAging(model.PKid, model.IsShow, model.Title, model.Content, operatorsUserName); } var beforvalue = new CityAgingModel(); if (tableDatas != null && tableDatas.Any()) { beforvalue = tableDatas.Where(t => t.PKid == model.PKid).FirstOrDefault(); } else { beforvalue = null; } if (returnValue > 0) { SaveLog(beforvalue, model); } } } catch (Exception e) { result.Status = false; result.Msg = "异常:" + e.Message; } return(Json(result)); }
/// <summary> /// 记录日志查询 /// </summary> /// <param name="beforvalue"></param> /// <param name="newvalue"></param> private void SaveLog(CityAgingModel beforvalue, CityAgingModel newvalue) { var model = new CityAgingModel() { CityId = newvalue.CityId, CityName = newvalue.CityName, CreateUser = newvalue.CreateUser, UpdateUser = newvalue.UpdateUser }; if (newvalue.PKid != -1) { model.PKid = newvalue.PKid; } if (newvalue.IsShow != -1) { model.IsShow = newvalue.IsShow; } if (newvalue.Title != "-1") { model.Title = newvalue.Title; } if (newvalue.Content != "-1") { model.Content = newvalue.Content; } var oprLog = new FlashSaleProductOprLog { OperateUser = ThreadIdentity.Operator.Name, CreateDateTime = DateTime.Now, BeforeValue = JsonConvert.SerializeObject(beforvalue), AfterValue = JsonConvert.SerializeObject(model), LogType = "CityAging", LogId = $"0|{newvalue.CityId}", Operation = "修改城市时效开关" }; var result = Tuhu.Provisioning.Business.Logger.LoggerManager.InsertLog("CityAgingOprLog", oprLog); }
/// <summary> /// 保存时效信息 /// </summary> /// <returns></returns> public JsonResult SaveCityAging(CityAgingModel model) { var result = new MJsonResult() { Status = true }; try { var returnValue = 0; if (model == null) { result.Status = false; result.Msg = "model 不能为空!"; return(Json(result)); } var operatorsUserName = ThreadIdentity.Operator.Name; var beforvalue = new CityAgingModel(); if (model.PKid != -1) { var tableData = CityAgingManage.SelectCityAgingInfoByIds(new List <int>() { model.PKid }); if (tableData != null && tableData.Any()) { beforvalue = tableData.FirstOrDefault(); } else { beforvalue = null; } } else { beforvalue = null; } if (model.PKid == -1) { returnValue = CityAgingManage.CreateSelectCityAging(model.CityId, model.CityName, model.IsShow, model.Title, model.Content, operatorsUserName); } else { model.UpdateUser = operatorsUserName; returnValue = CityAgingManage.UpdateSelectCityAging(model.PKid, model.IsShow, model.Title, model.Content, operatorsUserName); } if (returnValue > 0) { SaveLog(beforvalue, model); result.Status = true; result.Msg = "保存成功!"; } else { result.Status = false; result.Msg = "保存失败!"; } } catch (Exception e) { result.Status = false; result.Msg = "异常:" + e.Message; } return(Json(result)); }