From 5413f9c92be9d6f69da68182efb076b2f9f8efa0 Mon Sep 17 00:00:00 2001 From: zhaoy <137053305@qq.com> Date: Fri, 1 Mar 2024 16:35:55 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=89=E6=96=B9=E5=95=86=E5=93=81?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AExternalPlatform/Enum/ErrorCodeEnum.cs | 10 ++ .../CheckService/Services/CheckServices.cs | 3 +- .../Service/Goods/Dtos/GoodsDto.cs | 15 ++ .../Service/Goods/Dtos/GoodsInsertDto.cs | 40 +++++ .../Service/Goods/Dtos/GoodsPageInputDto.cs | 57 ++++++ .../Service/Goods/Dtos/GoodsUpdateDto.cs | 41 +++++ .../Service/Goods/GoodsServices.cs | 64 +++++++ .../Service/Goods/Services/GoodsService.cs | 170 ++++++++++++++++++ .../Service/Goods/Services/IGoodsService.cs | 38 ++++ .../Properties/launchSettings.json | 2 +- BPA.SAAS.Manage.Web.Entry/appsettings.json | 2 +- 11 files changed, 438 insertions(+), 4 deletions(-) create mode 100644 BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsDto.cs create mode 100644 BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsInsertDto.cs create mode 100644 BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsPageInputDto.cs create mode 100644 BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsUpdateDto.cs create mode 100644 BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/GoodsServices.cs create mode 100644 BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Services/GoodsService.cs create mode 100644 BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Services/IGoodsService.cs diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Enum/ErrorCodeEnum.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Enum/ErrorCodeEnum.cs index 5b0a505..ad4ab37 100644 --- a/BPA.SAAS.Manage.Application/AExternalPlatform/Enum/ErrorCodeEnum.cs +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Enum/ErrorCodeEnum.cs @@ -55,5 +55,15 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Enum /// [ErrorCodeItemMetadata("签名过期")] Code1006, + /// + /// 系统异常 + /// + [ErrorCodeItemMetadata("系统异常")] + Code1007, + /// + /// 商品不存在 + /// + [ErrorCodeItemMetadata("商品不存在")] + Code1008, } } diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/CheckService/Services/CheckServices.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/CheckService/Services/CheckServices.cs index 6800027..c456ea2 100644 --- a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/CheckService/Services/CheckServices.cs +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/CheckService/Services/CheckServices.cs @@ -47,12 +47,11 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.CheckService.Ser var data = await SqlSugarDb.Db.Queryable() .ClearFilter() .FirstAsync(x => x.Key == key); - await CheckTenant(data.GroupId); if (data == null) { throw Oops.Oh(ErrorCodeEnum.Code1004); } - + await CheckTenant(data.GroupId); } /// diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsDto.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsDto.cs new file mode 100644 index 0000000..5443815 --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsDto.cs @@ -0,0 +1,15 @@ +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 GoodsDto:BPA_GoodsInfo + { + 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 new file mode 100644 index 0000000..621a735 --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsInsertDto.cs @@ -0,0 +1,40 @@ +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 GoodsInsertDto + { + /// + /// 商品名称 + /// + public string Name { get; set; } + /// + /// 描述 + /// + public string Descritption { get; set; } + /// + /// 图片 + /// + public string ImgUrl { get; set; } + /// + /// 价格 + /// + public decimal Price { get; set; } + /// + /// 是否称重 + /// + public bool IsWeigh { get; set; } + /// + /// 商品分类id + /// + public string GoodsTypeId { get; set; } + /// + /// 商品单位id + /// + public string GoodsUintId { get; set; } + } +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsPageInputDto.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsPageInputDto.cs new file mode 100644 index 0000000..d700d38 --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsPageInputDto.cs @@ -0,0 +1,57 @@ +using BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto; +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.Goods.Dtos +{ + public class GoodsPageInputDto + { + public string GoodsTypeName { get; set; } + /// + /// 当前页码 + /// + private int current; + public virtual int Current + { + get + { + return current; + } + set + { + + current = value; + if (current <= 0) + { + current = 1; + } + } + } + //public int? Status { get; set; } + /// + /// 页码容量 + /// + + private int pagesize; + public virtual int PageSize + { + get + { + return pagesize; + } + set + { + + pagesize = value; + if (pagesize <= 0) + { + pagesize = 10; + } + } + } + } +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsUpdateDto.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsUpdateDto.cs new file mode 100644 index 0000000..933744e --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Dtos/GoodsUpdateDto.cs @@ -0,0 +1,41 @@ +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 GoodsUpdateDto + { + public string Id { get; set; } + /// + /// 商品名称 + /// + public string Name { get; set; } + /// + /// 描述 + /// + public string Descritption { get; set; } + /// + /// 图片 + /// + public string ImgUrl { get; set; } + /// + /// 价格 + /// + public decimal Price { get; set; } + /// + /// 是否称重 + /// + public bool IsWeigh { get; set; } + /// + /// 商品分类id + /// + public string GoodsTypeId { get; set; } + /// + /// 商品单位id + /// + public string GoodsUintId { get; set; } + } +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/GoodsServices.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/GoodsServices.cs new file mode 100644 index 0000000..d96f531 --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/GoodsServices.cs @@ -0,0 +1,64 @@ +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 System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods +{ + [ApiDescriptionSettings("开放平台", Tag = "商品管理"), AllowAnonymous] + public class GoodsServices: IDynamicApiController + { + private readonly IGoodsService _goodsService; + public GoodsServices(IGoodsService goodsService) + { + _goodsService = goodsService; + } + + /// + /// 分页查询商品 + /// + /// + /// + [HttpPost("/api/ExternalPlatform/Goods/GetGoodsPageList")] + public async Task>> GetGoodsPageList(GoodsPageInputDto inputDto) + { + return await _goodsService.GetGoodsPageList(inputDto); + } + /// + /// 添加商品 + /// + /// + /// + [HttpPost("/api/ExternalPlatform/Goods/AddGoods")] + public async Task AddGoods(GoodsInsertDto dto) + { + return await _goodsService.AddGoods(dto); + } + /// + /// 更新商品 + /// + /// + /// + [HttpPost("/api/ExternalPlatform/Goods/UpdateGoods")] + public async Task UpdateGoods(GoodsUpdateDto dto) + { + return await _goodsService.UpdateGoods(dto); + } + /// + /// 删除商品 + /// + /// + /// + [HttpPost("/api/ExternalPlatform/Goods/DeleteGoods")] + public async Task DeleteGoods(string[] ids) + { + return await _goodsService.DeleteGoods(ids); + } + } +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Services/GoodsService.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Services/GoodsService.cs new file mode 100644 index 0000000..b081efe --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Services/GoodsService.cs @@ -0,0 +1,170 @@ +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.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.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; + +namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods.Services +{ + public class GoodsService: UserAnalysis, IGoodsService, ITransient + { + public GoodsService() + { + + } + /// + /// 分页查询商品 + /// + /// + /// + public async Task>> GetGoodsPageList(GoodsPageInputDto inputDto) + { + int total = new RefAsync(); + var data = SqlSugarDb.Db.Queryable((a, b, c) => + new JoinQueryInfos(JoinType.Left, a.GoodsTypeId == b.Id, + JoinType.Left, a.GoodsUintId == c.Id)) + .Where((a, b, c) => a.IsDeleted == 0) + .WhereIF(!string.IsNullOrEmpty(inputDto.GoodsTypeName), (a, b, c) => b.Name.Contains(inputDto.GoodsTypeName)) + .Select((a, b, c) => new GoodsDto() + { + Id =a.Id.SelectAll() , + GoodsTypeName=b.Name, + GoodsUnitName=c.Name + + }).ToPageList(inputDto.Current, inputDto.PageSize, ref total); + + return new PageUtil>() + { + Total = total, + Data = data + }; + } + /// + /// 添加商品 + /// + /// + /// + public async Task AddGoods(GoodsInsertDto dto) + { + try + { + SqlSugarDb.Db.BeginTran(); + var resEntity = new BPA_GoodsInfo(); + resEntity.GoodsTypeId = dto.GoodsTypeId; + resEntity.GoodsUintId = dto.GoodsUintId; + if (string.IsNullOrWhiteSpace(dto.GoodsTypeId)) + { + var check=SqlSugarDb.Db.Queryable().Where(x => x.Name == "默认分类").First(); + if (check!=null) + { + resEntity.GoodsTypeId = check.Id; + } + else + { + var GoodsType=await SqlSugarDb.Db.Insertable(new BPA_GoodsType() { Pid="",Name= "默认分类" }).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync(); + resEntity.GoodsTypeId = GoodsType.Id; + } + } + if (string.IsNullOrWhiteSpace(dto.GoodsUintId)) + { + var check = SqlSugarDb.Db.Queryable().Where(x => x.Name == "默认单位").First(); + if (check != null) + { + resEntity.GoodsTypeId = check.Id; + } + else + { + 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.IsAttrubute = true; + resEntity.Code = GetNumber2(8); + var res = await SqlSugarDb.Db.Insertable(resEntity).CallEntityMethod(m => m.Create()).ExecuteCommandAsync(); + SqlSugarDb.Db.CommitTran(); + return res > 0; + } + catch (Exception) + { + SqlSugarDb.Db.RollbackTran(); + throw Oops.Oh(ErrorCodeEnum.Code1007); + } + + } + /// + /// 更新商品 + /// + /// + /// + public async Task UpdateGoods(GoodsUpdateDto dto) + { + // 查询数据库中是否存在未删除的商品类型 + var resEntity = SqlSugarDb.Db.Queryable().Where(it => it.IsDeleted == 0).First(it => it.Id == dto.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; + + var res = await SqlSugarDb.Db.Updateable(resEntity).ExecuteCommandAsync(); + return res > 0; + } + /// + /// 删除商品 + /// + /// + /// + public async Task DeleteGoods(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.Code1008); + var goodsbom = SqlSugarDb.Db.Queryable().Where(x => ids.Contains( x.Goods_Id)).ToList(); + var goodsTechnology = SqlSugarDb.Db.Queryable().Where(x => ids.Contains(x.GoodsId)).ToList(); + await SqlSugarDb.Db.Deleteable(goodsbom).ExecuteCommandAsync(); + await SqlSugarDb.Db.Deleteable(goodsTechnology).ExecuteCommandAsync(); + var res = await SqlSugarDb.Db.Deleteable(goods).ExecuteCommandAsync(); + SqlSugarDb.Db.CommitTran(); + return res > 0; + } + catch (Exception) + { + SqlSugarDb.Db.RollbackTran(); + throw Oops.Oh("删除失败"); + } + + } + 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/Goods/Services/IGoodsService.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Services/IGoodsService.cs new file mode 100644 index 0000000..6c09779 --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Goods/Services/IGoodsService.cs @@ -0,0 +1,38 @@ +using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Goods.Dtos; +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.Goods.Services +{ + public interface IGoodsService + { + /// + /// 分页查询商品 + /// + /// + /// + Task>> GetGoodsPageList(GoodsPageInputDto inputDto); + /// + /// 添加商品 + /// + /// + /// + Task AddGoods(GoodsInsertDto dto); + /// + /// 更新商品 + /// + /// + /// + Task UpdateGoods(GoodsUpdateDto dto); + /// + /// 删除商品 + /// + /// + /// + Task DeleteGoods(string[] ids); + } +} diff --git a/BPA.SAAS.Manage.Web.Entry/Properties/launchSettings.json b/BPA.SAAS.Manage.Web.Entry/Properties/launchSettings.json index 9571557..d0f1177 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:5006" + "applicationUrl": "http://localhost:5009" }, "Docker": { "commandName": "Docker", diff --git a/BPA.SAAS.Manage.Web.Entry/appsettings.json b/BPA.SAAS.Manage.Web.Entry/appsettings.json index 38a40c9..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://192.168.1.19:5008/", + "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;",