Merge branch 'S07' into test

This commit is contained in:
hardstylewyl 2025-03-27 11:39:53 +08:00
commit 3d1d0c969b
6 changed files with 46 additions and 61 deletions

View File

@ -49,7 +49,7 @@ public class EditTransportWarningSceneRuleItemDto
/// 时效 (单位h)
/// 注意:需要大于起始轨迹生成预警时间
/// </summary>
[Range(0.1f, 9999.9f, ErrorMessage = "时效必须范围0.1-9999.9")]
[Range(0.1f, 9999.9f, ErrorMessage = "时效范围0.1-9999.9")]
public float TransportTimeSpan { get; set; }
/// <summary>

View File

@ -1,5 +1,6 @@
using Microsoft.Extensions.Options;
using SJZY.Track.Application.Contract.Dtos.Warning;
using SJZY.Track.Application.Helpers;
using SJZY.Track.Application.Options;
using SJZY.Track.Application.Services.Warning.Model;
using SJZY.Track.Domain.Aggregates.KPIAreaAggregate;
@ -315,7 +316,6 @@ public sealed class WarningNotifyAggregator : ITransientDependency
{
var options = _optionsMonitor.CurrentValue;
var hours = options.ScanWarningNotifyTaskHourInterval;
const float timeZone = 8.00f;
var transportCount = 0;
var transportLastNHoursCount = 0;
var returnCount = 0;
@ -344,7 +344,6 @@ public sealed class WarningNotifyAggregator : ITransientDependency
return NotifyMessageBuilder.Build(
hours,
timeZone,
transportCount,
transportLastNHoursCount,
returnCount,
@ -364,7 +363,7 @@ public static class NotifyMessageBuilder
{
public const string Title = "预警通知";
public static string Build(int hours, float timeZone,
public static string Build(int hours,
int transportCount, int transportLastNHoursCount,
int returnCount, int returnLastNHoursCount,
int completeCount, int completeLastNHoursCount)
@ -375,15 +374,25 @@ public static class NotifyMessageBuilder
var url1 = "";
var url2 = "";
var url3 = "";
var message = $"尊敬的用户,截止到{dateTime}(UTC {timeZone:+0:00:F2}),轨迹中心监测到与您相关的预警风险信息共计{totalCount} 条,请及时处理,详情如下:";
var message = $"{Title}\n尊敬的用户,截止到{dateTime}(UTC {BuildLocalTimezoneStr()}),轨迹中心监测到与您相关的预警风险信息共计{totalCount} 条,请及时处理,详情如下:";
if (transportCount > 0)
message += $"\n运输时效预警共计{transportCount}条,其中过去{hours}小时内新增的预警{transportLastNHoursCount}条,查看详情{url1}";
message += $"\n运输时效预警共计{transportCount}条,其中过去{hours}小时内新增的预警{transportLastNHoursCount}条";
if (returnCount > 0)
message += $"\n回传时效预警共计{returnCount}条,其中过去{hours}小时内新增的预警{returnLastNHoursCount}条,查看详情{url2}";
message += $"\n回传时效预警共计{returnCount}条,其中过去{hours}小时内新增的预警{returnLastNHoursCount}条";
if (completeCount > 0)
message += $"\n轨迹完整预警共计{completeCount}条,其中过去{hours}小时内新增的预警{completeLastNHoursCount}条,查看详情{url3}";
message += $"\n轨迹完整预警共计{completeCount}条,其中过去{hours}小时内新增的预警{completeLastNHoursCount}条";
return message;
}
// 构建本地时区字符串标识 e.g UTC +8:00
private static string BuildLocalTimezoneStr()
{
var offset = TimeZoneInfo.Local.BaseUtcOffset;
var flag = offset.Hours > 0 ? "+" : "";
var offsetStr = offset.ToString().RemovePostFix(":00");
return $"UTC {flag}{offsetStr}";
}
}

View File

@ -55,4 +55,27 @@ public static class DateTimeHelper
return sign * (hours + minutes / 60f);
}
/// <summary>
/// 将浮点数时区转换为GMT格式
/// 如果为null则返回"--"
/// </summary>
/// <param name="timezone"></param>
/// <returns></returns>
public static string ConvertFloatToTimeZone(float? timezone)
{
if (timezone == null) return "--";
if (Math.Abs(timezone.Value - GlobalConst.NoneTrackTimeZone) < 0.01f) return "--";
if (Math.Abs(timezone.Value) < 0.01f) return "GMT +00:00";
// 将小数形式的小时转换为时区偏移量
var hours = (int) timezone.Value; // 提取整数部分作为小时
var minutes = (int) ((timezone.Value - hours) * 60); // 将小数部分乘以 60 转换为分钟
var offset = new TimeSpan(hours, minutes, 0);
var timeZoneStr = offset.ToString();
var flag = timezone > 0f ? "+" : "";
return $"GMT {flag}{timeZoneStr.RemovePostFix(":00")}";
}
}

View File

