2022-05-22 21:18:43 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using AsbCloudDb.Model;
|
|
|
|
|
using AsbCloudInfrastructure.Services.Cache;
|
2022-05-25 20:19:08 +05:00
|
|
|
|
using Mapster;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2022-05-22 21:18:43 +05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudInfrastructure.Services
|
|
|
|
|
{
|
2022-05-25 20:19:08 +05:00
|
|
|
|
public class ScheduleService : CrudServiceBase<ScheduleDto, ScheduleItem>, IScheduleService
|
2022-05-22 21:18:43 +05:00
|
|
|
|
{
|
2022-05-25 20:19:08 +05:00
|
|
|
|
public ScheduleService(IAsbCloudDbContext context) : base(context)
|
2022-05-22 21:18:43 +05:00
|
|
|
|
{
|
2022-05-25 20:19:08 +05:00
|
|
|
|
Includes.Add(nameof(ScheduleItem.Driller));
|
2022-05-22 21:18:43 +05:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-25 20:19:08 +05:00
|
|
|
|
public async Task<int> DeleteAsync(int id, CancellationToken dto)
|
|
|
|
|
{
|
|
|
|
|
return await base.DeleteAsync(id,dto);
|
2022-05-22 21:18:43 +05:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-25 20:19:08 +05:00
|
|
|
|
public async Task<IEnumerable<ScheduleDto>> GetAllAsync(CancellationToken token)
|
2022-05-22 21:18:43 +05:00
|
|
|
|
{
|
|
|
|
|
return await base.GetAllAsync(token);
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-25 20:19:08 +05:00
|
|
|
|
public async Task<ScheduleDto> GetAsync(int id, CancellationToken token)
|
2022-05-22 21:18:43 +05:00
|
|
|
|
{
|
2022-05-25 20:19:08 +05:00
|
|
|
|
var res= await base.GetAsync(id,token)
|
2022-05-22 21:18:43 +05:00
|
|
|
|
.ConfigureAwait(false);
|
2022-05-25 20:19:08 +05:00
|
|
|
|
return res;
|
2022-05-22 21:18:43 +05:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-25 20:19:08 +05:00
|
|
|
|
public async Task<DrillerDto> GetSchedule(int idWell, DateTimeOffset workTime, CancellationToken token = default)
|
2022-05-22 21:18:43 +05:00
|
|
|
|
{
|
2022-05-25 20:19:08 +05:00
|
|
|
|
IQueryable<ScheduleItem> query = context.Set<ScheduleItem>();
|
|
|
|
|
foreach (var include in Includes)
|
|
|
|
|
query = query.Include(include);
|
|
|
|
|
|
|
|
|
|
var entires = query.Where(e => e.IdWell==idWell
|
|
|
|
|
&& e.DrillStart <= workTime
|
|
|
|
|
&& e.DrillEnd >= workTime)
|
|
|
|
|
.FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
if (entires is null)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
return entires.Driller.Adapt<DrillerDto>();
|
2022-05-22 21:18:43 +05:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-25 20:19:08 +05:00
|
|
|
|
public async Task<int> InsertAsync(ScheduleDto dto, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
return await base.InsertAsync(dto,token);
|
2022-05-22 21:18:43 +05:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-25 20:19:08 +05:00
|
|
|
|
public async Task<int> UpdateAsync(int id, ScheduleDto dto, CancellationToken token)
|
2022-05-22 21:18:43 +05:00
|
|
|
|
{
|
2022-05-25 20:19:08 +05:00
|
|
|
|
return await base.UpdateAsync(id,dto,token);
|
2022-05-22 21:18:43 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|