Compare commits

..

2 Commits

Author SHA1 Message Date
d7b5b7e3ab Ченджлог (продолжение) 2024-11-25 18:11:46 +05:00
381557459b Ченджлог (начало) 2024-11-25 10:05:23 +05:00
15 changed files with 562 additions and 74 deletions

View File

@ -0,0 +1,61 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Persistence.Database.Model;
using Persistence.Models;
using Persistence.Repositories;
namespace Persistence.API.Controllers;
[ApiController]
[Authorize]
[Route("api/[controller]")]
public class ChangeLogRotorController : ControllerBase, IChangeLogApi<ProcessMapRotorDto, ChangeLogDto<ProcessMapRotorDto>>
{
private IChangeLogRepository<ProcessMapRotorDto, ChangeLogDto<ProcessMapRotorDto>> repository;
public ChangeLogRotorController(IChangeLogRepository<ProcessMapRotorDto, ChangeLogDto<ProcessMapRotorDto>> repository)
{
this.repository = repository;
}
public async Task<ActionResult<int>> Add(ProcessMapRotorDto dto, CancellationToken token)
{
await repository.InsertRange(0, [dto], token);
return null;
}
public Task<ActionResult<int>> AddRange(IEnumerable<ProcessMapRotorDto> dtos, CancellationToken token)
{
throw new NotImplementedException();
}
public Task<ActionResult<int>> Delete(int id, CancellationToken token)
{
throw new NotImplementedException();
}
public Task<ActionResult<int>> DeleteRange(IEnumerable<int> ids, CancellationToken token)
{
throw new NotImplementedException();
}
public Task<ActionResult<IEnumerable<ProcessMapRotorDto>>> GetChangeLogCurrent(CancellationToken token)
{
throw new NotImplementedException();
}
public Task<ActionResult<IEnumerable<ChangeLogDto<ProcessMapRotorDto>>>> GetChangeLogForDate(DateTimeOffset historyMoment, CancellationToken token)
{
throw new NotImplementedException();
}
public Task<ActionResult<int>> Update(ProcessMapRotorDto dto, CancellationToken token)
{
throw new NotImplementedException();
}
public Task<ActionResult<int>> UpdateRange(IEnumerable<ProcessMapRotorDto> dtos, CancellationToken token)
{
throw new NotImplementedException();
}
}

View File

