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 1/3] =?UTF-8?q?=E7=AC=AC=E4=B8=89=E6=96=B9=E5=95=86?= =?UTF-8?q?=E5=93=81=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;", From 652df5616ffcfed3bb2b7105601cc188c08827c5 Mon Sep 17 00:00:00 2001 From: zhaoy <137053305@qq.com> Date: Fri, 1 Mar 2024 17:55:42 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E7=AC=AC=E4=B8=89=E6=96=B9=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=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 | 26 +++ .../Service/Device/DeviceServices.cs | 62 ++++++ .../Service/Device/Dtos/DeviceDto.cs | 15 ++ .../Service/Device/Dtos/DeviceInsertDto.cs | 38 ++++ .../Service/Device/Dtos/DevicePageInputDto.cs | 56 ++++++ .../Service/Device/Dtos/DeviceUpateDto.cs | 38 ++++ .../Service/Device/Services/DeviceService.cs | 181 ++++++++++++++++++ .../Service/Device/Services/IDeviceService.cs | 41 ++++ BPA.SAAS.Manage.Web.Entry/appsettings.json | 2 +- 9 files changed, 458 insertions(+), 1 deletion(-) create mode 100644 BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/DeviceServices.cs create mode 100644 BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Dtos/DeviceDto.cs create mode 100644 BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Dtos/DeviceInsertDto.cs create mode 100644 BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Dtos/DevicePageInputDto.cs create mode 100644 BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Dtos/DeviceUpateDto.cs create mode 100644 BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Services/DeviceService.cs create mode 100644 BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Services/IDeviceService.cs diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Enum/ErrorCodeEnum.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Enum/ErrorCodeEnum.cs index ad4ab37..8a1c24e 100644 --- a/BPA.SAAS.Manage.Application/AExternalPlatform/Enum/ErrorCodeEnum.cs +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Enum/ErrorCodeEnum.cs @@ -65,5 +65,31 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Enum /// [ErrorCodeItemMetadata("商品不存在")] Code1008, + /// + /// 场景id不能为空 + /// + [ErrorCodeItemMetadata("场景id不能为空")] + Code1009, + /// + /// 产品不存在 + /// + [ErrorCodeItemMetadata("产品不存在")] + Code10010, + /// + /// 产品版本不存在 + /// + [ErrorCodeItemMetadata("产品版本不存在")] + Code10011, + /// + /// 设备不存在 + /// + [ErrorCodeItemMetadata("设备不存在")] + Code10012, + /// + /// 产品标签不存在 + /// + [ErrorCodeItemMetadata("产品标签不存在")] + Code10013, + } } diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/DeviceServices.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/DeviceServices.cs new file mode 100644 index 0000000..6b5e97f --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/DeviceServices.cs @@ -0,0 +1,62 @@ +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; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Device +{ + [ApiDescriptionSettings("开放平台", Tag = "设备管理"), AllowAnonymous] + public class DeviceServices:IDynamicApiController + { + IDeviceService _deviceService; + public DeviceServices(IDeviceService deviceService) + { + _deviceService= deviceService; + } + /// + /// 分页查询 + /// + /// + /// + [HttpPost("/api/ExternalPlatform/Device/GetDevicePageList")] + public async Task>> GetDevicePageList(DevicePageInputDto inputDto) + { + return await _deviceService.GetDevicePageList(inputDto); + } + /// + /// 添加 + /// + /// + /// + [HttpPost("/api/ExternalPlatform/Device/AddDevice")] + public async Task AddDevice(DeviceInsertDto dto) + { + return await _deviceService.AddDevice(dto); + } + /// + /// 更新 + /// + /// + /// + [HttpPost("/api/ExternalPlatform/Device/UpdateDevice")] + public async Task UpdateDevice(DeviceUpateDto dto) + { + return await _deviceService.UpdateDevice(dto); + } + /// + /// 删除 + /// + /// + /// + [HttpPost("/api/ExternalPlatform/Device/DeleteDevice")] + public async Task DeleteDevice(string[] ids) + { + return await _deviceService.DeleteDevice(ids); + } + } +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Dtos/DeviceDto.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Dtos/DeviceDto.cs new file mode 100644 index 0000000..5900ad1 --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Dtos/DeviceDto.cs @@ -0,0 +1,15 @@ +using BPA.SAAS.Manage.Core.Device; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Device.Dtos +{ + public class DeviceDto: BPA_DeviceInfo + { + public string ProductName { get; set; } + public string ProductVesion { get; set; } + } +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Dtos/DeviceInsertDto.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Dtos/DeviceInsertDto.cs new file mode 100644 index 0000000..f96a037 --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Dtos/DeviceInsertDto.cs @@ -0,0 +1,38 @@ +using BPA.SAAS.Manage.Comm.Enum; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Device.Dtos +{ + public class DeviceInsertDto + { + /// + /// 设备名称 + /// + public string DeviceName { get; set; } + + /// + /// 设备标签 + /// + public string DeviceTypeId { get; set; } + /// + ///归属场景(店铺) + /// + public string StopId { get; set; } + /// + /// 所属产品 + /// + public string ProductId { get; set; } + /// + /// 产品标签 + /// + public string ProductCode { get; set; } + /// + /// 产品版本 + /// + public string ProductVersionId { get; set; } + } +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Dtos/DevicePageInputDto.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Dtos/DevicePageInputDto.cs new file mode 100644 index 0000000..04be9cc --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Dtos/DevicePageInputDto.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Device.Dtos +{ + public class DevicePageInputDto + { + public string ProductName { get; set; } + public string ProductVesion { 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/Device/Dtos/DeviceUpateDto.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Dtos/DeviceUpateDto.cs new file mode 100644 index 0000000..a9ab1a0 --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Dtos/DeviceUpateDto.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.Device.Dtos +{ + public class DeviceUpateDto + { + public string Id { get; set; } + /// + /// 设备名称 + /// + public string DeviceName { get; set; } + + /// + /// 设备标签 + /// + public string DeviceTypeId { get; set; } + /// + ///归属场景(店铺) + /// + public string StopId { get; set; } + /// + /// 所属产品 + /// + public string ProductId { get; set; } + /// + /// 产品标签 + /// + public string ProductCode { get; set; } + /// + /// 产品版本 + /// + public string ProductVersionId { get; set; } + } +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Services/DeviceService.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Services/DeviceService.cs new file mode 100644 index 0000000..4717c74 --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Services/DeviceService.cs @@ -0,0 +1,181 @@ +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.Application.AExternalPlatform.Service.Goods.Dtos; +using BPA.SAAS.Manage.Comm.Const; +using BPA.SAAS.Manage.Core.Base; +using BPA.SAAS.Manage.Core.DataBase; +using BPA.SAAS.Manage.Core.Device; +using BPA.SAAS.Manage.Core.Product; +using Furion.DependencyInjection; +using Furion.RemoteRequest.Extensions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Device.Services +{ + public class DeviceService: UserAnalysis, IDeviceService, ITransient + { + private string BaseServerUrl = App.GetConfig("baseurl"); + /// + /// 分页查询 + /// + /// + /// + public async Task>> GetDevicePageList(DevicePageInputDto inputDto) + { + int total = new RefAsync(); + var data =await SqlSugarDb.Db.Queryable((a, b,c) => + new JoinQueryInfos(JoinType.Left, a.ProductId == b.Id, JoinType.Left, a.ProductVersionId == c.Id)) + .WhereIF(!string.IsNullOrEmpty(inputDto.ProductName), (a, b, c) => b.Name.Contains(inputDto.ProductName)) + .WhereIF(!string.IsNullOrEmpty(inputDto.ProductVesion), (a, b, c) => c.Vesion.Contains(inputDto.ProductVesion)) + .Select((a, b, c) => new DeviceDto() + { + Id = a.Id.SelectAll(), + ProductName = b.Name, + ProductVesion = c.Vesion + + }).ToPageListAsync(inputDto.Current, inputDto.PageSize, total); + + return new PageUtil>() + { + Total = total, + Data = data + }; + } + /// + /// 添加 + /// + /// + /// + public async Task AddDevice(DeviceInsertDto dto) + { + try + { + SqlSugarDb.Db.BeginTran(); + var resEntity = new BPA_DeviceInfo(); + resEntity.DeviceName = dto.DeviceName; + await CheckInsertParm(dto);//验证参数 + 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 == "默认标签").First(); + if (check != null) + { + resEntity.DeviceTypeId = check.Id; + } + else + { + var DeviceType = await SqlSugarDb.Db.Insertable(new BPA_DeviceType() { Name = "默认标签" }).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync(); + resEntity.DeviceTypeId = DeviceType.Id; + } + } + 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 TaskUpdateDevice(DeviceUpateDto dto) + { + var resEntity = SqlSugarDb.Db.Queryable().Where(it => it.IsDeleted == 0).First(it => it.Id == dto.Id); + await CheckUpdateParm(dto);//验证参数 + resEntity.DeviceName = dto.DeviceName; + 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.Id == dto.ProductCode).First(); + if (check != null) + { + resEntity.DeviceTypeId = check.Id; + } + else + { + throw Oops.Oh(ErrorCodeEnum.Code10013); + + } + } + else + { + var check = SqlSugarDb.Db.Queryable().Where(x => x.Name == "默认标签").First(); + if (check != null) + { + resEntity.DeviceTypeId = check.Id; + } + else + { + var DeviceType = await SqlSugarDb.Db.Insertable(new BPA_DeviceType() { Name = "默认标签" }).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync(); + resEntity.DeviceTypeId = DeviceType.Id; + } + } + var res = await SqlSugarDb.Db.Updateable(resEntity).ExecuteCommandAsync(); + return res > 0; + } + /// + /// 删除 + /// + /// + /// + public async Task DeleteDevice(string[] ids) + { + var model = SqlSugarDb.Db.Queryable().Where(x => ids.Contains(x.Id)).ToList(); + if (model == null) throw Oops.Oh(ErrorCodeEnum.Code10012); + var res = await SqlSugarDb.Db.Deleteable(model).ExecuteCommandAsync(); + return res > 0; + } + /// + /// 校验参数 + /// + /// + /// + private async Task CheckInsertParm(DeviceInsertDto dto) + { + if (string.IsNullOrWhiteSpace(dto.StopId)) throw Oops.Oh(ErrorCodeEnum.Code1009); + var getStopurl = BaseServerUrl + "api/store/getbyIdstorelist_alm?id=" + dto.StopId; + var responseStop = await getStopurl.SetHeaders(new + { + groupId = App.User?.FindFirst(ClaimConst.GroupId)?.Value + }).SetHttpMethod(HttpMethod.Get).GetAsStringAsync(); + var checkProduct = SqlSugarDb.Db.Queryable().Where(x => x.Id == dto.ProductId).Any(); + if (!checkProduct) throw Oops.Oh(ErrorCodeEnum.Code10010); + var checkProductVesion = SqlSugarDb.Db.Queryable().Where(x => x.Id == dto.ProductVersionId).Any(); + if (!checkProductVesion) throw Oops.Oh(ErrorCodeEnum.Code10011); + } + /// + /// 校验参数 + /// + /// + /// + private async Task CheckUpdateParm(DeviceUpateDto dto) + { + if (string.IsNullOrWhiteSpace(dto.StopId)) throw Oops.Oh(ErrorCodeEnum.Code1009); + var getStopurl = BaseServerUrl + "api/store/getbyIdstorelist_alm?id=" + dto.StopId; + var responseStop = await getStopurl.SetHeaders(new + { + groupId = App.User?.FindFirst(ClaimConst.GroupId)?.Value + }).SetHttpMethod(HttpMethod.Get).GetAsStringAsync(); + var checkProduct = SqlSugarDb.Db.Queryable().Where(x => x.Id == dto.ProductId).Any(); + if (!checkProduct) throw Oops.Oh(ErrorCodeEnum.Code10010); + var checkProductVesion = SqlSugarDb.Db.Queryable().Where(x => x.Id == dto.ProductVersionId).Any(); + if (!checkProductVesion) throw Oops.Oh(ErrorCodeEnum.Code10011); + } + } +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Services/IDeviceService.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Services/IDeviceService.cs new file mode 100644 index 0000000..031584a --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Services/IDeviceService.cs @@ -0,0 +1,41 @@ +using BPA.KitChen.GroupMeal.SqlSugar; +using BPA.SAAS.Manage.Application.AExternalPlatform.Enum; +using BPA.SAAS.Manage.Application.AExternalPlatform.Service.Device.Dtos; +using BPA.SAAS.Manage.Core.Base; +using BPA.SAAS.Manage.Core.Device; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Device.Services +{ + public interface IDeviceService + { + /// + /// 分页查询 + /// + /// + /// + Task>> GetDevicePageList(DevicePageInputDto inputDto); + /// + /// 添加 + /// + /// + /// + Task AddDevice(DeviceInsertDto dto); + /// + /// 更新 + /// + /// + /// + Task UpdateDevice(DeviceUpateDto dto); + /// + /// 删除 + /// + /// + /// + Task DeleteDevice(string[] ids); + } +} diff --git a/BPA.SAAS.Manage.Web.Entry/appsettings.json b/BPA.SAAS.Manage.Web.Entry/appsettings.json index 029e773..e4afa70 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:5008/", + "baseurl": "http://localhost:5007/", "ConnectionConfigs": [ { "ConnectionString": "server=10.2.1.21;Database=bpa_kitchen_kitchenbasemanage;Uid=root;Pwd=cygadmin;Allow Zero Datetime=True;Convert Zero Datetime=True;", From 64cd0d9578ed162d03a06461879c2a5ff88ae473 Mon Sep 17 00:00:00 2001 From: zhaoy <137053305@qq.com> Date: Fri, 1 Mar 2024 18:03:33 +0800 Subject: [PATCH 3/3] z --- .../BaseDto/ResponDataBase.cs | 16 ++++++++++++++ .../Service/Device/Dtos/StopDto.cs | 21 +++++++++++++++++++ .../Service/Device/Services/DeviceService.cs | 15 +++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/ResponDataBase.cs create mode 100644 BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Dtos/StopDto.cs diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/ResponDataBase.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/ResponDataBase.cs new file mode 100644 index 0000000..4d0820d --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/BaseDto/ResponDataBase.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto +{ + public class ResponDataBase + { + public string statusCode { get; set; } + public object data { get; set; } + public string succeeded { get; set; } + public string errors { get; set; } + } +} diff --git a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Dtos/StopDto.cs b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Dtos/StopDto.cs new file mode 100644 index 0000000..285033e --- /dev/null +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Dtos/StopDto.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Device.Dtos +{ + public class StopDto + { + public string Id { get; set; } + public string Name { get; set; } + public string OrgId { get; set; } + public string OrgName { get; set; } + public string Phone { get; set; } + public int Sort { get; set; } + public string Description { get; set; } + public string GroupId { get; set; } + public DateTime CreateAt { get; set; } + } +} 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 4717c74..e0e1b1d 100644 --- a/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Services/DeviceService.cs +++ b/BPA.SAAS.Manage.Application/AExternalPlatform/Service/Device/Services/DeviceService.cs @@ -3,6 +3,7 @@ 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.Application.AExternalPlatform.Service.Goods.Dtos; +using BPA.SAAS.Manage.Application.DataBase.Dtos.GoodsAttribute; using BPA.SAAS.Manage.Comm.Const; using BPA.SAAS.Manage.Core.Base; using BPA.SAAS.Manage.Core.DataBase; @@ -10,11 +11,13 @@ using BPA.SAAS.Manage.Core.Device; using BPA.SAAS.Manage.Core.Product; using Furion.DependencyInjection; using Furion.RemoteRequest.Extensions; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using ResponDataBase = BPA.SAAS.Manage.Application.AExternalPlatform.BaseDto.ResponDataBase; namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Device.Services { @@ -154,6 +157,12 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Device.Services { groupId = App.User?.FindFirst(ClaimConst.GroupId)?.Value }).SetHttpMethod(HttpMethod.Get).GetAsStringAsync(); + var resStop = JsonConvert.DeserializeObject(responseStop); + if (resStop.statusCode != "200") throw Oops.Oh("获取场景数据失败"); + var dataStop = JsonConvert.DeserializeObject>(resStop.data.ToString()); + if (dataStop.Count==0) throw Oops.Oh("获取场景数据失败"); + if(!dataStop.Where(x=>x.Id == dto.StopId).Any()) throw Oops.Oh("场景不存在"); + var checkProduct = SqlSugarDb.Db.Queryable().Where(x => x.Id == dto.ProductId).Any(); if (!checkProduct) throw Oops.Oh(ErrorCodeEnum.Code10010); var checkProductVesion = SqlSugarDb.Db.Queryable().Where(x => x.Id == dto.ProductVersionId).Any(); @@ -172,6 +181,12 @@ namespace BPA.SAAS.Manage.Application.AExternalPlatform.Service.Device.Services { groupId = App.User?.FindFirst(ClaimConst.GroupId)?.Value }).SetHttpMethod(HttpMethod.Get).GetAsStringAsync(); + var resStop = JsonConvert.DeserializeObject(responseStop); + if (resStop.statusCode != "200") throw Oops.Oh("获取场景数据失败"); + var dataStop = JsonConvert.DeserializeObject>(resStop.data.ToString()); + if (dataStop.Count == 0) throw Oops.Oh("获取场景数据失败"); + if (!dataStop.Where(x => x.Id == dto.StopId).Any()) throw Oops.Oh("场景不存在"); + var checkProduct = SqlSugarDb.Db.Queryable().Where(x => x.Id == dto.ProductId).Any(); if (!checkProduct) throw Oops.Oh(ErrorCodeEnum.Code10010); var checkProductVesion = SqlSugarDb.Db.Queryable().Where(x => x.Id == dto.ProductVersionId).Any();