修改系统邮件配置
continuous-integration/drone/push Build is passing Details

Test_HIR_Net8
hang 2025-08-19 17:40:06 +08:00
parent 9300f5756d
commit bee3084bbf
8 changed files with 19020 additions and 28 deletions

View File

@ -15567,6 +15567,13 @@
系统邮件配置表
</summary>
</member>
<member name="M:IRaCIS.Core.Application.Contracts.EmailNoticeConfigService.BatchUpdateEmail(System.Collections.Generic.List{IRaCIS.Core.Application.Contracts.BatchUpdateEmailTopicCommand})">
<summary>
批量更新邮件主题中英文
</summary>
<param name="inCommandList"></param>
<returns></returns>
</member>
<member name="T:IRaCIS.Core.Application.Contracts.ISystemBasicDataService">
<summary>
ISystemBasicDataService

View File

@ -72,7 +72,7 @@ namespace IRaCIS.Core.Application.Contracts
public UserTypeEnum? CopyUserType { get; set; }
public BusinessLevel? BusinessLevelEnum { get; set; }
}
@ -96,9 +96,6 @@ namespace IRaCIS.Core.Application.Contracts
public bool IsDeleted { get; set; }
public CriterionType? CriterionTypeEnum { get; set; }
/// <summary> 业务模块 /// </summary>
public int BusinessModuleEnum { get; set; }
@ -140,6 +137,24 @@ namespace IRaCIS.Core.Application.Contracts
public int? EmailDelaySeconds { get; set; }
[Comment("邮件配置的多个标准")]
public List<CriterionType>? CriterionTypeList { get; set; }
//public CriterionType? CriterionTypeEnum { get; set; }
}
public class BatchUpdateEmailTopicCommand
{
[NotDefault]
public Guid Id { get; set; }
public string EmailTopic { get; set; } = string.Empty;
public string EmailTopicCN { get; set; } = string.Empty;
}

View File

