feat(dal): Task - доработка моделей
This commit is contained in:
@@ -296,6 +296,11 @@
|
|||||||
public const string GetByApplicationInWork = BaseStat + "/work-workloads/";
|
public const string GetByApplicationInWork = BaseStat + "/work-workloads/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class Workload
|
||||||
|
{
|
||||||
|
public const string Build = BaseStat + "/workload/build";
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Наряды
|
#region Наряды
|
||||||
|
|||||||
34
PARR.API/Controllers/V1/Statistics/StatWorkloadController.cs
Normal file
34
PARR.API/Controllers/V1/Statistics/StatWorkloadController.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using PARR.API.Contracts.V1;
|
||||||
|
using PARR.API.Controllers.V1.Base;
|
||||||
|
using PARR.Constants;
|
||||||
|
|
||||||
|
namespace PARR.API.Controllers.V1.Statistics
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Статистика загруженности по ЗО, РГ
|
||||||
|
/// </summary>
|
||||||
|
[Authorize(Roles = ParrRoles.EsppRobot.RoleOrAdmin)]
|
||||||
|
public class StatWorkloadController : BaseApiController
|
||||||
|
{
|
||||||
|
public StatWorkloadController()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сформировать отчетность
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost(ApiRoutes.Workload.Build)]
|
||||||
|
public async Task<IActionResult> Build()
|
||||||
|
{
|
||||||
|
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -65,39 +65,41 @@ namespace PARR.API.Controllers.V1
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
///// <summary>
|
/// <summary>
|
||||||
///// Записать в кэш
|
/// Записать в кэш
|
||||||
///// </summary>
|
/// </summary>
|
||||||
///// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
///// <returns></returns>
|
/// <returns></returns>
|
||||||
//[HttpPost(ApiRoutes.Test.CreateCache)]
|
[HttpPost(ApiRoutes.Test.CreateCache)]
|
||||||
//public async Task<IActionResult> CreateCache()
|
public async Task<IActionResult> CreateCache()
|
||||||
//{
|
{
|
||||||
// var hashKey = redisCacheService.GetKey(new[] { "test", "mxa" });
|
//var val = await redisCacheService.GetCachedDataAsync<object>("96dAoIH/8Q9Bg8VY");
|
||||||
// var ttl = TimeSpan.FromMinutes(10);
|
|
||||||
|
|
||||||
// await redisCacheService.SetHashFieldAsync(hashKey, "t1", "val1", ttl);
|
//var hashKey = redisCacheService.GetKey(new[] { "test", "mxa" });
|
||||||
// await redisCacheService.SetHashFieldAsync(hashKey, "t2", "val2");
|
//var ttl = TimeSpan.FromMinutes(10);
|
||||||
// await redisCacheService.SetHashFieldAsync(hashKey, "t3", "val3");
|
|
||||||
|
|
||||||
// var length = await redisCacheService.GetHashLengthAsync(hashKey);
|
//await redisCacheService.SetHashFieldAsync(hashKey, "t1", "val1", ttl);
|
||||||
|
//await redisCacheService.SetHashFieldAsync(hashKey, "t2", "val2");
|
||||||
|
//await redisCacheService.SetHashFieldAsync(hashKey, "t3", "val3");
|
||||||
|
|
||||||
// var get = await redisCacheService.GetHashFieldAsync<string>(hashKey, "t1");
|
//var length = await redisCacheService.GetHashLengthAsync(hashKey);
|
||||||
|
|
||||||
// var getAll = await redisCacheService.GetAllHashFieldsAsync<string>(hashKey);
|
//var get = await redisCacheService.GetHashFieldAsync<string>(hashKey, "t1");
|
||||||
|
|
||||||
// await redisCacheService.DeleteHashFieldAsync(hashKey, "t1");
|
//var getAll = await redisCacheService.GetAllHashFieldsAsync<string>(hashKey);
|
||||||
// var getT1 = await redisCacheService.GetHashFieldAsync<string>(hashKey, "t1");
|
|
||||||
|
|
||||||
// var exist = await redisCacheService.HashFieldExistsAsync(hashKey, "t2");
|
//await redisCacheService.DeleteHashFieldAsync(hashKey, "t1");
|
||||||
|
//var getT1 = await redisCacheService.GetHashFieldAsync<string>(hashKey, "t1");
|
||||||
|
|
||||||
// await redisCacheService.DeleteHashAsync(hashKey);
|
//var exist = await redisCacheService.HashFieldExistsAsync(hashKey, "t2");
|
||||||
// var getT_1 = await redisCacheService.GetHashFieldAsync<string>(hashKey, "t1");
|
|
||||||
|
|
||||||
// await redisCacheService.SetHashTtlAsync(hashKey, ttl);
|
//await redisCacheService.DeleteHashAsync(hashKey);
|
||||||
|
//var getT_1 = await redisCacheService.GetHashFieldAsync<string>(hashKey, "t1");
|
||||||
|
|
||||||
// return Ok();
|
//await redisCacheService.SetHashTtlAsync(hashKey, ttl);
|
||||||
//}
|
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ using PARR.DAL.Extensions;
|
|||||||
using PARR.DAL.Models;
|
using PARR.DAL.Models;
|
||||||
using PARR.DAL.Models.Job;
|
using PARR.DAL.Models.Job;
|
||||||
using PARR.DAL.Models.Schedule;
|
using PARR.DAL.Models.Schedule;
|
||||||
using PARR.DAL.Models.Task;
|
using PARR.DAL.Models.TaskModels;
|
||||||
using PARR.DAL.Models.Unit;
|
using PARR.DAL.Models.Unit;
|
||||||
|
|
||||||
namespace PARR.DAL.Context
|
namespace PARR.DAL.Context
|
||||||
@@ -120,8 +120,8 @@ namespace PARR.DAL.Context
|
|||||||
|
|
||||||
#region Tasks
|
#region Tasks
|
||||||
|
|
||||||
public DbSet<PARR.DAL.Models.Task.Task> Tasks { get; set; }
|
public DbSet<TaskItem> Tasks { get; set; }
|
||||||
public DbSet<PARR.DAL.Models.Task.TaskStatus> TaskStatus { get; set; }
|
public DbSet<Models.TaskModels.TaskStatus> TaskStatus { get; set; }
|
||||||
public DbSet<TaskType> TaskTypes { get; set; }
|
public DbSet<TaskType> TaskTypes { get; set; }
|
||||||
public DbSet<TaskError> TaskErrors { get; set; }
|
public DbSet<TaskError> TaskErrors { get; set; }
|
||||||
|
|
||||||
@@ -572,7 +572,7 @@ namespace PARR.DAL.Context
|
|||||||
{
|
{
|
||||||
f.HasData(new TaskType[]
|
f.HasData(new TaskType[]
|
||||||
{
|
{
|
||||||
new() { Code = TaskTypeEnum.Workload, Name = TaskTypeEnum.Workload.ToString(), Description = "Формирование данных для отчетности - Загруженность", MaxRetries = 2 }
|
new() { Code = TaskTypeEnum.Workload, Name = TaskTypeEnum.Workload.ToString(), Description = "Формирование данных для отчетности - Загруженность", MaxRetries = 2, IsSingleton=true, MaxExecutionTimeMinutes=30, RetantionsDays=90 }
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -581,14 +581,14 @@ namespace PARR.DAL.Context
|
|||||||
|
|
||||||
#region TaskStatus
|
#region TaskStatus
|
||||||
|
|
||||||
modelBuilder.Entity<PARR.DAL.Models.Task.TaskStatus>(f =>
|
modelBuilder.Entity<PARR.DAL.Models.TaskModels.TaskStatus>(f =>
|
||||||
{
|
{
|
||||||
f.HasData(new PARR.DAL.Models.Task.TaskStatus[]
|
f.HasData(new PARR.DAL.Models.TaskModels.TaskStatus[]
|
||||||
{
|
{
|
||||||
new(){Code=TaskTaskStatusEnum.Wait, Name=TaskTaskStatusEnum.Wait.ToString(), Description="Ожидание"},
|
new(){Code=TaskItemStatusEnum.Pending, Name=TaskItemStatusEnum.Pending.ToString(), Description="Ожидание"},
|
||||||
new(){Code=TaskTaskStatusEnum.Processing, Name=TaskTaskStatusEnum.Processing.ToString(), Description="В работе"},
|
new(){Code=TaskItemStatusEnum.Processing, Name=TaskItemStatusEnum.Processing.ToString(), Description="В работе"},
|
||||||
new(){Code=TaskTaskStatusEnum.Success, Name=TaskTaskStatusEnum.Success.ToString(), Description="Выполнено успешно"},
|
new(){Code=TaskItemStatusEnum.Success, Name=TaskItemStatusEnum.Success.ToString(), Description="Выполнено успешно"},
|
||||||
new(){Code=TaskTaskStatusEnum.Error, Name=TaskTaskStatusEnum.Error.ToString(), Description="Ошибка"}
|
new(){Code=TaskItemStatusEnum.Failed, Name=TaskItemStatusEnum.Failed.ToString(), Description="Ошибка"}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -5,26 +5,26 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Статус задач Task
|
/// Статус задач Task
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public enum TaskTaskStatusEnum
|
public enum TaskItemStatusEnum
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ожидание
|
/// Ожидание
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Wait=10,
|
Pending=0,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// В работе
|
/// В работе
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Processing = 20,
|
Processing = 1,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Выполнено успешно
|
/// Выполнено успешно
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Success = 30,
|
Success = 2,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ошибка
|
/// Ошибка
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Error = 40
|
Failed = 3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@ using PARR.DAL.Models.Base;
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
namespace PARR.DAL.Models.Task
|
namespace PARR.DAL.Models.TaskModels
|
||||||
{
|
{
|
||||||
[Table("Errors", Schema = DataContextSettings.Task)]
|
[Table("Errors", Schema = DataContextSettings.Task)]
|
||||||
[Comment("Таблица ошибок заданий")]
|
[Comment("Таблица ошибок заданий")]
|
||||||
@@ -27,6 +27,6 @@ namespace PARR.DAL.Models.Task
|
|||||||
public string? StackTrace { get; set; }
|
public string? StackTrace { get; set; }
|
||||||
|
|
||||||
[ForeignKey(nameof(TaskId))]
|
[ForeignKey(nameof(TaskId))]
|
||||||
public Task? Task { get; set; }
|
public TaskItem? TaskItem { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,17 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PARR.Common.Domain;
|
||||||
|
using PARR.Constants;
|
||||||
using PARR.DAL.Context;
|
using PARR.DAL.Context;
|
||||||
using PARR.DAL.Contracts;
|
using PARR.DAL.Contracts;
|
||||||
using PARR.DAL.Models.Base;
|
using PARR.DAL.Models.Base;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
namespace PARR.DAL.Models.Task
|
namespace PARR.DAL.Models.TaskModels
|
||||||
{
|
{
|
||||||
[Table("Tasks", Schema = DataContextSettings.Task)]
|
[Table("Tasks", Schema = DataContextSettings.Task)]
|
||||||
[Comment("Таблица заданий")]
|
[Comment("Таблица заданий")]
|
||||||
public class Task : IBase
|
public class TaskItem : IBase, IHistoryInitiator
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
@@ -20,7 +22,7 @@ namespace PARR.DAL.Models.Task
|
|||||||
|
|
||||||
public TaskTypeEnum TypeCode { get; set; }
|
public TaskTypeEnum TypeCode { get; set; }
|
||||||
|
|
||||||
public TaskTaskStatusEnum StatusCode { get; set; }
|
public TaskItemStatusEnum StatusCode { get; set; }
|
||||||
|
|
||||||
public string? Payload { get; set; }
|
public string? Payload { get; set; }
|
||||||
|
|
||||||
@@ -35,6 +37,10 @@ namespace PARR.DAL.Models.Task
|
|||||||
public DateTimeOffset? ProcessedAt { get; set; }
|
public DateTimeOffset? ProcessedAt { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public string? InitiatorIp { get; set; }
|
||||||
|
public ParrComponentsEnum? InitiatorParrComponentId { get; set; }
|
||||||
|
public string? InitiatorComment { get; set; }
|
||||||
|
|
||||||
|
|
||||||
[ForeignKey(nameof(TypeCode))]
|
[ForeignKey(nameof(TypeCode))]
|
||||||
public TaskType? TaskType { get; set; }
|
public TaskType? TaskType { get; set; }
|
||||||
@@ -4,20 +4,20 @@ using PARR.DAL.Contracts;
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
namespace PARR.DAL.Models.Task
|
namespace PARR.DAL.Models.TaskModels
|
||||||
{
|
{
|
||||||
[Table("Statuses", Schema = DataContextSettings.Task)]
|
[Table("Statuses", Schema = DataContextSettings.Task)]
|
||||||
[Comment("Таблица статусов заданий")]
|
[Comment("Таблица статусов заданий")]
|
||||||
public class TaskStatus
|
public class TaskStatus
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
public TaskTaskStatusEnum Code { get; set; }
|
public TaskItemStatusEnum Code { get; set; }
|
||||||
|
|
||||||
public required string Name { get; set; }
|
public required string Name { get; set; }
|
||||||
|
|
||||||
public required string Description { get; set; }
|
public required string Description { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public ICollection<Task> Tasks { get; set; } = new HashSet<Task>();
|
public ICollection<TaskItem> Tasks { get; set; } = new HashSet<TaskItem>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@ using PARR.DAL.Contracts;
|
|||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
namespace PARR.DAL.Models.Task
|
namespace PARR.DAL.Models.TaskModels
|
||||||
{
|
{
|
||||||
[Table("Types", Schema = DataContextSettings.Task)]
|
[Table("Types", Schema = DataContextSettings.Task)]
|
||||||
[Comment("Таблица типов заданий")]
|
[Comment("Таблица типов заданий")]
|
||||||
@@ -22,7 +22,22 @@ namespace PARR.DAL.Models.Task
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public int MaxRetries { get; set; }
|
public int MaxRetries { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Максимальное время выполнения
|
||||||
|
/// </summary>
|
||||||
|
public int MaxExecutionTimeMinutes { get; set; }
|
||||||
|
|
||||||
public ICollection<Task> Tasks { get; set; } = new HashSet<Task>();
|
/// <summary>
|
||||||
|
/// Одновременно может быть только одна задача или несколько
|
||||||
|
/// </summary>
|
||||||
|
public bool IsSingleton { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сколько дней хранить в БД
|
||||||
|
/// </summary>
|
||||||
|
public int RetentionDays { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public ICollection<TaskItem> Tasks { get; set; } = new HashSet<TaskItem>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,12 +18,12 @@ using PARR.DAL.Services.Implementation;
|
|||||||
using PARR.DAL.Services.Implementations;
|
using PARR.DAL.Services.Implementations;
|
||||||
using PARR.DAL.Services.Implementations.Job;
|
using PARR.DAL.Services.Implementations.Job;
|
||||||
using PARR.DAL.Services.Implementations.Schedule;
|
using PARR.DAL.Services.Implementations.Schedule;
|
||||||
using PARR.DAL.Services.Implementations.Task;
|
using PARR.DAL.Services.Implementations.TaskServices;
|
||||||
using PARR.DAL.Services.Implementations.Unit;
|
using PARR.DAL.Services.Implementations.Unit;
|
||||||
using PARR.DAL.Services.Interfaces;
|
using PARR.DAL.Services.Interfaces;
|
||||||
using PARR.DAL.Services.Interfaces.Job;
|
using PARR.DAL.Services.Interfaces.Job;
|
||||||
using PARR.DAL.Services.Interfaces.Schedule;
|
using PARR.DAL.Services.Interfaces.Schedule;
|
||||||
using PARR.DAL.Services.Interfaces.Task;
|
using PARR.DAL.Services.Interfaces.TaskServices;
|
||||||
using PARR.DAL.Services.Interfaces.Unit;
|
using PARR.DAL.Services.Interfaces.Unit;
|
||||||
using PARR.DAL.Settings;
|
using PARR.DAL.Settings;
|
||||||
using StackExchange.Redis;
|
using StackExchange.Redis;
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using PARR.DAL.Context;
|
using PARR.DAL.Context;
|
||||||
using PARR.DAL.Models.Task;
|
using PARR.DAL.Models.TaskModels;
|
||||||
using PARR.DAL.Services.Abstracts;
|
using PARR.DAL.Services.Abstracts;
|
||||||
using PARR.DAL.Services.Interfaces.Task;
|
using PARR.DAL.Services.Interfaces.TaskServices;
|
||||||
|
|
||||||
namespace PARR.DAL.Services.Implementations.Task
|
namespace PARR.DAL.Services.Implementations.TaskServices
|
||||||
{
|
{
|
||||||
internal class TaskErrorService : BaseService<TaskError>, ITaskErrorService
|
internal class TaskErrorService : BaseService<TaskError>, ITaskErrorService
|
||||||
{
|
{
|
||||||
@@ -1,16 +1,17 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using PARR.DAL.Context;
|
using PARR.DAL.Context;
|
||||||
|
using PARR.DAL.Models.TaskModels;
|
||||||
using PARR.DAL.Services.Abstracts;
|
using PARR.DAL.Services.Abstracts;
|
||||||
using PARR.DAL.Services.Interfaces.Task;
|
using PARR.DAL.Services.Interfaces.TaskServices;
|
||||||
|
|
||||||
namespace PARR.DAL.Services.Implementations.Task
|
namespace PARR.DAL.Services.Implementations.TaskServices
|
||||||
{
|
{
|
||||||
internal class TaskService : BaseService<PARR.DAL.Models.Task.Task>, ITaskService
|
internal class TaskService : BaseService<TaskItem>, ITaskService
|
||||||
{
|
{
|
||||||
private readonly DataContext dataContext;
|
private readonly DataContext dataContext;
|
||||||
|
|
||||||
protected override DbSet<Models.Task.Task> EntitySet => dataContext.Tasks;
|
protected override DbSet<TaskItem> EntitySet => dataContext.Tasks;
|
||||||
|
|
||||||
protected override DataContext EntitiContext => dataContext;
|
protected override DataContext EntitiContext => dataContext;
|
||||||
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
using PARR.DAL.Services.Interfaces.Base;
|
|
||||||
|
|
||||||
namespace PARR.DAL.Services.Interfaces.Task
|
|
||||||
{
|
|
||||||
public interface ITaskService : IBaseService<PARR.DAL.Models.Task.Task>
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using PARR.DAL.Models.Task;
|
using PARR.DAL.Models.TaskModels;
|
||||||
using PARR.DAL.Services.Interfaces.Base;
|
using PARR.DAL.Services.Interfaces.Base;
|
||||||
|
|
||||||
namespace PARR.DAL.Services.Interfaces.Task
|
namespace PARR.DAL.Services.Interfaces.TaskServices
|
||||||
{
|
{
|
||||||
public interface ITaskErrorService : IBaseService<TaskError>
|
public interface ITaskErrorService : IBaseService<TaskError>
|
||||||
{
|
{
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using PARR.DAL.Models.TaskModels;
|
||||||
|
using PARR.DAL.Services.Interfaces.Base;
|
||||||
|
|
||||||
|
namespace PARR.DAL.Services.Interfaces.TaskServices
|
||||||
|
{
|
||||||
|
public interface ITaskService : IBaseService<TaskItem>
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user