forked from ddrilling/AsbCloudServer
CS2-104: Added deleting of existing drilling program on file marks actions
This commit is contained in:
parent
2f2193da76
commit
e716c6fbeb
@ -30,11 +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<int> MarkFileInfosAsUsedInProgramAsync(IEnumerable<FileInfoDto> fiDtos,
|
||||
int fileChangerId, CancellationToken token = default);
|
||||
Task<int> CreateFileMarkAsync(int idWell, int idMarkType, int idProgramPartFile, string comment,
|
||||
int fileChangerId, string fileChangerLogin, CancellationToken token);
|
||||
Task<int> MarkFileMarkAsDeletedAsync(int idWell, int idMark, CancellationToken token);
|
||||
Task<FileInfoDto> MoveAsync(int idWell, int? idUser, int idCategory, string destinationFileName, string srcFileFullName, CancellationToken token = default);
|
||||
}
|
||||
}
|
||||
|
2779
AsbCloudDb/Migrations/20211103084625_Rename_IdMark_To_IdMarkType.Designer.cs
generated
Normal file
2779
AsbCloudDb/Migrations/20211103084625_Rename_IdMark_To_IdMarkType.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,37 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace AsbCloudDb.Migrations
|
||||
{
|
||||
public partial class Rename_IdMark_To_IdMarkType : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "id_mark",
|
||||
table: "t_file_mark");
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "id_mark_type",
|
||||
table: "t_file_mark",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0,
|
||||
comment: "0 - Согласован");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "id_mark_type",
|
||||
table: "t_file_mark");
|
||||
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "id_mark",
|
||||
table: "t_file_mark",
|
||||
type: "integer",
|
||||
nullable: false,
|
||||
defaultValue: 0,
|
||||
comment: "0 - Согласован, \n1 - Уже внесен в программу бурения");
|
||||
}
|
||||
}
|
||||
}
|
@ -563,10 +563,10 @@ namespace AsbCloudDb.Migrations
|
||||
.HasColumnName("id_file")
|
||||
.HasComment("id файла");
|
||||
|
||||
b.Property<int>("IdMark")
|
||||
b.Property<int>("IdMarkType")
|
||||
.HasColumnType("integer")
|
||||
.HasColumnName("id_mark")
|
||||
.HasComment("0 - Согласован, \n1 - Уже внесен в программу бурения");
|
||||
.HasColumnName("id_mark_type")
|
||||
.HasComment("0 - Согласован");
|
||||
|
||||
b.Property<int>("IdUser")
|
||||
.HasColumnType("integer")
|
||||
|
@ -13,8 +13,8 @@ namespace AsbCloudDb.Model
|
||||
[Column("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Column("id_mark"), Comment("0 - Согласован, \n1 - Уже внесен в программу бурения")]
|
||||
public int IdMark { get; set; }
|
||||
[Column("id_mark_type"), Comment("0 - Согласован")]
|
||||
public int IdMarkType { get; set; }
|
||||
|
||||
[Column("date_created"), Comment("Дата совершенного действия")]
|
||||
public DateTime DateCreated { get; set; }
|
||||
|
@ -35,7 +35,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
var matchFiles = await fileService.GetInfosByCategoryAsync(idWell, idFileCategoryDrillingProgram, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
|
||||
if (matchFiles is not null && matchFiles.Any())
|
||||
{
|
||||
matchFiles = matchFiles.OrderByDescending(f => f.UploadDate);
|
||||
@ -46,26 +46,24 @@ namespace AsbCloudInfrastructure.Services
|
||||
await fileService.DeleteAsync(matchFilesIterator.Current.Id, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (filesInfos.All(f => f.UploadDate <= matchFile.UploadDate &&
|
||||
f.FileMarks.Any(fm => fm.IdMark == 1)))
|
||||
if (File.Exists(fileService.GetUrl(matchFile)))
|
||||
return matchFile;
|
||||
else
|
||||
await fileService.DeleteAsync(matchFile.Id, token)
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
||||
var resultFileName = $"Программа бурения {well.Cluster} {well.Caption}.xlsx";
|
||||
|
||||
var filteredFileInfos = filesInfos
|
||||
|
||||
var filteredFilePaths = filesInfos
|
||||
.Where(f => f.Name != resultFileName &&
|
||||
f.FileMarks != null &&
|
||||
f.FileMarks.Any(file => file.IdMark == 0));
|
||||
f.FileMarks.Any(file => file.IdMark == 0))
|
||||
.Select(file => fileService.GetUrl(file));
|
||||
|
||||
var tempResultFilePath = Path.Combine(Path.GetTempPath(), "drillingProgram", resultFileName);
|
||||
|
||||
UniteExcelFiles(filteredFileInfos.Select(f => fileService.GetUrl(f)), tempResultFilePath);
|
||||
|
||||
await fileService.MarkFileInfosAsUsedInProgramAsync(filteredFileInfos, fileChangerId, token);
|
||||
UniteExcelFiles(filteredFilePaths, tempResultFilePath);
|
||||
|
||||
var fileInfo = await fileService.MoveAsync(idWell, null, idFileCategoryDrillingProgram,
|
||||
resultFileName, tempResultFilePath, token).ConfigureAwait(false);
|
||||
|
@ -48,33 +48,8 @@ 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)
|
||||
public async Task<FileInfoDto> MoveAsync(int idWell, int? idUser, int idCategory,
|
||||
string destinationFileName, string srcFilePath, CancellationToken token = default)
|
||||
{
|
||||
destinationFileName = Path.GetFileName(destinationFileName);
|
||||
srcFilePath = Path.GetFullPath(srcFilePath);
|
||||
@ -106,7 +81,8 @@ namespace AsbCloudInfrastructure.Services
|
||||
return dto;
|
||||
}
|
||||
|
||||
public async Task<FileInfoDto> SaveAsync(int idWell, int? idUser, int idCategory, string fileFullName, Stream fileStream, CancellationToken token = default)
|
||||
public async Task<FileInfoDto> SaveAsync(int idWell, int? idUser, int idCategory,
|
||||
string fileFullName, Stream fileStream, CancellationToken token = default)
|
||||
{
|
||||
//save info to db
|
||||
var fileInfo = new AsbCloudDb.Model.FileInfo()
|
||||
@ -274,49 +250,42 @@ 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)
|
||||
public async Task<int> CreateFileMarkAsync(int idWell, int idMarkType, int idProgramPartFile, string comment,
|
||||
int fileChangerId, string fileChangerLogin, CancellationToken token)
|
||||
{
|
||||
var fileMark = await db.FileMarks
|
||||
.FirstOrDefaultAsync(t => t.IdFile == idFile &&
|
||||
t.IdMark == idMark && t.IdUser == fileChangerId, token)
|
||||
.FirstOrDefaultAsync(t => t.IdFile == idProgramPartFile &&
|
||||
t.IdMarkType == idMarkType && t.IdUser == fileChangerId, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (fileMark is not null)
|
||||
{
|
||||
var dto = fileMark.Adapt<FileMarkDto>();
|
||||
dto.UserLogin = fileChangerLogin;
|
||||
return dto;
|
||||
}
|
||||
return 0;
|
||||
|
||||
var newFileMark = new FileMark()
|
||||
{
|
||||
IdMark = idMark,
|
||||
IdMarkType = idMarkType,
|
||||
DateCreated = DateTime.Now,
|
||||
IdFile = idFile,
|
||||
IdFile = idProgramPartFile,
|
||||
IdUser = fileChangerId,
|
||||
Comment = comment
|
||||
};
|
||||
|
||||
var existingPrograms = await GetInfosByCategoryAsync(idWell, 14, token);
|
||||
if (existingPrograms is not null && existingPrograms.Any())
|
||||
await DeleteAsync(existingPrograms.First().Id, token);
|
||||
|
||||
db.FileMarks.Add(newFileMark);
|
||||
await db.SaveChangesAsync(token);
|
||||
|
||||
var resultDto = newFileMark.Adapt<FileMarkDto>();
|
||||
resultDto.UserLogin = fileChangerLogin;
|
||||
|
||||
return resultDto;
|
||||
return await db.SaveChangesAsync(token);
|
||||
}
|
||||
|
||||
public async Task<int> MarkFileMarkAsDeletedAsync(int idMark, CancellationToken token = default)
|
||||
public async Task<int> MarkFileMarkAsDeletedAsync(int idWell, int idFile,
|
||||
CancellationToken token)
|
||||
{
|
||||
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);
|
||||
var existingPrograms = await GetInfosByCategoryAsync(idWell, 14, token);
|
||||
if (existingPrograms is not null && existingPrograms.Any())
|
||||
await DeleteAsync(existingPrograms.First().Id, token);
|
||||
|
||||
return await MarkAsDeletedAsync(idFile, token);
|
||||
}
|
||||
|
||||
private async Task<string> PublishFileToCloudAsync(string filePath, string originalName,
|
||||
|
@ -114,8 +114,9 @@ namespace AsbCloudWebApi.Controllers
|
||||
idWell, token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
|
||||
var result = await fileService.CreateFileMarkAsync(idMark, idFile, comment,
|
||||
(int)fileChangerId, fileChangerLogin, token)
|
||||
var result = await fileService.CreateFileMarkAsync(idWell, idMark,
|
||||
idFile, comment, (int)fileChangerId, fileChangerLogin,
|
||||
token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return Ok(result);
|
||||
@ -125,12 +126,12 @@ namespace AsbCloudWebApi.Controllers
|
||||
/// Удаляет отметку о действии с файлом-частью программы бурения
|
||||
/// </summary>
|
||||
/// <param name="idWell"> id скважины </param>
|
||||
/// <param name="idMark"> id действия </param>
|
||||
/// <param name="idFile"> 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,
|
||||
public async Task<IActionResult> DeleteFileMarkAsync(int idWell, int idFile,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
var idCompany = User.GetCompanyId();
|
||||
@ -139,7 +140,8 @@ namespace AsbCloudWebApi.Controllers
|
||||
idWell, token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
|
||||
var result = await fileService.MarkFileMarkAsDeletedAsync(idMark, token);
|
||||
var result = await fileService.MarkFileMarkAsDeletedAsync(idWell,
|
||||
idFile, token);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user