JobStatus init

This commit is contained in:
Mikhail Kuznetsov
2023-06-20 12:29:58 +10:00
parent 57fe9eff09
commit 9c19e2fb91
20 changed files with 1370 additions and 148 deletions

View 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}"));
}
}
}

View File

@@ -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();
}
}
}