forked from ddrilling/AsbCloudServer
Recreate migration Add_mw_telemetry_datas_saub_stat.
This commit is contained in:
parent
5458ac5414
commit
692517798b
@ -2,6 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -1,21 +1,15 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudDb
|
||||
{
|
||||
#nullable enable
|
||||
public static class EFExtentionsSortBy
|
||||
{
|
||||
class TypeAcessor
|
||||
struct TypeAcessor
|
||||
{
|
||||
public LambdaExpression KeySelector { get; set; }
|
||||
public MethodInfo OrderBy { get; set; }
|
||||
@ -24,26 +18,26 @@ namespace AsbCloudDb
|
||||
public MethodInfo ThenByDescending { get; set; }
|
||||
}
|
||||
|
||||
static ConcurrentDictionary<Type, Dictionary<string, TypeAcessor>> TypePropSelectors { get; set; } = new();
|
||||
private static ConcurrentDictionary<Type, Dictionary<string, TypeAcessor>> TypePropSelectors { get; set; } = new();
|
||||
|
||||
static MethodInfo methodOrderBy = GetExtOrderMethod("OrderBy");
|
||||
private static readonly MethodInfo methodOrderBy = GetExtOrderMethod("OrderBy");
|
||||
|
||||
static MethodInfo methodOrderByDescending = GetExtOrderMethod("OrderByDescending");
|
||||
private static readonly MethodInfo methodOrderByDescending = GetExtOrderMethod("OrderByDescending");
|
||||
|
||||
static MethodInfo methodThenBy = GetExtOrderMethod("ThenBy");
|
||||
private static readonly MethodInfo methodThenBy = GetExtOrderMethod("ThenBy");
|
||||
|
||||
static MethodInfo methodThenByDescending = GetExtOrderMethod("ThenByDescending");
|
||||
private static readonly MethodInfo methodThenByDescending = GetExtOrderMethod("ThenByDescending");
|
||||
|
||||
static MethodInfo GetExtOrderMethod(string methodName)
|
||||
private static MethodInfo GetExtOrderMethod(string methodName)
|
||||
=> typeof(System.Linq.Queryable)
|
||||
.GetMethods()
|
||||
.Where(m => m.Name == methodName &&
|
||||
m.IsGenericMethodDefinition &&
|
||||
m.IsGenericMethodDefinition &&
|
||||
m.GetParameters().Length == 2 &&
|
||||
m.GetParameters()[1].ParameterType.IsAssignableTo(typeof(LambdaExpression)))
|
||||
.Single();
|
||||
|
||||
private static Dictionary<string, TypeAcessor> MakeTypeAcessors (Type type)
|
||||
private static Dictionary<string, TypeAcessor> MakeTypeAcessors(Type type)
|
||||
{
|
||||
var propContainer = new Dictionary<string, TypeAcessor>();
|
||||
var properties = type.GetProperties();
|
||||
@ -61,7 +55,7 @@ namespace AsbCloudDb
|
||||
ThenBy = methodThenBy.MakeGenericMethod(type, propertyInfo.PropertyType),
|
||||
ThenByDescending = methodThenByDescending.MakeGenericMethod(type, propertyInfo.PropertyType),
|
||||
};
|
||||
|
||||
|
||||
propContainer.Add(name, typeAccessor);
|
||||
}
|
||||
return propContainer;
|
||||
@ -92,7 +86,7 @@ namespace AsbCloudDb
|
||||
sortEnum.MoveNext();
|
||||
var orderedQuery = query.SortBy(sortEnum.Current);
|
||||
|
||||
while(sortEnum.MoveNext())
|
||||
while (sortEnum.MoveNext())
|
||||
orderedQuery = orderedQuery.ThenSortBy(sortEnum.Current);
|
||||
|
||||
return orderedQuery;
|
||||
@ -120,7 +114,7 @@ namespace AsbCloudDb
|
||||
var parts = propertySort.Split(" ", 2, StringSplitOptions.RemoveEmptyEntries);
|
||||
var isDesc = parts.Length >= 2 && parts[1].ToLower().Trim() == "desc";
|
||||
var propertyName = parts[0];
|
||||
|
||||
|
||||
var newQuery = query.SortBy(propertyName, isDesc);
|
||||
return newQuery;
|
||||
}
|
||||
@ -202,5 +196,4 @@ namespace AsbCloudDb
|
||||
return newQuery;
|
||||
}
|
||||
}
|
||||
#nullable disable
|
||||
}
|
||||
|
@ -12,12 +12,12 @@ namespace AsbCloudDb
|
||||
public static class EFExtentions
|
||||
{
|
||||
static Dictionary<Type, IQueryStringFactory> QueryFactories { get; set; } = new();
|
||||
|
||||
|
||||
static QueryStringFactory<T> GetQueryStringFactory<T>(DbSet<T> dbSet)
|
||||
where T : class
|
||||
{
|
||||
var t = typeof(T);
|
||||
var factory = (QueryStringFactory<T>)QueryFactories.GetValueOrDefault(t);
|
||||
var factory = (QueryStringFactory<T>?)QueryFactories.GetValueOrDefault(t);
|
||||
if (factory is null)
|
||||
{
|
||||
factory = new QueryStringFactory<T>(dbSet);
|
||||
@ -70,7 +70,7 @@ namespace AsbCloudDb
|
||||
var pkColsNames = dbset.EntityType.FindPrimaryKey()?.Properties.Select(p => p.GetColumnBaseName());
|
||||
pk = pkColsNames is null ? string.Empty : $"({string.Join(", ", pkColsNames)})";
|
||||
|
||||
TableName = dbset.EntityType.GetTableName();
|
||||
TableName = dbset.EntityType.GetTableName()!;
|
||||
getters = properties.Select(p => p.GetGetter());
|
||||
Columns = properties.Select(p => $"\"{p.GetColumnBaseName()}\"");
|
||||
var colunmsString = $"({string.Join(", ", Columns)})";
|
||||
@ -113,7 +113,7 @@ namespace AsbCloudDb
|
||||
return builder;
|
||||
}
|
||||
|
||||
private static string FormatValue(object v)
|
||||
private static string FormatValue(object? v)
|
||||
=> v switch
|
||||
{
|
||||
string vStr => $"'{vStr}'",
|
||||
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace AsbCloudDb.Migrations
|
||||
{
|
||||
#nullable disable
|
||||
public partial class Init : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
|
@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudDb.Model;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using System;
|
||||
|
||||
#nullable disable
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using System;
|
||||
|
||||
#nullable disable
|
||||
|
||||
|
5768
AsbCloudDb/Migrations/20220506041015_Add_mw_telemetry_datas_saub_stat.Designer.cs
generated
Normal file
5768
AsbCloudDb/Migrations/20220506041015_Add_mw_telemetry_datas_saub_stat.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,27 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace AsbCloudDb.Migrations
|
||||
{
|
||||
public partial class Add_mw_telemetry_datas_saub_stat : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.Sql(@"CREATE MATERIALIZED VIEW IF NOT exists mw_telemetry_datas_saub_stat AS
|
||||
SELECT t_telemetry_data_saub.id_telemetry,
|
||||
count(*) AS count_items,
|
||||
min(t_telemetry_data_saub.date) AS date_min,
|
||||
max(t_telemetry_data_saub.date) AS date_max,
|
||||
min(t_telemetry_data_saub.well_depth) AS depth_min,
|
||||
max(t_telemetry_data_saub.well_depth) AS depth_max
|
||||
FROM t_telemetry_data_saub
|
||||
GROUP BY t_telemetry_data_saub.id_telemetry;");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.Sql(@"drop MATERIALIZED view IF exists mw_telemetry_datas_saub_stat;");
|
||||
}
|
||||
}
|
||||
}
|
@ -2725,6 +2725,35 @@ namespace AsbCloudDb.Migrations
|
||||
b.HasComment("набор основных данных по SAUB");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AsbCloudDb.Model.TelemetryDataSaubStat", b =>
|
||||
{
|
||||
b.Property<long?>("Count")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("count_items");
|
||||
|
||||
b.Property<DateTimeOffset?>("DateMax")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("date_max");
|
||||
|
||||
b.Property<DateTimeOffset?>("DateMin")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
.HasColumnName("date_min");
|
||||
|
||||
b.Property<float?>("DepthMax")
|
||||
.HasColumnType("real")
|
||||
.HasColumnName("depth_max");
|
||||
|
||||
b.Property<float?>("DepthMin")
|
||||
.HasColumnType("real")
|
||||
.HasColumnName("depth_min");
|
||||
|
||||
b.Property<int>("IdTelemetry")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id_telemetry");
|
||||
|
||||
b.ToView("mw_telemetry_datas_saub_stat");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AsbCloudDb.Model.TelemetryDataSpin", b =>
|
||||
{
|
||||
b.Property<int>("IdTelemetry")
|
||||
|
@ -1,73 +1,65 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
|
||||
#nullable disable
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
//Scaffold-DbContext "Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True" Npgsql.EntityFrameworkCore.PostgreSQL -OutputDir Model -DataAnnotations
|
||||
public partial class AsbCloudDbContext : DbContext, IAsbCloudDbContext
|
||||
{
|
||||
public virtual DbSet<Cluster> Clusters { get; set; }
|
||||
public virtual DbSet<Company> Companies { get; set; }
|
||||
public virtual DbSet<CompanyType> CompaniesTypes { get; set; }
|
||||
public virtual DbSet<Deposit> Deposits { get; set; }
|
||||
public virtual DbSet<DetectedOperation> DetectedOperations { get; set; }
|
||||
public virtual DbSet<DrillingProgramPart> DrillingProgramParts { get; set; }
|
||||
public virtual DbSet<FileCategory> FileCategories { get; set; }
|
||||
public virtual DbSet<FileInfo> Files { get; set; }
|
||||
public virtual DbSet<FileMark> FileMarks { get; set; }
|
||||
public virtual DbSet<Measure> Measures { get; set; }
|
||||
public virtual DbSet<MeasureCategory> MeasureCategories { get; set; }
|
||||
public virtual DbSet<ReportProperty> ReportProperties { get; set; }
|
||||
public virtual DbSet<SetpointsRequest> SetpointsRequests { get; set; }
|
||||
public virtual DbSet<Telemetry> Telemetries { get; set; }
|
||||
public virtual DbSet<TelemetryDataSaub> TelemetryDataSaub { get; set; }
|
||||
public virtual DbSet<TelemetryDataSpin> TelemetryDataSpin { get; set; }
|
||||
public virtual DbSet<TelemetryEvent> TelemetryEvents { get; set; }
|
||||
public virtual DbSet<TelemetryMessage> TelemetryMessages { get; set; }
|
||||
public virtual DbSet<TelemetryUser> TelemetryUsers { get; set; }
|
||||
public virtual DbSet<User> Users { get; set; }
|
||||
public virtual DbSet<UserRole> UserRoles { get; set; }
|
||||
public virtual DbSet<Well> Wells { get; set; }
|
||||
public virtual DbSet<WellComposite> WellComposites { get; set; }
|
||||
public virtual DbSet<WellOperation> WellOperations { get; set; }
|
||||
public virtual DbSet<WellOperationCategory> WellOperationCategories { get; set; }
|
||||
public virtual DbSet<WellSectionType> WellSectionTypes { get; set; }
|
||||
public virtual DbSet<WellType> WellTypes { get; set; }
|
||||
public virtual DbSet<DrillParams> DrillParams { get; set; }
|
||||
public virtual DbSet<DrillFlowChart> DrillFlowChart { get; set; }
|
||||
public virtual DbSet<Permission> Permissions { get; set; }
|
||||
public virtual DbSet<RelationCompanyWell> RelationCompaniesWells { get; set; }
|
||||
public virtual DbSet<RelationUserUserRole> RelationUserUserRoles { get; set; }
|
||||
public virtual DbSet<RelationUserRolePermission> RelationUserRolePermissions { get; set; }
|
||||
public virtual DbSet<RelationUserRoleUserRole> RelationUserRoleUserRoles { get; set; }
|
||||
public virtual DbSet<RelationUserDrillingProgramPart> RelationDrillingProgramPartUsers { get; set; }
|
||||
public virtual DbSet<DailyReport> DailyReports { get; set; }
|
||||
public virtual DbSet<Cluster> Clusters => Set<Cluster>();
|
||||
public virtual DbSet<Company> Companies => Set<Company>();
|
||||
public virtual DbSet<CompanyType> CompaniesTypes => Set<CompanyType>();
|
||||
public virtual DbSet<DailyReport> DailyReports => Set<DailyReport>();
|
||||
public virtual DbSet<Deposit> Deposits => Set<Deposit>();
|
||||
public virtual DbSet<DetectedOperation> DetectedOperations => Set<DetectedOperation>();
|
||||
public virtual DbSet<DrillFlowChart> DrillFlowChart => Set<DrillFlowChart>();
|
||||
public virtual DbSet<DrillingProgramPart> DrillingProgramParts => Set<DrillingProgramPart>();
|
||||
public virtual DbSet<DrillParams> DrillParams => Set<DrillParams>();
|
||||
public virtual DbSet<FileCategory> FileCategories => Set<FileCategory>();
|
||||
public virtual DbSet<FileInfo> Files => Set<FileInfo>();
|
||||
public virtual DbSet<FileMark> FileMarks => Set<FileMark>();
|
||||
public virtual DbSet<Measure> Measures => Set<Measure>();
|
||||
public virtual DbSet<MeasureCategory> MeasureCategories => Set<MeasureCategory>();
|
||||
public virtual DbSet<Permission> Permissions => Set<Permission>();
|
||||
public virtual DbSet<RelationCompanyWell> RelationCompaniesWells => Set<RelationCompanyWell>();
|
||||
public virtual DbSet<RelationUserDrillingProgramPart> RelationDrillingProgramPartUsers => Set<RelationUserDrillingProgramPart>();
|
||||
public virtual DbSet<RelationUserRolePermission> RelationUserRolePermissions => Set<RelationUserRolePermission>();
|
||||
public virtual DbSet<RelationUserRoleUserRole> RelationUserRoleUserRoles => Set<RelationUserRoleUserRole>();
|
||||
public virtual DbSet<RelationUserUserRole> RelationUserUserRoles => Set<RelationUserUserRole>();
|
||||
public virtual DbSet<ReportProperty> ReportProperties => Set<ReportProperty>();
|
||||
public virtual DbSet<SetpointsRequest> SetpointsRequests => Set<SetpointsRequest>();
|
||||
public virtual DbSet<Telemetry> Telemetries => Set<Telemetry>();
|
||||
public virtual DbSet<TelemetryDataSaub> TelemetryDataSaub => Set<TelemetryDataSaub>();
|
||||
public virtual DbSet<TelemetryDataSaubStat> TelemetryDataSaubStats => Set<TelemetryDataSaubStat>();
|
||||
public virtual DbSet<TelemetryDataSpin> TelemetryDataSpin => Set<TelemetryDataSpin>();
|
||||
public virtual DbSet<TelemetryEvent> TelemetryEvents => Set<TelemetryEvent>();
|
||||
public virtual DbSet<TelemetryMessage> TelemetryMessages => Set<TelemetryMessage>();
|
||||
public virtual DbSet<TelemetryUser> TelemetryUsers => Set<TelemetryUser>();
|
||||
public virtual DbSet<User> Users => Set<User>();
|
||||
public virtual DbSet<UserRole> UserRoles => Set<UserRole>();
|
||||
public virtual DbSet<Well> Wells => Set<Well>();
|
||||
public virtual DbSet<WellComposite> WellComposites => Set<WellComposite>();
|
||||
public virtual DbSet<WellOperation> WellOperations => Set<WellOperation>();
|
||||
public virtual DbSet<WellOperationCategory> WellOperationCategories => Set<WellOperationCategory>();
|
||||
public virtual DbSet<WellSectionType> WellSectionTypes => Set<WellSectionType>();
|
||||
public virtual DbSet<WellType> WellTypes => Set<WellType>();
|
||||
|
||||
// WITS
|
||||
public DbSet<WITS.Record1> Record1 { get; set; }
|
||||
public DbSet<WITS.Record7> Record7 { get; set; }
|
||||
public DbSet<WITS.Record8> Record8 { get; set; }
|
||||
public DbSet<WITS.Record50> Record50 { get; set; }
|
||||
public DbSet<WITS.Record60> Record60 { get; set; }
|
||||
public DbSet<WITS.Record61> Record61 { get; set; }
|
||||
|
||||
//var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
||||
// .UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True")
|
||||
// .Options;
|
||||
//var context = new AsbCloudDbContext(options);
|
||||
public DbSet<WITS.Record1> Record1 => Set<WITS.Record1>();
|
||||
public DbSet<WITS.Record7> Record7 => Set<WITS.Record7>();
|
||||
public DbSet<WITS.Record8> Record8 => Set<WITS.Record8>();
|
||||
public DbSet<WITS.Record50> Record50 => Set<WITS.Record50>();
|
||||
public DbSet<WITS.Record60> Record60 => Set<WITS.Record60>();
|
||||
public DbSet<WITS.Record61> Record61 => Set<WITS.Record61>();
|
||||
|
||||
public AsbCloudDbContext() : base()
|
||||
{
|
||||
//Database.Migrate();
|
||||
}
|
||||
|
||||
public AsbCloudDbContext(DbContextOptions<AsbCloudDbContext> options)
|
||||
: base(options)
|
||||
{
|
||||
//Database.SetCommandTimeout(60 * 60 * 2);
|
||||
//Database.Migrate();
|
||||
}
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
@ -125,12 +117,6 @@ namespace AsbCloudDb.Model
|
||||
|
||||
modelBuilder.Entity<WITS.RecordBase>(entity =>
|
||||
{
|
||||
//entity.HasOne(d => d.Telemetry)
|
||||
// .WithMany(p => p.DataSaub)
|
||||
// .HasForeignKey(d => d.IdTelemetry)
|
||||
// .OnDelete(DeleteBehavior.Cascade)
|
||||
// .HasConstraintName("t_telemetry_data_saub_t_telemetry_id_fk");
|
||||
|
||||
entity.HasKey(nameof(ITelemetryData.IdTelemetry), nameof(ITelemetryData.DateTime));
|
||||
});
|
||||
|
||||
@ -291,9 +277,29 @@ namespace AsbCloudDb.Model
|
||||
.HasName("t_id_well_date_start_pk");
|
||||
});
|
||||
|
||||
modelBuilder.Entity<TelemetryDataSaubStat>(entity =>
|
||||
{
|
||||
entity.HasNoKey()
|
||||
.ToView("mw_telemetry_datas_saub_stat");
|
||||
});
|
||||
|
||||
FillData(modelBuilder);
|
||||
}
|
||||
|
||||
public Task<int> RefreshMaterializedViewAsync<TEntity>(string? mwName = null, CancellationToken token = default)
|
||||
where TEntity : class
|
||||
{
|
||||
var materializedView = string.IsNullOrEmpty(mwName)
|
||||
? Set<TEntity>().EntityType.GetViewName()
|
||||
: mwName;
|
||||
|
||||
if (string.IsNullOrEmpty(materializedView))
|
||||
return Task.FromResult(0);
|
||||
|
||||
var sql = $"REFRESH MATERIALIZED VIEW {materializedView};";
|
||||
return Database.ExecuteSqlRawAsync(sql, token);
|
||||
}
|
||||
|
||||
private static void FillData(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<UserRole>(entity =>
|
||||
|
@ -1,17 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
#nullable disable
|
||||
[Table("t_daily_report"), Comment("Ежедневные отчёты")]
|
||||
public class DailyReport
|
||||
public class DailyReport
|
||||
{
|
||||
[Column("id_well"), Comment("ID скважины")]
|
||||
public int IdWell { get; set; }
|
||||
@ -25,4 +21,5 @@ namespace AsbCloudDb.Model
|
||||
[ForeignKey(nameof(IdWell))]
|
||||
public virtual Well Well { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
#nullable disable
|
||||
public class DailyReportInfo
|
||||
{
|
||||
/// <summary>
|
||||
@ -210,4 +211,5 @@ namespace AsbCloudDb.Model
|
||||
/// </summary>
|
||||
public string Supervisor { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ using System.Text.Json.Serialization;
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
#nullable disable
|
||||
[Table("t_detected_operation"), Comment("автоматически определенные операции по телеметрии")]
|
||||
public class DetectedOperation
|
||||
{
|
||||
@ -47,6 +48,5 @@ namespace AsbCloudDb.Model
|
||||
|
||||
public override string ToString()
|
||||
=> $"{IdCategory}\t{DateStart:G}\t{DateEnd:G}\t{DurationMinutes:#0.#}\t{DepthStart:#0.#}\t{DepthEnd:#0.#}";
|
||||
//=> $"{{\"type\": {IdType},\t\"begin\":\"{Begin:G}\",\t\"end\":\"{End:G}\",\t\"depthBegin\":\"{BeginWellDepth:#0.#}\",\t\"depthEnd\":\"{EndWellDepth:#0.#}\"}}";
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ using System.Text.Json.Serialization;
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
#nullable disable
|
||||
[Table("t_drill_flow_chart"), Comment("Параметры коридоров бурения (диапазоны параметров бурения)")]
|
||||
public class DrillFlowChart : IId
|
||||
{
|
||||
|
@ -5,6 +5,7 @@ using System.Text.Json.Serialization;
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
#nullable disable
|
||||
[Table("t_drill_params"), Comment("Режим бурения в секции (диапазоны параметров бурения)")]
|
||||
public class DrillParams : IId
|
||||
{
|
||||
|
@ -5,7 +5,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
|
||||
#nullable disable
|
||||
[Table("t_drilling_program_part"), Comment("части программ бурения")]
|
||||
public class DrillingProgramPart
|
||||
{
|
||||
|
@ -4,6 +4,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
#nullable disable
|
||||
[Table("t_file_category"), Comment("Категории файлов")]
|
||||
public class FileCategory : IId
|
||||
{
|
||||
|
@ -7,6 +7,7 @@ using System.Text.Json.Serialization;
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
#nullable disable
|
||||
[Table("t_file_info"), Comment("Файлы всех категорий")]
|
||||
public class FileInfo : IId, IIdWell
|
||||
{
|
||||
|
@ -6,6 +6,7 @@ using System.Text.Json.Serialization;
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
#nullable disable
|
||||
[Table("t_file_mark"), Comment("Действия с файлами.")]
|
||||
public class FileMark
|
||||
{
|
||||
|
@ -2,6 +2,7 @@ using System;
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
#nullable disable
|
||||
public class FilePublishInfo
|
||||
{
|
||||
public int IdPublisher { get; set; }
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using AsbCloudDb.Model.WITS;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using System;
|
||||
using System.Threading;
|
||||
@ -8,41 +9,51 @@ namespace AsbCloudDb.Model
|
||||
{
|
||||
public interface IAsbCloudDbContext : IDisposable
|
||||
{
|
||||
DbSet<Cluster> Clusters { get; set; }
|
||||
DbSet<Company> Companies { get; set; }
|
||||
DbSet<DailyReport> DailyReports { get; set; }
|
||||
DbSet<Deposit> Deposits { get; set; }
|
||||
DbSet<DrillFlowChart> DrillFlowChart { get; set; }
|
||||
DbSet<DrillingProgramPart> DrillingProgramParts { get; set; }
|
||||
DbSet<DrillParams> DrillParams { get; set; }
|
||||
DbSet<FileCategory> FileCategories { get; set; }
|
||||
DbSet<FileInfo> Files { get; set; }
|
||||
DbSet<FileMark> FileMarks { get; set; }
|
||||
DbSet<Measure> Measures { get; set; }
|
||||
DbSet<MeasureCategory> MeasureCategories { get; set; }
|
||||
DbSet<Permission> Permissions { get; set; }
|
||||
DbSet<RelationCompanyWell> RelationCompaniesWells { get; set; }
|
||||
DbSet<RelationUserDrillingProgramPart> RelationDrillingProgramPartUsers { get; set; }
|
||||
DbSet<RelationUserRolePermission> RelationUserRolePermissions { get; set; }
|
||||
DbSet<RelationUserUserRole> RelationUserUserRoles { get; set; }
|
||||
DbSet<ReportProperty> ReportProperties { get; set; }
|
||||
DbSet<Telemetry> Telemetries { get; set; }
|
||||
DbSet<DetectedOperation> DetectedOperations { get; set; }
|
||||
DbSet<TelemetryDataSaub> TelemetryDataSaub { get; set; }
|
||||
DbSet<TelemetryDataSpin> TelemetryDataSpin { get; set; }
|
||||
DbSet<TelemetryEvent> TelemetryEvents { get; set; }
|
||||
DbSet<TelemetryMessage> TelemetryMessages { get; set; }
|
||||
DbSet<TelemetryUser> TelemetryUsers { get; set; }
|
||||
DbSet<User> Users { get; set; }
|
||||
DbSet<UserRole> UserRoles { get; set; }
|
||||
DbSet<Well> Wells { get; set; }
|
||||
DbSet<WellComposite> WellComposites { get; set; }
|
||||
DbSet<WellOperation> WellOperations { get; set; }
|
||||
DbSet<WellOperationCategory> WellOperationCategories { get; set; }
|
||||
DbSet<WellSectionType> WellSectionTypes { get; set; }
|
||||
DbSet<WellType> WellTypes { get; set; }
|
||||
DbSet<Cluster> Clusters { get; }
|
||||
DbSet<Company> Companies { get; }
|
||||
DbSet<DailyReport> DailyReports { get; }
|
||||
DbSet<Deposit> Deposits { get; }
|
||||
DbSet<DetectedOperation> DetectedOperations { get; }
|
||||
DbSet<DrillFlowChart> DrillFlowChart { get; }
|
||||
DbSet<DrillingProgramPart> DrillingProgramParts { get; }
|
||||
DbSet<DrillParams> DrillParams { get; }
|
||||
DbSet<FileCategory> FileCategories { get; }
|
||||
DbSet<FileInfo> Files { get; }
|
||||
DbSet<FileMark> FileMarks { get; }
|
||||
DbSet<Measure> Measures { get; }
|
||||
DbSet<MeasureCategory> MeasureCategories { get; }
|
||||
DbSet<Permission> Permissions { get; }
|
||||
DbSet<RelationCompanyWell> RelationCompaniesWells { get; }
|
||||
DbSet<RelationUserDrillingProgramPart> RelationDrillingProgramPartUsers { get; }
|
||||
DbSet<RelationUserRolePermission> RelationUserRolePermissions { get; }
|
||||
DbSet<RelationUserUserRole> RelationUserUserRoles { get; }
|
||||
DbSet<ReportProperty> ReportProperties { get; }
|
||||
DbSet<Telemetry> Telemetries { get; }
|
||||
DbSet<TelemetryDataSaub> TelemetryDataSaub { get; }
|
||||
DbSet<TelemetryDataSaubStat> TelemetryDataSaubStats { get; }
|
||||
DbSet<TelemetryDataSpin> TelemetryDataSpin { get; }
|
||||
DbSet<TelemetryEvent> TelemetryEvents { get; }
|
||||
DbSet<TelemetryMessage> TelemetryMessages { get; }
|
||||
DbSet<TelemetryUser> TelemetryUsers { get; }
|
||||
DbSet<User> Users { get; }
|
||||
DbSet<UserRole> UserRoles { get; }
|
||||
DbSet<Well> Wells { get; }
|
||||
DbSet<WellComposite> WellComposites { get; }
|
||||
DbSet<WellOperation> WellOperations { get; }
|
||||
DbSet<WellOperationCategory> WellOperationCategories { get; }
|
||||
DbSet<WellSectionType> WellSectionTypes { get; }
|
||||
DbSet<WellType> WellTypes { get; }
|
||||
|
||||
DbSet<Record1> Record1 { get; }
|
||||
DbSet<Record7> Record7 { get; }
|
||||
DbSet<Record8> Record8 { get; }
|
||||
DbSet<Record50> Record50 { get; }
|
||||
DbSet<Record60> Record60 { get; }
|
||||
DbSet<Record61> Record61 { get; }
|
||||
|
||||
DatabaseFacade Database { get; }
|
||||
|
||||
Task<int> RefreshMaterializedViewAsync<TEntity>(string? mwName = null, CancellationToken token = default) where TEntity : class;
|
||||
int SaveChanges();
|
||||
int SaveChanges(bool acceptAllChangesOnSuccess);
|
||||
Task<int> SaveChangesAsync(CancellationToken cancellationToken);
|
||||
|
@ -6,6 +6,7 @@ using System.Text.Json.Serialization;
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
#nullable disable
|
||||
[Table("t_measure"), Comment("Таблица c данными для вкладки \'Последние данные\'")]
|
||||
public class Measure : IId
|
||||
{
|
||||
|
@ -5,6 +5,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
#nullable disable
|
||||
[Table("t_measure_category"), Comment("Категория последних данных")]
|
||||
public class MeasureCategory : IId
|
||||
{
|
||||
|
@ -5,6 +5,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
#nullable disable
|
||||
[Table("t_permission"), Comment("Разрешения на доступ к данным")]
|
||||
public class Permission : IId
|
||||
{
|
||||
|
@ -3,6 +3,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
#nullable disable
|
||||
[Table("t_relation_user_drilling_program_part"), Comment("Отношение пользователей и частей ПБ")]
|
||||
public class RelationUserDrillingProgramPart
|
||||
{
|
||||
@ -23,4 +24,5 @@ namespace AsbCloudDb.Model
|
||||
public virtual User User { get; set; }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
#nullable disable
|
||||
[Table("t_relation_user_role_permission"), Comment("Отношение ролей пользователей и разрешений доступа")]
|
||||
public class RelationUserRolePermission
|
||||
{
|
||||
@ -20,4 +21,5 @@ namespace AsbCloudDb.Model
|
||||
[InverseProperty(nameof(Model.Permission.RelationUserRolePermissions))]
|
||||
public virtual Permission Permission { get; set; }
|
||||
}
|
||||
|
||||
}
|
@ -3,6 +3,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
#nullable disable
|
||||
[Table("t_relation_user_role_user_role"), Comment("Отношение ролей к ролям")]
|
||||
public class RelationUserRoleUserRole
|
||||
{
|
||||
@ -20,4 +21,5 @@ namespace AsbCloudDb.Model
|
||||
public virtual UserRole IncludeRole { get; set; }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
#nullable disable
|
||||
[Table("t_relation_user_user_role"), Comment("Отношение пользователей и ролей")]
|
||||
public class RelationUserUserRole
|
||||
{
|
||||
@ -20,4 +21,5 @@ namespace AsbCloudDb.Model
|
||||
[InverseProperty(nameof(Model.UserRole.RelationUsersUserRoles))]
|
||||
public virtual UserRole UserRole { get; set; }
|
||||
}
|
||||
|
||||
}
|
@ -5,6 +5,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
#nullable disable
|
||||
[Table("t_report_property"), Comment("Отчеты с данными по буровым")]
|
||||
public class ReportProperty : IId, IIdWell
|
||||
{
|
||||
@ -36,4 +37,5 @@ namespace AsbCloudDb.Model
|
||||
[ForeignKey(nameof(IdFile))]
|
||||
public virtual FileInfo File { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
#nullable disable
|
||||
[Table("t_setpoints_rquest"), Comment("Запросы на изменение уставок панели оператора")]
|
||||
public class SetpointsRequest : IId, IIdWell
|
||||
{
|
||||
@ -40,4 +41,5 @@ namespace AsbCloudDb.Model
|
||||
[ForeignKey(nameof(IdAuthor))]
|
||||
public virtual User Author { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
#nullable disable
|
||||
public class SimpleTimezone
|
||||
{
|
||||
public double Hours { get; set; }
|
||||
public string TimeZoneId { get; set; }
|
||||
public bool IsOverride { get; set; }
|
||||
}
|
||||
|
||||
}
|
27
AsbCloudDb/Model/TelemetryDataSaubStat.cs
Normal file
27
AsbCloudDb/Model/TelemetryDataSaubStat.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
public class TelemetryDataSaubStat
|
||||
{
|
||||
[Column("id_telemetry")]
|
||||
public int IdTelemetry { get; set; }
|
||||
|
||||
[Column("count_items")]
|
||||
public long? Count { get; set; }
|
||||
|
||||
[Column("date_min")]
|
||||
public DateTimeOffset? DateMin { get; set; }
|
||||
|
||||
[Column("date_max")]
|
||||
public DateTimeOffset? DateMax { get; set; }
|
||||
|
||||
[Column("depth_min")]
|
||||
public float? DepthMin { get; set; }
|
||||
|
||||
[Column("depth_max")]
|
||||
public float? DepthMax { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ using System.Text.Json.Serialization;
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
#nullable disable
|
||||
[Table("t_telemetry_data_spin"), Comment("набор основных данных по SpinMaster")]
|
||||
public class TelemetryDataSpin : ITelemetryData
|
||||
{
|
||||
@ -147,4 +148,5 @@ namespace AsbCloudDb.Model
|
||||
[InverseProperty(nameof(Model.Telemetry.DataSpin))]
|
||||
public virtual Telemetry Telemetry { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
#nullable disable
|
||||
public class TelemetryInfo
|
||||
{
|
||||
public DateTimeOffset DrillingStartDate { get; set; }
|
||||
@ -16,4 +17,5 @@ namespace AsbCloudDb.Model
|
||||
public string SpinPlcVersion { get; set; }
|
||||
public string Comment { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,9 +3,9 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
#nullable disable
|
||||
[Table("t_user_role"), Comment("Роли пользователей в системе")]
|
||||
public class UserRole : IId
|
||||
{
|
||||
@ -29,4 +29,5 @@ namespace AsbCloudDb.Model
|
||||
[InverseProperty(nameof(RelationUserRolePermission.UserRole))]
|
||||
public virtual ICollection<RelationUserRolePermission> RelationUserRolePermissions { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
#nullable enable
|
||||
|
||||
namespace AsbCloudDb.Model.WITS
|
||||
{
|
||||
|
@ -121,6 +121,6 @@ namespace AsbCloudDb.Model.WITS
|
||||
public short? Actcod { get; set; }
|
||||
|
||||
[ForeignKey(nameof(IdTelemetry))]
|
||||
public virtual Telemetry Telemetry { get; set; }
|
||||
public virtual Telemetry? Telemetry { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
#nullable disable
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
[Table("t_well_composite"), Comment("Композитная скважина")]
|
||||
@ -18,14 +17,14 @@ namespace AsbCloudDb.Model
|
||||
|
||||
[ForeignKey(nameof(IdWell))]
|
||||
[InverseProperty(nameof(Model.Well.WellComposites))]
|
||||
public virtual Well Well { get; set; }
|
||||
public virtual Well Well { get; set; } = null!;
|
||||
|
||||
[ForeignKey(nameof(IdWellSrc))]
|
||||
[InverseProperty(nameof(Model.Well.WellCompositeSrcs))]
|
||||
public virtual Well WellSrc { get; set; }
|
||||
public virtual Well WellSrc { get; set; } = null!;
|
||||
|
||||
[ForeignKey(nameof(IdWellSectionType))]
|
||||
[InverseProperty(nameof(Model.WellSectionType.WellComposites))]
|
||||
public virtual WellSectionType WellSectionType { get; set; }
|
||||
public virtual WellSectionType WellSectionType { get; set; } = null!;
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ using System.Text.Json.Serialization;
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
#nullable disable
|
||||
[Table("t_well_operation"), Comment("Данные по операциям на скважине")]
|
||||
public class WellOperation : IId
|
||||
{
|
||||
@ -55,4 +56,5 @@ namespace AsbCloudDb.Model
|
||||
[ForeignKey(nameof(IdCategory))]
|
||||
public virtual WellOperationCategory OperationCategory { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
#nullable disable
|
||||
[Table("t_well_operation_category"), Comment("Справочник операций на скважине")]
|
||||
public class WellOperationCategory : IId
|
||||
{
|
||||
|
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text.Json.Serialization;
|
||||
#nullable disable
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
@ -16,18 +15,18 @@ namespace AsbCloudDb.Model
|
||||
|
||||
[Column("caption"), Comment("Название")]
|
||||
[StringLength(255)]
|
||||
public string Caption { get; set; }
|
||||
public string Caption { get; set; } = string.Empty;
|
||||
|
||||
[JsonIgnore]
|
||||
[InverseProperty(nameof(WellOperation.WellSectionType))]
|
||||
public virtual ICollection<WellOperation> WellOperations { get; set; }
|
||||
public virtual ICollection<WellOperation> WellOperations { get; set; } = null!;
|
||||
|
||||
[JsonIgnore]
|
||||
[InverseProperty(nameof(DrillParams.WellSectionType))]
|
||||
public virtual ICollection<DrillParams> DrillParamsCollection { get; set; }
|
||||
public virtual ICollection<DrillParams> DrillParamsCollection { get; set; } = null!;
|
||||
|
||||
[JsonIgnore]
|
||||
[InverseProperty(nameof(WellComposite.WellSectionType))]
|
||||
public virtual ICollection<WellComposite> WellComposites { get; set; }
|
||||
public virtual ICollection<WellComposite> WellComposites { get; set; } = null!;
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text.Json.Serialization;
|
||||
#nullable disable
|
||||
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
@ -16,10 +15,10 @@ namespace AsbCloudDb.Model
|
||||
|
||||
[Column("caption"), Comment("Название")]
|
||||
[StringLength(255)]
|
||||
public string Caption { get; set; }
|
||||
public string Caption { get; set; } = null!;
|
||||
|
||||
[JsonIgnore]
|
||||
[InverseProperty(nameof(Well.WellType))]
|
||||
public virtual ICollection<Well> Wells { get; set; }
|
||||
public virtual ICollection<Well> Wells { get; set; } = null!;
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
#nullable enable
|
||||
public class WitsInfoService
|
||||
{
|
||||
private readonly InfoService witsInfoService;
|
||||
|
@ -1,4 +1,6 @@
|
||||
using AsbCloudInfrastructure.Services.DailyReport;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Services.DailyReport;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
@ -9,20 +11,16 @@ namespace ConsoleApp1
|
||||
static void Main(/*string[] args*/)
|
||||
{
|
||||
// use ServiceFactory to make services
|
||||
var makerExcel = new DailyReportMakerExcel();
|
||||
var db = ServiceFactory.Context;
|
||||
//var d = db.TelemetryDataSaubStats.ToList();
|
||||
|
||||
AsbCloudApp.Data.DailyReportDto dto = new() {
|
||||
WellName = "111",
|
||||
ClusterName = "cluster name",
|
||||
Contractor = "NaftaGas",
|
||||
};
|
||||
//db.RefreshMaterializedViewAsync<TelemetryDataSaubStat>().Wait();
|
||||
|
||||
using var stream = makerExcel.MakeReport(dto);
|
||||
using (var fileStream = System.IO.File.Create(@"c:/temp/1.xlsx"))
|
||||
{
|
||||
stream.CopyTo(fileStream);
|
||||
fileStream.Flush();
|
||||
}
|
||||
var d = db.WellSectionTypes
|
||||
.Include(e => e.DrillParamsCollection)
|
||||
.Include(e => e.WellComposites)
|
||||
.Include(e => e.WellOperations)
|
||||
.ToList();
|
||||
|
||||
Console.WriteLine("End of Test");
|
||||
Console.ReadLine();
|
||||
|
Loading…
Reference in New Issue
Block a user