@ -4,8 +4,11 @@
// 对此文件的更改可能会导致不正确的行为,并且如果重新生成代码,这些更改将会丢失。
//--------------------------------------------------------------------
using IRaCIS.Core.Application.Helper;
using IRaCIS.Core.Domain.Share;
using Microsoft.AspNetCore.Mvc;
using NPOI.SS.Formula.Functions;
using System.Linq;
using System.Text.RegularExpressions;
namespace IRaCIS.Core.Application.Contracts
@ -25,7 +28,8 @@ namespace IRaCIS.Core.Application.Contracts
.WhereIf(inQuery.SystemLevel == null, t => t.SystemLevel == SysEmailLevel.not_sys)
.WhereIf(inQuery.SystemLevel != null, t => t.SystemLevel == inQuery.SystemLevel)
.WhereIf(inQuery.IsDistinguishCriteria != null, t => t.IsDistinguishCriteria == inQuery.IsDistinguishCriteria)
.WhereIf(inQuery.CriterionTypeEnum != null, t => t.CriterionTypeEnum == inQuery.CriterionTypeEnum)
.WhereIf(inQuery.BusinessLevelEnum != null, t => t.BusinessLevelEnum == inQuery.BusinessLevelEnum)
.WhereIf(inQuery.CriterionTypeEnum != null, t => t.CriterionTypeList.Any(t => t == inQuery.CriterionTypeEnum))
.WhereIf(inQuery.BusinessModuleEnum != null, t => t.BusinessModuleEnum == inQuery.BusinessModuleEnum)
.WhereIf(inQuery.BusinessScenarioEnum != null, t => t.BusinessScenarioEnum == inQuery.BusinessScenarioEnum)
.WhereIf(inQuery.IsReturnRequired != null, t => t.IsReturnRequired == inQuery.IsReturnRequired)
@ -38,14 +42,84 @@ namespace IRaCIS.Core.Application.Contracts
return await emailNoticeConfigQueryable.ToPagedListAsync(inQuery);
}
/// <summary>
/// 批量更新邮件主题中英文
/// </summary>
/// <param name="inCommandList"></param>
/// <returns></returns>
public async Task<IResponseOutput> BatchUpdateEmail(List<BatchUpdateEmailTopicCommand> inCommandList)
{
var findIdList = inCommandList.Select(x => x.Id).ToList();
var regex = new Regex(@"\{\s*\d+\s*\}");
foreach (var inCommand in inCommandList)
{
if (regex.Matches($"{inCommand.EmailTopic}{inCommand.EmailTopicCN}")
.Any(t => t.Value.Contains(" ")))
{
//邮件模板占位符不允许有空格,请核查占位符的地方
return ResponseOutput.NotOk(I18n.T("EmailNoticeConfig_ContainEmpty"));
}
}
var list = _emailNoticeConfigrepository.Where(t => findIdList.Contains(t.Id), true).ToList();
foreach (var item in list)
{
var exist = inCommandList.FirstOrDefault(t => t.Id == item.Id);
if (exist != null)
{
item.EmailTopic = exist.EmailTopic;
item.EmailTopicCN = exist.EmailTopicCN;
}
}
await _emailNoticeConfigrepository.SaveChangesAsync();
return ResponseOutput.Ok();
}
public async Task<IResponseOutput> AddOrUpdateEmailNoticeConfig(EmailNoticeConfigAddOrEdit addOrEditEmailNoticeConfig)
{
var verifyExp1 = new EntityVerifyExp<EmailNoticeConfig>()
{
VerifyExp = t => t.BusinessScenarioEnum == addOrEditEmailNoticeConfig.BusinessScenarioEnum,
//var verifyExp1 = new EntityVerifyExp<EmailNoticeConfig>()
//{
// VerifyExp = t => t.BusinessScenarioEnum == addOrEditEmailNoticeConfig.BusinessScenarioEnum && t.CriterionTypeEnum == addOrEditEmailNoticeConfig.CriterionTypeEnum,
// VerifyMsg = _localizer["EmailNoticeConfig_RepeatEmailScenario"]
//};
var criterionList = _emailNoticeConfigrepository.Where(t => t.BusinessScenarioEnum == addOrEditEmailNoticeConfig.BusinessScenarioEnum && t.IsEnable == true)
.Where(t => t.CriterionTypeList != null)
.WhereIf(addOrEditEmailNoticeConfig.Id != null, t => t.Id != addOrEditEmailNoticeConfig.Id)
.Select(t => t.CriterionTypeList).ToList();//不能使用selectMany 会当成关联对象,不能当成字符串
if (addOrEditEmailNoticeConfig.CriterionTypeList != null)
{
foreach (var item in addOrEditEmailNoticeConfig.CriterionTypeList)
{
foreach (var itemList in criterionList)
{
if (itemList.Any(t => t == item))
{
return ResponseOutput.NotOk(_localizer["EmailNoticeConfig_RepeatEmailScenario"]);
}
}
}
}
var verifyExp2 = new EntityVerifyExp<EmailNoticeConfig>()
{
VerifyExp = t => t.Code == addOrEditEmailNoticeConfig.Code && t.IsDistinguishCriteria == addOrEditEmailNoticeConfig.IsDistinguishCriteria && t.SystemLevel == addOrEditEmailNoticeConfig.SystemLevel,
VerifyMsg = _localizer["EmailNoticeConfig_RepeatCode"]
VerifyMsg = _localizer["EmailNoticeConfig_RepeatEmailScenario"]
};
// 匹配所有占位符的正则表达式,允许包含空格的占位符
@ -59,10 +133,14 @@ namespace IRaCIS.Core.Application.Contracts
}
var entity = new EmailNoticeConfig() { };
if (addOrEditEmailNoticeConfig.Id == null)
{
var entity = _mapper.Map<EmailNoticeConfig>(addOrEditEmailNoticeConfig);
entity = _mapper.Map<EmailNoticeConfig>(addOrEditEmailNoticeConfig);
foreach (var item in addOrEditEmailNoticeConfig.ToUserTypeList)
@ -78,9 +156,9 @@ namespace IRaCIS.Core.Application.Contracts
}
await _emailNoticeConfigrepository.AddAsync(entity, true, verifyExp1);
await _emailNoticeConfigrepository.AddAsync(entity, true, verifyExp2);
return ResponseOutput.Ok(entity.Id.ToString());
}
else
{
@ -101,14 +179,32 @@ namespace IRaCIS.Core.Application.Contracts
}
var entity = await _emailNoticeConfigrepository.UpdateFromDTOAsync(addOrEditEmailNoticeConfig, true, false, verifyExp1);
entity = await _emailNoticeConfigrepository.UpdateFromDTOAsync(addOrEditEmailNoticeConfig, true, false, verifyExp2);
return ResponseOutput.Ok(entity.Id.ToString());
}
if (addOrEditEmailNoticeConfig.EmailCron != string.Empty)
{
//var jobId = $"{entity.Id}_({addOrEditEmailNoticeConfig.BusinessScenarioEnum})";
//HangfireJobHelper.RemoveCronJob(jobId);
////有的job 可能编辑控制直接不发,需要移除已存在的
//if (entity.IsAutoSend && entity.IsEnable)
//{
// HangfireJobHelper.AddOrUpdateTimingCronJob(jobId, addOrEditEmailNoticeConfig.BusinessScenarioEnum, addOrEditEmailNoticeConfig.EmailCron);
//}
}
return ResponseOutput.Ok(entity.Id.ToString());
}

View File

