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(FileInfoDto fileInfo);
|
||||||
string GetUrl(int idFile);
|
string GetUrl(int idFile);
|
||||||
string GetUrl(int idWell, int idCategory, int idFile, string dotExtention);
|
string GetUrl(int idWell, int idCategory, int idFile, string dotExtention);
|
||||||
Task<FileMarkDto> CreateFileMarkAsync(int idMark, int idFile, string comment,
|
Task<int> CreateFileMarkAsync(int idWell, int idMarkType, int idProgramPartFile, string comment,
|
||||||
int fileChangerId, string fileChangerLogin, CancellationToken token = default);
|
int fileChangerId, string fileChangerLogin, CancellationToken token);
|
||||||
Task<int> MarkFileMarkAsDeletedAsync(int idMark, CancellationToken token = default);
|
Task<int> MarkFileMarkAsDeletedAsync(int idWell, int idMark, CancellationToken token);
|
||||||
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);
|
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")
|
.HasColumnName("id_file")
|
||||||
.HasComment("id файла");
|
.HasComment("id файла");
|
||||||
|
|
||||||
b.Property<int>("IdMark")
|
b.Property<int>("IdMarkType")
|
||||||
.HasColumnType("integer")
|
.HasColumnType("integer")
|
||||||
.HasColumnName("id_mark")
|
.HasColumnName("id_mark_type")
|
||||||
.HasComment("0 - Согласован, \n1 - Уже внесен в программу бурения");
|
.HasComment("0 - Согласован");
|
||||||
|
|
||||||
b.Property<int>("IdUser")
|
b.Property<int>("IdUser")
|
||||||
.HasColumnType("integer")
|
.HasColumnType("integer")
|
||||||
|
@ -13,8 +13,8 @@ namespace AsbCloudDb.Model
|
|||||||
[Column("id")]
|
[Column("id")]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
[Column("id_mark"), Comment("0 - Согласован, \n1 - Уже внесен в программу бурения")]
|
[Column("id_mark_type"), Comment("0 - Согласован")]
|
||||||
public int IdMark { get; set; }
|
public int IdMarkType { get; set; }
|
||||||
|
|
||||||
[Column("date_created"), Comment("Дата совершенного действия")]
|
[Column("date_created"), Comment("Дата совершенного действия")]
|
||||||
public DateTime DateCreated { get; set; }
|
public DateTime DateCreated { get; set; }
|
||||||
|
@ -35,7 +35,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
var matchFiles = await fileService.GetInfosByCategoryAsync(idWell, idFileCategoryDrillingProgram, token)
|
var matchFiles = await fileService.GetInfosByCategoryAsync(idWell, idFileCategoryDrillingProgram, token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
if (matchFiles is not null && matchFiles.Any())
|
if (matchFiles is not null && matchFiles.Any())
|
||||||
{
|
{
|
||||||
matchFiles = matchFiles.OrderByDescending(f => f.UploadDate);
|
matchFiles = matchFiles.OrderByDescending(f => f.UploadDate);
|
||||||
@ -46,26 +46,24 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
await fileService.DeleteAsync(matchFilesIterator.Current.Id, token)
|
await fileService.DeleteAsync(matchFilesIterator.Current.Id, token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
if (filesInfos.All(f => f.UploadDate <= matchFile.UploadDate &&
|
if (File.Exists(fileService.GetUrl(matchFile)))
|
||||||
f.FileMarks.Any(fm => fm.IdMark == 1)))
|
|
||||||
return matchFile;
|
return matchFile;
|
||||||
else
|
else
|
||||||
await fileService.DeleteAsync(matchFile.Id, token)
|
await fileService.DeleteAsync(matchFile.Id, token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
var resultFileName = $"Программа бурения {well.Cluster} {well.Caption}.xlsx";
|
var resultFileName = $"Программа бурения {well.Cluster} {well.Caption}.xlsx";
|
||||||
|
|
||||||
var filteredFileInfos = filesInfos
|
var filteredFilePaths = filesInfos
|
||||||
.Where(f => f.Name != resultFileName &&
|
.Where(f => f.Name != resultFileName &&
|
||||||
f.FileMarks != null &&
|
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);
|
var tempResultFilePath = Path.Combine(Path.GetTempPath(), "drillingProgram", resultFileName);
|
||||||
|
|
||||||
UniteExcelFiles(filteredFileInfos.Select(f => fileService.GetUrl(f)), tempResultFilePath);
|
UniteExcelFiles(filteredFilePaths, tempResultFilePath);
|
||||||
|
|
||||||
await fileService.MarkFileInfosAsUsedInProgramAsync(filteredFileInfos, fileChangerId, token);
|
|
||||||
|
|
||||||
var fileInfo = await fileService.MoveAsync(idWell, null, idFileCategoryDrillingProgram,
|
var fileInfo = await fileService.MoveAsync(idWell, null, idFileCategoryDrillingProgram,
|
||||||
resultFileName, tempResultFilePath, token).ConfigureAwait(false);
|
resultFileName, tempResultFilePath, token).ConfigureAwait(false);
|
||||||
|
@ -48,33 +48,8 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
return fileWebLink;
|
return fileWebLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<int> MarkFileInfosAsUsedInProgramAsync(IEnumerable<FileInfoDto> fiDtos,
|
public async Task<FileInfoDto> MoveAsync(int idWell, int? idUser, int idCategory,
|
||||||
int fileChangerId, CancellationToken token = default)
|
string destinationFileName, string srcFilePath, 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);
|
destinationFileName = Path.GetFileName(destinationFileName);
|
||||||
srcFilePath = Path.GetFullPath(srcFilePath);
|
srcFilePath = Path.GetFullPath(srcFilePath);
|
||||||
@ -106,7 +81,8 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
return dto;
|
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
|
//save info to db
|
||||||
var fileInfo = new AsbCloudDb.Model.FileInfo()
|
var fileInfo = new AsbCloudDb.Model.FileInfo()
|
||||||
@ -274,49 +250,42 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
public string GetUrl(int idWell, int idCategory, int idFile, string dotExtention) =>
|
public string GetUrl(int idWell, int idCategory, int idFile, string dotExtention) =>
|
||||||
Path.Combine(RootPath, idWell.ToString(), idCategory.ToString(), $"{idFile}{dotExtention}");
|
Path.Combine(RootPath, idWell.ToString(), idCategory.ToString(), $"{idFile}{dotExtention}");
|
||||||
|
|
||||||
public async Task<FileMarkDto> CreateFileMarkAsync(int idMark, int idFile, string comment,
|
public async Task<int> CreateFileMarkAsync(int idWell, int idMarkType, int idProgramPartFile, string comment,
|
||||||
int fileChangerId, string fileChangerLogin, CancellationToken token = default)
|
int fileChangerId, string fileChangerLogin, CancellationToken token)
|
||||||
{
|
{
|
||||||
var fileMark = await db.FileMarks
|
var fileMark = await db.FileMarks
|
||||||
.FirstOrDefaultAsync(t => t.IdFile == idFile &&
|
.FirstOrDefaultAsync(t => t.IdFile == idProgramPartFile &&
|
||||||
t.IdMark == idMark && t.IdUser == fileChangerId, token)
|
t.IdMarkType == idMarkType && t.IdUser == fileChangerId, token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
if (fileMark is not null)
|
if (fileMark is not null)
|
||||||
{
|
return 0;
|
||||||
var dto = fileMark.Adapt<FileMarkDto>();
|
|
||||||
dto.UserLogin = fileChangerLogin;
|
|
||||||
return dto;
|
|
||||||
}
|
|
||||||
|
|
||||||
var newFileMark = new FileMark()
|
var newFileMark = new FileMark()
|
||||||
{
|
{
|
||||||
IdMark = idMark,
|
IdMarkType = idMarkType,
|
||||||
DateCreated = DateTime.Now,
|
DateCreated = DateTime.Now,
|
||||||
IdFile = idFile,
|
IdFile = idProgramPartFile,
|
||||||
IdUser = fileChangerId,
|
IdUser = fileChangerId,
|
||||||
Comment = comment
|
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);
|
db.FileMarks.Add(newFileMark);
|
||||||
await db.SaveChangesAsync(token);
|
return await db.SaveChangesAsync(token);
|
||||||
|
|
||||||
var resultDto = newFileMark.Adapt<FileMarkDto>();
|
|
||||||
resultDto.UserLogin = fileChangerLogin;
|
|
||||||
|
|
||||||
return resultDto;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 =>
|
var existingPrograms = await GetInfosByCategoryAsync(idWell, 14, token);
|
||||||
m.Id == idMark, token);
|
if (existingPrograms is not null && existingPrograms.Any())
|
||||||
if (fileMark is null)
|
await DeleteAsync(existingPrograms.First().Id, token);
|
||||||
return 0;
|
|
||||||
|
return await MarkAsDeletedAsync(idFile, token);
|
||||||
fileMark.IsDeleted = true;
|
|
||||||
|
|
||||||
return await db.SaveChangesAsync(token);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<string> PublishFileToCloudAsync(string filePath, string originalName,
|
private async Task<string> PublishFileToCloudAsync(string filePath, string originalName,
|
||||||
|
@ -114,8 +114,9 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
idWell, token).ConfigureAwait(false))
|
idWell, token).ConfigureAwait(false))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var result = await fileService.CreateFileMarkAsync(idMark, idFile, comment,
|
var result = await fileService.CreateFileMarkAsync(idWell, idMark,
|
||||||
(int)fileChangerId, fileChangerLogin, token)
|
idFile, comment, (int)fileChangerId, fileChangerLogin,
|
||||||
|
token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
@ -125,12 +126,12 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// Удаляет отметку о действии с файлом-частью программы бурения
|
/// Удаляет отметку о действии с файлом-частью программы бурения
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell"> id скважины </param>
|
/// <param name="idWell"> id скважины </param>
|
||||||
/// <param name="idMark"> id действия </param>
|
/// <param name="idFile"> id действия </param>
|
||||||
/// <param name="token"> Токен отмены задачи </param>
|
/// <param name="token"> Токен отмены задачи </param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpDelete("fileMark")]
|
[HttpDelete("fileMark")]
|
||||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
[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)
|
CancellationToken token = default)
|
||||||
{
|
{
|
||||||
var idCompany = User.GetCompanyId();
|
var idCompany = User.GetCompanyId();
|
||||||
@ -139,7 +140,8 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
idWell, token).ConfigureAwait(false))
|
idWell, token).ConfigureAwait(false))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var result = await fileService.MarkFileMarkAsDeletedAsync(idMark, token);
|
var result = await fileService.MarkFileMarkAsDeletedAsync(idWell,
|
||||||
|
idFile, token);
|
||||||
|
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user