CS2-104: Added recreate of drilling program if new files were confirmed

This commit is contained in:
cult 2021-11-02 16:33:49 +05:00
parent e396066a68
commit 2f2193da76
9 changed files with 2866 additions and 14 deletions

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

@ -33,6 +33,8 @@ namespace AsbCloudApp.Services
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,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

@ -566,7 +566,7 @@ namespace AsbCloudDb.Migrations
b.Property<int>("IdMark")
.HasColumnType("integer")
.HasColumnName("id_mark")
.HasComment("0 - Согласован, \n1 - Отредактирован");
.HasComment("0 - Согласован, \n1 - Уже внесен в программу бурения");
b.Property<int>("IdUser")
.HasColumnType("integer")

View File

@ -13,7 +13,7 @@ namespace AsbCloudDb.Model
[Column("id")]
public int Id { get; set; }
[Column("id_mark"), Comment("0 - Согласован, \n1 - Отредактирован")]
[Column("id_mark"), Comment("0 - Согласован, \n1 - Уже внесен в программу бурения")]
public int IdMark { get; set; }
[Column("date_created"), Comment("Дата совершенного действия")]

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,15 +56,16 @@ namespace AsbCloudInfrastructure.Services
var resultFileName = $"Программа бурения {well.Cluster} {well.Caption}.xlsx";
var fileNames = filesInfos
var filteredFileInfos = filesInfos
.Where(f => f.Name != resultFileName &&
f.FileMarks != null &&
f.FileMarks.Any(file => file.IdMark == 0))
.Select(f => fileService.GetUrl(f));
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);

View File

@ -37,12 +37,17 @@ namespace AsbCloudWebApi.Controllers
{
var idCompany = User.GetCompanyId();
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false))
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, token)
var fileInfo = await drillingProgramService.GetAsync(idWell,
(int)fileChangerId, token)
.ConfigureAwait(false);
if (fileInfo is null)
return NoContent();
@ -63,11 +68,15 @@ namespace AsbCloudWebApi.Controllers
{
var idCompany = User.GetCompanyId();
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
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, token)
var fileInfo = await drillingProgramService.GetAsync(idWell,
(int)fileChangerId, token)
.ConfigureAwait(false);
if (fileInfo is null)