diff --git a/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsAttribute/GoodsBomAttributeDto.cs b/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsAttribute/GoodsBomAttributeDto.cs index dac6ab2..065e653 100644 --- a/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsAttribute/GoodsBomAttributeDto.cs +++ b/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsAttribute/GoodsBomAttributeDto.cs @@ -9,6 +9,8 @@ namespace BPA.SAAS.Manage.Application.DataBase.Dtos.GoodsAttribute public class GoodsBomAttributeDto { public string GoodsId { get; set; } + public List BomId { get; set; } + public string Type { get; set; } public string BomName { get; set; } public string BomType { get; set; } public string[] BomtypeList { get; set; } diff --git a/BPA.SAAS.Manage.Application/DataBase/Services/GoodsService.cs b/BPA.SAAS.Manage.Application/DataBase/Services/GoodsService.cs index c65d20d..2dd9342 100644 --- a/BPA.SAAS.Manage.Application/DataBase/Services/GoodsService.cs +++ b/BPA.SAAS.Manage.Application/DataBase/Services/GoodsService.cs @@ -297,55 +297,84 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services _db.Ado.BeginTran(); try { - var sortMax = _db.Queryable().Max(x => x.Sort); - BPA_Bom newbPA_BOM = new BPA_Bom + if(dto.Type== "add") { - Name = dto.BomName, - Code = GetNumber2(), - IsMain = dto.BomType == "1" ? true : false, - Sort = sortMax + 1, - Id = Guid.NewGuid().ToString(), - CreateAt = DateTime.Now, - Status = CommonStatus.ENABLE, - }; - //添加配方 - var res = _db.Insertable(newbPA_BOM).CallEntityMethod(m => m.Create()).ExecuteCommand(); - //添加配方分类 - var list = dto.BomtypeList.Select(item => new BPA_BomTypeInfo() { BomId = newbPA_BOM.Id, BomTypeId = item }).ToList(); - _db.Insertable(list).CallEntityMethod(m => m.Create()).ExecuteCommand(); - - BPA_GoodsBom bom = new BPA_GoodsBom(); - bom.Goods_Id = dto.GoodsId; - bom.BomId = newbPA_BOM.Id; - bom.Status = CommonStatus.ENABLE; - //添加商品配方关系 - _db.Insertable(bom).CallEntityMethod(m => m.Create()).ExecuteCommand(); - List BOMEntryList = new(); - if (dto.Mate.Count > 0) + var sortMax = _db.Queryable().Max(x => x.Sort); + BPA_Bom newbPA_BOM = new BPA_Bom + { + Name = dto.BomName, + Code = GetNumber2(), + IsMain = dto.BomType == "1" ? true : false, + Sort = sortMax + 1, + Id = Guid.NewGuid().ToString(), + CreateAt = DateTime.Now, + Status = CommonStatus.ENABLE, + }; + //添加配方 + var res = _db.Insertable(newbPA_BOM).CallEntityMethod(m => m.Create()).ExecuteCommand(); + //添加配方分类 + var list = dto.BomtypeList.Select(item => new BPA_BomTypeInfo() { BomId = newbPA_BOM.Id, BomTypeId = item }).ToList(); + _db.Insertable(list).CallEntityMethod(m => m.Create()).ExecuteCommand(); + + BPA_GoodsBom bom = new BPA_GoodsBom(); + bom.Goods_Id = dto.GoodsId; + bom.BomId = newbPA_BOM.Id; + bom.Status = CommonStatus.ENABLE; + //添加商品配方关系 + _db.Insertable(bom).CallEntityMethod(m => m.Create()).ExecuteCommand(); + List BOMEntryList = new(); + if (dto.Mate.Count > 0) + { + for (int i = 0; i < dto.Mate.Count; i++) + { + BPA_BomEntry newbPA_BOMEnty = new BPA_BomEntry + { + BatchingId = dto.Mate[i].batchingId, + //BatchingKey = dto.Mate[i].AutoKey, + BomQty = dto.Mate[i].dosage, + BomId = newbPA_BOM.Id, + Status = CommonStatus.ENABLE, + IsReplace = false, + }; + BOMEntryList.Add(newbPA_BOMEnty); + } + } + //添加配方物料关系 + _db.Insertable(BOMEntryList).CallEntityMethod(m => m.Create()).ExecuteCommand(); + BPA_BomAttributeValueRe bPA_BomAttributeValueRe = new(); + bPA_BomAttributeValueRe.Id = Guid.NewGuid().ToString(); + bPA_BomAttributeValueRe.GoodsId = dto.GoodsId; + bPA_BomAttributeValueRe.BoomId = newbPA_BOM.Id; + bPA_BomAttributeValueRe.GoodsAttributeValueId = string.Join(",", dto.Shuxing); + //添加商品配方属性关系 + _db.Insertable(bPA_BomAttributeValueRe).ExecuteCommand(); + } + else { - for (int i = 0; i < dto.Mate.Count; i++) + if (dto.BomId.Count > 0) { - BPA_BomEntry newbPA_BOMEnty = new BPA_BomEntry + List bomlist = new(); + List bPA_BomAttributeValueRelist = new(); + for (int i = 0; i < dto.BomId.Count; i++) { - BatchingId = dto.Mate[i].batchingId, - //BatchingKey = dto.Mate[i].AutoKey, - BomQty = dto.Mate[i].dosage, - BomId = newbPA_BOM.Id, - Status = CommonStatus.ENABLE, - IsReplace = false, - }; - BOMEntryList.Add(newbPA_BOMEnty); + BPA_GoodsBom bom = new BPA_GoodsBom(); + bom.Goods_Id = dto.GoodsId; + bom.BomId = dto.BomId[i]; + bom.Status = CommonStatus.ENABLE; + bomlist.Add(bom); + BPA_BomAttributeValueRe bPA_BomAttributeValueRe = new(); + bPA_BomAttributeValueRe.Id = Guid.NewGuid().ToString(); + bPA_BomAttributeValueRe.GoodsId = dto.GoodsId; + bPA_BomAttributeValueRe.BoomId = dto.BomId[i]; + bPA_BomAttributeValueRe.GoodsAttributeValueId = string.Join(",", dto.Shuxing); + bPA_BomAttributeValueRelist.Add(bPA_BomAttributeValueRe); + } + //添加商品配方关系 + _db.Insertable(bomlist).CallEntityMethod(m => m.Create()).ExecuteCommand(); + //添加商品配方属性关系 + _db.Insertable(bPA_BomAttributeValueRelist).ExecuteCommand(); } } - //添加配方物料关系 - _db.Insertable(BOMEntryList).CallEntityMethod(m => m.Create()).ExecuteCommand(); - BPA_BomAttributeValueRe bPA_BomAttributeValueRe = new(); - bPA_BomAttributeValueRe.Id = Guid.NewGuid().ToString(); - bPA_BomAttributeValueRe.GoodsId = dto.GoodsId; - bPA_BomAttributeValueRe.BoomId = newbPA_BOM.Id; - bPA_BomAttributeValueRe.GoodsAttributeValueId = string.Join(",", dto.Shuxing); - //添加商品配方属性关系 - _db.Insertable(bPA_BomAttributeValueRe).ExecuteCommand(); _db.Ado.CommitTran(); return true; }