@ -186,7 +186,7 @@ public class CompleteWarningService : ApplicationService
LatestTrackContent = orderIdTrack?.TrackContent,
LatestTrackPlace = orderIdTrack?.TrackPlace,
LatestTrackTime = orderIdTrack?.TrackTime,
LatestTrackTimeZone = FormatTimeZone(orderIdTrack?.TrackTimeZone),
LatestTrackTimeZone = DateTimeHelper.ConvertFloatToTimeZone(orderIdTrack?.TrackTimeZone),
NotifyUserNames = ToUserNames(x.NotifyUsers),
CreateTime = x.CreateTime,
@ -229,22 +229,6 @@ public class CompleteWarningService : ApplicationService
}).ToList()
}).ToList();
}
// 格式化时区
string FormatTimeZone(float? timezone)
{
if (timezone == null) return "--";
if (Math.Abs(timezone.Value - GlobalConst.NoneTrackTimeZone) < 1) return "--";
// 将小数形式的小时转换为时区偏移量
var hours = (int) timezone.Value; // 提取整数部分作为小时
var minutes = (int) ((timezone.Value - hours) * 60); // 将小数部分乘以 60 转换为分钟
var offset = new TimeSpan(hours, minutes, 0);
var timeZoneStr = offset.ToString();
var flag = timezone > 0f ? "+" : "";
return $"GMT {flag}{timeZoneStr.RemovePostFix(":00")}";
}
}
/// <summary>

View File

@ -3,6 +3,7 @@ using SJZY.Expand.ABP.Core.PublicMethords;
using SJZY.Track.Application.Contract.Dtos.Warning;
using SJZY.Track.Application.Contract.Dtos.Warning.Return;
using SJZY.Track.Application.Contract.Events;
using SJZY.Track.Application.Helpers;
using SJZY.Track.Application.Services.Warning.Handlers;
using SJZY.Track.Application.Services.Warning.Model;
using SJZY.Track.Domain.Aggregates.OrderAggregate;
@ -146,7 +147,7 @@ public class ReturnWarningService : ApplicationService
TrackContent = x.TrackContent,
TrackPlace = x.TrackPlace,
TrackTime = x.TrackTime,
TrackTimeZone = FormatTimeZone(x.TrackTimeZone),
TrackTimeZone = DateTimeHelper.ConvertFloatToTimeZone(x.TrackTimeZone),
TrackCreateTime = x.TrackCreateTime,
// 轨迹信息(映射后)
PushTrackCode = x.PushTrackCode,
@ -186,22 +187,6 @@ public class ReturnWarningService : ApplicationService
return string.Join(',', notifyUsers.ToObject<List<NotifyUserDto>>().Select(x => x.UserName));
}
// 格式化时区
string FormatTimeZone(float? timezone)
{
if (timezone == null) return "--";
if (Math.Abs(timezone.Value - GlobalConst.NoneTrackTimeZone) < 1) return "--";
// 将小数形式的小时转换为时区偏移量
var hours = (int) timezone.Value; // 提取整数部分作为小时
var minutes = (int) ((timezone.Value - hours) * 60); // 将小数部分乘以 60 转换为分钟
var offset = new TimeSpan(hours, minutes, 0);
var timeZoneStr = offset.ToString();
var flag = timezone > 0f ? "+" : "";
return $"GMT {flag}{timeZoneStr.RemovePostFix(":00")}";
}
// 时间
string FormatTimeSpan(long? milliseconds)
{

View File

@ -223,20 +223,20 @@ public class TransportWarningService : ApplicationService
// 最新轨迹 (不冗余)
LatestTrackContent = orderIdTrack?.TrackContent,
LatestTrackTime = orderIdTrack?.TrackTime,
LatestTrackTimeZone = FormatTimeZone(orderIdTrack?.TrackTimeZone),
LatestTrackTimeZone = DateTimeHelper.ConvertFloatToTimeZone(orderIdTrack?.TrackTimeZone),
LatestTrackPlace = orderIdTrack?.TrackPlace,
// 起始轨迹
StartTrackStatus = x.StartTrackStatus,
StartTrackContent = x.StartTrackContent,
StartTrackTime = x.StartTrackTime,
StartTrackTimeZone = FormatTimeZone(x.StartTrackTimeZone),
StartTrackTimeZone = DateTimeHelper.ConvertFloatToTimeZone(x.StartTrackTimeZone),
// 截止轨迹
EndTrackStatus = x.EndTrackStatus,
EndTrackContent = x.EndTrackContent,
EndTrackTime = x.EndTrackTime,
EndTrackTimeZone = FormatTimeZone(x.EndTrackTimeZone),
EndTrackTimeZone = DateTimeHelper.ConvertFloatToTimeZone(x.EndTrackTimeZone),
WarningName = x.WarningName,
WarningRuleDescription = x.WarningRuleDescription,
@ -283,22 +283,6 @@ public class TransportWarningService : ApplicationService
return $"{timeSpan.Days:00}天{timeSpan.Hours:00}小时{timeSpan.Minutes:00}分钟";
}
// 格式化时区
string FormatTimeZone(float? timezone)
{
if (timezone == null) return "--";
if (Math.Abs(timezone.Value - GlobalConst.NoneTrackTimeZone) < 1) return "--";
// 将小数形式的小时转换为时区偏移量
var hours = (int) timezone.Value; // 提取整数部分作为小时
var minutes = (int) ((timezone.Value - hours) * 60); // 将小数部分乘以 60 转换为分钟
var offset = new TimeSpan(hours, minutes, 0);
var timeZoneStr = offset.ToString();
var flag = timezone > 0f ? "+" : "";
return $"GMT {flag}{timeZoneStr.RemovePostFix(":00")}";
}
}
/// <summary>