feat(api): Доделал респонс RobotTaskScheduleResponse
This commit is contained in:
@@ -21,6 +21,28 @@
|
||||
|
||||
public string? Description { get; set; }
|
||||
|
||||
// TODO:
|
||||
public required string Exclude { get; set; }
|
||||
|
||||
public required string Timezone { get; set; }
|
||||
|
||||
public required string RepeatRange { get; set; }
|
||||
|
||||
public required string GenerationTime { get; set; }
|
||||
|
||||
public required string NextStart { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Тип задания: ругелярно, еженедельно...
|
||||
/// </summary>
|
||||
public required string ScheduleType { get; set; }
|
||||
|
||||
public List<RobotTaskScheduleSchResponse>? Schedule { get; set; }
|
||||
}
|
||||
|
||||
public class RobotTaskScheduleSchResponse
|
||||
{
|
||||
public required string Type { get; set; }
|
||||
public required string Value { get; set; }
|
||||
public int Order { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,8 +42,7 @@ namespace PARR.API.Controllers.V1
|
||||
await robotConfigurationService.FindUnfulfilledTaskAndSetRobotErrorStatusAsync(settingsFromDb.RobotAttemptsNumber, settingsFromDb.RobotWaitTime);
|
||||
|
||||
var query = robotConfigurationService.Get()
|
||||
.Where(t => t.RobotCode == (int)robotCode && t.TaskStatusCode == (int)taskStatusCode)
|
||||
.AsSplitQuery();
|
||||
.Where(t => t.RobotCode == (int)robotCode && t.TaskStatusCode == (int)taskStatusCode);
|
||||
|
||||
switch (robotCode)
|
||||
{
|
||||
@@ -55,11 +54,19 @@ namespace PARR.API.Controllers.V1
|
||||
.ThenInclude(w => w!.Work)
|
||||
.ThenInclude(t => t!.Tnk)
|
||||
.ThenInclude(s => s!.Subprocess)
|
||||
.ThenInclude(p => p!.Process);
|
||||
.ThenInclude(p => p!.Process)
|
||||
.AsSplitQuery();
|
||||
break;
|
||||
case RobotsEnum.ScheduleOrder:
|
||||
// тут не делаем AsSplitQuery, не может подтянуть все таблицы
|
||||
query = query.Include(t => t.Template)
|
||||
.ThenInclude(t => t!.Host).ThenInclude(t => t!.ResponseArea);
|
||||
.ThenInclude(t => t!.Host).ThenInclude(t => t!.ResponseArea)
|
||||
.Include(t => t.Template)
|
||||
.ThenInclude(t => t!.ApplicationsInWork)
|
||||
.ThenInclude(t => t!.EsppSchValues)
|
||||
.ThenInclude(t => t!.EsppSchTypeConfig)
|
||||
.ThenInclude(t => t!.EsppSchTypeSchedule)
|
||||
;
|
||||
//todo: include
|
||||
break;
|
||||
default:
|
||||
@@ -79,7 +86,8 @@ namespace PARR.API.Controllers.V1
|
||||
//и что текущая попытка не больше разрешенной(берется из настроек, поле `RobotAttemptsNumber`) - если это так, берется эта запись.
|
||||
|
||||
var endDate = DateTimeOffset.UtcNow.Add(-settingsFromDb.RobotWaitTime);
|
||||
task = await query.FirstOrDefaultAsync(t =>
|
||||
task = await query
|
||||
.FirstOrDefaultAsync(t =>
|
||||
t.RobotStatusCode == (int)RobotStatusEnum.InProgress
|
||||
&& t.AttemptsNumber < settingsFromDb.RobotAttemptsNumber
|
||||
&& t.LastRobotStatusUpdated < endDate
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using AutoMapper;
|
||||
using PARR.API.Contracts.V1.Responses;
|
||||
using PARR.API.MappingProfiles.Resolvers;
|
||||
using PARR.BLL.Helpers;
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.Models.V1;
|
||||
|
||||
@@ -97,7 +98,6 @@ namespace PARR.API.MappingProfiles
|
||||
.ForMember(d => d.WorkName, o => o.MapFrom(s => s.Template!.ApplicationsInWork!.Work!.Name))
|
||||
.ForMember(d => d.WorkEsppId, o => o.MapFrom(s => s.Template!.ApplicationsInWork!.Work!.EsppId));
|
||||
|
||||
//TODO: сделать маппинг!!!
|
||||
CreateMap<RobotConfiguration, RobotTaskScheduleResponse>()
|
||||
.ForMember(d => d.EsppId, o => o.MapFrom(s => s.Template!.ScheduleEsppId))
|
||||
.ForMember(d => d.ScheduleName, o => o.MapFrom(s => s.Template!.Name))
|
||||
@@ -106,7 +106,14 @@ namespace PARR.API.MappingProfiles
|
||||
.ForMember(d => d.TemplateName, o => o.MapFrom(s => s.Template!.Name))
|
||||
.ForMember(d => d.TemplateId, o => o.MapFrom(s => s.Template!.Id))
|
||||
.ForMember(d => d.WorkGroup, o => o.MapFrom(s => s.Template!.Host!.WorkGroup))
|
||||
;
|
||||
.ForMember(d => d.Exclude, o => o.MapFrom<RobotTaskScheduleExcludeResolver>())
|
||||
.ForMember(d => d.Timezone, o => o.MapFrom<RobotTaskScheduleTimezoneResolver>())
|
||||
.ForMember(d => d.RepeatRange, o => o.MapFrom<RobotTaskScheduleRepeatRangeResolver>())
|
||||
.ForMember(d => d.GenerationTime, o => o.MapFrom(s => s.Template!.ApplicationsInWork!.ScheduleGenerationTime))
|
||||
.ForMember(d => d.NextStart, o => o.MapFrom(s => EsppScheduleHelpers.GetFirstStart(s.Template!.ApplicationsInWork!.ScheduleStartDate, s.Template!.ApplicationsInWork!.ScheduleGenerationTime)))
|
||||
.ForMember(d => d.ScheduleType, o => o.MapFrom(s =>
|
||||
s.Template!.ApplicationsInWork!.EsppSchValues!.First()!.EsppSchTypeConfig!.EsppSchTypeSchedule!.Description))
|
||||
.ForMember(d => d.Schedule, o => o.MapFrom<RobotTaskScheduleSchResolver>());
|
||||
// === RobotConfiguration ===
|
||||
|
||||
CreateMap<Robot, RobotResponse>();
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using AutoMapper;
|
||||
using PARR.API.Contracts.V1.Responses;
|
||||
using PARR.DAL.Contracts;
|
||||
using PARR.DAL.Models;
|
||||
|
||||
namespace PARR.API.MappingProfiles.Resolvers
|
||||
{
|
||||
public class RobotTaskScheduleExcludeResolver : IValueResolver<RobotConfiguration, RobotTaskScheduleResponse, string>
|
||||
{
|
||||
private readonly SettingsFromDb settingsFromDb;
|
||||
|
||||
public RobotTaskScheduleExcludeResolver(SettingsFromDb settingsFromDb)
|
||||
{
|
||||
this.settingsFromDb = settingsFromDb;
|
||||
}
|
||||
|
||||
public string Resolve(RobotConfiguration source, RobotTaskScheduleResponse destination, string destMember, ResolutionContext context)
|
||||
{
|
||||
return settingsFromDb.ScheduleExclude;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using AutoMapper;
|
||||
using PARR.API.Contracts.V1.Responses;
|
||||
using PARR.DAL.Contracts;
|
||||
using PARR.DAL.Models;
|
||||
|
||||
namespace PARR.API.MappingProfiles.Resolvers
|
||||
{
|
||||
public class RobotTaskScheduleRepeatRangeResolver : IValueResolver<RobotConfiguration, RobotTaskScheduleResponse, string>
|
||||
{
|
||||
private readonly SettingsFromDb settingsFromDb;
|
||||
|
||||
public RobotTaskScheduleRepeatRangeResolver(SettingsFromDb settingsFromDb)
|
||||
{
|
||||
this.settingsFromDb = settingsFromDb;
|
||||
}
|
||||
|
||||
public string Resolve(RobotConfiguration source, RobotTaskScheduleResponse destination, string destMember, ResolutionContext context)
|
||||
{
|
||||
return settingsFromDb.ScheduleRepeatRange;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using AutoMapper;
|
||||
using PARR.API.Contracts.V1.Responses;
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
|
||||
namespace PARR.API.MappingProfiles.Resolvers
|
||||
{
|
||||
public class RobotTaskScheduleSchResolver : IValueResolver<RobotConfiguration, RobotTaskScheduleResponse, List<RobotTaskScheduleSchResponse>?>
|
||||
{
|
||||
private readonly IEsppSchTypeConfigService esppConfigService;
|
||||
|
||||
public RobotTaskScheduleSchResolver(IEsppSchTypeConfigService esppConfigService)
|
||||
{
|
||||
this.esppConfigService = esppConfigService;
|
||||
}
|
||||
|
||||
public List<RobotTaskScheduleSchResponse>? Resolve(RobotConfiguration source, RobotTaskScheduleResponse destination, List<RobotTaskScheduleSchResponse>? destMember, ResolutionContext context)
|
||||
{
|
||||
//todo: может вынести эту логику в сервис?
|
||||
var appInWorksId = source.Template!.ApplicationInWorkId;
|
||||
|
||||
var configs = esppConfigService.GetWithSchIncludes()
|
||||
.Where(t => t.EsppSchValues.Any(x => x.ApplicationsInWorkId == appInWorksId))
|
||||
.ToList();
|
||||
|
||||
var response = configs.Select(conf =>
|
||||
new RobotTaskScheduleSchResponse
|
||||
{
|
||||
Order = conf.Order,
|
||||
Type = conf.EsppSchType!.Name,
|
||||
Value = conf.EsppSchValues.First().EsppSchTypeValue!.Value
|
||||
});
|
||||
|
||||
return response.OrderBy(t => t.Order).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using AutoMapper;
|
||||
using PARR.API.Contracts.V1.Responses;
|
||||
using PARR.DAL.Contracts;
|
||||
using PARR.DAL.Models;
|
||||
|
||||
namespace PARR.API.MappingProfiles.Resolvers
|
||||
{
|
||||
public class RobotTaskScheduleTimezoneResolver : IValueResolver<RobotConfiguration, RobotTaskScheduleResponse, string>
|
||||
{
|
||||
private readonly SettingsFromDb settingsFromDb;
|
||||
|
||||
public RobotTaskScheduleTimezoneResolver(SettingsFromDb settingsFromDb)
|
||||
{
|
||||
this.settingsFromDb = settingsFromDb;
|
||||
}
|
||||
|
||||
public string Resolve(RobotConfiguration source, RobotTaskScheduleResponse destination, string destMember, ResolutionContext context)
|
||||
{
|
||||
return settingsFromDb.ScheduleTimezone;
|
||||
}
|
||||
}
|
||||
}
|
||||
20
PARR.BLL/Helpers/EsppScheduleHelpers.cs
Normal file
20
PARR.BLL/Helpers/EsppScheduleHelpers.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace PARR.BLL.Helpers
|
||||
{
|
||||
public static class EsppScheduleHelpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Получить дату первого старта в формате ЕСПП
|
||||
/// </summary>
|
||||
/// <param name="startDate"></param>
|
||||
/// <param name="time"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetFirstStart(DateOnly startDate, TimeSpan time)
|
||||
{
|
||||
var date = new DateTime(startDate.Year, startDate.Month, startDate.Day, time.Hours, time.Minutes, time.Seconds);
|
||||
|
||||
return date.ToString("dd/MM/yy HH:mm:ss", CultureInfo.InvariantCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,6 +55,7 @@ namespace PARR.DAL
|
||||
services.AddTransient<IRobotService, RobotService>();
|
||||
services.AddTransient<IRobotConfigurationService, RobotConfigurationService>();
|
||||
services.AddTransient<IRobotHistoryService, RobotHistoryService>();
|
||||
services.AddTransient<IEsppSchTypeConfigService, EsppSchTypeConfigService>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PARR.DAL.Context;
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.Services.Abstracts;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
|
||||
namespace PARR.DAL.Services.Implementations
|
||||
{
|
||||
internal class EsppSchTypeConfigService : BaseService<EsppSchTypeConfig>, IEsppSchTypeConfigService
|
||||
{
|
||||
private readonly DataContext dataContext;
|
||||
|
||||
public EsppSchTypeConfigService(DataContext dataContext, ILogger<EsppSchTypeConfigService> logger) : base(logger)
|
||||
{
|
||||
this.dataContext = dataContext;
|
||||
}
|
||||
|
||||
protected override DbSet<EsppSchTypeConfig> EntitySet => dataContext.EsppSchTypeConfigs;
|
||||
|
||||
protected override DataContext EntitiContext => dataContext;
|
||||
|
||||
public IQueryable<EsppSchTypeConfig> GetWithSchIncludes()
|
||||
{
|
||||
return Get()
|
||||
.Include(t => t.EsppSchValues)
|
||||
.Include(t => t.EsppSchTypeSchedule)
|
||||
.Include(t => t.EsppSchType)
|
||||
.ThenInclude(t => t!.EsppSchTypeValues)
|
||||
.ThenInclude(t => t!.EsppSchValues);
|
||||
}
|
||||
}
|
||||
}
|
||||
10
PARR.DAL/Services/Interfaces/IEsppSchTypeConfigService.cs
Normal file
10
PARR.DAL/Services/Interfaces/IEsppSchTypeConfigService.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using PARR.DAL.Models;
|
||||
using PARR.DAL.Services.Interfaces.Base;
|
||||
|
||||
namespace PARR.DAL.Services.Interfaces
|
||||
{
|
||||
public interface IEsppSchTypeConfigService : IBaseService<EsppSchTypeConfig>
|
||||
{
|
||||
IQueryable<EsppSchTypeConfig> GetWithSchIncludes();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user