CS2-104: Added confirm of drilling program parts

This commit is contained in:
cult 2021-11-01 16:41:25 +05:00
parent fdef85a291
commit a53d557f2a
13 changed files with 3123 additions and 5 deletions

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
namespace AsbCloudApp.Data
{
@ -13,5 +14,6 @@ namespace AsbCloudApp.Data
public long Size { get; set; }
public FilePublishInfoDto PublishInfo { get; set; }
public UserDto Author { get; set; }
public IEnumerable<FileMarkDto> FileMarks { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using System;
namespace AsbCloudApp.Data
{
public class FileMarkDto
{
public int Id { get; set; }
public int IdMark { get; set; }
public DateTime DateCreated { get; set; }
public int IdFile { get; set; }
public string UserLogin { get; set; }
public string Comment { get; set; }
}
}

View File

@ -30,6 +30,9 @@ namespace AsbCloudApp.Services
string GetUrl(FileInfoDto fileInfo);
string GetUrl(int idFile);
string GetUrl(int idWell, int idCategory, int idFile, string dotExtention);
Task<FileMarkDto> CreateFileMarkAsync(int idMark, int idFile, string comment,
int fileChangerId, string fileChangerLogin, CancellationToken token = default);
Task<int> MarkFileMarkAsDeletedAsync(int idMark, CancellationToken token = default);
Task<FileInfoDto> MoveAsync(int idWell, int? idUser, int idCategory, string destinationFileName, string srcFileFullName, CancellationToken token = default);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,59 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace AsbCloudDb.Migrations
{
public partial class Add_File_Marks : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "t_file_mark",
columns: table => new
{
id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
id_mark = table.Column<int>(type: "integer", nullable: false, comment: "0 - Согласован, \n1 - Отредактирован"),
date_created = table.Column<DateTime>(type: "timestamp without time zone", nullable: false, comment: "Дата совершенного действия"),
id_file = table.Column<int>(type: "integer", nullable: false, comment: "id файла"),
id_user = table.Column<int>(type: "integer", nullable: false, comment: "id пользователя"),
comment = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true, comment: "Комментарий"),
is_deleted = table.Column<bool>(type: "boolean", nullable: false, comment: "Помечен ли файл как удаленный")
},
constraints: table =>
{
table.PrimaryKey("PK_t_file_mark", x => x.id);
table.ForeignKey(
name: "t_file_mark_t_file_info_fk",
column: x => x.id_file,
principalTable: "t_file_info",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "t_user_t_file_mark_fk",
column: x => x.id_user,
principalTable: "t_user",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
},
comment: "Действия с файлами.");
migrationBuilder.CreateIndex(
name: "IX_t_file_mark_id_file",
table: "t_file_mark",
column: "id_file");
migrationBuilder.CreateIndex(
name: "IX_t_file_mark_id_user",
table: "t_file_mark",
column: "id_user");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "t_file_mark");
}
}
}

View File

