Фиксы

This commit is contained in:
Степанов Дмитрий 2024-09-02 09:47:34 +05:00
parent cf40bb85a1
commit 28788bde1f
4 changed files with 44 additions and 41 deletions

View File

@ -62,13 +62,11 @@ public interface IWellOperationRepository
Task<DatesRangeDto?> GetDatesRangeAsync(int idWell, int idType, CancellationToken cancellationToken); Task<DatesRangeDto?> GetDatesRangeAsync(int idWell, int idType, CancellationToken cancellationToken);
/// <summary> /// <summary>
/// Возвращает первую и последнюю операцию /// Возвращает первую и последнюю фактическую операцию
/// </summary> /// </summary>
/// <param name="idWell"></param> /// <param name="idWell"></param>
/// <param name="idType"></param> /// <returns></returns>
/// <param name="token"></param> (WellOperationBaseDto First, WellOperationBaseDto Last)? GetFirstAndLastFact(int idWell);
/// <returns></returns>
Task<(WellOperationBaseDto First, WellOperationBaseDto Last)?> GetFirstAndLastAsync(int idWell, int idType, CancellationToken token);
/// <summary> /// <summary>
/// Получить список операций по запросу /// Получить список операций по запросу

View File

@ -195,34 +195,36 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationBaseDto,
}; };
} }
public async Task<(WellOperationBaseDto First, WellOperationBaseDto Last)?> GetFirstAndLastAsync(int idWell, int idType, CancellationToken token) public (WellOperationBaseDto First, WellOperationBaseDto Last)? GetFirstAndLastFact(int idWell)
{ {
var cachedDictionary = await memoryCache.GetOrCreateAsync(cacheKeyWellOperations, async (entry) => var cachedDictionary = memoryCache.GetOrCreate(cacheKeyWellOperations, (entry) =>
{ {
entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(5); entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(5);
var query = dbContext.Set<WellOperation>() var query = dbContext.Set<WellOperation>()
.Where(o => o.IdType == idType) .Where(o => o.IdType == WellOperation.IdOperationTypeFact)
.GroupBy(o => o.IdWell) .GroupBy(o => o.IdWell)
.Select(group => new .Select(group => new
{ {
IdWell = group.Key, IdWell = group.Key,
FirstFact = group.OrderBy(o => o.DateStart).First(), FirstFact = group.OrderBy(o => o.DateStart).First(),
LastFact = group.OrderBy(o => o.DateStart).Last(), LastFact = group.OrderBy(o => o.DateStart).Last(),
}); });
var entities = await query.ToArrayAsync(token); var entities = query.ToArray();
var dictionary = entities.ToDictionary(s => s.IdWell, s => (Convert(s.FirstFact), Convert(s.LastFact))); var dictionary = entities.ToDictionary(s => s.IdWell, s => (Convert(s.FirstFact), Convert(s.LastFact)));
entry.Value = dictionary; entry.Value = dictionary;
return dictionary; return dictionary;
})!;
})!;
var firstAndLast = cachedDictionary.GetValueOrDefault(idWell);
return firstAndLast;
var firstAndLast = cachedDictionary?.GetValueOrDefault(idWell);
return firstAndLast;
} }
public override async Task<int> DeleteAsync(int id, CancellationToken token) public override async Task<int> DeleteAsync(int id, CancellationToken token)
{ {
var result = await base.DeleteAsync(id, token); var result = await base.DeleteAsync(id, token);
if (result > 0) if (result > 0)

View File

@ -274,7 +274,7 @@ public class WellService : CrudCacheRepositoryBase<WellDto, Well>, IWellService
dto.Timezone = GetTimezone(entity.Id); dto.Timezone = GetTimezone(entity.Id);
dto.StartDate = wellOperationRepository dto.StartDate = wellOperationRepository
.GetFirstAndLast(entity.Id)?.First?.DateStart; .GetFirstAndLastFact(entity.Id)?.First?.DateStart;
dto.WellType = entity.WellType.Caption; dto.WellType = entity.WellType.Caption;
dto.Cluster = entity.Cluster.Caption; dto.Cluster = entity.Cluster.Caption;
dto.Deposit = entity.Cluster.Deposit.Caption; dto.Deposit = entity.Cluster.Deposit.Caption;

View File

@ -15,22 +15,25 @@ public static class XLExtentions
workbook.Worksheets.FirstOrDefault(ws => string.Equals(ws.Name.Trim(), sheetName.Trim(), StringComparison.CurrentCultureIgnoreCase)) workbook.Worksheets.FirstOrDefault(ws => string.Equals(ws.Name.Trim(), sheetName.Trim(), StringComparison.CurrentCultureIgnoreCase))
?? throw new FileFormatException(string.Format(NotFoundSheetTemplate, sheetName)); ?? throw new FileFormatException(string.Format(NotFoundSheetTemplate, sheetName));
public static IXLCell SetCellValue<T>(this IXLCell cell, T value, string? format = null) public static IXLCell SetCellValue<T>(this IXLCell cell, T? value, string? format = null)
{ {
if (value is DateTime || value is DateTimeOffset) if (value == null)
{ return cell;
cell.Style.DateFormat.Format = format ?? "DD.MM.YYYY HH:MM:SS";
if (value is DateTimeOffset dateTimeOffset) if (value is DateTime || value is DateTimeOffset)
{ {
cell.Value = XLCellValue.FromObject(dateTimeOffset.DateTime); cell.Style.DateFormat.Format = format ?? "DD.MM.YYYY HH:MM:SS";
return cell;
}
}
cell.Value = XLCellValue.FromObject(value); if (value is DateTimeOffset dateTimeOffset)
{
cell.Value = XLCellValue.FromObject(dateTimeOffset.DateTime);
return cell;
}
}
return cell; cell.Value = XLCellValue.FromObject(value);
return cell;
} }
public static IXLCell SetHyperlink(this IXLCell cell, string link) public static IXLCell SetHyperlink(this IXLCell cell, string link)