pref:轨迹推送配置补充支持只使用时间格式化
add-validation:增加推送配置新增/更新的格时间格式化模板验证 - 在时间和时区模式下,不允许只输入时区模板
This commit is contained in:
parent
720c342dfb
commit
24d08cbc84
@ -463,7 +463,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
|
|||||||
if (string.IsNullOrWhiteSpace(compareFields))
|
if (string.IsNullOrWhiteSpace(compareFields))
|
||||||
return trackIdentifies.Contains($"{code}{timeStr}");
|
return trackIdentifies.Contains($"{code}{timeStr}");
|
||||||
|
|
||||||
var extra = x.GetValueOrDefault("extra");
|
var extra = x.GetValueOrDefault("extra");
|
||||||
if (extra == null) return false;
|
if (extra == null) return false;
|
||||||
|
|
||||||
if (((JsonElement) extra).TryGetProperty(compareFields, out var comparerValueJsonElement))
|
if (((JsonElement) extra).TryGetProperty(compareFields, out var comparerValueJsonElement))
|
||||||
@ -538,15 +538,22 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
|
|||||||
if (config.DateTimeFormatType == (int) DateTimeFormatEnum.Timestamp)
|
if (config.DateTimeFormatType == (int) DateTimeFormatEnum.Timestamp)
|
||||||
return DateTimeHelper.ConvertToUnixTimestamp(dateTime).ToString();
|
return DateTimeHelper.ConvertToUnixTimestamp(dateTime).ToString();
|
||||||
|
|
||||||
if (config.DateTimeFormatType == (int) DateTimeFormatEnum.DateTimeAndTimezone
|
if (config.DateTimeFormatType == (int) DateTimeFormatEnum.DateTimeAndTimezone)
|
||||||
&& !string.IsNullOrEmpty(config.DateTimeFormat)
|
|
||||||
&& !string.IsNullOrEmpty(config.TimezoneFormat))
|
|
||||||
{
|
{
|
||||||
var zoneStr = DateTimeHelper.TimezoneFormat(timezone, config.TimezoneFormat);
|
// 只有时间
|
||||||
var datetimeStr = DateTimeHelper.FormatDateTime(dateTime, config.DateTimeFormat);
|
if (!string.IsNullOrWhiteSpace(config.DateTimeFormat) && string.IsNullOrWhiteSpace(config.TimezoneFormat))
|
||||||
return $"{datetimeStr} {zoneStr}";
|
return DateTimeHelper.FormatDateTime(dateTime, config.DateTimeFormat);
|
||||||
|
|
||||||
|
// 时间和时区
|
||||||
|
if (!string.IsNullOrWhiteSpace(config.DateTimeFormat) && !string.IsNullOrWhiteSpace(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");
|
return dateTime.ToString("yyyy-MM-ddTHH:mm:ss.fffK");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,12 +5,14 @@ using SJZY.Expand.ABP.Core.Logger;
|
|||||||
using SJZY.Expand.ABP.Core.PublicMethords;
|
using SJZY.Expand.ABP.Core.PublicMethords;
|
||||||
using SJZY.Track.Application.Contract.Dtos.TrackPush;
|
using SJZY.Track.Application.Contract.Dtos.TrackPush;
|
||||||
using SJZY.Track.Application.Contract.Services;
|
using SJZY.Track.Application.Contract.Services;
|
||||||
|
using SJZY.Track.Application.Helpers;
|
||||||
using SJZY.Track.Application.Localization;
|
using SJZY.Track.Application.Localization;
|
||||||
using SJZY.Track.Application.Services.Warning.Handlers;
|
using SJZY.Track.Application.Services.Warning.Handlers;
|
||||||
using SJZY.Track.Domain.Aggregates.OrderAggregate;
|
using SJZY.Track.Domain.Aggregates.OrderAggregate;
|
||||||
using SJZY.Track.Domain.Aggregates.TrackPushAggregate;
|
using SJZY.Track.Domain.Aggregates.TrackPushAggregate;
|
||||||
using SJZY.Track.Domain.Dtos.Common;
|
using SJZY.Track.Domain.Dtos.Common;
|
||||||
using SJZY.Track.Domain.Dtos.TrackPush;
|
using SJZY.Track.Domain.Dtos.TrackPush;
|
||||||
|
using SJZY.Track.Domain.Enums;
|
||||||
using Volo.Abp.DependencyInjection;
|
using Volo.Abp.DependencyInjection;
|
||||||
|
|
||||||
namespace SJZY.Track.Application.Services.TrackPush;
|
namespace SJZY.Track.Application.Services.TrackPush;
|
||||||
@ -112,7 +114,7 @@ public class TrackPushService : ApplicationService, ISingletonDependency
|
|||||||
/// <param name="input"></param>
|
/// <param name="input"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("Edit")]
|
[HttpPost("Edit")]
|
||||||
public async Task<bool> EditAsync([FromBody] EditTrackPushConfigInput input)
|
public async Task<string> EditAsync([FromBody] EditTrackPushConfigInput input)
|
||||||
{
|
{
|
||||||
if (input.Options != OptionTypeNoNull.删除)
|
if (input.Options != OptionTypeNoNull.删除)
|
||||||
{
|
{
|
||||||
@ -124,6 +126,14 @@ public class TrackPushService : ApplicationService, ISingletonDependency
|
|||||||
throw new BusinessException(message: _stringLocalizer["IsTrackPushConfigAny"]);
|
throw new BusinessException(message: _stringLocalizer["IsTrackPushConfigAny"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var msg = string.Empty;
|
||||||
|
if (input.Options is OptionTypeNoNull.新增 or OptionTypeNoNull.修改)
|
||||||
|
{
|
||||||
|
var (success, message) = CheckDateTimeFormat(input.DateTimeFormat, input.DateTimeFormatType, input.TimezoneFormat);
|
||||||
|
if (!success) throw new BusinessException(message: message);
|
||||||
|
msg = message;
|
||||||
|
}
|
||||||
|
|
||||||
using var ts = TransactionScopeHelper.Create();
|
using var ts = TransactionScopeHelper.Create();
|
||||||
|
|
||||||
switch (input.Options)
|
switch (input.Options)
|
||||||
@ -161,7 +171,7 @@ public class TrackPushService : ApplicationService, ISingletonDependency
|
|||||||
}
|
}
|
||||||
|
|
||||||
ts.Complete();
|
ts.Complete();
|
||||||
return true;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -346,4 +356,52 @@ public class TrackPushService : ApplicationService, ISingletonDependency
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static (bool Success, string Message) CheckDateTimeFormat(string? dateTimeFormat, int? dateTimeFormatType, string? timezoneFormat)
|
||||||
|
{
|
||||||
|
const int defaultTimeZone = 8;
|
||||||
|
var dateTime = DateTime.Now;
|
||||||
|
string dateStr;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (dateTimeFormatType == (int) DateTimeFormatEnum.Timestamp)
|
||||||
|
{
|
||||||
|
dateStr = DateTimeHelper.ConvertToUnixTimestamp(dateTime).ToString();
|
||||||
|
return (true, $"格式化样例:{dateStr}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dateTimeFormatType == (int) DateTimeFormatEnum.DateTimeAndTimezone)
|
||||||
|
{
|
||||||
|
// 没时间有时区,出错
|
||||||
|
if (string.IsNullOrWhiteSpace(dateTimeFormat) && !string.IsNullOrWhiteSpace(timezoneFormat))
|
||||||
|
return (false, "如果填写了时区格式,那么时间格式是必须的");
|
||||||
|
|
||||||
|
// 只有时间
|
||||||
|
if (!string.IsNullOrWhiteSpace(dateTimeFormat) && string.IsNullOrWhiteSpace(timezoneFormat))
|
||||||
|
{
|
||||||
|
var datetimeStr = DateTimeHelper.FormatDateTime(dateTime, dateTimeFormat);
|
||||||
|
return (true, $"格式化样例:{datetimeStr}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 时间和时区同时存在
|
||||||
|
if (!string.IsNullOrWhiteSpace(dateTimeFormat) && !string.IsNullOrWhiteSpace(timezoneFormat))
|
||||||
|
{
|
||||||
|
var zoneStr = DateTimeHelper.TimezoneFormat(defaultTimeZone, timezoneFormat);
|
||||||
|
var datetimeStr = DateTimeHelper.FormatDateTime(dateTime, dateTimeFormat);
|
||||||
|
dateStr = $"{datetimeStr} {zoneStr}";
|
||||||
|
return (true, $"格式化样例:{dateStr}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return (false, $"时间格式错误请检查:{e.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 默认情况
|
||||||
|
dateTimeFormat ??= "yyyy-MM-ddTHH:mm:ss.fffK";
|
||||||
|
dateStr = dateTime.ToString(dateTimeFormat);
|
||||||
|
return (true, $"格式化样例:{dateStr}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user