@ -539,6 +539,57 @@ namespace AsbCloudDb.Migrations
.HasComment("Файлы всех категорий");
});
modelBuilder.Entity("AsbCloudDb.Model.FileMark", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasColumnName("id")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Comment")
.HasMaxLength(255)
.HasColumnType("character varying(255)")
.HasColumnName("comment")
.HasComment("Комментарий");
b.Property<DateTime>("DateCreated")
.HasColumnType("timestamp without time zone")
.HasColumnName("date_created")
.HasComment("Дата совершенного действия");
b.Property<int>("IdFile")
.HasColumnType("integer")
.HasColumnName("id_file")
.HasComment("id файла");
b.Property<int>("IdMark")
.HasColumnType("integer")
.HasColumnName("id_mark")
.HasComment("0 - Согласован, \n1 - Отредактирован");
b.Property<int>("IdUser")
.HasColumnType("integer")
.HasColumnName("id_user")
.HasComment("id пользователя");
b.Property<bool>("IsDeleted")
.HasColumnType("boolean")
.HasColumnName("is_deleted")
.HasComment("Помечен ли файл как удаленный");
b.HasKey("Id");
b.HasIndex("IdFile");
b.HasIndex("IdUser");
b.ToTable("t_file_mark");
b
.HasComment("Действия с файлами.");
});
modelBuilder.Entity("AsbCloudDb.Model.Measure", b =>
{
b.Property<int>("Id")
@ -2371,6 +2422,27 @@ namespace AsbCloudDb.Migrations
b.Navigation("Well");
});
modelBuilder.Entity("AsbCloudDb.Model.FileMark", b =>
{
b.HasOne("AsbCloudDb.Model.FileInfo", "FileInfo")
.WithMany("FileMarks")
.HasForeignKey("IdFile")
.HasConstraintName("t_file_mark_t_file_info_fk")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("AsbCloudDb.Model.User", "Author")
.WithMany("FileMarks")
.HasForeignKey("IdUser")
.HasConstraintName("t_user_t_file_mark_fk")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Author");
b.Navigation("FileInfo");
});
modelBuilder.Entity("AsbCloudDb.Model.Measure", b =>
{
b.HasOne("AsbCloudDb.Model.MeasureCategory", "Category")
@ -2631,6 +2703,11 @@ namespace AsbCloudDb.Migrations
b.Navigation("Clusters");
});
modelBuilder.Entity("AsbCloudDb.Model.FileInfo", b =>
{
b.Navigation("FileMarks");
});
modelBuilder.Entity("AsbCloudDb.Model.MeasureCategory", b =>
{
b.Navigation("Measures");
@ -2655,6 +2732,8 @@ namespace AsbCloudDb.Migrations
modelBuilder.Entity("AsbCloudDb.Model.User", b =>
{
b.Navigation("FileMarks");
b.Navigation("Files");
});

View File

@ -17,6 +17,7 @@ namespace AsbCloudDb.Model
public virtual DbSet<Deposit> Deposits { 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; }
@ -224,6 +225,21 @@ namespace AsbCloudDb.Model
{
entity.HasIndex(d => d.IdWellOperationCategory);
});
modelBuilder.Entity<FileMark>(entity =>
{
entity.HasOne(d => d.Author)
.WithMany(p => p.FileMarks)
.HasForeignKey(d => d.IdUser)
.OnDelete(DeleteBehavior.Cascade)
.HasConstraintName("t_user_t_file_mark_fk");
entity.HasOne(d => d.FileInfo)
.WithMany(p => p.FileMarks)
.HasForeignKey(d => d.IdFile)
.OnDelete(DeleteBehavior.Cascade)
.HasConstraintName("t_file_mark_t_file_info_fk");
});
FillData(modelBuilder);
}

View File

@ -1,5 +1,6 @@
using Microsoft.EntityFrameworkCore;
using System;
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
@ -48,5 +49,8 @@ namespace AsbCloudDb.Model
[JsonIgnore]
[ForeignKey(nameof(IdCategory))]
public virtual FileCategory FileCategory { get; set; }
[InverseProperty(nameof(FileMark.FileInfo))]
public virtual ICollection<FileMark> FileMarks { get; set; }
}
}

View File

@ -0,0 +1,43 @@
using System;
using System.Text.Json.Serialization;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace AsbCloudDb.Model
{
[Table("t_file_mark"), Comment("Действия с файлами.")]
public class FileMark
{
[Key]
[Column("id")]
public int Id { get; set; }
[Column("id_mark"), Comment("0 - Согласован, \n1 - Отредактирован")]
public int IdMark { get; set; }
[Column("date_created"), Comment("Дата совершенного действия")]
public DateTime DateCreated { get; set; }
[Column("id_file"), Comment("id файла")]
public int IdFile { get; set; }
[Column("id_user"), Comment("id пользователя")]
public int IdUser { get; set; }
[Column("comment"), Comment("Комментарий")]
[StringLength(255)]
public string Comment { get; set; }
[Column("is_deleted"), Comment("Помечен ли файл как удаленный")]
public bool IsDeleted { get; set; }
[JsonIgnore]
[ForeignKey(nameof(IdUser))]
public virtual User Author { get; set; }
[JsonIgnore]
[ForeignKey(nameof(IdFile))]
public virtual FileInfo FileInfo { get; set; }
}
}

View File

@ -20,6 +20,7 @@ namespace AsbCloudDb.Model
DbSet<UserRole> UserRoles { get; set; }
DbSet<ReportProperty> ReportProperties { get; set; }
DbSet<FileInfo> Files { get; set; }
DbSet<FileMark> FileMarks { get; set; }
DbSet<FileCategory> FileCategories { get; set; }
DbSet<Telemetry> Telemetries { get; set; }
DbSet<TelemetryUser> TelemetryUsers { get; set; }

View File

