This commit is contained in:
xiaolipro 2024-10-08 10:35:43 +08:00
parent 775256c128
commit ec04a43d44
7 changed files with 21 additions and 18 deletions

View File

@ -20,7 +20,7 @@
<PackageReference Include="DotNetCore.CAP.RabbitMQ" Version="8.2.0"/> <PackageReference Include="DotNetCore.CAP.RabbitMQ" Version="8.2.0"/>
<PackageReference Include="DotNetCore.CAP.MySql" Version="8.2.0"/> <PackageReference Include="DotNetCore.CAP.MySql" Version="8.2.0"/>
<PackageReference Include="DotNetCore.CAP.InMemoryStorage" Version="8.2.0"/> <PackageReference Include="DotNetCore.CAP.InMemoryStorage" Version="8.2.0"/>
<PackageReference Include="SJZY.OTel" Version="1.0.8"/> <!-- <PackageReference Include="SJZY.OTel" Version="1.0.8"/>-->
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using SJZY.OTel;
using SJZY.Track.Domain.Aggregates.OrderAggregate; using SJZY.Track.Domain.Aggregates.OrderAggregate;
namespace SJZY.Track.Application.Services.DebugApis; namespace SJZY.Track.Application.Services.DebugApis;
@ -15,7 +14,7 @@ public class OTelService : ApplicationService
_orderRepository = orderRepository; _orderRepository = orderRepository;
} }
[OTel] // [OTel]
public async Task<string> Hello(string name) public async Task<string> Hello(string name)
{ {
var order = await _orderRepository.GetFirstAsync(x => true); var order = await _orderRepository.GetFirstAsync(x => true);
@ -29,7 +28,7 @@ public class OTelService : ApplicationService
return $"hello {name}"; return $"hello {name}";
} }
[OTel] // [OTel]
private async Task DoSomethingAsync(OrderEntity order) private async Task DoSomethingAsync(OrderEntity order)
{ {
var order2 = await _orderRepository.GetFirstAsync(x => true); var order2 = await _orderRepository.GetFirstAsync(x => true);
@ -43,7 +42,7 @@ public class OTelService : ApplicationService
await DoWorkAsync(); await DoWorkAsync();
} }
[OTel] // [OTel]
private async Task DoWorkAsync() private async Task DoWorkAsync()
{ {
await Task.Delay(1000); await Task.Delay(1000);

View File

@ -67,7 +67,7 @@ public class ForewarningNotifyService : IForewarningNotifyService, ITransientDep
var interval = (rule.TotalTimeSpan - rule.WarnTimeSpan) / rule.WarnCount; var interval = (rule.TotalTimeSpan - rule.WarnTimeSpan) / rule.WarnCount;
var startTime = order.TrackTime.AddHours(rule.WarnTimeSpan); var startTime = order.TrackTime.AddHours(rule.WarnTimeSpan);
for (var i = 0; i < rule.WarnCount; i++) for (var i = 1; i <= rule.WarnCount; i++)
{ {
var timestamp = GetTimestamp(startTime); var timestamp = GetTimestamp(startTime);
startTime = startTime.AddHours(interval); startTime = startTime.AddHours(interval);
@ -83,7 +83,7 @@ public class ForewarningNotifyService : IForewarningNotifyService, ITransientDep
order order
).ForEach(rule => ).ForEach(rule =>
{ {
for (var i = 0; i < rule.WarnCount; i++) for (var i = 1; i <= rule.WarnCount; i++)
{ {
dels.Add((rule.Id, order.Id, i)); dels.Add((rule.Id, order.Id, i));
} }
@ -135,12 +135,13 @@ public class ForewarningNotifyService : IForewarningNotifyService, ITransientDep
// 写入es预警记录 // 写入es预警记录
var warningRecords = await WriteWarningRecordAsync(entries, notifyRules); var warningRecords = await WriteWarningRecordAsync(entries, notifyRules);
// 发通知
await SendCoreAsync(subSystemId, entries, notifyRules);
// 移除已处理的预警 // 移除已处理的预警
await RedisHelper.Client.ZRemRangeByScoreAsync(redisKey, 0, timestamp); await RedisHelper.Client.ZRemRangeByScoreAsync(redisKey, 0, timestamp);
// 发通知
// tips:通知发送失败不应该影响预警记录的写入,可以进入重试队列
await SendCoreAsync(subSystemId, entries, notifyRules);
return warningRecords.Count; return warningRecords.Count;
} }
@ -161,6 +162,7 @@ public class ForewarningNotifyService : IForewarningNotifyService, ITransientDep
SubSystemId = rule.SubSystemId, SubSystemId = rule.SubSystemId,
SubSystemName = rule.SubSystemName, SubSystemName = rule.SubSystemName,
WarningName = rule.WarningName, WarningName = rule.WarningName,
CustomId = rule.CustomId,
CustomName = rule.CustomName, CustomName = rule.CustomName,
RuleId = entry.RuleId, RuleId = entry.RuleId,
Rule = rule.ToString(), Rule = rule.ToString(),
@ -275,7 +277,7 @@ public class ForewarningNotifyService : IForewarningNotifyService, ITransientDep
{ {
// todo:失败是否上报重试? // todo:失败是否上报重试?
LogHelper.Error( LogHelper.Error(
$"{nameof(ForewarningNotifyService)} 发送{mode.ToString()}通知失败,用户:{userId},内容:\n{msgContent}\n失败报文:{res.ToJson()}"); $"{nameof(ForewarningNotifyService)} 发送{mode.ToString()}通知失败,用户:{userId}\n内容:\n{msgContent}\n失败报文:{res.ToJson()}");
} }
} }

View File

@ -26,6 +26,7 @@ public class OrderWarningService : ApplicationService
/// <param name="inputVo"></param> /// <param name="inputVo"></param>
/// <param name="userId"></param> /// <param name="userId"></param>
/// <returns></returns> /// <returns></returns>
[HttpGet("GetOrderWarningPageList/{userId:int?}")]
[HttpPost("GetOrderWarningPageList")] [HttpPost("GetOrderWarningPageList")]
public async Task<UnifyPageResultDto<GetOrderWarningPageOutput>> GetOrderWarningPageListAsync( public async Task<UnifyPageResultDto<GetOrderWarningPageOutput>> GetOrderWarningPageListAsync(
[FromBody] GetOrderWarningPageListVo inputVo, [FromQuery] int? userId) [FromBody] GetOrderWarningPageListVo inputVo, [FromQuery] int? userId)
@ -64,6 +65,8 @@ public class OrderWarningService : ApplicationService
item.LatestTrackTime = order.LatestTrackTime; item.LatestTrackTime = order.LatestTrackTime;
item.LatestTrackPlace = order.LatestTrackPlace; item.LatestTrackPlace = order.LatestTrackPlace;
item.LatestTrackContent = order.LatestTrackContent; item.LatestTrackContent = order.LatestTrackContent;
list.Add(item);
}); });
return new UnifyPageResultDto<GetOrderWarningPageOutput>(list, inputVo.PageIndex, inputVo.PageSize, return new UnifyPageResultDto<GetOrderWarningPageOutput>(list, inputVo.PageIndex, inputVo.PageSize,

View File

@ -3,7 +3,6 @@ using DotNetCore.CAP;
using DotNetCore.CAP.Internal; using DotNetCore.CAP.Internal;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using RabbitMQ.Client; using RabbitMQ.Client;
using Savorboard.CAP.InMemoryMessageQueue;
using SJZY.Expand.ABP.Core.Localization; using SJZY.Expand.ABP.Core.Localization;
using SJZY.Expand.ABP.Core.Logger; using SJZY.Expand.ABP.Core.Logger;
using SJZY.Expand.ABP.Core.PublicMethords; using SJZY.Expand.ABP.Core.PublicMethords;
@ -84,10 +83,6 @@ public class SjzyTrackApplicationModule : AbpModule
context.Services.AddCapTableNameService(); context.Services.AddCapTableNameService();
context.Services.AddCap(options => context.Services.AddCap(options =>
{ {
#if DEBUG
options.UseInMemoryStorage();
options.UseInMemoryMessageQueue();
#else
options.UseMySql(configuration["ConnectionStrings:DefaultConnection"]!); options.UseMySql(configuration["ConnectionStrings:DefaultConnection"]!);
options.UseRabbitMQ(configure => options.UseRabbitMQ(configure =>
{ {
@ -98,7 +93,6 @@ public class SjzyTrackApplicationModule : AbpModule
configure.BasicQosOptions = configure.BasicQosOptions =
new RabbitMQOptions.BasicQos(configuration.GetValue<ushort>("CAP:PrefetchCount")); new RabbitMQOptions.BasicQos(configuration.GetValue<ushort>("CAP:PrefetchCount"));
}); });
#endif
options.FailedRetryInterval = configuration.GetValue<int>("CAP:FailedRetryInterval"); options.FailedRetryInterval = configuration.GetValue<int>("CAP:FailedRetryInterval");
options.FailedRetryCount = configuration.GetValue<int>("CAP:FailedRetryCount"); options.FailedRetryCount = configuration.GetValue<int>("CAP:FailedRetryCount");
options.SucceedMessageExpiredAfter = configuration.GetValue<int>("CAP:SucceedMessageExpiredAfter"); options.SucceedMessageExpiredAfter = configuration.GetValue<int>("CAP:SucceedMessageExpiredAfter");

View File

@ -26,6 +26,11 @@ public class GetWarningNotifiesVo
/// </summary> /// </summary>
public string WarningName { get; set; } = null!; public string WarningName { get; set; } = null!;
/// <summary>
/// 客户id
/// </summary>
public int CustomId { get; set; }
/// <summary> /// <summary>
/// 客户简称 /// 客户简称
/// </summary> /// </summary>
@ -103,7 +108,6 @@ public class GetWarningNotifiesVo
/// </summary> /// </summary>
public string FactorTypeSort { get; set; } = null!; public string FactorTypeSort { get; set; } = null!;
public override string ToString() public override string ToString()
{ {
// {起飞-落地+普货+1/2/3/4+美国 时效9,预警时效7,次数3} // {起飞-落地+普货+1/2/3/4+美国 时效9,预警时效7,次数3}

View File

@ -30,6 +30,7 @@ public class WarningQueries : ISugarRepository, IWarningQueries,
SubSystemName = system.CnName, SubSystemName = system.CnName,
RuleId = wr.Id, RuleId = wr.Id,
WarningName = w.Name, WarningName = w.Name,
CustomId = w.CustomerId,
CustomName = cus.Name, CustomName = cus.Name,
TotalTimeSpan = wr.TotalTimeSpan, TotalTimeSpan = wr.TotalTimeSpan,
WarnTimeSpan = wr.WarnTimeSpan, WarnTimeSpan = wr.WarnTimeSpan,