邮件模板接收人设置与客户属性统一

dev
嵇文龙 1 week ago
parent e5aa876eb1
commit 59a9384a4f

@ -1,5 +1,4 @@
using DS.Module.Core.Enums;
using SqlSugar;
using SqlSugar;
namespace DS.WMS.Core.Info.Entity
{

@ -61,8 +61,8 @@ namespace DS.WMS.Core.TaskInteraction.Entity
/// <summary>
/// 接收人设置
/// </summary>
[Navigate(NavigateType.OneToOne, nameof(Id))]
public BusinessTaskMailReceiver? Receiver { get; set; }
[Navigate(NavigateType.OneToMany, nameof(BusinessTaskMailReceiver.TaskMailId))]
public List<BusinessTaskMailReceiver>? Receivers { get; set; }
/// <summary>
/// 发送人设置

@ -9,129 +9,27 @@ namespace DS.WMS.Core.TaskInteraction.Entity
public class BusinessTaskMailReceiver
{
/// <summary>
/// 任务邮件配置ID
/// </summary>
[SugarColumn(IsPrimaryKey = true)]
public long TaskMailId { get; set; }
/// <summary>
/// Desc:是否船公司
/// </summary>
[SugarColumn(ColumnDescription = "是否船公司", DefaultValue = "0")]
public bool IsCarrier { get; set; }
/// <summary>
/// Desc:是否订舱公司
/// ID
/// </summary>
[SugarColumn(ColumnDescription = "是否订舱公司", DefaultValue = "0")]
public bool IsBooking { get; set; }
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public long Id { get; set; }
/// <summary>
/// Desc:是否场站
/// </summary>
[SugarColumn(ColumnDescription = "是否场站", DefaultValue = "0")]
public bool IsYard { get; set; }
/// <summary>
/// Desc:是否车队
/// </summary>
[SugarColumn(ColumnDescription = "是否车队", DefaultValue = "0")]
public bool IsTruck { get; set; }
/// <summary>
/// Desc:是否委托单位
/// </summary>
[SugarColumn(ColumnDescription = "是否委托单位", DefaultValue = "0")]
public bool IsController { get; set; }
///// <summary>
///// Desc:是否报关行
///// </summary>
//[SugarColumn(ColumnDescription = "是否报关行", DefaultValue = "0")]
//public bool IsCustom { get; set; }
///// <summary>
///// Desc:是否代理(国外)
///// </summary>
//[SugarColumn(ColumnDescription = "是否代理(国外)", DefaultValue = "0")]
//public bool IsAgent { get; set; }
///// <summary>
///// Desc:是否代理(国内)
///// </summary>
//[SugarColumn(ColumnDescription = "是否代理(国内)", DefaultValue = "0")]
//public bool IsAgentCn { get; set; }
///// <summary>
///// Desc:是否快递公司
///// </summary>
//[SugarColumn(ColumnDescription = "是否快递公司", DefaultValue = "0")]
//public bool IsExpress { get; set; }
///// <summary>
///// Desc:是否航空公司
///// </summary>
//[SugarColumn(ColumnDescription = "是否航空公司", DefaultValue = "0")]
//public bool IsAirLines { get; set; }
/// <summary>
/// Desc:是否发货人
/// 任务邮件配置ID
/// </summary>
[SugarColumn(ColumnDescription = "是否发货人", DefaultValue = "0")]
public bool IsShipper { get; set; }
[SugarColumn(IsPrimaryKey = true)]
public long TaskMailId { get; set; }
/// <summary>
/// Desc:是否收货人
/// 属性值
/// </summary>
[SugarColumn(ColumnDescription = "是否收货人", DefaultValue = "0")]
public bool IsConsignee { get; set; }
///// <summary>
///// Desc:是否通知人
///// </summary>
//[SugarColumn(ColumnDescription = "是否通知人", DefaultValue = "0")]
//public bool IsNotifyParty { get; set; }
///// <summary>
///// Desc:是否仓库
///// </summary>
//[SugarColumn(ColumnDescription = "是否仓库", DefaultValue = "0")]
//public bool IsWareHouse { get; set; }
///// <summary>
///// Desc:是否保险公司
///// </summary>
//[SugarColumn(ColumnDescription = "是否保险公司", DefaultValue = "0")]
//public bool IsInsurer { get; set; }
///// <summary>
///// Desc:是否租箱公司
///// </summary>
//[SugarColumn(ColumnDescription = "是否租箱公司", DefaultValue = "0")]
//public bool IsLeasing { get; set; }
///// <summary>
///// Desc:是否贸易代理
///// </summary>
//[SugarColumn(ColumnDescription = "是否贸易代理", DefaultValue = "0")]
//public bool IsTradingAgency { get; set; }
///// <summary>
///// Desc:是否船代
///// </summary>
//[SugarColumn(ColumnDescription = "是否船代", DefaultValue = "0")]
//public bool IsShipAgency { get; set; }
///// <summary>
///// Desc:是否经营单位
///// </summary>
//[SugarColumn(ColumnDescription = "是否经营单位", DefaultValue = "0")]
//public bool IsEnterprise { get; set; }
[SugarColumn(ColumnDescription = "属性值", Length = 50, IsNullable = false)]
public string Value { get; set; }
/// <summary>
/// Desc:是否国内发货人
/// 属性名称
/// </summary>
[SugarColumn(ColumnDescription = "是否国内发货人", DefaultValue = "0")]
public bool IsShipperCn { get; set; }
[SugarColumn(ColumnDescription = "属性名称", Length = 50, IsNullable = true)]
public string? Name { get; set; }
}
}

