From 1cd82bee7e949f3ace56b0bda1b55a7eeb5bb46f Mon Sep 17 00:00:00 2001 From: gwbvipvip Date: Tue, 16 Jul 2024 10:26:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=86=E7=B1=BB=E6=9B=B4?= =?UTF-8?q?=E6=96=B0Bug=E4=BF=AE=E5=A4=8D20240716?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataBase/Services/GoodsTypeService.cs | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/BPA.SAAS.Manage.Application/DataBase/Services/GoodsTypeService.cs b/BPA.SAAS.Manage.Application/DataBase/Services/GoodsTypeService.cs index a89237a..a5f8b04 100644 --- a/BPA.SAAS.Manage.Application/DataBase/Services/GoodsTypeService.cs +++ b/BPA.SAAS.Manage.Application/DataBase/Services/GoodsTypeService.cs @@ -93,10 +93,10 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services { try { + _db.Ado.BeginTran(); var res = 0; if (string.IsNullOrWhiteSpace(dto.Id)) { - _db.Ado.BeginTran(); var old = await _db.Queryable().FirstAsync(t => t.Name == dto.Name); if (old != null) throw Oops.Oh($"已存在{dto.Name},添加失败!"); @@ -146,17 +146,23 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services try { var res = 0; - _db.Ado.BeginTran(); - var oldAttributeList = _db.Queryable().Where(it => it.GoodsTypeId == typeEntity.Id).ToList(); - if (oldAttributeList.Count > 0) + var attributeList = await _db.Queryable().Where(it => it.GoodsTypeId == typeEntity.Id).ToListAsync(); + var attributeValueList = await _db.Queryable().ToListAsync(); + var actionList = await _db.Queryable().Select(t => t.GoodsAttributeId).Distinct().ToListAsync(); + if (attributeList.Count > 0) { - foreach (var oldAttribute in oldAttributeList) + foreach (var oldAttribute in attributeList) { - var oldValueList = _db.Queryable().Where(it => it.GoodsAttributeId == oldAttribute.Id).ToList(); + var oldValueList = attributeValueList.Where(it => it.GoodsAttributeId == oldAttribute.Id).ToList(); + foreach (var _ in oldValueList.SelectMany(oldValue => actionList.Where(action => action.Contains(oldValue.Id)).Select(action => new { }).Select(_ => new { }))) + { + throw Oops.Oh("该商品分类属性已存在工艺,请删除对应工艺才能修改!"); + } + if (oldValueList.Count > 0) res += await _db.Deleteable(oldValueList).ExecuteCommandAsync(); } - res += await _db.Deleteable(oldAttributeList).ExecuteCommandAsync(); + res += await _db.Deleteable(attributeList).ExecuteCommandAsync(); } if (AttributeList != null) { @@ -183,16 +189,15 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services valueList.Add(value); } } - res += await _db.Insertable(valueList).CallEntityMethod(m => m.Create()).ExecuteCommandAsync(); + if(valueList.Count > 0) + res += await _db.Insertable(valueList).CallEntityMethod(m => m.Create()).ExecuteCommandAsync(); } } - _db.Ado.CommitTran(); return res; } - catch (Exception) + catch (Exception e) { - _db.Ado.RollbackTran(); - throw Oops.Oh("添加失败!"); + throw Oops.Oh(e.Message); } } ///