public ActionResult Save(SE_MDBeautyCategoryProductConfigModel model) { bool result = false; if (model != null) { try { model.Brands = string.IsNullOrWhiteSpace(model.Brands) ? null : model.Brands; if (model.PId == 0) { var userName = HttpContext.User?.Identity?.Name; var data = SyncProdcutLibrary(model, userName); logger.Info(data); result = SE_MDBeautyCategoryProductConfigBLL.BatchInsertOrUpdateSyncProdcutLibrary(data, model); } else { result = SE_MDBeautyCategoryProductConfigBLL.Update(model); using (var client = new Tuhu.Service.Shop.CacheClient()) { client.UpdateBeautyProductDetailByPid(model.PId); } } } catch (Exception ex) { logger.Error(ex.Message, ex); } } return(RedirectToAction("Index", "SE_MDBeautyCategoryConfig")); }
/// <summary> /// 批量生成&批量修改产品 /// </summary> public static bool BatchInsertOrUpdate(SE_MDBeautyCategoryProductConfigModel model) { try { return SE_MDBeautyCategoryProductConfigDAL.BatchInsertOrUpdate(ProcessConnection.OpenTuhu_Groupon, model); } catch (Exception ex) { throw ex; } }
// // GET: /SE_MDBeautyCategoryProductConfig/Edit/5 public ActionResult Edit(int id = 0) { SE_MDBeautyCategoryProductConfigModel model = new SE_MDBeautyCategoryProductConfigModel(); model.RecommendCar = 4; //默认选项 if (id > 0) { model = SE_MDBeautyCategoryProductConfigBLL.Select(id); } ViewBag.ZTreeJsonForCategory = SE_MDBeautyCategoryConfigController.SE_MDBeautyCategoryTreeJson(model.CategoryIds, true); //ViewBag.ZTreeJsonForBrand = SE_MDBeautyBrandConfigController.SE_MDBeautyBrandTreeJson(model.Brands, true); ViewBag.ZTreeJsonForBrand = id > 0 ? SE_MDBeautyBrandTreeForCategoryIdJson(model.CategoryIds, model.Brands, true) : "[]"; return(View(model)); }
public ActionResult Save(SE_MDBeautyCategoryProductConfigModel model) { bool result = false; if (model != null) { try { var userName = HttpContext.User?.Identity?.Name; model.Brands = string.IsNullOrWhiteSpace(model.Brands) ? null : model.Brands; if (model.PId == 0) { var data = SyncProdcutLibrary(model, userName); logger.Info(data); result = SE_MDBeautyCategoryProductConfigBLL.BatchInsertOrUpdateSyncProdcutLibrary(data, model); } else { result = SE_MDBeautyCategoryProductConfigBLL.Update(model); model.ProdcutId = (SE_MDBeautyCategoryProductConfigBLL.Select(model.PId))?.ProdcutId; var propinfo = new Dictionary <string, object>() { ["Image_filename"] = model.Image_filename }; var updateResult = ProductService.UpdateProductByPropertyNames(model.ProdcutId, propinfo, userName); if (!updateResult) { logger.Error($"更新产品图片属性失败,product:{JsonConvert.SerializeObject(model)}"); } using (var client = new Tuhu.Service.Shop.CacheClient()) { client.UpdateBeautyProductDetailByPid(model.PId); } } } catch (Exception ex) { logger.Error(ex.Message, ex); } } return(RedirectToAction("Index", "SE_MDBeautyCategoryConfig")); }
public static bool Insert(SqlConnection connection, SE_MDBeautyCategoryProductConfigModel model) { using (IDbConnection conn = connection) { string sql = @" INSERT INTO [SE_MDBeautyCategoryProductConfig] ([ProdcutName] ,[CategoryIds] ,[Describe] ,[BeginPrice] ,[EndPrice] ,[BeginPromotionPrice] ,[EndPromotionPrice] ,[Commission] ,[EveryDayNum] ,[Brands] ,[RecommendCar] ,[AdaptiveCar] ,[IsDisable] ,[IsNotShow] ,[CreateTime]) VALUES (@ProdcutName ,@CategoryIds ,@DESCRIBE ,@BeginPrice ,@EndPrice ,@BeginPromotionPrice ,@EndPromotionPrice ,@Commission ,@EveryDayNum ,@Brands ,@RecommendCar ,@AdaptiveCar ,@IsDisable ,@IsNotShow ,@CreateTime)"; return(conn.Execute(sql, model) > 0); } }
// // GET: /SE_MDBeautyCategoryProductConfig/Edit/5 public ActionResult Edit(int id = 0) { SE_MDBeautyCategoryProductConfigModel model = new SE_MDBeautyCategoryProductConfigModel(); model.RecommendCar = 4; //默认选项 if (id > 0) { model = SE_MDBeautyCategoryProductConfigBLL.Select(id); if (!string.IsNullOrEmpty(model.ProdcutId)) { var imageUrl = (ProductService.GetProductBaseInfo(model.ProdcutId))?.Image; model.Image_filename = imageUrl; } } ViewBag.ZTreeJsonForCategory = SE_MDBeautyCategoryConfigController.SE_MDBeautyCategoryTreeJson(model.CategoryIds, true); //ViewBag.ZTreeJsonForBrand = SE_MDBeautyBrandConfigController.SE_MDBeautyBrandTreeJson(model.Brands, true); ViewBag.ZTreeJsonForBrand = id > 0 ? SE_MDBeautyBrandTreeForCategoryIdJson(model.CategoryIds, model.Brands, true) : "[]"; return(View(model)); }
public static bool Update(SqlConnection connection, SE_MDBeautyCategoryProductConfigModel model) { using (IDbConnection conn = connection) { string sql = @" UPDATE [SE_MDBeautyCategoryProductConfig] SET [ProdcutName] = @ProdcutName ,[CategoryIds] = @CategoryIds ,[Describe] = @Describe ,[Commission] = @Commission ,[BeginPrice] = @BeginPrice ,[EndPrice] = @EndPrice ,[BeginPromotionPrice] = @BeginPromotionPrice ,[EndPromotionPrice] = @EndPromotionPrice ,[EveryDayNum] = @EveryDayNum ,[Brands] = @Brands ,[RecommendCar] = @RecommendCar ,[AdaptiveCar] = @AdaptiveCar ,[IsDisable] = @IsDisable ,[IsNotShow]=@IsNotShow ,[CreateTime] = @CreateTime WHERE PId = @PId "; return(conn.Execute(sql, model) > 0); } }
/// <summary> /// 批量插入或修改产品,并同步产品库 /// </summary> public static bool BatchInsertOrUpdateSyncProdcutLibrary(Dictionary<string, string> dicSQL, SE_MDBeautyCategoryProductConfigModel model) { try { return SE_MDBeautyCategoryProductConfigDAL.BatchInsertOrUpdateSyncProdcutLibrary(ProcessConnection.OpenTuhu_Groupon, dicSQL, model); } catch (Exception ex) { throw ex; } }
/// <summary> /// 同步产品库 /// </summary> private Dictionary <string, string> SyncProdcutLibrary(SE_MDBeautyCategoryProductConfigModel model, string userName) { lock (SyncLock_Save) { CachingLogsHelp.CacheItemRemove(); List <string> SyncProdcutLibraryLog = new List <string>(); Dictionary <string, string> dicSQL = new Dictionary <string, string>(); List <BatchTreeModel> dataTreeItems = JsonConvert.DeserializeObject <List <BatchTreeModel> >(model?.Brands); if (dataTreeItems != null && dataTreeItems.Any()) { #region 检测产品 var _AdaptiveCarCheckBox = model.AdaptiveCarCheckBox?.Split(','); List <string> sqlWhere = new List <string>(); if (_AdaptiveCarCheckBox != null && _AdaptiveCarCheckBox.Any()) { if (dataTreeItems != null && dataTreeItems.Any()) { foreach (var a in dataTreeItems) { if (!string.IsNullOrWhiteSpace(a.CategorysName)) { if (a.Childs != null && a.Childs.Any()) { foreach (var b in a.Childs) { foreach (var c in _AdaptiveCarCheckBox?.ToList()) { sqlWhere.Add(string.Format("{0}|{1}|{2}", model.CategoryIds, a.ParentId + "," + b.Id, c)); } } } else { foreach (var c in _AdaptiveCarCheckBox?.ToList()) { sqlWhere.Add(string.Format("{0}|{1}|{2}", model.CategoryIds, a.ParentId, c)); } } } else { SyncProdcutLibraryLog.Add($"检测产品: {model.Brands} 数据异常,请打开重试!,操作时间:{DateTime.Now.ToString()}"); } } } } string checkSQL = @"SELECT * FROM ( SELECT ISNULL(CategoryIds,'') + '|' + ISNULL(Brands,'') + '|'+ ISNULL(CONVERT(nvarchar,AdaptiveCar),'') as 'TreeItems',* FROM SE_MDBeautyCategoryProductConfig WITH(NOLOCK) ) AS tab1 WHERE tab1.TreeItems IN(" + "'" + string.Join("','", sqlWhere) + "'" + ")"; IEnumerable <SE_MDBeautyCategoryProductConfigModel> dataList = SE_MDBeautyCategoryProductConfigBLL.CustomQuery <SE_MDBeautyCategoryProductConfigModel>(checkSQL); #endregion #region 公共变量 string sqlInsert = @" INSERT [SE_MDBeautyCategoryProductConfig] ( [ProdcutId], [ProdcutName], [CategoryIds], [Describe], [Commission], [BeginPrice], [EndPrice], [BeginPromotionPrice], [EndPromotionPrice], [EveryDayNum], [Brands], [RecommendCar], [AdaptiveCar], [IsDisable], [CreateTime], [IsNotShow]) VALUES "; string sqlUpdate = @" UPDATE [SE_MDBeautyCategoryProductConfig] SET [ProdcutName] = {1} ,[Describe] = {2} ,[Commission] = @Commission ,[BeginPrice] = @BeginPrice ,[EndPrice] = @EndPrice ,[BeginPromotionPrice] = @BeginPromotionPrice ,[EndPromotionPrice] = @EndPromotionPrice ,[EveryDayNum] = @EveryDayNum ,[IsDisable] = @IsDisable ,[CreateTime] = GETDATE() ,[IsNotShow]=@IsNotShow WHERE PId IN({0}) "; List <string> sqlInsertWhere = new List <string>(); List <SE_MDBeautyCategoryProductConfigModel> sqlUpdateWhere = new List <SE_MDBeautyCategoryProductConfigModel>(); #endregion #region 遍历品牌 foreach (var item in dataTreeItems) { if (!string.IsNullOrWhiteSpace(item.CategorysName)) { if (item.Childs != null && item.Childs.Any()) //判断是否遍历子系列 { #region 遍历系列 foreach (var itemChilds in item.Childs) { #region 遍历车型 using (IProductClient client = new ProductClient()) { foreach (var itemCar in _AdaptiveCarCheckBox?.ToList()) { Thread.Sleep(2000); //延时操作 string itemCarName = (itemCar == "1" ? "五座轿车" : itemCar == "2" ? "SUV/MPV" : itemCar == "3" ? "SUV" : itemCar == "4" ? "MPV" : ""); string _TreeItems = string.Format("{0}|{1}|{2}", model.CategoryIds, item.ParentId + "," + itemChilds.Id, itemCar); var _compareData = dataList?.Where(_ => _.TreeItems == _TreeItems)?.FirstOrDefault(); if (_compareData == null) { #region 步添加到产品库 Service.OperationResult <string> createResult = client.CreateProductV2( new WholeProductInfo { Name = item.Name + itemChilds.Name + itemCarName + item.CategorysName, DisplayName = item.Name + itemChilds.Name + itemCarName + item.CategorysName, Description = model.Describe?.Replace("$1", item.CategorysName)?.Replace("$2", itemChilds.Name), PrimaryParentCategory = model.PrimaryParentCategory, ProductID = model.ProdcutId, //Common.PinYinConverter.ConvertToFirstSpell(item.Name + itemChilds.Name + itemCarName + item.CategorysName), VariantID = null, Image_filename = model.Image_filename, CatalogName = "CarPAR", DefinitionName = model.DefinitionName, CreateDatetime = DateTime.Now }, userName, ChannelType.MenDian); if (createResult.Success && !string.IsNullOrWhiteSpace(createResult?.Result)) { sqlInsertWhere.Add(string.Format(" ( N'{14}',N'{0}',N'{1}',N'{2}',{3},{4},{5},{6},{7},{8},N'{9}',{10},{11},{12},N'{13}',{15}) \r\n", item.Name + itemChilds.Name + itemCarName + item.CategorysName, model.CategoryIds, model.Describe?.Replace("$1", item.CategorysName)?.Replace("$2", itemChilds.Name), model.Commission, model.BeginPrice, model.EndPrice, model.BeginPromotionPrice, model.EndPromotionPrice, model.EveryDayNum, item.ParentId + "," + itemChilds.Id, model.RecommendCar, itemCar, model.IsDisable.GetHashCode(), model.CreateTime, createResult.Result, //产品ID model.IsNotShow.GetHashCode() )); } SyncProdcutLibraryLog.Add($"子集:添加,操作人:{userName},ErrorMessage:{createResult.ErrorMessage},Exception:{createResult.Exception},ErrorCode:{createResult.ErrorCode},Result:{createResult.Result},Success:{createResult.Success},操作时间:{DateTime.Now.ToString()}"); #endregion } else { #region 步修改产品库 Service.OperationResult <bool> updateResult = client.UpdateProduct( new WholeProductInfo { Name = item.Name + itemChilds.Name + itemCarName + item.CategorysName, DisplayName = item.Name + itemChilds.Name + itemCarName + item.CategorysName, Description = model.Describe?.Replace("$1", item.CategorysName)?.Replace("$2", ""), PrimaryParentCategory = model.PrimaryParentCategory, ProductID = _compareData.ProdcutId.Split('|')[0], VariantID = _compareData.ProdcutId.Split('|')[1], Image_filename = model.Image_filename, CatalogName = "CarPAR", DefinitionName = model.DefinitionName }, userName, ChannelType.MenDian); if (updateResult.Success && updateResult.Result) { sqlUpdateWhere.Add(new SE_MDBeautyCategoryProductConfigModel() { ProdcutId = _compareData.ProdcutId, PId = _compareData.PId, ProdcutName = item.Name + itemChilds.Name + itemCarName + item.CategorysName, Describe = model.Describe?.Replace("$1", item.CategorysName)?.Replace("$2", itemChilds.Name), }); } SyncProdcutLibraryLog.Add($"子集:修改,操作人:{userName},ErrorMessage:{updateResult.ErrorMessage},Exception:{updateResult.Exception},ErrorCode:{updateResult.ErrorCode},ProdcutId:{_compareData.ProdcutId},Result:{updateResult.Result},Success:{updateResult.Success},操作时间:{DateTime.Now.ToString()}"); #endregion } } } #endregion } #endregion } else { #region 遍历车型 using (IProductClient client = new ProductClient()) { foreach (var itemCar in _AdaptiveCarCheckBox?.ToList()) { Thread.Sleep(2000); //延时操作 string itemCarName = (itemCar == "1" ? "五座轿车" : itemCar == "2" ? "SUV/MPV" : itemCar == "3" ? "SUV" : itemCar == "4" ? "MPV" : ""); string _TreeItems = string.Format("{0}|{1}|{2}", model.CategoryIds, item.ParentId, itemCar); var _compareData = dataList?.Where(_ => _.TreeItems == _TreeItems)?.FirstOrDefault(); if (_compareData == null) { #region 步添加到产品库 Service.OperationResult <string> createResult = client.CreateProductV2( new WholeProductInfo { Name = item.Name + itemCarName + item.CategorysName, DisplayName = item.Name + itemCarName + item.CategorysName, Description = model.Describe?.Replace("$1", item.CategorysName)?.Replace("$2", ""), PrimaryParentCategory = model.PrimaryParentCategory, ProductID = model.ProdcutId, //Common.PinYinConverter.ConvertToFirstSpell(item.Name + itemCarName + item.CategorysName), VariantID = null, Image_filename = model.Image_filename, CatalogName = "CarPAR", DefinitionName = model.DefinitionName }, userName, ChannelType.MenDian); if (createResult.Success && !string.IsNullOrWhiteSpace(createResult?.Result)) { sqlInsertWhere.Add(string.Format(" ( N'{14}',N'{0}',N'{1}',N'{2}',{3},{4},{5},{6},{7},{8},N'{9}',{10},{11},{12},N'{13}',{15}) \r\n", item.Name + itemCarName + item.CategorysName, model.CategoryIds, model.Describe?.Replace("$1", item.CategorysName)?.Replace("$2", ""), model.Commission, model.BeginPrice, model.EndPrice, model.BeginPromotionPrice, model.EndPromotionPrice, model.EveryDayNum, item.ParentId, model.RecommendCar, itemCar, model.IsDisable.GetHashCode(), model.CreateTime, createResult.Result, //产品ID model.IsNotShow.GetHashCode() )); } SyncProdcutLibraryLog.Add($"添加,操作人:{userName},ErrorMessage:{createResult.ErrorMessage},Exception:{createResult.Exception},ErrorCode:{createResult.ErrorCode},Result:{createResult.Result},Success:{createResult.Success},操作时间:{DateTime.Now.ToString()}"); #endregion } else { #region 步修改产品库 Service.OperationResult <bool> updateResult = client.UpdateProduct( new WholeProductInfo { Name = item.Name + itemCarName + item.CategorysName, DisplayName = item.Name + itemCarName + item.CategorysName, Description = model.Describe?.Replace("$1", item.CategorysName)?.Replace("$2", ""), PrimaryParentCategory = model.PrimaryParentCategory, ProductID = _compareData.ProdcutId.Split('|')[0], VariantID = _compareData.ProdcutId.Split('|')[1], Image_filename = model.Image_filename, CatalogName = "CarPAR", DefinitionName = model.DefinitionName }, userName, ChannelType.MenDian); if (updateResult.Success && updateResult.Result) { sqlUpdateWhere.Add(new SE_MDBeautyCategoryProductConfigModel() { ProdcutId = _compareData.ProdcutId, PId = _compareData.PId, ProdcutName = item.Name + itemCarName + item.CategorysName, Describe = model.Describe?.Replace("$1", item.CategorysName)?.Replace("$2", ""), }); } SyncProdcutLibraryLog.Add($"修改,操作人:{userName},ErrorMessage:{updateResult.ErrorMessage},Exception:{updateResult.Exception},ErrorCode:{updateResult.ErrorCode},ProdcutId:{_compareData.ProdcutId},Result:{updateResult.Result},Success:{updateResult.Success},操作时间:{DateTime.Now.ToString()}"); #endregion } } } #endregion } } else { SyncProdcutLibraryLog.Add($"遍历品牌: {model.Brands} 数据异常,请打开重试!,操作时间:{DateTime.Now.ToString()}"); } } #endregion #region 拼接条件 if (sqlInsertWhere != null && sqlInsertWhere.Any()) { dicSQL.Add("INSERT", sqlInsert + string.Join(",", sqlInsertWhere)); } if (sqlUpdateWhere != null && sqlUpdateWhere.Any()) { string _ProdcutName = " CASE PId ", _Describe = " CASE PId "; foreach (var item in sqlUpdateWhere) { _ProdcutName += string.Format("WHEN {0} THEN N'{1}'", item.PId, item.ProdcutName); _Describe += string.Format("WHEN {0} THEN N'{1}'", item.PId, item.Describe); } _ProdcutName += " END "; _Describe += " END "; dicSQL.Add("UPDATE", string.Format(sqlUpdate, string.Join(",", sqlUpdateWhere.Select(s => s.PId)), _ProdcutName, _Describe)); } #endregion } else { SyncProdcutLibraryLog.Add($"入口: dataTreeItems = null , Brands = {model.Brands} !,操作时间:{DateTime.Now.ToString()}"); } CachingLogsHelp.AddOrGetExisting(SyncProdcutLibraryLog); return(dicSQL); } }
/// <summary> /// 批量插入或修改产品,并同步产品库 /// </summary> public static bool BatchInsertOrUpdateSyncProdcutLibrary(SqlConnection connection, Dictionary <string, string> dicSQL, SE_MDBeautyCategoryProductConfigModel model) { if (dicSQL == null || !dicSQL.Any()) { return(false); } using (IDbConnection conn = connection) { IDbTransaction transaction = conn.BeginTransaction(); try { if (dicSQL.ContainsKey("INSERT")) { conn.Execute(dicSQL["INSERT"], null, transaction); } if (dicSQL.ContainsKey("UPDATE")) { conn.Execute(dicSQL["UPDATE"], new { @Commission = model.Commission, @BeginPrice = model.BeginPrice, @EndPrice = model.EndPrice, @BeginPromotionPrice = model.BeginPromotionPrice, @EndPromotionPrice = model.EndPromotionPrice, @EveryDayNum = model.EveryDayNum, @IsDisable = model.IsDisable, @IsNotShow = model.IsNotShow, }, transaction); } transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } } return(true); }
/// <summary> /// 批量生成&批量修改产品 /// </summary> public static bool BatchInsertOrUpdate(SqlConnection connection, SE_MDBeautyCategoryProductConfigModel model) { using (IDbConnection conn = connection) { List <BatchTreeModel> dataTreeItems = JsonConvert.DeserializeObject <List <BatchTreeModel> >(model?.Brands); #region 检测产品 var _AdaptiveCarCheckBox = model.AdaptiveCarCheckBox?.Split(','); List <string> sqlWhere = new List <string>(); if (_AdaptiveCarCheckBox != null && _AdaptiveCarCheckBox.Any()) { if (dataTreeItems != null && dataTreeItems.Any()) { foreach (var a in dataTreeItems) { if (a.Childs != null && a.Childs.Any()) { foreach (var b in a.Childs) { foreach (var c in _AdaptiveCarCheckBox?.ToList()) { sqlWhere.Add(string.Format("{0}|{1}|{2}", model.CategoryIds, a.ParentId + "," + b.Id, c)); } } } else { foreach (var c in _AdaptiveCarCheckBox?.ToList()) { sqlWhere.Add(string.Format("{0}|{1}|{2}", model.CategoryIds, a.ParentId, c)); } } } } } string sql = @"SELECT * FROM ( SELECT ISNULL(CategoryIds,'') + '|' + ISNULL(Brands,'') + '|'+ ISNULL(CONVERT(nvarchar,AdaptiveCar),'') as 'TreeItems',* FROM SE_MDBeautyCategoryProductConfig WITH(NOLOCK) ) AS tab1 WHERE tab1.TreeItems IN(" + "'" + string.Join("','", sqlWhere) + "'" + ")"; IEnumerable <SE_MDBeautyCategoryProductConfigModel> dataList = conn.Query <SE_MDBeautyCategoryProductConfigModel>(sql); #endregion #region 批量插入或更新 string sqlInsert = @" INSERT [SE_MDBeautyCategoryProductConfig] ([ProdcutName],[CategoryIds],[Describe],[Commission],[BeginPrice],[EndPrice],[BeginPromotionPrice],[EndPromotionPrice],[EveryDayNum],[Brands],[RecommendCar],[AdaptiveCar],[IsDisable],[CreateTime]) VALUES "; string sqlUpdate = @" UPDATE [SE_MDBeautyCategoryProductConfig] SET [ProdcutName] = {1} ,[Describe] = {2} ,[Commission] = @Commission ,[BeginPrice] = @BeginPrice ,[EndPrice] = @EndPrice ,[BeginPromotionPrice] = @BeginPromotionPrice ,[EndPromotionPrice] = @EndPromotionPrice ,[EveryDayNum] = @EveryDayNum ,[IsDisable] = @IsDisable WHERE PId IN({0}) "; List <string> sqlInsertWhere = new List <string>(); List <SE_MDBeautyCategoryProductConfigModel> sqlUpdateWhere = new List <SE_MDBeautyCategoryProductConfigModel>(); IDbTransaction transaction = conn.BeginTransaction(); try { #region 遍历品牌 foreach (var item in dataTreeItems) { if (item.Childs != null && item.Childs.Any()) //判断是否遍历子系列 { #region 遍历系列 foreach (var itemChilds in item.Childs) { #region 遍历车型 foreach (var itemCar in _AdaptiveCarCheckBox?.ToList()) { string itemCarName = (itemCar == "1" ? "五座轿车" : itemCar == "2" ? "SUV/MPV" : itemCar == "3" ? "SUV" : "MPV"); string _TreeItems = string.Format("{0}|{1}|{2}", model.CategoryIds, item.ParentId + "," + itemChilds.Id, itemCar); var _compareData = dataList?.Where(_ => _.TreeItems == _TreeItems)?.FirstOrDefault(); if (_compareData == null) { sqlInsertWhere.Add(string.Format(" ( N'{0}',N'{1}',N'{2}',{3},{4},{5},{6},{7},{8},N'{9}',{10},{11},{12},N'{13}') \r\n", item.Name + itemChilds.Name + itemCarName + item.CategorysName, model.CategoryIds, model.Describe?.Replace("$1", item.CategorysName).Replace("$2", itemChilds.Name), model.Commission, model.BeginPrice, model.EndPrice, model.BeginPromotionPrice, model.EndPromotionPrice, model.EveryDayNum, item.ParentId + "," + itemChilds.Id, model.RecommendCar, itemCar, model.IsDisable.GetHashCode(), model.IsNotShow.GetHashCode(), model.CreateTime)); } else { sqlUpdateWhere.Add(new SE_MDBeautyCategoryProductConfigModel() { PId = _compareData.PId, ProdcutName = item.Name + itemCarName + item.CategorysName, Describe = model.Describe?.Replace("$1", item.CategorysName).Replace("$2", itemChilds.Name), }); } } #endregion } #endregion } else { #region 遍历车型 foreach (var itemCar in _AdaptiveCarCheckBox?.ToList()) { string itemCarName = (itemCar == "1" ? "五座轿车" : itemCar == "2" ? "SUV/MPV" : itemCar == "3" ? "SUV" : "MPV"); string _TreeItems = string.Format("{0}|{1}|{2}", model.CategoryIds, item.ParentId, itemCar); var _compareData = dataList?.Where(_ => _.TreeItems == _TreeItems)?.FirstOrDefault(); if (_compareData == null) { sqlInsertWhere.Add(string.Format(" ( N'{0}',N'{1}',N'{2}',{3},{4},{5},{6},{7},{8},N'{9}',{10},{11},{12},N'{13}') \r\n", item.Name + itemCarName + item.CategorysName, model.CategoryIds, model.Describe?.Replace("$1", item.CategorysName).Replace("$2", ""), model.Commission, model.BeginPrice, model.EndPrice, model.BeginPromotionPrice, model.EndPromotionPrice, model.EveryDayNum, item.ParentId, model.RecommendCar, itemCar, model.IsDisable.GetHashCode(), model.IsNotShow.GetHashCode(), model.CreateTime)); } else { sqlUpdateWhere.Add(new SE_MDBeautyCategoryProductConfigModel() { PId = _compareData.PId, ProdcutName = item.Name + itemCarName + item.CategorysName, Describe = model.Describe?.Replace("$1", item.CategorysName).Replace("$2", ""), }); } } #endregion } } #endregion #region 组装SQL if (sqlInsertWhere != null && sqlInsertWhere.Any()) { conn.Execute(sqlInsert + string.Join(",", sqlInsertWhere), null, transaction); } if (sqlUpdateWhere != null && sqlUpdateWhere.Any()) { string _ProdcutName = " CASE PId ", _Describe = " CASE PId "; foreach (var item in sqlUpdateWhere) { _ProdcutName += string.Format("WHEN {0} THEN N'{1}'", item.PId, item.ProdcutName); _Describe += string.Format("WHEN {0} THEN N'{1}'", item.PId, item.Describe); } _ProdcutName += " END "; _Describe += " END "; conn.Execute(string.Format(sqlUpdate, string.Join(",", sqlUpdateWhere.Select(s => s.PId)), _ProdcutName, _Describe), new { @Commission = model.Commission, @BeginPrice = model.BeginPrice, @EndPrice = model.EndPrice, @BeginPromotionPrice = model.BeginPromotionPrice, @EndPromotionPrice = model.EndPromotionPrice, @EveryDayNum = model.EveryDayNum, @IsDisable = model.IsDisable, @IsNotShow = model.IsNotShow, }, transaction); } #endregion transaction.Commit(); } catch (Exception) { transaction.Rollback(); return(false); } #endregion } return(true); }