From 061cffc6c3bfbcccd57b16d60f46d5bbf4d6c121 Mon Sep 17 00:00:00 2001 From: xiaolipro <2357729423@qq.com> Date: Fri, 26 Jul 2024 12:59:01 +0800 Subject: [PATCH] =?UTF-8?q?add=EF=BC=9A=E9=A2=84=E8=AD=A6crud?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dtos/Forewarning/CreateWarningInput.cs | 42 +++++ .../Dtos/Forewarning/EditWarningOutput.cs | 58 ++++++ .../Dtos/Forewarning/UpdateWarningInput.cs | 45 +++++ .../Helpers/ForewarningHelper.cs | 168 ++++++++++++------ .../ForewarningServices/ForewarningService.cs | 142 +++++++++++---- .../Forewarning/CreateRuleFactorValidation.cs | 1 + .../Forewarning/RuleTrackStateDtoValidator.cs | 2 +- .../IWarningRepository.cs | 32 +++- .../ForewarningAggregate/WarningEntity.cs | 30 +++- .../WarningFactorEntity.cs | 2 +- .../WarningNotifyEntity.cs | 48 +++++ .../ForewarningAggregate/WarningRuleEntity.cs | 2 +- .../Dtos/Forewarning/CreateRuleRequest.cs | 48 ----- ...ckStatusSpanDto.cs => WarningNitifyDto.cs} | 2 +- ...{WarningRuleOutput.cs => WarningRuleVo.cs} | 4 +- .../VEntities/VExternalSubjectEntity.cs | 2 +- src/SJZY.Track.Repository/DataBaseContext.cs | 37 ++-- .../Queries/TrackOrderQueries.cs | 1 - .../Repositories/TrackPushConfigRepository.cs | 1 - .../Repositories/WarningRepository.cs | 65 +++++-- 20 files changed, 530 insertions(+), 202 deletions(-) create mode 100644 src/SJZY.Track.Application.Contract/Dtos/Forewarning/CreateWarningInput.cs create mode 100644 src/SJZY.Track.Application.Contract/Dtos/Forewarning/EditWarningOutput.cs create mode 100644 src/SJZY.Track.Application.Contract/Dtos/Forewarning/UpdateWarningInput.cs create mode 100644 src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/WarningNotifyEntity.cs delete mode 100644 src/SJZY.Track.Domain/Dtos/Forewarning/CreateRuleRequest.cs rename src/SJZY.Track.Domain/Dtos/Forewarning/{TrackStatusSpanDto.cs => WarningNitifyDto.cs} (92%) rename src/SJZY.Track.Domain/Dtos/Forewarning/{WarningRuleOutput.cs => WarningRuleVo.cs} (94%) diff --git a/src/SJZY.Track.Application.Contract/Dtos/Forewarning/CreateWarningInput.cs b/src/SJZY.Track.Application.Contract/Dtos/Forewarning/CreateWarningInput.cs new file mode 100644 index 00000000..0179e744 --- /dev/null +++ b/src/SJZY.Track.Application.Contract/Dtos/Forewarning/CreateWarningInput.cs @@ -0,0 +1,42 @@ +using SJZY.Track.Domain.Dtos.Forewarning; +using SJZY.Track.Domain.Enums; + +namespace SJZY.Track.Application.Contract.Dtos.Forewarning; + +public class CreateWarningInput +{ + /// + /// 模板名称 + /// + public string Name { get; set; } = null!; + + /// + /// 子系统id + /// + public int SubSystemId { get; set; } + + /// + /// 客户id + /// + public int CustomerId { get; set; } + + /// + /// 通知方式 + /// + public NotifyMode NotifyMode { get; set; } + + /// + /// 通知模板 + /// + public string NotifyTemplate { get; set; } = null!; + + /// + /// 轨迹状态跨度列表 + /// + public List TrackStatusSpans { get; set; } = new(); + + /// + /// 预警因素列表。 + /// + public List WarningFactors { get; set; } = new(); +} \ No newline at end of file diff --git a/src/SJZY.Track.Application.Contract/Dtos/Forewarning/EditWarningOutput.cs b/src/SJZY.Track.Application.Contract/Dtos/Forewarning/EditWarningOutput.cs new file mode 100644 index 00000000..f8c65d67 --- /dev/null +++ b/src/SJZY.Track.Application.Contract/Dtos/Forewarning/EditWarningOutput.cs @@ -0,0 +1,58 @@ +using SJZY.Track.Domain.Dtos.Forewarning; +using SJZY.Track.Domain.Enums; + +namespace SJZY.Track.Application.Contract.Dtos.Forewarning; + +public class EditWarningOutput +{ + /// + /// 模板名称 + /// + public string Name { get; set; } = null!; + + /// + /// 子系统id + /// + public int SubSystemId { get; set; } + + /// + /// 客户id + /// + public int CustomerId { get; set; } + + /// + /// 通知方式 + /// + public NotifyMode NotifyMode { get; set; } + + /// + /// 通知模板 + /// + public string NotifyTemplate { get; set; } = null!; + + /// + /// 通知列表 + /// + public List TrackStatusSpans { get; set; } = new(); + + /// + /// 预警因素列表。 + /// + public List WarningFactors { get; set; } = new(); +} + +public class WarningNotifyWithIdDto: WarningNitifyDto +{ + /// + /// 通知id + /// + public int Id { get; set; } +} + +public class WarningFactorWithIdDto : WarningFactorDto +{ + /// + /// 因素id + /// + public int Id { get; set; } +} \ No newline at end of file diff --git a/src/SJZY.Track.Application.Contract/Dtos/Forewarning/UpdateWarningInput.cs b/src/SJZY.Track.Application.Contract/Dtos/Forewarning/UpdateWarningInput.cs new file mode 100644 index 00000000..0d00a8d3 --- /dev/null +++ b/src/SJZY.Track.Application.Contract/Dtos/Forewarning/UpdateWarningInput.cs @@ -0,0 +1,45 @@ +using SJZY.Track.Domain.Dtos.Forewarning; +using SJZY.Track.Domain.Enums; + +namespace SJZY.Track.Application.Contract.Dtos.Forewarning; + +public class UpdateWarningInput +{ + /// + /// 预警id + /// + public int Id { get; set; } + + /// + /// 模板名称 + /// + public string Name { get; set; } = null!; + + /// + /// 通知方式 + /// + public NotifyMode NotifyMode { get; set; } + + /// + /// 通知模板 + /// + public string NotifyTemplate { get; set; } = null!; + + /// + /// 通知列表 + /// + public List Notifies { get; set; } = new(); +} + +public class NotifyDto +{ + /// + /// 通知id + /// + public int Id { get; set; } + + /// + /// 通知人id + /// + public int NotifyUserId { get; set; } +} \ No newline at end of file diff --git a/src/SJZY.Track.Application/Helpers/ForewarningHelper.cs b/src/SJZY.Track.Application/Helpers/ForewarningHelper.cs index c945e018..c03be716 100644 --- a/src/SJZY.Track.Application/Helpers/ForewarningHelper.cs +++ b/src/SJZY.Track.Application/Helpers/ForewarningHelper.cs @@ -1,8 +1,10 @@ using Newtonsoft.Json.Linq; using SJZY.Expand.ABP.Core.PublicMethords; +using SJZY.Track.Application.Contract.Dtos.Forewarning; using SJZY.Track.Domain.Aggregates.ForewarningAggregate; using SJZY.Track.Domain.Dtos.Forewarning; using SJZY.Track.Domain.Enums; +using SqlSugar; namespace SJZY.Track.Application.Helpers; @@ -14,9 +16,14 @@ public class ForewarningHelper /// /// /// - public static List CalcRuleList(List statusSpans, + public static List CalcRuleList(List statusSpans, List factors) { + if (statusSpans.Count == 0 || factors.Count == 0) + { + throw new BusinessException(message: "轨迹状态区间或因素列表为空"); + } + var len = statusSpans.Count * factors.Select(f => f.FactorValue.Count).Aggregate((pre, cur) => pre * cur); if (len == 0) { @@ -32,19 +39,18 @@ public class ForewarningHelper foreach (var factor in factors) { var factorValueCount = factor.FactorValue.Count; - repeat /= factor.FactorValue.Count; // repeat梯度下降,与times成反比关系 - - for (int time = 0; time < len / repeat / factorValueCount; time++) - { - FillFactor(factor, rules, repeat, time); - } + + // repeat梯度下降,与times成反比关系 + repeat /= factor.FactorValue.Count; + var times = len / repeat / factorValueCount; + FillFactor(factor, rules, repeat, times); } return rules; } - private static void FillStatus(List statusSpans, List rules, int repeat) + private static void FillStatus(List statusSpans, List rules, int repeat) { for (var i = 0; i < statusSpans.Count; i++) { @@ -59,70 +65,77 @@ public class ForewarningHelper } } - private static void FillFactor(WarningFactorDto factor, List rules, int repeat, int time) + private static void FillFactor(WarningFactorDto factor, List rules, int repeat, int times) { - for (var i = 0; i < factor.FactorValue.Count * time; i++) + var row = 0; + for (var i = 0; i < times; i++) { - for (var j = 0; j < repeat; j++) + foreach (var value in factor.FactorValue) { - var row = i * repeat + j; - var value = factor.FactorValue[row]; var strValue = value.ToString(); - switch (factor.FactorType) + if (strValue.IsNullOrEmpty()) { - case RuleFactorType.CargoType: - if (value.Type is not JTokenType.String) - { - throw new BusinessException(message: "货物类型只接收字符串"); - } + throw new BusinessException(message: "因素值不能为空"); + } - rules[row].CargoType = strValue; - break; - case RuleFactorType.Months: - foreach (var item in strValue.Split("/")) - { - if (!int.TryParse(item, out var month) || month < 1 || month > 12) + for (var j = 0; j < repeat; j++, row++) + { + switch (factor.FactorType) + { + case RuleFactorType.CargoType: + if (value.Type is not JTokenType.String) { - throw new BusinessException(message: "请输入合法的月份,多个月份请以'/'连接"); + throw new BusinessException(message: "货物类型只接收字符串"); } - } - rules[row].Months = strValue; - break; - case RuleFactorType.Areas: - if (value.Type is not JTokenType.Integer) - { - throw new BusinessException(message: "分区请传id"); - } + rules[row].CargoType = strValue; + break; + case RuleFactorType.Months: + foreach (var item in strValue.Split("/")) + { + if (!int.TryParse(item, out var month) || month < 1 || month > 12) + { + throw new BusinessException(message: "请输入合法的月份,多个月份请以'/'连接"); + } + } - rules[row].AreaId = int.Parse(strValue); - break; - case RuleFactorType.IsTransit: - if (value.Type is not JTokenType.Boolean) - { - throw new BusinessException(message: "是否中转只接收bool类型"); - } + rules[row].Months = strValue; + break; + case RuleFactorType.Areas: + if (value.Type is not JTokenType.Integer) + { + throw new BusinessException(message: "分区请传id"); + } - rules[row].IsTransit = bool.Parse(strValue); - break; - case RuleFactorType.LeavePort: - if (value.Type is not JTokenType.String) - { - throw new BusinessException(message: "货物类型只接收字符串"); - } + rules[row].AreaId = int.Parse(strValue); + break; + case RuleFactorType.IsTransit: + if (value.Type is not JTokenType.Boolean) + { + throw new BusinessException(message: "是否中转只接收bool类型"); + } - rules[row].LeavePort = strValue; - break; - case RuleFactorType.ProductCode: - if (value.Type is not JTokenType.String) - { - throw new BusinessException(message: "货物类型只接收字符串"); - } + rules[row].IsTransit = bool.Parse(strValue); + break; + case RuleFactorType.LeavePort: + if (value.Type is not JTokenType.String) + { + throw new BusinessException(message: "货物类型只接收字符串"); + } - rules[row].ProductCode = strValue; - break; - default: - throw new BusinessException(message: $"不支持的因素:{factor.FactorType}"); + rules[row].LeavePort = strValue; + break; + case RuleFactorType.ProductCode: + if (value.Type is not JTokenType.String) + { + throw new BusinessException(message: "货物类型只接收字符串"); + } + + rules[row].ProductCode = strValue; + break; + default: + throw new BusinessException(message: $"不支持的因素:{factor.FactorType}"); + } } } } @@ -136,4 +149,41 @@ public class ForewarningHelper Value = x.FactorValue.ToJson() }).ToList(); } + + public static List 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) + { + return new EditWarningOutput + { + Name = warning.Name, + SubSystemId = warning.SubSystemId, + CustomerId = warning.CustomerId, + NotifyMode = warning.WarningNotifies.First().NotifyMode, + NotifyTemplate = warning.WarningNotifies.First().NotifyTemplate, + TrackStatusSpans = warning.WarningNotifies.Select(x => new WarningNotifyWithIdDto + { + Id = x.Id, + StartTrackStatusId = x.StartTrackStatusId, + EndTrackStatusId = x.EndTrackStatusId, + NotifyUserId = x.NotifyUserId, + }).ToList(), + WarningFactors = warning.WarningFactors.Select(x => new WarningFactorWithIdDto + { + Id = x.Id, + FactorType = x.Type, + FactorValue = JArray.Parse(x.Value), + }).ToList() + }; + } } \ No newline at end of file diff --git a/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningService.cs b/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningService.cs index 6a1b011d..6d8a61d4 100644 --- a/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningService.cs +++ b/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningService.cs @@ -16,7 +16,19 @@ public class ForewarningService : ApplicationService { _warningRepository = warningRepository; } - + + /// + /// 获取预警分页列表 + /// + /// + /// + [HttpPost("GetWarningPageList")] + public async Task> GetWarningPageList(GetWarningPageInputVo inputVo) + { + if (!inputVo.KeyWord.IsNullOrEmpty()) inputVo.KeyWord = inputVo.KeyWord!.Trim(); + return await _warningRepository.GetWarningPageListAsync(inputVo); + } + /// /// 创建预警 /// @@ -28,10 +40,106 @@ public class ForewarningService : ApplicationService var warning = ObjectMapper.Map(input); warning.WarningRules = ForewarningHelper.CalcRuleList(input.TrackStatusSpans, input.WarningFactors); warning.WarningFactors = ForewarningHelper.MapFactorEntities(input.WarningFactors); + warning.WarningNotifies = ForewarningHelper.MapNotifyEntities(input); await _warningRepository.CreateForewarningAsync(warning); return true; } + + /// + /// 编辑预警 + /// + /// + /// + [HttpPost("EditWarning")] + public async Task EditWarning(int warningId) + { + var warning = await _warningRepository.GetByIdAsync(warningId); + if (warning == null) + { + throw new BusinessException(message: "预警不存在"); + } + + return ForewarningHelper.MapWarningSummary(warning); + } + + /// + /// 更新预警 + /// + /// + /// + [HttpPost("UpdateWarning")] + public async Task UpdateWarning(UpdateWarningInput input) + { + var warning = await _warningRepository.GetFirstAsync(x => x.Id == input.Id); + if (warning == null) + { + throw new BusinessException(message: "预警不存在"); + } + + if (await _warningRepository.IsAnyAsync(x => + x.SubSystemId == warning.SubSystemId && x.CustomerId == warning.CustomerId && x.Id != warning.Id)) + { + throw new BusinessException(message: "该子系统下的客户已经存在一个同名预警: " + warning.Name); + } + + warning.SetName(input.Name); + + warning.WarningNotifies = input.Notifies.Select(x => new WarningNotifyEntity + { + Id = x.Id, + NotifyMode = input.NotifyMode, + NotifyTemplate = input.NotifyTemplate, + NotifyUserId = x.NotifyUserId + }).ToList(); + + await _warningRepository.UpdateForewarningAsync(warning); + + return true; + } + + /// + /// 启用or禁用预警 + /// + /// 预警id + /// 是否启用 + /// + [HttpPost("TurnWarning")] + public async Task TurnWarning(int warningId, bool isEnable) + { + var warning = await _warningRepository.GetFirstAsync(x => x.Id == warningId); + if (warning == null) + { + throw new BusinessException(message: "预警不存在"); + } + + if (isEnable) + { + if (await _warningRepository.IsAnyAsync(x => + x.SubSystemId == warning.SubSystemId && x.CustomerId == warning.CustomerId && x.IsEnable)) + { + throw new BusinessException(message: "该子系统下的客户已经存在一个启用的预警,请先禁用"); + } + } + + warning.SetEnable(isEnable); + + return await _warningRepository.TurnWarningAsync(warning); + } + + /// + /// 查询预警规则列表 + /// + /// 预警规则id + /// + [HttpGet("GetWarningRuleList")] + public async Task> GetWarningRuleListAsync([Required] int warningId) + { + var rules = await _warningRepository.GetWarningRuleListAsync(warningId); + + return rules; + } + /// /// 修改预警规则时效 /// @@ -54,36 +162,4 @@ public class ForewarningService : ApplicationService return true; } - - - /// - /// 获取预警分页列表 - /// - /// - /// - [HttpPost("GetWarningPageList")] - public async Task> GetWarningPageList(GetWarningPageInputVo inputVo) - { - if (!inputVo.KeyWord.IsNullOrEmpty()) inputVo.KeyWord = inputVo.KeyWord!.Trim(); - return await _warningRepository.GetWarningPageListAsync(inputVo); - } - - /// - /// 查询预警规则列表 - /// - /// 预警规则id - /// - [HttpGet("GetWarningRuleList")] - public async Task> GetWarningRuleListAsync([Required] int warningId) - { - return await _warningRepository.GetWarningRuleListAsync(warningId); - } - - /// - /// 发送预警通知 - /// - [HttpPost("SendForewarningNotification")] - public void SendForewarningNotification() - { - } } \ No newline at end of file diff --git a/src/SJZY.Track.Application/Validations/Forewarning/CreateRuleFactorValidation.cs b/src/SJZY.Track.Application/Validations/Forewarning/CreateRuleFactorValidation.cs index cc5cd662..40f58dd3 100644 --- a/src/SJZY.Track.Application/Validations/Forewarning/CreateRuleFactorValidation.cs +++ b/src/SJZY.Track.Application/Validations/Forewarning/CreateRuleFactorValidation.cs @@ -1,4 +1,5 @@ using FluentValidation; +using SJZY.Track.Application.Contract.Dtos.Forewarning; using SJZY.Track.Domain.Dtos.Forewarning; namespace SJZY.Track.Application.Validations.Forewarning; diff --git a/src/SJZY.Track.Application/Validations/Forewarning/RuleTrackStateDtoValidator.cs b/src/SJZY.Track.Application/Validations/Forewarning/RuleTrackStateDtoValidator.cs index 7dab2f60..cf61bc45 100644 --- a/src/SJZY.Track.Application/Validations/Forewarning/RuleTrackStateDtoValidator.cs +++ b/src/SJZY.Track.Application/Validations/Forewarning/RuleTrackStateDtoValidator.cs @@ -3,7 +3,7 @@ using SJZY.Track.Domain.Dtos.Forewarning; namespace SJZY.Track.Application.Validations.Forewarning; -public class RuleTrackStateDtoValidator : AbstractValidator +public class RuleTrackStateDtoValidator : AbstractValidator { public RuleTrackStateDtoValidator() { diff --git a/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/IWarningRepository.cs b/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/IWarningRepository.cs index b3f6bd97..efa73bbd 100644 --- a/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/IWarningRepository.cs +++ b/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/IWarningRepository.cs @@ -5,18 +5,11 @@ namespace SJZY.Track.Domain.Aggregates.ForewarningAggregate; public interface IWarningRepository : IBasicRepository { /// - /// 创建预警 + /// 创建预警,include factors, notifies, rules /// /// /// Task CreateForewarningAsync(WarningEntity warning); - - /// - /// 修改预警 - /// - /// - /// - Task UpdateForewarningAsync(WarningEntity warning); /// /// 复制预警 @@ -37,7 +30,14 @@ public interface IWarningRepository : IBasicRepository /// /// 预警id /// - Task> GetWarningRuleListAsync(int warningId); + Task> GetWarningRuleListAsync(int warningId); + + /// + /// 修改预警 + /// + /// + /// + Task UpdateForewarningAsync(WarningEntity warning); /// /// 修改预警时效 @@ -45,4 +45,18 @@ public interface IWarningRepository : IBasicRepository /// /// Task ModifyTimeSpansAsync(List inputItems); + + /// + /// 启用预警 + /// + /// + /// + Task TurnWarningAsync(WarningEntity warning); + + /// + /// 获取预警,include factors, notifies + /// + /// + /// + Task GetByIdAsync(int warningId); } \ No newline at end of file diff --git a/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/WarningEntity.cs b/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/WarningEntity.cs index b713ffe0..abfc0064 100644 --- a/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/WarningEntity.cs +++ b/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/WarningEntity.cs @@ -1,3 +1,6 @@ +using SJZY.Track.Domain.Enums; +using Volo.Abp; + namespace SJZY.Track.Domain.Aggregates.ForewarningAggregate; [SugarTable("t_warning")] @@ -21,12 +24,6 @@ public class WarningEntity: IFullAuditedBasicEntitys, IAggregateRoot [SugarColumn(ColumnName = "CustomerId")] public int CustomerId { get; set; } - /// - /// 客户 - /// - [SugarColumn(ColumnName = "CustomerName", Length = 255)] - public string CustomerName { get; set; } = null!; - /// /// 规则模板名称,KPI名称 /// @@ -50,4 +47,25 @@ public class WarningEntity: IFullAuditedBasicEntitys, IAggregateRoot /// [SugarColumn(IsIgnore = true)] public List WarningFactors { get; set; } = new(); + + /// + /// 预警通知 + /// + [SugarColumn(IsIgnore = true)] + public List WarningNotifies { get; set; } = new(); + + public void SetName(string name) + { + Name = name; + } + + public void SetEnable(bool isEnable) + { + if (IsEnable == isEnable) + { + throw new BusinessException(message: $"预警已经是{(isEnable ? "启用" : "禁用")}状态"); + } + + IsEnable = isEnable; + } } \ No newline at end of file diff --git a/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/WarningFactorEntity.cs b/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/WarningFactorEntity.cs index 62a37538..46d9c4d8 100644 --- a/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/WarningFactorEntity.cs +++ b/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/WarningFactorEntity.cs @@ -2,7 +2,7 @@ using SJZY.Track.Domain.Enums; namespace SJZY.Track.Domain.Aggregates.ForewarningAggregate; -public class WarningFactorEntity : IFullAuditedBasicEntitys +public class WarningFactorEntity : IFullAuditedBasicEntitys, IEntity { /// /// 自增主键 diff --git a/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/WarningNotifyEntity.cs b/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/WarningNotifyEntity.cs new file mode 100644 index 00000000..1b08f86f --- /dev/null +++ b/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/WarningNotifyEntity.cs @@ -0,0 +1,48 @@ +using SJZY.Track.Domain.Enums; + +namespace SJZY.Track.Domain.Aggregates.ForewarningAggregate; + +public class WarningNotifyEntity : IFullAuditedBasicEntitys, IEntity +{ + /// + /// 自增主键 + /// + [SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)] + public int Id { get; set; } + + /// + /// 预警id + /// + [SugarColumn(ColumnName = "WarningId")] + public int WarningId { get; set; } + + /// + /// 起始轨迹状态id + /// + [SugarColumn(ColumnName = "StartTrackStatusId", IsNullable = false)] + public int StartTrackStatusId { get; set; } + + /// + /// 终止轨迹状态id + /// + [SugarColumn(ColumnName = "EndTrackStatusId", IsNullable = false)] + public int EndTrackStatusId { get; set; } + + /// + /// 通知方式 + /// + [SugarColumn(ColumnName = "NotifyMode")] + public NotifyMode NotifyMode { get; set; } + + /// + /// 通知模板 + /// + [SugarColumn(ColumnName = "NotifyTemplate", Length = 256)] + public string NotifyTemplate { get; set; } = null!; + + /// + /// 通知人 + /// + [SugarColumn(ColumnName = "NotifyUserId")] + public int NotifyUserId { get; set; } +} \ No newline at end of file diff --git a/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/WarningRuleEntity.cs b/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/WarningRuleEntity.cs index ce26f2a1..4baac33e 100644 --- a/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/WarningRuleEntity.cs +++ b/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/WarningRuleEntity.cs @@ -1,7 +1,7 @@ namespace SJZY.Track.Domain.Aggregates.ForewarningAggregate; [SugarTable("t_warning_rule")] -public class WarningRuleEntity : IFullAuditedBasicEntitys +public class WarningRuleEntity : IFullAuditedBasicEntitys, IEntity { /// /// 自增主键 diff --git a/src/SJZY.Track.Domain/Dtos/Forewarning/CreateRuleRequest.cs b/src/SJZY.Track.Domain/Dtos/Forewarning/CreateRuleRequest.cs deleted file mode 100644 index 0226853e..00000000 --- a/src/SJZY.Track.Domain/Dtos/Forewarning/CreateRuleRequest.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using SJZY.Track.Domain.Enums; - -namespace SJZY.Track.Domain.Dtos.Forewarning -{ - public class CreateWarningInput - { - /// - /// 模板名称 - /// - public string Name { get; set; } = null!; - - /// - /// 子系统id - /// - public int SubSystemId { get; set; } - - /// - /// 客户id - /// - public int CustomerId { get; set; } - - /// - /// 客户名称 - /// - public string CustomerName { get; set; } = null!; - - /// - /// 通知方式 - /// - public NotifyMode NotifyMode { get; set; } - - /// - /// 通知模板 - /// - public string NotifyTemplate { get; set; } = null!; - - /// - /// 轨迹状态跨度列表 - /// - public List TrackStatusSpans { get; set; } = new(); - - /// - /// 预警因素列表。 - /// - public List WarningFactors { get; set; } = new(); - } -} \ No newline at end of file diff --git a/src/SJZY.Track.Domain/Dtos/Forewarning/TrackStatusSpanDto.cs b/src/SJZY.Track.Domain/Dtos/Forewarning/WarningNitifyDto.cs similarity index 92% rename from src/SJZY.Track.Domain/Dtos/Forewarning/TrackStatusSpanDto.cs rename to src/SJZY.Track.Domain/Dtos/Forewarning/WarningNitifyDto.cs index f9eda466..255a421a 100644 --- a/src/SJZY.Track.Domain/Dtos/Forewarning/TrackStatusSpanDto.cs +++ b/src/SJZY.Track.Domain/Dtos/Forewarning/WarningNitifyDto.cs @@ -1,6 +1,6 @@ namespace SJZY.Track.Domain.Dtos.Forewarning; -public class TrackStatusSpanDto +public class WarningNitifyDto { /// /// 起始轨迹状态id diff --git a/src/SJZY.Track.Domain/Dtos/Forewarning/WarningRuleOutput.cs b/src/SJZY.Track.Domain/Dtos/Forewarning/WarningRuleVo.cs similarity index 94% rename from src/SJZY.Track.Domain/Dtos/Forewarning/WarningRuleOutput.cs rename to src/SJZY.Track.Domain/Dtos/Forewarning/WarningRuleVo.cs index c614eb38..439393e1 100644 --- a/src/SJZY.Track.Domain/Dtos/Forewarning/WarningRuleOutput.cs +++ b/src/SJZY.Track.Domain/Dtos/Forewarning/WarningRuleVo.cs @@ -1,6 +1,6 @@ namespace SJZY.Track.Domain.Dtos.Forewarning; -public class WarningRuleOutput +public class WarningRuleVo { /// /// 自增主键 @@ -45,7 +45,7 @@ public class WarningRuleOutput /// /// 区域 /// - public int? AreaId { get; set; } + public string? Area { get; set; } /// /// 是否中转 diff --git a/src/SJZY.Track.Domain/VEntities/VExternalSubjectEntity.cs b/src/SJZY.Track.Domain/VEntities/VExternalSubjectEntity.cs index 51bea216..1743a9fd 100644 --- a/src/SJZY.Track.Domain/VEntities/VExternalSubjectEntity.cs +++ b/src/SJZY.Track.Domain/VEntities/VExternalSubjectEntity.cs @@ -1,4 +1,4 @@ -namespace SJZY.Track.Repository.VData.Entitys; +namespace SJZY.Track.Domain.VEntities; /// /// 外部主体 diff --git a/src/SJZY.Track.Repository/DataBaseContext.cs b/src/SJZY.Track.Repository/DataBaseContext.cs index 88539836..afc9be0c 100644 --- a/src/SJZY.Track.Repository/DataBaseContext.cs +++ b/src/SJZY.Track.Repository/DataBaseContext.cs @@ -20,21 +20,20 @@ public class DataBaseContext //新增 if (entityInfo.OperationType == DataFilterType.InsertByObject) { + var time = DateTime.Now; + var userId = CurrentUserRequest.CurrentUser.UserId; + if (entityInfo.PropertyName == nameof(ICreateBaicEntity.CreateTime)) - entityInfo.SetValue(DateTime.Now); - if (entityInfo.PropertyName == nameof(ICreateBaicEntity.CreateUserId)) + entityInfo.SetValue(time); + else if (entityInfo.PropertyName == nameof(IUpdateBasicEntity.UpdateTime)) + entityInfo.SetValue(time); + else if (entityInfo.PropertyName == nameof(ICreateBaicEntity.CreateUserId)) { - if (oldValue == null || (int)oldValue == 0) - { - try - { - entityInfo.SetValue(CurrentUserRequest.CurrentUser?.UserId); - } - catch - { - } - } - //entityInfo.SetValue(CurrentUserRequest.CurrentUser.UserId); + entityInfo.SetValue(userId); + } + else if (entityInfo.PropertyName == nameof(IUpdateBasicEntity.UpdateUserId)) + { + entityInfo.SetValue(userId); } } //修改 @@ -44,17 +43,7 @@ public class DataBaseContext entityInfo.SetValue(DateTime.Now); else if (entityInfo.PropertyName == nameof(IUpdateBasicEntity.UpdateUserId)) { - if (oldValue == null || (int)oldValue == 1) - { - try - { - entityInfo.SetValue(CurrentUserRequest.CurrentUser.UserId); - } - catch - { - } - } - //entityInfo.SetValue(CurrentUserRequest.CurrentUser.UserId); + entityInfo.SetValue(CurrentUserRequest.CurrentUser.UserId); } //删除 else if (entityInfo.PropertyName == nameof(IDeleteBasicEntity.IsDeleted)) diff --git a/src/SJZY.Track.Repository/Queries/TrackOrderQueries.cs b/src/SJZY.Track.Repository/Queries/TrackOrderQueries.cs index 841a3555..669ed58c 100644 --- a/src/SJZY.Track.Repository/Queries/TrackOrderQueries.cs +++ b/src/SJZY.Track.Repository/Queries/TrackOrderQueries.cs @@ -4,7 +4,6 @@ using SJZY.Track.Domain.Dtos.Order; using SJZY.Track.Domain.Enums; using SJZY.Track.Domain.Queries; using SJZY.Track.Domain.VEntities; -using SJZY.Track.Repository.VData.Entitys; namespace SJZY.Track.Repository.Queries; diff --git a/src/SJZY.Track.Repository/Repositories/TrackPushConfigRepository.cs b/src/SJZY.Track.Repository/Repositories/TrackPushConfigRepository.cs index c7e21820..f073f286 100644 --- a/src/SJZY.Track.Repository/Repositories/TrackPushConfigRepository.cs +++ b/src/SJZY.Track.Repository/Repositories/TrackPushConfigRepository.cs @@ -6,7 +6,6 @@ using SJZY.Track.Domain.Dtos.Common; using SJZY.Track.Domain.Dtos.TrackPush; using SJZY.Track.Domain.Enums; using SJZY.Track.Domain.VEntities; -using SJZY.Track.Repository.VData.Entitys; namespace SJZY.Track.Repository.Repositories; diff --git a/src/SJZY.Track.Repository/Repositories/WarningRepository.cs b/src/SJZY.Track.Repository/Repositories/WarningRepository.cs index 81c704ac..fe25f1d7 100644 --- a/src/SJZY.Track.Repository/Repositories/WarningRepository.cs +++ b/src/SJZY.Track.Repository/Repositories/WarningRepository.cs @@ -1,5 +1,6 @@ using SJZY.Track.Domain; using SJZY.Track.Domain.Aggregates.ForewarningAggregate; +using SJZY.Track.Domain.Aggregates.KPIAreaAggregate; using SJZY.Track.Domain.Aggregates.TrackStatusAggregate; using SJZY.Track.Domain.Dtos.Forewarning; using SJZY.Track.Domain.VEntities; @@ -13,20 +14,17 @@ public class WarningRepository : BasicRepository, IWarningReposit using var tran = TransactionHelper.GetReadCommitted(); var ruleId = await InsertReturnIdentityAsync(warning); - warning.WarningRules.ForEach(x => x.WarningId = ruleId); + warning.WarningNotifies.ForEach(x => x.WarningId = ruleId); warning.WarningFactors.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(); return ruleId; } - public Task UpdateForewarningAsync(WarningEntity warning) - { - throw new NotImplementedException(); - } - public Task CopyForewarning(int warningId) { throw new NotImplementedException(); @@ -36,40 +34,79 @@ public class WarningRepository : BasicRepository, IWarningReposit { var query = Context.Queryable() .LeftJoin((a, b) => a.SubSystemId == b.Id) + .LeftJoin((a, b, c) => a.CustomerId == c.Id) .WhereIF(input.SystemId.HasValue, (a, b) => a.SubSystemId == input.SystemId) - .WhereIF(!string.IsNullOrEmpty(input.KeyWord), a => a.CustomerName.Contains(input.KeyWord!) || a.Name.Contains(input.KeyWord!)) + .WhereIF(!string.IsNullOrEmpty(input.KeyWord), + (a, b, c) => a.Name.Contains(input.KeyWord!) || c.Name.Contains(input.KeyWord!)) .OrderBy(a => a.UpdateTime, OrderByType.Desc); return query - .Select((a, b) => new WarningPageOutput + .Select((a, b, c) => new WarningPageOutput { Id = a.Id, SubSystem = b.CnName, - Custom = a.CustomerName, + Custom = c.Name, Name = a.Name, UpdateTime = a.UpdateTime }) .ToPagedListAsync(input.PageIndex, input.PageSize); } - - public async Task> GetWarningRuleListAsync(int warningId) + + public async Task> GetWarningRuleListAsync(int warningId) { return await Context.Queryable() .LeftJoin((a, b) => a.StartTrackStatusId == b.Id) .LeftJoin((a, b, c) => a.EndTrackStatusId == c.Id) + .LeftJoin((a, b, c, d) => a.AreaId == d.Id) .Where(a => a.WarningId == warningId) - .Select((a, b, c) => new WarningRuleOutput + .Select((a, b, c, d) => new WarningRuleVo { StartTrackStatus = b.Status, EndTrackStatus = c.Status, + Area = d.Name }, true) .ToListAsync(); } + public async Task UpdateForewarningAsync(WarningEntity warning) + { + using var tran = TransactionHelper.GetReadCommitted(); + + await Context.Updateable(warning).ExecuteCommandAsync(); + await Context.Updateable(warning.WarningNotifies) + .UpdateColumns(x => new { x.NotifyMode, x.NotifyTemplate, x.NotifyUserId, x.UpdateTime, x.UpdateUserId }) + .ExecuteCommandAsync(); + + tran.Complete(); + } + public async Task ModifyTimeSpansAsync(List rules) { return await Context.Updateable(rules) - .UpdateColumns(x => new { x.TotalTimeSpan, x.WarnTimeSpan, x.WarnCount }) + .UpdateColumns(x => new { x.TotalTimeSpan, x.WarnTimeSpan, x.WarnCount, x.UpdateTime, x.UpdateUserId }) .ExecuteCommandAsync(); } + + public async Task TurnWarningAsync(WarningEntity warning) + { + return await Context.Updateable(warning) + .UpdateColumns(x => new { x.IsEnable, x.UpdateTime, x.UpdateUserId }) + .ExecuteCommandAsync() > 0; + } + + public async Task GetByIdAsync(int warningId) + { + var warning = await GetFirstAsync(x => x.Id == warningId); + + if (warning == null) return null; + + warning.WarningFactors = await Context.Queryable() + .Where(x => x.WarningId == warningId) + .ToListAsync(); + warning.WarningNotifies = await Context.Queryable() + .Where(x => x.WarningId == warningId) + .ToListAsync(); + + return warning; + } } \ No newline at end of file