diff --git a/AsbCloudApp/Data/DailyReport/ItemInfoDto.cs b/AsbCloudApp/Data/DailyReport/ItemInfoDto.cs index 7cfaeed0..0c9d9269 100644 --- a/AsbCloudApp/Data/DailyReport/ItemInfoDto.cs +++ b/AsbCloudApp/Data/DailyReport/ItemInfoDto.cs @@ -4,22 +4,22 @@ namespace AsbCloudApp.Data.DailyReport { /// /// хранение дополнительной информации о записи - /// автоматическое формирование данных на серверной стороне + /// запись формируется на сервере автоматически /// public class ItemInfoDto { /// - /// пользователь, внесший изменения + /// пользователь, внесший изменения (запись формируется на сервере автоматически) /// public int? IdUser { get; set; } /// - /// имя пользователя, внесшего изменения + /// имя пользователя, внесшего изменения (запись формируется на сервере автоматически) /// public string? UserName { get; set; } /// - /// дата последнего обновления + /// дата последнего обновления (запись формируется на сервере автоматически) /// public DateTimeOffset? LastUpdateDate { get; set; } } diff --git a/AsbCloudApp/Services/IDailyReportService.cs b/AsbCloudApp/Services/IDailyReportService.cs index 574a04bf..865985c0 100644 --- a/AsbCloudApp/Services/IDailyReportService.cs +++ b/AsbCloudApp/Services/IDailyReportService.cs @@ -16,11 +16,11 @@ namespace AsbCloudApp.Services /// получить список сформированных рапортов по скважине за период времени /// /// - /// - /// + /// + /// /// /// - Task> GetListAsync(int idWell, DateTime? v1, DateTime? v2, CancellationToken cancellationToken); + Task> GetListAsync(int idWell, DateTime? begin, DateTime? end, CancellationToken cancellationToken); /// /// Добавить новый рапорт @@ -30,7 +30,7 @@ namespace AsbCloudApp.Services /// /// /// - Task AddAsync(int idWell, DateTime startDate, int idUser, CancellationToken token = default); + Task AddAsync(int idWell, DateTime startDate, int idUser, CancellationToken token); /// /// Сформировать файл рапорта @@ -39,7 +39,7 @@ namespace AsbCloudApp.Services /// /// /// - Task MakeReportAsync(int idWell, DateTime date, CancellationToken token = default); + Task MakeReportAsync(int idWell, DateTime date, CancellationToken token); /// /// изменить блок данных для суточного рапорта diff --git a/AsbCloudDb/Model/DefaultData/EntityFillerWellOperationCategory.cs b/AsbCloudDb/Model/DefaultData/EntityFillerWellOperationCategory.cs index b5d8707b..a6db7abb 100644 --- a/AsbCloudDb/Model/DefaultData/EntityFillerWellOperationCategory.cs +++ b/AsbCloudDb/Model/DefaultData/EntityFillerWellOperationCategory.cs @@ -1,43 +1,50 @@ -using Microsoft.VisualBasic; -using static AsbCloudDb.Model.DefaultData.DefaultContextData; +using System.Linq; namespace AsbCloudDb.Model.DefaultData { - internal class EntityFillerWellOperationCategory : EntityFiller + public class EntityFillerWellOperationCategory : EntityFiller { - - public override WellOperationCategory[] GetData() => new WellOperationCategory[]{ - - // Этап работ - new () {Id = WellOperationCategory.IdDrilling, Name = "БУРЕНИЕ", KeyValueName = "dT", KeyValueUnits = "м/ч" }, - new () {Id = 3001, Name = "СПО", KeyValueName = "dT", KeyValueUnits = "мин" }, - new () {Id = 3002, Name = "КРЕПЛЕНИЕ", KeyValueName = "dT", KeyValueUnits = "мин" }, - new () {Id = 3003, Name = "ГФР", KeyValueName = "dT", KeyValueUnits = "мин" }, - new () {Id = 3004, Name = "Вспомогательные операции", KeyValueName = "dT", KeyValueUnits = "мин" }, - new () {Id = WellOperationCategory.IdNonProductiveTime, Name = "Непроизводительное время (НПВ)", KeyValueName = "dT", KeyValueUnits = "мин" }, + /// + /// Этапы работ + /// + public static WellOperationCategory[] WorkStages { get; } = new WellOperationCategory[]{ + new() { Id = WellOperationCategory.IdDrilling, Name = "БУРЕНИЕ", KeyValueName = "dT", KeyValueUnits = "м/ч" }, + new() { Id = WellOperationCategory.IdSPOStage, Name = "СПО", KeyValueName = "dT", KeyValueUnits = "мин" }, + new() { Id = WellOperationCategory.IdFastening, Name = "КРЕПЛЕНИЕ", KeyValueName = "dT", KeyValueUnits = "мин" }, + new() { Id = WellOperationCategory.IdGFR, Name = "ГФР", KeyValueName = "dT", KeyValueUnits = "мин" }, + new() { Id = WellOperationCategory.IdAuxiliaryOperations, Name = "Вспомогательные операции", KeyValueName = "dT", KeyValueUnits = "мин" }, + new() { Id = WellOperationCategory.IdNonProductiveTime, Name = "Непроизводительное время (НПВ)", KeyValueName = "dT", KeyValueUnits = "мин" }, + }; - // Виды работ - new () {Id = WellOperationCategory.Knbk, IdParent = 3000, Name = "КНБК", KeyValueName = "dT", KeyValueUnits = "мин" }, + /// + /// Виды работ + /// + public static WellOperationCategory[] WorkTypes { get; } = new WellOperationCategory[]{ + new () {Id = WellOperationCategory.IdKnbk, IdParent = 3000, Name = "КНБК", KeyValueName = "dT", KeyValueUnits = "мин" }, new () {Id = WellOperationCategory.IdMechanicalDrilling, IdParent = 3000, Name = "Механическое. бурение", KeyValueName = "dT", KeyValueUnits = "м/ч" }, - new () {Id = WellOperationCategory.MeasurementStat, IdParent = 3000, Name = "Статический замер", KeyValueName = "dT", KeyValueUnits = "мин" }, - new () {Id = WellOperationCategory.NormalizedWellDiameter, IdParent = 3000, Name = "Нормализация диаметра скважины", KeyValueName = "dT", KeyValueUnits = "мин" }, - new () {Id = WellOperationCategory.Building, IdParent = 3000, Name = "Наращивание", KeyValueName = "dT", KeyValueUnits = "мин" }, - new () {Id = WellOperationCategory.SPO , IdParent = 3001, Name = "СПО", KeyValueName = "dT", KeyValueUnits = "мин" }, - new () {Id = WellOperationCategory.CasingRunning, IdParent = 3002, Name = "Спуск обсадной колонны", KeyValueName = "dT", KeyValueUnits = "мин" }, - new () {Id = WellOperationCategory.Cementing, IdParent = 3002, Name = "Цементирование", KeyValueName = "dT", KeyValueUnits = "мин" }, - new () {Id = WellOperationCategory.AuxiliaryWorkFastening, IdParent = 3002, Name = "Вспомогательные работы при креплении", KeyValueName = "dT", KeyValueUnits = "мин" }, - new () {Id = WellOperationCategory.AssemblyOrDisassemblyGIS, IdParent = 3003, Name = "Сборка/разборка приборов ГИС", KeyValueName = "dT", KeyValueUnits = "мин" }, - new () {Id = WellOperationCategory.SPO2, IdParent = 3003, Name = "СПО", KeyValueName = "dT", KeyValueUnits = "мин" }, - new () {Id = WellOperationCategory.GIS, IdParent = 3003, Name = "ГИС", KeyValueName = "dT", KeyValueUnits = "мин" }, - new () {Id = WellOperationCategory.FlushingOBR, IdParent = 3004, Name = "Промывка, ОБР", KeyValueName = "dT", KeyValueUnits = "мин" }, - new () {Id = WellOperationCategory.AuxiliaryWork, IdParent = 3004, Name = "Вспомогательные работы", KeyValueName = "dT", KeyValueUnits = "мин" }, - new () {Id = WellOperationCategory.EquipmentRepair, IdParent = 3005, Name = "Ремонт оборудования", KeyValueName = "dT", KeyValueUnits = "мин" }, - new () {Id = WellOperationCategory.EmergencyWork, IdParent = 3005, Name = "Аварийные работы", KeyValueName = "dT", KeyValueUnits = "мин" }, - new () {Id = WellOperationCategory.Complication, IdParent = 3005, Name = "Осложнение", KeyValueName = "dT", KeyValueUnits = "мин" }, - new () {Id = WellOperationCategory.OperationsNotIncludedGGD, IdParent = 3005, Name = "Незаложенные в ГГД операции", KeyValueName = "dT", KeyValueUnits = "мин" }, + new () {Id = WellOperationCategory.IdMeasurementStat, IdParent = 3000, Name = "Статический замер", KeyValueName = "dT", KeyValueUnits = "мин" }, + new () {Id = WellOperationCategory.IdNormalizedWellDiameter, IdParent = 3000, Name = "Нормализация диаметра скважины", KeyValueName = "dT", KeyValueUnits = "мин" }, + new () {Id = WellOperationCategory.IdBuilding, IdParent = 3000, Name = "Наращивание", KeyValueName = "dT", KeyValueUnits = "мин" }, + new () {Id = WellOperationCategory.IdSPO , IdParent = 3001, Name = "СПО", KeyValueName = "dT", KeyValueUnits = "мин" }, + new () {Id = WellOperationCategory.IdCasingRunning, IdParent = 3002, Name = "Спуск обсадной колонны", KeyValueName = "dT", KeyValueUnits = "мин" }, + new () {Id = WellOperationCategory.IdCementing, IdParent = 3002, Name = "Цементирование", KeyValueName = "dT", KeyValueUnits = "мин" }, + new () {Id = WellOperationCategory.IdAuxiliaryWorkFastening, IdParent = 3002, Name = "Вспомогательные работы при креплении", KeyValueName = "dT", KeyValueUnits = "мин" }, + new () {Id = WellOperationCategory.IdAssemblyOrDisassemblyGIS, IdParent = 3003, Name = "Сборка/разборка приборов ГИС", KeyValueName = "dT", KeyValueUnits = "мин" }, + new () {Id = WellOperationCategory.IdSPO2, IdParent = 3003, Name = "СПО", KeyValueName = "dT", KeyValueUnits = "мин" }, + new () {Id = WellOperationCategory.IdGIS, IdParent = 3003, Name = "ГИС", KeyValueName = "dT", KeyValueUnits = "мин" }, + new () {Id = WellOperationCategory.IdFlushingOBR, IdParent = 3004, Name = "Промывка, ОБР", KeyValueName = "dT", KeyValueUnits = "мин" }, + new () {Id = WellOperationCategory.IdAuxiliaryWork, IdParent = 3004, Name = "Вспомогательные работы", KeyValueName = "dT", KeyValueUnits = "мин" }, + new () {Id = WellOperationCategory.IdEquipmentRepair, IdParent = 3005, Name = "Ремонт оборудования", KeyValueName = "dT", KeyValueUnits = "мин" }, + new () {Id = WellOperationCategory.IdEmergencyWork, IdParent = 3005, Name = "Аварийные работы", KeyValueName = "dT", KeyValueUnits = "мин" }, + new () {Id = WellOperationCategory.IdComplication, IdParent = 3005, Name = "Осложнение", KeyValueName = "dT", KeyValueUnits = "мин" }, + new () {Id = WellOperationCategory.IdOperationsNotIncludedGGD, IdParent = 3005, Name = "Незаложенные в ГГД операции", KeyValueName = "dT", KeyValueUnits = "мин" }, + }; - //переименованные категории с новым ИД - new () {Id = WellOperationCategory.IdBhaDisassembly, IdParent = 4000, Name = "Разборка КНБК", KeyValueName = "dT", KeyValueUnits = "мин" }, + /// + /// Категории работ + /// + public static WellOperationCategory[] WorkCategories { get; } = new WellOperationCategory[]{ + new () {Id = WellOperationCategory.IdBhaDisassembly, IdParent = 4000, Name = "Разборка КНБК", KeyValueName = "dT", KeyValueUnits = "мин" }, new () {Id = WellOperationCategory.IdBhaAssembly, IdParent = 4000, Name = "Сборка КНБК", KeyValueName = "dT", KeyValueUnits = "мин" }, new () {Id = WellOperationCategory.IdSlide, IdParent = 4001, Name = "Бурение слайдом", KeyValueName = "МСП", KeyValueUnits = "м/ч" }, new () {Id = WellOperationCategory.IdRotor, IdParent = 4001, Name = "Бурение ротором", KeyValueName = "МСП", KeyValueUnits = "м/ч" }, @@ -95,7 +102,7 @@ namespace AsbCloudDb.Model.DefaultData new () {Id = 5055, IdParent = 4013, Name = "Тех.отстой", KeyValueName = "dT", KeyValueUnits = "мин" }, new () {Id = 5056, IdParent = 4013, Name = "Учебная тревога \"Выброс\"", KeyValueName = "dT", KeyValueUnits = "мин" }, new () {Id = 5057, IdParent = 4013, Name = "Чистка ЦСГО/емкостного блока", KeyValueName = "dT", KeyValueUnits = "мин" }, - new () {Id = WellOperationCategory.IdEquipmentRepair, IdParent = 4014, Name = "Ремонт бурового оборудования", KeyValueName = "dT", KeyValueUnits = "мин" }, + new () {Id = WellOperationCategory.IdEquipmentDrillingRepair, IdParent = 4014, Name = "Ремонт бурового оборудования", KeyValueName = "dT", KeyValueUnits = "мин" }, new () {Id = 5059, IdParent = 4015, Name = "Ловильные работы", KeyValueName = "dT", KeyValueUnits = "мин" }, new () {Id = 5060, IdParent = 4015, Name = "Ожидание", KeyValueName = "dT", KeyValueUnits = "мин" }, new () {Id = 5061, IdParent = 4015, Name = "Определение места прихвата и ЛМ", KeyValueName = "dT", KeyValueUnits = "мин" }, @@ -116,7 +123,7 @@ namespace AsbCloudDb.Model.DefaultData new () {Id = 5076, IdParent = 4017, Name = "НПВ / прочее", KeyValueName = "dT", KeyValueUnits = "мин" }, new () {Id = 5077, IdParent = 4017, Name = "Обработка раствора (несоответствие параметров)", KeyValueName = "dT", KeyValueUnits = "мин" }, new () {Id = 5078, IdParent = 4017, Name = "подъем ОК", KeyValueName = "dT", KeyValueUnits = "мин" }, - new () {Id = 5079, IdParent = 4017, Name = "Ревизия КНБК/инструмента/ЗТС", KeyValueName = "dT", KeyValueUnits = "мин" }, + new () {Id = 5079, IdParent = 4017, Name = "Ревизия КНБК/инструмента/ЗТС", KeyValueName = "dT", KeyValueUnits = "мин" }, new () {Id = 5082, IdParent = 4000, Name = "Сборка устройства ориентирования КО", KeyValueName = "dT", KeyValueUnits = "мин" }, new () {Id = 5083, IdParent = 4003, Name = "Проработка принудительная", KeyValueName = "dT", KeyValueUnits = "мин" }, new () {Id = 5084, IdParent = 4005, Name = "Шаблонировка подъем БИ, продувка", KeyValueName = "dT", KeyValueUnits = "мин" }, @@ -138,5 +145,8 @@ namespace AsbCloudDb.Model.DefaultData new () {Id = 5100, IdParent = 4013, Name = "Смена рабочего переводника ВСП", KeyValueName = "dT", KeyValueUnits = "мин" }, new () {Id = 5101, IdParent = 4014, Name = "Ремонт", KeyValueName = "dT", KeyValueUnits = "мин" }, }; + + public override WellOperationCategory[] GetData() + => WorkStages.Concat(WorkTypes).Concat(WorkCategories).ToArray(); } } diff --git a/AsbCloudDb/Model/WellOperationCategory.cs b/AsbCloudDb/Model/WellOperationCategory.cs index 297f7537..5262ad23 100644 --- a/AsbCloudDb/Model/WellOperationCategory.cs +++ b/AsbCloudDb/Model/WellOperationCategory.cs @@ -13,16 +13,122 @@ namespace AsbCloudDb.Model /// БУРЕНИЕ /// public const int IdDrilling = 3000; + + /// + /// СПО + /// + public const int IdSPOStage = 3001; + + /// + /// КРЕПЛЕНИЕ + /// + public const int IdFastening = 3002; + + /// + /// ГФР + /// + public const int IdGFR = 3003; + + /// + /// Вспомогательные операции + /// + public const int IdAuxiliaryOperations = 3004; + /// /// Непроизводительное время (НПВ) /// public const int IdNonProductiveTime = 3005; + /// + /// КНБК + /// + public const int IdKnbk = 4000; + /// /// Механическое. бурение /// public const int IdMechanicalDrilling = 4001; + /// + /// Статический замер + /// + public const int IdMeasurementStat = 4002; + + /// + /// Нормализация диаметра скважины + /// + public const int IdNormalizedWellDiameter = 4003; + + /// + /// Наращивание + /// + public const int IdBuilding = 4004; + + /// + /// СПО + /// + public const int IdSPO = 4005; + + /// + /// Спуск обсадной колонны + /// + public const int IdCasingRunning = 4006; + + /// + /// Цементирование + /// + public const int IdCementing = 4007; + + /// + /// Вспомогательные работы при креплении + /// + public const int IdAuxiliaryWorkFastening = 4008; + + /// + /// Сборка/разборка приборов ГИС + /// + public const int IdAssemblyOrDisassemblyGIS = 4009; + + /// + /// СПО2 + /// + public const int IdSPO2 = 4010; + + /// + /// ГИС + /// + public const int IdGIS = 4011; + + /// + /// Промывка, ОБР + /// + public const int IdFlushingOBR = 4012; + + /// + /// Вспомогательные работы + /// + public const int IdAuxiliaryWork = 4013; + + /// + /// Ремонт оборудования + /// + public const int IdEquipmentRepair = 4014; + + /// + /// Аварийные работы + /// + public const int IdEmergencyWork = 4015; + + /// + /// Осложнение + /// + public const int IdComplication = 4016; + + /// + /// Незаложенные в ГГД операции + /// + public const int IdOperationsNotIncludedGGD = 4017; + /// /// Разборка КНБК /// @@ -82,98 +188,13 @@ namespace AsbCloudDb.Model /// /// Ремонт бурового оборудования /// - public const int IdEquipmentRepair = 5058; - - /// - /// КНБК - /// - public const int Knbk = 4000; - - /// - /// СПО - /// - public const int SPO = 4005; - - /// - /// ГИС - /// - public const int GIS = 4011; - - /// - /// Статический замер - /// - public const int MeasurementStat = 4002; - - /// - /// Нормализация диаметра скважины - /// - public const int NormalizedWellDiameter = 4003; - - /// - /// Наращивание - /// - public const int Building = 4004; - - /// - /// Спуск обсадной колонны - /// - public const int CasingRunning = 4006; - - /// - /// Цементирование - /// - public const int Cementing = 4007; - - /// - /// Вспомогательные работы при креплении - /// - public const int AuxiliaryWorkFastening = 4008; - - /// - /// Сборка/разборка приборов ГИС - /// - public const int AssemblyOrDisassemblyGIS = 4009; - - /// - /// СПО2 - /// - public const int SPO2 = 4010; - - /// - /// Промывка, ОБР - /// - public const int FlushingOBR = 4012; - - /// - /// Вспомогательные работы - /// - public const int AuxiliaryWork = 4013; - - /// - /// Ремонт оборудования - /// - public const int EquipmentRepair = 4014; - - /// - /// Аварийные работы - /// - public const int EmergencyWork = 4015; - - /// - /// Осложнение - /// - public const int Complication = 4016; - - /// - /// Незаложенные в ГГД операции - /// - public const int OperationsNotIncludedGGD = 4017; + public const int IdEquipmentDrillingRepair = 5058; /// /// Список всех категорий НПВ /// public static readonly int[] NonProductiveTimeSubIds = { - IdEquipmentRepair, + IdEquipmentDrillingRepair, 5059, 5060, 5061, diff --git a/AsbCloudInfrastructure/Services/DailyReport/DailyReportBlocks/TimeBalanceBlock.cs b/AsbCloudInfrastructure/Services/DailyReport/DailyReportBlocks/TimeBalanceBlock.cs index 6447c33b..4fc9185a 100644 --- a/AsbCloudInfrastructure/Services/DailyReport/DailyReportBlocks/TimeBalanceBlock.cs +++ b/AsbCloudInfrastructure/Services/DailyReport/DailyReportBlocks/TimeBalanceBlock.cs @@ -7,15 +7,45 @@ using System.Linq; namespace AsbCloudInfrastructure.Services.DailyReport.DailyReportBlocks { + /// + /// Пострение баланса времени + /// class TimeBalanceBlock : BlockAbstract { - + /// + /// Начальная ячейка + /// public override CellAddress AddressBlockBegin { get; } - public Dictionary OperationsStatistics { get; set; } - public IEnumerable OperationCategories { get; set; } + + /// + /// Конечная ячейка + /// public override CellAddress AddressBlockEnd { get; } - public CellAddress Title { get { return AddressBlockBegin + (1, 3); } } + /// + /// Ячейка с заголовком + /// + private CellAddress Title { get { return AddressBlockBegin + (1, 3); } } + + /// + /// Статистика по операциям + /// + private Dictionary OperationsStatistics { get; } + + /// + /// Категории операций + /// + private IEnumerable OperationCategories { get; } + + /// + /// количество стобцов в таблице + /// + private readonly int CountColumns = 3; + + /// + /// количество категорий операций + /// + private int OperationCategoriesCount { get { return OperationCategories.Count(); } } public TimeBalanceBlock(CellAddress addressBlockBegin, TimeBalanceDto blockDto, IEnumerable operationCategories) @@ -25,7 +55,9 @@ namespace AsbCloudInfrastructure.Services.DailyReport.DailyReportBlocks OperationsStatistics = blockDto.OperationsStat; OperationCategories = operationCategories; - AddressBlockEnd = AddressBlockBegin + (7, 6); + var rowColumn = (CountColumns * 2) + (OperationCategoriesCount % CountColumns == 0 ? 0 : 2); + var cellColumn = OperationCategoriesCount % CountColumns; + AddressBlockEnd = AddressBlockBegin + (rowColumn, cellColumn); } public override void Draw(IXLWorksheet sheet) @@ -35,113 +67,27 @@ namespace AsbCloudInfrastructure.Services.DailyReport.DailyReportBlocks .Merge() .SetValue("БАЛАНС ВРЕМЕНИ"); - sheet.Cell(AddressBlockBegin + (2, 1)) - ._SetValue(GetCaption(WellOperationCategory.Knbk), true); + var rowColumn = 2; + var cellColumn = 1; + var rowsCountInColumn = OperationCategoriesCount / CountColumns; + if (OperationCategoriesCount % CountColumns != 0) + rowsCountInColumn++; - sheet.Cell(AddressBlockBegin + (3, 1)) - ._SetValue(GetCaption(WellOperationCategory.IdMechanicalDrilling), true); + foreach (var operationCategory in OperationCategories) + { + sheet.Cell(AddressBlockBegin + (rowColumn, cellColumn)) + ._SetValue(GetCaption(operationCategory.Id), true); + sheet.Cell(AddressBlockBegin + (rowColumn, cellColumn + 1)) + ._SetValue(GetValue(operationCategory.Id), true); - sheet.Cell(AddressBlockBegin + (4, 1)) - ._SetValue(GetCaption(WellOperationCategory.MeasurementStat), true); - - sheet.Cell(AddressBlockBegin + (5, 1)) - ._SetValue(GetCaption(WellOperationCategory.NormalizedWellDiameter), true); - - sheet.Cell(AddressBlockBegin + (6, 1)) - ._SetValue(GetCaption(WellOperationCategory.Building), true); - - sheet.Cell(AddressBlockBegin + (7, 1)) - ._SetValue(GetValue(WellOperationCategory.SPO), true); - - sheet.Cell(AddressBlockBegin + (2, 2)) - ._SetValue(GetValue(WellOperationCategory.Knbk)); - - sheet.Cell(AddressBlockBegin + (3, 2)) - ._SetValue(GetValue(WellOperationCategory.IdMechanicalDrilling)); - - sheet.Cell(AddressBlockBegin + (4, 2)) - ._SetValue(GetValue(WellOperationCategory.MeasurementStat)); - - sheet.Cell(AddressBlockBegin + (5, 2)) - ._SetValue(GetValue(WellOperationCategory.NormalizedWellDiameter)); - - sheet.Cell(AddressBlockBegin + (6, 2)) - ._SetValue(GetValue(WellOperationCategory.Building)); - - sheet.Cell(AddressBlockBegin + (7, 2)) - ._SetValue(GetValue(WellOperationCategory.SPO)); - - sheet.Cell(AddressBlockBegin + (2, 3)) - ._SetValue(GetCaption(WellOperationCategory.CasingRunning)); - - sheet.Cell(AddressBlockBegin + (3, 3)) - ._SetValue(GetCaption(WellOperationCategory.Cementing)); - - sheet.Cell(AddressBlockBegin + (4, 3)) - ._SetValue(GetCaption(WellOperationCategory.AuxiliaryWorkFastening)); - - sheet.Cell(AddressBlockBegin + (5, 3)) - ._SetValue(GetCaption(WellOperationCategory.AssemblyOrDisassemblyGIS)); - - sheet.Cell(AddressBlockBegin + (6, 3)) - ._SetValue(GetCaption(WellOperationCategory.SPO2)); - - sheet.Cell(AddressBlockBegin + (7, 3)) - ._SetValue(GetCaption(WellOperationCategory.GIS)); - - sheet.Cell(AddressBlockBegin + (2, 4)) - ._SetValue(GetValue(WellOperationCategory.CasingRunning)); - - sheet.Cell(AddressBlockBegin + (3, 4)) - ._SetValue(GetValue(WellOperationCategory.Cementing)); - - sheet.Cell(AddressBlockBegin + (4, 4)) - ._SetValue(GetValue(WellOperationCategory.AuxiliaryWorkFastening)); - - sheet.Cell(AddressBlockBegin + (5, 4)) - ._SetValue(GetValue(WellOperationCategory.AssemblyOrDisassemblyGIS)); - - sheet.Cell(AddressBlockBegin + (6, 4)) - ._SetValue(GetValue(WellOperationCategory.SPO2)); - - sheet.Cell(AddressBlockBegin + (7, 4)) - ._SetValue(GetValue(WellOperationCategory.GIS)); - - sheet.Cell(AddressBlockBegin + (2, 5)) - ._SetValue(GetCaption(WellOperationCategory.FlushingOBR)); - - sheet.Cell(AddressBlockBegin + (3, 5)) - ._SetValue(GetCaption(WellOperationCategory.AuxiliaryWork)); - - sheet.Cell(AddressBlockBegin + (4, 5)) - ._SetValue(GetCaption(WellOperationCategory.EquipmentRepair)); - - sheet.Cell(AddressBlockBegin + (5, 5)) - ._SetValue(GetCaption(WellOperationCategory.EmergencyWork)); - - sheet.Cell(AddressBlockBegin + (6, 5)) - ._SetValue(GetCaption(WellOperationCategory.Complication)); - - sheet.Cell(AddressBlockBegin + (7, 5)) - ._SetValue(GetCaption(WellOperationCategory.OperationsNotIncludedGGD)); - - sheet.Cell(AddressBlockBegin + (2, 6)) - ._SetValue(GetValue(WellOperationCategory.FlushingOBR)); - - sheet.Cell(AddressBlockBegin + (3, 6)) - ._SetValue(GetValue(WellOperationCategory.AuxiliaryWork)); - - sheet.Cell(AddressBlockBegin + (4, 6)) - ._SetValue(GetValue(WellOperationCategory.EquipmentRepair)); - - sheet.Cell(AddressBlockBegin + (5, 6)) - ._SetValue(GetValue(WellOperationCategory.EmergencyWork)); - - sheet.Cell(AddressBlockBegin + (6, 6)) - ._SetValue(GetValue(WellOperationCategory.Complication)); - - sheet.Cell(AddressBlockBegin + (7, 6)) - ._SetValue(GetValue(WellOperationCategory.OperationsNotIncludedGGD)); + if (rowColumn <= rowsCountInColumn) + rowColumn++; + else + { + rowColumn = 2; + cellColumn = cellColumn + 2; + } + } } private string GetValue(int categoryId) diff --git a/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs b/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs index 43451215..cd72197c 100644 --- a/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs +++ b/AsbCloudInfrastructure/Services/DailyReport/DailyReportService.cs @@ -6,6 +6,7 @@ using AsbCloudApp.Requests; using AsbCloudApp.Services; using AsbCloudDb.Model; using AsbCloudDb.Model.DailyReport; +using AsbCloudDb.Model.DefaultData; using Mapster; using Microsoft.EntityFrameworkCore; using System; @@ -65,13 +66,9 @@ namespace AsbCloudInfrastructure.Services.DailyReport .ConfigureAwait(false); var factOperationsForDtos = await GetFactOperationsForDailyReportAsync(idWell, token); + var userDtos = await userRepository.GetAllAsync(token); - var dtos = new List(entities.Length); - foreach (var entity in entities) - { - var dto = await Convert(entity, factOperationsForDtos, token); - dtos.Add(dto); - } + var dtos = entities.Select(entity => Convert(entity, factOperationsForDtos, userDtos)); return dtos; } @@ -93,36 +90,7 @@ namespace AsbCloudInfrastructure.Services.DailyReport return factOperations; } - /// - /// Заполнение DTO-модели данными о пользователях - /// - /// - /// - /// - private async Task SetUserNamesToDailyReportDtoAsync(DailyReportDto dto, CancellationToken token) - { - var blocks = new ItemInfoDto[] { - dto.Head, - dto.Bha, - dto.NoDrilling, - dto.TimeBalance, - dto.Saub, - dto.Sign - }; - - foreach (var block in blocks) - { - if (block.IdUser is not null) - { - var user = await userRepository.GetOrDefaultAsync(block.IdUser.Value, token); - block.UserName = user is not null ? user.MakeDisplayName() : $"userId:{block.IdUser.Value}"; - } - } - - return dto; - } - - public async Task AddAsync(int idWell, DateTime startDate, int idUser, CancellationToken token = default) + public async Task AddAsync(int idWell, DateTime startDate, int idUser, CancellationToken token) { var well = wellService.GetOrDefault(idWell); if (well is null) @@ -178,9 +146,12 @@ namespace AsbCloudInfrastructure.Services.DailyReport return result; } - public async Task MakeReportAsync(int idWell, DateTime date, CancellationToken token = default) + public async Task MakeReportAsync(int idWell, DateTime date, CancellationToken token) { - var wellOperationCategories = wellOperationRepository.GetCategories(true); + var stageIds = EntityFillerWellOperationCategory.WorkStages.Select(w => w.Id).ToArray(); + var wellOperationCategories = wellOperationRepository.GetCategories(true) + .Where(o => o.IdParent is not null) + .Where(o => stageIds.Contains(o.IdParent!.Value)); var dailyReportDto = await GetOrDefaultAsync(idWell, date, token); if (dailyReportDto is null) @@ -204,7 +175,8 @@ namespace AsbCloudInfrastructure.Services.DailyReport throw new ArgumentInvalidException("Daily report doesn`t exist", nameof(date)); var factOperationsForDtos = await GetFactOperationsForDailyReportAsync(idWell, token); - var dto = await Convert(entity, factOperationsForDtos, token); + var userDtos = await userRepository.GetAllAsync(token); + var dto = Convert(entity, factOperationsForDtos, userDtos); return dto; } @@ -213,12 +185,12 @@ namespace AsbCloudInfrastructure.Services.DailyReport /// /// модель базы данных /// список фактичских операций для формирования суточного рапорта - /// + /// список пользователей для нахождения последнего изменившего запись /// - private async Task Convert( + private DailyReportDto Convert( AsbCloudDb.Model.DailyReport.DailyReport entity, IEnumerable factOperationsForDtos, - CancellationToken token) + IEnumerable users) { var dto = entity.Info.Adapt(); dto.StartDate = entity.StartDate; @@ -231,7 +203,23 @@ namespace AsbCloudInfrastructure.Services.DailyReport dto.TimeBalance.OperationsStat = dailyFactOperation; - await SetUserNamesToDailyReportDtoAsync(dto, token); + var blocks = new ItemInfoDto[] { + dto.Head, + dto.Bha, + dto.NoDrilling, + dto.TimeBalance, + dto.Saub, + dto.Sign + }; + + foreach (var block in blocks) + { + if (block.IdUser is not null) + { + var user = users.FirstOrDefault(u => u.Id == block.IdUser.Value); + block.UserName = user is not null ? user.MakeDisplayName() : $"userId:{block.IdUser.Value}"; + } + } return dto; } diff --git a/AsbCloudWebApi/Controllers/DailyReportController.cs b/AsbCloudWebApi/Controllers/DailyReportController.cs index 0c5cfc38..7d508ceb 100644 --- a/AsbCloudWebApi/Controllers/DailyReportController.cs +++ b/AsbCloudWebApi/Controllers/DailyReportController.cs @@ -1,5 +1,4 @@ using AsbCloudApp.Data.DailyReport; -using AsbCloudApp.Exceptions; using AsbCloudApp.Repositories; using AsbCloudApp.Services; using Microsoft.AspNetCore.Authorization; @@ -45,7 +44,7 @@ namespace AsbCloudWebApi.Controllers [HttpGet] //[Permission] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] - public async Task GetListAsync(int idWell, DateTime? begin = null, DateTime? end = null, CancellationToken token = default) + public async Task GetListAsync(int idWell, DateTime? begin, DateTime? end, CancellationToken token) { var result = await dailyReportService.GetListAsync(idWell, begin, end, token); return Ok(result); @@ -61,21 +60,14 @@ namespace AsbCloudWebApi.Controllers [HttpPost] //[Permission] [ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)] - public async Task AddAsync(int idWell, [Required] DateTime startDate, CancellationToken token = default) + public async Task AddAsync(int idWell, [Required] DateTime startDate, CancellationToken token) { var idUser = User.GetUserId(); if (idUser is null) return Forbid(); - try - { - var result = await dailyReportService.AddAsync(idWell, startDate, (int)idUser, token); - return Ok(result); - } - catch (ArgumentInvalidException ex) - { - return BadRequest(ex.Message); - } + var result = await dailyReportService.AddAsync(idWell, startDate, (int)idUser, token); + return Ok(result); } /// @@ -88,10 +80,8 @@ namespace AsbCloudWebApi.Controllers /// [HttpPut("{date}/head")] [ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)] - public async Task UpdateHeadAsync(int idWell, [Required] DateTime date, [Required] HeadDto dto, CancellationToken token = default) - { - return await UpdateReportBlockAsync(idWell, date, dto, token); - } + public Task UpdateHeadAsync(int idWell, [Required] DateTime date, [Required] HeadDto dto, CancellationToken token) + => UpdateReportBlockAsync(idWell, date, dto, token); /// /// Сохранение изменений набора данных для формирования рапорта (блок КНБК) @@ -103,10 +93,8 @@ namespace AsbCloudWebApi.Controllers /// [HttpPut("{date}/bha")] [ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)] - public async Task UpdateBhaAsync(int idWell, [Required] DateTime date, [Required] BhaDto dto, CancellationToken token = default) - { - return await UpdateReportBlockAsync(idWell, date, dto, token); - } + public Task UpdateBhaAsync(int idWell, [Required] DateTime date, [Required] BhaDto dto, CancellationToken token) + => UpdateReportBlockAsync(idWell, date, dto, token); /// /// Сохранение изменений набора данных для формирования рапорта (безметражные работы) @@ -118,10 +106,8 @@ namespace AsbCloudWebApi.Controllers /// [HttpPut("{date}/noDrilling")] [ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)] - public async Task UpdateNoDrillingAsync(int idWell, [Required] DateTime date, [Required] NoDrillingDto dto, CancellationToken token = default) - { - return await UpdateReportBlockAsync(idWell, date, dto, token); - } + public Task UpdateNoDrillingAsync(int idWell, [Required] DateTime date, [Required] NoDrillingDto dto, CancellationToken token) + => UpdateReportBlockAsync(idWell, date, dto, token); /// /// Сохранение изменений набора данных для формирования рапорта (САУБ) @@ -133,10 +119,8 @@ namespace AsbCloudWebApi.Controllers /// [HttpPut("{date}/saub")] [ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)] - public async Task UpdateSaubAsync(int idWell, [Required] DateTime date, [Required] SaubDto dto, CancellationToken token = default) - { - return await UpdateReportBlockAsync(idWell, date, dto, token); - } + public Task UpdateSaubAsync(int idWell, [Required] DateTime date, [Required] SaubDto dto, CancellationToken token) + => UpdateReportBlockAsync(idWell, date, dto, token); /// /// Сохранение изменений набора данных для формирования рапорта (подпись) @@ -148,10 +132,8 @@ namespace AsbCloudWebApi.Controllers /// [HttpPut("{date}/sign")] [ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)] - public async Task UpdateSignAsync(int idWell, [Required] DateTime date, [Required] SignDto dto, CancellationToken token = default) - { - return await UpdateReportBlockAsync(idWell, date, dto, token); - } + public Task UpdateSignAsync(int idWell, [Required] DateTime date, [Required] SignDto dto, CancellationToken token) + => UpdateReportBlockAsync(idWell, date, dto, token); /// /// Обновление блока суточного рапорта @@ -163,29 +145,15 @@ namespace AsbCloudWebApi.Controllers /// private async Task UpdateReportBlockAsync(int idWell, DateTime date, ItemInfoDto dto, CancellationToken token) { - if (!SetEditorIdToDailyReportBlock(dto)) + if (!await UserHasAccesToWellAsync(idWell, token)) return Forbid(); + dto.IdUser = User.GetUserId(); + var result = await dailyReportService.UpdateBlockAsync(idWell, date, dto, token); return Ok(result); } - /// - /// Записать ключ пользователя, вносящего изменения в блок суточного рапорта - /// - /// - /// - private bool SetEditorIdToDailyReportBlock(ItemInfoDto dto) - { - var idUser = User.GetUserId(); - if (idUser is null) - return false; - else - dto.IdUser = idUser; - - return true; - } - /// /// Сформировать и скачать рапорт в формате excel /// @@ -196,7 +164,7 @@ namespace AsbCloudWebApi.Controllers [HttpGet("{date}/excel")] //[Permission] [ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)] - public async Task DownloadAsync(int idWell, DateTime date, CancellationToken token = default) + public async Task DownloadAsync(int idWell, DateTime date, CancellationToken token) { var well = await wellService.GetOrDefaultAsync(idWell, token); var stream = await dailyReportService.MakeReportAsync(idWell, date, token); @@ -208,5 +176,15 @@ namespace AsbCloudWebApi.Controllers else return NoContent(); } + + protected async Task UserHasAccesToWellAsync(int idWell, CancellationToken token) + { + var idCompany = User.GetCompanyId(); + if (idCompany is not null && + await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token) + .ConfigureAwait(false)) + return true; + return false; + } } }