邮件修改
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
143d7f0c4b
commit
4d3ecd05dc
|
|
@ -991,7 +991,7 @@
|
||||||
<param name="_userInfo"></param>
|
<param name="_userInfo"></param>
|
||||||
<param name="_localizer"></param>
|
<param name="_localizer"></param>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:IRaCIS.Core.Application.Service.EmailLogService.#ctor(IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.EmailLog},IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.EmailRecipientLog},Microsoft.Extensions.Options.IOptionsMonitor{IRaCIS.Core.Domain.Share.SystemEmailSendConfig},AutoMapper.IMapper,IRaCIS.Core.Domain.Share.IUserInfo,Microsoft.Extensions.Localization.IStringLocalizer)">
|
<member name="M:IRaCIS.Core.Application.Service.EmailLogService.#ctor(IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.EmailLog},IRaCIS.Core.Application.Helper.IOSSService,IRaCIS.Core.Infra.EFCore.IRepository{IRaCIS.Core.Domain.Models.EmailRecipientLog},Microsoft.Extensions.Options.IOptionsMonitor{IRaCIS.Core.Domain.Share.SystemEmailSendConfig},AutoMapper.IMapper,IRaCIS.Core.Domain.Share.IUserInfo,Microsoft.Extensions.Localization.IStringLocalizer)">
|
||||||
<summary>
|
<summary>
|
||||||
邮件日志
|
邮件日志
|
||||||
</summary>
|
</summary>
|
||||||
|
|
@ -1010,7 +1010,7 @@
|
||||||
</member>
|
</member>
|
||||||
<member name="M:IRaCIS.Core.Application.Service.EmailLogService.GetEmailInfo(IRaCIS.Core.Application.ViewModel.GetEmailInfoInDto)">
|
<member name="M:IRaCIS.Core.Application.Service.EmailLogService.GetEmailInfo(IRaCIS.Core.Application.ViewModel.GetEmailInfoInDto)">
|
||||||
<summary>
|
<summary>
|
||||||
获取单挑邮件日志详情
|
获取单条邮件日志详情
|
||||||
</summary>
|
</summary>
|
||||||
<param name="inDto"></param>
|
<param name="inDto"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ public class EmailLogAddOrEdit
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 附件
|
/// 附件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<string> Attachments { get; set; }
|
public List<EmaliAttachmentInfo> Attachments { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 日期
|
/// 日期
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,11 @@ using MailKit;
|
||||||
using MailKit.Net.Imap;
|
using MailKit.Net.Imap;
|
||||||
using MailKit.Search;
|
using MailKit.Search;
|
||||||
using MailKit.Security;
|
using MailKit.Security;
|
||||||
|
using MassTransit;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using MimeKit;
|
using MimeKit;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Mail;
|
using System.Net.Mail;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
@ -32,6 +34,7 @@ namespace IRaCIS.Core.Application.Service;
|
||||||
/// <param name="_localizer"></param>
|
/// <param name="_localizer"></param>
|
||||||
[ApiExplorerSettings(GroupName = "Common")]
|
[ApiExplorerSettings(GroupName = "Common")]
|
||||||
public class EmailLogService(IRepository<EmailLog> _emailLogRepository,
|
public class EmailLogService(IRepository<EmailLog> _emailLogRepository,
|
||||||
|
IOSSService oSSService,
|
||||||
IRepository<EmailRecipientLog> _emailRecipientLogRepository,
|
IRepository<EmailRecipientLog> _emailRecipientLogRepository,
|
||||||
IOptionsMonitor<SystemEmailSendConfig> systemEmailConfig,
|
IOptionsMonitor<SystemEmailSendConfig> systemEmailConfig,
|
||||||
IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer): BaseService, IEmailLogService
|
IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer): BaseService, IEmailLogService
|
||||||
|
|
@ -64,7 +67,7 @@ public class EmailLogService(IRepository<EmailLog> _emailLogRepository,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取单挑邮件日志详情
|
/// 获取单条邮件日志详情
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="inDto"></param>
|
/// <param name="inDto"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
|
|
@ -73,7 +76,7 @@ public class EmailLogService(IRepository<EmailLog> _emailLogRepository,
|
||||||
{
|
{
|
||||||
|
|
||||||
var emailInfo=await _emailLogRepository
|
var emailInfo=await _emailLogRepository
|
||||||
.Where(x => x.Id == inDto.Id)
|
.Where(x => x.Id == inDto.Id).Include(x=>x.EmailRecipientLogList)
|
||||||
.ProjectTo<GetEmailInfoOutDto>(_mapper.ConfigurationProvider)
|
.ProjectTo<GetEmailInfoOutDto>(_mapper.ConfigurationProvider)
|
||||||
.FirstNotNullAsync();
|
.FirstNotNullAsync();
|
||||||
|
|
||||||
|
|
@ -90,6 +93,44 @@ public class EmailLogService(IRepository<EmailLog> _emailLogRepository,
|
||||||
var uid = new UniqueId(uint.Parse(emailInfo.UniqueId));
|
var uid = new UniqueId(uint.Parse(emailInfo.UniqueId));
|
||||||
var message = sentFolder.GetMessage(uid);
|
var message = sentFolder.GetMessage(uid);
|
||||||
emailInfo.Content = message.HtmlBody ?? string.Empty;
|
emailInfo.Content = message.HtmlBody ?? string.Empty;
|
||||||
|
|
||||||
|
|
||||||
|
if (emailInfo.Attachments.Count == 0)
|
||||||
|
{
|
||||||
|
List< EmaliAttachmentInfo > attachmentInfos = new List<EmaliAttachmentInfo>();
|
||||||
|
foreach (var att in message.Attachments)
|
||||||
|
{
|
||||||
|
EmaliAttachmentInfo emaliAttachmentInfo = new EmaliAttachmentInfo();
|
||||||
|
emaliAttachmentInfo.AttachmentName = att.ContentDisposition?.FileName ?? att.ContentType.Name ?? "unknown";
|
||||||
|
|
||||||
|
// 2. 解码后的流直接上传,不落盘
|
||||||
|
if (att is MimePart part)
|
||||||
|
{
|
||||||
|
// 重要:每次上传新建一个独立流,否则迭代过程中流位置会乱
|
||||||
|
await using var decodeStream = new MemoryStream();
|
||||||
|
await part.Content.DecodeToAsync(decodeStream);
|
||||||
|
decodeStream.Position = 0;
|
||||||
|
|
||||||
|
// 3. 调你自己的 OSS 方法
|
||||||
|
emaliAttachmentInfo.AttachmentPath = await oSSService.UploadToOSSAsync(
|
||||||
|
fileStream: decodeStream,
|
||||||
|
oosFolderPath: $"EmailAttachment/{emailInfo.Id}", // OSS 虚拟目录
|
||||||
|
fileRealName: emaliAttachmentInfo.AttachmentName,
|
||||||
|
isFileNameAddGuid: true); // 让方法自己在文件名前加 Guid
|
||||||
|
|
||||||
|
attachmentInfos.Add(emaliAttachmentInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
await _emailLogRepository.UpdatePartialFromQueryAsync(emailInfo.Id.Value, x => new EmailLog()
|
||||||
|
{
|
||||||
|
Attachments = attachmentInfos
|
||||||
|
});
|
||||||
|
emailInfo.Attachments = attachmentInfos;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
sentFolder.Close();
|
sentFolder.Close();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
@ -102,6 +143,8 @@ public class EmailLogService(IRepository<EmailLog> _emailLogRepository,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//var ossRelativePath = await oSSService.UploadToOSSAsync(fileStream, $"{trialId.ToString()}/InspectionUpload/DataReconciliation", realFileName);
|
||||||
|
|
||||||
return emailInfo;
|
return emailInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -208,12 +251,13 @@ public class EmailLogService(IRepository<EmailLog> _emailLogRepository,
|
||||||
var message = sentFolder.GetMessage(uid);
|
var message = sentFolder.GetMessage(uid);
|
||||||
var emaillog = new EmailLog
|
var emaillog = new EmailLog
|
||||||
{
|
{
|
||||||
|
Id=NewId.NextGuid(),
|
||||||
UniqueId = uid.ToString(),
|
UniqueId = uid.ToString(),
|
||||||
MessageId = message.MessageId ?? string.Empty,
|
MessageId = message.MessageId ?? string.Empty,
|
||||||
EmailSubject = message.Subject ?? string.Empty,
|
EmailSubject = message.Subject ?? string.Empty,
|
||||||
EmailDate = message.Date.UtcDateTime,
|
EmailDate = message.Date.UtcDateTime,
|
||||||
EmailStateEnum = EmailState.Success,
|
EmailStateEnum = EmailState.Success,
|
||||||
Attachments = new List<string>() { },
|
Attachments = new List<EmaliAttachmentInfo>() { },
|
||||||
};
|
};
|
||||||
|
|
||||||
var fromMailbox = message.From.Mailboxes.FirstOrDefault();
|
var fromMailbox = message.From.Mailboxes.FirstOrDefault();
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ public class EmailLog : BaseFullAuditEntity
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 附件
|
/// 附件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<string> Attachments { get; set; }
|
public List<EmaliAttachmentInfo> Attachments { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 日期
|
/// 日期
|
||||||
|
|
@ -63,3 +63,11 @@ public class EmailLog : BaseFullAuditEntity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public class EmaliAttachmentInfo
|
||||||
|
{
|
||||||
|
public string AttachmentName { get; set; }
|
||||||
|
|
||||||
|
public string AttachmentPath { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,13 @@ public class IRaCISDBContext : DbContext
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity<EmailLog>(entity =>
|
||||||
|
{
|
||||||
|
entity.OwnsMany(x => x.Attachments, ownedNavigationBuilder =>
|
||||||
|
{
|
||||||
|
ownedNavigationBuilder.ToJson();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
#region pgsql codefirst 配置 暂时屏蔽
|
#region pgsql codefirst 配置 暂时屏蔽
|
||||||
|
|
|
||||||
21016
IRaCIS.Core.Infra.EFCore/Migrations/20251106015642_AttachmentInfo.Designer.cs
generated
Normal file
21016
IRaCIS.Core.Infra.EFCore/Migrations/20251106015642_AttachmentInfo.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,36 @@
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace IRaCIS.Core.Infra.EFCore.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AttachmentInfo : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Attachments",
|
||||||
|
table: "EmailLog",
|
||||||
|
type: "nvarchar(max)",
|
||||||
|
nullable: true,
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "nvarchar(max)");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AlterColumn<string>(
|
||||||
|
name: "Attachments",
|
||||||
|
table: "EmailLog",
|
||||||
|
type: "nvarchar(max)",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: "",
|
||||||
|
oldClrType: typeof(string),
|
||||||
|
oldType: "nvarchar(max)",
|
||||||
|
oldNullable: true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2305,10 +2305,6 @@ namespace IRaCIS.Core.Infra.EFCore.Migrations
|
||||||
b.Property<Guid>("Id")
|
b.Property<Guid>("Id")
|
||||||
.HasColumnType("uniqueidentifier");
|
.HasColumnType("uniqueidentifier");
|
||||||
|
|
||||||
b.Property<string>("Attachments")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("nvarchar(max)");
|
|
||||||
|
|
||||||
b.Property<string>("Content")
|
b.Property<string>("Content")
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("nvarchar(max)");
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
@ -16515,6 +16511,37 @@ namespace IRaCIS.Core.Infra.EFCore.Migrations
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
|
b.OwnsMany("IRaCIS.Core.Domain.Models.EmaliAttachmentInfo", "Attachments", b1 =>
|
||||||
|
{
|
||||||
|
b1.Property<Guid>("EmailLogId")
|
||||||
|
.HasColumnType("uniqueidentifier");
|
||||||
|
|
||||||
|
b1.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b1.Property<string>("AttachmentName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(400)
|
||||||
|
.HasColumnType("nvarchar(400)");
|
||||||
|
|
||||||
|
b1.Property<string>("AttachmentPath")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(400)
|
||||||
|
.HasColumnType("nvarchar(400)");
|
||||||
|
|
||||||
|
b1.HasKey("EmailLogId", "Id");
|
||||||
|
|
||||||
|
b1.ToTable("EmailLog");
|
||||||
|
|
||||||
|
b1.ToJson("Attachments");
|
||||||
|
|
||||||
|
b1.WithOwner()
|
||||||
|
.HasForeignKey("EmailLogId");
|
||||||
|
});
|
||||||
|
|
||||||
|
b.Navigation("Attachments");
|
||||||
|
|
||||||
b.Navigation("CreateUserRole");
|
b.Navigation("CreateUserRole");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue