forked from ddrilling/AsbCloudServer
Убрал ненужные переопределения.
Добавил учет часового пояса скважины.
This commit is contained in:
parent
339921b968
commit
23cf8d2108
@ -137,7 +137,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
public virtual TModel Convert(TDto src) => src.Adapt<TModel>();
|
||||
|
||||
private IQueryable<TModel> GetQueryWithIncludes()
|
||||
protected IQueryable<TModel> GetQueryWithIncludes()
|
||||
{
|
||||
IQueryable<TModel> query = dbSet;
|
||||
foreach (var include in Includes)
|
||||
|
@ -14,33 +14,5 @@ namespace AsbCloudInfrastructure.Services
|
||||
public DrillerService(IAsbCloudDbContext context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<int> DeleteAsync(int id, CancellationToken dto)
|
||||
{
|
||||
return await base.DeleteAsync(id, dto);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<DrillerDto>> GetAllAsync(CancellationToken token)
|
||||
{
|
||||
return await base.GetAllAsync(token);
|
||||
}
|
||||
|
||||
public async Task<DrillerDto> GetAsync(int id, CancellationToken token)
|
||||
{
|
||||
return await base.GetAsync(id,token)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<int> InsertAsync(DrillerDto dto, CancellationToken token)
|
||||
{
|
||||
return await base.InsertAsync(dto, token);
|
||||
}
|
||||
|
||||
public async Task<int> UpdateAsync(int id, DrillerDto dto, CancellationToken token)
|
||||
{
|
||||
return await base.UpdateAsync(id,dto, token);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,68 +1,68 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Services.Cache;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
public class ScheduleService : CrudServiceBase<ScheduleDto, ScheduleItem>, IScheduleService
|
||||
#nullable enable
|
||||
public class ScheduleService : CrudServiceBase<ScheduleDto, Schedule>, IScheduleService
|
||||
{
|
||||
public ScheduleService(IAsbCloudDbContext context) : base(context)
|
||||
private readonly IWellService wellService;
|
||||
|
||||
public ScheduleService(IAsbCloudDbContext context, IWellService wellService) : base(context)
|
||||
{
|
||||
Includes.Add(nameof(ScheduleItem.Driller));
|
||||
Includes.Add(nameof(Schedule.Driller));
|
||||
this.wellService = wellService;
|
||||
}
|
||||
|
||||
public async Task<int> DeleteAsync(int id, CancellationToken dto)
|
||||
public async Task<DrillerDto?> GetDrillerAsync(int idWell, DateTime workTime, CancellationToken token = default)
|
||||
{
|
||||
return await base.DeleteAsync(id,dto);
|
||||
}
|
||||
var hoursOffset = wellService.GetTimezone(idWell).Hours;
|
||||
var date = workTime.ToUtcDateTimeOffset(hoursOffset);
|
||||
|
||||
public async Task<IEnumerable<ScheduleDto>> GetAllAsync(CancellationToken token)
|
||||
{
|
||||
return await base.GetAllAsync(token);
|
||||
}
|
||||
var entities = await GetQueryWithIncludes()
|
||||
.Where(s => s.IdWell==idWell
|
||||
&& s.DrillStart <= date
|
||||
&& s.DrillEnd >= date)
|
||||
.ToListAsync(token);
|
||||
|
||||
public async Task<ScheduleDto> GetAsync(int id, CancellationToken token)
|
||||
{
|
||||
var res= await base.GetAsync(id,token)
|
||||
.ConfigureAwait(false);
|
||||
return res;
|
||||
}
|
||||
|
||||
public async Task<DrillerDto> GetSchedule(int idWell, DateTimeOffset workTime, CancellationToken token = default)
|
||||
{
|
||||
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)
|
||||
if (!entities.Any())
|
||||
return null;
|
||||
|
||||
return entires.Driller.Adapt<DrillerDto>();
|
||||
var remoteDate = date.ToRemoteDateTime(hoursOffset);
|
||||
var time = new TimeOnly(remoteDate.Hour, remoteDate.Minute, remoteDate.Second);
|
||||
|
||||
var entity = entities.FirstOrDefault(s =>
|
||||
(s.ShiftStart > s.ShiftEnd) ^
|
||||
(time >= s.ShiftStart && time < s.ShiftEnd)
|
||||
);
|
||||
|
||||
return entity?.Driller.Adapt<DrillerDto>();
|
||||
}
|
||||
|
||||
public async Task<int> InsertAsync(ScheduleDto dto, CancellationToken token)
|
||||
public override Schedule Convert(ScheduleDto dto)
|
||||
{
|
||||
return await base.InsertAsync(dto,token);
|
||||
var hoursOffset = wellService.GetTimezone(dto.IdWell).Hours;
|
||||
var entity = base.Convert(dto);
|
||||
entity.DrillStart = dto.DrillStart.ToUtcDateTimeOffset(hoursOffset);
|
||||
entity.DrillEnd = dto.DrillEnd.ToUtcDateTimeOffset(hoursOffset);
|
||||
return entity;
|
||||
}
|
||||
|
||||
public async Task<int> UpdateAsync(int id, ScheduleDto dto, CancellationToken token)
|
||||
public override ScheduleDto Convert(Schedule entity)
|
||||
{
|
||||
return await base.UpdateAsync(id,dto,token);
|
||||
var hoursOffset = wellService.GetTimezone(entity.IdWell).Hours;
|
||||
var dto = base.Convert(entity);
|
||||
dto.DrillStart = entity.DrillStart.ToRemoteDateTime(hoursOffset);
|
||||
dto.DrillEnd = entity.DrillEnd.ToRemoteDateTime(hoursOffset);
|
||||
return dto;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
#nullable disable
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user