diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Enum/ErrorCodeEnum.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Enum/ErrorCodeEnum.cs index 2e9b147..4733d50 100644 --- a/BPA.SAAS.Manage.Application/AExternalPlatform/Enum/ErrorCodeEnum.cs +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Enum/ErrorCodeEnum.cs @@ -97,5 +97,10 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Enum /// [ErrorCodeItemMetadata("授权过期")] Code10014, + /// + /// 配方不存在 + /// + [ErrorCodeItemMetadata("配方不存在")] + Code10015, } } diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Bom/BomServices.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Bom/BomServices.cs new file mode 100644 index 0000000..7cd9f15 --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Bom/BomServices.cs @@ -0,0 +1,84 @@ +using BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto; +using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Bom.Dtos; +using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Bom.Services; +using BPA.SAAS.Manage.Application.DataBase.Dtos.Bom; +using BPA.SAAS.Manage.Core.Base; +using Microsoft.AspNetCore.Components.Forms; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Bom +{ + [ApiDescriptionSettings("开放平台", Tag = "配方管理"), AllowAnonymous] + public class BomServices:IDynamicApiController + { + IBomService _bomService; + public BomServices(IBomService bomService) + { + _bomService= bomService; + } + /// + /// 分页查询 + /// + /// + /// + [HttpPost("/api/ExternalPlatform/Bom/GetBomPageList")] + public async Task>> GetBomPageList(BomPageInputDto inputDto) + { + return await _bomService.GetBomPageList(inputDto); + } + /// + /// 添加 + /// + /// + /// + [HttpPost("/api/ExternalPlatform/Bom/AddBom")] + public async Task AddBom(BaseRequestDto dto) + { + return await _bomService.AddBom(dto); + } + /// + /// 更新 + /// + /// + /// + [HttpPost("/api/ExternalPlatform/Bom/UpdateBom")] + public async Task UpdateBom(BaseRequestDto dto) + { + return await _bomService.UpdateBom(dto); + } + /// + /// 删除 + /// + /// + /// + [HttpPost("/api/ExternalPlatform/Bom/DeleteBom")] + public async Task DeleteBom(string[] ids) + { + return await _bomService.DeleteBom(ids); + } + /// + /// 根据配方id查询配方详情 + /// + /// + /// + [HttpGet("/api/ExternalPlatform/Bom/GetBomEntry")] + public async Task GetBomEntry(string bomId) + { + return await _bomService.GetBomEntry(bomId); + } + /// + /// 添加配方详情 + /// + /// + /// + [HttpPost("/api/ExternalPlatform/Bom/AddBomEntry")] + public async Task AddBomEntry(BomEntryInsertDto dto) + { + return await _bomService.AddBomEntry(dto); + } + } +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Bom/Dtos/BomDto.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Bom/Dtos/BomDto.cs new file mode 100644 index 0000000..5d46832 --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Bom/Dtos/BomDto.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Bom.Dtos +{ + public class BomDto + { + public string Id { get; set; } + public string Name { get; set; } + /// + /// 1主料配方0 辅料配方 + /// + public bool IsMain { get; set; } + public int Sort { get; set; } + public string GroupId { get; set; } + public List BomEntr { get; set; } + } + public class BomEntr + { + public string Id { get; set; } + public string BatchingId { get; set; } + public string BatchingName { get; set; } + /// + /// 配方用量 + /// + public decimal BomQty { get; set; } + + /// + /// 配方id + /// + public string BomId { get; set; } + public int Sort { get; set; } + public string GroupId { get; set; } + } +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Bom/Dtos/BomEntryDto.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Bom/Dtos/BomEntryDto.cs new file mode 100644 index 0000000..a4520d3 --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Bom/Dtos/BomEntryDto.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Bom.Dtos +{ + public class BomEntryDto + { + public string Id { get; set; } + public string BatchingId { get; set; } + public string BatchingName { get; set; } + /// + /// 配方用量 + /// + public decimal BomQty { get; set; } + + /// + /// 配方id + /// + public string BomId { get; set; } + public string BomName { get; set; } + public int Sort { get; set; } + } +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Bom/Dtos/BomEntryInsertDto.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Bom/Dtos/BomEntryInsertDto.cs new file mode 100644 index 0000000..be71297 --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Bom/Dtos/BomEntryInsertDto.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.Bom.Dtos +{ + public class BomEntryInsertDto + { + public string BatchingId { get; set; } + /// + /// 配方用量 + /// + public decimal BomQty { get; set; } + + /// + /// 配方id + /// + public string BomId { get; set; } + public int Sort { get; set; } + } +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Bom/Dtos/BomInsertDto.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Bom/Dtos/BomInsertDto.cs new file mode 100644 index 0000000..0c42aa7 --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Bom/Dtos/BomInsertDto.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Bom.Dtos +{ + public class BomInsertDto + { + public string Name { get; set; } + public string BomTypeName { get; set; } + /// + /// 1主料配方0 辅料配方 + /// + public bool IsMain { get; set; } + public int Sort { get; set; } + } +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Bom/Dtos/BomUpdateDto.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Bom/Dtos/BomUpdateDto.cs new file mode 100644 index 0000000..1df22d1 --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Bom/Dtos/BomUpdateDto.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Bom.Dtos +{ + public class BomUpdateDto + { + public string Id { get; set; } + public string Name { get; set; } + /// + /// 1主料配方0 辅料配方 + /// + public bool IsMain { get; set; } + public int Sort { get; set; } + } +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Bom/Services/BomService.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Bom/Services/BomService.cs new file mode 100644 index 0000000..8fb3a02 --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Bom/Services/BomService.cs @@ -0,0 +1,211 @@ +using BPA.KitChen.GroupMeal.SqlSugar; +using BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto; +using BPA.SAAS.Manage.Application.AExternalPlatform.Enum; +using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Bom.Dtos; +using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods.Dtos; +using BPA.SAAS.Manage.Application.DataBase.Dtos.Bom; +using BPA.SAAS.Manage.Application.DataBase.Interface; +using BPA.SAAS.Manage.Core.Base; +using BPA.SAAS.Manage.Core.DataBase; +using BPA.SAAS.Manage.Core.Device; +using NPOI.SS.Formula.Functions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Bom.Services +{ + public class BomService: IBomService, ITransient + { + public BomService() + { + + } + /// + /// 分页查询 + /// + /// + /// + public async Task>> GetBomPageList(BomPageInputDto inputDto) + { + int total = new RefAsync(); + var data = SqlSugarDb.Db.Queryable() + .Select(a => new BomDto() + { + Id = a.Id.SelectAll(), + }) + .Mapper(x => + { + var list=SqlSugarDb.Db.Queryable((a,b)=> new JoinQueryInfos(JoinType.Left, a.BatchingId == b.Id)).Select((a,b)=>new BomEntr + { + Id=a.Id, + BatchingId=a.BatchingId, + BomQty=a.BomQty, + BomId=a.BomId, + Sort=a.sort, + GroupId=a.GroupId, + BatchingName=b.Batching_Name + }).ToList(); + x.BomEntr = list; + }) + .ToPageList(inputDto.Current, inputDto.PageSize, ref total); + + return new PageUtil>() + { + Total = total, + Data = data + }; + } + /// + /// 添加 + /// + /// + /// + public async Task AddBom(BaseRequestDto dto) + { + try + { + SqlSugarDb.Db.BeginTran(); + var resEntity = new BPA_Bom(); + resEntity.Name = dto.DataInfo.Name; + resEntity.IsMain = dto.DataInfo.IsMain; + resEntity.Sort = dto.DataInfo.Sort; + resEntity.Code = GetNumber2(8); + var bom = await SqlSugarDb.Db.Insertable(resEntity).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync(); + BPA_BomTypeInfo _BomTypeInfo = new(); + _BomTypeInfo.BomId = bom.Id; + var check = SqlSugarDb.Db.Queryable().Where(x => x.Name == dto.DataInfo.BomTypeName).First(); + if (check != null) + { + _BomTypeInfo.BomTypeId = check.Id; + } + else + { + var check1 = SqlSugarDb.Db.Queryable().Where(x => x.Name == "默认分类").First(); + if (check1 != null) + { + _BomTypeInfo.BomTypeId=check1.Id; + } + else + { + await SqlSugarDb.Db.Insertable(new BPA_BomType() { Name= "默认分类" }).CallEntityMethod(m => m.Create()).ExecuteCommandAsync(); + } + } + // resEntity.Code = GetNumber2(8); + var res = await SqlSugarDb.Db.Insertable(_BomTypeInfo).CallEntityMethod(m => m.Create()).ExecuteCommandAsync(); + SqlSugarDb.Db.CommitTran(); + return res > 0; + } + catch (Exception) + { + SqlSugarDb.Db.RollbackTran(); + throw Oops.Oh(ErrorCodeEnum.Code1007); + } + + } + /// + /// 更新 + /// + /// + /// + public async Task UpdateBom(BaseRequestDto dto) + { + // 查询数据库中是否存在未删除的商品类型 + var resEntity = SqlSugarDb.Db.Queryable().Where(it => it.IsDeleted == 0).First(it => it.Id == dto.DataInfo.Id); + if (null == resEntity) + { + throw Oops.Oh(ErrorCodeEnum.Code10015); + } + resEntity.Name = dto.DataInfo.Name; + resEntity.IsMain = dto.DataInfo.IsMain; + resEntity.Sort = dto.DataInfo.Sort; + + var res = await SqlSugarDb.Db.Updateable(resEntity).ExecuteCommandAsync(); + return res > 0; + } + /// + /// 删除 + /// + /// + /// + public async Task DeleteBom(string[] ids) + { + try + { + SqlSugarDb.Db.BeginTran(); + var goods = SqlSugarDb.Db.Queryable().Where(x => ids.Contains(x.Id)).ToList(); + if (goods == null) throw Oops.Oh(ErrorCodeEnum.Code10015); + var goodsbom = SqlSugarDb.Db.Queryable().Where(x => ids.Contains(x.BomId)).ToList(); + await SqlSugarDb.Db.Deleteable(goodsbom).ExecuteCommandAsync(); + var res = await SqlSugarDb.Db.Deleteable(goods).ExecuteCommandAsync(); + SqlSugarDb.Db.CommitTran(); + return res > 0; + } + catch (Exception) + { + SqlSugarDb.Db.RollbackTran(); + throw Oops.Oh("删除失败"); + } + + } + /// + /// 根据配方id查询配方详情 + /// + /// + /// + public async Task GetBomEntry(string bomId) + { + try + { + var resEntity=await SqlSugarDb.Db.Queryable((a,b,c)=> new JoinQueryInfos(JoinType.Left, a.BomId == b.Id, JoinType.Left, a.BatchingId == c.Id)) + .Select((a, b, c)=> new BomEntryDto() + { + Id=a.Id, + BatchingId=a.BatchingId, + BomQty=a.BomQty, + Sort=a.sort, + BatchingName=c.Batching_Name, + BomId = a.BomId, + BomName=b.Name + }).FirstAsync(); + + return resEntity; + } + catch (Exception) + { + throw Oops.Oh(ErrorCodeEnum.Code1007); + } + } + /// + /// 添加配方详情 + /// + /// + /// + public async Task AddBomEntry(BomEntryInsertDto dto) + { + try + { + var resEntity = new BPA_BomEntry(); + resEntity.BatchingId = dto.BatchingId; + resEntity.BomId = dto.BomId; + resEntity.BomQty = dto.BomQty; + resEntity.sort = dto.Sort; + var res = await SqlSugarDb.Db.Insertable(resEntity).CallEntityMethod(m => m.Create()).ExecuteCommandAsync(); + return res > 0; + } + catch (Exception) + { + throw Oops.Oh(ErrorCodeEnum.Code1007); + } + } + private string GetNumber2(int Length = 10) + { + byte[] buffer = Guid.NewGuid().ToByteArray(); + var ram = BitConverter.ToInt64(buffer, 0); + var str = string.Format("{0}", ram.ToString().Substring(0, Length)); + return str; + } + } +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Bom/Services/IBomService.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Bom/Services/IBomService.cs new file mode 100644 index 0000000..a533b2c --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Bom/Services/IBomService.cs @@ -0,0 +1,52 @@ +using BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto; +using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Bom.Dtos; +using BPA.SAAS.Manage.Application.DataBase.Dtos.Bom; +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.AExternalPlatform.Service.Bom.Services +{ + public interface IBomService + { + /// + /// 分页查询 + /// + /// + /// + public async Task>> GetBomPageList(BomPageInputDto inputDto); + /// + /// 添加 + /// + /// + /// + public async Task AddBom(BaseRequestDto dto); + /// + /// 更新 + /// + /// + /// + public async Task UpdateBom(BaseRequestDto dto); + /// + /// 删除 + /// + /// + /// + public async Task DeleteBom(string[] ids); + /// + /// 根据配方id查询配方详情 + /// + /// + /// + public async Task GetBomEntry(string bomId); + /// + /// 添加配方详情 + /// + /// + /// + public async Task AddBomEntry(BomEntryInsertDto dto); + } +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/DeviceServices.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/DeviceServices.cs index 6b5e97f..9a4a8d3 100644 --- a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/DeviceServices.cs +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/DeviceServices.cs @@ -1,4 +1,5 @@ -using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Device.Dtos; +using BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto; +using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Device.Dtos; using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Device.Services; using BPA.SAAS.Manage.Core.Base; using Microsoft.AspNetCore.Components.Forms; diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Services/DeviceService.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Services/DeviceService.cs index c424657..8c0f0c2 100644 --- a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Services/DeviceService.cs +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Services/DeviceService.cs @@ -12,6 +12,7 @@ using BPA.SAAS.Manage.Core.Product; using Furion.DependencyInjection; using Furion.RemoteRequest.Extensions; using Newtonsoft.Json; +using SqlSugar; using System; using System.Collections.Generic; using System.Linq; @@ -66,12 +67,17 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Device.Services resEntity.StopId = dto.StopId; resEntity.ProductId = dto.ProductId; resEntity.ProductVersionId = dto.ProductVersionId; - if (string.IsNullOrWhiteSpace(dto.ProductCode)) + var check = SqlSugarDb.Db.Queryable().Where(x => x.Name == dto.ProductCode).First(); + if (check != null) + { + resEntity.DeviceTypeId = check.Id; + } + else { - var check = SqlSugarDb.Db.Queryable().Where(x => x.Name == "默认标签").First(); - if (check != null) + var check1 = SqlSugarDb.Db.Queryable().Where(x => x.Name == "默认标签").First(); + if (check1 != null) { - resEntity.DeviceTypeId = check.Id; + resEntity.DeviceTypeId = check1.Id; } else { @@ -105,7 +111,7 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Device.Services resEntity.ProductVersionId = dto.ProductVersionId; if (!string.IsNullOrWhiteSpace(dto.ProductCode)) { - var check = SqlSugarDb.Db.Queryable().Where(x => x.Id == dto.ProductCode).First(); + var check = SqlSugarDb.Db.Queryable().Where(x => x.Name == dto.ProductCode).First(); if (check != null) { resEntity.DeviceTypeId = check.Id; diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Services/IDeviceService.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Services/IDeviceService.cs index 031584a..ee866b5 100644 --- a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Services/IDeviceService.cs +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Services/IDeviceService.cs @@ -1,4 +1,5 @@ using BPA.KitChen.GroupMeal.SqlSugar; +using BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto; using BPA.SAAS.Manage.Application.AExternalPlatform.Enum; using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Device.Dtos; using BPA.SAAS.Manage.Core.Base; diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsAttributeVewDto.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsAttributeVewDto.cs new file mode 100644 index 0000000..3476a17 --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsAttributeVewDto.cs @@ -0,0 +1,24 @@ +using BPA.SAAS.Manage.Core.DataBase; +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 GoodsAttributeVewDto + { + public string Id { get; set; } + /// + /// 属性名称 + /// + public string AttributeName { get; set; } + /// + /// 商品小类id + /// + public string GoodsTypeId { get; set; } + public List AttributeValueList { get; set; } + public int Sort { get; set; } + } +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsAttributeinsertDto.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsAttributeinsertDto.cs new file mode 100644 index 0000000..7a307c3 --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsAttributeinsertDto.cs @@ -0,0 +1,34 @@ +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 GoodsAttributeinsertDto + { + /// + /// 属性名称 + /// + public string AttributeName { get; set; } + /// + /// 商品分类 + /// + public string GoodsTypeName { get; set; } + public List GoodsAttributeValue { get; set; } + } + public class GoodsAttributeValue + { + public string Id { get; set; } + /// + ///商品属性id + /// + public string GoodsAttributeId { get; set; } + /// + /// 属性值 + /// + public string AttributeValue { get; set; } + public int Sort { get; set; } + } +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsDto.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsDto.cs index 5443815..4d738e1 100644 --- a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsDto.cs +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsDto.cs @@ -1,4 +1,5 @@ -using BPA.SAAS.Manage.Core.DataBase; +using BPA.SAAS.Manage.Comm.Enum; +using BPA.SAAS.Manage.Core.DataBase; using System; using System.Collections.Generic; using System.Linq; @@ -7,8 +8,17 @@ using System.Threading.Tasks; namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods.Dtos { - public class GoodsDto:BPA_GoodsInfo + public class GoodsDto { + public string Id { get; set; } + public string Name { get; set; } + public string Descritption { get; set; } + public string ImgUrl { get; set; } + public string Code { get; set; } + public decimal Price { get; set; } + public string GoodsUintId { get; set; } + public string GoodsTypeId { get; set; } + public string GroupId { get; set; } public string GoodsTypeName { get; set; } public string GoodsUnitName { get; set; } } diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsInsertDto.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsInsertDto.cs index 621a735..1557f9d 100644 --- a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsInsertDto.cs +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsInsertDto.cs @@ -31,10 +31,10 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods.Dtos /// /// 商品分类id /// - public string GoodsTypeId { get; set; } + public string GoodsTypeName { get; set; } /// /// 商品单位id /// - public string GoodsUintId { get; set; } + public string GoodsUintName { get; set; } } } diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsTechnologyActionListViewDto.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsTechnologyActionListViewDto.cs new file mode 100644 index 0000000..72391dc --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsTechnologyActionListViewDto.cs @@ -0,0 +1,49 @@ +using BPA.SAAS.Manage.Application.DataBase.Dtos.GoodsTechnology; +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 GoodsTechnologyActionListViewDto + { + public string DeviceId { get; set; } + public string WarehousrTemplateId { get; set; } + public string GoodsAttributeId { get; set; } + public string DeviceName { get; set; } + public List Data { get; set; } + } + public class GoodsTechnologyActionViewDto + { + public string Id { get; set; } + /// + /// 步骤名称 + /// + public string StepName { get; set; } + /// + /// 动作json + /// + public string ActionJson { get; set; } + /// + /// 商品属性id集合 + /// + public string GoodsAttributeId { get; set; } + /// + /// 是否物料 + /// + public bool IsBatch { get; set; } + /// + /// 动作value + /// + public string ChnologyId { get; set; } + public DateTime CreateAt { get; set; } + public string GroupId { get; set; } + public int IsDeleted { get; set; } + public int Sort { get; set; } + public string GoodsId { get; set; } + public string DeviceId { get; set; } + public string WarehousrTemplateId { 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 d96f531..cc8b612 100644 --- a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/GoodsServices.cs +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/GoodsServices.cs @@ -1,8 +1,10 @@ -using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods.Dtos; +using BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto; +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.Core.Base; using Microsoft.AspNetCore.Components.Forms; +using Org.BouncyCastle.Crypto; using System; using System.Collections.Generic; using System.Linq; @@ -36,7 +38,7 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods /// /// [HttpPost("/api/ExternalPlatform/Goods/AddGoods")] - public async Task AddGoods(GoodsInsertDto dto) + public async Task AddGoods(BaseRequestDto dto) { return await _goodsService.AddGoods(dto); } @@ -46,7 +48,7 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods /// /// [HttpPost("/api/ExternalPlatform/Goods/UpdateGoods")] - public async Task UpdateGoods(GoodsUpdateDto dto) + public async Task UpdateGoods(BaseRequestDto dto) { return await _goodsService.UpdateGoods(dto); } @@ -60,5 +62,44 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods { return await _goodsService.DeleteGoods(ids); } + /// + ///添加商品属性 + /// + /// + /// + [HttpPost("/api/ExternalPlatform/Goods/AddGoodsAttribute")] + public async Task AddGoodsAttribute(GoodsAttributeinsertDto dto) + { + return await _goodsService.AddGoodsAttribute(dto); + } + /// + /// 查询商品属性 + /// + /// + [HttpGet("/api/ExternalPlatform/Goods/GetGoodsAttributeList")] + public async Task> GetGoodsAttributeList() + { + return await _goodsService.GetGoodsAttributeList(); + } + /// + /// 查询商品工艺 + /// + /// + /// + [HttpGet("/api/ExternalPlatform/Goods/GetGoodsTechnologyAction")] + public async Task> GetGoodsTechnologyAction(string goodsId) + { + return await _goodsService.GetGoodsTechnologyAction(goodsId); + } + /// + /// 删除商品工艺 + /// + /// + /// + [HttpGet("/api/ExternalPlatform/Goods/DeleteGoodsTechnologyAction")] + public async Task DeleteGoodsTechnologyAction(string id) + { + return await _goodsService.DeleteGoodsTechnologyAction(id); + } } } 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 d07358a..dfbd7b0 100644 --- a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Services/GoodsService.cs +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Services/GoodsService.cs @@ -2,18 +2,10 @@ using BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto; using BPA.SAAS.Manage.Application.AExternalPlatform.Enum; using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods.Dtos; -using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Material.Dtos; -using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Material.Services; -using BPA.SAAS.Manage.Application.DataBase.Interface; -using BPA.SAAS.Manage.Comm.Enum; +using BPA.SAAS.Manage.Application.DataBase.Dtos.GoodsTechnology; using BPA.SAAS.Manage.Core.Base; using BPA.SAAS.Manage.Core.DataBase; -using Org.BouncyCastle.Crypto; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using BPA.SAAS.Manage.Core.Device; namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods.Services { @@ -55,45 +47,56 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods.Services /// /// /// - public async Task AddGoods(GoodsInsertDto dto) + public async Task AddGoods(BaseRequestDto dto) { try { SqlSugarDb.Db.BeginTran(); var resEntity = new BPA_GoodsInfo(); - resEntity.GoodsTypeId = dto.GoodsTypeId; - resEntity.GoodsUintId = dto.GoodsUintId; - if (string.IsNullOrWhiteSpace(dto.GoodsTypeId)) + //resEntity.GoodsTypeId = dto.DataInfo.GoodsTypeName; + //resEntity.GoodsUintId = dto.DataInfo.GoodsUintName; + var check = SqlSugarDb.Db.Queryable().Where(x => x.Name == dto.DataInfo.GoodsTypeName).First(); + if (check != null) { - var check=SqlSugarDb.Db.Queryable().Where(x => x.Name == "默认分类").First(); - if (check!=null) + resEntity.GoodsTypeId = check.Id; + } + else + { + var check1 = SqlSugarDb.Db.Queryable().Where(x => x.Name == "默认分类").First(); + if (check1 != null) { - resEntity.GoodsTypeId = check.Id; + resEntity.GoodsTypeId = check1.Id; } else { - var GoodsType=await SqlSugarDb.Db.Insertable(new BPA_GoodsType() { Pid="",Name= "默认分类" }).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync(); + var GoodsType = await SqlSugarDb.Db.Insertable(new BPA_GoodsType() { Pid = "", Name = "默认分类" }).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync(); resEntity.GoodsTypeId = GoodsType.Id; } + + } + var checkUint = SqlSugarDb.Db.Queryable().Where(x => x.Name == dto.DataInfo.GoodsUintName).First(); + if (checkUint != null) + { + resEntity.GoodsUintId = checkUint.Id; } - if (string.IsNullOrWhiteSpace(dto.GoodsUintId)) + else { - var check = SqlSugarDb.Db.Queryable().Where(x => x.Name == "默认单位").First(); - if (check != null) + var checkUint1 = SqlSugarDb.Db.Queryable().Where(x => x.Name == dto.DataInfo.GoodsUintName).First(); + if (checkUint1 != null) { - resEntity.GoodsTypeId = check.Id; + resEntity.GoodsUintId = checkUint1.Id; } else { - var GoodsUint = await SqlSugarDb.Db.Insertable(new BPA_GoodsUint() {Name = "默认单位" }).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync(); + var GoodsUint = await SqlSugarDb.Db.Insertable(new BPA_GoodsUint() { Name = "默认单位" }).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync(); resEntity.GoodsUintId = GoodsUint.Id; } } - resEntity.Name = dto.Name; - resEntity.Descritption = dto.Descritption; - resEntity.ImgUrl = dto.ImgUrl; - resEntity.Price = dto.Price; - resEntity.IsWeigh = dto.IsWeigh; + resEntity.Name = dto.DataInfo.Name; + resEntity.Descritption = dto.DataInfo.Descritption; + resEntity.ImgUrl = dto.DataInfo.ImgUrl; + resEntity.Price = dto.DataInfo.Price; + resEntity.IsWeigh = dto.DataInfo.IsWeigh; resEntity.IsAttrubute = true; resEntity.Code = GetNumber2(8); @@ -113,21 +116,21 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods.Services /// /// /// - public async Task UpdateGoods(GoodsUpdateDto dto) + public async Task UpdateGoods(BaseRequestDto dto) { // 查询数据库中是否存在未删除的商品类型 - var resEntity = SqlSugarDb.Db.Queryable().Where(it => it.IsDeleted == 0).First(it => it.Id == dto.Id); + var resEntity = SqlSugarDb.Db.Queryable().Where(it => it.IsDeleted == 0).First(it => it.Id == dto.DataInfo.Id); if (null == resEntity) { throw Oops.Oh(ErrorCodeEnum.Code1008); } - resEntity.GoodsTypeId = dto.GoodsTypeId; - resEntity.Name = dto.Name; - resEntity.Descritption = dto.Descritption; - resEntity.ImgUrl = dto.ImgUrl; - resEntity.Price = dto.Price; - resEntity.IsWeigh = dto.IsWeigh; - resEntity.GoodsUintId = dto.GoodsUintId; + resEntity.GoodsTypeId = dto.DataInfo.GoodsTypeId; + resEntity.Name = dto.DataInfo.Name; + resEntity.Descritption = dto.DataInfo.Descritption; + resEntity.ImgUrl = dto.DataInfo.ImgUrl; + resEntity.Price = dto.DataInfo.Price; + resEntity.IsWeigh = dto.DataInfo.IsWeigh; + resEntity.GoodsUintId = dto.DataInfo.GoodsUintId; var res = await SqlSugarDb.Db.Updateable(resEntity).ExecuteCommandAsync(); return res > 0; @@ -159,6 +162,146 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods.Services } } + /// + ///添加商品属性 + /// + /// + /// + public async Task AddGoodsAttribute(GoodsAttributeinsertDto dto) + { + try + { + SqlSugarDb.Db.BeginTran(); + BPA_GoodsAttribute _GoodsAttribute = new(); + _GoodsAttribute.Id = Guid.NewGuid().ToString(); + _GoodsAttribute.AttributeName = dto.AttributeName; + var GoodsType = SqlSugarDb.Db.Queryable().Where(x => x.Name == dto.GoodsTypeName).First(); + if (GoodsType == null) + { + var resGoodsType = await SqlSugarDb.Db.Insertable(new BPA_GoodsType() { Pid = "", Name = "默认分类" }).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync(); + _GoodsAttribute.GoodsTypeId = resGoodsType.Id; + } + else + { + _GoodsAttribute.GoodsTypeId = GoodsType.Id; + } + var res = await SqlSugarDb.Db.Insertable(_GoodsAttribute).ExecuteCommandAsync(); + List GoodsAttributeValueList = new(); + if (dto.GoodsAttributeValue.Count > 0) + { + SqlSugarDb.Db.Deleteable().Where(x => x.GoodsAttributeId == _GoodsAttribute.Id).ExecuteCommand(); + for (int i = 0; i < dto.GoodsAttributeValue.Count; i++) + { + BPA_GoodsAttributeValue _GoodsAttributeValue = new(); + _GoodsAttributeValue.GoodsAttributeId = _GoodsAttribute.Id; + _GoodsAttributeValue.AttributeValue = dto.GoodsAttributeValue[i].AttributeValue; + _GoodsAttributeValue.Sort = dto.GoodsAttributeValue[i].Sort; + GoodsAttributeValueList.Add(_GoodsAttributeValue); + } + SqlSugarDb.Db.Insertable(GoodsAttributeValueList).ExecuteCommand(); + } + SqlSugarDb.Db.CommitTran(); + return res > 0; + } + catch (Exception) + { + SqlSugarDb.Db.RollbackTran(); + throw Oops.Oh(ErrorCodeEnum.Code1007); + throw; + } + + } + /// + /// 查询商品属性 + /// + /// + public async Task> GetGoodsAttributeList() + { + var res = await SqlSugarDb.Db.Queryable() + .OrderBy(a => a.CreateAt, OrderByType.Desc) + .Select(a => new GoodsAttributeVewDto + { + Id = a.Id, + AttributeName = a.AttributeName, + GoodsTypeId = a.GoodsTypeId, + Sort = a.Sort, + }) + .Mapper(x => + { + var list = SqlSugarDb.Db.Queryable().Where(p => p.GoodsAttributeId == x.Id).Select(x=>new GoodsAttributeValue() { AttributeValue=x.AttributeValue,Id=x.Id, GoodsAttributeId =x.GoodsAttributeId}).ToList(); + x.AttributeValueList = list; + }) + .ToListAsync(); + return res; + } + /// + /// 查询商品工艺 + /// + /// + /// + public async Task> GetGoodsTechnologyAction(string goodsId) + { + List goodsTechnologyActionListViews = new List(); + var list = SqlSugarDb.Db.Queryable().Where(x => x.GoodsId == goodsId) + .Select(x => new GoodsTechnologyActionViewDto() + { + Id = x.Id.SelectAll(), + }).OrderBy(x => x.Sort, OrderByType.Asc).ToList(); + var Devicelist = await SqlSugarDb.Db.Queryable().ToListAsync(); + var GoodsAttributeValue = await SqlSugarDb.Db.Queryable().ToListAsync(); + var sf = list.GroupBy(x => x.GoodsAttributeId).ToList(); + var sf1 = list.GroupBy(x => x.WarehousrTemplateId).ToList(); + for (int i = 0; i < sf.Count; i++) + { + var sd = GoodsAttributeValue?.Where(x => sf[i].Key.Contains(x.Id)).Select(x => x.AttributeValue).ToArray(); + var sdw = GoodsAttributeValue?.Where(x => sf[i].Key.Contains(x.Id)).Select(x => x.Id).ToArray(); + var nane = string.Join('-', sd); + var s = sf[i].AsQueryable().ToList().GroupBy(x => x.DeviceId).ToList(); + for (int t = 0; t < s.Count; t++) + { + GoodsTechnologyActionListViewDto item = new() + { + DeviceId = s[t].Key, + WarehousrTemplateId = sf1[t].Key, + GoodsAttributeId = string.Join(',', sdw), + DeviceName = Devicelist?.FirstOrDefault(x => x.Id == s[t].Key).DeviceName + "【" + nane + "】", + Data = s[t].AsQueryable().ToList(), + }; + goodsTechnologyActionListViews.Add(item); + } + } + + return goodsTechnologyActionListViews; + } + /// + /// 删除商品工艺 + /// + /// + /// + public async Task DeleteGoodsTechnologyAction(string id) + { + var item = await SqlSugarDb.Db.Queryable().Where(x => x.Id == id).FirstAsync(); + if (item != null) + { + var res = await SqlSugarDb.Db.Deleteable(item).ExecuteCommandAsync() > 0; + var list = SqlSugarDb.Db.Queryable().Where(x => x.GoodsId == item.GoodsId && x.DeviceId == item.DeviceId).OrderBy(x => x.Sort, OrderByType.Asc).ToList(); + var uplist = new List(); + for (int i = 0; i < list.Count; i++) + { + list[i].Sort = i + 1; + uplist.Add(list[i]); + } + if (uplist.Count > 0) + { + await SqlSugarDb.Db.Updateable(uplist).ExecuteCommandAsync(); + } + return true; + } + else + { + throw Oops.Oh("找不到相关数据,删除失败"); + } + } 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 6c09779..2a7ade6 100644 --- a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Services/IGoodsService.cs +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Services/IGoodsService.cs @@ -1,4 +1,5 @@ -using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods.Dtos; +using BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto; +using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods.Dtos; using BPA.SAAS.Manage.Core.Base; using System; using System.Collections.Generic; @@ -21,18 +22,41 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods.Services /// /// /// - Task AddGoods(GoodsInsertDto dto); + Task AddGoods(BaseRequestDto dto); /// /// 更新商品 /// /// /// - Task UpdateGoods(GoodsUpdateDto dto); + Task UpdateGoods(BaseRequestDto dto); /// /// 删除商品 /// /// /// Task DeleteGoods(string[] ids); + /// + ///添加商品属性 + /// + /// + /// + Task AddGoodsAttribute(GoodsAttributeinsertDto dto); + /// + /// 查询商品属性 + /// + /// + Task> GetGoodsAttributeList(); + /// + /// 查询商品工艺 + /// + /// + /// + Task> GetGoodsTechnologyAction(string goodsId); + /// + /// 删除商品工艺 + /// + /// + /// + Task DeleteGoodsTechnologyAction(string id); } } diff --git a/BPA.SAAS.Manage.Application/BPA.SAAS.Manage.Application.csproj b/BPA.SAAS.Manage.Application/BPA.SAAS.Manage.Application.csproj index 6e8a2cf..0361b47 100644 --- a/BPA.SAAS.Manage.Application/BPA.SAAS.Manage.Application.csproj +++ b/BPA.SAAS.Manage.Application/BPA.SAAS.Manage.Application.csproj @@ -30,4 +30,8 @@ + + + + diff --git a/BPA.SAAS.Manage.Web.Entry/Properties/launchSettings.json b/BPA.SAAS.Manage.Web.Entry/Properties/launchSettings.json index d0f1177..9571557 100644 --- a/BPA.SAAS.Manage.Web.Entry/Properties/launchSettings.json +++ b/BPA.SAAS.Manage.Web.Entry/Properties/launchSettings.json @@ -14,7 +14,7 @@ "ASPNETCORE_ENVIRONMENT": "Development" }, "dotnetRunMessages": true, - "applicationUrl": "http://localhost:5009" + "applicationUrl": "http://localhost:5006" }, "Docker": { "commandName": "Docker", diff --git a/BPA.SAAS.Manage.Web.Entry/appsettings.json b/BPA.SAAS.Manage.Web.Entry/appsettings.json index e4afa70..029e773 100644 --- a/BPA.SAAS.Manage.Web.Entry/appsettings.json +++ b/BPA.SAAS.Manage.Web.Entry/appsettings.json @@ -8,7 +8,7 @@ } }, "AllowedHosts": "*", - "baseurl": "http://localhost:5007/", + "baseurl": "http://localhost:5008/", "ConnectionConfigs": [ { "ConnectionString": "server=10.2.1.21;Database=bpa_kitchen_kitchenbasemanage;Uid=root;Pwd=cygadmin;Allow Zero Datetime=True;Convert Zero Datetime=True;",