forked from ddrilling/AsbCloudServer
Merge branch 'dev' of https://bitbucket.org/autodrilling/asbcloudserver into dev
This commit is contained in:
commit
f62ec98ea9
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace AsbCloudApp.Data
|
namespace AsbCloudApp.Data
|
||||||
{
|
{
|
||||||
@ -13,5 +14,6 @@ namespace AsbCloudApp.Data
|
|||||||
public long Size { get; set; }
|
public long Size { get; set; }
|
||||||
public FilePublishInfoDto PublishInfo { get; set; }
|
public FilePublishInfoDto PublishInfo { get; set; }
|
||||||
public UserDto Author { get; set; }
|
public UserDto Author { get; set; }
|
||||||
|
public IEnumerable<FileMarkDto> FileMarks { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
14
AsbCloudApp/Data/FileMarkDto.cs
Normal file
14
AsbCloudApp/Data/FileMarkDto.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,7 @@ namespace AsbCloudApp.Services
|
|||||||
{
|
{
|
||||||
public interface IDrillingProgramService
|
public interface IDrillingProgramService
|
||||||
{
|
{
|
||||||
Task<FileInfoDto> GetAsync(int idWell, CancellationToken token = default);
|
Task<FileInfoDto> GetAsync(int idWell, int fileChangerId,
|
||||||
|
CancellationToken token = default);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -30,6 +30,11 @@ 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,
|
||||||
|
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);
|
Task<FileInfoDto> MoveAsync(int idWell, int? idUser, int idCategory, string destinationFileName, string srcFileFullName, CancellationToken token = default);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2779
AsbCloudDb/Migrations/20211101112932_Add_File_Marks.Designer.cs
generated
Normal file
2779
AsbCloudDb/Migrations/20211101112932_Add_File_Marks.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
59
AsbCloudDb/Migrations/20211101112932_Add_File_Marks.cs
Normal file
59
AsbCloudDb/Migrations/20211101112932_Add_File_Marks.cs
Normal 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
2779
AsbCloudDb/Migrations/20211102113125_Change_File_Mark_Comment.Designer.cs
generated
Normal file
2779
AsbCloudDb/Migrations/20211102113125_Change_File_Mark_Comment.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -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 - Уже внесен в программу бурения");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -539,6 +539,57 @@ namespace AsbCloudDb.Migrations
|
|||||||
.HasComment("Файлы всех категорий");
|
.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 =>
|
modelBuilder.Entity("AsbCloudDb.Model.Measure", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@ -2371,6 +2422,27 @@ namespace AsbCloudDb.Migrations
|
|||||||
b.Navigation("Well");
|
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 =>
|
modelBuilder.Entity("AsbCloudDb.Model.Measure", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("AsbCloudDb.Model.MeasureCategory", "Category")
|
b.HasOne("AsbCloudDb.Model.MeasureCategory", "Category")
|
||||||
@ -2631,6 +2703,11 @@ namespace AsbCloudDb.Migrations
|
|||||||
b.Navigation("Clusters");
|
b.Navigation("Clusters");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("AsbCloudDb.Model.FileInfo", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("FileMarks");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("AsbCloudDb.Model.MeasureCategory", b =>
|
modelBuilder.Entity("AsbCloudDb.Model.MeasureCategory", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("Measures");
|
b.Navigation("Measures");
|
||||||
@ -2655,6 +2732,8 @@ namespace AsbCloudDb.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("AsbCloudDb.Model.User", b =>
|
modelBuilder.Entity("AsbCloudDb.Model.User", b =>
|
||||||
{
|
{
|
||||||
|
b.Navigation("FileMarks");
|
||||||
|
|
||||||
b.Navigation("Files");
|
b.Navigation("Files");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ namespace AsbCloudDb.Model
|
|||||||
public virtual DbSet<Deposit> Deposits { get; set; }
|
public virtual DbSet<Deposit> Deposits { get; set; }
|
||||||
public virtual DbSet<FileCategory> FileCategories { get; set; }
|
public virtual DbSet<FileCategory> FileCategories { get; set; }
|
||||||
public virtual DbSet<FileInfo> Files { 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<Measure> Measures { get; set; }
|
||||||
public virtual DbSet<MeasureCategory> MeasureCategories { get; set; }
|
public virtual DbSet<MeasureCategory> MeasureCategories { get; set; }
|
||||||
public virtual DbSet<ReportProperty> ReportProperties { get; set; }
|
public virtual DbSet<ReportProperty> ReportProperties { get; set; }
|
||||||
@ -225,6 +226,21 @@ namespace AsbCloudDb.Model
|
|||||||
entity.HasIndex(d => d.IdWellOperationCategory);
|
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);
|
FillData(modelBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
@ -48,5 +49,8 @@ namespace AsbCloudDb.Model
|
|||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
[ForeignKey(nameof(IdCategory))]
|
[ForeignKey(nameof(IdCategory))]
|
||||||
public virtual FileCategory FileCategory { get; set; }
|
public virtual FileCategory FileCategory { get; set; }
|
||||||
|
|
||||||
|
[InverseProperty(nameof(FileMark.FileInfo))]
|
||||||
|
public virtual ICollection<FileMark> FileMarks { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
43
AsbCloudDb/Model/FileMark.cs
Normal file
43
AsbCloudDb/Model/FileMark.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
@ -20,6 +20,7 @@ namespace AsbCloudDb.Model
|
|||||||
DbSet<UserRole> UserRoles { get; set; }
|
DbSet<UserRole> UserRoles { get; set; }
|
||||||
DbSet<ReportProperty> ReportProperties { get; set; }
|
DbSet<ReportProperty> ReportProperties { get; set; }
|
||||||
DbSet<FileInfo> Files { get; set; }
|
DbSet<FileInfo> Files { get; set; }
|
||||||
|
DbSet<FileMark> FileMarks { get; set; }
|
||||||
DbSet<FileCategory> FileCategories { get; set; }
|
DbSet<FileCategory> FileCategories { get; set; }
|
||||||
DbSet<Telemetry> Telemetries { get; set; }
|
DbSet<Telemetry> Telemetries { get; set; }
|
||||||
DbSet<TelemetryUser> TelemetryUsers { get; set; }
|
DbSet<TelemetryUser> TelemetryUsers { get; set; }
|
||||||
|
@ -68,9 +68,12 @@ namespace AsbCloudDb.Model
|
|||||||
public virtual UserRole Role { get; set; }
|
public virtual UserRole Role { get; set; }
|
||||||
|
|
||||||
|
|
||||||
[InverseProperty(nameof(Model.FileInfo.Author))]
|
[InverseProperty(nameof(FileInfo.Author))]
|
||||||
public virtual ICollection<FileInfo> Files { get; set; }
|
public virtual ICollection<FileInfo> Files { get; set; }
|
||||||
|
|
||||||
|
[InverseProperty(nameof(FileMark.Author))]
|
||||||
|
public virtual ICollection<FileMark> FileMarks { get; set; }
|
||||||
|
|
||||||
public string MakeDisplayName()
|
public string MakeDisplayName()
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(Surname))
|
if (string.IsNullOrEmpty(Surname))
|
||||||
|
@ -25,7 +25,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
this.wellService = wellService;
|
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)
|
var filesInfos = await fileService.GetInfosByCategoryAsync(idWell, idFileCategoryDrillingProgramItems, token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
@ -46,7 +46,8 @@ 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 (filesInfos.All(f => f.UploadDate <= matchFile.UploadDate &&
|
||||||
|
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)
|
||||||
@ -55,13 +56,16 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
var resultFileName = $"Программа бурения {well.Cluster} {well.Caption}.xlsx";
|
var resultFileName = $"Программа бурения {well.Cluster} {well.Caption}.xlsx";
|
||||||
|
|
||||||
var fileNames = filesInfos
|
var filteredFileInfos = filesInfos
|
||||||
.Where(f => f.Name != resultFileName)
|
.Where(f => f.Name != resultFileName &&
|
||||||
.Select(f => fileService.GetUrl(f));
|
f.FileMarks != null &&
|
||||||
|
f.FileMarks.Any(file => file.IdMark == 0));
|
||||||
|
|
||||||
var tempResultFilePath = Path.Combine(Path.GetTempPath(), "drillingProgram", resultFileName);
|
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,
|
var fileInfo = await fileService.MoveAsync(idWell, null, idFileCategoryDrillingProgram,
|
||||||
resultFileName, tempResultFilePath, token).ConfigureAwait(false);
|
resultFileName, tempResultFilePath, token).ConfigureAwait(false);
|
||||||
|
@ -48,6 +48,32 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
return fileWebLink;
|
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);
|
destinationFileName = Path.GetFileName(destinationFileName);
|
||||||
@ -120,6 +146,7 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
int idCategory, CancellationToken token = default)
|
int idCategory, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
var entities = await dbSetConfigured
|
var entities = await dbSetConfigured
|
||||||
|
.Include(f => f.FileMarks)
|
||||||
.Where(e => e.IdWell == idWell && e.IdCategory == idCategory && e.IsDeleted == false)
|
.Where(e => e.IdWell == idWell && e.IdCategory == idCategory && e.IsDeleted == false)
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.ToListAsync(token)
|
.ToListAsync(token)
|
||||||
@ -135,13 +162,16 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
{
|
{
|
||||||
var query = dbSetConfigured
|
var query = dbSetConfigured
|
||||||
.Where(e => e.IdWell == idWell &&
|
.Where(e => e.IdWell == idWell &&
|
||||||
e.IdCategory == idCategory);
|
e.IdCategory == idCategory);
|
||||||
|
|
||||||
query = query.Where(e => !e.IsDeleted);
|
query = query.Where(e => !e.IsDeleted);
|
||||||
|
|
||||||
|
if (idCategory == 13)
|
||||||
|
query = query.Include(f => f.FileMarks);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(companyName))
|
if (!string.IsNullOrEmpty(companyName))
|
||||||
query = query
|
query = query
|
||||||
.Include(file => file.Author)
|
.Include(file => file.Author)
|
||||||
.ThenInclude(a => a.Company)
|
.ThenInclude(a => a.Company)
|
||||||
.Where(e => (e.Author == null) || (e.Author.Company == null) || e.Author.Company.Caption.Contains(companyName));
|
.Where(e => (e.Author == null) || (e.Author.Company == null) || e.Author.Company.Caption.Contains(companyName));
|
||||||
|
|
||||||
@ -244,6 +274,51 @@ 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,
|
||||||
|
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,
|
private async Task<string> PublishFileToCloudAsync(string filePath, string originalName,
|
||||||
CancellationToken token = default)
|
CancellationToken token = default)
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@ -14,11 +15,14 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
{
|
{
|
||||||
private readonly IDrillingProgramService drillingProgramService;
|
private readonly IDrillingProgramService drillingProgramService;
|
||||||
private readonly IFileService fileService;
|
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.drillingProgramService = drillingProgramService;
|
||||||
this.fileService = fileService;
|
this.fileService = fileService;
|
||||||
|
this.wellService = wellService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -31,8 +35,19 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[ProducesResponseType(typeof(FileResult), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(FileResult), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> GetAsync(int idWell, CancellationToken token = default)
|
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);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
if (fileInfo is null)
|
if (fileInfo is null)
|
||||||
return NoContent();
|
return NoContent();
|
||||||
|
|
||||||
@ -51,7 +66,17 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[ProducesResponseType(typeof(string), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(string), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> GetFileWebLinkAsync(int idWell, CancellationToken token = default)
|
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);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
if (fileInfo is null)
|
if (fileInfo is null)
|
||||||
@ -64,5 +89,59 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
|
|
||||||
return Ok(fileWebUrl);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user