@ -0,0 +1,152 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using Persistence.Database.Model;
#nullable disable
namespace Persistence.Database.Postgres.Migrations
{
[DbContext(typeof(PersistenceDbContext))]
[Migration("20241122124437_AddChangeLog")]
partial class AddChangeLog
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.UseCollation("Russian_Russia.1251")
.HasAnnotation("ProductVersion", "8.0.10")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "adminpack");
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Persistence.Database.Model.ChangeLog", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("Id");
b.Property<DateTimeOffset>("Creation")
.HasColumnType("timestamp with time zone")
.HasColumnName("Creation");
b.Property<int>("IdAuthor")
.HasColumnType("integer")
.HasColumnName("IdAuthor");
b.Property<int?>("IdEditor")
.HasColumnType("integer")
.HasColumnName("IdEditor");
b.Property<int?>("IdNext")
.HasColumnType("integer")
.HasColumnName("IdNext");
b.Property<DateTimeOffset?>("Obsolete")
.HasColumnType("timestamp with time zone")
.HasColumnName("Obsolete");
b.Property<object>("Value")
.IsRequired()
.HasColumnType("jsonb")
.HasColumnName("Value");
b.HasKey("Id");
b.ToTable("ChangeLog");
});
modelBuilder.Entity("Persistence.Database.Model.DataSaub", b =>
{
b.Property<DateTimeOffset>("Date")
.HasColumnType("timestamp with time zone")
.HasColumnName("date");
b.Property<double?>("AxialLoad")
.HasColumnType("double precision")
.HasColumnName("axialLoad");
b.Property<double?>("BitDepth")
.HasColumnType("double precision")
.HasColumnName("bitDepth");
b.Property<double?>("BlockPosition")
.HasColumnType("double precision")
.HasColumnName("blockPosition");
b.Property<double?>("BlockSpeed")
.HasColumnType("double precision")
.HasColumnName("blockSpeed");
b.Property<double?>("Flow")
.HasColumnType("double precision")
.HasColumnName("flow");
b.Property<double?>("HookWeight")
.HasColumnType("double precision")
.HasColumnName("hookWeight");
b.Property<int>("IdFeedRegulator")
.HasColumnType("integer")
.HasColumnName("idFeedRegulator");
b.Property<int?>("Mode")
.HasColumnType("integer")
.HasColumnName("mode");
b.Property<double?>("Mse")
.HasColumnType("double precision")
.HasColumnName("mse");
b.Property<short>("MseState")
.HasColumnType("smallint")
.HasColumnName("mseState");
b.Property<double?>("Pressure")
.HasColumnType("double precision")
.HasColumnName("pressure");
b.Property<double?>("Pump0Flow")
.HasColumnType("double precision")
.HasColumnName("pump0Flow");
b.Property<double?>("Pump1Flow")
.HasColumnType("double precision")
.HasColumnName("pump1Flow");
b.Property<double?>("Pump2Flow")
.HasColumnType("double precision")
.HasColumnName("pump2Flow");
b.Property<double?>("RotorSpeed")
.HasColumnType("double precision")
.HasColumnName("rotorSpeed");
b.Property<double?>("RotorTorque")
.HasColumnType("double precision")
.HasColumnName("rotorTorque");
b.Property<string>("User")
.HasColumnType("text")
.HasColumnName("user");
b.Property<double?>("WellDepth")
.HasColumnType("double precision")
.HasColumnName("wellDepth");
b.HasKey("Date");
b.ToTable("DataSaub");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,39 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Persistence.Database.Postgres.Migrations
{
/// <inheritdoc />
public partial class AddChangeLog : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "ChangeLog",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
IdAuthor = table.Column<int>(type: "integer", nullable: false),
IdEditor = table.Column<int>(type: "integer", nullable: true),
Creation = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
Obsolete = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
IdNext = table.Column<int>(type: "integer", nullable: true),
Value = table.Column<object>(type: "jsonb", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ChangeLog", x => x.Id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ChangeLog");
}
}
}

View File

@ -24,6 +24,43 @@ namespace Persistence.Database.Postgres.Migrations
NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "adminpack");
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Persistence.Database.Model.ChangeLog", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("Id");
b.Property<DateTimeOffset>("Creation")
.HasColumnType("timestamp with time zone")
.HasColumnName("Creation");
b.Property<int>("IdAuthor")
.HasColumnType("integer")
.HasColumnName("IdAuthor");
b.Property<int?>("IdEditor")
.HasColumnType("integer")
.HasColumnName("IdEditor");
b.Property<int?>("IdNext")
.HasColumnType("integer")
.HasColumnName("IdNext");
b.Property<DateTimeOffset?>("Obsolete")
.HasColumnType("timestamp with time zone")
.HasColumnName("Obsolete");
b.Property<object>("Value")
.IsRequired()
.HasColumnType("jsonb")
.HasColumnName("Value");
b.HasKey("Id");
b.ToTable("ChangeLog");
});
modelBuilder.Entity("Persistence.Database.Model.DataSaub", b =>
{
b.Property<DateTimeOffset>("Date")

View File

@ -5,6 +5,7 @@ namespace Persistence.Database.Model;
public partial class PersistenceDbContext : DbContext, IPersistenceDbContext
{
public DbSet<DataSaub> DataSaub => Set<DataSaub>();
public DbSet<ChangeLog> ChangeLog => Set<ChangeLog>();
public PersistenceDbContext()
: base()

View File

@ -0,0 +1,59 @@

using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
namespace Persistence.Database.Model;
/// <summary>
/// Часть записи, описывающая изменение
/// </summary>
public class ChangeLog : IChangeLog
{
/// <summary>
/// Ид записи
/// </summary>
[Key, Column("Id")]
public Guid Id { get; set; }
/// <summary>
/// Дискриминатор таблицы
/// </summary>
[Column("IdDiscriminator")]
public Guid IdDiscriminator { get; set; }
/// <summary>
/// Автор изменения
/// </summary>
[Column("IdAuthor")]
public Guid IdAuthor { get; set; }
/// <summary>
/// Редактор
/// </summary>
[Column("IdEditor")]
public Guid? IdEditor { get; set; }
/// <summary>
/// Дата создания записи
/// </summary>
[Column("Creation")]
public DateTimeOffset Creation { get; set; }
/// <summary>
/// Дата устаревания (например при удалении)
/// </summary>
[Column("Obsolete")]
public DateTimeOffset? Obsolete { get; set; }
/// <summary>
/// Id заменяющей записи
/// </summary>
[Column("IdNext")]
public Guid? IdNext { get; set; }
/// <summary>
/// Значение
/// </summary>
[Column("Value", TypeName = "jsonb")]
public required object Value { get; set; }
}

View File

@ -0,0 +1,29 @@

using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
namespace Persistence.Database.Model;
/// <summary>
/// Часть записи, описывающая изменение данных, содержащие начальную и конечную глубину, а также секцию
/// </summary>
public class ChangeLogWithWellDepthAndSectionId : ChangeLog
{
/// <summary>
/// Глубина забоя на дату начала интервала
/// </summary>
[Column("DepthStart")]
public double? DepthStart { get; set; }
/// <summary>
/// Глубина забоя на дату окончания интервала
/// </summary>
[Column("DepthEnd")]
public double? DepthEnd { get; set; }
/// <summary>
/// Ключ секции
/// </summary>
[Column("IdSection")]
public Guid IdSection { get; set; }
}

View File

@ -0,0 +1,43 @@

namespace Persistence.Database.Model;
/// <summary>
/// Часть записи описывающая изменение
/// </summary>
public interface IChangeLog
{
/// <summary>
/// Ид записи
/// </summary>
public Guid Id { get; set; }
/// <summary>
/// Автор изменения
/// </summary>
public Guid IdAuthor { get; set; }
/// <summary>
/// Редактор
/// </summary>
public Guid? IdEditor { get; set; }
/// <summary>
/// Дата создания записи
/// </summary>
public DateTimeOffset Creation { get; set; }
/// <summary>
/// Дата устаревания (например при удалении)
/// </summary>
public DateTimeOffset? Obsolete { get; set; }
/// <summary>
/// Id заменяющей записи
/// </summary>
public Guid? IdNext { get; set; }
/// <summary>
/// Значение
/// </summary>
public object Value { get; set; }
}

View File

@ -5,4 +5,5 @@ namespace Persistence.Database;
public interface IPersistenceDbContext : IDisposable
{
DbSet<DataSaub> DataSaub { get; }
DbSet<ChangeLog> ChangeLog { get; }
}

View File

@ -0,0 +1,68 @@
using Mapster;
using Microsoft.EntityFrameworkCore;
using Persistence.Database.Model;
using Persistence.Models;
using Persistence.Repositories;
namespace Persistence.Repository.Repositories;
public class ChangeLogRepository<TDto, TChangeLogDto> : IChangeLogRepository<TDto, TChangeLogDto>
where TDto : class, IChangeLogDto, new()
where TChangeLogDto : ChangeLogDto<TDto>
{
private DbContext db;
public ChangeLogRepository(DbContext db)
{
this.db = db;
}
public Task<int> Clear(int idUser, CancellationToken token)
{
throw new NotImplementedException();
}
public Task<int> ClearAndInsertRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token)
{
throw new NotImplementedException();
}
public Task<IEnumerable<TChangeLogDto>> GetChangeLogForDate(DateTimeOffset? updateFrom, CancellationToken token)
{
throw new NotImplementedException();
}
public Task<IEnumerable<TDto>> GetCurrent(DateTimeOffset moment, CancellationToken token)
{
throw new NotImplementedException();
}
public Task<IEnumerable<DateOnly>> GetDatesChange(CancellationToken token)
{
throw new NotImplementedException();
}
public Task<IEnumerable<TDto>> GetGtDate(DateTimeOffset dateBegin, CancellationToken token)
{
throw new NotImplementedException();
}
public Task<int> InsertRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token)
{
throw new NotImplementedException();
}
public Task<int> MarkAsDeleted(int idUser, IEnumerable<int> ids, CancellationToken token)
{
throw new NotImplementedException();
}
public Task<int> UpdateOrInsertRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token)
{
throw new NotImplementedException();
}
public Task<int> UpdateRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token)
{
throw new NotImplementedException();
}
}

