86 lines
3.1 KiB
C#
86 lines
3.1 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Logging;
|
|
using PARR.Constants;
|
|
using PARR.DAL.Context;
|
|
using PARR.DAL.Contracts;
|
|
using PARR.DAL.Models;
|
|
using PARR.DAL.Services.Abstracts;
|
|
using PARR.DAL.Services.Interfaces;
|
|
|
|
namespace PARR.DAL.Services.Implementations
|
|
{
|
|
internal class TemplateService : BaseService<Template>, ITemplateService
|
|
{
|
|
private readonly DataContext dataContext;
|
|
private readonly ILogger<TemplateService> logger;
|
|
|
|
protected override DbSet<Template> EntitySet => dataContext.Templates;
|
|
|
|
protected override DataContext EntitiContext => dataContext;
|
|
|
|
public TemplateService(DataContext dataContext, ILogger<TemplateService> logger) : base(logger)
|
|
{
|
|
this.dataContext = dataContext;
|
|
this.logger = logger;
|
|
}
|
|
|
|
public async Task<Template?> GetTemplateByNameAsync(string name)
|
|
{
|
|
return await GetWithIncludes()
|
|
.Include(t => t.RobotConfigurations)
|
|
.FirstOrDefaultAsync(t => t.Name == name);
|
|
}
|
|
|
|
public IQueryable<Template> GetWithIncludes()
|
|
{
|
|
return Get()
|
|
.Include(h => h.Host)
|
|
.ThenInclude(t => t!.ResponseArea)
|
|
.Include(h => h.Host)
|
|
.ThenInclude(t => t!.WorkGroup)
|
|
.ThenInclude(t => t!.ResponseArea)
|
|
.Include(h => h.Host)
|
|
.ThenInclude(t => t!.EkStatus)
|
|
.Include(a => a.ApplicationsInWork)
|
|
.ThenInclude(w => w!.Work)
|
|
.ThenInclude(t => t!.Tnk)
|
|
.ThenInclude(s => s!.Subprocess)
|
|
.ThenInclude(p => p!.Process);
|
|
}
|
|
|
|
public override Task<bool> CreateAsync(Template obj)
|
|
{
|
|
// добавление роботов для шаблона
|
|
obj.RobotConfigurations = new List<RobotConfiguration>
|
|
{
|
|
// робот по управлению шаблоном
|
|
new RobotConfiguration
|
|
{
|
|
Id = Guid.NewGuid(),
|
|
DateCreated = DateTimeOffset.UtcNow,
|
|
TemplateId = obj.Id,
|
|
RobotCode = (int)RobotsEnum.TemplateOrder,
|
|
TaskStatusCode = (int)TaskStatusEnum.Creating,
|
|
RobotStatusCode = (int)RobotStatusEnum.Wait,
|
|
AttemptsNumber = 0,
|
|
LastRobotStatusUpdated = null
|
|
},
|
|
// робот по управлениею расписанием
|
|
new RobotConfiguration
|
|
{
|
|
Id = Guid.NewGuid(),
|
|
DateCreated = DateTimeOffset.UtcNow,
|
|
TemplateId = obj.Id,
|
|
RobotCode = (int)RobotsEnum.ScheduleOrder,
|
|
TaskStatusCode = (int)TaskStatusEnum.Creating,
|
|
RobotStatusCode = (int)RobotStatusEnum.Wait,
|
|
AttemptsNumber = 0,
|
|
LastRobotStatusUpdated = null
|
|
}
|
|
};
|
|
|
|
return base.CreateAsync(obj);
|
|
}
|
|
}
|
|
}
|