Browse Source

商品分类更新Bug修复20240716

ingredientmanage
gwbvipvip 5 months ago
parent
commit
1cd82bee7e
1 changed files with 17 additions and 12 deletions
  1. +17
    -12
      BPA.SAAS.Manage.Application/DataBase/Services/GoodsTypeService.cs

+ 17
- 12
BPA.SAAS.Manage.Application/DataBase/Services/GoodsTypeService.cs View File

@@ -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<BPA_GoodsType>().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<BPA_GoodsAttribute>().Where(it => it.GoodsTypeId == typeEntity.Id).ToList();
if (oldAttributeList.Count > 0)
var attributeList = await _db.Queryable<BPA_GoodsAttribute>().Where(it => it.GoodsTypeId == typeEntity.Id).ToListAsync();
var attributeValueList = await _db.Queryable<BPA_GoodsAttributeValue>().ToListAsync();
var actionList = await _db.Queryable<BPA_GoodsTechnologyAction>().Select(t => t.GoodsAttributeId).Distinct().ToListAsync();
if (attributeList.Count > 0)
{
foreach (var oldAttribute in oldAttributeList)
foreach (var oldAttribute in attributeList)
{
var oldValueList = _db.Queryable<BPA_GoodsAttributeValue>().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);
}
}
/// <summary>


Loading…
Cancel
Save