forked from ddrilling/AsbCloudServer
73 lines
2.2 KiB
C#
73 lines
2.2 KiB
C#
using AsbCloudApp.Data.ProcessMaps;
|
|
using AsbCloudApp.Requests;
|
|
using AsbCloudApp.Services;
|
|
using AsbCloudDb.Model;
|
|
using AsbCloudDb.Model.ProcessMapPlan;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace AsbCloudInfrastructure.Repository;
|
|
|
|
public class ProcessMapPlanBaseRepository<TDto, TEntity> : ChangeLogRepositoryAbstract<TDto, TEntity, ProcessMapPlanBaseRequestWithWell>
|
|
where TDto : ProcessMapPlanBaseDto
|
|
where TEntity : ProcessMapPlanBase
|
|
{
|
|
private readonly IWellService wellService;
|
|
|
|
public ProcessMapPlanBaseRepository(IAsbCloudDbContext context, IWellService wellService)
|
|
: base(context)
|
|
{
|
|
this.wellService = wellService;
|
|
}
|
|
|
|
protected override IQueryable<TEntity> BuildQuery(ProcessMapPlanBaseRequestWithWell request)
|
|
{
|
|
var query = db
|
|
.Set<TEntity>()
|
|
.Include(e => e.Author)
|
|
.Include(e => e.Editor)
|
|
.Include(e => e.Well)
|
|
.Include(e => e.WellSectionType)
|
|
.Where(e => e.IdWell == request.IdWell);
|
|
|
|
if (request.UpdateFrom.HasValue)
|
|
{
|
|
var from = request.UpdateFrom.Value.ToUniversalTime();
|
|
query = query.Where(e => e.Creation >= from || e.Obsolete >= from);
|
|
}
|
|
|
|
if (request.Moment.HasValue)
|
|
{
|
|
var moment = request.Moment.Value.ToUniversalTime();
|
|
query = query
|
|
.Where(e => e.Creation <= moment)
|
|
.Where(e => e.Obsolete == null || e.Obsolete >= moment);
|
|
}
|
|
|
|
return query;
|
|
}
|
|
|
|
protected override TimeSpan GetTimezoneOffset(ProcessMapPlanBaseRequestWithWell request)
|
|
{
|
|
var timezone = wellService.GetTimezone(request.IdWell);
|
|
var offset = TimeSpan.FromHours(timezone.Hours);
|
|
return offset;
|
|
}
|
|
|
|
protected override TDto Convert(TEntity entity, TimeSpan offset)
|
|
{
|
|
var dto = base.Convert(entity, offset);
|
|
dto.Section = entity.WellSectionType.Caption;
|
|
return dto;
|
|
}
|
|
|
|
protected override TEntity Convert(TDto dto)
|
|
{
|
|
var entity = base.Convert(dto);
|
|
//entity.Author = null;
|
|
//entity.Editor = null;
|
|
return entity;
|
|
}
|
|
}
|