diff --git a/AsbCloudApp/Repositories/IDailyReportRepository.cs b/AsbCloudApp/Repositories/IDailyReportRepository.cs index e9a20d2c..6e59941d 100644 --- a/AsbCloudApp/Repositories/IDailyReportRepository.cs +++ b/AsbCloudApp/Repositories/IDailyReportRepository.cs @@ -26,17 +26,8 @@ public interface IDailyReportRepository : ICrudRepository /// Получить суточный отчёт /// /// - /// + /// /// /// - Task GetOrDefaultAsync(int idWell, DateTime dateStart, CancellationToken cancellationToken); - - /// - /// Проверка существование суточного отчёта - /// - /// - /// - /// - /// - Task AnyAsync(int idWell, DateTime dateStart, CancellationToken cancellationToken); + Task GetOrDefaultAsync(int idWell, DateTime date, CancellationToken cancellationToken); } \ No newline at end of file diff --git a/AsbCloudDb/Migrations/20231103095402_Update_DailyReport.Designer.cs b/AsbCloudDb/Migrations/20231114051111_Update_DailyReport.Designer.cs similarity index 98% rename from AsbCloudDb/Migrations/20231103095402_Update_DailyReport.Designer.cs rename to AsbCloudDb/Migrations/20231114051111_Update_DailyReport.Designer.cs index afe2ed3a..23c75c4b 100644 --- a/AsbCloudDb/Migrations/20231103095402_Update_DailyReport.Designer.cs +++ b/AsbCloudDb/Migrations/20231114051111_Update_DailyReport.Designer.cs @@ -13,7 +13,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace AsbCloudDb.Migrations { [DbContext(typeof(AsbCloudDbContext))] - [Migration("20231103095402_Update_DailyReport")] + [Migration("20231114051111_Update_DailyReport")] partial class Update_DailyReport { protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -122,7 +122,8 @@ namespace AsbCloudDb.Migrations .HasColumnName("caption"); b.Property("IsContact") - .HasColumnType("boolean"); + .HasColumnType("boolean") + .HasColumnName("is_contact"); b.Property("Order") .HasColumnType("integer") @@ -136,23 +137,72 @@ namespace AsbCloudDb.Migrations new { Id = 1, - Caption = "Недрапользователь", - IsContact = false, - Order = 1 + Caption = "Недропользователь", + IsContact = true, + Order = 3 }, new { Id = 2, Caption = "Буровой подрядчик", - IsContact = false, + IsContact = true, Order = 2 }, new { Id = 3, Caption = "Сервис автоматизации бурения", - IsContact = false, + IsContact = true, Order = 0 + }, + new + { + Id = 4, + Caption = "Сервис по ГТИ", + IsContact = true, + Order = 6 + }, + new + { + Id = 5, + Caption = "Растворный сервис", + IsContact = true, + Order = 4 + }, + new + { + Id = 6, + Caption = "Сервис по ННБ", + IsContact = true, + Order = 5 + }, + new + { + Id = 7, + Caption = "Служба супервайзинга", + IsContact = false, + Order = 1 + }, + new + { + Id = 9, + Caption = "Сервис по цементированию", + IsContact = true, + Order = 7 + }, + new + { + Id = 11, + Caption = "Дизельный сервис", + IsContact = false, + Order = 9 + }, + new + { + Id = 12, + Caption = "Сервис по обслуживанию верхних силовых приводов", + IsContact = true, + Order = 8 }); }); @@ -223,7 +273,7 @@ namespace AsbCloudDb.Migrations b.HasComment("Контакты"); }); - modelBuilder.Entity("AsbCloudDb.Model.DailyReport", b => + modelBuilder.Entity("AsbCloudDb.Model.DailyReports.DailyReport", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -231,34 +281,39 @@ namespace AsbCloudDb.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - b.Property("Blocks") - .HasColumnType("jsonb") - .HasColumnName("blocks") - .HasComment("Блоки использующиеся в отчёте"); - - b.Property("DateEnd") + b.Property("Date") .HasColumnType("timestamp with time zone") - .HasColumnName("date_end") - .HasComment("Конечная дата отчёта"); + .HasColumnName("date") + .HasComment("Дата формирования отчёта"); b.Property("DateLastUpdate") .HasColumnType("timestamp with time zone") .HasColumnName("date_last_update") .HasComment("Дата последнего обновления"); - b.Property("DateStart") - .HasColumnType("timestamp with time zone") - .HasColumnName("date_start") - .HasComment("Начальная дата отчёта"); - b.Property("IdWell") .HasColumnType("integer") .HasColumnName("id_well") .HasComment("ID скважины"); + b.Property("SignBlock") + .HasColumnType("jsonb") + .HasColumnName("sign_block") + .HasComment("Подпись"); + + b.Property("SubsystemBlock") + .HasColumnType("jsonb") + .HasColumnName("subsystem_block") + .HasComment("Наработкой подсистем"); + + b.Property("TimeBalanceBlock") + .HasColumnType("jsonb") + .HasColumnName("time_balance_block") + .HasComment("Баланс времени"); + b.HasKey("Id"); - b.HasIndex("IdWell", "DateStart") + b.HasIndex("IdWell", "Date") .IsUnique(); b.ToTable("t_daily_report"); @@ -4598,14 +4653,14 @@ namespace AsbCloudDb.Migrations new { Id = 65536, - Description = "Spin master", - Name = "Spin master" + Description = "Осцилляция", + Name = "Осцилляция" }, new { Id = 65537, - Description = "Torque master", - Name = "Torque master" + Description = "Демпфер", + Name = "Демпфер" }); }); @@ -7089,6 +7144,36 @@ namespace AsbCloudDb.Migrations Id = 33, Caption = "Техническая колонна 3", Order = 2.2f + }, + new + { + Id = 34, + Caption = "Хвостовик 6", + Order = 6.5f + }, + new + { + Id = 35, + Caption = "Хвостовик 7", + Order = 6.6f + }, + new + { + Id = 36, + Caption = "Хвостовик 8", + Order = 6.7f + }, + new + { + Id = 37, + Caption = "Хвостовик 9", + Order = 6.8f + }, + new + { + Id = 38, + Caption = "Хвостовик 10", + Order = 6.9f }); }); @@ -7864,7 +7949,7 @@ namespace AsbCloudDb.Migrations b.Navigation("Well"); }); - modelBuilder.Entity("AsbCloudDb.Model.DailyReport", b => + modelBuilder.Entity("AsbCloudDb.Model.DailyReports.DailyReport", b => { b.HasOne("AsbCloudDb.Model.Well", "Well") .WithMany() diff --git a/AsbCloudDb/Migrations/20231103095402_Update_DailyReport.cs b/AsbCloudDb/Migrations/20231114051111_Update_DailyReport.cs similarity index 77% rename from AsbCloudDb/Migrations/20231103095402_Update_DailyReport.cs rename to AsbCloudDb/Migrations/20231114051111_Update_DailyReport.cs index bf44fb65..2f189844 100644 --- a/AsbCloudDb/Migrations/20231103095402_Update_DailyReport.cs +++ b/AsbCloudDb/Migrations/20231114051111_Update_DailyReport.cs @@ -30,20 +30,13 @@ namespace AsbCloudDb.Migrations defaultValue: 0) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - migrationBuilder.AddColumn( - name: "blocks", - table: "t_daily_report", - type: "jsonb", - nullable: true, - comment: "Блоки использующиеся в отчёте"); - migrationBuilder.AddColumn( - name: "date_end", + name: "date", table: "t_daily_report", type: "timestamp with time zone", nullable: false, defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), - comment: "Конечная дата отчёта"); + comment: "Дата формирования отчёта"); migrationBuilder.AddColumn( name: "date_last_update", @@ -52,13 +45,26 @@ namespace AsbCloudDb.Migrations nullable: true, comment: "Дата последнего обновления"); - migrationBuilder.AddColumn( - name: "date_start", + migrationBuilder.AddColumn( + name: "sign_block", table: "t_daily_report", - type: "timestamp with time zone", - nullable: false, - defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), - comment: "Начальная дата отчёта"); + type: "jsonb", + nullable: true, + comment: "Подпись"); + + migrationBuilder.AddColumn( + name: "subsystem_block", + table: "t_daily_report", + type: "jsonb", + nullable: true, + comment: "Наработкой подсистем"); + + migrationBuilder.AddColumn( + name: "time_balance_block", + table: "t_daily_report", + type: "jsonb", + nullable: true, + comment: "Баланс времени"); migrationBuilder.AddPrimaryKey( name: "PK_t_daily_report", @@ -66,9 +72,9 @@ namespace AsbCloudDb.Migrations column: "Id"); migrationBuilder.CreateIndex( - name: "IX_t_daily_report_id_well_date_start", + name: "IX_t_daily_report_id_well_date", table: "t_daily_report", - columns: new[] { "id_well", "date_start" }, + columns: new[] { "id_well", "date" }, unique: true); } @@ -79,19 +85,15 @@ namespace AsbCloudDb.Migrations table: "t_daily_report"); migrationBuilder.DropIndex( - name: "IX_t_daily_report_id_well_date_start", + name: "IX_t_daily_report_id_well_date", table: "t_daily_report"); - + migrationBuilder.DropColumn( name: "Id", table: "t_daily_report"); migrationBuilder.DropColumn( - name: "blocks", - table: "t_daily_report"); - - migrationBuilder.DropColumn( - name: "date_end", + name: "date", table: "t_daily_report"); migrationBuilder.DropColumn( @@ -99,7 +101,15 @@ namespace AsbCloudDb.Migrations table: "t_daily_report"); migrationBuilder.DropColumn( - name: "date_start", + name: "sign_block", + table: "t_daily_report"); + + migrationBuilder.DropColumn( + name: "subsystem_block", + table: "t_daily_report"); + + migrationBuilder.DropColumn( + name: "time_balance_block", table: "t_daily_report"); migrationBuilder.AddColumn( diff --git a/AsbCloudDb/Migrations/AsbCloudDbContextModelSnapshot.cs b/AsbCloudDb/Migrations/AsbCloudDbContextModelSnapshot.cs index 5792ca46..23bd3d30 100644 --- a/AsbCloudDb/Migrations/AsbCloudDbContextModelSnapshot.cs +++ b/AsbCloudDb/Migrations/AsbCloudDbContextModelSnapshot.cs @@ -264,7 +264,7 @@ namespace AsbCloudDb.Migrations b.HasComment("Контакты"); }); - modelBuilder.Entity("AsbCloudDb.Model.DailyReport", b => + modelBuilder.Entity("AsbCloudDb.Model.DailyReports.DailyReport", b => { b.Property("Id") .ValueGeneratedOnAdd() @@ -272,34 +272,39 @@ namespace AsbCloudDb.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - b.Property("Blocks") - .HasColumnType("jsonb") - .HasColumnName("blocks") - .HasComment("Блоки использующиеся в отчёте"); - - b.Property("DateEnd") + b.Property("Date") .HasColumnType("timestamp with time zone") - .HasColumnName("date_end") - .HasComment("Конечная дата отчёта"); + .HasColumnName("date") + .HasComment("Дата формирования отчёта"); b.Property("DateLastUpdate") .HasColumnType("timestamp with time zone") .HasColumnName("date_last_update") .HasComment("Дата последнего обновления"); - b.Property("DateStart") - .HasColumnType("timestamp with time zone") - .HasColumnName("date_start") - .HasComment("Начальная дата отчёта"); - b.Property("IdWell") .HasColumnType("integer") .HasColumnName("id_well") .HasComment("ID скважины"); + b.Property("SignBlock") + .HasColumnType("jsonb") + .HasColumnName("sign_block") + .HasComment("Подпись"); + + b.Property("SubsystemBlock") + .HasColumnType("jsonb") + .HasColumnName("subsystem_block") + .HasComment("Наработкой подсистем"); + + b.Property("TimeBalanceBlock") + .HasColumnType("jsonb") + .HasColumnName("time_balance_block") + .HasComment("Баланс времени"); + b.HasKey("Id"); - b.HasIndex("IdWell", "DateStart") + b.HasIndex("IdWell", "Date") .IsUnique(); b.ToTable("t_daily_report"); @@ -7935,7 +7940,7 @@ namespace AsbCloudDb.Migrations b.Navigation("Well"); }); - modelBuilder.Entity("AsbCloudDb.Model.DailyReport", b => + modelBuilder.Entity("AsbCloudDb.Model.DailyReports.DailyReport", b => { b.HasOne("AsbCloudDb.Model.Well", "Well") .WithMany() diff --git a/AsbCloudDb/Model/AsbCloudDbContext.cs b/AsbCloudDb/Model/AsbCloudDbContext.cs index f2c22eae..0016e981 100644 --- a/AsbCloudDb/Model/AsbCloudDbContext.cs +++ b/AsbCloudDb/Model/AsbCloudDbContext.cs @@ -3,6 +3,7 @@ using AsbCloudDb.Model.Subsystems; using Microsoft.EntityFrameworkCore; using System.Threading; using System.Threading.Tasks; +using AsbCloudDb.Model.DailyReports; using AsbCloudDb.Model.Manuals; using AsbCloudDb.Model.ProcessMaps; @@ -333,10 +334,16 @@ namespace AsbCloudDb.Model modelBuilder.Entity(entity => { - entity.HasIndex(e => new { e.IdWell, e.DateStart }) + entity.HasIndex(e => new { e.IdWell, e.Date }) .IsUnique(); - entity.Property(e => e.Blocks) + entity.Property(e => e.SubsystemBlock) + .HasJsonConversion(); + + entity.Property(e => e.SignBlock) + .HasJsonConversion(); + + entity.Property(e => e.TimeBalanceBlock) .HasJsonConversion(); }); diff --git a/AsbCloudDb/Model/DailyReport.cs b/AsbCloudDb/Model/DailyReport.cs deleted file mode 100644 index aca76f71..00000000 --- a/AsbCloudDb/Model/DailyReport.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using Microsoft.EntityFrameworkCore; - -namespace AsbCloudDb.Model; - -[Table("t_daily_report"), Comment("Ежедневные отчёты")] -public class DailyReport : IId -{ - [Key] - public int Id { get; set; } - - [Column("id_well"), Comment("ID скважины")] - public int IdWell { get; set; } - - [Column("date_last_update", TypeName = "timestamp with time zone"), Comment("Дата последнего обновления")] - public DateTime? DateLastUpdate { get; set; } - - [Column("date_start", TypeName = "timestamp with time zone"), Comment("Начальная дата отчёта")] - public DateTime DateStart { get; set; } - - [Column("date_end", TypeName = "timestamp with time zone"), Comment("Конечная дата отчёта")] - public DateTime DateEnd { get; set; } - - [Column("blocks", TypeName = "jsonb"), Comment("Блоки использующиеся в отчёте")] - public string? Blocks { get; set; } - - [ForeignKey(nameof(IdWell))] - public virtual Well Well { get; set; } = null!; -} \ No newline at end of file diff --git a/AsbCloudDb/Model/DailyReports/Blocks/Sign/SignBlock.cs b/AsbCloudDb/Model/DailyReports/Blocks/Sign/SignBlock.cs new file mode 100644 index 00000000..2e394f79 --- /dev/null +++ b/AsbCloudDb/Model/DailyReports/Blocks/Sign/SignBlock.cs @@ -0,0 +1,8 @@ +namespace AsbCloudDb.Model.DailyReports.Blocks.Sign; + +public class SignBlock : ItemInfo +{ + public SignRecord? DrillingMaster { get; set; } + + public SignRecord? Supervisor { get; set; } +} \ No newline at end of file diff --git a/AsbCloudDb/Model/DailyReports/Blocks/Sign/SignRecord.cs b/AsbCloudDb/Model/DailyReports/Blocks/Sign/SignRecord.cs new file mode 100644 index 00000000..9ea1119e --- /dev/null +++ b/AsbCloudDb/Model/DailyReports/Blocks/Sign/SignRecord.cs @@ -0,0 +1,10 @@ +namespace AsbCloudDb.Model.DailyReports.Blocks.Sign; + +public class SignRecord +{ + public string Name { get; set; } = null!; + + public string Surname { get; set; } = null!; + + public string? Patronymic { get; set; } +} \ No newline at end of file diff --git a/AsbCloudDb/Model/DailyReports/Blocks/Subsystem/SubsystemBlock.cs b/AsbCloudDb/Model/DailyReports/Blocks/Subsystem/SubsystemBlock.cs new file mode 100644 index 00000000..c63afc0f --- /dev/null +++ b/AsbCloudDb/Model/DailyReports/Blocks/Subsystem/SubsystemBlock.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; + +namespace AsbCloudDb.Model.DailyReports.Blocks.Subsystem; + +public class SubsystemBlock : ItemInfo +{ + public double? WellBore { get; set; } + + public double? MeasurementsPerDay { get; set; } + + public double? TotalRopPlan { get; set; } + + public string? Comment { get; set; } + + public IEnumerable? Subsystems { get; set; } +} \ No newline at end of file diff --git a/AsbCloudDb/Model/DailyReports/Blocks/Subsystem/SubsystemRecord.cs b/AsbCloudDb/Model/DailyReports/Blocks/Subsystem/SubsystemRecord.cs new file mode 100644 index 00000000..7464a842 --- /dev/null +++ b/AsbCloudDb/Model/DailyReports/Blocks/Subsystem/SubsystemRecord.cs @@ -0,0 +1,14 @@ +namespace AsbCloudDb.Model.DailyReports.Blocks.Subsystem; + +public class SubsystemRecord +{ + public string SubsystemName { get; set; } = null!; + + public int IdTimeInterval { get; set; } + + public double? SumDepthInterval { get; set; } + + public double? UsedTimeHours { get; set; } + + public double? KUsage { get; set; } +} \ No newline at end of file diff --git a/AsbCloudDb/Model/DailyReports/Blocks/TimeBalance/TimeBalanceBlock.cs b/AsbCloudDb/Model/DailyReports/Blocks/TimeBalance/TimeBalanceBlock.cs new file mode 100644 index 00000000..6af3a946 --- /dev/null +++ b/AsbCloudDb/Model/DailyReports/Blocks/TimeBalance/TimeBalanceBlock.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; + +namespace AsbCloudDb.Model.DailyReports.Blocks.TimeBalance; + +public class TimeBalanceBlock : ItemInfo +{ + public int IdSection { get; set; } + + public string? SectionName { get; set; } + + public double? WellDepthPlan { get; set; } + + public double WellDepthFact { get; set; } + + public double? WellOperationSlipsTimeCount { get; set; } + + public IEnumerable? WellOperations { get; set; } +} \ No newline at end of file diff --git a/AsbCloudDb/Model/DailyReports/Blocks/TimeBalance/TimeBalanceRecord.cs b/AsbCloudDb/Model/DailyReports/Blocks/TimeBalance/TimeBalanceRecord.cs new file mode 100644 index 00000000..5c08ab8c --- /dev/null +++ b/AsbCloudDb/Model/DailyReports/Blocks/TimeBalance/TimeBalanceRecord.cs @@ -0,0 +1,16 @@ +namespace AsbCloudDb.Model.DailyReports.Blocks.TimeBalance; + +public class TimeBalanceRecord +{ + public int IdWellOperation { get; set; } + + public double? DurationHoursPlan { get; set; } + + public double? DurationHoursFact { get; set; } + + public double? DrillingDeviationPerSection { get; set; } + + public double? DrillingDeviationPerDay { get; set; } + + public string? ReasonDeviation { get; set; } +} \ No newline at end of file diff --git a/AsbCloudDb/Model/DailyReports/DailyReport.cs b/AsbCloudDb/Model/DailyReports/DailyReport.cs new file mode 100644 index 00000000..1906d9ab --- /dev/null +++ b/AsbCloudDb/Model/DailyReports/DailyReport.cs @@ -0,0 +1,37 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using AsbCloudDb.Model.DailyReports.Blocks.Sign; +using AsbCloudDb.Model.DailyReports.Blocks.Subsystem; +using AsbCloudDb.Model.DailyReports.Blocks.TimeBalance; +using Microsoft.EntityFrameworkCore; + +namespace AsbCloudDb.Model.DailyReports; + +[Table("t_daily_report"), Comment("Ежедневные отчёты")] +public class DailyReport : IId +{ + [Key] + public int Id { get; set; } + + [Column("id_well"), Comment("ID скважины")] + public int IdWell { get; set; } + + [Column("date_last_update", TypeName = "timestamp with time zone"), Comment("Дата последнего обновления")] + public DateTime? DateLastUpdate { get; set; } + + [Column("date", TypeName = "timestamp with time zone"), Comment("Дата формирования отчёта")] + public DateTime Date { get; set; } + + [Column("sign_block", TypeName = "jsonb"), Comment("Подпись")] + public SignBlock? SignBlock { get; set; } + + [Column("time_balance_block", TypeName = "jsonb"), Comment("Баланс времени")] + public TimeBalanceBlock? TimeBalanceBlock { get; set; } + + [Column("subsystem_block", TypeName = "jsonb"), Comment("Наработкой подсистем")] + public SubsystemBlock? SubsystemBlock { get; set; } + + [ForeignKey(nameof(IdWell))] + public virtual Well Well { get; set; } = null!; +} \ No newline at end of file diff --git a/AsbCloudDb/Model/IAsbCloudDbContext.cs b/AsbCloudDb/Model/IAsbCloudDbContext.cs index a0365121..6d5098c8 100644 --- a/AsbCloudDb/Model/IAsbCloudDbContext.cs +++ b/AsbCloudDb/Model/IAsbCloudDbContext.cs @@ -7,6 +7,7 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using System; using System.Threading; using System.Threading.Tasks; +using AsbCloudDb.Model.DailyReports; using AsbCloudDb.Model.Manuals; using AsbCloudDb.Model.ProcessMaps; diff --git a/AsbCloudInfrastructure/Repository/DailyReportRepository.cs b/AsbCloudInfrastructure/Repository/DailyReportRepository.cs index 44e8ec41..147cae3e 100644 --- a/AsbCloudInfrastructure/Repository/DailyReportRepository.cs +++ b/AsbCloudInfrastructure/Repository/DailyReportRepository.cs @@ -1,17 +1,17 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text.Json; using System.Threading; using System.Threading.Tasks; +using AsbCloudApp.Data; using AsbCloudApp.Data.DailyReport; -using AsbCloudApp.Data.DailyReport.Blocks.Sign; -using AsbCloudApp.Data.DailyReport.Blocks.Subsystems; 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; @@ -19,15 +19,6 @@ namespace AsbCloudInfrastructure.Repository; public class DailyReportRepository : CrudRepositoryBase, IDailyReportRepository { - private class Blocks - { - public SubsystemBlockDto? Subsystem { get; set; } - - public TimeBalanceBlockDto? TimeBalance { get; set; } - - public SignBlockDto? Sign { get; set; } - } - public DailyReportRepository(IAsbCloudDbContext dbContext) : base(dbContext) { @@ -41,10 +32,10 @@ public class DailyReportRepository : CrudRepositoryBase d.IdWell == idWell); if (request.GeDate.HasValue) - query = query.Where(d => d.DateStart >= request.GeDate.Value.ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc)); + query = query.Where(d => d.Date >= request.GeDate.Value.ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc)); if (request.LeDate.HasValue) - query = query.Where(d => d.DateStart <= request.LeDate.Value.ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc)); + query = query.Where(d => d.Date <= request.LeDate.Value.ToDateTime(TimeOnly.MinValue, DateTimeKind.Utc)); if (request.SortFields?.Any() == true) { @@ -62,45 +53,44 @@ public class DailyReportRepository : CrudRepositoryBase GetOrDefaultAsync(int idWell, DateTime dateStart, CancellationToken cancellationToken) + public async Task GetOrDefaultAsync(int idWell, DateTime date, CancellationToken cancellationToken) { var entity = await GetQuery() .Include(d => d.Well) + .AsNoTracking() .SingleOrDefaultAsync(d => d.IdWell == idWell && - d.DateStart == dateStart, cancellationToken); + d.Date == date, cancellationToken); return entity is null ? null : Convert(entity); } - public Task AnyAsync(int idWell, DateTime dateStart, CancellationToken cancellationToken) => - GetQuery().AnyAsync(d => d.IdWell == idWell && d.DateStart == dateStart, cancellationToken); - - protected override DailyReport Convert(DailyReportDto src) - { - var entity = base.Convert(src); - - entity.Blocks = JsonSerializer.Serialize(new Blocks - { - Subsystem = src.SubsystemBlock, - TimeBalance = src.TimeBalanceBlock, - Sign = src.SignBlock, - }); - - return entity; - } - protected override DailyReportDto Convert(DailyReport src) { var dto = base.Convert(src); - if (string.IsNullOrWhiteSpace(src.Blocks)) + if (dto.TimeBalanceBlock is null) return dto; + + dto.TimeBalanceBlock.WellDepth = new PlanFactDto() + { + Plan = src.TimeBalanceBlock?.WellDepthPlan + }; - var blocks = JsonSerializer.Deserialize(src.Blocks); + if (src.TimeBalanceBlock?.WellOperations?.Any() == true) + { + dto.TimeBalanceBlock.WellOperations = src.TimeBalanceBlock.WellOperations.Select(w => + { + var wellOperation = w.Adapt(); + + wellOperation.DurationHours = new PlanFactDto() + { + Plan = w.DurationHoursPlan, + Fact = w.DurationHoursFact + }; - dto.SubsystemBlock = blocks?.Subsystem; - dto.TimeBalanceBlock = blocks?.TimeBalance; - dto.SignBlock = blocks?.Sign; + return wellOperation; + }); + } return dto; }