From e2502e224971bd838dfabb6c3a02a60dcd16ac68 Mon Sep 17 00:00:00 2001 From: gwbvipvip Date: Fri, 2 Feb 2024 17:14:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Service/Applet/AppletService.cs | 75 ++++++++++--- .../Dtos/MiniStoreConfigurationInput.cs | 2 + .../Applet/Dtos/PayTemplatePageInputDto.cs | 1 + .../ShopManage/FoodMenu/Dtos/BaseResultDto.cs | 35 +++++- .../FoodMenu/Dtos/FoodMenuBaseDto.cs | 1 + .../FoodMenu/Dtos/FoodMenuQueryInputDto.cs | 1 + .../ShopManage/FoodMenu/FoodMenuServices.cs | 54 ++++++++-- .../ShopManage/Printer/PrinterServices.cs | 15 ++- .../StoreAdvertisementService.cs | 31 ++++-- .../Service/SysService/ISysService.cs | 4 +- .../Service/SysService/SysService.cs | 24 +++++ .../SysService/TransferUploadObjectModel.cs | 100 ++++++++++++++++++ .../Entity/BPA_FoodMenu.cs | 2 + .../Entity/BPA_StoreAdvertisement.cs | 1 + .../Properties/launchSettings.json | 2 +- BPA.KitChen.StoreManagement/appsettings.json | 2 +- 16 files changed, 309 insertions(+), 41 deletions(-) create mode 100644 BPA.KitChen.StoreManagement.Application/Service/SysService/TransferUploadObjectModel.cs diff --git a/BPA.KitChen.StoreManagement.Application/Service/Applet/AppletService.cs b/BPA.KitChen.StoreManagement.Application/Service/Applet/AppletService.cs index a3021aa..f2a7183 100644 --- a/BPA.KitChen.StoreManagement.Application/Service/Applet/AppletService.cs +++ b/BPA.KitChen.StoreManagement.Application/Service/Applet/AppletService.cs @@ -128,7 +128,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Applet [HttpPost("/api/AppletService/MaterialAdd")] public async Task MaterialAdd(AddMiniStorePageMaterialInput input) { - var res = await db.Queryable().FirstAsync(x => x.MaterialCode == input.MaterialCode ); + var res = await db.Queryable().FirstAsync(x => x.MaterialCode == input.MaterialCode && x.PageId == input.PageId); if (res != null) { throw Oops.Bah("素材编码重复"); @@ -209,7 +209,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Applet throw Oops.Bah("没有找到数据"); } //判断编码重复 - var data1 = await db.Queryable().FirstAsync(x => x.Id != input.Id && x.MaterialCode == input.MaterialCode ); + var data1 = await db.Queryable().FirstAsync(x => x.Id != input.Id && x.MaterialCode == input.MaterialCode && x.PageId == input.PageId); if (data1 != null) { throw Oops.Bah("编码重复"); @@ -228,17 +228,25 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Applet /// [HttpPost("/api/AppletService/MiniStoreMaterial")] [AllowAnonymous] - public async Task> MiniStoreMaterial(QueryMiniStorePageInput input) + public async Task> MiniStoreMaterial(QueryMiniStorePageInput input) { List outputs = new(); - var datas = await db.Queryable().Where(x => x.StoreId == input.StoreId).ToListAsync(); - foreach (var item in datas) + var datas = await db.Queryable().Where(x => x.StoreId == input.StoreId && x.Id == input.PageId).ToListAsync(); + + if (datas.Count > 0) { + var ids = datas.Select(x => x.Id); + + var pageList = await db.Queryable().Where(x => ids.Contains(x.PageId)) + .OrderBy(x => x.Id) + .ToPagedListAsync(input.Current, input.PageSize); + + + MiniStorePageConfigOutput output = new(); - output.PageName = item.PageName; - output.PageRoute = item.PageRoute; - var lists = await db.Queryable().Where(x => x.PageId == item.Id).ToListAsync(); - foreach (var materialItem in lists) + output.PageName = datas[0]?.PageName ?? ""; + output.PageRoute = datas[0]?.PageRoute ?? ""; + foreach (var materialItem in pageList.Items) { MiniStorePageMaterialOutput material = new(); material.MaterialName = materialItem.MaterialName; @@ -249,9 +257,23 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Applet output.List.Add(material); } outputs.Add(output); + return new SqlSugarPagedList() + { + Items = outputs, + PageIndex = pageList.PageIndex, + PageSize = pageList.PageSize, + TotalCount = pageList.TotalCount, + TotalPages = pageList.TotalPages, + + }; } - return outputs; + + return new SqlSugarPagedList() + { + Items = new List() + }; + } #endregion @@ -264,7 +286,12 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Applet { db.Ado.BeginTran(); - var payTemplate = await db.Insertable(new BPA_PayTemplate() + var payTemplate = db.Queryable().First(x => x.IsDeleted == 0 && x.Name == inputDto.Name); + if (payTemplate != null) + { + throw Oops.Bah("名称重复"); + } + payTemplate = await db.Insertable(new BPA_PayTemplate() { Name = inputDto.Name, }).CallEntityMethod(t => t.Create()).ExecuteReturnEntityAsync(); @@ -300,9 +327,10 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Applet db.Ado.CommitTran(); return result; } - catch (Exception) + catch (Exception e) { db.Ado.RollbackTran(); + throw Oops.Bah(e.Message); return false; } } @@ -345,6 +373,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Applet int total = 0; var res = db.Queryable() .Where(x => x.IsDeleted == 0) + .WhereIF(!string.IsNullOrEmpty(inputDto.Name), x => x.Name.Contains(inputDto.Name)) .Select(t => new PayTemplateOutDto { Id = t.Id.SelectAll(), @@ -384,10 +413,17 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Applet [HttpPost("/api/paytemplate/update")] public async Task Update(PayTemplateCreateOrUpdateInputDto inputDto) { - var payTemplate = db.Queryable().First(x => x.Id == inputDto.Id && x.IsDeleted == 0); + var payTemplate = db.Queryable().First(x => x.Id != inputDto.Id && x.IsDeleted == 0 && x.Name == inputDto.Name); + if (payTemplate != null) + { + throw Oops.Bah("名称重复"); + } + + payTemplate = db.Queryable().First(x => x.Id == inputDto.Id && x.IsDeleted == 0); if (payTemplate == null) return false; payTemplate.Name = inputDto.Name; + var payTemplateInfo = db.Queryable().Where(x => x.PayTemplateId == inputDto.Id).ToList(); foreach (var item in payTemplateInfo) { @@ -431,6 +467,12 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Applet [HttpPost("/api/appid/add")] public async Task AppidAdd(BPA_AppIdConfig inputDto) { + var data = db.Queryable().First(x => x.IsDeleted == 0 && x.AppId == inputDto.AppId); + if (data != null) + { + throw Oops.Bah("AppId重复"); + } + try { var result = await db.Insertable(inputDto).CallEntityMethod(t => t.Create()).ExecuteCommandAsync() > 0; @@ -488,7 +530,12 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Applet [HttpPost("/api/appid/update")] public async Task AppidUpdate(BPA_AppIdConfig inputDto) { - var data = db.Queryable().First(x => x.Id == inputDto.Id && x.IsDeleted == 0); + var data = db.Queryable().First(x => x.Id != inputDto.Id && x.IsDeleted == 0 && x.AppId == inputDto.AppId); + if (data != null) + { + throw Oops.Bah("AppId重复"); + } + data = db.Queryable().First(x => x.Id == inputDto.Id && x.IsDeleted == 0); if (data == null) return false; data.AppId = inputDto.AppId; try diff --git a/BPA.KitChen.StoreManagement.Application/Service/Applet/Dtos/MiniStoreConfigurationInput.cs b/BPA.KitChen.StoreManagement.Application/Service/Applet/Dtos/MiniStoreConfigurationInput.cs index 4df2a4f..e8458fb 100644 --- a/BPA.KitChen.StoreManagement.Application/Service/Applet/Dtos/MiniStoreConfigurationInput.cs +++ b/BPA.KitChen.StoreManagement.Application/Service/Applet/Dtos/MiniStoreConfigurationInput.cs @@ -65,6 +65,8 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Applet.Dtos /// 主键 /// public string StoreId { get; set; } + + public string PageId { get; set; } } #endregion diff --git a/BPA.KitChen.StoreManagement.Application/Service/Applet/Dtos/PayTemplatePageInputDto.cs b/BPA.KitChen.StoreManagement.Application/Service/Applet/Dtos/PayTemplatePageInputDto.cs index eb1cdd9..860f8be 100644 --- a/BPA.KitChen.StoreManagement.Application/Service/Applet/Dtos/PayTemplatePageInputDto.cs +++ b/BPA.KitChen.StoreManagement.Application/Service/Applet/Dtos/PayTemplatePageInputDto.cs @@ -10,5 +10,6 @@ namespace BPA.KitChen.StoreManagement.Application.Service.Applet.Dtos { public class PayTemplatePageInputDto: PageInputBase { + public string Name { get; set; } } } diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/FoodMenu/Dtos/BaseResultDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/FoodMenu/Dtos/BaseResultDto.cs index d7c9f90..6a76cef 100644 --- a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/FoodMenu/Dtos/BaseResultDto.cs +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/FoodMenu/Dtos/BaseResultDto.cs @@ -45,7 +45,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu.Dt public string goodsTypeName { get; set; } - public string remark { get; set; } + public string descritption { get; set; } public int isDeleted { get; set; } @@ -55,11 +55,42 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu.Dt public string design { get; set; } - public int isWeigh { get; set; } + public string isWeigh { get; set; } public string defaultMate { get; set; } public string isAttrubute { get; set; } + + public List goodstechnology { get; set; } + } + + public class GoodstechnologyItem + { + public string stepName { get; set; } + + public string actionJson { get; set; } + + public string goodsAttributeId { get; set; } + + public string isBatch { get; set; } + + public string chnologyId { get; set; } + + public string groupId { get; set; } + + public int sort { get; set; } + + public string goodsId { get; set; } + + public string deviceId { get; set; } + + public string id { get; set; } + + public string createAt { get; set; } + + public string createBy { get; set; } + + public int isDeleted { get; set; } } public class BaseResultDto2 diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/FoodMenu/Dtos/FoodMenuBaseDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/FoodMenu/Dtos/FoodMenuBaseDto.cs index cf382f1..f438b28 100644 --- a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/FoodMenu/Dtos/FoodMenuBaseDto.cs +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/FoodMenu/Dtos/FoodMenuBaseDto.cs @@ -24,5 +24,6 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu.Dt { public string GoodsId { get; set;} public string GoodsName { get; set; } + public decimal Price { get; set;} } } diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/FoodMenu/Dtos/FoodMenuQueryInputDto.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/FoodMenu/Dtos/FoodMenuQueryInputDto.cs index d41e0fe..4a24653 100644 --- a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/FoodMenu/Dtos/FoodMenuQueryInputDto.cs +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/FoodMenu/Dtos/FoodMenuQueryInputDto.cs @@ -37,6 +37,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu.Dt { public string Id { get; set; } public string Name { get; set; } + public decimal Price { get; set; } public bool Check { get; set; } } } diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/FoodMenu/FoodMenuServices.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/FoodMenu/FoodMenuServices.cs index 8a3e990..ee0eb1f 100644 --- a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/FoodMenu/FoodMenuServices.cs +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/FoodMenu/FoodMenuServices.cs @@ -73,6 +73,37 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu }; } + /// + /// 删除菜谱 + /// + /// + /// + [HttpPost("/api/FoodMenu/DelShopFoodMenu")] + public async Task DelShopFoodMenu(string id) + { + try + { + db.Ado.BeginTran(); + var data = db.Queryable().Where(a => a.Id == id).ToList(); + + var res = await db.Deleteable(data).ExecuteCommandAsync(); + + + var data2 = db.Queryable().Where(a => a.FoodMenuId == id).ToList(); + + await db.Deleteable(data2).ExecuteCommandAsync(); + + + db.Ado.CommitTran(); + return true; + } + catch (Exception ex) + { + return false; + } + + + } /// @@ -92,7 +123,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu if (obj1 != null && data.Id != obj1.Id) { - throw new Exception("名称或编码重复"); + throw new Exception("名称重复"); } if (data != null) @@ -178,7 +209,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu //var url1 = App.Configuration["SAAS_Manage"] + "/api/goods/getgoodslist"; //var json1 = HttpHelper.HttpGet(url1, "", dic, ""); - var url = App.Configuration["SAAS_Manage"] + "/api/goods/page"; + var url = App.Configuration["SAAS_Manage"] + "api/goods/page"; var json2 = HttpHelper.PostData(url, JsonConvert.SerializeObject(new { current = inputDto.Current, @@ -204,6 +235,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu { Id = item.id, Name = item.name, + Price = item.price, Check = check }); } @@ -260,7 +292,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu Dictionary dic = new Dictionary(); dic.Add("Authorization", authorization); - var url1 = App.Configuration["SAAS_Manage"] + "/api/goods/getgoodslist"; + var url1 = App.Configuration["SAAS_Manage"] + "api/goods/getgoodslist"; var json1 = HttpHelper.HttpGet(url1, "", dic, ""); var data2 = JsonConvert.DeserializeObject(json1); @@ -275,6 +307,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu FoodMenuId = inputDto.FoodMenuId, GoodsName = data2?.data?.First(c => c.id == x.GoodsId)?.name, GoodsId = x.GoodsId, + Price= data2?.data?.First(c => c.id == x.GoodsId)?.price??0, }).ToList(); if (data.Count > 0) { @@ -294,6 +327,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu { var tihsAdd = thisData.Where(x => x.FoodId == item2.GoodsId).FirstOrDefault(); + var price = data2?.data?.First(c => c.id == (tihsAdd?.FoodId ?? item2.GoodsId))?.price ?? 0; await db.Insertable(new BPA_StoreFoodMenu() { CookingWorkId = tihsAdd?.CookingWorkId ?? "", @@ -302,11 +336,11 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu FoodId = tihsAdd?.FoodId ?? item2.GoodsId, FoodMenuId = inputDto.FoodMenuId, FoodName = item?.First()?.FoodName, - Price = tihsAdd?.Price ?? 0, + Price = price, StopSales = tihsAdd?.StopSales ?? 0, StoreId = item.First().StoreId, - Vip2Price = tihsAdd?.Vip2Price ?? 0, - VipPrice = tihsAdd?.VipPrice ?? 0, + Vip2Price = price, + VipPrice = price, }).CallEntityMethod(m => m.Create()).ExecuteCommandAsync(); } @@ -318,8 +352,8 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu StoreId = inputDto.StoreId, FoodMenuIds = new List { - inputDto.FoodMenuId - } + inputDto.FoodMenuId, + }, }); db.Ado.CommitTran(); @@ -379,8 +413,8 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.FoodMenu Id = a.Id, goodsId = a.Id, goodsName=a.GoodsName, - Price = 0, - vipPrice = 0, + Price = a.Price, + vipPrice = a.Price, a.FoodMenuId }).ToList(); diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Printer/PrinterServices.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Printer/PrinterServices.cs index 0b4dedb..2b2af8f 100644 --- a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Printer/PrinterServices.cs +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/Printer/PrinterServices.cs @@ -24,6 +24,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Printer /// 核心对象:拥有完整的SqlSugar全部功能 /// private readonly SqlSugarScope db; + /// /// construct /// @@ -326,9 +327,19 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.Printer /// /// [HttpPut("/api/Printer/UpdatePrinterTemplate")] - public bool UpdatePrinterTemplate(PrinterTemplateCreateOrUpdateInputDto inputDto) + public async Task UpdatePrinterTemplate(PrinterTemplateCreateOrUpdateInputDto inputDto) { - var res = db.Updateable(inputDto.Adapt()) + + var data =await db.Queryable().FirstAsync(x => x.Id == inputDto.Id); + data.Title = inputDto.Title; + data.Explain = inputDto.Explain; + data.Footer = inputDto.Footer; + data.IsShowNumber = inputDto.IsShowNumber; + data.IsShowPrintTime = inputDto.IsShowPrintTime; + data.Subtitle = inputDto.Subtitle; + data.Title = inputDto.Title; + + var res = db.Updateable(data) .CallEntityMethod(m => m.Modify()).ExecuteCommand(); return res > 0; } diff --git a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/StoreAdvertisement/StoreAdvertisementService.cs b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/StoreAdvertisement/StoreAdvertisementService.cs index 80aa5ce..1074e9b 100644 --- a/BPA.KitChen.StoreManagement.Application/Service/ShopManage/StoreAdvertisement/StoreAdvertisementService.cs +++ b/BPA.KitChen.StoreManagement.Application/Service/ShopManage/StoreAdvertisement/StoreAdvertisementService.cs @@ -1,6 +1,7 @@ using BPA.KitChen.StoreManagement.Application.BaseDto; using BPA.KitChen.StoreManagement.Application.Service.ShopManage.StoreAdvertisement.Dtos; using BPA.KitChen.StoreManagement.Application.Service.ShopManage.StoreDesktopNumber; +using BPA.KitChen.StoreManagement.Application.Service.SysService; using BPA.KitChen.StoreManagement.Core.Common; using BPA.KitChen.StoreManagement.Core.Common.Const; using BPA.KitChen.StoreManagement.Core.Entity; @@ -24,12 +25,14 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.StoreAdvert { private readonly SqlSugarScope db; private readonly IWebHostEnvironment _webHostEnvironment; + private readonly ISysService _sysService; private readonly string host = "";//App.Configuration["HostPort"]; - public StoreAdvertisementService(IWebHostEnvironment webHostEnvironment) + public StoreAdvertisementService(IWebHostEnvironment webHostEnvironment, ISysService sysService) { db = SqlSugarDb.Db; _webHostEnvironment= webHostEnvironment; + _sysService = sysService; } /// @@ -68,17 +71,17 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.StoreAdvert if (inputDto.UploadType == 1) //校验:0自定义上传,1网络路径 videoUrls = inputDto.NetWorkUrl; else - videoUrls = inputDto.VideoUrl; + videoUrls = inputDto.ImageUrl[0].Name;/*; inputDto.VideoUrl;*/ } BPA_StoreAdvertisement info = new BPA_StoreAdvertisement() { ImageUrl = imageUrls.TrimEnd('|'), Content = inputDto.Content??"", - VideoUrl = videoUrls, + VideoUrl = string.IsNullOrEmpty(videoUrls)?"": videoUrls, UploadType = inputDto.UploadType, - StartTime = inputDto.StartTime, - EndTime = inputDto.EndTime, + StartTime = inputDto.StartTime??DateTime.Now.ToString(), + EndTime = inputDto.EndTime ?? DateTime.Now.ToString(), Type = inputDto.Type, Step = inputDto.Step, Title = inputDto.Title, @@ -191,6 +194,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.StoreAdvert [HttpPut("/api/StoreAdvertisement/UpdateStoreAdvertisement")] public bool UpdateStoreAdvertisementAsync(StoreAdvertisementEntityDto inputDto) { + inputDto.ImageUrl= inputDto.ImageUrl.Where(x=>x!=null).ToList(); string imageUrls = string.Empty; string videoUrls = string.Empty; //广告类型 0图片 1 视频 @@ -207,7 +211,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.StoreAdvert { foreach (var item in inputDto.ImageUrl) { - imageUrls += item.Name??"" + "|"; + imageUrls += (item.Name??"") + "|"; } } } @@ -218,12 +222,12 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.StoreAdvert if (inputDto.UploadType == 1) //校验:0自定义上传,1网络路径 videoUrls = inputDto.NetWorkUrl; else - videoUrls = inputDto.VideoUrl; + videoUrls = inputDto.ImageUrl[0].Name;/*; inputDto.VideoUrl;*/ } var data = db.Queryable().Where(x => x.Id == inputDto.Id).First(); data.UploadType = inputDto.UploadType; - data.StartTime = inputDto.StartTime; - data.EndTime = inputDto.EndTime; + data.StartTime = inputDto.StartTime??DateTime.Now.ToString(); + data.EndTime = inputDto.EndTime ?? DateTime.Now.ToString(); data.Content = inputDto.Content; data.Title = inputDto.Title; data.Step = inputDto.Step; @@ -276,7 +280,7 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.StoreAdvert /// [Route("/api/Upload/FormImg")] [HttpPost, AllowAnonymous, NonUnify] - public ResultEntity UploadImg(IFormFile file, string storeId) + public async Task UploadImg(IFormFile file, string storeId) { if (file == null) return new ResultEntity() @@ -330,7 +334,14 @@ namespace BPA.KitChen.StoreManagement.Application.Service.ShopManage.StoreAdvert IsSuccess = false, Msg = "该店铺不存在" }; + var res = await _sysService.GetCosImgesURL(file); + + return new ResultEntity() + { + Data =new List(){ res }, + IsSuccess = true, + }; //返回的文件地址 List filenames = new List(); try diff --git a/BPA.KitChen.StoreManagement.Application/Service/SysService/ISysService.cs b/BPA.KitChen.StoreManagement.Application/Service/SysService/ISysService.cs index ed415c7..6f3c5a1 100644 --- a/BPA.KitChen.StoreManagement.Application/Service/SysService/ISysService.cs +++ b/BPA.KitChen.StoreManagement.Application/Service/SysService/ISysService.cs @@ -1,4 +1,5 @@ -using System; +using Microsoft.AspNetCore.Http; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -8,5 +9,6 @@ namespace BPA.KitChen.StoreManagement.Application.Service.SysService { public interface ISysService { + Task GetCosImgesURL(IFormFile file); } } diff --git a/BPA.KitChen.StoreManagement.Application/Service/SysService/SysService.cs b/BPA.KitChen.StoreManagement.Application/Service/SysService/SysService.cs index ba90ed3..0797be8 100644 --- a/BPA.KitChen.StoreManagement.Application/Service/SysService/SysService.cs +++ b/BPA.KitChen.StoreManagement.Application/Service/SysService/SysService.cs @@ -7,6 +7,8 @@ using COSXML.Model.Tag; using Furion; using Furion.DependencyInjection; using Furion.DynamicApiController; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using SqlSugar; using System.Text.RegularExpressions; @@ -85,5 +87,27 @@ namespace BPA.KitChen.StoreManagement.Application.Service.SysService } return null; } + + [HttpPost("/api/systemconfig/GetCosFileURL"), ApiDescriptionSettings(SplitCamelCase = false), AllowAnonymous, NonUnify] + public async Task GetCosImgesURL(IFormFile file) + { + byte[] pReadByte = new byte[0]; + + var pFileStream = file.OpenReadStream(); + + BinaryReader r = new BinaryReader(pFileStream); + r.BaseStream.Seek(0, SeekOrigin.Begin); //将文件指针设置到文件开 + pReadByte = r.ReadBytes((int)r.BaseStream.Length); + + TransferUploadObjectModel m = new TransferUploadObjectModel(); + /// 高级接口上传对象 + var result = await m.TransferUploadFile(new FileInputInfoDto() + { + Directory = "goods", + FileExtension = Path.GetExtension(file.FileName).Replace(".", ""), + Method = "PUT", + }, pReadByte); + return result; + } } } diff --git a/BPA.KitChen.StoreManagement.Application/Service/SysService/TransferUploadObjectModel.cs b/BPA.KitChen.StoreManagement.Application/Service/SysService/TransferUploadObjectModel.cs new file mode 100644 index 0000000..f77292d --- /dev/null +++ b/BPA.KitChen.StoreManagement.Application/Service/SysService/TransferUploadObjectModel.cs @@ -0,0 +1,100 @@ +using COSXML.Model.Object; +using COSXML.Auth; +using COSXML.Transfer; +using System; +using COSXML; +using System.Threading.Tasks; +using BPA.Kitchen.Core.Common; +using Furion.DatabaseAccessor; +using Furion; +using Microsoft.AspNetCore.Components.Forms; +using SqlSugar; +using COSXML.Model.Bucket; +using COSXML.Utils; +using BPA.KitChen.StoreManagement.Core.Common; +using BPA.KitChen.StoreManagement.Application.Service.SysService.Dtos; +using BPA.KitChen.StoreManagement.Core.Common.Const; + +namespace BPA.KitChen.StoreManagement.Application.Service.SysService +{ + public class TransferUploadObjectModel + { + + private readonly ISqlSugarRepository repository; + private readonly SqlSugarClient db; + private CosXml cosXml; + public TransferUploadObjectModel() + { + var cosConfig = CosConfig.cosInfoOptions; + // repository = sqlSugarRepository; + //db = NewSqlSugar.GetInstance(repository.Context); // 推荐操作 + CosXmlConfig config = new CosXmlConfig.Builder() + .SetRegion(cosConfig.Region) // 设置默认的区域, COS 地域的简称请参照 https://cloud.tencent.com/document/product/436/6224 + .Build(); + + string secretId = cosConfig.SecretId; // 云 API 密钥 SecretId, 获取 API 密钥请参照 https://console.cloud.tencent.com/cam/capi + string secretKey = cosConfig.SecretKey; // 云 API 密钥 SecretKey, 获取 API 密钥请参照 https://console.cloud.tencent.com/cam/capi + long durationSecond = 6000; //每次请求签名有效时长,单位为秒 + QCloudCredentialProvider qCloudCredentialProvider = new DefaultQCloudCredentialProvider(secretId, + secretKey, durationSecond); + + this.cosXml = new CosXmlServer(config, qCloudCredentialProvider); + } + + + + /// 高级接口上传文件 + public async Task TransferUploadFile(FileInputInfoDto inputDto, byte[] data) + { + var cosConfig = CosConfig.cosInfoOptions; + // 初始化 TransferConfig + TransferConfig transferConfig = new TransferConfig(); + // 手动设置开始分块上传的大小阈值为10MB,默认值为5MB + transferConfig.DivisionForUpload = 10 * 1024 * 1024; + // 手动设置分块上传中每个分块的大小为2MB,默认值为1MB + transferConfig.SliceSizeForUpload = 2 * 1024 * 1024; + + + string GroupId = App.User.FindFirst(ClaimConst.GroupId)?.Value; + string baseUrl = "/Franchisee/"; + //if (!string.IsNullOrWhiteSpace(GroupId)) + //{ + // var Companycheck = db.Queryable().Where(x => x.Id == GroupId).First(); + // baseUrl = baseUrl + Companycheck.Code + "/"; + //} + DateTime dt = DateTime.Now; + baseUrl = baseUrl + inputDto.Directory + "/" + dt.ToFileTime().ToString() + "." + inputDto.FileExtension; + + + + try + { + // 存储桶名称,此处填入格式必须为 bucketname-APPID, 其中 APPID 获取参考 https://console.cloud.tencent.com/developer + String bucket = cosConfig.Bucket; + String cosPath = baseUrl; //对象在存储桶中的位置标识符,即称对象键 + + // byte[] data = new byte[1024]; // 二进制数据 + + PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, cosPath, data); + // 发起上传 + PutObjectResult result = cosXml.PutObject(putObjectRequest); + Console.WriteLine(result.GetResultInfo()); + return @"https://" + cosConfig.Bucket + ".cos.ap-chengdu.myqcloud.com/" + cosPath; + } + catch (COSXML.CosException.CosClientException clientEx) + { + //请求失败 + Console.WriteLine("CosClientException: " + clientEx); + } + catch (COSXML.CosException.CosServerException serverEx) + { + //请求失败 + Console.WriteLine("CosServerException: " + serverEx.GetInfo()); + } + return ""; + + } + + + } +} diff --git a/BPA.KitChen.StoreManagement.Core/Entity/BPA_FoodMenu.cs b/BPA.KitChen.StoreManagement.Core/Entity/BPA_FoodMenu.cs index e3d2224..aba9689 100644 --- a/BPA.KitChen.StoreManagement.Core/Entity/BPA_FoodMenu.cs +++ b/BPA.KitChen.StoreManagement.Core/Entity/BPA_FoodMenu.cs @@ -25,6 +25,8 @@ namespace BPA.KitChen.StoreManagement.Core.Entity [SugarColumn(ColumnDataType = "Nvarchar(64)", IsNullable = true)] public string GoodsName { get; set; } + [SugarColumn(ColumnDataType = "decimal(18,2)", IsNullable = false)] + public decimal Price { get; set; } /// /// 菜谱信息表 /// diff --git a/BPA.KitChen.StoreManagement.Core/Entity/BPA_StoreAdvertisement.cs b/BPA.KitChen.StoreManagement.Core/Entity/BPA_StoreAdvertisement.cs index ae1444c..d550dbf 100644 --- a/BPA.KitChen.StoreManagement.Core/Entity/BPA_StoreAdvertisement.cs +++ b/BPA.KitChen.StoreManagement.Core/Entity/BPA_StoreAdvertisement.cs @@ -37,6 +37,7 @@ namespace BPA.KitChen.StoreManagement.Core.Entity /// /// 图片存储路径 /// + [SugarColumn(ColumnDataType = "Nvarchar(2000)", IsNullable = true)] public string ImageUrl { get; set; } /// /// 视频存储路径 diff --git a/BPA.KitChen.StoreManagement/Properties/launchSettings.json b/BPA.KitChen.StoreManagement/Properties/launchSettings.json index 30f117c..a4c19cb 100644 --- a/BPA.KitChen.StoreManagement/Properties/launchSettings.json +++ b/BPA.KitChen.StoreManagement/Properties/launchSettings.json @@ -14,7 +14,7 @@ "dotnetRunMessages": true, "launchBrowser": true, "launchUrl": "api/index.html", - "applicationUrl": "http://localhost:5298", + "applicationUrl": "http://localhost:5002", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/BPA.KitChen.StoreManagement/appsettings.json b/BPA.KitChen.StoreManagement/appsettings.json index efcc19c..a75e313 100644 --- a/BPA.KitChen.StoreManagement/appsettings.json +++ b/BPA.KitChen.StoreManagement/appsettings.json @@ -21,7 +21,7 @@ "UserName": "emqx_u_block", "Password": "emqx_p_admin8765490789" }, - "SAAS_Manage": "http://10.2.1.26:21995/saasbase/", + "SAAS_Manage": "http://localhost:5001/", "DBConnectionStr": "server=10.2.1.21;Port=3306;Database=bpa_kitchen_storemanage;Uid=root;Pwd=cygadmin;", "AllowedHosts": "*"