From 0d1796879019d1501edb9c01d6e3acd38dd5b80b Mon Sep 17 00:00:00 2001 From: wanghaomei Date: Thu, 29 Dec 2022 17:47:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=93=E5=8D=B0=E6=A8=A1=E6=9D=BF=E5=89=8D?= =?UTF-8?q?=E6=9C=9F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entity/BookingPrintTemplate.cs | 4 + .../BookingPrintTemplateService.cs | 79 ++++++++++++++++++- .../Dto/BookingPrintTemplateInput.cs | 32 +++++++- 3 files changed, 109 insertions(+), 6 deletions(-) diff --git a/Myshipping.Application/Entity/BookingPrintTemplate.cs b/Myshipping.Application/Entity/BookingPrintTemplate.cs index 96c0aab1..22e23755 100644 --- a/Myshipping.Application/Entity/BookingPrintTemplate.cs +++ b/Myshipping.Application/Entity/BookingPrintTemplate.cs @@ -39,5 +39,9 @@ namespace Myshipping.Application.Entity /// 分单 /// public bool IsSub { get; set; } + /// + /// 显示名称 + /// + public string DisplayName { get; set; } } } \ No newline at end of file diff --git a/Myshipping.Application/Service/BookingPrintTemplate/BookingPrintTemplateService.cs b/Myshipping.Application/Service/BookingPrintTemplate/BookingPrintTemplateService.cs index b3cc5b7d..010e9535 100644 --- a/Myshipping.Application/Service/BookingPrintTemplate/BookingPrintTemplateService.cs +++ b/Myshipping.Application/Service/BookingPrintTemplate/BookingPrintTemplateService.cs @@ -62,7 +62,7 @@ namespace Myshipping.Application } /// - /// 增加订舱打印模板 + /// 增加订舱打印模板(准备作废) /// /// /// @@ -130,7 +130,7 @@ namespace Myshipping.Application /// - /// 更新订舱打印模板 + /// 更新订舱打印模板(准备作废) /// /// /// @@ -191,6 +191,81 @@ namespace Myshipping.Application await _rep.UpdateAsync(entity); } + /// + /// 保存订舱打印模板(新增或修改) + /// + /// + /// + /// + [HttpPost("/BookingPrintTemplate/save")] + public async Task Save(IFormFile file, [FromForm] SaveBookingPrintTemplateInput input) + { + var opt = App.GetOptions(); + if (file != null && file.Length > 0) + { + var fileSuffix = Path.GetExtension(file.FileName).ToLower(); // 文件后缀 + if (!opt.fileType.Contains(fileSuffix)) + { + throw Oops.Bah(BookingErrorCode.BOOK114); + } + } + + BookingPrintTemplate entity = null; + if (input.Id > 0) + { + entity = _rep.AsQueryable().Filter(null, true).First(x => x.Id == input.Id); + input.Adapt(entity); + await _rep.UpdateAsync(entity); + } + else + { + //新增时必须上传文件 + if (file == null || file.Length == 0) + { + throw Oops.Bah(BookingErrorCode.BOOK113); + } + + entity = input.Adapt(); + await _rep.InsertAsync(entity); + } + + if (file != null && file.Length > 0) + { + var originalFilename = file.FileName; // 文件原始名称 + + var dirAbs = string.Empty; + if (string.IsNullOrEmpty(opt.basePath)) + { + dirAbs = Path.Combine(App.WebHostEnvironment.WebRootPath, opt.relativePath); + } + else + { + dirAbs = Path.Combine(opt.basePath, opt.relativePath); + } + + if (!Directory.Exists(dirAbs)) + Directory.CreateDirectory(dirAbs); + + + // 先存库获取Id + var id = YitIdHelper.NextId(); + var fileSuffix = Path.GetExtension(file.FileName).ToLower(); + var fileSaveName = $"{id}{fileSuffix}".ToLower(); + var fileRelaPath = Path.Combine(opt.relativePath, fileSaveName).ToLower(); + var fileAbsPath = Path.Combine(dirAbs, fileSaveName).ToLower(); + using (var stream = File.Create(fileAbsPath)) + { + await file.CopyToAsync(stream); + } + + entity.FileName = originalFilename; + entity.FilePath = fileRelaPath; + await _rep.UpdateAsync(entity); + } + + return entity.Id; + } + /// /// 删除订舱打印模板 /// diff --git a/Myshipping.Application/Service/BookingPrintTemplate/Dto/BookingPrintTemplateInput.cs b/Myshipping.Application/Service/BookingPrintTemplate/Dto/BookingPrintTemplateInput.cs index 8d755ffb..9250a6fc 100644 --- a/Myshipping.Application/Service/BookingPrintTemplate/Dto/BookingPrintTemplateInput.cs +++ b/Myshipping.Application/Service/BookingPrintTemplate/Dto/BookingPrintTemplateInput.cs @@ -10,12 +10,12 @@ namespace Myshipping.Application public class BookingPrintTemplateInput { /// - /// 模板类型 + /// 模板类型(准备作废) /// public string TypeCode { get; set; } /// - /// 类型名称 + /// 类型名称(准备作废) /// public virtual string TypeName { get; set; } @@ -30,14 +30,29 @@ namespace Myshipping.Application public string TenantName { get; set; } /// - /// 主单 + /// 主单(准备作废) /// public bool IsMain { get; set; } /// - /// 分单 + /// 分单(准备作废) /// public bool IsSub { get; set; } + /// + /// 显示名称 + /// + public string DisplayName { get; set; } + + /// + /// 分类代码 + /// + public string CateCode { get; set; } + + /// + /// 分类名称 + /// + public virtual string CateName { get; set; } + } /// @@ -60,6 +75,15 @@ namespace Myshipping.Application } + public class SaveBookingPrintTemplateInput : BookingPrintTemplateInput + { + /// + /// 主键Id + /// + public long Id { get; set; } + + } + /// /// 订舱打印模板获取(删除)输入参数 ///