@ -68,8 +68,11 @@ namespace AsbCloudDb.Model
public virtual UserRole Role { get; set; }
[InverseProperty(nameof(Model.FileInfo.Author))]
[InverseProperty(nameof(FileInfo.Author))]
public virtual ICollection<FileInfo> Files { get; set; }
[InverseProperty(nameof(FileMark.Author))]
public virtual ICollection<FileMark> FileMarks { get; set; }
public string MakeDisplayName()
{

View File

@ -243,6 +243,51 @@ namespace AsbCloudInfrastructure.Services
public string GetUrl(int idWell, int idCategory, int idFile, string dotExtention) =>
Path.Combine(RootPath, idWell.ToString(), idCategory.ToString(), $"{idFile}{dotExtention}");
public async Task<FileMarkDto> CreateFileMarkAsync(int idMark, int idFile, string comment,
int fileChangerId, string fileChangerLogin, CancellationToken token = default)
{
var fileMark = await db.FileMarks
.FirstOrDefaultAsync(t => t.IdFile == idFile &&
t.IdMark == idMark && t.IdUser == fileChangerId, token)
.ConfigureAwait(false);
if (fileMark is not null)
{
var dto = fileMark.Adapt<FileMarkDto>();
dto.UserLogin = fileChangerLogin;
return dto;
}
var newFileMark = new FileMark()
{
IdMark = idMark,
DateCreated = DateTime.Now,
IdFile = idFile,
IdUser = fileChangerId,
Comment = comment
};
db.FileMarks.Add(newFileMark);
await db.SaveChangesAsync(token);
var resultDto = newFileMark.Adapt<FileMarkDto>();
resultDto.UserLogin = fileChangerLogin;
return resultDto;
}
public async Task<int> MarkFileMarkAsDeletedAsync(int idMark, CancellationToken token = default)
{
var fileMark = await db.FileMarks.FirstOrDefaultAsync(m =>
m.Id == idMark, token);
if (fileMark is null)
return 0;
fileMark.IsDeleted = true;
return await db.SaveChangesAsync(token);
}
private async Task<string> PublishFileToCloudAsync(string filePath, string originalName,
CancellationToken token = default)

View File

@ -1,4 +1,5 @@
using AsbCloudApp.Services;
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.IO;
@ -14,11 +15,14 @@ namespace AsbCloudWebApi.Controllers
{
private readonly IDrillingProgramService drillingProgramService;
private readonly IFileService fileService;
private readonly IWellService wellService;
public DrillingProgramController(IDrillingProgramService drillingProgramService, IFileService fileService)
public DrillingProgramController(IDrillingProgramService drillingProgramService,
IFileService fileService, IWellService wellService)
{
this.drillingProgramService = drillingProgramService;
this.fileService = fileService;
this.wellService = wellService;
}
/// <summary>
@ -31,6 +35,12 @@ namespace AsbCloudWebApi.Controllers
[ProducesResponseType(typeof(FileResult), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetAsync(int idWell, CancellationToken token = default)
{
var idCompany = User.GetCompanyId();
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false))
return Forbid();
var fileInfo = await drillingProgramService.GetAsync(idWell, token)
.ConfigureAwait(false);
if (fileInfo is null)
@ -51,6 +61,12 @@ namespace AsbCloudWebApi.Controllers
[ProducesResponseType(typeof(string), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetFileWebLinkAsync(int idWell, CancellationToken token = default)
{
var idCompany = User.GetCompanyId();
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false))
return Forbid();
var fileInfo = await drillingProgramService.GetAsync(idWell, token)
.ConfigureAwait(false);
@ -64,5 +80,59 @@ namespace AsbCloudWebApi.Controllers
return Ok(fileWebUrl);
}
/// <summary>
/// Регистрирует совершенные действия с частями программы бурения
/// </summary>
/// <param name="idWell"> id скважины </param>
/// <param name="idMark"> id действия </param>
/// <param name="idFile"> id файла </param>
/// <param name="comment"> Комментарий </param>
/// <param name="token"> Токен отмены задачи </param>
/// <returns></returns>
[HttpPost("fileMark")]
[ProducesResponseType(typeof(FileMarkDto), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> CreateFileMarkAsync(int idWell, int idMark,
int idFile, string comment, CancellationToken token = default)
{
var idCompany = User.GetCompanyId();
var fileChangerId = User.GetUserId();
var fileChangerLogin = User.Identity?.Name ?? "";
if (idCompany is null || fileChangerId is null ||
!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false))
return Forbid();
var result = await fileService.CreateFileMarkAsync(idMark, idFile, comment,
(int)fileChangerId, fileChangerLogin, token)
.ConfigureAwait(false);
return Ok(result);
}
/// <summary>
/// Удаляет отметку о действии с файлом-частью программы бурения
/// </summary>
/// <param name="idWell"> id скважины </param>
/// <param name="idMark"> id действия </param>
/// <param name="token"> Токен отмены задачи </param>
/// <returns></returns>
[HttpDelete("fileMark")]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> DeleteFileMarkAsync(int idWell, int idMark,
CancellationToken token = default)
{
var idCompany = User.GetCompanyId();
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false))
return Forbid();
var result = await fileService.MarkFileMarkAsDeletedAsync(idMark, token);
return Ok(result);
}
}
}