邮件修改
continuous-integration/drone/push Build is passing Details

Test_IRC_Net8
he 2025-11-06 09:59:19 +08:00
parent 143d7f0c4b
commit 4d3ecd05dc
8 changed files with 21149 additions and 12 deletions

View File

@ -991,7 +991,7 @@
<param name="_userInfo"></param>
<param name="_localizer"></param>
</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>
@ -1010,7 +1010,7 @@
</member>
<member name="M:IRaCIS.Core.Application.Service.EmailLogService.GetEmailInfo(IRaCIS.Core.Application.ViewModel.GetEmailInfoInDto)">
<summary>
获取单邮件日志详情
获取单邮件日志详情
</summary>
<param name="inDto"></param>
<returns></returns>

View File

@ -75,7 +75,7 @@ public class EmailLogAddOrEdit
/// <summary>
/// 附件
/// </summary>
public List<string> Attachments { get; set; }
public List<EmaliAttachmentInfo> Attachments { get; set; }
/// <summary>
/// 日期

View File

@ -14,9 +14,11 @@ using MailKit;
using MailKit.Net.Imap;
using MailKit.Search;
using MailKit.Security;
using MassTransit;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using MimeKit;
using System.IO;
using System.Linq;
using System.Net.Mail;
using System.Threading.Tasks;
@ -32,6 +34,7 @@ namespace IRaCIS.Core.Application.Service;
/// <param name="_localizer"></param>
[ApiExplorerSettings(GroupName = "Common")]
public class EmailLogService(IRepository<EmailLog> _emailLogRepository,
IOSSService oSSService,
IRepository<EmailRecipientLog> _emailRecipientLogRepository,
IOptionsMonitor<SystemEmailSendConfig> systemEmailConfig,
IMapper _mapper, IUserInfo _userInfo, IStringLocalizer _localizer): BaseService, IEmailLogService
@ -64,7 +67,7 @@ public class EmailLogService(IRepository<EmailLog> _emailLogRepository,
}
/// <summary>
/// 获取单邮件日志详情
/// 获取单邮件日志详情
/// </summary>
/// <param name="inDto"></param>
/// <returns></returns>
@ -73,7 +76,7 @@ public class EmailLogService(IRepository<EmailLog> _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)
.FirstNotNullAsync();
@ -90,6 +93,44 @@ public class EmailLogService(IRepository<EmailLog> _emailLogRepository,
var uid = new UniqueId(uint.Parse(emailInfo.UniqueId));
var message = sentFolder.GetMessage(uid);
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();
}
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;
}
@ -208,12 +251,13 @@ public class EmailLogService(IRepository<EmailLog> _emailLogRepository,
var message = sentFolder.GetMessage(uid);
var emaillog = new EmailLog
{
Id=NewId.NextGuid(),
UniqueId = uid.ToString(),
MessageId = message.MessageId ?? string.Empty,
EmailSubject = message.Subject ?? string.Empty,
EmailDate = message.Date.UtcDateTime,
EmailStateEnum = EmailState.Success,
Attachments = new List<string>() { },
Attachments = new List<EmaliAttachmentInfo>() { },
};
var fromMailbox = message.From.Mailboxes.FirstOrDefault();

View File

@ -27,7 +27,7 @@ public class EmailLog : BaseFullAuditEntity
/// <summary>
/// 附件
/// </summary>
public List<string> Attachments { get; set; }
public List<EmaliAttachmentInfo> Attachments { get; set; }
/// <summary>
/// 日期
@ -63,3 +63,11 @@ public class EmailLog : BaseFullAuditEntity
}
public class EmaliAttachmentInfo
{
public string AttachmentName { get; set; }
public string AttachmentPath { get; set; }
}

View File

@ -95,7 +95,13 @@ public class IRaCISDBContext : DbContext
});
});
modelBuilder.Entity<EmailLog>(entity =>
{
entity.OwnsMany(x => x.Attachments, ownedNavigationBuilder =>
{
ownedNavigationBuilder.ToJson();
});
});
#region pgsql codefirst 配置 暂时屏蔽

File diff suppressed because it is too large Load Diff

View File

@ -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);
}
}
}

View File

@ -2305,10 +2305,6 @@ namespace IRaCIS.Core.Infra.EFCore.Migrations
b.Property<Guid>("Id")
.HasColumnType("uniqueidentifier");
b.Property<string>("Attachments")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("nvarchar(max)");
@ -16515,6 +16511,37 @@ namespace IRaCIS.Core.Infra.EFCore.Migrations
.OnDelete(DeleteBehavior.Cascade)
.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");
});