fix:修复提供接口轨迹查询排序根据转化后的utc0来排序

This commit is contained in:
hardstylewyl 2025-04-11 15:35:41 +08:00
parent ea080314c5
commit dd1d041e3f
2 changed files with 23 additions and 2 deletions

View File

@ -78,4 +78,24 @@ public static class DateTimeHelper
var flag = timezone > 0f ? "+" : "";
return $"GMT {flag}{timeZoneStr.RemovePostFix(":00")}";
}
/// <summary>
/// 转换为utc0时区的时间转化进行Compare
/// </summary>
public static int ConvertUtc0Compare(DateTime a, float aZone, DateTime b, float bZone)
{
if (Math.Abs(aZone - bZone) < 0.01f)
{
return a.CompareTo(b);
}
if (Math.Abs(aZone - GlobalConst.NoneTrackTimeZone) < 0.01f)
aZone = 8.0f;
if (Math.Abs(bZone - GlobalConst.NoneTrackTimeZone) < 0.01f)
bZone = 8.0f;
var aUtc = a.Subtract(TimeSpan.FromHours(aZone));
var bUtc = b.Subtract(TimeSpan.FromHours(bZone));
return aUtc.CompareTo(bUtc);
}
}

View File

@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Http;
using SJZY.Expand.AliyunOSS;
using SJZY.Track.Application.Contract.Dtos.ProvideServices;
using SJZY.Track.Application.Helpers;
using SJZY.Track.Domain.Aggregates.TrackDetailsAggregate;
using SJZY.Track.Domain.Aggregates.TrackTemplateAggregate;
using SJZY.Track.Domain.Dtos.TrackTemplate;
@ -201,12 +202,12 @@ public partial class TrackService
case SortMethod.ByTrackTime:
case SortMethod.ByTemplateAndTrackTime:
// tips:quick-sort 直接修改原list
list.ForEach(item => item.TrackDetails.Sort((a, b) => a.Time.CompareTo(b.Time)));
list.ForEach(item => item.TrackDetails.Sort((a, b) => DateTimeHelper.ConvertUtc0Compare(a.Time, a.TimeZone ?? 8, b.Time, b.TimeZone ?? 8)));
break;
case null:
case SortMethod.ByTrackTimeDesc:
case SortMethod.ByTemplateAndTrackTimeDesc:
list.ForEach(item => item.TrackDetails.Sort((a, b) => b.Time.CompareTo(a.Time)));
list.ForEach(item => item.TrackDetails.Sort((a, b) => DateTimeHelper.ConvertUtc0Compare(b.Time, b.TimeZone ?? 8, a.Time, a.TimeZone ?? 8)));
break;
default:
throw new ArgumentOutOfRangeException(nameof(sortMethod), sortMethod, "不支持的排序方式");