feat: 轨迹映射界面的推送配置增加推送时间格式 开发测试完成

This commit is contained in:
钟喜旺 2024-07-25 15:03:47 +08:00
parent 740bc61558
commit aae9add71c
4 changed files with 65 additions and 22 deletions

View File

@ -21,7 +21,7 @@ public class TrackUpdateInput
public class TrackItem public class TrackItem
{ {
public string Location { get; set; } = null!; public string Location { get; set; } = null!;
public DateTime Date { get; set; } public string Date { get; set; }
public double TimeZone { get; set; } public double TimeZone { get; set; }
public string? Description { get; set; } public string? Description { get; set; }
public string? DescriptionCn { 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 Newtonsoft.Json;
using SJZY.Expand.ABP.Core.PublicMethords; using SJZY.Expand.ABP.Core.PublicMethords;
using SJZY.InterfaceRelay.Application.Contracts; using SJZY.InterfaceRelay.Application.Contracts;
@ -87,8 +88,6 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
if (!config.IsAutoPush) continue; if (!config.IsAutoPush) continue;
if (config.OrderType != order.OrderType) continue; if (config.OrderType != order.OrderType) continue;
// todo 确认是不是这里转换
DateTimeFormat( @event.SystemPushInfo.TrackTime,"yyyy-MM-dd HH:mm:ss");
var log = new TrackPushRecordIndex var log = new TrackPushRecordIndex
{ {
OptionType = @event.OptionType.ToString(), OptionType = @event.OptionType.ToString(),
@ -114,7 +113,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
var tracks = await _trackDetailsRepository.GetListAsync(@event.OrderIds, @event.TrackCode); var tracks = await _trackDetailsRepository.GetListAsync(@event.OrderIds, @event.TrackCode);
tracks = tracks.DistinctBy(x => x.OrderId).ToList(); // 防止重复推送 tracks = tracks.DistinctBy(x => x.OrderId).ToList(); // 防止重复推送
var temp=this.DateTimeFormat(DateTime.Now, -8.0, config);
if (tracks.Count == 0) return; // 一个能推的轨迹都不存在 if (tracks.Count == 0) return; // 一个能推的轨迹都不存在
// tips:人工推送只要能推就推了,不会校验已推和顺序问题,因为可能是更新 // tips:人工推送只要能推就推了,不会校验已推和顺序问题,因为可能是更新
@ -162,12 +161,6 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
} }
} }
private string DateTimeFormat(DateTime dateTime,string format)
{
return dateTime.ToString("yyyy-MM-dd HH:mm:ss");
}
private async Task DoUpdateAsync(TrackPushEvent @event) private async Task DoUpdateAsync(TrackPushEvent @event)
{ {
var config = _pushConfigs.FirstOrDefault(x => x.TrackCode == @event.TrackCode); var config = _pushConfigs.FirstOrDefault(x => x.TrackCode == @event.TrackCode);
@ -210,12 +203,14 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
private TrackUpdateInput BuiltUpdateItem(TrackPushContentConfigDto config, TrackPushRecordIndex log) 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 var track = new TrackItem
{ {
// 推真实的发生地和发生时间(时间是计算后的) // 推真实的发生地和发生时间(时间是计算后的)
Location = log.TrackPlace, Location = log.TrackPlace,
Date = log.TrackTime.AddHours( Date = trackDateStr,
config.TrackTimeZone ?? log.TrackTimeZone - log.TrackTimeZone),
TimeZone = config.TrackTimeZone ?? log.TrackTimeZone, TimeZone = config.TrackTimeZone ?? log.TrackTimeZone,
Description = config.TrackEnContentValue, Description = config.TrackEnContentValue,
DescriptionCn = config.TrackContentValue, DescriptionCn = config.TrackContentValue,
@ -236,12 +231,14 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
private async Task<TrackPushInput> BuiltPushItem(TrackPushContentConfigDto config, TrackPushRecordIndex log) 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 var track = new TrackItem
{ {
// 推真实的发生地和发生时间(时间是计算后的) // 推真实的发生地和发生时间(时间是计算后的)
Location = log.TrackPlace, Location = log.TrackPlace,
Date = log.TrackTime.AddHours( Date = trackDateStr,
config.TrackTimeZone ?? log.TrackTimeZone - log.TrackTimeZone),
TimeZone = config.TrackTimeZone ?? log.TrackTimeZone, TimeZone = config.TrackTimeZone ?? log.TrackTimeZone,
Description = config.TrackEnContentValue, Description = config.TrackEnContentValue,
DescriptionCn = config.TrackContentValue, DescriptionCn = config.TrackContentValue,
@ -258,7 +255,6 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
if (config.IsAllPush) if (config.IsAllPush)
{ {
//todo 这个是指每次都带上之前的轨迹嘛
var history = await _trackPushRecordsRepository.GetLatestTrackPushRecordAsync(log.OrderId); var history = await _trackPushRecordsRepository.GetLatestTrackPushRecordAsync(log.OrderId);
if (history != default) if (history != default)
{ {
@ -296,4 +292,28 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
return matched != null && matched.TrackCode == trackCode ? matched : default; 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; namespace SJZY.Track.Application.Helpers;
public static class DateTimeHelper public static class DateTimeHelper
{ {
/// <summary> /// <summary>
/// Generates a Unix timestamp from a DateTime object. /// convert to a Unix timestamp from a DateTime object.
/// </summary> /// </summary>
/// <param name="dateTime">The DateTime object to convert to a Unix timestamp.</param> /// <param name="dateTime">The DateTime object to convert to a Unix timestamp.</param>
/// <returns>The Unix timestamp as a long.</returns> /// <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(); return new DateTimeOffset(dateTime).ToUnixTimeSeconds();
} }
@ -29,8 +31,9 @@ public static class DateTimeHelper
/// <param name="timezone"></param> /// <param name="timezone"></param>
/// <param name="format"></param> /// <param name="format"></param>
/// <returns></returns> /// <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 DotNetCore.CAP;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using SJZY.Track.Application.CAP.EventHandlers;
using SJZY.Track.Application.Contract.Dtos.ProvideServices; using SJZY.Track.Application.Contract.Dtos.ProvideServices;
using SJZY.Track.Application.Contract.Events; using SJZY.Track.Application.Contract.Events;
using SJZY.Track.Domain.Aggregates.OrderAggregate; using SJZY.Track.Domain.Aggregates.OrderAggregate;
@ -21,16 +22,17 @@ public class TrackPushService : ApplicationService
private readonly ICapPublisher _capPublisher; private readonly ICapPublisher _capPublisher;
private readonly ITrackPushRecordsRepository _trackPushRecordsRepository; private readonly ITrackPushRecordsRepository _trackPushRecordsRepository;
private readonly IHttpClientProxy<IRequestCurrentUserService> _requestCurrentUserService; private readonly IHttpClientProxy<IRequestCurrentUserService> _requestCurrentUserService;
TrackPushEventHandler _trackPushEventHandler;
public TrackPushService(IOrderRepository orderRepository public TrackPushService(IOrderRepository orderRepository
, ICapPublisher capPublisher , ICapPublisher capPublisher
, ITrackPushRecordsRepository trackPushRecordsRepository, , ITrackPushRecordsRepository trackPushRecordsRepository,
IHttpClientProxy<IRequestCurrentUserService> requestCurrentUserService) IHttpClientProxy<IRequestCurrentUserService> requestCurrentUserService, TrackPushEventHandler trackPushEventHandler)
{ {
_orderRepository = orderRepository; _orderRepository = orderRepository;
_capPublisher = capPublisher; _capPublisher = capPublisher;
_trackPushRecordsRepository = trackPushRecordsRepository; _trackPushRecordsRepository = trackPushRecordsRepository;
_requestCurrentUserService = requestCurrentUserService; _requestCurrentUserService = requestCurrentUserService;
_trackPushEventHandler = trackPushEventHandler;
} }
/// <summary> /// <summary>
@ -41,6 +43,24 @@ public class TrackPushService : ApplicationService
[HttpPost("Track/Push")] [HttpPost("Track/Push")]
public async Task<string> PushTrackAsync(PushTrackInput input) 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(); // 单号去重、去空 input.OrderNos = input.OrderNos.Where(x => !x.IsNullOrWhiteSpace()).Distinct().ToList(); // 单号去重、去空
var orders = await _orderRepository.GetArrayAsync(x => var orders = await _orderRepository.GetArrayAsync(x =>