From 29624edec3c665d23be849f304e57a5b3b5c5e06 Mon Sep 17 00:00:00 2001 From: xiaolipro <2357729423@qq.com> Date: Mon, 30 Sep 2024 15:25:55 +0800 Subject: [PATCH] =?UTF-8?q?change=EF=BC=9A=E6=94=AF=E6=8C=81otel=20con?= =?UTF-8?q?=EF=BC=9A=E5=AF=B9=E6=8E=A5=E5=89=8D=E7=AB=AF=EF=BC=8C=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E9=A2=84=E8=AD=A6=E7=BC=96=E8=BE=91=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=8C=BA=E5=9F=9F=E7=BB=99name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/SJZY.Track.Application/FodyWeavers.xml | 3 ++ src/SJZY.Track.Application/FodyWeavers.xsd | 26 ++++++++++ .../Helpers/ForewarningHelper.cs | 28 ++++++++-- .../SJZY.Track.Application.csproj | 1 + .../Services/DebugApis/OTelService.cs | 51 +++++++++++++++++++ .../ForewarningNotifyService.cs | 2 +- .../ForewarningServices/ForewarningService.cs | 13 ++++- .../ForewarningAggregate/RuleAreaEntity.cs | 6 --- .../Aggregates/KPIAreaAggregate.cs | 6 --- src/SJZY.Track.Domain/FodyWeavers.xml | 3 ++ src/SJZY.Track.Domain/FodyWeavers.xsd | 31 +++++++++++ .../SJZY.Track.Domain.csproj | 7 +-- 12 files changed, 151 insertions(+), 26 deletions(-) create mode 100644 src/SJZY.Track.Application/FodyWeavers.xml create mode 100644 src/SJZY.Track.Application/FodyWeavers.xsd create mode 100644 src/SJZY.Track.Application/Services/DebugApis/OTelService.cs delete mode 100644 src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/RuleAreaEntity.cs delete mode 100644 src/SJZY.Track.Domain/Aggregates/KPIAreaAggregate.cs create mode 100644 src/SJZY.Track.Domain/FodyWeavers.xml create mode 100644 src/SJZY.Track.Domain/FodyWeavers.xsd diff --git a/src/SJZY.Track.Application/FodyWeavers.xml b/src/SJZY.Track.Application/FodyWeavers.xml new file mode 100644 index 00000000..510b255f --- /dev/null +++ b/src/SJZY.Track.Application/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + diff --git a/src/SJZY.Track.Application/FodyWeavers.xsd b/src/SJZY.Track.Application/FodyWeavers.xsd new file mode 100644 index 00000000..f35a69b7 --- /dev/null +++ b/src/SJZY.Track.Application/FodyWeavers.xsd @@ -0,0 +1,26 @@ + + + + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ 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 f91da6db..62243800 100644 --- a/src/SJZY.Track.Application/Helpers/ForewarningHelper.cs +++ b/src/SJZY.Track.Application/Helpers/ForewarningHelper.cs @@ -164,9 +164,11 @@ public class ForewarningHelper }).ToList(); } - public static EditWarningOutput MapWarningSummary(WarningEntity warning, List statusList) + public static EditWarningOutput MapWarningSummary(WarningEntity warning, List statusList, + List areaList) { var statusDic = statusList.ToDictionary(x => x.Id, x => x.Name); + var areaDic = areaList.ToDictionary(x => x.Id, x => x.Name); return new EditWarningOutput { Name = warning.Name, @@ -184,11 +186,27 @@ public class ForewarningHelper ? new List() : x.NotifyMode.Split(',').Select(int.Parse).ToList(), }).ToList(), - WarningFactors = warning.WarningFactors.Select(x => new WarningFactorWithIdDto + WarningFactors = warning.WarningFactors.Select(x => { - Id = x.Id, - FactorType = (int) x.Type, - FactorValue = JsonConvert.DeserializeObject>(x.Value)!, + if (x.Type == RuleFactorType.Area) + { + var areaIds = JsonConvert.DeserializeObject>(x.Value); + return new WarningFactorWithIdDto + { + Id = x.Id, + FactorType = (int) x.Type, + FactorValue = areaIds? + .Select(area => areaDic.TryGetValue(area, out var name) ? name : area.ToString()) + .Cast().ToList() ?? new List(), + }; + } + + return new WarningFactorWithIdDto + { + Id = x.Id, + FactorType = (int) x.Type, + FactorValue = JsonConvert.DeserializeObject>(x.Value)!, + }; }).ToList() }; } diff --git a/src/SJZY.Track.Application/SJZY.Track.Application.csproj b/src/SJZY.Track.Application/SJZY.Track.Application.csproj index 67055e65..7e97d032 100644 --- a/src/SJZY.Track.Application/SJZY.Track.Application.csproj +++ b/src/SJZY.Track.Application/SJZY.Track.Application.csproj @@ -20,6 +20,7 @@ + diff --git a/src/SJZY.Track.Application/Services/DebugApis/OTelService.cs b/src/SJZY.Track.Application/Services/DebugApis/OTelService.cs new file mode 100644 index 00000000..8e2a9ddf --- /dev/null +++ b/src/SJZY.Track.Application/Services/DebugApis/OTelService.cs @@ -0,0 +1,51 @@ +using Microsoft.AspNetCore.Authorization; +using SJZY.OTel; +using SJZY.Track.Domain.Aggregates.OrderAggregate; + +namespace SJZY.Track.Application.Services.DebugApis; + +[AllowAnonymous] +[ApiExplorerSettings(GroupName = "调试专用")] +public class OTelService : ApplicationService +{ + private readonly IBasicRepository _orderRepository; + + public OTelService(IBasicRepository orderRepository) + { + _orderRepository = orderRepository; + } + + [OTel] + public async Task Hello(string name) + { + var order = await _orderRepository.GetFirstAsync(x => true); + if (order == null) + { + throw new BusinessException(message: "订单不存在"); + } + + await DoSomethingAsync(order); + + return $"hello {name}"; + } + + [OTel] + private async Task DoSomethingAsync(OrderEntity order) + { + var order2 = await _orderRepository.GetFirstAsync(x => true); + + if (order.Id == order2?.Id) + { + await Task.Delay(3000); + } + + + await DoWorkAsync(); + } + + [OTel] + private async Task DoWorkAsync() + { + await Task.Delay(1000); + } +} diff --git a/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningNotifyService.cs b/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningNotifyService.cs index 2749e8a9..8fd2819a 100644 --- a/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningNotifyService.cs +++ b/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningNotifyService.cs @@ -110,7 +110,7 @@ public class ForewarningNotifyService : IForewarningNotifyService, ITransientDep tran.Exec(); - LogHelper.Info($"本次共计产生{addCounter}条预警,移除{delCounter}条预警,触发缘由是"); + LogHelper.Info($"本次共计产生{addCounter}条预警,移除{delCounter}条预警,触发缘由是{dto}"); await _warningRecordEsRepository.BulkUpdateAsync(dels); // 标记处理完成 } diff --git a/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningService.cs b/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningService.cs index ae39736d..ff697642 100644 --- a/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningService.cs +++ b/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningService.cs @@ -4,6 +4,7 @@ using SJZY.Track.Application.Contract.Dtos.Forewarning; using SJZY.Track.Application.Contract.Services; using SJZY.Track.Application.Helpers; using SJZY.Track.Domain.Aggregates.ForewarningAggregate; +using SJZY.Track.Domain.Aggregates.KPIAreaAggregate; using SJZY.Track.Domain.Aggregates.TrackStatusAggregate; using SJZY.Track.Domain.Dtos.Common; using SJZY.Track.Domain.Dtos.Forewarning; @@ -69,7 +70,8 @@ public class ForewarningService : ApplicationService /// [HttpGet("EditWarning")] public async Task EditWarning(int warningId, - [FromServices] IBasicQuery statusQuery) + [FromServices] IBasicQuery statusQuery, + [FromServices] IKpiAreaRepository kpiAreaRepository) { var warning = await _warningRepository.GetByIdAsync(warningId); @@ -85,7 +87,14 @@ public class ForewarningService : ApplicationService Name = x.Status }); - return ForewarningHelper.MapWarningSummary(warning, statusList); + var areaList = await kpiAreaRepository.GetListAsync(x => x.SubSystemId == warning.SubSystemId, x => + new IdWithNameDto + { + Id = x.Id, + Name = x.Name + }); + + return ForewarningHelper.MapWarningSummary(warning, statusList, areaList); } /// diff --git a/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/RuleAreaEntity.cs b/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/RuleAreaEntity.cs deleted file mode 100644 index c6325956..00000000 --- a/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/RuleAreaEntity.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace SJZY.Track.Domain.Aggregates.ForewarningAggregate; - -public class RuleAreaEntity -{ - -} \ No newline at end of file diff --git a/src/SJZY.Track.Domain/Aggregates/KPIAreaAggregate.cs b/src/SJZY.Track.Domain/Aggregates/KPIAreaAggregate.cs deleted file mode 100644 index 353b4ebc..00000000 --- a/src/SJZY.Track.Domain/Aggregates/KPIAreaAggregate.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace SJZY.Track.Domain.Aggregates; - -public class KPIAreaAggregate -{ - -} \ No newline at end of file diff --git a/src/SJZY.Track.Domain/FodyWeavers.xml b/src/SJZY.Track.Domain/FodyWeavers.xml new file mode 100644 index 00000000..510b255f --- /dev/null +++ b/src/SJZY.Track.Domain/FodyWeavers.xml @@ -0,0 +1,3 @@ + + + diff --git a/src/SJZY.Track.Domain/FodyWeavers.xsd b/src/SJZY.Track.Domain/FodyWeavers.xsd new file mode 100644 index 00000000..d1150002 --- /dev/null +++ b/src/SJZY.Track.Domain/FodyWeavers.xsd @@ -0,0 +1,31 @@ + + + + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all + weavers have been executed. + + + + + + A comma-separated list of error codes that can be safely ignored in assembly + verification. + + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + + diff --git a/src/SJZY.Track.Domain/SJZY.Track.Domain.csproj b/src/SJZY.Track.Domain/SJZY.Track.Domain.csproj index ea3705c5..d3ab704d 100644 --- a/src/SJZY.Track.Domain/SJZY.Track.Domain.csproj +++ b/src/SJZY.Track.Domain/SJZY.Track.Domain.csproj @@ -6,15 +6,10 @@ net7.0 True - + - - - - -