This commit is contained in:
Фролов 2021-11-02 17:50:52 +05:00
commit f62ec98ea9
17 changed files with 5993 additions and 17 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

@ -6,6 +6,7 @@ namespace AsbCloudApp.Services
{
public interface IDrillingProgramService
{
Task<FileInfoDto> GetAsync(int idWell, CancellationToken token = default);
Task<FileInfoDto> GetAsync(int idWell, int fileChangerId,
CancellationToken token = default);
}
}

View File

@ -30,6 +30,11 @@ 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<int> MarkFileInfosAsUsedInProgramAsync(IEnumerable<FileInfoDto> fiDtos,
int fileChangerId, 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");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,33 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace AsbCloudDb.Migrations
{
public partial class Change_File_Mark_Comment : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<int>(
name: "id_mark",
table: "t_file_mark",
type: "integer",
nullable: false,
comment: "0 - Согласован, \n1 - Уже внесен в программу бурения",
oldClrType: typeof(int),
oldType: "integer",
oldComment: "0 - Согласован, \n1 - Отредактирован");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<int>(
name: "id_mark",
table: "t_file_mark",
type: "integer",
nullable: false,
comment: "0 - Согласован, \n1 - Отредактирован",
oldClrType: typeof(int),
oldType: "integer",
oldComment: "0 - Согласован, \n1 - Уже внесен в программу бурения");
}
}
}

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

@ -25,7 +25,7 @@ namespace AsbCloudInfrastructure.Services
this.wellService = wellService;
}
public async Task<FileInfoDto> GetAsync(int idWell, CancellationToken token = default)
public async Task<FileInfoDto> GetAsync(int idWell, int fileChangerId, CancellationToken token = default)
{
var filesInfos = await fileService.GetInfosByCategoryAsync(idWell, idFileCategoryDrillingProgramItems, token)
.ConfigureAwait(false);
@ -46,7 +46,8 @@ namespace AsbCloudInfrastructure.Services
await fileService.DeleteAsync(matchFilesIterator.Current.Id, token)
.ConfigureAwait(false);
if (filesInfos.All(f => f.UploadDate <= matchFile.UploadDate))
if (filesInfos.All(f => f.UploadDate <= matchFile.UploadDate &&
f.FileMarks.Any(fm => fm.IdMark == 1)))
return matchFile;
else
await fileService.DeleteAsync(matchFile.Id, token)
@ -55,13 +56,16 @@ namespace AsbCloudInfrastructure.Services
var resultFileName = $"Программа бурения {well.Cluster} {well.Caption}.xlsx";
var fileNames = filesInfos
.Where(f => f.Name != resultFileName)
.Select(f => fileService.GetUrl(f));
var filteredFileInfos = filesInfos
.Where(f => f.Name != resultFileName &&
f.FileMarks != null &&
f.FileMarks.Any(file => file.IdMark == 0));
var tempResultFilePath = Path.Combine(Path.GetTempPath(), "drillingProgram", resultFileName);
UniteExcelFiles(fileNames, tempResultFilePath);
UniteExcelFiles(filteredFileInfos.Select(f => fileService.GetUrl(f)), tempResultFilePath);
await fileService.MarkFileInfosAsUsedInProgramAsync(filteredFileInfos, fileChangerId, token);
var fileInfo = await fileService.MoveAsync(idWell, null, idFileCategoryDrillingProgram,
resultFileName, tempResultFilePath, token).ConfigureAwait(false);

View File

@ -48,6 +48,32 @@ namespace AsbCloudInfrastructure.Services
return fileWebLink;
}
public async Task<int> MarkFileInfosAsUsedInProgramAsync(IEnumerable<FileInfoDto> fiDtos,
int fileChangerId, CancellationToken token = default)
{
var ids = fiDtos.Select(f => f.Id);
var fileInfos = await db.Files.Where(f => ids.Contains(f.Id))
.Include(f => f.FileMarks)
.ToListAsync(token)
.ConfigureAwait(false);
fileInfos.ForEach(f =>
{
if (!f.FileMarks.Any(fm => fm.IdMark == 1))
{
f.FileMarks.Add(new FileMark()
{
IdMark = 1,
DateCreated = DateTime.Now,
IdFile = f.Id,
IdUser = fileChangerId
});
}
});
return await db.SaveChangesAsync(token);
}
public async Task<FileInfoDto> MoveAsync(int idWell, int? idUser, int idCategory, string destinationFileName, string srcFilePath, CancellationToken token = default)
{
destinationFileName = Path.GetFileName(destinationFileName);
@ -120,6 +146,7 @@ namespace AsbCloudInfrastructure.Services
int idCategory, CancellationToken token = default)
{
var entities = await dbSetConfigured
.Include(f => f.FileMarks)
.Where(e => e.IdWell == idWell && e.IdCategory == idCategory && e.IsDeleted == false)
.AsNoTracking()
.ToListAsync(token)
@ -134,14 +161,17 @@ namespace AsbCloudInfrastructure.Services
DateTime end = default, int skip = 0, int take = 32, CancellationToken token = default)
{
var query = dbSetConfigured
.Where(e => e.IdWell == idWell &&
e.IdCategory == idCategory);
.Where(e => e.IdWell == idWell &&
e.IdCategory == idCategory);
query = query.Where(e => !e.IsDeleted);
if (idCategory == 13)
query = query.Include(f => f.FileMarks);
if (!string.IsNullOrEmpty(companyName))
query = query
.Include(file => file.Author)
.Include(file => file.Author)
.ThenInclude(a => a.Company)
.Where(e => (e.Author == null) || (e.Author.Company == null) || e.Author.Company.Caption.Contains(companyName));
@ -243,6 +273,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,8 +35,19 @@ namespace AsbCloudWebApi.Controllers
[ProducesResponseType(typeof(FileResult), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetAsync(int idWell, CancellationToken token = default)
{
var fileInfo = await drillingProgramService.GetAsync(idWell, token)
var idCompany = User.GetCompanyId();
var fileChangerId = User.GetUserId();
if (idCompany is null || fileChangerId is null ||
!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false))
return Forbid();
var fileInfo = await drillingProgramService.GetAsync(idWell,
(int)fileChangerId, token)
.ConfigureAwait(false);
if (fileInfo is null)
return NoContent();
@ -51,7 +66,17 @@ namespace AsbCloudWebApi.Controllers
[ProducesResponseType(typeof(string), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetFileWebLinkAsync(int idWell, CancellationToken token = default)
{
var fileInfo = await drillingProgramService.GetAsync(idWell, token)
var idCompany = User.GetCompanyId();
var fileChangerId = User.GetUserId();
if (idCompany is null || fileChangerId is null ||
!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false))
return Forbid();
var fileInfo = await drillingProgramService.GetAsync(idWell,
(int)fileChangerId, token)
.ConfigureAwait(false);
if (fileInfo is null)
@ -64,5 +89,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);
}
}
}