From 38189c9613a24b7ddabd76fd1decd1d01dd931b5 Mon Sep 17 00:00:00 2001 From: gwbvipvip Date: Mon, 19 Feb 2024 10:07:03 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataBase/BomServices.cs | 13 ++++++++++++ .../DataBase/Dtos/Bom/BomDto.cs | 14 +++++++++++++ .../DataBase/Interface/IBomService.cs | 8 +++++++ .../DataBase/Services/BomService.cs | 21 +++++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 BPA.SAAS.Manage.Application/DataBase/Dtos/Bom/BomDto.cs diff --git a/BPA.SAAS.Manage.Application/DataBase/BomServices.cs b/BPA.SAAS.Manage.Application/DataBase/BomServices.cs index 8b27fff..859eb22 100644 --- a/BPA.SAAS.Manage.Application/DataBase/BomServices.cs +++ b/BPA.SAAS.Manage.Application/DataBase/BomServices.cs @@ -1,5 +1,6 @@ using BPA.SAAS.Manage.Application.DataBase.Dtos.Bom; using BPA.SAAS.Manage.Application.DataBase.Interface; +using BPA.SAAS.Manage.Core.Base; using System; using System.Collections.Generic; using System.Linq; @@ -25,6 +26,7 @@ namespace BPA.SAAS.Manage.Application.DataBase { return await _bomService.GetBomList(); } + /// /// 根据配方id查询配方信息 /// @@ -94,5 +96,16 @@ namespace BPA.SAAS.Manage.Application.DataBase { return await _bomService.GetBomTypeList(); } + + /// + ///获取 配方列表 + /// + /// + /// + [HttpPost("/api/bom/BomPage")] + public async Task BomPage(BomPageInputDto inputDto) + { + return await _bomService.BomPage(inputDto); + } } } diff --git a/BPA.SAAS.Manage.Application/DataBase/Dtos/Bom/BomDto.cs b/BPA.SAAS.Manage.Application/DataBase/Dtos/Bom/BomDto.cs new file mode 100644 index 0000000..16ffc17 --- /dev/null +++ b/BPA.SAAS.Manage.Application/DataBase/Dtos/Bom/BomDto.cs @@ -0,0 +1,14 @@ +using BPA.SAAS.Manage.Core.Base; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.DataBase.Dtos.Bom +{ + public class BomPageInputDto: PageInputBase + { + + } +} diff --git a/BPA.SAAS.Manage.Application/DataBase/Interface/IBomService.cs b/BPA.SAAS.Manage.Application/DataBase/Interface/IBomService.cs index faf895b..77d10db 100644 --- a/BPA.SAAS.Manage.Application/DataBase/Interface/IBomService.cs +++ b/BPA.SAAS.Manage.Application/DataBase/Interface/IBomService.cs @@ -1,4 +1,5 @@ using BPA.SAAS.Manage.Application.DataBase.Dtos.Bom; +using BPA.SAAS.Manage.Core.Base; using System; using System.Collections.Generic; using System.Linq; @@ -54,5 +55,12 @@ namespace BPA.SAAS.Manage.Application.DataBase.Interface /// /// Task> GetBomTypeList(); + + /// + ///获取 配方列表 + /// + /// + /// + Task BomPage(BomPageInputDto inputDto); } } diff --git a/BPA.SAAS.Manage.Application/DataBase/Services/BomService.cs b/BPA.SAAS.Manage.Application/DataBase/Services/BomService.cs index b6efca7..adb3f09 100644 --- a/BPA.SAAS.Manage.Application/DataBase/Services/BomService.cs +++ b/BPA.SAAS.Manage.Application/DataBase/Services/BomService.cs @@ -1,6 +1,8 @@ using BPA.SAAS.Manage.Application.DataBase.Dtos.Bom; +using BPA.SAAS.Manage.Application.DataBase.Dtos.GoodsAttribute; using BPA.SAAS.Manage.Application.DataBase.Interface; using BPA.SAAS.Manage.Comm.Enum; +using BPA.SAAS.Manage.Core.Base; using BPA.SAAS.Manage.Core.DataBase; using NPOI.SS.Formula.Functions; using System; @@ -219,5 +221,24 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services var str = string.Format("{0}", ram.ToString().Substring(0, Length)); return str; } + + /// + ///获取 配方列表 + /// + /// + /// + public async Task BomPage(BomPageInputDto inputDto) + { + int total = new RefAsync(); + var res = await _db.Queryable() + .ToPageListAsync(inputDto.Current, inputDto.PageSize, total); + + return new PageUtil() + { + Data = res, + Total= total, + + }; + } } } From 37aafced3124d0d21108c5207f5a62a5d19715fa Mon Sep 17 00:00:00 2001 From: zhaoy <137053305@qq.com> Date: Mon, 19 Feb 2024 14:42:38 +0800 Subject: [PATCH 2/4] z --- .../GoodsAttribute/GoodsBomAttributeDto.cs | 2 + .../DataBase/Services/GoodsService.cs | 115 +++++++++++------- 2 files changed, 74 insertions(+), 43 deletions(-) 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; } From 0938ba2991d65b09f3bfe37434244dd77e9da989 Mon Sep 17 00:00:00 2001 From: zhaoy <137053305@qq.com> Date: Mon, 19 Feb 2024 17:50:27 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=95=86=E5=93=81=E9=85=8D=E6=96=B9?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataBase/Dtos/Goods/GoodsBomPageView.cs | 18 +++++ .../DataBase/Dtos/Goods/GoodsBomQueryDto.cs | 16 +++++ .../GoodsAttribute/GoodsBomAttributeDto.cs | 3 +- .../DataBase/GoodsServices.cs | 2 +- .../DataBase/Interface/IGoodsService.cs | 2 +- .../DataBase/Services/GoodsService.cs | 66 +++++++++++-------- .../DataBase/BPA_BomAttributeValueRe.cs | 11 +++- 7 files changed, 87 insertions(+), 31 deletions(-) create mode 100644 BPA.SAAS.Manage.Application/DataBase/Dtos/Goods/GoodsBomPageView.cs create mode 100644 BPA.SAAS.Manage.Application/DataBase/Dtos/Goods/GoodsBomQueryDto.cs diff --git a/BPA.SAAS.Manage.Application/DataBase/Dtos/Goods/GoodsBomPageView.cs b/BPA.SAAS.Manage.Application/DataBase/Dtos/Goods/GoodsBomPageView.cs new file mode 100644 index 0000000..a03ceca --- /dev/null +++ b/BPA.SAAS.Manage.Application/DataBase/Dtos/Goods/GoodsBomPageView.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.DataBase.Dtos.Goods +{ + public class GoodsBomPageView + { + public string Id { get; set; } + public string Name { get; set; } + public string BomId { get; set; } + public bool IsMain { get; set; } + public string GoodsAttributeValueId { get; set; } + public string GoodsAttributeValue { get; set; } + } +} diff --git a/BPA.SAAS.Manage.Application/DataBase/Dtos/Goods/GoodsBomQueryDto.cs b/BPA.SAAS.Manage.Application/DataBase/Dtos/Goods/GoodsBomQueryDto.cs new file mode 100644 index 0000000..7d475c1 --- /dev/null +++ b/BPA.SAAS.Manage.Application/DataBase/Dtos/Goods/GoodsBomQueryDto.cs @@ -0,0 +1,16 @@ +using BPA.SAAS.Manage.Core.Base; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.DataBase.Dtos.Goods +{ + public class GoodsBomQueryDto: PageInputBase + { + public string GoodsId { get; set; } + public string Name { get; set; } + public string GoodsAttributeValue { get; set; } + } +} diff --git a/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsAttribute/GoodsBomAttributeDto.cs b/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsAttribute/GoodsBomAttributeDto.cs index 065e653..8c36b42 100644 --- a/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsAttribute/GoodsBomAttributeDto.cs +++ b/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsAttribute/GoodsBomAttributeDto.cs @@ -9,7 +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 BomId { get; set; } + public string GoodsAttributeValue { get; set; } public string Type { get; set; } public string BomName { get; set; } public string BomType { get; set; } diff --git a/BPA.SAAS.Manage.Application/DataBase/GoodsServices.cs b/BPA.SAAS.Manage.Application/DataBase/GoodsServices.cs index e966e16..7e966c2 100644 --- a/BPA.SAAS.Manage.Application/DataBase/GoodsServices.cs +++ b/BPA.SAAS.Manage.Application/DataBase/GoodsServices.cs @@ -85,7 +85,7 @@ namespace BPA.SAAS.Manage.Application.DataBase /// /// [HttpPost("/api/goods/getgoodsbompage")] - public async Task GetGoodsBomPageAsync(OrtherGoodsQueryDto dto) + public async Task GetGoodsBomPageAsync(GoodsBomQueryDto dto) { return await _goodsService.GetGoodsBomPageAsync(dto); } diff --git a/BPA.SAAS.Manage.Application/DataBase/Interface/IGoodsService.cs b/BPA.SAAS.Manage.Application/DataBase/Interface/IGoodsService.cs index 9caf633..7d9202e 100644 --- a/BPA.SAAS.Manage.Application/DataBase/Interface/IGoodsService.cs +++ b/BPA.SAAS.Manage.Application/DataBase/Interface/IGoodsService.cs @@ -52,7 +52,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Interface /// /// /// - Task GetGoodsBomPageAsync(OrtherGoodsQueryDto dto); + Task GetGoodsBomPageAsync(GoodsBomQueryDto dto); /// /// 删除商品配方 /// diff --git a/BPA.SAAS.Manage.Application/DataBase/Services/GoodsService.cs b/BPA.SAAS.Manage.Application/DataBase/Services/GoodsService.cs index 2dd9342..bda1701 100644 --- a/BPA.SAAS.Manage.Application/DataBase/Services/GoodsService.cs +++ b/BPA.SAAS.Manage.Application/DataBase/Services/GoodsService.cs @@ -1,5 +1,6 @@ using BPA.Franchisee.Application.FranchiseeCenter.GoodsServices; using BPA.SAAS.Manage.Application.DataBase.Dtos.Batching; +using BPA.SAAS.Manage.Application.DataBase.Dtos.Bom; using BPA.SAAS.Manage.Application.DataBase.Dtos.Goods; using BPA.SAAS.Manage.Application.DataBase.Dtos.GoodsAttribute; using BPA.SAAS.Manage.Application.DataBase.Interface; @@ -252,19 +253,26 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services /// /// /// - public async Task GetGoodsBomPageAsync(OrtherGoodsQueryDto dto) + public async Task GetGoodsBomPageAsync(GoodsBomQueryDto dto) { RefAsync total = 0; - var res =await _db.Queryable((a, b) => new JoinQueryInfos( - JoinType.Left, a.Id == b.BomId + var res =await _db.Queryable((a, b) => new JoinQueryInfos( + JoinType.Left, a.Id == b.BoomId )) - .WhereIF(!string.IsNullOrWhiteSpace(dto.GoodsId), (a, b) => b.Goods_Id == dto.GoodsId) - .Select((a, b) => new + .WhereIF(!string.IsNullOrWhiteSpace(dto.GoodsId), (a, b) => b.GoodsId==dto.GoodsId) + .WhereIF(!string.IsNullOrWhiteSpace(dto.Name), (a, b) => a.Name.Contains(dto.Name)) + .WhereIF(!string.IsNullOrWhiteSpace(dto.GoodsAttributeValue), (a, b) => b.GoodsAttributeValue.Contains(dto.GoodsAttributeValue)) + .Select((a, b) => new GoodsBomPageView { Id = b.Id, Name = a.Name, - BomId= b.BomId, - IsMain = a.IsMain + BomId= b.BoomId, + IsMain = a.IsMain, + GoodsAttributeValueId=b.GoodsAttributeValueId, + }).Mapper(x => + { + var AttributeValue = _db.Queryable().Where(p => x.GoodsAttributeValueId.Contains(p.Id)).Select(p=>p.AttributeValue).ToArray(); + x.GoodsAttributeValue =string.Join("-", AttributeValue); }) .ToPageListAsync(dto.Current, dto.PageSize, total); PageUtil util = new PageUtil() @@ -281,10 +289,12 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services /// public async Task BatchDelGoodsBomAsync(string Ids) { - // var GoodsBom=_db.Queryable().Where(x => x.Id == Ids).First(); - + // var GoodsBom=_db.Queryable().Where(x => x.Id == Ids).First(); + var model=_db.Queryable().Where(x => x.Id == Ids).First(); + if(model==null) throw Oops.Oh("配方不存在"); + _db.Deleteable().Where(x => x.Goods_Id == model.GoodsId && x.BomId== model.BoomId).ExecuteCommand(); // 查询数据库中是否存在未删除的商品 - var res = _db.Deleteable().In(Ids).ExecuteCommand(); + var res = _db.Deleteable().In(Ids).ExecuteCommand(); return res > 0; } /// @@ -346,34 +356,38 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services bPA_BomAttributeValueRe.GoodsId = dto.GoodsId; bPA_BomAttributeValueRe.BoomId = newbPA_BOM.Id; bPA_BomAttributeValueRe.GoodsAttributeValueId = string.Join(",", dto.Shuxing); + bPA_BomAttributeValueRe.GoodsAttributeValue = dto.GoodsAttributeValue; //添加商品配方属性关系 _db.Insertable(bPA_BomAttributeValueRe).ExecuteCommand(); } else { - if (dto.BomId.Count > 0) + if (string.IsNullOrWhiteSpace(dto.BomId)) throw Oops.Oh("请选择配方"); + if (!string.IsNullOrWhiteSpace(dto.BomId)) { - List bomlist = new(); - List bPA_BomAttributeValueRelist = new(); - for (int i = 0; i < dto.BomId.Count; i++) + var check=_db.Queryable().Where(x => x.Goods_Id == dto.GoodsId && x.BomId == dto.BomId).Any(); + if (!check) { BPA_GoodsBom bom = new BPA_GoodsBom(); bom.Goods_Id = dto.GoodsId; - bom.BomId = dto.BomId[i]; + bom.BomId = dto.BomId; 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(bom).CallEntityMethod(m => m.Create()).ExecuteCommand(); } - //添加商品配方关系 - _db.Insertable(bomlist).CallEntityMethod(m => m.Create()).ExecuteCommand(); + string vid = string.Join(",", dto.Shuxing); + var checkvid = _db.Queryable().Where(x => x.GoodsId == dto.GoodsId && x.BoomId == dto.BomId && x.GoodsAttributeValueId== vid).Any(); + if(checkvid) throw Oops.Oh("该配方已经存在"); //添加商品配方属性关系 - _db.Insertable(bPA_BomAttributeValueRelist).ExecuteCommand(); - } + BPA_BomAttributeValueRe bPA_BomAttributeValueRe = new(); + bPA_BomAttributeValueRe.Id = Guid.NewGuid().ToString(); + bPA_BomAttributeValueRe.GoodsId = dto.GoodsId; + bPA_BomAttributeValueRe.BoomId = dto.BomId; + bPA_BomAttributeValueRe.GoodsAttributeValueId = vid; + bPA_BomAttributeValueRe.GoodsAttributeValue = dto.GoodsAttributeValue; + _db.Insertable(bPA_BomAttributeValueRe).ExecuteCommand(); + } + } _db.Ado.CommitTran(); return true; diff --git a/BPA.SAAS.Manage.Core/DataBase/BPA_BomAttributeValueRe.cs b/BPA.SAAS.Manage.Core/DataBase/BPA_BomAttributeValueRe.cs index a7184f1..2660e93 100644 --- a/BPA.SAAS.Manage.Core/DataBase/BPA_BomAttributeValueRe.cs +++ b/BPA.SAAS.Manage.Core/DataBase/BPA_BomAttributeValueRe.cs @@ -1,4 +1,5 @@ -using SqlSugar; +using BPA.SAAS.Manage.Core.Base; +using SqlSugar; using System; using System.Collections.Generic; using System.Linq; @@ -11,8 +12,9 @@ namespace BPA.SAAS.Manage.Core.DataBase /// 配方商品属性关系 /// [SugarTable("bpa_bomattributevaluere")] - public class BPA_BomAttributeValueRe + public class BPA_BomAttributeValueRe:IGroupId { + [SugarColumn(IsPrimaryKey = true, ColumnDataType = "Nvarchar(64)", IsNullable = false)] public string Id { get; set; } public string GoodsId { get; set; } /// @@ -23,5 +25,10 @@ namespace BPA.SAAS.Manage.Core.DataBase /// 商品属性值id /// public string GoodsAttributeValueId { get; set; } + /// + /// 商品属性值 + /// + public string GoodsAttributeValue { get; set; } + public string GroupId { get; set; } } } From ea2171e48a309c8380ba59dac15e8c8fe165dad1 Mon Sep 17 00:00:00 2001 From: gwbvipvip Date: Mon, 19 Feb 2024 20:11:47 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataBase/BomServices.cs | 25 ++++ .../DataBase/Dtos/Bom/BomDto.cs | 15 +++ .../DataBase/Interface/IBomService.cs | 20 ++- .../DataBase/Services/BomService.cs | 126 +++++++++++++++++- 4 files changed, 178 insertions(+), 8 deletions(-) diff --git a/BPA.SAAS.Manage.Application/DataBase/BomServices.cs b/BPA.SAAS.Manage.Application/DataBase/BomServices.cs index 859eb22..8216827 100644 --- a/BPA.SAAS.Manage.Application/DataBase/BomServices.cs +++ b/BPA.SAAS.Manage.Application/DataBase/BomServices.cs @@ -1,6 +1,9 @@ using BPA.SAAS.Manage.Application.DataBase.Dtos.Bom; using BPA.SAAS.Manage.Application.DataBase.Interface; +using BPA.SAAS.Manage.Comm.Enum; using BPA.SAAS.Manage.Core.Base; +using BPA.SAAS.Manage.Core.DataBase; +using Microsoft.AspNetCore.Components.Forms; using System; using System.Collections.Generic; using System.Linq; @@ -107,5 +110,27 @@ namespace BPA.SAAS.Manage.Application.DataBase { return await _bomService.BomPage(inputDto); } + + /// + /// 添加配方 + /// + /// + /// + [HttpPost("/api/bom/AddBom")] + public async Task AddBom(BomCreateInputDto dto) + { + return await _bomService.AddBom(dto); + } + + /// + /// 删除配方 + /// + /// + /// + [HttpPost("/api/bom/DelBom")] + public async Task DelBom(string id) + { + return await _bomService.DelBom(id); + } } } diff --git a/BPA.SAAS.Manage.Application/DataBase/Dtos/Bom/BomDto.cs b/BPA.SAAS.Manage.Application/DataBase/Dtos/Bom/BomDto.cs index 16ffc17..b626732 100644 --- a/BPA.SAAS.Manage.Application/DataBase/Dtos/Bom/BomDto.cs +++ b/BPA.SAAS.Manage.Application/DataBase/Dtos/Bom/BomDto.cs @@ -9,6 +9,21 @@ namespace BPA.SAAS.Manage.Application.DataBase.Dtos.Bom { public class BomPageInputDto: PageInputBase { + public string Name { get; set; } + public string bomTypeList { get; set; } + public List Pertains { get; set; } + } + public class BomCreateInputDto + { + public string BomName { get; set; } + public string BomType { get; set; } + public string[] BomtypeList { get; set; } + public List Mate { get; set; } + } + public class Mateinfo + { + public string batchingId { get; set; } + public int dosage { get; set; } } } diff --git a/BPA.SAAS.Manage.Application/DataBase/Interface/IBomService.cs b/BPA.SAAS.Manage.Application/DataBase/Interface/IBomService.cs index 77d10db..1f7f762 100644 --- a/BPA.SAAS.Manage.Application/DataBase/Interface/IBomService.cs +++ b/BPA.SAAS.Manage.Application/DataBase/Interface/IBomService.cs @@ -26,13 +26,13 @@ namespace BPA.SAAS.Manage.Application.DataBase.Interface /// /// /// - Task AddBom(BomInputDto dto); + Task AddBom(BomInputDto dto); /// /// 更新 /// /// /// - Task UpdateBom(BomInputDto dto); + Task UpdateBom(BomInputDto dto); /// 更新配方详情 /// /// @@ -49,7 +49,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Interface /// /// /// - Task AddBomType(AddBomTypeInputDto dto); + Task AddBomType(AddBomTypeInputDto dto); /// /// 配方分类列表 /// @@ -62,5 +62,19 @@ namespace BPA.SAAS.Manage.Application.DataBase.Interface /// /// Task BomPage(BomPageInputDto inputDto); + + /// + /// 添加配方 + /// + /// + /// + Task AddBom(BomCreateInputDto dto); + + /// + /// 删除配方 + /// + /// + /// + Task DelBom(string id); } } diff --git a/BPA.SAAS.Manage.Application/DataBase/Services/BomService.cs b/BPA.SAAS.Manage.Application/DataBase/Services/BomService.cs index adb3f09..b68a8ca 100644 --- a/BPA.SAAS.Manage.Application/DataBase/Services/BomService.cs +++ b/BPA.SAAS.Manage.Application/DataBase/Services/BomService.cs @@ -117,6 +117,8 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services } } + + /// /// 更新配方详情 /// @@ -229,16 +231,130 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services /// public async Task BomPage(BomPageInputDto inputDto) { + + var pertainList = _db.Queryable((a, b) => + new JoinQueryInfos(JoinType.Left, a.BomTypeId == b.Id)) + .Where((a, b) => a.IsDeleted == 0 && b.IsDeleted == 0) + .WhereIF(inputDto.Pertains != null && inputDto.Pertains.Count > 0, (a, b) => inputDto.Pertains.Contains(b.Pertain)) + .WhereIF(!string.IsNullOrWhiteSpace(inputDto.bomTypeList), (a, b) => b.Id == inputDto.bomTypeList) + .Select((a, b) => a.BomId) + .ToList(); + int total = new RefAsync(); - var res = await _db.Queryable() - .ToPageListAsync(inputDto.Current, inputDto.PageSize, total); + var res = _db.Queryable() + .Where(it => it.IsDeleted == 0) + .WhereIF(!string.IsNullOrEmpty(inputDto.Name),x=>x.Name.Contains(inputDto.Name)) + .WhereIF(!string.IsNullOrWhiteSpace(inputDto.bomTypeList), x => pertainList.Contains(x.Id)) + .OrderBy(i => i.CreateAt, OrderByType.Desc) + .ToPageList(inputDto.Current, inputDto.PageSize, ref total); + + + var listtype = _db.Queryable() + .Where(a => res.Select(x => x.Id).Contains(a.BomId) && a.IsDeleted == 0).ToList(); - return new PageUtil() + var data = new List(); + foreach (var item in res) { - Data = res, - Total= total, + var obj = listtype.Where(x => x.BomId == item.Id).Select(x => x.BomTypeId).ToList(); + data.Add(new + { + BomTypeList = obj, + Name = item.Name, + Code = item.Code, + item.IsMain, + item.BOMInfo, + item.Status, + item.Id, + item.Sort, + }); + } + PageUtil util = new PageUtil() + { + Total = total, + Data = data }; + return util; + } + + /// + /// 添加配方 + /// + /// + /// + public async Task AddBom(BomCreateInputDto dto) + { + _db.Ado.BeginTran(); + try + { + var sortMax = _db.Queryable().Max(x => x.Sort); + BPA_Bom newbPA_BOM = new BPA_Bom + { + Name = dto.BomName, + Code = GetNumber2(), + IsMain = true, + 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(); + + + 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(); + _db.Ado.CommitTran(); + return true; + } + catch (Exception e) + { + _db.Ado.RollbackTran(); + throw Oops.Oh("添加失败,失败信息:" + e.Message); + } + } + + /// + /// 删除配方 + /// + /// + /// + public async Task DelBom(string id) + { + + try + { + _db.Ado.BeginTran(); + await _db.Deleteable().Where(x => x.Id == id).ExecuteCommandAsync(); + await _db.Deleteable().Where(x => x.BomId == id).ExecuteCommandAsync(); + _db.Ado.CommitTran(); + return true; + } + catch (Exception e) + { + _db.Ado.RollbackTran(); + throw Oops.Oh("删除失败" + e.Message); + } } } }