temp:remove notify table

This commit is contained in:
xiaolipro 2024-08-05 09:23:26 +08:00
parent decb50a085
commit 9de31445a9
16 changed files with 142 additions and 200 deletions

View File

@ -20,20 +20,10 @@ public class CreateWarningInput
/// </summary> /// </summary>
public int CustomerId { get; set; } public int CustomerId { get; set; }
/// <summary>
/// 通知方式
/// </summary>
public NotifyMode NotifyMode { get; set; }
/// <summary>
/// 通知模板
/// </summary>
public string NotifyTemplate { get; set; } = null!;
/// <summary> /// <summary>
/// 轨迹状态跨度列表 /// 轨迹状态跨度列表
/// </summary> /// </summary>
public List<WarningNitifyDto> TrackStatusSpans { get; set; } = new(); public List<WarningNotifyDto> TrackStatusSpans { get; set; } = new();
/// <summary> /// <summary>
/// 预警因素列表。 /// 预警因素列表。

View File

@ -1,5 +1,4 @@
using SJZY.Track.Domain.Dtos.Forewarning; using SJZY.Track.Domain.Dtos.Forewarning;
using SJZY.Track.Domain.Enums;
namespace SJZY.Track.Application.Contract.Dtos.Forewarning; namespace SJZY.Track.Application.Contract.Dtos.Forewarning;
@ -20,20 +19,10 @@ public class EditWarningOutput
/// </summary> /// </summary>
public int CustomerId { get; set; } public int CustomerId { get; set; }
/// <summary>
/// 通知方式
/// </summary>
public NotifyMode NotifyMode { get; set; }
/// <summary>
/// 通知模板
/// </summary>
public string NotifyTemplate { get; set; } = null!;
/// <summary> /// <summary>
/// 通知列表 /// 通知列表
/// </summary> /// </summary>
public List<WarningNotifyWithIdDto> TrackStatusSpans { get; set; } = new(); public List<WarningNotifyDto> TrackStatusSpans { get; set; } = new();
/// <summary> /// <summary>
/// 预警因素列表。 /// 预警因素列表。
@ -41,13 +30,6 @@ public class EditWarningOutput
public List<WarningFactorWithIdDto> WarningFactors { get; set; } = new(); public List<WarningFactorWithIdDto> WarningFactors { get; set; } = new();
} }
public class WarningNotifyWithIdDto: WarningNitifyDto
{
/// <summary>
/// 通知id
/// </summary>
public int Id { get; set; }
}
public class WarningFactorWithIdDto : WarningFactorDto public class WarningFactorWithIdDto : WarningFactorDto
{ {

View File

@ -15,31 +15,8 @@ public class UpdateWarningInput
/// </summary> /// </summary>
public string Name { get; set; } = null!; public string Name { get; set; } = null!;
/// <summary>
/// 通知方式
/// </summary>
public NotifyMode NotifyMode { get; set; }
/// <summary>
/// 通知模板
/// </summary>
public string NotifyTemplate { get; set; } = null!;
/// <summary> /// <summary>
/// 通知列表 /// 通知列表
/// </summary> /// </summary>
public List<NotifyDto> Notifies { get; set; } = new(); public List<WarningNotifyDto> Notifies { get; set; } = new();
}
public class NotifyDto
{
/// <summary>
/// 通知id
/// </summary>
public int Id { get; set; }
/// <summary>
/// 通知人id
/// </summary>
public int NotifyUserId { get; set; }
} }

View File

