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

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

@ -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

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

@ -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,13 +27,16 @@ namespace DS.WMS.Core.Invoice.Method
/// <summary>
/// 发起开票请求
/// </summary>
/// <param name="invoices">开票的发票信息</param>
/// <param name="ids">开票的发票ID</param>
/// <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();
request.order = invoices.Select(x => new InvoiceInfo
InvoiceIssuanceRequest request = new()
{
order = await TenantDb.Queryable<Entity.Invoice>().Where(x => ids.Contains(x.Id)).Select(x => new InvoiceInfo
{
invoiceType = ((int)x.Type).ToString(),
orderNo = x.BillNO,
@ -57,7 +61,7 @@ namespace DS.WMS.Core.Invoice.Method
//---------发票明细---------
invoiceDetail = x.InvoiceDetails.Select(y => new InvoiceDetailInfo
{
mxxh = x.InvoiceDetails.IndexOf(y) + 1,
mxxh = SqlFunc.RowNumber(y.Id), //x.InvoiceDetails.IndexOf(y) + 1,
xmmc = y.Name,
spfwjc = string.Empty,
specType = y.Specification,
@ -71,7 +75,11 @@ namespace DS.WMS.Core.Invoice.Method
invoiceLineProperty = "00"
}).ToList()
}).ToList();
}).ToListAsync()
};
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);
if (!result.Succeeded)
@ -80,14 +88,12 @@ namespace DS.WMS.Core.Invoice.Method
var invResult = result.Data;
if (invResult.Success)
{
return DataResult<string>.Success(invResult.Data);
}
else
{
if (invResult.Code == 1)
return await InitiateAsync(invoices);
return await InitiateAsync(ids);
return DataResult<string>.Failed(invResult.Message);
}

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

@ -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
/// </summary>
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>

@ -41,7 +41,7 @@ namespace DS.WMS.Core.Op.Method.TaskInteraction
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();

@ -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
/// </summary>
public class TaskMailService : ServiceBase, ITaskMailService
{
Lazy<IActionManagerService> actionService;
/// <summary>
/// 初始化
/// </summary>
/// <param name="provider"></param>
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>

@ -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.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;
}
/// <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>
@ -59,5 +74,16 @@ namespace DS.WMS.OpApi.Controllers
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