feat: Перенесены внешние сервисы в Infrastructure. Удалены лишние проекты.
This commit is contained in:
27
PARR.Core/Common/Helpers/EsppScheduleHelpers.cs
Normal file
27
PARR.Core/Common/Helpers/EsppScheduleHelpers.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace PARR.BLL.Helpers
|
||||
{
|
||||
public static class EsppScheduleHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Получить время создания наряда в формате ЕСПП
|
||||
/// </summary>
|
||||
/// <param name="date"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetGenerationTime(DateTimeOffset date)
|
||||
{
|
||||
return date.ToString("HH:mm:ss", CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить следующее срабатывание в формате ЕСПП
|
||||
/// </summary>
|
||||
/// <param name="date"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetNextRun(DateTimeOffset date)
|
||||
{
|
||||
return date.ToString("dd/MM/yy HH:mm:ss", CultureInfo.InvariantCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
15
PARR.Core/Common/Helpers/SqlHelpers.cs
Normal file
15
PARR.Core/Common/Helpers/SqlHelpers.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace PARR.Core.Common.Helpers
|
||||
{
|
||||
public static class SqlHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Преобразует Regex в Like для SQL
|
||||
/// </summary>
|
||||
/// <param name="regexPattern"></param>
|
||||
/// <returns></returns>
|
||||
public static string RegexToLike(string regexPattern)
|
||||
{
|
||||
return regexPattern.Replace("*", "%").ToLower();
|
||||
}
|
||||
}
|
||||
}
|
||||
30
PARR.Core/Common/Implementations/TransformService.cs
Normal file
30
PARR.Core/Common/Implementations/TransformService.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PARR.Core.Common.Interfaces;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace PARR.Core.Common.Implementations
|
||||
{
|
||||
internal class TransformService: ITransformService
|
||||
{
|
||||
private readonly ILogger<TransformService> logger;
|
||||
|
||||
public TransformService(ILogger<TransformService> logger)
|
||||
{
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public T? GetModelFromJson<T>(string str)
|
||||
{
|
||||
try
|
||||
{
|
||||
return JsonSerializer.Deserialize<T>(str);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, $"Ошибка при конвертации строки в модель. {str}");
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
14
PARR.Core/Common/Interfaces/IInfluxDbService.cs
Normal file
14
PARR.Core/Common/Interfaces/IInfluxDbService.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using InfluxDB.Client;
|
||||
|
||||
namespace PARR.Core.Common.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Сервис взаимодействия с InfluxDb
|
||||
/// </summary>
|
||||
public interface IInfluxDbService
|
||||
{
|
||||
Task<T> QueryAsync<T>(Func<QueryApi, Task<T>> action, string token);
|
||||
|
||||
bool Write(Action<WriteApi> action, string token);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace PARR.Core.Common
|
||||
namespace PARR.Core.Common.Interfaces
|
||||
{
|
||||
//public delegate Task IntervalHandlerDelegate();
|
||||
|
||||
135
PARR.Core/Common/Interfaces/IRedisCacheService.cs
Normal file
135
PARR.Core/Common/Interfaces/IRedisCacheService.cs
Normal file
@@ -0,0 +1,135 @@
|
||||
namespace PARR.Core.Common.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Сервис по управлению КЭШ
|
||||
/// </summary>
|
||||
public interface IRedisCacheService
|
||||
{
|
||||
/// <summary>
|
||||
/// Получить кэшированные данные
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
T? GetCachedData<T>(string key);
|
||||
|
||||
/// <summary>
|
||||
/// Получить кэшированные данные асинхронно
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
Task<T?> GetCachedDataAsync<T>(string key);
|
||||
|
||||
/// <summary>
|
||||
/// Добавить в кэш данные
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="cacheDuration"></param>
|
||||
void SetCachedData<T>(string key, T data, TimeSpan cacheDuration);
|
||||
|
||||
/// <summary>
|
||||
/// Добавить в кэш данные асинхронно
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="cacheDuration"></param>
|
||||
/// <returns></returns>
|
||||
Task SetCachedDataAsync<T>(string key, T data, TimeSpan cacheDuration);
|
||||
|
||||
/// <summary>
|
||||
/// Удалить кэшированные данные
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
void DeleteCachedData(string key);
|
||||
|
||||
/// <summary>
|
||||
/// Удалить кэшированные данные асинхронно
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
Task DeleteCachedDataAsync(string key);
|
||||
|
||||
/// <summary>
|
||||
/// Сгенерировать уникальный ключ
|
||||
/// </summary>
|
||||
/// <param name="keyParts"></param>
|
||||
/// <param name="keyPartsToHash"></param>
|
||||
/// <returns></returns>
|
||||
string GetKey(string[] keyParts, string[]? keyPartsToHash = null);
|
||||
|
||||
|
||||
#region Работа с Hash
|
||||
|
||||
/// <summary>
|
||||
/// Изменить одно поле в Hash
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="hashKey"></param>
|
||||
/// <param name="field"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="ttl">Если указано, обновится у всего Hash. Если не указано и hash не существовал, создастся Hash с бесокнечным ttl</param>
|
||||
/// <returns></returns>
|
||||
Task SetHashFieldAsync<T>(string hashKey, string field, T value, TimeSpan? ttl = null);
|
||||
|
||||
/// <summary>
|
||||
/// Получить значение поля из Hash
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="hashKey"></param>
|
||||
/// <param name="field"></param>
|
||||
/// <returns></returns>
|
||||
Task<T?> GetHashFieldAsync<T>(string hashKey, string field);
|
||||
|
||||
/// <summary>
|
||||
/// Получить все значения из Hash
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="hashKey"></param>
|
||||
/// <returns></returns>
|
||||
Task<Dictionary<string, T>> GetAllHashFieldsAsync<T>(string hashKey);
|
||||
|
||||
/// <summary>
|
||||
/// Удалить одну запись из Hash
|
||||
/// </summary>
|
||||
/// <param name="hashKey"></param>
|
||||
/// <param name="field"></param>
|
||||
/// <returns></returns>
|
||||
Task DeleteHashFieldAsync(string hashKey, string field);
|
||||
|
||||
/// <summary>
|
||||
/// Есть ли запись в Hash
|
||||
/// </summary>
|
||||
/// <param name="hashKey"></param>
|
||||
/// <param name="field"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> HashFieldExistsAsync(string hashKey, string field);
|
||||
|
||||
/// <summary>
|
||||
/// Удалить весь Hash
|
||||
/// </summary>
|
||||
/// <param name="hashKey"></param>
|
||||
/// <returns></returns>
|
||||
Task DeleteHashAsync(string hashKey);
|
||||
|
||||
/// <summary>
|
||||
/// Получить количество записей в Hash
|
||||
/// </summary>
|
||||
/// <param name="hashKey"></param>
|
||||
/// <returns></returns>
|
||||
Task<long> GetHashLengthAsync(string hashKey);
|
||||
|
||||
/// <summary>
|
||||
/// Установить TTL для Hash
|
||||
/// </summary>
|
||||
/// <param name="hashKey"></param>
|
||||
/// <param name="ttl"></param>
|
||||
/// <returns></returns>
|
||||
Task SetHashTtlAsync(string hashKey, TimeSpan ttl);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
7
PARR.Core/Common/Interfaces/ITransformService.cs
Normal file
7
PARR.Core/Common/Interfaces/ITransformService.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace PARR.Core.Common.Interfaces
|
||||
{
|
||||
public interface ITransformService
|
||||
{
|
||||
T? GetModelFromJson<T>(string str);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using PARR.Domain.DTOs.RabbitApi;
|
||||
using PARR.Domain.Settings;
|
||||
|
||||
namespace PARR.Core.Common.RabbitServices
|
||||
namespace PARR.Core.Common.Interfaces.RabbitServices
|
||||
{
|
||||
public interface IRabbitAdminService
|
||||
{
|
||||
@@ -1,7 +1,7 @@
|
||||
using PARR.Domain.Common.Rabbit;
|
||||
using PARR.Domain.Settings;
|
||||
|
||||
namespace PARR.Core.Common.RabbitServices
|
||||
namespace PARR.Core.Common.Interfaces.RabbitServices
|
||||
{
|
||||
public delegate Task MqMessageHandlerDelegate(string msg);
|
||||
|
||||
Reference in New Issue
Block a user