2024-02-21 15:08:51 +05:00
|
|
|
|
using AsbCloudApp.Data.ProcessMaps;
|
2024-01-19 17:48:45 +05:00
|
|
|
|
using AsbCloudApp.Requests;
|
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using AsbCloudDb.Model;
|
|
|
|
|
using AsbCloudDb.Model.ProcessMapPlan;
|
2024-05-03 14:37:46 +05:00
|
|
|
|
using Mapster;
|
2024-01-19 17:48:45 +05:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudInfrastructure.Repository;
|
|
|
|
|
|
2024-01-29 12:25:58 +05:00
|
|
|
|
public class ProcessMapPlanBaseRepository<TDto, TEntity> : ChangeLogRepositoryAbstract<TDto, TEntity, ProcessMapPlanBaseRequestWithWell>
|
2024-05-28 00:05:21 +05:00
|
|
|
|
where TDto : AsbCloudApp.Data.IId
|
2024-01-19 17:48:45 +05:00
|
|
|
|
where TEntity : ProcessMapPlanBase
|
|
|
|
|
{
|
|
|
|
|
private readonly IWellService wellService;
|
|
|
|
|
|
2024-01-29 12:25:58 +05:00
|
|
|
|
public ProcessMapPlanBaseRepository(IAsbCloudDbContext context, IWellService wellService)
|
|
|
|
|
: base(context)
|
2024-01-19 17:48:45 +05:00
|
|
|
|
{
|
|
|
|
|
this.wellService = wellService;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-29 12:25:58 +05:00
|
|
|
|
protected override IQueryable<TEntity> BuildQuery(ProcessMapPlanBaseRequestWithWell request)
|
2024-01-19 17:48:45 +05:00
|
|
|
|
{
|
2024-02-06 16:49:29 +05:00
|
|
|
|
var query = db
|
2024-01-19 17:48:45 +05:00
|
|
|
|
.Set<TEntity>()
|
2024-01-25 15:39:19 +05:00
|
|
|
|
.Include(e => e.Author)
|
|
|
|
|
.Include(e => e.Editor)
|
2024-01-29 12:25:58 +05:00
|
|
|
|
.Include(e => e.Well)
|
2024-03-14 10:30:25 +05:00
|
|
|
|
.Include(e => e.WellSectionType)
|
2024-01-29 12:25:58 +05:00
|
|
|
|
.Where(e => e.IdWell == request.IdWell);
|
2024-01-19 17:48:45 +05:00
|
|
|
|
|
|
|
|
|
if (request.UpdateFrom.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var from = request.UpdateFrom.Value.ToUniversalTime();
|
2024-01-20 15:38:37 +05:00
|
|
|
|
query = query.Where(e => e.Creation >= from || e.Obsolete >= from);
|
2024-01-19 17:48:45 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (request.Moment.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var moment = request.Moment.Value.ToUniversalTime();
|
|
|
|
|
query = query
|
2024-01-21 09:38:07 +05:00
|
|
|
|
.Where(e => e.Creation <= moment)
|
|
|
|
|
.Where(e => e.Obsolete == null || e.Obsolete >= moment);
|
2024-01-19 17:48:45 +05:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-29 12:25:58 +05:00
|
|
|
|
return query;
|
2024-01-19 17:48:45 +05:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-29 12:25:58 +05:00
|
|
|
|
protected override TimeSpan GetTimezoneOffset(ProcessMapPlanBaseRequestWithWell request)
|
2024-01-19 17:48:45 +05:00
|
|
|
|
{
|
2024-01-29 12:25:58 +05:00
|
|
|
|
var timezone = wellService.GetTimezone(request.IdWell);
|
2024-01-19 17:48:45 +05:00
|
|
|
|
var offset = TimeSpan.FromHours(timezone.Hours);
|
2024-01-29 12:25:58 +05:00
|
|
|
|
return offset;
|
2024-01-22 11:49:45 +05:00
|
|
|
|
}
|
2024-03-14 10:30:25 +05:00
|
|
|
|
|
2024-03-15 17:41:19 +05:00
|
|
|
|
protected override TEntity Convert(TDto dto)
|
|
|
|
|
{
|
|
|
|
|
var entity = base.Convert(dto);
|
|
|
|
|
entity.Author = null;
|
|
|
|
|
entity.Editor = null;
|
|
|
|
|
return entity;
|
|
|
|
|
}
|
2024-01-19 17:48:45 +05:00
|
|
|
|
}
|