Browse Source

opt:修改属性值设置后工艺配置值出现问题

ingredientmanage
zhaoy 5 months ago
parent
commit
9b9ab4b511
1 changed files with 74 additions and 27 deletions
  1. +74
    -27
      BPA.SAAS.Manage.Application/DataBase/Services/GoodsAttributeService.cs

+ 74
- 27
BPA.SAAS.Manage.Application/DataBase/Services/GoodsAttributeService.cs View File

@@ -4,7 +4,7 @@ using BPA.SAAS.Manage.Comm.Const;
using BPA.SAAS.Manage.Core.DataBase; using BPA.SAAS.Manage.Core.DataBase;
using BPA.SAAS.Manage.Application.DataBase.Dtos.GoodsAttribute; using BPA.SAAS.Manage.Application.DataBase.Dtos.GoodsAttribute;
using StackExchange.Profiling.Internal; using StackExchange.Profiling.Internal;
using BPA.SAAS.Manage.Comm.Enum;


namespace BPA.Franchisee.Application.FranchiseeCenter.GoodsServices namespace BPA.Franchisee.Application.FranchiseeCenter.GoodsServices
{ {
@@ -84,6 +84,7 @@ namespace BPA.Franchisee.Application.FranchiseeCenter.GoodsServices
{ {
try try
{ {
var res = 0;
if (!string.IsNullOrWhiteSpace(dto.Id)) if (!string.IsNullOrWhiteSpace(dto.Id))
{ {
_db.Ado.BeginTran(); _db.Ado.BeginTran();
@@ -96,19 +97,55 @@ namespace BPA.Franchisee.Application.FranchiseeCenter.GoodsServices
resEntity.GoodsTypeId = dto.GoodsTypeId; resEntity.GoodsTypeId = dto.GoodsTypeId;
resEntity.Sort = dto.Sort; resEntity.Sort = dto.Sort;
await _db.Updateable(resEntity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); await _db.Updateable(resEntity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
//查询是否有数据
var dellist = _db.Queryable<BPA_GoodsAttributeValue>().Where(it => it.GoodsAttributeId == dto.Id).ToList(); var dellist = _db.Queryable<BPA_GoodsAttributeValue>().Where(it => it.GoodsAttributeId == dto.Id).ToList();
await _db.Deleteable(dellist).ExecuteCommandAsync(); ;
List<BPA_GoodsAttributeValue> list = new();
for (int i = 0; i < dto.GoodsAttributeValueList.Count; i++)
if (dellist?.Count == 0)
{ {
BPA_GoodsAttributeValue GoodsAttributeValue = new();
GoodsAttributeValue.AttributeValue = dto.GoodsAttributeValueList[i].AttributeValue;
GoodsAttributeValue.GoodsAttributeId = dto.Id;
GoodsAttributeValue.Sort= dto.GoodsAttributeValueList[i].Sort;
list.Add(GoodsAttributeValue);
List<BPA_GoodsAttributeValue> list = new();
for (int i = 0; i < dto.GoodsAttributeValueList.Count; i++)
{
BPA_GoodsAttributeValue GoodsAttributeValue = new();
GoodsAttributeValue.AttributeValue = dto.GoodsAttributeValueList[i].AttributeValue;
GoodsAttributeValue.GoodsAttributeId = dto.Id;
GoodsAttributeValue.Sort = dto.GoodsAttributeValueList[i].Sort;
list.Add(GoodsAttributeValue);
}
res = await _db.Insertable(list).CallEntityMethod(m => m.Create()).ExecuteCommandAsync();
}
else
{
//对比 1若存在则更新 ;2不存在则新增
//新增的
List<BPA_GoodsAttributeValue> newlist = new();
//修改的
List<BPA_GoodsAttributeValue> updatelist = new();
//循环增加的数据
foreach (var item in dto.GoodsAttributeValueList)
{
var updateselect = dellist.FirstOrDefault(x => x.Id == item.Id);
if (updateselect.AttributeValue!=item.AttributeValue|| updateselect.Sort!=item.Sort)
{
//更新
BPA_GoodsAttributeValue GoodsAttributeValue = new();
GoodsAttributeValue.Id = item.Id;
GoodsAttributeValue.AttributeValue =item.AttributeValue;
GoodsAttributeValue.GoodsAttributeId = dto.Id;
GoodsAttributeValue.Sort = item.Sort;
res = await _db.Updateable(GoodsAttributeValue).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
}
//查询id是否存在
if (string.IsNullOrWhiteSpace(item.GoodsAttributeId))
{
//新增
BPA_GoodsAttributeValue GoodsAttributeValue = new();
GoodsAttributeValue.AttributeValue = item.AttributeValue;
GoodsAttributeValue.GoodsAttributeId = dto.Id;
GoodsAttributeValue.Sort = item.Sort;
newlist.Add(GoodsAttributeValue);
res = await _db.Insertable(newlist).CallEntityMethod(m => m.Create()).ExecuteCommandAsync();
}
}
} }
var res = await _db.Insertable(list).CallEntityMethod(m => m.Create()).ExecuteCommandAsync();
_db.Ado.CommitTran(); _db.Ado.CommitTran();
return res > 0; return res > 0;
} }
@@ -123,23 +160,26 @@ namespace BPA.Franchisee.Application.FranchiseeCenter.GoodsServices
}; };
var GoodsAttribute = await _db.Insertable(newGoodsAttribute).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync(); var GoodsAttribute = await _db.Insertable(newGoodsAttribute).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync();
List<BPA_GoodsAttributeValue> list = new(); List<BPA_GoodsAttributeValue> list = new();
for (int i = 0; i < dto.GoodsAttributeValueList.Count; i++)
if (dto.GoodsAttributeValueList!=null)
{ {
BPA_GoodsAttributeValue GoodsAttributeValue = new();
GoodsAttributeValue.AttributeValue = dto.GoodsAttributeValueList[i].AttributeValue;
GoodsAttributeValue.GoodsAttributeId = GoodsAttribute.Id;
GoodsAttributeValue.Sort = dto.GoodsAttributeValueList[i].Sort;
list.Add(GoodsAttributeValue);
for (int i = 0; i < dto.GoodsAttributeValueList.Count; i++)
{
BPA_GoodsAttributeValue GoodsAttributeValue = new();
GoodsAttributeValue.AttributeValue = dto.GoodsAttributeValueList[i].AttributeValue;
GoodsAttributeValue.GoodsAttributeId = GoodsAttribute.Id;
GoodsAttributeValue.Sort = dto.GoodsAttributeValueList[i].Sort;
list.Add(GoodsAttributeValue);
}
} }
var res = await _db.Insertable(list).CallEntityMethod(m => m.Create()).ExecuteCommandAsync();
res = await _db.Insertable(list).CallEntityMethod(m => m.Create()).ExecuteCommandAsync();
_db.Ado.CommitTran(); _db.Ado.CommitTran();
return res > 0; return res > 0;
} }
} }
catch (Exception)
catch (Exception )
{ {
_db.Ado.RollbackTran(); _db.Ado.RollbackTran();
throw Oops.Oh("添加失败");
throw Oops.Oh("添加失败");
} }


@@ -152,8 +192,8 @@ namespace BPA.Franchisee.Application.FranchiseeCenter.GoodsServices
public async Task<bool> DeleteGoodsAttribute(string[] Ids) public async Task<bool> DeleteGoodsAttribute(string[] Ids)
{ {
// 查询数据库中是否存在未删除的商品 // 查询数据库中是否存在未删除的商品
var resEntitites = _db.Queryable<BPA_GoodsAttribute>().In(Ids).ToList();
var res =await _db.Deleteable(resEntitites).ExecuteCommandAsync();
var resEntitites = _db.Queryable<BPA_GoodsAttribute>().In(Ids).ToList();
var res =await _db.Deleteable(resEntitites).ExecuteCommandAsync();
if (res > 0) if (res > 0)
{ {
var resEntititesattr = _db.Queryable<BPA_GoodsAttributeValue>().In("GoodsAttributeId", Ids).ToList(); var resEntititesattr = _db.Queryable<BPA_GoodsAttributeValue>().In("GoodsAttributeId", Ids).ToList();
@@ -235,18 +275,25 @@ namespace BPA.Franchisee.Application.FranchiseeCenter.GoodsServices
/// <returns></returns> /// <returns></returns>
public async Task<bool> DeleteGoodsAttributeValue(string id) public async Task<bool> DeleteGoodsAttributeValue(string id)
{ {
// 查询数据库中是否存在未删除的商品

// 查询数据库中是否存在未删除的商品
var res = 0;
var resEntitites = _db.Queryable<BPA_GoodsAttributeValue>().In(id).ToList(); var resEntitites = _db.Queryable<BPA_GoodsAttributeValue>().In(id).ToList();
var res =await _db.Deleteable(resEntitites).ExecuteCommandAsync();
//查询三级是否使用
var resCountion= _db.Queryable<BPA_GoodsTechnologyAction>().Where(x=> x.GoodsAttributeId.Contains(id)).ToList();
if (resCountion?.Count()==0)
{
var res = await _db.Deleteable(resEntitites).ExecuteCommandAsync();
if (res > 0) if (res > 0)
{ {


//1.查询上架商品 //1.查询上架商品
//2.删除上架商品 //2.删除上架商品
} }
return res > 0;
}
return res > 0;

} }
/// <summary> /// <summary>
/// 根据商品id查询商品属性 /// 根据商品id查询商品属性


Loading…
Cancel
Save