View File

@ -1,9 +1,11 @@
namespace Persistence.Models;
/// <summary>
/// Часть записи описывающая изменение
/// </summary>
public class ChangeLogDto<T> where T: class
public class ChangeLogDto<T> : IChangeLogDto
where T: class
{
/// <summary>
/// Запись
@ -11,32 +13,37 @@ public class ChangeLogDto<T> where T: class
public required T Item { get; set; }
/// <summary>
/// Автор
///
/// </summary>
public UserDto? Author { get; set; }
public int Id { get; set; }
/// <summary>
/// Автор
///
/// </summary>
public UserDto? Editor { get; set; }
public int IdAuthor { get; set; }
/// <summary>
/// Дата создания записи
///
/// </summary>
public int? IdEditor { get; set; }
/// <summary>
///
/// </summary>
public DateTimeOffset Creation { get; set; }
/// <summary>
/// Дата устаревания (например, при удалении)
///
/// </summary>
public DateTimeOffset? Obsolete { get; set; }
/// <summary>
/// Id состояния
///
/// </summary>
public int IdState { get; set; }
public int? IdNext { get; set; }
/// <summary>
/// Id заменяемой записи
///
/// </summary>
public int? IdPrevious { get; set; }
public required object Value { get; set; }
}

View File

@ -1,62 +0,0 @@
namespace Persistence.Models;
/// <summary>
/// Часть записи описывающая изменение
/// </summary>
public interface IChangeLogAbstract
{
/// <summary>
/// Актуальная
/// </summary>
public const int IdStateActual = 0;
/// <summary>
/// Замененная
/// </summary>
public const int IdStateReplaced = 1;
/// <summary>
/// Удаленная
/// </summary>
public const int IdStateDeleted = 2;
/// <summary>
/// Очищено при импорте
/// </summary>
public const int IdCleared = 3;
/// <summary>
/// Ид записи
/// </summary>
public int Id { get; set; }
/// <summary>
/// Автор изменения
/// </summary>
public int IdAuthor { get; set; }
/// <summary>
/// Редактор
/// </summary>
public int? IdEditor { get; set; }
/// <summary>
/// Дата создания записи
/// </summary>
public DateTimeOffset Creation { get; set; }
/// <summary>
/// Дата устаревания (например при удалении)
/// </summary>
public DateTimeOffset? Obsolete { get; set; }
/// <summary>
/// "ИД состояния записи: \n0 - актуальная\n1 - замененная\n2 - удаленная
/// </summary>
public int IdState { get; set; }
/// <summary>
/// Id заменяемой записи
/// </summary>
public int? IdPrevious { get; set; }
}

View File

@ -0,0 +1,42 @@
namespace Persistence.Models;
/// <summary>
/// Часть записи описывающая изменение
/// </summary>
public interface IChangeLogDto
{
///// <summary>
///// Ид записи
///// </summary>
//public int Id { get; set; }
///// <summary>
///// Автор изменения
///// </summary>
//public int IdAuthor { get; set; }
///// <summary>
///// Редактор
///// </summary>
//public int? IdEditor { get; set; }
///// <summary>
///// Дата создания записи
///// </summary>
//public DateTimeOffset Creation { get; set; }
///// <summary>
///// Дата устаревания (например при удалении)
///// </summary>
//public DateTimeOffset? Obsolete { get; set; }
///// <summary>
///// Id заменяющей записи
///// </summary>
//public int? IdNext { get; set; }
///// <summary>
///// Значение
///// </summary>
//public object Value { get; set; }
}

View File

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Persistence.Models;
public class ProcessMapRotorDto : IChangeLogDto
{
public string Caption { get; set; }
}

View File

@ -7,7 +7,7 @@ namespace Persistence.Repositories;
/// </summary>
/// <typeparam name="TDto"></typeparam>
public interface IChangeLogRepository<TDto, TChangeLogDto> : ISyncRepository<TDto>
where TDto : class, ITimeSeriesAbstractDto, new()
where TDto : class, IChangeLogDto, new()
where TChangeLogDto : ChangeLogDto<TDto>
{
/// <summary>