@ -1,5 +1,4 @@
using DS.Module.Core;
using DS.Module.UserModule;
using DS.WMS.Core.Sys.Entity;
using DS.WMS.Core.TaskInteraction.Dtos;
using DS.WMS.Core.TaskInteraction.Entity;
@ -40,10 +39,12 @@ namespace DS.WMS.Core.TaskInteraction.Method.Jobs
}
long id = long.Parse(config.Value);
var mailTemplate = await TenantDb.Queryable<BusinessTaskMail>().FirstAsync(x => x.Id == id);
var mailTemplate = await TenantDb.Queryable<BusinessTaskMail>()
.Includes(x => x.Sender).Includes(x => x.Receivers).Includes(x => x.CC).Includes(x => x.Attachments)
.FirstAsync(x => x.Id == id);
MailGenerator generator = new(ServiceProvider);
var model = await generator.GetBusinessModelAsync(mailTemplate, context.JobInfo.BusinessId, context.JobInfo.BusinessType);
await generator.SendAsync(mailTemplate, model);
context.Result = await generator.SendAsync(mailTemplate, model);
}
}
}

@ -298,34 +298,10 @@ namespace DS.WMS.Core.TaskInteraction.Method
}
//设置收件人
if (mailConfig.Receiver == null)
if (mailConfig.Receivers.Count == 0)
return DataResult.Failed("邮件模板未设置收件人");
List<string> receiverTypes = [];
if (mailConfig.Receiver.IsCarrier)
receiverTypes.Add("carrier");
if (mailConfig.Receiver.IsBooking)
receiverTypes.Add("booking");
if (mailConfig.Receiver.IsYard)
receiverTypes.Add("yard");
if (mailConfig.Receiver.IsTruck)
receiverTypes.Add("truck");
if (mailConfig.Receiver.IsController)
receiverTypes.Add("controller");
if (mailConfig.Receiver.IsShipper)
receiverTypes.Add("shipper");
if (mailConfig.Receiver.IsShipperCn)
receiverTypes.Add("shippercn");
if (mailConfig.Receiver.IsConsignee)
receiverTypes.Add("consignee");
var receiverTypes = mailConfig.Receivers.Select(x => x.Value);
templateModel.Receivers = await TenantDb.Queryable<BusinessOrderContact>().Where(x => receiverTypes.Contains(x.CustomerType)
&& x.Email != null && x.Email != string.Empty && x.BusinessId == templateModel.BusinessId && x.BusinessType == templateModel.BusinessType)
.Select(x => new MailReceiver { DisplayName = x.Name, MailAddress = x.Email }).ToListAsync();

