parent
9de31445a9
commit
2f2805268e
@ -20,10 +20,20 @@ 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<WarningNotifyDto> TrackStatusSpans { get; set; } = new();
|
public List<WarningNitifyDto> TrackStatusSpans { get; set; } = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 预警因素列表。
|
/// 预警因素列表。
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
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;
|
||||||
|
|
||||||
@ -19,10 +20,20 @@ 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<WarningNotifyDto> TrackStatusSpans { get; set; } = new();
|
public List<WarningNotifyWithIdDto> TrackStatusSpans { get; set; } = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 预警因素列表。
|
/// 预警因素列表。
|
||||||
@ -30,6 +41,13 @@ 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
|
||||||
{
|
{
|
||||||
|
|||||||
@ -15,8 +15,31 @@ 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<WarningNotifyDto> Notifies { get; set; } = new();
|
public List<NotifyDto> Notifies { get; set; } = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class NotifyDto
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 通知id
|
||||||
|
/// </summary>
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 通知人id
|
||||||
|
/// </summary>
|
||||||
|
public int NotifyUserId { get; set; }
|
||||||
}
|
}
|
||||||
@ -15,12 +15,17 @@ public class ForewarningHelper
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 递推分裂预警规则列表
|
/// 递推分裂预警规则列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input"></param>
|
/// <param name="statusSpans"></param>
|
||||||
|
/// <param name="factors"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static List<WarningRuleEntity> CalcRuleList(CreateWarningInput input)
|
public static List<WarningRuleEntity> CalcRuleList(List<WarningNitifyDto> statusSpans,
|
||||||
|
List<WarningFactorDto> factors)
|
||||||
{
|
{
|
||||||
var statusSpans = input.TrackStatusSpans;
|
if (statusSpans.Count == 0 || factors.Count == 0)
|
||||||
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)
|
||||||
{
|
{
|
||||||
@ -47,7 +52,7 @@ public class ForewarningHelper
|
|||||||
return rules;
|
return rules;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void FillStatus(List<WarningNotifyDto> statusSpans, List<WarningRuleEntity> rules, int repeat)
|
private static void FillStatus(List<WarningNitifyDto> statusSpans, List<WarningRuleEntity> rules, int repeat)
|
||||||
{
|
{
|
||||||
var row = 0;
|
var row = 0;
|
||||||
foreach (var span in statusSpans)
|
foreach (var span in statusSpans)
|
||||||
@ -58,8 +63,6 @@ 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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -149,23 +152,36 @@ public class ForewarningHelper
|
|||||||
}).ToList();
|
}).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EditWarningOutput MapWarningSummary(WarningEntity warning)
|
public static List<WarningNotifyEntity> MapNotifyEntities(CreateWarningInput input)
|
||||||
{
|
{
|
||||||
|
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,
|
||||||
TrackStatusSpans = warning.WarningRules.GroupBy(x => new
|
NotifyMode = warning.WarningNotifies.First().NotifyMode,
|
||||||
{ x.StartTrackStatusId, x.StartTrackStatus, x.EndTrackStatusId, x.EndTrackStatus })
|
NotifyTemplate = warning.WarningNotifies.First().NotifyTemplate,
|
||||||
.Select(x => new WarningNotifyDto
|
TrackStatusSpans = warning.WarningNotifies.Select(x => new WarningNotifyWithIdDto
|
||||||
{
|
{
|
||||||
StartTrackStatusId = x.Key.StartTrackStatusId,
|
Id = x.Id,
|
||||||
StartTrackStatus = x.Key.StartTrackStatus,
|
StartTrackStatusId = x.StartTrackStatusId,
|
||||||
EndTrackStatusId = x.Key.EndTrackStatusId,
|
StartTrackStatus = statusDic.TryGetValue(x.StartTrackStatusId, out var start) ? start : "",
|
||||||
EndTrackStatus = x.Key.EndTrackStatus,
|
EndTrackStatusId = x.EndTrackStatusId,
|
||||||
NotifyMode = x.First().NotifyMode,
|
EndTrackStatus = statusDic.TryGetValue(x.EndTrackStatusId, out var end) ? end : "",
|
||||||
NotifyUserId = x.First().NotifyUserId,
|
NotifyUserId = x.NotifyUserId,
|
||||||
}).ToList(),
|
}).ToList(),
|
||||||
WarningFactors = warning.WarningFactors.Select(x => new WarningFactorWithIdDto
|
WarningFactors = warning.WarningFactors.Select(x => new WarningFactorWithIdDto
|
||||||
{
|
{
|
||||||
|
|||||||
@ -6,6 +6,7 @@ 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;
|
||||||
@ -16,14 +17,11 @@ 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>
|
||||||
@ -46,11 +44,6 @@ 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 =>
|
||||||
@ -59,9 +52,11 @@ public class ForewarningService : ApplicationService
|
|||||||
throw new BusinessException(message: "该子系统下的客户已经存在一个同名预警: " + warning.Name);
|
throw new BusinessException(message: "该子系统下的客户已经存在一个同名预警: " + warning.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
warning.WarningRules = ForewarningHelper.CalcRuleList(input);
|
warning.WarningRules = ForewarningHelper.CalcRuleList(input.TrackStatusSpans, input.WarningFactors);
|
||||||
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;
|
||||||
}
|
}
|
||||||
@ -70,18 +65,27 @@ 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.GetWithRulesAsync(warningId);
|
var warning = await _warningRepository.GetByIdAsync(warningId);
|
||||||
|
|
||||||
if (warning == null)
|
if (warning == null)
|
||||||
{
|
{
|
||||||
throw new BusinessException(message: "预警不存在");
|
throw new BusinessException(message: "预警不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
return ForewarningHelper.MapWarningSummary(warning);
|
var statusList = await statusQuery.GetListAsync(x => x.SubSystemId == warning.SubSystemId, x =>
|
||||||
|
new IdWithNameDto
|
||||||
|
{
|
||||||
|
Id = x.Id,
|
||||||
|
Name = x.Status
|
||||||
|
});
|
||||||
|
|
||||||
|
return ForewarningHelper.MapWarningSummary(warning, statusList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -107,14 +111,11 @@ public class ForewarningService : ApplicationService
|
|||||||
|
|
||||||
warning.SetName(input.Name);
|
warning.SetName(input.Name);
|
||||||
|
|
||||||
await VerifyAndFillStatusAsync(input.Notifies, warning.SubSystemId);
|
warning.WarningNotifies = input.Notifies.Select(x => new WarningNotifyEntity
|
||||||
|
|
||||||
warning.WarningRules = input.Notifies.Select(x => new WarningRuleEntity()
|
|
||||||
{
|
{
|
||||||
WarningId = warning.Id,
|
Id = x.Id,
|
||||||
StartTrackStatusId = x.StartTrackStatusId,
|
NotifyMode = input.NotifyMode,
|
||||||
EndTrackStatusId = x.EndTrackStatusId,
|
NotifyTemplate = input.NotifyTemplate,
|
||||||
NotifyMode = x.NotifyMode,
|
|
||||||
NotifyUserId = x.NotifyUserId
|
NotifyUserId = x.NotifyUserId
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
@ -123,45 +124,6 @@ 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>
|
||||||
|
|||||||
@ -11,6 +11,9 @@ 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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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<WarningNotifyDto>
|
public class RuleTrackStateDtoValidator : AbstractValidator<WarningNitifyDto>
|
||||||
{
|
{
|
||||||
public RuleTrackStateDtoValidator()
|
public RuleTrackStateDtoValidator()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -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?> GetWithRulesAsync(int warningId);
|
Task<WarningEntity?> GetByIdAsync(int warningId);
|
||||||
}
|
}
|
||||||
@ -54,6 +54,12 @@ 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;
|
||||||
|
|||||||
@ -0,0 +1,49 @@
|
|||||||
|
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; }
|
||||||
|
}
|
||||||
@ -1,5 +1,3 @@
|
|||||||
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")]
|
||||||
@ -94,16 +92,4 @@ 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; }
|
|
||||||
}
|
}
|
||||||
@ -12,12 +12,6 @@ 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>
|
||||||
@ -41,4 +35,10 @@ 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; }
|
||||||
}
|
}
|
||||||
@ -1,8 +1,6 @@
|
|||||||
using SJZY.Track.Domain.Enums;
|
|
||||||
|
|
||||||
namespace SJZY.Track.Domain.Dtos.Forewarning;
|
namespace SJZY.Track.Domain.Dtos.Forewarning;
|
||||||
|
|
||||||
public class WarningNotifyDto
|
public class WarningNitifyDto
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 起始轨迹状态id
|
/// 起始轨迹状态id
|
||||||
@ -24,11 +22,6 @@ public class WarningNotifyDto
|
|||||||
/// </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>
|
||||||
@ -1,15 +1,14 @@
|
|||||||
namespace SJZY.Track.Domain.Enums;
|
namespace SJZY.Track.Domain.Enums;
|
||||||
|
|
||||||
[Flags]
|
|
||||||
public enum NotifyMode
|
public enum NotifyMode
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 站内信
|
/// 站内信
|
||||||
/// </summary>
|
/// </summary>
|
||||||
SiteInternal = 0x1,
|
SiteInternal = 1,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 飞书
|
/// 飞书
|
||||||
/// </summary>
|
/// </summary>
|
||||||
FeiShu = 0x10,
|
FeiShu = 2
|
||||||
}
|
}
|
||||||
@ -20,9 +20,12 @@ 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) => new GetWarningNotifiesVo
|
.Select<GetWarningNotifiesVo>((w, wr, a, wn) => new GetWarningNotifiesVo
|
||||||
{
|
{
|
||||||
RuleId = wr.Id,
|
RuleId = wr.Id,
|
||||||
WarningName = w.Name,
|
WarningName = w.Name,
|
||||||
@ -37,8 +40,9 @@ public class WarningQueries : ISugarRepository, IWarningQueries,
|
|||||||
IsTransit = wr.IsTransit,
|
IsTransit = wr.IsTransit,
|
||||||
LeavePort = wr.LeavePort,
|
LeavePort = wr.LeavePort,
|
||||||
ProductCode = wr.ProductCode,
|
ProductCode = wr.ProductCode,
|
||||||
NotifyMode = wr.NotifyMode,
|
NotifyMode = wn.NotifyMode,
|
||||||
NotifyUserId = wr.NotifyUserId,
|
NotifyTemplate = wn.NotifyTemplate,
|
||||||
|
NotifyUserId = wn.NotifyUserId,
|
||||||
FactorTypeSort = w.FactorTypeSort
|
FactorTypeSort = w.FactorTypeSort
|
||||||
})
|
})
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|||||||
@ -14,12 +14,13 @@ 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);
|
||||||
await Context.Insertable(warning.WarningFactors).ExecuteCommandAsync();
|
|
||||||
|
|
||||||
warning.WarningRules.ForEach(x => x.WarningId = ruleId);
|
warning.WarningRules.ForEach(x => x.WarningId = ruleId);
|
||||||
await Context.Insertable(warning.WarningRules).ExecuteCommandAsync();
|
|
||||||
|
|
||||||
|
await Context.Insertable(warning.WarningFactors).ExecuteCommandAsync();
|
||||||
|
await Context.Insertable(warning.WarningNotifies).ExecuteCommandAsync();
|
||||||
|
await Context.Insertable(warning.WarningRules).ExecuteCommandAsync();
|
||||||
tran.Complete();
|
tran.Complete();
|
||||||
return ruleId;
|
return ruleId;
|
||||||
}
|
}
|
||||||
@ -72,19 +73,8 @@ 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)
|
||||||
await Context.Updateable(warning.WarningRules).WhereColumns(x => new
|
.UpdateColumns(x => new { x.NotifyMode, x.NotifyTemplate, x.NotifyUserId, x.UpdateTime, x.UpdateUserId })
|
||||||
{
|
|
||||||
x.WarningId,
|
|
||||||
x.StartTrackStatusId,
|
|
||||||
x.EndTrackStatusId
|
|
||||||
}).UpdateColumns(x => new
|
|
||||||
{
|
|
||||||
x.NotifyMode,
|
|
||||||
x.NotifyUserId,
|
|
||||||
x.UpdateTime,
|
|
||||||
x.UpdateUserId,
|
|
||||||
}, true)
|
|
||||||
.ExecuteCommandAsync();
|
.ExecuteCommandAsync();
|
||||||
|
|
||||||
tran.Complete();
|
tran.Complete();
|
||||||
@ -104,7 +94,7 @@ public class WarningRepository : BasicRepository<WarningEntity>, IWarningReposit
|
|||||||
.ExecuteCommandAsync() > 0;
|
.ExecuteCommandAsync() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<WarningEntity?> GetWithRulesAsync(int warningId)
|
public async Task<WarningEntity?> GetByIdAsync(int warningId)
|
||||||
{
|
{
|
||||||
var warning = await GetFirstAsync(x => x.Id == warningId);
|
var warning = await GetFirstAsync(x => x.Id == warningId);
|
||||||
|
|
||||||
@ -113,8 +103,7 @@ 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();
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user