forked from ddrilling/AsbCloudServer
1bda2d5b77
1. Устранение багов выявленных при тестировании 2. Изменение имён методов в сервисе суточных отчётов 3. Фикс получения фиктивных суточных отчётов 4. Фикс шаблона 5. Правки в контроллере 6. Фикс в репозитории. Приведение к utc доа выполнения запроса 7. Покрытие сервиса тестами
103 lines
2.5 KiB
C#
103 lines
2.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using AsbCloudApp.Data;
|
|
using AsbCloudApp.Data.DailyReport;
|
|
using AsbCloudApp.Data.DailyReport.Blocks.TimeBalance;
|
|
using AsbCloudApp.Repositories;
|
|
using AsbCloudApp.Requests;
|
|
using AsbCloudDb;
|
|
using AsbCloudDb.Model;
|
|
using AsbCloudDb.Model.DailyReports;
|
|
using Mapster;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace AsbCloudInfrastructure.Repository;
|
|
|
|
public class DailyReportRepository : CrudRepositoryBase<DailyReportDto, DailyReport>,
|
|
IDailyReportRepository
|
|
{
|
|
public DailyReportRepository(IAsbCloudDbContext dbContext)
|
|
: base(dbContext)
|
|
{
|
|
}
|
|
|
|
public async Task<IEnumerable<DailyReportDto>> GetAsync(int idWell, FileReportRequest request, CancellationToken cancellationToken)
|
|
{
|
|
var skip = request.Skip ?? 0;
|
|
var take = request.Take ?? 10;
|
|
|
|
var query = GetQuery().Where(d => d.IdWell == idWell);
|
|
|
|
if (request.GeDate.HasValue)
|
|
{
|
|
var geDate = request.GeDate.Value.ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc);
|
|
query = query.Where(d => d.Date >= geDate);
|
|
}
|
|
|
|
if (request.LeDate.HasValue)
|
|
{
|
|
var leDate = request.LeDate.Value.ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc);
|
|
query = query.Where(d => d.Date <= leDate);
|
|
}
|
|
|
|
if (request.SortFields?.Any() == true)
|
|
{
|
|
query = query.SortBy(request.SortFields);
|
|
}
|
|
|
|
var entities = await query
|
|
.Skip(skip)
|
|
.Take(take)
|
|
.AsNoTracking()
|
|
.ToArrayAsync(cancellationToken);
|
|
|
|
var dtos = entities.Select(Convert);
|
|
|
|
return dtos;
|
|
}
|
|
|
|
public async Task<DailyReportDto?> GetOrDefaultAsync(int idWell, DateTime date, CancellationToken cancellationToken)
|
|
{
|
|
var entity = await GetQuery()
|
|
.Include(d => d.Well)
|
|
.AsNoTracking()
|
|
.SingleOrDefaultAsync(d => d.IdWell == idWell &&
|
|
d.Date == date, cancellationToken);
|
|
|
|
return entity is null ? null : Convert(entity);
|
|
}
|
|
|
|
protected override DailyReportDto Convert(DailyReport src)
|
|
{
|
|
var dto = base.Convert(src);
|
|
|
|
if (dto.TimeBalanceBlock is null)
|
|
return dto;
|
|
|
|
dto.TimeBalanceBlock.WellDepth = new PlanFactDto<double?>()
|
|
{
|
|
Plan = src.TimeBalanceBlock?.WellDepthPlan
|
|
};
|
|
|
|
if (src.TimeBalanceBlock?.WellOperations?.Any() == true)
|
|
{
|
|
dto.TimeBalanceBlock.WellOperations = src.TimeBalanceBlock.WellOperations.Select(w =>
|
|
{
|
|
var wellOperation = w.Adapt<TimeBalanceRecordDto>();
|
|
|
|
wellOperation.DurationHours = new PlanFactDto<double?>()
|
|
{
|
|
Plan = w.DurationHoursPlan,
|
|
Fact = w.DurationHoursFact
|
|
};
|
|
|
|
return wellOperation;
|
|
});
|
|
}
|
|
|
|
return dto;
|
|
}
|
|
} |