邮件模板配置服务增加渲染模板内容

usertest
嵇文龙 3 months ago
parent 894e1aed26
commit 57e274f643

@ -680,6 +680,9 @@ public static class MultiLanguageConst
[Description("未配置开票API请求地址请联系管理员")] [Description("未配置开票API请求地址请联系管理员")]
public const string InvoiceAPIUrlNull = "Invoice_API_Url_Null"; public const string InvoiceAPIUrlNull = "Invoice_API_Url_Null";
[Description("开票信息不完整,请检查每张发票是否添加了费用明细")]
public const string InvoiceIncomplete = "Invoice_Incomplete";
#endregion #endregion
#region 预订舱API #region 预订舱API

@ -26,7 +26,7 @@ namespace DS.WMS.Core.Invoice.Method
BaseUri = new Uri(config.GetValue<string>("InvoiceApi:BaseUrl")); BaseUri = new Uri(config.GetValue<string>("InvoiceApi:BaseUrl"));
UserKey = config.GetValue<string>("InvoiceApi:UserKey"); UserKey = config.GetValue<string>("InvoiceApi:UserKey");
string? us = config.GetValue<string>("InvoiceApi:UserSecret"); var us = config.GetValue<string>("InvoiceApi:UserSecret");
if (!us.IsNullOrEmpty()) if (!us.IsNullOrEmpty())
{ {
UserSecret = new SecureString(); UserSecret = new SecureString();

@ -3,6 +3,7 @@ using DS.WMS.Core.Application.Method;
using DS.WMS.Core.Invoice.Dtos; using DS.WMS.Core.Invoice.Dtos;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
namespace DS.WMS.Core.Invoice.Method namespace DS.WMS.Core.Invoice.Method
{ {
@ -26,52 +27,59 @@ namespace DS.WMS.Core.Invoice.Method
/// <summary> /// <summary>
/// 发起开票请求 /// 发起开票请求
/// </summary> /// </summary>
/// <param name="invoices">开票的发票信息</param> /// <param name="ids">开票的发票ID</param>
/// <returns></returns> /// <returns></returns>
public async Task<DataResult<string>> InitiateAsync(params Entity.Invoice[] invoices) public async Task<DataResult<string>> InitiateAsync(params long[] ids)
{ {
ArgumentNullException.ThrowIfNull(ids, nameof(ids));
//请求参数设置 //请求参数设置
InvoiceIssuanceRequest request = new(); InvoiceIssuanceRequest request = new()
request.order = invoices.Select(x => new InvoiceInfo
{ {
invoiceType = ((int)x.Type).ToString(), order = await TenantDb.Queryable<Entity.Invoice>().Where(x => ids.Contains(x.Id)).Select(x => new InvoiceInfo
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 = x.InvoiceDetails.IndexOf(y) + 1, invoiceType = ((int)x.Type).ToString(),
xmmc = y.Name, orderNo = x.BillNO,
spfwjc = string.Empty, email = x.Email,
specType = y.Specification, buyerTaxNum = x.TaxID,
unit = y.Unit, buyerName = x.InvoiceHeader,
num = y.Quantity.ToString(), buyerAddress = x.CustomerAddress,
taxExcludedAmount = y.UnitPrice, buyerTel = x.CustomerPhone,
taxRate = y.TaxRate.ToString(), gmfkhh = x.CustomerBankName,
tax = y.TaxAmount, gmfzh = x.CustomerAccount,
taxIncludedAmount = y.TaxUnitPrice, skyhmc = x.BankName,
goodsCode = "", //商品和服务税收分类合并编码 skyhzh = x.Account,
invoiceLineProperty = "00" checker = x.Checker,
}).ToList() 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<string>.FailedWithDesc(MultiLanguageConst.InvoiceIncomplete);
var result = await api.PostAsync<InvoiceIssuanceResult<string>>("/api/Invoice/services", request); var result = await api.PostAsync<InvoiceIssuanceResult<string>>("/api/Invoice/services", request);
if (!result.Succeeded) if (!result.Succeeded)
@ -80,14 +88,12 @@ namespace DS.WMS.Core.Invoice.Method
var invResult = result.Data; var invResult = result.Data;
if (invResult.Success) if (invResult.Success)
{ {
return DataResult<string>.Success(invResult.Data); return DataResult<string>.Success(invResult.Data);
} }
else else
{ {
if (invResult.Code == 1) if (invResult.Code == 1)
return await InitiateAsync(invoices); return await InitiateAsync(ids);
return DataResult<string>.Failed(invResult.Message); return DataResult<string>.Failed(invResult.Message);
} }

@ -167,7 +167,7 @@ namespace DS.WMS.Core.Invoice.Method
#pragma warning disable CS4014 #pragma warning disable CS4014
/// <summary> /// <summary>
/// 提交发票开票 /// 提交
/// </summary> /// </summary>
/// <param name="request">请求参数</param> /// <param name="request">请求参数</param>
/// <returns></returns> /// <returns></returns>

@ -1,5 +1,6 @@
using DS.Module.Core; using DS.Module.Core;
using DS.Module.Core.Data; using DS.Module.Core.Data;
using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.Op.Entity.TaskInteraction; using DS.WMS.Core.Op.Entity.TaskInteraction;
namespace DS.WMS.Core.Op.Interface.TaskInteraction namespace DS.WMS.Core.Op.Interface.TaskInteraction
@ -9,6 +10,15 @@ namespace DS.WMS.Core.Op.Interface.TaskInteraction
/// </summary> /// </summary>
public interface ITaskMailService public interface ITaskMailService
{ {
/// <summary>
/// 渲染模板
/// </summary>
/// <param name="docType">单据类型</param>
/// <param name="bsId">业务ID</param>
/// <param name="businessType">业务类型</param>
/// <returns></returns>
Task<DataResult<string>> RenderTemplateAsync(DocumentType docType, long bsId, BusinessType businessType);
/// <summary> /// <summary>
/// 获取分页列表 /// 获取分页列表
/// </summary> /// </summary>

@ -41,7 +41,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
Db.QueryFilter.Clear<ITenantId>(); Db.QueryFilter.Clear<ITenantId>();
} }
static async Task<string> RenderTemplateAsync(string name, string templateText, object model, IRazorEngine? razorEngine = null) internal static async Task<string> RenderTemplateAsync(string name, string templateText, object model, IRazorEngine? razorEngine = null)
{ {
int hashCode = name.GetHashCode(); int hashCode = name.GetHashCode();

@ -1,8 +1,10 @@
using DS.Module.Core; using DS.Module.Core;
using DS.Module.Core.Data; using DS.Module.Core.Data;
using DS.Module.Core.Extensions; using DS.Module.Core.Extensions;
using DS.WMS.Core.Op.Entity;
using DS.WMS.Core.Op.Entity.TaskInteraction; using DS.WMS.Core.Op.Entity.TaskInteraction;
using DS.WMS.Core.Op.Interface.TaskInteraction; using DS.WMS.Core.Op.Interface.TaskInteraction;
using Microsoft.Extensions.DependencyInjection;
namespace DS.WMS.Core.Op.Method.TaskInteraction namespace DS.WMS.Core.Op.Method.TaskInteraction
{ {
@ -11,12 +13,41 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
/// </summary> /// </summary>
public class TaskMailService : ServiceBase, ITaskMailService public class TaskMailService : ServiceBase, ITaskMailService
{ {
Lazy<IActionManagerService> actionService;
/// <summary> /// <summary>
/// 初始化 /// 初始化
/// </summary> /// </summary>
/// <param name="provider"></param> /// <param name="provider"></param>
public TaskMailService(IServiceProvider provider) : base(provider) public TaskMailService(IServiceProvider provider) : base(provider)
{ {
actionService = new Lazy<IActionManagerService>(provider.GetRequiredService<IActionManagerService>());
}
/// <summary>
/// 渲染模板
/// </summary>
/// <param name="docType">单据类型</param>
/// <param name="bsId">业务ID</param>
/// <param name="businessType">业务类型</param>
/// <returns></returns>
public async Task<DataResult<string>> RenderTemplateAsync(DocumentType docType, long bsId, BusinessType businessType)
{
var taskMail = await TenantDb.Queryable<BusinessTaskMail>()
.Where(x => x.DocumentType == docType).OrderByDescending(x => x.CreateTime).FirstAsync();
if (taskMail == null)
return DataResult<string>.FailedWithDesc(MultiLanguageConst.EmptyData);
if (string.IsNullOrEmpty(taskMail.Content))
return DataResult<string>.Success(taskMail.Content);
var order = await actionService.Value.GetBusinessDataAsync(bsId, businessType);
if (order == null)
return DataResult<string>.FailedWithDesc(MultiLanguageConst.EmptyData);
var model = new MailTemplateModel { Primary = order };
string content = await MailService.RenderTemplateAsync(docType.ToString(), taskMail.Content, model);
return DataResult<string>.Success(content);
} }
/// <summary> /// <summary>

@ -1,9 +0,0 @@
using RazorEngineCore;
namespace DS.WMS.Core.Op.Method.TaskInteraction
{
internal class TemplateTranslator
{
}
}

@ -1,4 +1,6 @@
using DS.Module.Core; 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.Entity.TaskInteraction;
using DS.WMS.Core.Op.Interface.TaskInteraction; using DS.WMS.Core.Op.Interface.TaskInteraction;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -21,6 +23,19 @@ namespace DS.WMS.OpApi.Controllers
this.service = service; this.service = service;
} }
/// <summary>
/// 渲染模板
/// </summary>
/// <param name="docType">单据类型</param>
/// <param name="bsId">业务ID</param>
/// <param name="businessType">业务类型</param>
/// <returns></returns>
[HttpGet, Route("RenderTemplate")]
public async Task<DataResult<string>> RenderTemplateAsync(DocumentType docType, long bsId, BusinessType businessType)
{
return await service.RenderTemplateAsync(docType, bsId, businessType);
}
/// <summary> /// <summary>
/// 获取分页列表 /// 获取分页列表
/// </summary> /// </summary>
@ -59,5 +74,16 @@ namespace DS.WMS.OpApi.Controllers
return await service.EditAsync(taskMail); return await service.EditAsync(taskMail);
} }
/// <summary>
/// 删除
/// </summary>
/// <param name="idModel"></param>
/// <returns></returns>
[HttpPost, Route("Delete")]
public async Task<DataResult> DeleteAsync(IdModel idModel)
{
return await service.DeleteAsync(idModel);
}
} }
} }

Loading…
Cancel
Save