debug and fix daily report

This commit is contained in:
ngfrolov 2022-05-05 15:14:29 +05:00
parent 5de01e5b5d
commit 5458ac5414
2 changed files with 23 additions and 15 deletions

View File

@ -76,9 +76,12 @@ namespace AsbCloudInfrastructure.Services.DailyReport
public async Task<int> UpdateAsync(int idWell, DateTime date, DailyReportDto dto, CancellationToken token)
{
var offsetHours = wellService.GetTimezone(idWell).Hours;
var reportDateOffset = date.ToUtcDateTimeOffset(offsetHours);
var dateOffset = date.ToUtcDateTimeOffset(offsetHours);
var entity = await db.DailyReports
.FirstOrDefaultAsync(r => r.IdWell == idWell && r.StartDate == reportDateOffset, token);
.FirstOrDefaultAsync(r => r.IdWell == idWell &&
r.StartDate.Year == dateOffset.Year &&
r.StartDate.DayOfYear == dateOffset.DayOfYear
, token);
if (entity is null)
return 0;
@ -104,15 +107,16 @@ namespace AsbCloudInfrastructure.Services.DailyReport
{
var offsetHours = wellService.GetTimezone(idWell).Hours;
var dateOffset = date.ToUtcDateTimeOffset(offsetHours);
var query = db.DailyReports
.Where(r => r.IdWell == idWell)
.Where(d => d.StartDate == dateOffset);
var entity = await db.DailyReports
.FirstOrDefaultAsync(r => r.IdWell == idWell &&
r.StartDate.Year == dateOffset.Year &&
r.StartDate.DayOfYear == dateOffset.DayOfYear
, token);
var data = await query.FirstOrDefaultAsync(token);
if (data is null)
if (entity is null)
return null;
else
return Convert(data, offsetHours);
return Convert(entity, offsetHours);
}
private async Task<DailyReportDto> MakeDefaultDailyReportAsync(int idWell, CancellationToken token)
@ -121,10 +125,9 @@ namespace AsbCloudInfrastructure.Services.DailyReport
var offsetHours = wellService.GetTimezone(idWell).Hours;
var dto = new DailyReportDto()
{
ReportDate = DateTimeOffset.UtcNow.ToRemoteDateTime(offsetHours),
ReportDate = DateTimeOffset.UtcNow.ToRemoteDateTime(offsetHours).Date,
WellName = well.Caption,
ClusterName = well.Cluster,
ClusterName = well.Cluster,
};
DailyReportDto result = dto;
return result;
@ -133,14 +136,17 @@ namespace AsbCloudInfrastructure.Services.DailyReport
private static DailyReportDto Convert(AsbCloudDb.Model.DailyReport entity, double offsetHours)
{
var dto = entity.Info.Adapt<DailyReportDto>();
dto.ReportDate = entity.StartDate.ToRemoteDateTime(offsetHours);
dto.ReportDate = entity.StartDate
.ToRemoteDateTime(offsetHours);
return dto;
}
private static DailyReportInfo Convert(DailyReportDto dto, double offsetHours)
{
var entity = dto.Adapt<DailyReportInfo>();
entity.ReportDate = dto.ReportDate.ToUtcDateTimeOffset(offsetHours);
var entity = dto.Adapt<DailyReportInfo>();
entity.ReportDate = dto.ReportDate
.ToUtcDateTimeOffset(offsetHours)
.Date;
return entity;
}
}

View File

@ -101,10 +101,12 @@ namespace AsbCloudWebApi.Controllers
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> DownloadAsync(int idWell, DateTime date, CancellationToken token = default)
{
var well = await wellService.GetAsync(idWell, token);
var stream = await dailyReportService.MakeReportAsync(idWell, date, token);
if (stream != null)
{
var fileName = "CP.xlsx";
var fileName = $"Суточный рапорт по скважине {well.Caption} куст {well.Cluster}.xlsx";
return File(stream, "application/octet-stream", fileName);
}
else