diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsEnergyConfigQuDto.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsEnergyConfigQuDto.cs new file mode 100644 index 0000000..eada2a4 --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsEnergyConfigQuDto.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods.Dtos +{ + public class GoodsEnergyConfigQuDto + { + public string GoodsId { get; set; } + public string Name { get; set; } + } +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsEnergyConfigVuewDto.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsEnergyConfigVuewDto.cs new file mode 100644 index 0000000..2c49471 --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsEnergyConfigVuewDto.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods.Dtos +{ + public class GoodsEnergyConfigVuewDto + { + public string Id { get; set; } + public string GoodsId { get; set; } + public string Name { get; set; } + //public string Uint { get; set; } + public List Details { get; set; } + } + public class GoodsEnergyConfigDetailsView + { + public string Id { get; set; } + public string Key { get; set; } + public string Value { get; set; } + } +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/GoodsServices.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/GoodsServices.cs index 81883d4..4cb908f 100644 --- a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/GoodsServices.cs +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/GoodsServices.cs @@ -2,6 +2,7 @@ using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods.Dtos; using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods.Services; using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Material.Services; +using BPA.SAAS.Manage.Application.DataBase.Dtos.GoodsEnergyConfig; using BPA.SAAS.Manage.Core.Base; using Microsoft.AspNetCore.Components.Forms; using Org.BouncyCastle.Crypto; @@ -181,5 +182,15 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods { return await _goodsService.DelGoodsUint(dto); } + /// + /// 查询商品能量配置 + /// + /// + /// + [HttpPost("/api/ExternalPlatform/Goods/GetGoodsEnergyConfig")] + public async Task> GetGoodsEnergyConfigPage(GoodsEnergyConfigQuDto dto) + { + return await _goodsService.GetGoodsEnergyConfigPage(dto); + } } } diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Services/GoodsService.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Services/GoodsService.cs index e4cacf8..aecfef4 100644 --- a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Services/GoodsService.cs +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Services/GoodsService.cs @@ -6,6 +6,7 @@ using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Material.Dtos; using BPA.SAAS.Manage.Application.AExternalPlatform.Service.ThirdpartyPush.Dtos; using BPA.SAAS.Manage.Application.AExternalPlatform.Service.ThirdpartyPush.Services; using BPA.SAAS.Manage.Application.DataBase.Dtos.Goods; +using BPA.SAAS.Manage.Application.DataBase.Dtos.GoodsEnergyConfig; using BPA.SAAS.Manage.Application.DataBase.Dtos.GoodsTechnology; using BPA.SAAS.Manage.Application.DataBase.Dtos.GoodsType; using BPA.SAAS.Manage.Core.Base; @@ -561,6 +562,36 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods.Services } } + /// + /// 查询商品能量配置 + /// + /// + /// + public async Task> GetGoodsEnergyConfigPage(GoodsEnergyConfigQuDto dto) + { + List conModels = new List(); + //string groupId = App.User.FindFirst(ClaimConst.GroupId)?.Value; + if (!string.IsNullOrEmpty(dto.Name)) + { + conModels.Add(new ConditionalModel() { FieldName = "Name", ConditionalType = ConditionalType.Like, FieldValue = dto.Name }); + } + if (!string.IsNullOrEmpty(dto.GoodsId)) + { + conModels.Add(new ConditionalModel() { FieldName = "GoodsId", ConditionalType = ConditionalType.Like, FieldValue = dto.GoodsId }); + } + int total = new RefAsync(); + var res = await SqlSugarDb.Db.Queryable() + .Where(conModels) + .OrderBy(a => a.CreateAt, OrderByType.Desc) + .Select(x=>new GoodsEnergyConfigVuewDto() { Id=x.Id,Name=x.Name, GoodsId =x.GoodsId}) + .Mapper(x => + { + var data=SqlSugarDb.Db.Queryable().Where(it => it.GoodsenergyconfigId == x.Id).Select(it=>new GoodsEnergyConfigDetailsView() { Id=it.Id.SelectAll()}).ToList(); + x.Details = data; + }) + .ToListAsync(); + return res; + } private string GetNumber2(int Length = 10) { byte[] buffer = Guid.NewGuid().ToByteArray(); diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Services/IGoodsService.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Services/IGoodsService.cs index 35c3c17..bc1882d 100644 --- a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Services/IGoodsService.cs +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Services/IGoodsService.cs @@ -1,5 +1,6 @@ using BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto; using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods.Dtos; +using BPA.SAAS.Manage.Application.DataBase.Dtos.GoodsEnergyConfig; using BPA.SAAS.Manage.Core.Base; using System; using System.Collections.Generic; @@ -61,5 +62,11 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods.Services Task AddGoodsUint(List dto); Task UpdateGoodsUint(GoodsUintUpdateDto dto); Task DelGoodsUint(GoodsUintDelDto dto); + /// + /// 查询商品能量配置 + /// + /// + /// + Task> GetGoodsEnergyConfigPage(GoodsEnergyConfigQuDto dto); } } diff --git a/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsEnergyConfig/GoodsEnergyConfigDetailsViewDto.cs b/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsEnergyConfig/GoodsEnergyConfigDetailsViewDto.cs new file mode 100644 index 0000000..9be1405 --- /dev/null +++ b/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsEnergyConfig/GoodsEnergyConfigDetailsViewDto.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.DataBase.Dtos.GoodsEnergyConfig +{ + public class GoodsEnergyConfigDetailsViewDto + { + public string Id { get; set; } + public string Key { get; set; } + public string Value { get; set; } + } +} diff --git a/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsEnergyConfig/GoodsEnergyConfigDto.cs b/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsEnergyConfig/GoodsEnergyConfigDto.cs index 7026190..920b891 100644 --- a/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsEnergyConfig/GoodsEnergyConfigDto.cs +++ b/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsEnergyConfig/GoodsEnergyConfigDto.cs @@ -12,5 +12,12 @@ namespace BPA.SAAS.Manage.Application.DataBase.Dtos.GoodsEnergyConfig public string GoodsId { get; set; } public string Name { get; set; } public string Uint { get; set; } + public List Details { get; set; } + + } + public class GoodsEnergyConfigDetails + { + public string Key { get; set; } + public string Value { get; set; } } } diff --git a/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsEnergyConfig/GoodsEnergyConfigQueryDto.cs b/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsEnergyConfig/GoodsEnergyConfigQueryDto.cs index 27c6904..69cddfe 100644 --- a/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsEnergyConfig/GoodsEnergyConfigQueryDto.cs +++ b/BPA.SAAS.Manage.Application/DataBase/Dtos/GoodsEnergyConfig/GoodsEnergyConfigQueryDto.cs @@ -9,6 +9,7 @@ namespace BPA.SAAS.Manage.Application.DataBase.Dtos.GoodsEnergyConfig { public class GoodsEnergyConfigQueryDto: PageInputBase { + public string GoodsId { get; set; } public string Name { get; set; } } } diff --git a/BPA.SAAS.Manage.Application/DataBase/GoodsEnergyConfigServices.cs b/BPA.SAAS.Manage.Application/DataBase/GoodsEnergyConfigServices.cs index 2310ab7..bfc6245 100644 --- a/BPA.SAAS.Manage.Application/DataBase/GoodsEnergyConfigServices.cs +++ b/BPA.SAAS.Manage.Application/DataBase/GoodsEnergyConfigServices.cs @@ -57,15 +57,16 @@ namespace BPA.SAAS.Manage.Application.DataBase { return await _energyConfigService.DelGoodsEnergyConfig(Id); } + /// - /// 分页查询 + /// 查询详情 /// - /// + /// /// - [HttpPost("/api/goodsenergyconfig/getgoodsenergyconfigdetailspage")] - public async Task GetGoodsEnergyConfigDetailsPage(GoodsEnergyConfigDetailsQueryDto dto) + [HttpGet("/api/goodsenergyconfig/getgoodsenergyconfigdetailslist")] + public async Task> GetGoodsEnergyConfigDetailsList(string goodsenergyconfigId) { - return await _energyConfigService.GetGoodsEnergyConfigDetailsPage(dto); + return await _energyConfigService.GetGoodsEnergyConfigDetailsList(goodsenergyconfigId); } /// /// 添加 diff --git a/BPA.SAAS.Manage.Application/DataBase/Interface/IGoodsEnergyConfigService.cs b/BPA.SAAS.Manage.Application/DataBase/Interface/IGoodsEnergyConfigService.cs index 31f0c34..252fa8d 100644 --- a/BPA.SAAS.Manage.Application/DataBase/Interface/IGoodsEnergyConfigService.cs +++ b/BPA.SAAS.Manage.Application/DataBase/Interface/IGoodsEnergyConfigService.cs @@ -36,11 +36,11 @@ namespace BPA.SAAS.Manage.Application.DataBase.Interface /// Task DelGoodsEnergyConfig(string Id); /// - /// 分页查询 + /// 查询详情 /// - /// + /// /// - Task GetGoodsEnergyConfigDetailsPage(GoodsEnergyConfigDetailsQueryDto dto); + Task> GetGoodsEnergyConfigDetailsList(string goodsenergyconfigId); /// /// 添加 /// diff --git a/BPA.SAAS.Manage.Application/DataBase/Services/GoodsEnergyConfigService.cs b/BPA.SAAS.Manage.Application/DataBase/Services/GoodsEnergyConfigService.cs index fd37231..8e0f08e 100644 --- a/BPA.SAAS.Manage.Application/DataBase/Services/GoodsEnergyConfigService.cs +++ b/BPA.SAAS.Manage.Application/DataBase/Services/GoodsEnergyConfigService.cs @@ -5,6 +5,7 @@ using BPA.SAAS.Manage.Comm.Const; using BPA.SAAS.Manage.Comm.Enum; using BPA.SAAS.Manage.Core.Base; using BPA.SAAS.Manage.Core.DataBase; +using NPOI.POIFS.Storage; using System; using System.Collections.Generic; using System.Linq; @@ -33,6 +34,10 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services { conModels.Add(new ConditionalModel() { FieldName = "Name", ConditionalType = ConditionalType.Like, FieldValue = dto.Name }); } + if (!string.IsNullOrEmpty(dto.GoodsId)) + { + conModels.Add(new ConditionalModel() { FieldName = "GoodsId", ConditionalType = ConditionalType.Like, FieldValue = dto.GoodsId }); + } int total = new RefAsync(); var res = await _db.Queryable() .Where(conModels) @@ -53,16 +58,39 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services /// public async Task AddGoodsEnergyConfig(GoodsEnergyConfigDto dto) { - var resEntity = _db.Queryable().First(it => it.Name == dto.Name); - if (resEntity != null) throw Oops.Oh("配置名称已存在"); - var newType = new BPA_GoodsEnergyConfig + try { - GoodsId = dto.GoodsId, - Name = dto.Name, - Uint = dto.Uint, - }; - var res = await _db.Insertable(newType).CallEntityMethod(m => m.Create()).ExecuteCommandAsync(); - return res > 0; + _db.Ado.BeginTran(); + var resEntity = _db.Queryable().First(it => it.Name == dto.Name); + if (resEntity != null) throw Oops.Oh("配置名称已存在"); + var newType = new BPA_GoodsEnergyConfig + { + GoodsId = dto.GoodsId, + Name = dto.Name, + Uint = dto.Uint, + }; + var model = await _db.Insertable(newType).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync(); + List list = new(); + for (int i = 0; i < dto.Details.Count; i++) + { + var model1 = new BPA_GoodsEnergyConfigDetails + { + GoodsenergyconfigId = model.Id, + Key = dto.Details[i].Key, + Value = dto.Details[i].Value, + }; + list.Add(model1); + } + var res = await _db.Insertable(list).CallEntityMethod(m => m.Create()).ExecuteCommandAsync(); + _db.Ado.CommitTran(); + return res > 0; + } + catch (Exception e) + { + _db.Ado.RollbackTran(); + throw Oops.Oh("系统异常,异常信息:"+ e.Message); + } + } /// /// 更新 @@ -71,15 +99,40 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services /// public async Task UpdateGoodsEnergyConfig(GoodsEnergyConfigDto dto) { - // 查询数据库中是否存在未删除的商品类型 - var resEntity = _db.Queryable().First(it => it.Id == dto.Id); - if (null == resEntity) throw Oops.Oh("配置不存在"); - var resEntity1 = _db.Queryable().First(it => it.Name == dto.Name && it.Id!= dto.Id); - if (resEntity1 != null) throw Oops.Oh("配置名称已存在"); - resEntity.Name = dto.Name; - resEntity.Uint = dto.Uint; - var res = await _db.Updateable(resEntity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); - return res > 0; + try + { + _db.Ado.BeginTran(); + // 查询数据库中是否存在未删除的商品类型 + var resEntity = _db.Queryable().First(it => it.Id == dto.Id); + if (null == resEntity) throw Oops.Oh("配置不存在"); + var resEntity1 = _db.Queryable().First(it => it.Name == dto.Name && it.Id != dto.Id); + if (resEntity1 != null) throw Oops.Oh("配置名称已存在"); + resEntity.Name = dto.Name; + resEntity.Uint = dto.Uint; + await _db.Updateable(resEntity).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); + var model = _db.Queryable().Where(it => it.GoodsenergyconfigId == dto.Id).ToList(); + if (model.Count > 0) await _db.Deleteable(model).ExecuteCommandAsync(); + List list = new(); + for (int i = 0; i < dto.Details.Count; i++) + { + var model1 = new BPA_GoodsEnergyConfigDetails + { + GoodsenergyconfigId = dto.Id, + Key = dto.Details[i].Key, + Value = dto.Details[i].Value, + }; + list.Add(model1); + } + var res = await _db.Insertable(list).CallEntityMethod(m => m.Create()).ExecuteCommandAsync(); + _db.Ado.CommitTran(); + return res > 0; + } + catch (Exception e) + { + _db.Ado.RollbackTran(); + throw Oops.Oh("系统异常,异常信息:" + e.Message); + } + } /// /// 删除 @@ -88,34 +141,40 @@ namespace BPA.SAAS.Manage.Application.DataBase.Services /// public async Task DelGoodsEnergyConfig(string Id) { - // 查询数据库中是否存在未删除的商品类型 - var resEntity = _db.Queryable().First(it => it.Id == Id); - if (resEntity==null) + try { - throw Oops.Oh("配置不存在"); + _db.Ado.BeginTran(); + // 查询数据库中是否存在未删除的商品类型 + var resEntity = _db.Queryable().First(it => it.Id == Id); + if (resEntity == null) + { + throw Oops.Oh("配置不存在"); + } + var model = _db.Queryable().Where(it => it.GoodsenergyconfigId == Id).ToList(); + if (model.Count > 0) await _db.Deleteable(model).ExecuteCommandAsync(); + var res = await _db.Deleteable(resEntity).ExecuteCommandAsync(); + _db.Ado.CommitTran(); + return res > 0; } - var res = await _db.Deleteable(resEntity).ExecuteCommandAsync(); - return res > 0; + catch (Exception e) + { + + _db.Ado.RollbackTran(); + throw Oops.Oh("系统异常,异常信息:" + e.Message); + } + } - /// - /// 分页查询 - /// - /// - /// - public async Task GetGoodsEnergyConfigDetailsPage(GoodsEnergyConfigDetailsQueryDto dto) + + public async Task> GetGoodsEnergyConfigDetailsList(string goodsenergyconfigId) { - + int total = new RefAsync(); var res = await _db.Queryable() + .Where(x=>x.GoodsenergyconfigId== goodsenergyconfigId) .OrderBy(a => a.CreateAt, OrderByType.Desc) - .ToPageListAsync(dto.Current, dto.PageSize, total); - PageUtil util = new PageUtil() - { - Total = total, - Data = res - - }; - return util; + .Select(x => new GoodsEnergyConfigDetailsViewDto() { Id=x.Id,Key=x.Key,Value=x.Value}) + .ToListAsync(); + return res; } /// /// 添加