JobStatus init
This commit is contained in:
@@ -27,11 +27,11 @@
|
||||
public const string Metrics = Base + "/metrics";
|
||||
}
|
||||
|
||||
public static class Scheduler
|
||||
public static class Jobs
|
||||
{
|
||||
public const string GetAll = Base + "/schedulers/";
|
||||
public const string GetAll = Base + "/jobs/";
|
||||
|
||||
public const string GetByIp = Base + "/schedulers/ip/";
|
||||
public const string GetByIp = Base + "/jobs/ip/";
|
||||
//public const string Get = Base + "/schedulers/" + getParam;
|
||||
|
||||
//public const string GetAreas = Base + "/schedulers/" + getParam + "/areas";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace PARR.API.Contracts.V1.Requests.Queries
|
||||
{
|
||||
public class SchedulerGetAllQuery
|
||||
public class JobGetAllQuery
|
||||
{
|
||||
/// <summary>
|
||||
/// true - вкл задания, false - выкл задания, null - все задания
|
||||
@@ -1,7 +1,8 @@
|
||||
namespace PARR.API.Contracts.V1.Requests.Queries
|
||||
{
|
||||
public class SchedulerGetByIpQuery
|
||||
public class JobGetByIpQuery
|
||||
{
|
||||
public string? Ip { get; set; }
|
||||
public DateTimeOffset? Date { get; set; }
|
||||
}
|
||||
}
|
||||
8
PARR.API/Contracts/V1/Responses/JobModeResponse.cs
Normal file
8
PARR.API/Contracts/V1/Responses/JobModeResponse.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace PARR.API.Contracts.V1.Responses
|
||||
{
|
||||
public class JobModeResponse
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public required string Name { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,20 @@
|
||||
namespace PARR.API.Contracts.V1.Responses
|
||||
{
|
||||
public class SchedulerBaseResponse
|
||||
public class JobBaseResponse
|
||||
{
|
||||
public required string Name { get; set; }
|
||||
public DateTimeOffset StartAt { get; set; }
|
||||
public int FrequencyMinute { get; set; }
|
||||
|
||||
public required JobModeResponse JobMode { get; set; }
|
||||
}
|
||||
|
||||
public class SchedulerGetAllResponse: SchedulerBaseResponse
|
||||
public class JobGetAllResponse : JobBaseResponse
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public bool IsEnabled { get; set; }
|
||||
}
|
||||
|
||||
public class SchedulerResponse
|
||||
public class JobResponse
|
||||
{
|
||||
|
||||
}
|
||||
116
PARR.API/Controllers/V1/JobController.cs
Normal file
116
PARR.API/Controllers/V1/JobController.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PARR.API.Contracts.V1;
|
||||
using PARR.API.Contracts.V1.Requests.Queries;
|
||||
using PARR.API.Contracts.V1.Responses;
|
||||
using PARR.API.Contracts.V1.Responses.Base;
|
||||
using PARR.API.Controllers.V1.Base;
|
||||
using PARR.API.Extensions;
|
||||
using PARR.API.Services.Interfaces;
|
||||
using PARR.DAL.DomainModels;
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
|
||||
using static PARR.API.Contracts.V1.ApiRoutes;
|
||||
|
||||
namespace PARR.API.Controllers.V1
|
||||
{
|
||||
public class JobController : BaseApiController
|
||||
{
|
||||
private readonly IMapper mapper;
|
||||
private readonly IJobService jobService;
|
||||
//private readonly ISchedulerService schedulerService;
|
||||
private readonly IClientService clientService;
|
||||
private readonly IHostService hostService;
|
||||
|
||||
public JobController(
|
||||
IMapper mapper,
|
||||
IJobService jobService,
|
||||
IClientService clientService,
|
||||
IHostService hostService
|
||||
)
|
||||
{
|
||||
this.mapper = mapper;
|
||||
this.jobService = jobService;
|
||||
//this.schedulerService = schedulerService;
|
||||
this.clientService = clientService;
|
||||
this.hostService = hostService;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Список всех jobов постранично в соотвествии с фильтрами
|
||||
/// </summary>
|
||||
/// <param name="paginationQuery"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.Jobs.GetAll)]
|
||||
public async Task<IActionResult> GetAll([FromQuery] PaginationQuery paginationQuery, [FromQuery] JobGetAllQuery filter)
|
||||
{
|
||||
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
|
||||
IQueryable<Job> query = jobService.Get().Include(t => t.JobMode).OrderBy(s => s.StartAt);
|
||||
|
||||
if (filter.IsEnabled.HasValue)
|
||||
query = query.Where(t => t.IsEnabled == filter.IsEnabled);
|
||||
|
||||
if (filter.StartDatePlanned.HasValue)
|
||||
query = query.Where(t => t.StartAt.DateTime.Date <= filter.StartDatePlanned.Value.DateTime.Date); ;
|
||||
|
||||
var jobs = await jobService.GetPage(query, paginationFilter).ToListAsync();
|
||||
|
||||
if (!jobs.Any())
|
||||
return NoContent();
|
||||
|
||||
var jobResponse = mapper.Map<List<JobGetAllResponse>>(jobs);
|
||||
var paginationResponse = new PagedResponse<JobGetAllResponse>(jobResponse, true).GetPaginatedProps(paginationFilter, query);
|
||||
|
||||
return Ok(paginationResponse);
|
||||
}
|
||||
|
||||
|
||||
[HttpGet(ApiRoutes.Jobs.GetByIp)]
|
||||
public async Task<IActionResult> GetByClientIP([FromQuery] JobGetByIpQuery requestQuery)
|
||||
{
|
||||
var ip = requestQuery.Ip ?? clientService.GetClientIp()?.ToString();
|
||||
if (string.IsNullOrEmpty(ip))
|
||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = "Client IP address is null." } }));
|
||||
|
||||
var date = requestQuery.Date ?? DateTimeOffset.Now;
|
||||
|
||||
// С одним IP может быть несколько информационных систем, соответственного а таблице храниться несколько записей хостов с одинаковым IP
|
||||
var hosts = await hostService.Get().Where(h => h.IP == ip).ToListAsync();
|
||||
var hostJobsDict = new Dictionary<DAL.Models.Host, List<Job>>();
|
||||
foreach (var host in hosts)
|
||||
{
|
||||
var jobsHost = await jobService.Get()
|
||||
.Include(a => a.Application).ThenInclude(ah => ah.ApplicationsInHosts)/*.ThenInclude(h => h.Host)*/
|
||||
.Include(jm=>jm.JobMode)
|
||||
.AsSplitQuery()
|
||||
.Where(j => j.Application != null && j.Application.ApplicationsInHosts.Any(ah => ah.HostId == host.Id))
|
||||
.ToListAsync();
|
||||
if (jobsHost.Any())
|
||||
hostJobsDict.Add(host, jobsHost);
|
||||
}
|
||||
//hostJobsDict.Values.Distinct();
|
||||
|
||||
var jobsJoined = new List<Job>();
|
||||
foreach(var job in hostJobsDict.Values)
|
||||
{
|
||||
job.ForEach(item =>
|
||||
{
|
||||
jobsJoined.Add(item);
|
||||
});
|
||||
}
|
||||
jobsJoined.Distinct();
|
||||
|
||||
|
||||
if (!jobsJoined.Any())
|
||||
return NoContent();
|
||||
|
||||
var jobResponse = mapper.Map<List<JobGetAllResponse>>(jobsJoined);
|
||||
|
||||
return Ok(new Response<List<JobGetAllResponse>>(jobResponse, true, new List<ErrorModel>(), $"{ip},{date}"));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using PARR.API.Contracts.V1.Requests.Queries;
|
||||
using PARR.API.Contracts.V1;
|
||||
using PARR.API.Controllers.V1.Base;
|
||||
using AutoMapper;
|
||||
using PARR.DAL.DomainModels;
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PARR.API.Contracts.V1.Responses;
|
||||
using PARR.API.Contracts.V1.Responses.Base;
|
||||
using PARR.API.Extensions;
|
||||
using System.Runtime.CompilerServices;
|
||||
using PARR.API.Services.Interfaces;
|
||||
|
||||
namespace PARR.API.Controllers.V1
|
||||
{
|
||||
public class ShchedullerController : BaseApiController
|
||||
{
|
||||
private readonly IMapper mapper;
|
||||
private readonly ISchedulerService schedulerService;
|
||||
private readonly IClientService clientService;
|
||||
|
||||
public ShchedullerController(
|
||||
IMapper mapper,
|
||||
ISchedulerService schedulerService,
|
||||
IClientService clientService
|
||||
)
|
||||
{
|
||||
this.mapper = mapper;
|
||||
this.schedulerService = schedulerService;
|
||||
this.clientService = clientService;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Список всех планировщиков постранично в соотвествии с фильтрами
|
||||
/// </summary>
|
||||
/// <param name="paginationQuery"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet(ApiRoutes.Scheduler.GetAll)]
|
||||
public async Task<IActionResult> GetAll([FromQuery] PaginationQuery paginationQuery, [FromQuery] SchedulerGetAllQuery filter)
|
||||
{
|
||||
var paginationFilter = mapper.Map<PaginationFilter>(paginationQuery);
|
||||
IQueryable<Scheduler> query = schedulerService.Get().OrderBy(s => s.StartAt);
|
||||
|
||||
if (filter.IsEnabled.HasValue)
|
||||
query = query.Where(t => t.IsEnabled == filter.IsEnabled);
|
||||
|
||||
if (filter.StartDatePlanned.HasValue)
|
||||
query = query.Where(t => t.StartAt.DateTime.Date <= filter.StartDatePlanned.Value.DateTime.Date); ;
|
||||
|
||||
var schedulers = await schedulerService.GetPage(query, paginationFilter).ToListAsync();
|
||||
|
||||
if (!schedulers.Any())
|
||||
return NoContent();
|
||||
|
||||
var schedulerResponse = mapper.Map<List<SchedulerGetAllResponse>>(schedulers);
|
||||
var paginationResponse = new PagedResponse<SchedulerGetAllResponse>(schedulerResponse, true).GetPaginatedProps(paginationFilter, query);
|
||||
|
||||
return Ok(paginationResponse);
|
||||
}
|
||||
|
||||
|
||||
[HttpGet(ApiRoutes.Scheduler.GetByIp)]
|
||||
public async Task<IActionResult> GetByClientIP([FromQuery] SchedulerGetByIpQuery requestQuery)
|
||||
{
|
||||
var ip = requestQuery.Ip ?? clientService.GetClientIp()?.ToString();
|
||||
if (string.IsNullOrEmpty(ip))
|
||||
return BadRequest(new Response(false, new List<ErrorModel> { new ErrorModel { Message = "Client IP address is null." } }));
|
||||
|
||||
// TODO;
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -8,11 +8,14 @@ namespace PARR.API.MappingProfiles
|
||||
{
|
||||
public DomainToResponseProfile()
|
||||
{
|
||||
// --- Scheduler ---
|
||||
CreateMap<Scheduler, SchedulerBaseResponse>()
|
||||
.Include<Scheduler, SchedulerGetAllResponse>()
|
||||
// --- Job ---
|
||||
CreateMap<Job, JobBaseResponse>()
|
||||
.Include<Job, JobGetAllResponse>()
|
||||
.ForMember(d => d.FrequencyMinute, o => o.MapFrom(s => s.Frequency));
|
||||
CreateMap<Scheduler, SchedulerGetAllResponse>();
|
||||
CreateMap<Job, JobGetAllResponse>();
|
||||
|
||||
|
||||
CreateMap<JobMode, JobModeResponse>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user