From 57e274f6430c255097a43fde31363a1883a29f33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B5=87=E6=96=87=E9=BE=99?= Date: Wed, 4 Sep 2024 16:15:57 +0800 Subject: [PATCH] =?UTF-8?q?=E9=82=AE=E4=BB=B6=E6=A8=A1=E6=9D=BF=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=9C=8D=E5=8A=A1=E5=A2=9E=E5=8A=A0=E6=B8=B2=E6=9F=93?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Constants/MultiLanguageConst.cs | 3 + .../Invoice/Method/InvoiceApiFox.cs | 2 +- .../Invoice/Method/InvoiceIssuanceService.cs | 92 ++++++++++--------- .../Invoice/Method/InvoiceService`1.cs | 2 +- .../TaskInteraction/ITaskMailService.cs | 10 ++ .../Op/Method/TaskInteraction/MailService.cs | 2 +- .../Method/TaskInteraction/TaskMailService.cs | 31 +++++++ .../TaskInteraction/TemplateTranslator.cs | 9 -- .../Controllers/TaskMailController.cs | 26 ++++++ 9 files changed, 122 insertions(+), 55 deletions(-) delete mode 100644 ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TemplateTranslator.cs diff --git a/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs b/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs index 67fc3b9e..b7dc6843 100644 --- a/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs +++ b/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs @@ -680,6 +680,9 @@ public static class MultiLanguageConst [Description("未配置开票API请求地址,请联系管理员")] public const string InvoiceAPIUrlNull = "Invoice_API_Url_Null"; + + [Description("开票信息不完整,请检查每张发票是否添加了费用明细")] + public const string InvoiceIncomplete = "Invoice_Incomplete"; #endregion #region 预订舱API diff --git a/ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceApiFox.cs b/ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceApiFox.cs index 6986cffc..10def636 100644 --- a/ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceApiFox.cs +++ b/ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceApiFox.cs @@ -26,7 +26,7 @@ namespace DS.WMS.Core.Invoice.Method BaseUri = new Uri(config.GetValue("InvoiceApi:BaseUrl")); UserKey = config.GetValue("InvoiceApi:UserKey"); - string? us = config.GetValue("InvoiceApi:UserSecret"); + var us = config.GetValue("InvoiceApi:UserSecret"); if (!us.IsNullOrEmpty()) { UserSecret = new SecureString(); diff --git a/ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceIssuanceService.cs b/ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceIssuanceService.cs index 2d2bbb76..175c13bd 100644 --- a/ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceIssuanceService.cs +++ b/ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceIssuanceService.cs @@ -3,6 +3,7 @@ using DS.WMS.Core.Application.Method; using DS.WMS.Core.Invoice.Dtos; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using SqlSugar; namespace DS.WMS.Core.Invoice.Method { @@ -26,52 +27,59 @@ namespace DS.WMS.Core.Invoice.Method /// /// 发起开票请求 /// - /// 开票的发票信息 + /// 开票的发票ID /// - public async Task> InitiateAsync(params Entity.Invoice[] invoices) + public async Task> InitiateAsync(params long[] ids) { + ArgumentNullException.ThrowIfNull(ids, nameof(ids)); + //请求参数设置 - InvoiceIssuanceRequest request = new(); - request.order = invoices.Select(x => new InvoiceInfo + InvoiceIssuanceRequest request = new() { - invoiceType = ((int)x.Type).ToString(), - orderNo = x.BillNO, - email = x.Email, - buyerTaxNum = x.TaxID, - buyerName = x.InvoiceHeader, - buyerAddress = x.CustomerAddress, - buyerTel = x.CustomerPhone, - gmfkhh = x.CustomerBankName, - gmfzh = x.CustomerAccount, - skyhmc = x.BankName, - skyhzh = x.Account, - checker = x.Checker, - payee = x.Payee, - //---------金额项--------- - hjse = x.InvoiceAmount * x.TaxRate, - hjje = x.InvoiceAmount - x.InvoiceAmount * x.TaxRate, - jshj = x.InvoiceAmount, - clerk = x.CreateUserName, //开票人 - kprzjhm = "", //证件号 - kprzjlx = "201", //身份证, - //---------发票明细--------- - invoiceDetail = x.InvoiceDetails.Select(y => new InvoiceDetailInfo + order = await TenantDb.Queryable().Where(x => ids.Contains(x.Id)).Select(x => new InvoiceInfo { - mxxh = x.InvoiceDetails.IndexOf(y) + 1, - xmmc = y.Name, - spfwjc = string.Empty, - specType = y.Specification, - unit = y.Unit, - num = y.Quantity.ToString(), - taxExcludedAmount = y.UnitPrice, - taxRate = y.TaxRate.ToString(), - tax = y.TaxAmount, - taxIncludedAmount = y.TaxUnitPrice, - goodsCode = "", //商品和服务税收分类合并编码 - invoiceLineProperty = "00" - }).ToList() + invoiceType = ((int)x.Type).ToString(), + orderNo = x.BillNO, + email = x.Email, + buyerTaxNum = x.TaxID, + buyerName = x.InvoiceHeader, + buyerAddress = x.CustomerAddress, + buyerTel = x.CustomerPhone, + gmfkhh = x.CustomerBankName, + gmfzh = x.CustomerAccount, + skyhmc = x.BankName, + skyhzh = x.Account, + checker = x.Checker, + payee = x.Payee, + //---------金额项--------- + hjse = x.InvoiceAmount * x.TaxRate, + hjje = x.InvoiceAmount - x.InvoiceAmount * x.TaxRate, + jshj = x.InvoiceAmount, + clerk = x.CreateUserName, //开票人 + kprzjhm = "", //证件号 + kprzjlx = "201", //身份证, + //---------发票明细--------- + invoiceDetail = x.InvoiceDetails.Select(y => new InvoiceDetailInfo + { + mxxh = SqlFunc.RowNumber(y.Id), //x.InvoiceDetails.IndexOf(y) + 1, + xmmc = y.Name, + spfwjc = string.Empty, + specType = y.Specification, + unit = y.Unit, + num = y.Quantity.ToString(), + taxExcludedAmount = y.UnitPrice, + taxRate = y.TaxRate.ToString(), + tax = y.TaxAmount, + taxIncludedAmount = y.TaxUnitPrice, + goodsCode = "", //商品和服务税收分类合并编码 + invoiceLineProperty = "00" + }).ToList() + + }).ToListAsync() + }; - }).ToList(); + if (request.order.Count == 0 || request.order.Any(x => x.invoiceDetail.Count == 0)) + return DataResult.FailedWithDesc(MultiLanguageConst.InvoiceIncomplete); var result = await api.PostAsync>("/api/Invoice/services", request); if (!result.Succeeded) @@ -80,14 +88,12 @@ namespace DS.WMS.Core.Invoice.Method var invResult = result.Data; if (invResult.Success) { - - return DataResult.Success(invResult.Data); } else { if (invResult.Code == 1) - return await InitiateAsync(invoices); + return await InitiateAsync(ids); return DataResult.Failed(invResult.Message); } diff --git a/ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceService`1.cs b/ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceService`1.cs index 56a400c7..ff101a44 100644 --- a/ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceService`1.cs +++ b/ds-wms-service/DS.WMS.Core/Invoice/Method/InvoiceService`1.cs @@ -167,7 +167,7 @@ namespace DS.WMS.Core.Invoice.Method #pragma warning disable CS4014 /// - /// 提交发票开票 + /// 提交 /// /// 请求参数 /// diff --git a/ds-wms-service/DS.WMS.Core/Op/Interface/TaskInteraction/ITaskMailService.cs b/ds-wms-service/DS.WMS.Core/Op/Interface/TaskInteraction/ITaskMailService.cs index 954841c7..a984ab82 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Interface/TaskInteraction/ITaskMailService.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Interface/TaskInteraction/ITaskMailService.cs @@ -1,5 +1,6 @@ using DS.Module.Core; using DS.Module.Core.Data; +using DS.WMS.Core.Op.Entity; using DS.WMS.Core.Op.Entity.TaskInteraction; namespace DS.WMS.Core.Op.Interface.TaskInteraction @@ -9,6 +10,15 @@ namespace DS.WMS.Core.Op.Interface.TaskInteraction /// public interface ITaskMailService { + /// + /// 渲染模板 + /// + /// 单据类型 + /// 业务ID + /// 业务类型 + /// + Task> RenderTemplateAsync(DocumentType docType, long bsId, BusinessType businessType); + /// /// 获取分页列表 /// diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/MailService.cs b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/MailService.cs index c14a8b31..10eb5beb 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/MailService.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/MailService.cs @@ -41,7 +41,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction Db.QueryFilter.Clear(); } - static async Task RenderTemplateAsync(string name, string templateText, object model, IRazorEngine? razorEngine = null) + internal static async Task RenderTemplateAsync(string name, string templateText, object model, IRazorEngine? razorEngine = null) { int hashCode = name.GetHashCode(); diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TaskMailService.cs b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TaskMailService.cs index 639200cf..a1513261 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TaskMailService.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TaskMailService.cs @@ -1,8 +1,10 @@ using DS.Module.Core; using DS.Module.Core.Data; using DS.Module.Core.Extensions; +using DS.WMS.Core.Op.Entity; using DS.WMS.Core.Op.Entity.TaskInteraction; using DS.WMS.Core.Op.Interface.TaskInteraction; +using Microsoft.Extensions.DependencyInjection; namespace DS.WMS.Core.Op.Method.TaskInteraction { @@ -11,12 +13,41 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction /// public class TaskMailService : ServiceBase, ITaskMailService { + Lazy actionService; + /// /// 初始化 /// /// public TaskMailService(IServiceProvider provider) : base(provider) { + actionService = new Lazy(provider.GetRequiredService()); + } + + /// + /// 渲染模板 + /// + /// 单据类型 + /// 业务ID + /// 业务类型 + /// + public async Task> RenderTemplateAsync(DocumentType docType, long bsId, BusinessType businessType) + { + var taskMail = await TenantDb.Queryable() + .Where(x => x.DocumentType == docType).OrderByDescending(x => x.CreateTime).FirstAsync(); + + if (taskMail == null) + return DataResult.FailedWithDesc(MultiLanguageConst.EmptyData); + if (string.IsNullOrEmpty(taskMail.Content)) + return DataResult.Success(taskMail.Content); + + var order = await actionService.Value.GetBusinessDataAsync(bsId, businessType); + if (order == null) + return DataResult.FailedWithDesc(MultiLanguageConst.EmptyData); + + var model = new MailTemplateModel { Primary = order }; + string content = await MailService.RenderTemplateAsync(docType.ToString(), taskMail.Content, model); + return DataResult.Success(content); } /// diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TemplateTranslator.cs b/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TemplateTranslator.cs deleted file mode 100644 index c10749e6..00000000 --- a/ds-wms-service/DS.WMS.Core/Op/Method/TaskInteraction/TemplateTranslator.cs +++ /dev/null @@ -1,9 +0,0 @@ -using RazorEngineCore; - -namespace DS.WMS.Core.Op.Method.TaskInteraction -{ - internal class TemplateTranslator - { - - } -} diff --git a/ds-wms-service/DS.WMS.OpApi/Controllers/TaskMailController.cs b/ds-wms-service/DS.WMS.OpApi/Controllers/TaskMailController.cs index 3db396c0..3207a082 100644 --- a/ds-wms-service/DS.WMS.OpApi/Controllers/TaskMailController.cs +++ b/ds-wms-service/DS.WMS.OpApi/Controllers/TaskMailController.cs @@ -1,4 +1,6 @@ using DS.Module.Core; +using DS.Module.Core.Data; +using DS.WMS.Core.Op.Entity; using DS.WMS.Core.Op.Entity.TaskInteraction; using DS.WMS.Core.Op.Interface.TaskInteraction; using Microsoft.AspNetCore.Mvc; @@ -21,6 +23,19 @@ namespace DS.WMS.OpApi.Controllers this.service = service; } + /// + /// 渲染模板 + /// + /// 单据类型 + /// 业务ID + /// 业务类型 + /// + [HttpGet, Route("RenderTemplate")] + public async Task> RenderTemplateAsync(DocumentType docType, long bsId, BusinessType businessType) + { + return await service.RenderTemplateAsync(docType, bsId, businessType); + } + /// /// 获取分页列表 /// @@ -59,5 +74,16 @@ namespace DS.WMS.OpApi.Controllers return await service.EditAsync(taskMail); } + + /// + /// 删除 + /// + /// + /// + [HttpPost, Route("Delete")] + public async Task DeleteAsync(IdModel idModel) + { + return await service.DeleteAsync(idModel); + } } }