@ -1125,7 +1125,6 @@ namespace IRaCIS.Core.Application.Service.Common
/// <summary>
/// 邮件导出
/// </summary>
@ -1140,9 +1139,9 @@ namespace IRaCIS.Core.Application.Service.Common
{
var emailNoticeConfigQueryable = _emailNoticeConfigrepository
//.WhereIf(inQuery.SystemLevel == null, t => t.SystemLevel == SysEmailLevel.not_sys)
//.WhereIf(inQuery.SystemLevel != null, t => t.SystemLevel == inQuery.SystemLevel)
//.WhereIf(inQuery.IsDistinguishCriteria != null, t => t.IsDistinguishCriteria == inQuery.IsDistinguishCriteria)
.WhereIf(inQuery.CriterionTypeEnum != null, t => t.CriterionTypeEnum == inQuery.CriterionTypeEnum)
.WhereIf(inQuery.SystemLevel != null, t => t.SystemLevel == inQuery.SystemLevel)
.WhereIf(inQuery.IsDistinguishCriteria != null, t => t.IsDistinguishCriteria == inQuery.IsDistinguishCriteria)
.WhereIf(inQuery.CriterionTypeEnum != null, t => t.CriterionTypeList.Any(c => c == inQuery.CriterionTypeEnum))
.WhereIf(inQuery.BusinessScenarioEnum != null, t => t.BusinessScenarioEnum == inQuery.BusinessScenarioEnum)
.WhereIf(inQuery.IsReturnRequired != null, t => t.IsReturnRequired == inQuery.IsReturnRequired)
.WhereIf(inQuery.IsEnable != null, t => t.IsEnable == inQuery.IsEnable)

View File

@ -23,7 +23,7 @@ public class EmailNoticeConfig : BaseFullDeleteAuditEntity
public string AttachPath { get; set; } = null!;
[Comment("业务级别")]
public int BusinessLevelEnum { get; set; }
public BusinessLevel BusinessLevelEnum { get; set; }
[Comment("业务模块")]
public BusinessModule BusinessModuleEnum { get; set; }
@ -33,9 +33,6 @@ public class EmailNoticeConfig : BaseFullDeleteAuditEntity
public string Code { get; set; } = null!;
[Comment("标准枚举")]
public CriterionType? CriterionTypeEnum { get; set; }
public string Description { get; set; } = null!;
[Comment("发送周期")]
@ -68,6 +65,9 @@ public class EmailNoticeConfig : BaseFullDeleteAuditEntity
public bool IsReturnRequired { get; set; }
public SysEmailLevel SystemLevel { get; set; }
[Comment("邮件配置的多个标准")]
public List<CriterionType>? CriterionTypeList { get; set; }
}
[Comment("后台 - 邮件配置用户类型表(需要同步)")]
[Table("EmailNoticeUserType")]
@ -83,6 +83,21 @@ public class EmailNoticeUserType : Entity
public EmailUserType EmailUserType { get; set; }
}
public enum BusinessLevel
{
Default = 0,
System = 1,
//需要手动添加到项目的邮件
Trial = 2,
//项目默认发送的邮件,不需要手动添加到项目
TrialDefault = 3
}
public enum BusinessModule
{
/// <summary>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,40 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace IRaCIS.Core.Infra.EFCore.Migrations
{
/// <inheritdoc />
public partial class emailMofify : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "CriterionTypeEnum",
table: "EmailNoticeConfig");
migrationBuilder.AddColumn<string>(
name: "CriterionTypeList",
table: "EmailNoticeConfig",
type: "nvarchar(max)",
nullable: true,
comment: "邮件配置的多个标准");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "CriterionTypeList",
table: "EmailNoticeConfig");
migrationBuilder.AddColumn<int>(
name: "CriterionTypeEnum",
table: "EmailNoticeConfig",
type: "int",
nullable: true,
comment: "标准枚举");
}
}
}

View File

@ -1933,9 +1933,9 @@ namespace IRaCIS.Core.Infra.EFCore.Migrations
b.Property<Guid>("CreateUserId")
.HasColumnType("uniqueidentifier");
b.Property<int?>("CriterionTypeEnum")
.HasColumnType("int")
.HasComment("标准枚举");
b.Property<string>("CriterionTypeList")
.HasColumnType("nvarchar(max)")
.HasComment("邮件配置的多个标准");
b.Property<Guid?>("DeleteUserId")
.HasColumnType("uniqueidentifier");
@ -17961,7 +17961,7 @@ namespace IRaCIS.Core.Infra.EFCore.Migrations
.IsRequired();
b.HasOne("IRaCIS.Core.Domain.Models.Trial", "Trial")
.WithMany("TrialUserList")
.WithMany("TrialUserRoleList")
.HasForeignKey("TrialId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@ -18714,7 +18714,7 @@ namespace IRaCIS.Core.Infra.EFCore.Migrations
b.Navigation("TrialStateChangeList");
b.Navigation("TrialUserList");
b.Navigation("TrialUserRoleList");
b.Navigation("UserFeedBackList");