Merge remote-tracking branch 'origin/S04轨迹预警' into S04轨迹预警

This commit is contained in:
xiaolipro 2024-07-25 21:06:18 +08:00
commit 9ba1ee660b
4 changed files with 65 additions and 22 deletions

View File

@ -21,7 +21,7 @@ public class TrackUpdateInput
public class TrackItem
{
public string Location { get; set; } = null!;
public DateTime Date { get; set; }
public string Date { get; set; }
public double TimeZone { get; set; }
public string? Description { get; set; }
public string? DescriptionCn { get; set; }

View File

@ -1,4 +1,5 @@
using DotNetCore.CAP;
using System.Globalization;
using DotNetCore.CAP;
using Newtonsoft.Json;
using SJZY.Expand.ABP.Core.PublicMethords;
using SJZY.InterfaceRelay.Application.Contracts;
@ -87,8 +88,6 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
if (!config.IsAutoPush) continue;
if (config.OrderType != order.OrderType) continue;
// todo 确认是不是这里转换
DateTimeFormat( @event.SystemPushInfo.TrackTime,"yyyy-MM-dd HH:mm:ss");
var log = new TrackPushRecordIndex
{
OptionType = @event.OptionType.ToString(),
@ -114,7 +113,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
var tracks = await _trackDetailsRepository.GetListAsync(@event.OrderIds, @event.TrackCode);
tracks = tracks.DistinctBy(x => x.OrderId).ToList(); // 防止重复推送
var temp=this.DateTimeFormat(DateTime.Now, -8.0, config);
if (tracks.Count == 0) return; // 一个能推的轨迹都不存在
// tips:人工推送只要能推就推了,不会校验已推和顺序问题,因为可能是更新
@ -161,12 +160,6 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
throw new BusinessException(message: $"requestId: {r.RequestId}; {r.Msg}");
}
}
private string DateTimeFormat(DateTime dateTime,string format)
{
return dateTime.ToString("yyyy-MM-dd HH:mm:ss");
}
private async Task DoUpdateAsync(TrackPushEvent @event)
{
@ -210,12 +203,14 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
private TrackUpdateInput BuiltUpdateItem(TrackPushContentConfigDto config, TrackPushRecordIndex log)
{
var trackDatetime = log.TrackTime.AddHours(config.TrackTimeZone ?? log.TrackTimeZone - log.TrackTimeZone);
var trackDateStr = DateTimeFormat(trackDatetime,config.TrackTimeZone ?? log.TrackTimeZone,config);
var track = new TrackItem
{
// 推真实的发生地和发生时间(时间是计算后的)
Location = log.TrackPlace,
Date = log.TrackTime.AddHours(
config.TrackTimeZone ?? log.TrackTimeZone - log.TrackTimeZone),
Date = trackDateStr,
TimeZone = config.TrackTimeZone ?? log.TrackTimeZone,
Description = config.TrackEnContentValue,
DescriptionCn = config.TrackContentValue,
@ -236,12 +231,14 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
private async Task<TrackPushInput> BuiltPushItem(TrackPushContentConfigDto config, TrackPushRecordIndex log)
{
var trackDatetime = log.TrackTime.AddHours(config.TrackTimeZone ?? log.TrackTimeZone - log.TrackTimeZone);
var trackDateStr = DateTimeFormat(trackDatetime,config.TrackTimeZone ?? log.TrackTimeZone,config);
var track = new TrackItem
{
// 推真实的发生地和发生时间(时间是计算后的)
Location = log.TrackPlace,
Date = log.TrackTime.AddHours(
config.TrackTimeZone ?? log.TrackTimeZone - log.TrackTimeZone),
Date = trackDateStr,
TimeZone = config.TrackTimeZone ?? log.TrackTimeZone,
Description = config.TrackEnContentValue,
DescriptionCn = config.TrackContentValue,
@ -258,7 +255,6 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
if (config.IsAllPush)
{
//todo 这个是指每次都带上之前的轨迹嘛
var history = await _trackPushRecordsRepository.GetLatestTrackPushRecordAsync(log.OrderId);
if (history != default)
{
@ -296,4 +292,28 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
return matched != null && matched.TrackCode == trackCode ? matched : default;
}
/// <summary>
/// 转换推送时间格式
/// </summary>
/// <param name="dateTime"></param>
/// <param name="timezone"></param>
/// <param name="config"></param>
/// <returns></returns>
private string DateTimeFormat(DateTime dateTime,double timezone, TrackPushContentConfigDto config)
{
if (config.DateTimeFormatType == DateTimeFormatEnum.Timestamp)
return DateTimeHelper.ConvertToUnixTimestamp(dateTime).ToString();
if (config.DateTimeFormatType == DateTimeFormatEnum.DateTimeAndTimezone
&& !string.IsNullOrEmpty(config.DateTimeFormat)
&& !string.IsNullOrEmpty(config.TimezoneFormat))
{
var zoneStr = DateTimeHelper.TimezoneFormat(timezone, config.TimezoneFormat);
var datetimeStr = DateTimeHelper.FormatDateTime(dateTime, config.DateTimeFormat);
return $"{datetimeStr} {zoneStr}";
}
return dateTime.ToString("yyyy-MM-ddTHH:mm:ss.fffK");
}
}

View File

@ -1,13 +1,15 @@
using SJZY.OTel;
namespace SJZY.Track.Application.Helpers;
public static class DateTimeHelper
{
/// <summary>
/// Generates a Unix timestamp from a DateTime object.
/// convert to a Unix timestamp from a DateTime object.
/// </summary>
/// <param name="dateTime">The DateTime object to convert to a Unix timestamp.</param>
/// <returns>The Unix timestamp as a long.</returns>
public static long GenerateUnixTimestamp(DateTime dateTime)
public static long ConvertToUnixTimestamp(DateTime dateTime)
{
return new DateTimeOffset(dateTime).ToUnixTimeSeconds();
}
@ -29,8 +31,9 @@ public static class DateTimeHelper
/// <param name="timezone"></param>
/// <param name="format"></param>
/// <returns></returns>
public static string TimezoneFormat(float timezone, string format)
public static string TimezoneFormat(double timezone, string format)
{
return string.Format(format, timezone);
//时区是整数丢掉浮点数部分
return format.Replace("hh", ((int)timezone).ToString());
}
}

View File

@ -1,5 +1,6 @@
using DotNetCore.CAP;
using Microsoft.AspNetCore.Authorization;
using SJZY.Track.Application.CAP.EventHandlers;
using SJZY.Track.Application.Contract.Dtos.ProvideServices;
using SJZY.Track.Application.Contract.Events;
using SJZY.Track.Domain.Aggregates.OrderAggregate;
@ -21,16 +22,17 @@ public class TrackPushService : ApplicationService
private readonly ICapPublisher _capPublisher;
private readonly ITrackPushRecordsRepository _trackPushRecordsRepository;
private readonly IHttpClientProxy<IRequestCurrentUserService> _requestCurrentUserService;
TrackPushEventHandler _trackPushEventHandler;
public TrackPushService(IOrderRepository orderRepository
, ICapPublisher capPublisher
, ITrackPushRecordsRepository trackPushRecordsRepository,
IHttpClientProxy<IRequestCurrentUserService> requestCurrentUserService)
IHttpClientProxy<IRequestCurrentUserService> requestCurrentUserService, TrackPushEventHandler trackPushEventHandler)
{
_orderRepository = orderRepository;
_capPublisher = capPublisher;
_trackPushRecordsRepository = trackPushRecordsRepository;
_requestCurrentUserService = requestCurrentUserService;
_trackPushEventHandler = trackPushEventHandler;
}
/// <summary>
@ -41,6 +43,24 @@ public class TrackPushService : ApplicationService
[HttpPost("Track/Push")]
public async Task<string> PushTrackAsync(PushTrackInput input)
{
var trackPushEvenst = new TrackPushEvent
{
OptionType = OptionType.新增, // Assuming OptionType.新增 corresponds to 1
SubSystemId = 9534,
CustomId = 228618,
OrderIds = new int[] { 1 },
TrackCode = "CP",
OperationMan = "郑志红",
SystemPushInfo = new SystemPushStruct
{
TrackStatus = null,
TrackContent = null,
TrackPlace = null,
TrackTime = DateTime.Parse("0001-01-01T00:00:00"),
TrackTimeZone = 0.0f
}
};
await _trackPushEventHandler.ConsumerAsync(trackPushEvenst);
input.OrderNos = input.OrderNos.Where(x => !x.IsNullOrWhiteSpace()).Distinct().ToList(); // 单号去重、去空
var orders = await _orderRepository.GetArrayAsync(x =>