@ -15,17 +15,12 @@ public class ForewarningHelper
/// <summary> /// <summary>
/// 递推分裂预警规则列表 /// 递推分裂预警规则列表
/// </summary> /// </summary>
/// <param name="statusSpans"></param> /// <param name="input"></param>
/// <param name="factors"></param>
/// <returns></returns> /// <returns></returns>
public static List<WarningRuleEntity> CalcRuleList(List<WarningNitifyDto> statusSpans, public static List<WarningRuleEntity> CalcRuleList(CreateWarningInput input)
List<WarningFactorDto> factors)
{ {
if (statusSpans.Count == 0 || factors.Count == 0) var statusSpans = input.TrackStatusSpans;
{ var factors = input.WarningFactors;
throw new BusinessException(message: "轨迹状态区间或因素列表为空");
}
var len = statusSpans.Count * factors.Select(f => f.FactorValue.Count).Aggregate((pre, cur) => pre * cur); var len = statusSpans.Count * factors.Select(f => f.FactorValue.Count).Aggregate((pre, cur) => pre * cur);
if (len == 0) if (len == 0)
{ {
@ -52,7 +47,7 @@ public class ForewarningHelper
return rules; return rules;
} }
private static void FillStatus(List<WarningNitifyDto> statusSpans, List<WarningRuleEntity> rules, int repeat) private static void FillStatus(List<WarningNotifyDto> statusSpans, List<WarningRuleEntity> rules, int repeat)
{ {
var row = 0; var row = 0;
foreach (var span in statusSpans) foreach (var span in statusSpans)
@ -63,6 +58,8 @@ public class ForewarningHelper
rules[row].StartTrackStatus = span.StartTrackStatus; rules[row].StartTrackStatus = span.StartTrackStatus;
rules[row].EndTrackStatusId = span.EndTrackStatusId; rules[row].EndTrackStatusId = span.EndTrackStatusId;
rules[row].EndTrackStatus = span.EndTrackStatus; rules[row].EndTrackStatus = span.EndTrackStatus;
rules[row].NotifyMode = span.NotifyMode;
rules[row].NotifyUserId = span.NotifyUserId;
} }
} }
} }
@ -152,36 +149,23 @@ public class ForewarningHelper
}).ToList(); }).ToList();
} }
public static List<WarningNotifyEntity> MapNotifyEntities(CreateWarningInput input) public static EditWarningOutput MapWarningSummary(WarningEntity warning)
{ {
return input.TrackStatusSpans.Select(x => new WarningNotifyEntity
{
StartTrackStatusId = x.StartTrackStatusId,
EndTrackStatusId = x.EndTrackStatusId,
NotifyMode = input.NotifyMode,
NotifyTemplate = input.NotifyTemplate,
NotifyUserId = x.NotifyUserId
}).ToList();
}
public static EditWarningOutput MapWarningSummary(WarningEntity warning, List<IdWithNameDto> statusList)
{
var statusDic = statusList.ToDictionary(x => x.Id, x => x.Name);
return new EditWarningOutput return new EditWarningOutput
{ {
Name = warning.Name, Name = warning.Name,
SubSystemId = warning.SubSystemId, SubSystemId = warning.SubSystemId,
CustomerId = warning.CustomerId, CustomerId = warning.CustomerId,
NotifyMode = warning.WarningNotifies.First().NotifyMode, TrackStatusSpans = warning.WarningRules.GroupBy(x => new
NotifyTemplate = warning.WarningNotifies.First().NotifyTemplate, { x.StartTrackStatusId, x.StartTrackStatus, x.EndTrackStatusId, x.EndTrackStatus })
TrackStatusSpans = warning.WarningNotifies.Select(x => new WarningNotifyWithIdDto .Select(x => new WarningNotifyDto
{ {
Id = x.Id, StartTrackStatusId = x.Key.StartTrackStatusId,
StartTrackStatusId = x.StartTrackStatusId, StartTrackStatus = x.Key.StartTrackStatus,
StartTrackStatus = statusDic.TryGetValue(x.StartTrackStatusId, out var start) ? start : "", EndTrackStatusId = x.Key.EndTrackStatusId,
EndTrackStatusId = x.EndTrackStatusId, EndTrackStatus = x.Key.EndTrackStatus,
EndTrackStatus = statusDic.TryGetValue(x.EndTrackStatusId, out var end) ? end : "", NotifyMode = x.First().NotifyMode,
NotifyUserId = x.NotifyUserId, NotifyUserId = x.First().NotifyUserId,
}).ToList(), }).ToList(),
WarningFactors = warning.WarningFactors.Select(x => new WarningFactorWithIdDto WarningFactors = warning.WarningFactors.Select(x => new WarningFactorWithIdDto
{ {

View File

@ -6,7 +6,6 @@ using SJZY.Track.Application.Helpers;
using SJZY.Track.Domain.Aggregates.ForewarningAggregate; using SJZY.Track.Domain.Aggregates.ForewarningAggregate;
using SJZY.Track.Domain.Aggregates.TrackStatusAggregate; using SJZY.Track.Domain.Aggregates.TrackStatusAggregate;
using SJZY.Track.Domain.Dtos.Forewarning; using SJZY.Track.Domain.Dtos.Forewarning;
using SJZY.Track.Domain.Dtos.TrackStatus;
using SJZY.Track.Domain.Queries; using SJZY.Track.Domain.Queries;
namespace SJZY.Track.Application.Services.ForewarningServices; namespace SJZY.Track.Application.Services.ForewarningServices;
@ -17,11 +16,14 @@ public class ForewarningService : ApplicationService
{ {
private readonly IWarningRepository _warningRepository; private readonly IWarningRepository _warningRepository;
private readonly IForewarningCacheService _forewarningCacheService; private readonly IForewarningCacheService _forewarningCacheService;
private readonly IBasicQuery<TrackStatusEntity> _trackStatusQueries;
public ForewarningService(IWarningRepository warningRepository, IForewarningCacheService forewarningCacheService) public ForewarningService(IWarningRepository warningRepository, IForewarningCacheService forewarningCacheService,
IBasicQuery<TrackStatusEntity> trackStatusQueries)
{ {
_warningRepository = warningRepository; _warningRepository = warningRepository;
_forewarningCacheService = forewarningCacheService; _forewarningCacheService = forewarningCacheService;
_trackStatusQueries = trackStatusQueries;
} }
/// <summary> /// <summary>
@ -44,6 +46,11 @@ public class ForewarningService : ApplicationService
[HttpPost("CreateWarning")] [HttpPost("CreateWarning")]
public async Task<bool> CreateWarning(CreateWarningInput input) public async Task<bool> CreateWarning(CreateWarningInput input)
{ {
if (input.TrackStatusSpans.Count == 0 || input.WarningFactors.Count == 0)
{
throw new BusinessException(message: "轨迹状态区间或因素列表为空");
}
var warning = ObjectMapper.Map<CreateWarningInput, WarningEntity>(input); var warning = ObjectMapper.Map<CreateWarningInput, WarningEntity>(input);
if (await _warningRepository.IsAnyAsync(x => if (await _warningRepository.IsAnyAsync(x =>
@ -52,11 +59,9 @@ public class ForewarningService : ApplicationService
throw new BusinessException(message: "该子系统下的客户已经存在一个同名预警: " + warning.Name); throw new BusinessException(message: "该子系统下的客户已经存在一个同名预警: " + warning.Name);
} }
warning.WarningRules = ForewarningHelper.CalcRuleList(input.TrackStatusSpans, input.WarningFactors); warning.WarningRules = ForewarningHelper.CalcRuleList(input);
warning.FactorTypeSort = input.WarningFactors.Select(x => x.FactorType).JoinAsString(","); warning.FactorTypeSort = input.WarningFactors.Select(x => x.FactorType).JoinAsString(",");
warning.WarningFactors = ForewarningHelper.MapFactorEntities(input.WarningFactors); warning.WarningFactors = ForewarningHelper.MapFactorEntities(input.WarningFactors);
warning.WarningNotifies = ForewarningHelper.MapNotifyEntities(input);
await _warningRepository.CreateForewarningAsync(warning); await _warningRepository.CreateForewarningAsync(warning);
return true; return true;
} }
@ -65,27 +70,18 @@ public class ForewarningService : ApplicationService
/// 编辑预警 /// 编辑预警
/// </summary> /// </summary>
/// <param name="warningId"></param> /// <param name="warningId"></param>
/// <param name="statusQuery"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost("EditWarning")] [HttpPost("EditWarning")]
public async Task<EditWarningOutput> EditWarning(int warningId, public async Task<EditWarningOutput> EditWarning(int warningId)
[FromServices] IBasicQuery<TrackStatusEntity> statusQuery)
{ {
var warning = await _warningRepository.GetByIdAsync(warningId); var warning = await _warningRepository.GetWithRulesAsync(warningId);
if (warning == null) if (warning == null)
{ {
throw new BusinessException(message: "预警不存在"); throw new BusinessException(message: "预警不存在");
} }
var statusList = await statusQuery.GetListAsync(x => x.SubSystemId == warning.SubSystemId, x => return ForewarningHelper.MapWarningSummary(warning);
new IdWithNameDto
{
Id = x.Id,
Name = x.Status
});
return ForewarningHelper.MapWarningSummary(warning, statusList);
} }
/// <summary> /// <summary>
@ -111,11 +107,14 @@ public class ForewarningService : ApplicationService
warning.SetName(input.Name); warning.SetName(input.Name);
warning.WarningNotifies = input.Notifies.Select(x => new WarningNotifyEntity await VerifyAndFillStatusAsync(input.Notifies, warning.SubSystemId);
warning.WarningRules = input.Notifies.Select(x => new WarningRuleEntity()
{ {
Id = x.Id, WarningId = warning.Id,
NotifyMode = input.NotifyMode, StartTrackStatusId = x.StartTrackStatusId,
NotifyTemplate = input.NotifyTemplate, EndTrackStatusId = x.EndTrackStatusId,
NotifyMode = x.NotifyMode,
NotifyUserId = x.NotifyUserId NotifyUserId = x.NotifyUserId
}).ToList(); }).ToList();
@ -124,6 +123,45 @@ public class ForewarningService : ApplicationService
return true; return true;
} }
private async Task VerifyAndFillStatusAsync(List<WarningNotifyDto> notifies, int subSystemId)
{
var statusIds = new List<int>();
notifies.ForEach(x =>
{
if (x.StartTrackStatusId == x.EndTrackStatusId)
{
throw new BusinessException(message: "起止轨迹状态不能相同");
}
statusIds.Add(x.StartTrackStatusId);
statusIds.Add(x.EndTrackStatusId);
});
var statusList = await _trackStatusQueries.GetListAsync(
x => x.SubSystemId == subSystemId && statusIds.Contains(x.Id), x =>
new IdWithNameDto
{
Id = x.Id,
Name = x.Status
});
var statusDic = statusList.ToDictionary(x => x.Id, x => x.Name);
notifies.ForEach(x =>
{
if (!statusDic.ContainsKey(x.StartTrackStatusId))
{
throw new BusinessException(message: "存在非法轨迹状态(包含子系统下不存在的轨迹状态)");
}
if (!statusDic.ContainsKey(x.EndTrackStatusId))
{
throw new BusinessException(message: "存在非法轨迹状态(包含子系统下不存在的轨迹状态)");
}
x.StartTrackStatus = statusDic[x.StartTrackStatusId];
x.EndTrackStatus = statusDic[x.EndTrackStatusId];
});
}
/// <summary> /// <summary>
/// 启用or禁用预警 /// 启用or禁用预警
/// </summary> /// </summary>

View File

@ -11,9 +11,6 @@ public class CreateRuleFactorValidation : AbstractValidator<CreateWarningInput>
RuleFor(x => x.WarningFactors).NotNull().WithMessage("因素列表不能为空"); RuleFor(x => x.WarningFactors).NotNull().WithMessage("因素列表不能为空");
RuleFor(x => x.TrackStatusSpans).NotNull().WithMessage("轨迹状态列表不能为空"); RuleFor(x => x.TrackStatusSpans).NotNull().WithMessage("轨迹状态列表不能为空");
RuleFor(x => x.NotifyTemplate).NotEmpty().WithMessage("通知模板必填")
.MaximumLength(256).WithMessage("通知模板长度不能超过256");
// todo: more validation // todo: more validation
} }
} }

View File

@ -3,7 +3,7 @@ using SJZY.Track.Domain.Dtos.Forewarning;
namespace SJZY.Track.Application.Validations.Forewarning; namespace SJZY.Track.Application.Validations.Forewarning;
public class RuleTrackStateDtoValidator : AbstractValidator<WarningNitifyDto> public class RuleTrackStateDtoValidator : AbstractValidator<WarningNotifyDto>
{ {
public RuleTrackStateDtoValidator() public RuleTrackStateDtoValidator()
{ {

View File

@ -54,9 +54,9 @@ public interface IWarningRepository : IBasicRepository<WarningEntity>
Task<bool> TurnWarningAsync(WarningEntity warning); Task<bool> TurnWarningAsync(WarningEntity warning);
/// <summary> /// <summary>
/// 获取预警,include factors, notifies /// 获取预警 附带规则
/// </summary> /// </summary>
/// <param name="warningId"></param> /// <param name="warningId"></param>
/// <returns></returns> /// <returns></returns>
Task<WarningEntity?> GetByIdAsync(int warningId); Task<WarningEntity?> GetWithRulesAsync(int warningId);
} }

View File

@ -54,12 +54,6 @@ public class WarningEntity: IFullAuditedBasicEntitys, IAggregateRoot
[SugarColumn(IsIgnore = true)] [SugarColumn(IsIgnore = true)]
public List<WarningFactorEntity> WarningFactors { get; set; } = new(); public List<WarningFactorEntity> WarningFactors { get; set; } = new();
/// <summary>
/// 预警通知
/// </summary>
[SugarColumn(IsIgnore = true)]
public List<WarningNotifyEntity> WarningNotifies { get; set; } = new();
public void SetName(string name) public void SetName(string name)
{ {
Name = name; Name = name;

View File

@ -1,49 +0,0 @@
using SJZY.Track.Domain.Enums;
namespace SJZY.Track.Domain.Aggregates.ForewarningAggregate;
[SugarTable("t_warning_notify")]
public class WarningNotifyEntity : IFullAuditedBasicEntitys, IEntity
{
/// <summary>
/// 自增主键
/// </summary>
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
/// <summary>
/// 预警id
/// </summary>
[SugarColumn(ColumnName = "WarningId")]
public int WarningId { get; set; }
/// <summary>
/// 起始轨迹状态id
/// </summary>
[SugarColumn(ColumnName = "StartTrackStatusId", IsNullable = false)]
public int StartTrackStatusId { get; set; }
/// <summary>
/// 终止轨迹状态id
/// </summary>
[SugarColumn(ColumnName = "EndTrackStatusId", IsNullable = false)]
public int EndTrackStatusId { get; set; }
/// <summary>
/// 通知方式
/// </summary>
[SugarColumn(ColumnName = "NotifyMode")]
public NotifyMode NotifyMode { get; set; }
/// <summary>
/// 通知模板
/// </summary>
[SugarColumn(ColumnName = "NotifyTemplate", Length = 256)]
public string NotifyTemplate { get; set; } = null!;
/// <summary>
/// 通知人
/// </summary>
[SugarColumn(ColumnName = "NotifyUserId")]
public int NotifyUserId { get; set; }
}

View File

@ -1,3 +1,5 @@
using SJZY.Track.Domain.Enums;
namespace SJZY.Track.Domain.Aggregates.ForewarningAggregate; namespace SJZY.Track.Domain.Aggregates.ForewarningAggregate;
[SugarTable("t_warning_rule")] [SugarTable("t_warning_rule")]
@ -92,4 +94,16 @@ public class WarningRuleEntity : IFullAuditedBasicEntitys, IEntity
/// </summary> /// </summary>
[SugarColumn(ColumnName = "ProductCode")] [SugarColumn(ColumnName = "ProductCode")]
public string? ProductCode { get; set; } public string? ProductCode { get; set; }
/// <summary>
/// 通知方式
/// </summary>
[SugarColumn(ColumnName = "NotifyMode")]
public NotifyMode NotifyMode { get; set; }
/// <summary>
/// 通知人
/// </summary>
[SugarColumn(ColumnName = "NotifyUserId")]
public int NotifyUserId { get; set; }
} }

View File

@ -12,6 +12,12 @@ public class TrackStatusEntity : IFullAuditedBasicEntitys, IAggregateRoot
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)] [SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; } public int Id { get; set; }
/// <summary>
/// 子系统id
/// </summary>
[SugarColumn(ColumnName = "SubSystemId")]
public int SubSystemId { get; set; }
/// <summary> /// <summary>
/// 轨迹状态代码 /// 轨迹状态代码
/// </summary> /// </summary>
@ -35,10 +41,4 @@ public class TrackStatusEntity : IFullAuditedBasicEntitys, IAggregateRoot
/// </summary> /// </summary>
[SugarColumn(ColumnName = "Status")] [SugarColumn(ColumnName = "Status")]
public string Status { get; set; } = null!; public string Status { get; set; } = null!;
/// <summary>
/// 子系统id
/// </summary>
[SugarColumn(ColumnName = "SubSystemId")]
public int SubSystemId { get; set; }
} }

View File

@ -1,6 +1,8 @@
using SJZY.Track.Domain.Enums;
namespace SJZY.Track.Domain.Dtos.Forewarning; namespace SJZY.Track.Domain.Dtos.Forewarning;
public class WarningNitifyDto public class WarningNotifyDto
{ {
/// <summary> /// <summary>
/// 起始轨迹状态id /// 起始轨迹状态id
@ -22,6 +24,11 @@ public class WarningNitifyDto
/// </summary> /// </summary>
public string EndTrackStatus { get; set; } = null!; public string EndTrackStatus { get; set; } = null!;
/// <summary>
/// 通知方式
/// </summary>
public NotifyMode NotifyMode { get; set; }
/// <summary> /// <summary>
/// 通知人id /// 通知人id
/// </summary> /// </summary>

View File

@ -1,14 +1,15 @@
namespace SJZY.Track.Domain.Enums; namespace SJZY.Track.Domain.Enums;
[Flags]
public enum NotifyMode public enum NotifyMode
{ {
/// <summary> /// <summary>
/// 站内信 /// 站内信
/// </summary> /// </summary>
SiteInternal = 1, SiteInternal = 0x1,
/// <summary> /// <summary>
/// 飞书 /// 飞书
/// </summary> /// </summary>
FeiShu = 2 FeiShu = 0x10,
} }

View File

@ -20,12 +20,9 @@ public class WarningQueries : ISugarRepository, IWarningQueries,
return await Context.Queryable<WarningEntity>() return await Context.Queryable<WarningEntity>()
.LeftJoin<WarningRuleEntity>((w, wr) => w.Id == wr.WarningId) .LeftJoin<WarningRuleEntity>((w, wr) => w.Id == wr.WarningId)
.LeftJoin<RuleAreaEntity>((w, wr, a) => wr.AreaId == a.Id) .LeftJoin<RuleAreaEntity>((w, wr, a) => wr.AreaId == a.Id)
.LeftJoin<WarningNotifyEntity>((w, wr, a, wn) =>
wr.WarningId == wn.WarningId && wr.StartTrackStatusId == wn.StartTrackStatusId &&
wr.EndTrackStatusId == wn.EndTrackStatusId)
.Filter(null, true) // 支持历史规则 .Filter(null, true) // 支持历史规则
.Where((w, wr) => ruleIds.Contains(wr.Id)) .Where((w, wr) => ruleIds.Contains(wr.Id))
.Select<GetWarningNotifiesVo>((w, wr, a, wn) => new GetWarningNotifiesVo .Select<GetWarningNotifiesVo>((w, wr, a) => new GetWarningNotifiesVo
{ {
RuleId = wr.Id, RuleId = wr.Id,
WarningName = w.Name, WarningName = w.Name,
@ -40,9 +37,8 @@ public class WarningQueries : ISugarRepository, IWarningQueries,
IsTransit = wr.IsTransit, IsTransit = wr.IsTransit,
LeavePort = wr.LeavePort, LeavePort = wr.LeavePort,
ProductCode = wr.ProductCode, ProductCode = wr.ProductCode,
NotifyMode = wn.NotifyMode, NotifyMode = wr.NotifyMode,
NotifyTemplate = wn.NotifyTemplate, NotifyUserId = wr.NotifyUserId,
NotifyUserId = wn.NotifyUserId,
FactorTypeSort = w.FactorTypeSort FactorTypeSort = w.FactorTypeSort
}) })
.ToListAsync(); .ToListAsync();

View File

@ -14,13 +14,12 @@ public class WarningRepository : BasicRepository<WarningEntity>, IWarningReposit
using var tran = TransactionHelper.GetReadCommitted(); using var tran = TransactionHelper.GetReadCommitted();
var ruleId = await InsertReturnIdentityAsync(warning); var ruleId = await InsertReturnIdentityAsync(warning);
warning.WarningNotifies.ForEach(x => x.WarningId = ruleId);
warning.WarningFactors.ForEach(x => x.WarningId = ruleId); warning.WarningFactors.ForEach(x => x.WarningId = ruleId);
warning.WarningRules.ForEach(x => x.WarningId = ruleId);
await Context.Insertable(warning.WarningFactors).ExecuteCommandAsync(); await Context.Insertable(warning.WarningFactors).ExecuteCommandAsync();
await Context.Insertable(warning.WarningNotifies).ExecuteCommandAsync();
warning.WarningRules.ForEach(x => x.WarningId = ruleId);
await Context.Insertable(warning.WarningRules).ExecuteCommandAsync(); await Context.Insertable(warning.WarningRules).ExecuteCommandAsync();
tran.Complete(); tran.Complete();
return ruleId; return ruleId;
} }
@ -73,8 +72,19 @@ public class WarningRepository : BasicRepository<WarningEntity>, IWarningReposit
using var tran = TransactionHelper.GetReadCommitted(); using var tran = TransactionHelper.GetReadCommitted();
await Context.Updateable(warning).ExecuteCommandAsync(); await Context.Updateable(warning).ExecuteCommandAsync();
await Context.Updateable(warning.WarningNotifies)
.UpdateColumns(x => new { x.NotifyMode, x.NotifyTemplate, x.NotifyUserId, x.UpdateTime, x.UpdateUserId }) await Context.Updateable(warning.WarningRules).WhereColumns(x => new
{
x.WarningId,
x.StartTrackStatusId,
x.EndTrackStatusId
}).UpdateColumns(x => new
{
x.NotifyMode,
x.NotifyUserId,
x.UpdateTime,
x.UpdateUserId,
}, true)
.ExecuteCommandAsync(); .ExecuteCommandAsync();
tran.Complete(); tran.Complete();
@ -94,7 +104,7 @@ public class WarningRepository : BasicRepository<WarningEntity>, IWarningReposit
.ExecuteCommandAsync() > 0; .ExecuteCommandAsync() > 0;
} }
public async Task<WarningEntity?> GetByIdAsync(int warningId) public async Task<WarningEntity?> GetWithRulesAsync(int warningId)
{ {
var warning = await GetFirstAsync(x => x.Id == warningId); var warning = await GetFirstAsync(x => x.Id == warningId);
@ -103,7 +113,8 @@ public class WarningRepository : BasicRepository<WarningEntity>, IWarningReposit
warning.WarningFactors = await Context.Queryable<WarningFactorEntity>() warning.WarningFactors = await Context.Queryable<WarningFactorEntity>()
.Where(x => x.WarningId == warningId) .Where(x => x.WarningId == warningId)
.ToListAsync(); .ToListAsync();
warning.WarningNotifies = await Context.Queryable<WarningNotifyEntity>()
warning.WarningRules = await Context.Queryable<WarningRuleEntity>()
.Where(x => x.WarningId == warningId) .Where(x => x.WarningId == warningId)
.ToListAsync(); .ToListAsync();