@ -83,7 +83,7 @@ namespace DS.WMS.Core.TaskInteraction.Method
{
var whereList = request.GetConditionalModels(Db);
return await TenantDb.Queryable<BusinessTaskMail>()
.Includes(x => x.Receiver).Includes(x => x.Sender).Includes(x => x.CC)
.Includes(x => x.Receivers).Includes(x => x.Sender).Includes(x => x.CC)
.Where(whereList).ToQueryPageAsync(request.PageCondition);
}
@ -95,7 +95,7 @@ namespace DS.WMS.Core.TaskInteraction.Method
public async Task<DataResult<BusinessTaskMail>> GetAsync(long id)
{
var entity = await TenantDb.Queryable<BusinessTaskMail>()
.Includes(x => x.Receiver).Includes(x => x.Sender).Includes(x => x.CC).Includes(x => x.Attachments)
.Includes(x => x.Receivers).Includes(x => x.Sender).Includes(x => x.CC).Includes(x => x.Attachments)
.Where(x => x.Id == id).FirstAsync();
return DataResult<BusinessTaskMail>.Success(entity);
@ -109,7 +109,7 @@ namespace DS.WMS.Core.TaskInteraction.Method
public async Task<BusinessTaskMail> GetAsync(string name)
{
return await TenantDb.Queryable<BusinessTaskMail>()
.Includes(x => x.Receiver).Includes(x => x.Sender).Includes(x => x.CC).Includes(x => x.Attachments)
.Includes(x => x.Receivers).Includes(x => x.Sender).Includes(x => x.CC).Includes(x => x.Attachments)
.Where(x => x.Name.Contains(name)).FirstAsync();
}
@ -125,19 +125,25 @@ namespace DS.WMS.Core.TaskInteraction.Method
{
if (taskMail.Id == 0)
{
taskMail.Receiver ??= new();
taskMail.Receivers ??= [];
taskMail.Sender ??= new();
taskMail.CC ??= new();
taskMail = await TenantDb.InsertNav(taskMail)
.Include(x => x.Receiver).Include(x => x.Sender).Include(x => x.CC)
.ExecuteReturnEntityAsync();
taskMail = await TenantDb.InsertNav(taskMail).Include(x => x.Sender).Include(x => x.CC).ExecuteReturnEntityAsync();
}
else
{
await TenantDb.UpdateNav(taskMail)
.Include(x => x.Receiver).Include(x => x.Sender).Include(x => x.CC)
.ExecuteCommandAsync();
await TenantDb.UpdateNav(taskMail).Include(x => x.Sender).Include(x => x.CC).ExecuteCommandAsync();
}
if (taskMail.Receivers?.Count > 0)
{
var list = taskMail.Receivers.FindAll(x => x.TaskMailId == 0);
foreach (var item in list)
item.TaskMailId = taskMail.Id;
await TenantDb.Deleteable<BusinessTaskMailReceiver>().Where(x => x.TaskMailId == taskMail.Id).ExecuteCommandAsync();
await TenantDb.Insertable(taskMail.Receivers).ExecuteCommandAsync();
}
if (taskMail.Attachments?.Count > 0)
@ -148,8 +154,6 @@ namespace DS.WMS.Core.TaskInteraction.Method
await TenantDb.Deleteable<BusinessTaskAttachment>().Where(x => x.TaskMailId == taskMail.Id).ExecuteCommandAsync();
await TenantDb.Insertable(taskMail.Attachments).ExecuteCommandAsync();
//await TenantDb.Storageable(taskMail.Attachments).DefaultAddElseUpdate().ExecuteCommandAsync();
}
await TenantDb.Ado.CommitTranAsync();
@ -175,7 +179,7 @@ namespace DS.WMS.Core.TaskInteraction.Method
try
{
await TenantDb.DeleteNav<BusinessTaskMail>(x => model.Ids.Contains(x.Id))
.Include(x => x.Receiver).Include(x => x.Sender).Include(x => x.CC).Include(x => x.Attachments)
.Include(x => x.Receivers).Include(x => x.Sender).Include(x => x.CC).Include(x => x.Attachments)
.ExecuteCommandAsync();
await TenantDb.Ado.CommitTranAsync();

@ -1,8 +1,13 @@
using DS.Module.Core;
using DS.Module.Core.Data;
using DS.Module.Core.Extensions;
using DS.WMS.Core.Sys.Entity;
using DS.WMS.Core.TaskInteraction.Entity;
using DS.WMS.Core.TaskInteraction.Interface;
using Fasterflect;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
namespace DS.WMS.OpApi.Controllers
{
@ -95,7 +100,7 @@ namespace DS.WMS.OpApi.Controllers
[HttpPost, Route("Edit")]
public async Task<DataResult> EditAsync([FromBody] BusinessTaskMail taskMail)
{
if (taskMail.Receiver == null)
if (taskMail.Receivers == null)
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TaskMailReceiverNotNull));
if (taskMail.Sender == null)

Loading…
Cancel
Save