Добавление даты и ключа пользователя, внесшего изменения в блоки суточного рапорта

This commit is contained in:
Olga Nemt 2023-03-22 11:29:53 +05:00
parent 8a9a565365
commit baee2ae139
3 changed files with 68 additions and 59 deletions

View File

@ -9,5 +9,7 @@
/// Глубина забоя /// Глубина забоя
/// </summary> /// </summary>
public double Depth { get; set; } public double Depth { get; set; }
//TODO: Дописать
} }
} }

View File

@ -108,18 +108,7 @@ namespace AsbCloudInfrastructure.Services.DailyReport.DailyReportBlocks
._SetValue("Расширка", true); ._SetValue("Расширка", true);
sheet.Cell(AddressRepair) sheet.Cell(AddressRepair)
._SetValue("Ремонт", true); ._SetValue("Ремонт", true);
sheet.Cell(AddressDrillingValue) //TODO: дописать timebalance
._SetValue($"{blockDto.Drilling}");
sheet.Cell(AddressFlushingValue)
._SetValue($"{blockDto.Flushing}");
sheet.Cell(AddressBuildingValue)
._SetValue($"{blockDto.Building}");
sheet.Cell(AddressElaborationValue)
._SetValue($"{blockDto.Elaboration}");
sheet.Cell(AddressExtensionValue)
._SetValue($"{blockDto.Extension}");
sheet.Cell(AddressRepairValue)
._SetValue($"{blockDto.Repair}");
sheet.Cell(AddressKnbk) sheet.Cell(AddressKnbk)
._SetValue("КНБК"); ._SetValue("КНБК");
sheet.Cell(AddressSpo) sheet.Cell(AddressSpo)
@ -132,18 +121,18 @@ namespace AsbCloudInfrastructure.Services.DailyReport.DailyReportBlocks
._SetValue("ПГР"); ._SetValue("ПГР");
sheet.Cell(AddressGis) sheet.Cell(AddressGis)
._SetValue("ГИС"); ._SetValue("ГИС");
sheet.Cell(AddressKnbkValue) //sheet.Cell(AddressKnbkValue)
._SetValue($"{blockDto.Knbk}"); // ._SetValue($"{blockDto.Knbk}");
sheet.Cell(AddressSpoValue) //sheet.Cell(AddressSpoValue)
._SetValue($"{blockDto.Spo}"); // ._SetValue($"{blockDto.Spo}");
sheet.Cell(AddressPzrValue) //sheet.Cell(AddressPzrValue)
._SetValue($"{blockDto.Pzr}"); // ._SetValue($"{blockDto.Pzr}");
sheet.Cell(AddressPvoValue) //sheet.Cell(AddressPvoValue)
._SetValue($"{blockDto.Pvo}"); // ._SetValue($"{blockDto.Pvo}");
sheet.Cell(AddressPgrValue) //sheet.Cell(AddressPgrValue)
._SetValue($"{blockDto.Pgr}"); // ._SetValue($"{blockDto.Pgr}");
sheet.Cell(AddressGisValue) //sheet.Cell(AddressGisValue)
._SetValue($"{blockDto.Gis}"); // ._SetValue($"{blockDto.Gis}");
sheet.Cell(AddressOzc) sheet.Cell(AddressOzc)
._SetValue("ОЗЦ"); ._SetValue("ОЗЦ");
sheet.Cell(AddressEngineeringWorks) sheet.Cell(AddressEngineeringWorks)
@ -156,18 +145,18 @@ namespace AsbCloudInfrastructure.Services.DailyReport.DailyReportBlocks
._SetValue("Простой"); ._SetValue("Простой");
sheet.Cell(AddressNpv) sheet.Cell(AddressNpv)
._SetValue("НПВ"); ._SetValue("НПВ");
sheet.Cell(AddressOzcValue) //sheet.Cell(AddressOzcValue)
._SetValue($"{blockDto.Ozc}"); // ._SetValue($"{blockDto.Ozc}");
sheet.Cell(AddressEngineeringWorksValue) //sheet.Cell(AddressEngineeringWorksValue)
._SetValue($"{blockDto.EngineeringWorks}"); // ._SetValue($"{blockDto.EngineeringWorks}");
sheet.Cell(AddressTakingMeasureValue) //sheet.Cell(AddressTakingMeasureValue)
._SetValue($"{blockDto.TakingMeasure}"); // ._SetValue($"{blockDto.TakingMeasure}");
sheet.Cell(AddressCementingValue) //sheet.Cell(AddressCementingValue)
._SetValue($"{blockDto.Cementing}"); // ._SetValue($"{blockDto.Cementing}");
sheet.Cell(AddressSimpleValue) //sheet.Cell(AddressSimpleValue)
._SetValue($"{blockDto.Simple}"); // ._SetValue($"{blockDto.Simple}");
sheet.Cell(AddressNpvValue) //sheet.Cell(AddressNpvValue)
._SetValue($"{blockDto.Npv}"); // ._SetValue($"{blockDto.Npv}");
} }
} }

View File

@ -68,6 +68,32 @@ namespace AsbCloudInfrastructure.Services.DailyReport
var entities = await query.OrderByDescending(e => e.StartDate).ToListAsync(token); var entities = await query.OrderByDescending(e => e.StartDate).ToListAsync(token);
var dtos = entities.Select(Convert).ToList();
var factOperationsForDtos = await getFactOperationsForDailyReportAsync(idWell, token);
foreach (var dto in dtos)
{
dto.TimeBalance.OperationsStat = (factOperationsForDtos
.Where(o => DateOnly.FromDateTime(o.DateStart) == dto.StartDate)
.GroupBy(o => o.IdCategory)
.Select(g => new OperationStatDto() { Depth = g.Sum(o => o.DepthEnd - o.DepthStart) }));
await SetUserNamesToDailyReportDtoAsync(dto, token);
}
return dtos;
}
/// <summary>
/// получение фактических операций для суточного рапорта
/// </summary>
/// <param name="idWell"></param>
/// <param name="token"></param>
/// <returns></returns>
private async Task<IEnumerable<WellOperationDto>> getFactOperationsForDailyReportAsync(int idWell, CancellationToken token)
{
var request = new WellOperationRequest() var request = new WellOperationRequest()
{ {
IdWell = idWell, IdWell = idWell,
@ -75,45 +101,37 @@ namespace AsbCloudInfrastructure.Services.DailyReport
}; };
var factOperations = await wellOperationRepository.GetAsync(request, token); var factOperations = await wellOperationRepository.GetAsync(request, token);
return factOperations;
var dtos = entities.Select(Convert);
var result = await Task.WhenAll(dtos.Select(i => BindDataToDtoAsync(i, factOperations, token)));
return result;
} }
/// <summary> /// <summary>
/// Заполнение DTO-модели необходимыми данными /// Заполнение DTO-модели данными о пользователях
/// </summary> /// </summary>
/// <param name="dto"></param> /// <param name="dto"></param>
/// <param name="factOperations"></param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
private async Task<DailyReportDto> BindDataToDtoAsync(DailyReportDto dto, IEnumerable<WellOperationDto> factOperations, CancellationToken token) private async Task<DailyReportDto> SetUserNamesToDailyReportDtoAsync(DailyReportDto dto, CancellationToken token)
{ {
var blocks = new ItemInfoDto[] { var blocks = new ItemInfoDto[] {
dto.Head, dto.Head,
dto.Bha, dto.Bha,
dto.NoDrilling, dto.NoDrilling,
dto.TimeBalance,
dto.Saub, dto.Saub,
dto.Sign, dto.Sign
dto.TimeBalance
}; };
foreach (var block in blocks) foreach (var block in blocks)
{ {
if (block.IdUser is not null) if (block.IdUser is not null)
{ {
var userDto = await userRepository.GetOrDefaultAsync(block.IdUser.Value, token); var user = await userRepository.GetOrDefaultAsync(block.IdUser.Value, token);
if (userDto is not null) block.UserName = user is not null
block.UserName = string.Format("{0} {1} {2}", userDto.Surname, userDto.Name, userDto.Patronymic); ? string.Format("{0} {1} {2}", user.Surname, user.Name, user.Patronymic)
: String.Empty;
} }
} }
dto.TimeBalance.OperationsStat = (factOperations
.Where(o => DateOnly.FromDateTime(o.DateStart) == dto.StartDate)
.GroupBy(o => o.IdCategory)
.Select(g => new OperationStatDto() { Depth = g.Sum(o => o.DepthEnd - o.DepthStart) }));
return dto; return dto;
} }