diff --git a/AsbCloudApp/Data/FileInfoDto.cs b/AsbCloudApp/Data/FileInfoDto.cs index 2feda444..444aecf3 100644 --- a/AsbCloudApp/Data/FileInfoDto.cs +++ b/AsbCloudApp/Data/FileInfoDto.cs @@ -5,8 +5,10 @@ namespace AsbCloudApp.Data public class FileInfoDto { public int Id { get; set; } - public string Name { get; set; } + public int IdWell { get; set; } public int IdCategory { get; set; } + public int IdAuthor { get; set; } + public string Name { get; set; } public DateTime UploadDate { get; set; } public string AuthorName { get; set; } public int CompanyId { get; set; } diff --git a/AsbCloudApp/Services/IDrillingProgramService.cs b/AsbCloudApp/Services/IDrillingProgramService.cs new file mode 100644 index 00000000..034dfd6c --- /dev/null +++ b/AsbCloudApp/Services/IDrillingProgramService.cs @@ -0,0 +1,11 @@ +using AsbCloudApp.Data; +using System.Threading; +using System.Threading.Tasks; + +namespace AsbCloudApp.Services +{ + public interface IDrillingProgramService + { + Task GetAsync(int idWell, CancellationToken token = default); + } +} \ No newline at end of file diff --git a/AsbCloudApp/Services/IFileService.cs b/AsbCloudApp/Services/IFileService.cs index 915868e0..c0b3e489 100644 --- a/AsbCloudApp/Services/IFileService.cs +++ b/AsbCloudApp/Services/IFileService.cs @@ -10,20 +10,20 @@ namespace AsbCloudApp.Services public interface IFileService { string RootPath { get; } - IDictionary SaveFileInfos(int idWell, int idUser, - IEnumerable filesInfo); - Task SaveFile(int idWell, int idCategory, int fileId, - string fileExtension, Stream fileStream); + Task SaveAsync(int idWell, int idUser, int idCategory, string fileFullName, Stream fileStream, CancellationToken token = default); - Task> GetFilesInfoAsync(int idWell, + Task> GetInfosAsync(int idWell, int idCategory, IEnumerable companies, DateTime begin, DateTime end, int skip, int take, CancellationToken token = default); - Task GetFileInfoAsync(int fileId, + Task GetInfoAsync(int fileId, CancellationToken token); - Task DeleteFileAsync(int idFile, + Task MarkAsDeletedAsync(int idFile, CancellationToken token = default); + Task> GetInfosByCategoryAsync(int idWell, int idCategory, CancellationToken token = default); + Task DeletedAsync(int id, CancellationToken token); + string GetFileName(FileInfoDto fileInfo); } } diff --git a/AsbCloudApp/Services/IWellService.cs b/AsbCloudApp/Services/IWellService.cs index 95afc6b3..8e6db9c4 100644 --- a/AsbCloudApp/Services/IWellService.cs +++ b/AsbCloudApp/Services/IWellService.cs @@ -13,5 +13,6 @@ namespace AsbCloudApp.Services Task> GetOperationsAsync(int idWell, CancellationToken token); Task GetWellCaptionByIdAsync(int idWell, CancellationToken token); Task> GetCompaniesAsync(int idWell, CancellationToken token); + Task GetAsync(int idWell, CancellationToken token); } } diff --git a/AsbCloudDb/Model/AsbCloudDbContext.cs b/AsbCloudDb/Model/AsbCloudDbContext.cs index 95ec134f..90af933b 100644 --- a/AsbCloudDb/Model/AsbCloudDbContext.cs +++ b/AsbCloudDb/Model/AsbCloudDbContext.cs @@ -285,7 +285,8 @@ namespace AsbCloudDb.Model new FileCategory {Id = 9, Name = "Последний замер бурового раствора ФАКТ", ShortName = "fluidFactLastData"}, new FileCategory {Id = 10, Name = "Последние данные Шламограммы", ShortName = "mudLastData"}, new FileCategory {Id = 11, Name = "Последние данные ННБ", ShortName = "nnbLastData"}, - new FileCategory {Id = 12, Name = "Рапорт", ShortName = "report"} + new FileCategory {Id = 12, Name = "Рапорт", ShortName = "report"}, + new FileCategory {Id = 13, Name = "Программа бурения", ShortName = "ПБ"}, }); }); @@ -411,90 +412,90 @@ namespace AsbCloudDb.Model { entity.HasData(new List { new WellOperation{ Id = 64049, IdWell = 1, IdWellSectionType = 2, IdCategory = 1025, IdType = 0, WellDepth = 1400, StartDate = DateTime.Parse("2021-09-02 15:30"), DurationHours = 3.5}, -new WellOperation{ Id = 31502, IdWell = 1, IdWellSectionType = 1, IdCategory = 1027, IdType = 0, WellDepth = 800, StartDate = DateTime.Parse("2021-08-24 07:00"), DurationHours = 1.16666666666667}, -new WellOperation{ Id = 1531, IdWell = 5, IdWellSectionType = 2, IdCategory = 1025, IdType = 1, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 00:00"), DurationHours = 3.5}, -new WellOperation{ Id = 44572, IdWell = 1, IdWellSectionType = 1, IdCategory = 1047, IdType = 0, WellDepth = 1400, StartDate = DateTime.Parse("2021-08-27 05:00"), DurationHours = 3.5}, -new WellOperation{ Id = 44514, IdWell = 1, IdWellSectionType = 2, IdCategory = 1046, IdType = 0, WellDepth = 1400, StartDate = DateTime.Parse("2021-09-02 19:00"), DurationHours = 3.5}, -new WellOperation{ Id = 53383, IdWell = 2, IdWellSectionType = 2, IdCategory = 1027, IdType = 1, WellDepth = 800, StartDate = DateTime.Parse("2021-08-24 07:00"), DurationHours = 3.5}, -new WellOperation{ Id = 3431, IdWell = 1, IdWellSectionType = 1, IdCategory = 1047, IdType = 1, WellDepth = 1300, StartDate = DateTime.Parse("2021-08-25 15:40"), DurationHours = 3.5}, -new WellOperation{ Id = 21460, IdWell = 1, IdWellSectionType = 1, IdCategory = 1025, IdType = 1, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 01:10"), DurationHours = 3.5}, -new WellOperation{ Id = 30464, IdWell = 1, IdWellSectionType = 2, IdCategory = 1026, IdType = 0, WellDepth = 1500, StartDate = DateTime.Parse("2021-09-03 12:30"), DurationHours = 3.5}, -new WellOperation{ Id = 73111, IdWell = 1, IdWellSectionType = 2, IdCategory = 1026, IdType = 1, WellDepth = 1500, StartDate = DateTime.Parse("2021-09-04 13:00"), DurationHours = 3.5}, -new WellOperation{ Id = 81351, IdWell = 1, IdWellSectionType = 1, IdCategory = 1001, IdType = 1, WellDepth = 1110, StartDate = DateTime.Parse("2021-08-25 05:10"), DurationHours = 3.5}, -new WellOperation{ Id = 24480, IdWell = 1, IdWellSectionType = 2, IdCategory = 1027, IdType = 0, WellDepth = 1400, StartDate = DateTime.Parse("2021-09-02 22:30"), DurationHours = 3.5}, -new WellOperation{ Id = 19101, IdWell = 1, IdWellSectionType = 1, IdCategory = 1026, IdType = 0, WellDepth = 1250, StartDate = DateTime.Parse("2021-08-25 21:30"), DurationHours = 3.5}, -new WellOperation{ Id = 34738, IdWell = 1, IdWellSectionType = 2, IdCategory = 1046, IdType = 1, WellDepth = 1400, StartDate = DateTime.Parse("2021-09-04 02:30"), DurationHours = 3.5}, -new WellOperation{ Id = 37606, IdWell = 5, IdWellSectionType = 2, IdCategory = 1027, IdType = 1, WellDepth = 800, StartDate = DateTime.Parse("2021-08-24 07:00"), DurationHours = 3.5}, -new WellOperation{ Id = 71293, IdWell = 1, IdWellSectionType = 1, IdCategory = 1033, IdType = 1, WellDepth = 1300, StartDate = DateTime.Parse("2021-08-25 22:40"), DurationHours = 3.5}, -new WellOperation{ Id = 91696, IdWell = 1, IdWellSectionType = 1, IdCategory = 1025, IdType = 0, WellDepth = 1250, StartDate = DateTime.Parse("2021-08-26 18:30"), DurationHours = 3.5}, -new WellOperation{ Id = 77916, IdWell = 1, IdWellSectionType = 1, IdCategory = 1047, IdType = 0, WellDepth = 1250, StartDate = DateTime.Parse("2021-08-25 11:00"), DurationHours = 3.5}, -new WellOperation{ Id = 93585, IdWell = 1, IdWellSectionType = 1, IdCategory = 1046, IdType = 0, WellDepth = 800, StartDate = DateTime.Parse("2021-08-24 10:30"), DurationHours = 3.5}, -new WellOperation{ Id = 42016, IdWell = 4, IdWellSectionType = 2, IdCategory = 1046, IdType = 0, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 03:30"), DurationHours = 3.5}, -new WellOperation{ Id = 90466, IdWell = 1, IdWellSectionType = 1, IdCategory = 1048, IdType = 1, WellDepth = 1300, StartDate = DateTime.Parse("2021-08-26 09:10"), DurationHours = 3.5}, -new WellOperation{ Id = 15914, IdWell = 1, IdWellSectionType = 1, IdCategory = 1001, IdType = 0, WellDepth = 1250, StartDate = DateTime.Parse("2021-08-27 01:30"), DurationHours = 3.5}, -new WellOperation{ Id = 63469, IdWell = 4, IdWellSectionType = 2, IdCategory = 1026, IdType = 0, WellDepth = 1100, StartDate = DateTime.Parse("2021-08-27 08:30"), DurationHours = 3.5}, -new WellOperation{ Id = 23659, IdWell = 1, IdWellSectionType = 2, IdCategory = 1001, IdType = 1, WellDepth = 1400, StartDate = DateTime.Parse("2021-09-04 06:00"), DurationHours = 3.5}, -new WellOperation{ Id = 93508, IdWell = 1, IdWellSectionType = 2, IdCategory = 1027, IdType = 1, WellDepth = 1400, StartDate = DateTime.Parse("2021-09-03 23:00"), DurationHours = 3.5}, -new WellOperation{ Id = 74346, IdWell = 2, IdWellSectionType = 2, IdCategory = 1026, IdType = 0, WellDepth = 1100, StartDate = DateTime.Parse("2021-08-27 08:30"), DurationHours = 3.5}, -new WellOperation{ Id = 3139, IdWell = 1, IdWellSectionType = 1, IdCategory = 1047, IdType = 1, WellDepth = 1110, StartDate = DateTime.Parse("2021-08-24 22:10"), DurationHours = 3.5}, -new WellOperation{ Id = 11429, IdWell = 2, IdWellSectionType = 2, IdCategory = 1046, IdType = 1, WellDepth = 800, StartDate = DateTime.Parse("2021-08-24 10:30"), DurationHours = 3.5}, -new WellOperation{ Id = 14542, IdWell = 1, IdWellSectionType = 1, IdCategory = 1046, IdType = 0, WellDepth = 1100, StartDate = DateTime.Parse("2021-08-24 21:00"), DurationHours = 3.5}, -new WellOperation{ Id = 70906, IdWell = 4, IdWellSectionType = 2, IdCategory = 1046, IdType = 0, WellDepth = 800, StartDate = DateTime.Parse("2021-08-24 10:30"), DurationHours = 3.5}, -new WellOperation{ Id = 82194, IdWell = 1, IdWellSectionType = 2, IdCategory = 1046, IdType = 0, WellDepth = 1400, StartDate = DateTime.Parse("2021-09-03 02:00"), DurationHours = 3.5}, -new WellOperation{ Id = 13578, IdWell = 1, IdWellSectionType = 1, IdCategory = 1046, IdType = 0, WellDepth = 1250, StartDate = DateTime.Parse("2021-08-26 08:00"), DurationHours = 3.5}, -new WellOperation{ Id = 57798, IdWell = 1, IdWellSectionType = 1, IdCategory = 1033, IdType = 0, WellDepth = 1250, StartDate = DateTime.Parse("2021-08-25 14:30"), DurationHours = 3.5}, -new WellOperation{ Id = 37277, IdWell = 1, IdWellSectionType = 1, IdCategory = 1001, IdType = 0, WellDepth = 1100, StartDate = DateTime.Parse("2021-08-25 00:30"), DurationHours = 3.5}, -new WellOperation{ Id = 23233, IdWell = 1, IdWellSectionType = 1, IdCategory = 1045, IdType = 0, WellDepth = 1250, StartDate = DateTime.Parse("2021-08-25 07:30"), DurationHours = 3.5}, -new WellOperation{ Id = 26075, IdWell = 2, IdWellSectionType = 2, IdCategory = 1046, IdType = 0, WellDepth = 800, StartDate = DateTime.Parse("2021-08-24 10:30"), DurationHours = 3.5}, -new WellOperation{ Id = 8230, IdWell = 1, IdWellSectionType = 1, IdCategory = 1027, IdType = 1, WellDepth = 800, StartDate = DateTime.Parse("2021-08-26 12:40"), DurationHours = 3.5}, -new WellOperation{ Id = 26414, IdWell = 1, IdWellSectionType = 1, IdCategory = 1026, IdType = 0, WellDepth = 1250, StartDate = DateTime.Parse("2021-08-26 15:00"), DurationHours = 3.5}, -new WellOperation{ Id = 92747, IdWell = 1, IdWellSectionType = 1, IdCategory = 1046, IdType = 0, WellDepth = 1250, StartDate = DateTime.Parse("2021-08-26 22:00"), DurationHours = 3.5}, -new WellOperation{ Id = 89559, IdWell = 1, IdWellSectionType = 1, IdCategory = 1027, IdType = 1, WellDepth = 800, StartDate = DateTime.Parse("2021-08-25 19:10"), DurationHours = 3.5}, -new WellOperation{ Id = 99336, IdWell = 1, IdWellSectionType = 1, IdCategory = 1027, IdType = 1, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 08:10"), DurationHours = 3.5}, -new WellOperation{ Id = 80943, IdWell = 1, IdWellSectionType = 1, IdCategory = 1047, IdType = 0, WellDepth = 1250, StartDate = DateTime.Parse("2021-08-25 04:00"), DurationHours = 3.5}, -new WellOperation{ Id = 11934, IdWell = 1, IdWellSectionType = 1, IdCategory = 1006, IdType = 0, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 08:10"), DurationHours = 2.33333333333333}, -new WellOperation{ Id = 88089, IdWell = 1, IdWellSectionType = 1, IdCategory = 1046, IdType = 1, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 11:40"), DurationHours = 3.5}, -new WellOperation{ Id = 57116, IdWell = 1, IdWellSectionType = 1, IdCategory = 1047, IdType = 0, WellDepth = 1250, StartDate = DateTime.Parse("2021-08-25 18:00"), DurationHours = 3.5}, -new WellOperation{ Id = 57561, IdWell = 5, IdWellSectionType = 2, IdCategory = 1046, IdType = 1, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 03:30"), DurationHours = 3.5}, -new WellOperation{ Id = 72783, IdWell = 1, IdWellSectionType = 1, IdCategory = 1046, IdType = 1, WellDepth = 1110, StartDate = DateTime.Parse("2021-08-25 01:40"), DurationHours = 3.5}, -new WellOperation{ Id = 75549, IdWell = 1, IdWellSectionType = 1, IdCategory = 1046, IdType = 0, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 03:30"), DurationHours = 3.5}, -new WellOperation{ Id = 60717, IdWell = 2, IdWellSectionType = 2, IdCategory = 1025, IdType = 1, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 00:00"), DurationHours = 3.5}, -new WellOperation{ Id = 21171, IdWell = 1, IdWellSectionType = 1, IdCategory = 1025, IdType = 0, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 00:00"), DurationHours = 3.5}, -new WellOperation{ Id = 13547, IdWell = 2, IdWellSectionType = 2, IdCategory = 1047, IdType = 1, WellDepth = 1100, StartDate = DateTime.Parse("2021-08-24 17:30"), DurationHours = 15}, -new WellOperation{ Id = 83361, IdWell = 5, IdWellSectionType = 2, IdCategory = 1026, IdType = 1, WellDepth = 1100, StartDate = DateTime.Parse("2021-08-27 08:30"), DurationHours = 3.5}, -new WellOperation{ Id = 58676, IdWell = 2, IdWellSectionType = 2, IdCategory = 1001, IdType = 1, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 14:00"), DurationHours = 3.5}, -new WellOperation{ Id = 46864, IdWell = 1, IdWellSectionType = 2, IdCategory = 1025, IdType = 1, WellDepth = 1400, StartDate = DateTime.Parse("2021-09-03 16:00"), DurationHours = 3.5}, -new WellOperation{ Id = 95276, IdWell = 1, IdWellSectionType = 1, IdCategory = 1027, IdType = 1, WellDepth = 800, StartDate = DateTime.Parse("2021-08-24 18:40"), DurationHours = 3.5}, -new WellOperation{ Id = 33478, IdWell = 1, IdWellSectionType = 1, IdCategory = 1047, IdType = 0, WellDepth = 1100, StartDate = DateTime.Parse("2021-08-24 17:30"), DurationHours = 3.5}, -new WellOperation{ Id = 85086, IdWell = 1, IdWellSectionType = 2, IdCategory = 1047, IdType = 1, WellDepth = 1500, StartDate = DateTime.Parse("2021-09-04 09:30"), DurationHours = 3.5}, -new WellOperation{ Id = 38808, IdWell = 1, IdWellSectionType = 2, IdCategory = 1001, IdType = 0, WellDepth = 1400, StartDate = DateTime.Parse("2021-09-03 05:30"), DurationHours = 3.5}, -new WellOperation{ Id = 60045, IdWell = 5, IdWellSectionType = 2, IdCategory = 1001, IdType = 1, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 14:00"), DurationHours = 3.5}, -new WellOperation{ Id = 82773, IdWell = 2, IdWellSectionType = 2, IdCategory = 1027, IdType = 0, WellDepth = 800, StartDate = DateTime.Parse("2021-08-24 07:00"), DurationHours = 3.5}, -new WellOperation{ Id = 38025, IdWell = 1, IdWellSectionType = 1, IdCategory = 1047, IdType = 1, WellDepth = 1300, StartDate = DateTime.Parse("2021-08-25 08:40"), DurationHours = 3.5}, -new WellOperation{ Id = 8312, IdWell = 1, IdWellSectionType = 1, IdCategory = 1047, IdType = 1, WellDepth = 1300, StartDate = DateTime.Parse("2021-08-26 02:10"), DurationHours = 3.5}, -new WellOperation{ Id = 84440, IdWell = 1, IdWellSectionType = 2, IdCategory = 1046, IdType = 1, WellDepth = 1400, StartDate = DateTime.Parse("2021-09-03 19:30"), DurationHours = 3.5}, -new WellOperation{ Id = 78963, IdWell = 1, IdWellSectionType = 1, IdCategory = 1026, IdType = 1, WellDepth = 1300, StartDate = DateTime.Parse("2021-08-26 05:40"), DurationHours = 3.5}, -new WellOperation{ Id = 39690, IdWell = 2, IdWellSectionType = 2, IdCategory = 1046, IdType = 1, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 03:30"), DurationHours = 3.5}, -new WellOperation{ Id = 88719, IdWell = 2, IdWellSectionType = 2, IdCategory = 1001, IdType = 0, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 14:00"), DurationHours = 3.5}, -new WellOperation{ Id = 64890, IdWell = 1, IdWellSectionType = 1, IdCategory = 1001, IdType = 1, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 15:10"), DurationHours = 3.5}, -new WellOperation{ Id = 95476, IdWell = 1, IdWellSectionType = 1, IdCategory = 1025, IdType = 0, WellDepth = 1250, StartDate = DateTime.Parse("2021-08-26 04:30"), DurationHours = 3.5}, -new WellOperation{ Id = 78257, IdWell = 4, IdWellSectionType = 2, IdCategory = 1027, IdType = 0, WellDepth = 800, StartDate = DateTime.Parse("2021-08-24 07:00"), DurationHours = 3.5}, -new WellOperation{ Id = 41260, IdWell = 1, IdWellSectionType = 2, IdCategory = 1047, IdType = 0, WellDepth = 1500, StartDate = DateTime.Parse("2021-09-03 09:00"), DurationHours = 3.5}, -new WellOperation{ Id = 41055, IdWell = 5, IdWellSectionType = 2, IdCategory = 1047, IdType = 1, WellDepth = 1100, StartDate = DateTime.Parse("2021-08-24 17:30"), DurationHours = 15}, -new WellOperation{ Id = 47051, IdWell = 1, IdWellSectionType = 1, IdCategory = 1046, IdType = 1, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 04:40"), DurationHours = 3.5}, -new WellOperation{ Id = 14068, IdWell = 1, IdWellSectionType = 1, IdCategory = 1045, IdType = 1, WellDepth = 1300, StartDate = DateTime.Parse("2021-08-25 12:10"), DurationHours = 3.5}, -new WellOperation{ Id = 96039, IdWell = 4, IdWellSectionType = 2, IdCategory = 1047, IdType = 0, WellDepth = 1100, StartDate = DateTime.Parse("2021-08-24 17:30"), DurationHours = 15}, -new WellOperation{ Id = 34668, IdWell = 1, IdWellSectionType = 1, IdCategory = 1001, IdType = 0, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 14:00"), DurationHours = 3.5}, -new WellOperation{ Id = 43146, IdWell = 2, IdWellSectionType = 2, IdCategory = 1026, IdType = 1, WellDepth = 1100, StartDate = DateTime.Parse("2021-08-27 08:30"), DurationHours = 3.5}, -new WellOperation{ Id = 15263, IdWell = 2, IdWellSectionType = 2, IdCategory = 1046, IdType = 0, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 03:30"), DurationHours = 3.5}, -new WellOperation{ Id = 20802, IdWell = 2, IdWellSectionType = 2, IdCategory = 1025, IdType = 0, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 00:00"), DurationHours = 3.5}, -new WellOperation{ Id = 81320, IdWell = 4, IdWellSectionType = 2, IdCategory = 1001, IdType = 0, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 14:00"), DurationHours = 3.5}, -new WellOperation{ Id = 43902, IdWell = 2, IdWellSectionType = 2, IdCategory = 1047, IdType = 0, WellDepth = 1100, StartDate = DateTime.Parse("2021-08-24 17:30"), DurationHours = 15}, -new WellOperation{ Id = 62958, IdWell = 4, IdWellSectionType = 2, IdCategory = 1025, IdType = 0, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 00:00"), DurationHours = 3.5}, -new WellOperation{ Id = 74174, IdWell = 5, IdWellSectionType = 2, IdCategory = 1046, IdType = 1, WellDepth = 800, StartDate = DateTime.Parse("2021-08-24 10:30"), DurationHours = 3.5}, -new WellOperation{ Id = 76347, IdWell = 1, IdWellSectionType = 1, IdCategory = 1048, IdType = 0, WellDepth = 1250, StartDate = DateTime.Parse("2021-08-26 01:00"), DurationHours = 3.5}, -new WellOperation{ Id = 51329, IdWell = 1, IdWellSectionType = 1, IdCategory = 1026, IdType = 0, WellDepth = 1400, StartDate = DateTime.Parse("2021-08-27 08:30"), DurationHours = 3.5}, -new WellOperation{ Id = 76341, IdWell = 1, IdWellSectionType = 1, IdCategory = 1047, IdType = 0, WellDepth = 1250, StartDate = DateTime.Parse("2021-08-26 11:30"), DurationHours = 3.5}, + new WellOperation{ Id = 31502, IdWell = 1, IdWellSectionType = 1, IdCategory = 1027, IdType = 0, WellDepth = 800, StartDate = DateTime.Parse("2021-08-24 07:00"), DurationHours = 1.16666666666667}, + new WellOperation{ Id = 1531, IdWell = 5, IdWellSectionType = 2, IdCategory = 1025, IdType = 1, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 00:00"), DurationHours = 3.5}, + new WellOperation{ Id = 44572, IdWell = 1, IdWellSectionType = 1, IdCategory = 1047, IdType = 0, WellDepth = 1400, StartDate = DateTime.Parse("2021-08-27 05:00"), DurationHours = 3.5}, + new WellOperation{ Id = 44514, IdWell = 1, IdWellSectionType = 2, IdCategory = 1046, IdType = 0, WellDepth = 1400, StartDate = DateTime.Parse("2021-09-02 19:00"), DurationHours = 3.5}, + new WellOperation{ Id = 53383, IdWell = 2, IdWellSectionType = 2, IdCategory = 1027, IdType = 1, WellDepth = 800, StartDate = DateTime.Parse("2021-08-24 07:00"), DurationHours = 3.5}, + new WellOperation{ Id = 3431, IdWell = 1, IdWellSectionType = 1, IdCategory = 1047, IdType = 1, WellDepth = 1300, StartDate = DateTime.Parse("2021-08-25 15:40"), DurationHours = 3.5}, + new WellOperation{ Id = 21460, IdWell = 1, IdWellSectionType = 1, IdCategory = 1025, IdType = 1, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 01:10"), DurationHours = 3.5}, + new WellOperation{ Id = 30464, IdWell = 1, IdWellSectionType = 2, IdCategory = 1026, IdType = 0, WellDepth = 1500, StartDate = DateTime.Parse("2021-09-03 12:30"), DurationHours = 3.5}, + new WellOperation{ Id = 73111, IdWell = 1, IdWellSectionType = 2, IdCategory = 1026, IdType = 1, WellDepth = 1500, StartDate = DateTime.Parse("2021-09-04 13:00"), DurationHours = 3.5}, + new WellOperation{ Id = 81351, IdWell = 1, IdWellSectionType = 1, IdCategory = 1001, IdType = 1, WellDepth = 1110, StartDate = DateTime.Parse("2021-08-25 05:10"), DurationHours = 3.5}, + new WellOperation{ Id = 24480, IdWell = 1, IdWellSectionType = 2, IdCategory = 1027, IdType = 0, WellDepth = 1400, StartDate = DateTime.Parse("2021-09-02 22:30"), DurationHours = 3.5}, + new WellOperation{ Id = 19101, IdWell = 1, IdWellSectionType = 1, IdCategory = 1026, IdType = 0, WellDepth = 1250, StartDate = DateTime.Parse("2021-08-25 21:30"), DurationHours = 3.5}, + new WellOperation{ Id = 34738, IdWell = 1, IdWellSectionType = 2, IdCategory = 1046, IdType = 1, WellDepth = 1400, StartDate = DateTime.Parse("2021-09-04 02:30"), DurationHours = 3.5}, + new WellOperation{ Id = 37606, IdWell = 5, IdWellSectionType = 2, IdCategory = 1027, IdType = 1, WellDepth = 800, StartDate = DateTime.Parse("2021-08-24 07:00"), DurationHours = 3.5}, + new WellOperation{ Id = 71293, IdWell = 1, IdWellSectionType = 1, IdCategory = 1033, IdType = 1, WellDepth = 1300, StartDate = DateTime.Parse("2021-08-25 22:40"), DurationHours = 3.5}, + new WellOperation{ Id = 91696, IdWell = 1, IdWellSectionType = 1, IdCategory = 1025, IdType = 0, WellDepth = 1250, StartDate = DateTime.Parse("2021-08-26 18:30"), DurationHours = 3.5}, + new WellOperation{ Id = 77916, IdWell = 1, IdWellSectionType = 1, IdCategory = 1047, IdType = 0, WellDepth = 1250, StartDate = DateTime.Parse("2021-08-25 11:00"), DurationHours = 3.5}, + new WellOperation{ Id = 93585, IdWell = 1, IdWellSectionType = 1, IdCategory = 1046, IdType = 0, WellDepth = 800, StartDate = DateTime.Parse("2021-08-24 10:30"), DurationHours = 3.5}, + new WellOperation{ Id = 42016, IdWell = 4, IdWellSectionType = 2, IdCategory = 1046, IdType = 0, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 03:30"), DurationHours = 3.5}, + new WellOperation{ Id = 90466, IdWell = 1, IdWellSectionType = 1, IdCategory = 1048, IdType = 1, WellDepth = 1300, StartDate = DateTime.Parse("2021-08-26 09:10"), DurationHours = 3.5}, + new WellOperation{ Id = 15914, IdWell = 1, IdWellSectionType = 1, IdCategory = 1001, IdType = 0, WellDepth = 1250, StartDate = DateTime.Parse("2021-08-27 01:30"), DurationHours = 3.5}, + new WellOperation{ Id = 63469, IdWell = 4, IdWellSectionType = 2, IdCategory = 1026, IdType = 0, WellDepth = 1100, StartDate = DateTime.Parse("2021-08-27 08:30"), DurationHours = 3.5}, + new WellOperation{ Id = 23659, IdWell = 1, IdWellSectionType = 2, IdCategory = 1001, IdType = 1, WellDepth = 1400, StartDate = DateTime.Parse("2021-09-04 06:00"), DurationHours = 3.5}, + new WellOperation{ Id = 93508, IdWell = 1, IdWellSectionType = 2, IdCategory = 1027, IdType = 1, WellDepth = 1400, StartDate = DateTime.Parse("2021-09-03 23:00"), DurationHours = 3.5}, + new WellOperation{ Id = 74346, IdWell = 2, IdWellSectionType = 2, IdCategory = 1026, IdType = 0, WellDepth = 1100, StartDate = DateTime.Parse("2021-08-27 08:30"), DurationHours = 3.5}, + new WellOperation{ Id = 3139, IdWell = 1, IdWellSectionType = 1, IdCategory = 1047, IdType = 1, WellDepth = 1110, StartDate = DateTime.Parse("2021-08-24 22:10"), DurationHours = 3.5}, + new WellOperation{ Id = 11429, IdWell = 2, IdWellSectionType = 2, IdCategory = 1046, IdType = 1, WellDepth = 800, StartDate = DateTime.Parse("2021-08-24 10:30"), DurationHours = 3.5}, + new WellOperation{ Id = 14542, IdWell = 1, IdWellSectionType = 1, IdCategory = 1046, IdType = 0, WellDepth = 1100, StartDate = DateTime.Parse("2021-08-24 21:00"), DurationHours = 3.5}, + new WellOperation{ Id = 70906, IdWell = 4, IdWellSectionType = 2, IdCategory = 1046, IdType = 0, WellDepth = 800, StartDate = DateTime.Parse("2021-08-24 10:30"), DurationHours = 3.5}, + new WellOperation{ Id = 82194, IdWell = 1, IdWellSectionType = 2, IdCategory = 1046, IdType = 0, WellDepth = 1400, StartDate = DateTime.Parse("2021-09-03 02:00"), DurationHours = 3.5}, + new WellOperation{ Id = 13578, IdWell = 1, IdWellSectionType = 1, IdCategory = 1046, IdType = 0, WellDepth = 1250, StartDate = DateTime.Parse("2021-08-26 08:00"), DurationHours = 3.5}, + new WellOperation{ Id = 57798, IdWell = 1, IdWellSectionType = 1, IdCategory = 1033, IdType = 0, WellDepth = 1250, StartDate = DateTime.Parse("2021-08-25 14:30"), DurationHours = 3.5}, + new WellOperation{ Id = 37277, IdWell = 1, IdWellSectionType = 1, IdCategory = 1001, IdType = 0, WellDepth = 1100, StartDate = DateTime.Parse("2021-08-25 00:30"), DurationHours = 3.5}, + new WellOperation{ Id = 23233, IdWell = 1, IdWellSectionType = 1, IdCategory = 1045, IdType = 0, WellDepth = 1250, StartDate = DateTime.Parse("2021-08-25 07:30"), DurationHours = 3.5}, + new WellOperation{ Id = 26075, IdWell = 2, IdWellSectionType = 2, IdCategory = 1046, IdType = 0, WellDepth = 800, StartDate = DateTime.Parse("2021-08-24 10:30"), DurationHours = 3.5}, + new WellOperation{ Id = 8230, IdWell = 1, IdWellSectionType = 1, IdCategory = 1027, IdType = 1, WellDepth = 800, StartDate = DateTime.Parse("2021-08-26 12:40"), DurationHours = 3.5}, + new WellOperation{ Id = 26414, IdWell = 1, IdWellSectionType = 1, IdCategory = 1026, IdType = 0, WellDepth = 1250, StartDate = DateTime.Parse("2021-08-26 15:00"), DurationHours = 3.5}, + new WellOperation{ Id = 92747, IdWell = 1, IdWellSectionType = 1, IdCategory = 1046, IdType = 0, WellDepth = 1250, StartDate = DateTime.Parse("2021-08-26 22:00"), DurationHours = 3.5}, + new WellOperation{ Id = 89559, IdWell = 1, IdWellSectionType = 1, IdCategory = 1027, IdType = 1, WellDepth = 800, StartDate = DateTime.Parse("2021-08-25 19:10"), DurationHours = 3.5}, + new WellOperation{ Id = 99336, IdWell = 1, IdWellSectionType = 1, IdCategory = 1027, IdType = 1, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 08:10"), DurationHours = 3.5}, + new WellOperation{ Id = 80943, IdWell = 1, IdWellSectionType = 1, IdCategory = 1047, IdType = 0, WellDepth = 1250, StartDate = DateTime.Parse("2021-08-25 04:00"), DurationHours = 3.5}, + new WellOperation{ Id = 11934, IdWell = 1, IdWellSectionType = 1, IdCategory = 1006, IdType = 0, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 08:10"), DurationHours = 2.33333333333333}, + new WellOperation{ Id = 88089, IdWell = 1, IdWellSectionType = 1, IdCategory = 1046, IdType = 1, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 11:40"), DurationHours = 3.5}, + new WellOperation{ Id = 57116, IdWell = 1, IdWellSectionType = 1, IdCategory = 1047, IdType = 0, WellDepth = 1250, StartDate = DateTime.Parse("2021-08-25 18:00"), DurationHours = 3.5}, + new WellOperation{ Id = 57561, IdWell = 5, IdWellSectionType = 2, IdCategory = 1046, IdType = 1, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 03:30"), DurationHours = 3.5}, + new WellOperation{ Id = 72783, IdWell = 1, IdWellSectionType = 1, IdCategory = 1046, IdType = 1, WellDepth = 1110, StartDate = DateTime.Parse("2021-08-25 01:40"), DurationHours = 3.5}, + new WellOperation{ Id = 75549, IdWell = 1, IdWellSectionType = 1, IdCategory = 1046, IdType = 0, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 03:30"), DurationHours = 3.5}, + new WellOperation{ Id = 60717, IdWell = 2, IdWellSectionType = 2, IdCategory = 1025, IdType = 1, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 00:00"), DurationHours = 3.5}, + new WellOperation{ Id = 21171, IdWell = 1, IdWellSectionType = 1, IdCategory = 1025, IdType = 0, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 00:00"), DurationHours = 3.5}, + new WellOperation{ Id = 13547, IdWell = 2, IdWellSectionType = 2, IdCategory = 1047, IdType = 1, WellDepth = 1100, StartDate = DateTime.Parse("2021-08-24 17:30"), DurationHours = 15}, + new WellOperation{ Id = 83361, IdWell = 5, IdWellSectionType = 2, IdCategory = 1026, IdType = 1, WellDepth = 1100, StartDate = DateTime.Parse("2021-08-27 08:30"), DurationHours = 3.5}, + new WellOperation{ Id = 58676, IdWell = 2, IdWellSectionType = 2, IdCategory = 1001, IdType = 1, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 14:00"), DurationHours = 3.5}, + new WellOperation{ Id = 46864, IdWell = 1, IdWellSectionType = 2, IdCategory = 1025, IdType = 1, WellDepth = 1400, StartDate = DateTime.Parse("2021-09-03 16:00"), DurationHours = 3.5}, + new WellOperation{ Id = 95276, IdWell = 1, IdWellSectionType = 1, IdCategory = 1027, IdType = 1, WellDepth = 800, StartDate = DateTime.Parse("2021-08-24 18:40"), DurationHours = 3.5}, + new WellOperation{ Id = 33478, IdWell = 1, IdWellSectionType = 1, IdCategory = 1047, IdType = 0, WellDepth = 1100, StartDate = DateTime.Parse("2021-08-24 17:30"), DurationHours = 3.5}, + new WellOperation{ Id = 85086, IdWell = 1, IdWellSectionType = 2, IdCategory = 1047, IdType = 1, WellDepth = 1500, StartDate = DateTime.Parse("2021-09-04 09:30"), DurationHours = 3.5}, + new WellOperation{ Id = 38808, IdWell = 1, IdWellSectionType = 2, IdCategory = 1001, IdType = 0, WellDepth = 1400, StartDate = DateTime.Parse("2021-09-03 05:30"), DurationHours = 3.5}, + new WellOperation{ Id = 60045, IdWell = 5, IdWellSectionType = 2, IdCategory = 1001, IdType = 1, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 14:00"), DurationHours = 3.5}, + new WellOperation{ Id = 82773, IdWell = 2, IdWellSectionType = 2, IdCategory = 1027, IdType = 0, WellDepth = 800, StartDate = DateTime.Parse("2021-08-24 07:00"), DurationHours = 3.5}, + new WellOperation{ Id = 38025, IdWell = 1, IdWellSectionType = 1, IdCategory = 1047, IdType = 1, WellDepth = 1300, StartDate = DateTime.Parse("2021-08-25 08:40"), DurationHours = 3.5}, + new WellOperation{ Id = 8312, IdWell = 1, IdWellSectionType = 1, IdCategory = 1047, IdType = 1, WellDepth = 1300, StartDate = DateTime.Parse("2021-08-26 02:10"), DurationHours = 3.5}, + new WellOperation{ Id = 84440, IdWell = 1, IdWellSectionType = 2, IdCategory = 1046, IdType = 1, WellDepth = 1400, StartDate = DateTime.Parse("2021-09-03 19:30"), DurationHours = 3.5}, + new WellOperation{ Id = 78963, IdWell = 1, IdWellSectionType = 1, IdCategory = 1026, IdType = 1, WellDepth = 1300, StartDate = DateTime.Parse("2021-08-26 05:40"), DurationHours = 3.5}, + new WellOperation{ Id = 39690, IdWell = 2, IdWellSectionType = 2, IdCategory = 1046, IdType = 1, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 03:30"), DurationHours = 3.5}, + new WellOperation{ Id = 88719, IdWell = 2, IdWellSectionType = 2, IdCategory = 1001, IdType = 0, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 14:00"), DurationHours = 3.5}, + new WellOperation{ Id = 64890, IdWell = 1, IdWellSectionType = 1, IdCategory = 1001, IdType = 1, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 15:10"), DurationHours = 3.5}, + new WellOperation{ Id = 95476, IdWell = 1, IdWellSectionType = 1, IdCategory = 1025, IdType = 0, WellDepth = 1250, StartDate = DateTime.Parse("2021-08-26 04:30"), DurationHours = 3.5}, + new WellOperation{ Id = 78257, IdWell = 4, IdWellSectionType = 2, IdCategory = 1027, IdType = 0, WellDepth = 800, StartDate = DateTime.Parse("2021-08-24 07:00"), DurationHours = 3.5}, + new WellOperation{ Id = 41260, IdWell = 1, IdWellSectionType = 2, IdCategory = 1047, IdType = 0, WellDepth = 1500, StartDate = DateTime.Parse("2021-09-03 09:00"), DurationHours = 3.5}, + new WellOperation{ Id = 41055, IdWell = 5, IdWellSectionType = 2, IdCategory = 1047, IdType = 1, WellDepth = 1100, StartDate = DateTime.Parse("2021-08-24 17:30"), DurationHours = 15}, + new WellOperation{ Id = 47051, IdWell = 1, IdWellSectionType = 1, IdCategory = 1046, IdType = 1, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 04:40"), DurationHours = 3.5}, + new WellOperation{ Id = 14068, IdWell = 1, IdWellSectionType = 1, IdCategory = 1045, IdType = 1, WellDepth = 1300, StartDate = DateTime.Parse("2021-08-25 12:10"), DurationHours = 3.5}, + new WellOperation{ Id = 96039, IdWell = 4, IdWellSectionType = 2, IdCategory = 1047, IdType = 0, WellDepth = 1100, StartDate = DateTime.Parse("2021-08-24 17:30"), DurationHours = 15}, + new WellOperation{ Id = 34668, IdWell = 1, IdWellSectionType = 1, IdCategory = 1001, IdType = 0, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 14:00"), DurationHours = 3.5}, + new WellOperation{ Id = 43146, IdWell = 2, IdWellSectionType = 2, IdCategory = 1026, IdType = 1, WellDepth = 1100, StartDate = DateTime.Parse("2021-08-27 08:30"), DurationHours = 3.5}, + new WellOperation{ Id = 15263, IdWell = 2, IdWellSectionType = 2, IdCategory = 1046, IdType = 0, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 03:30"), DurationHours = 3.5}, + new WellOperation{ Id = 20802, IdWell = 2, IdWellSectionType = 2, IdCategory = 1025, IdType = 0, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 00:00"), DurationHours = 3.5}, + new WellOperation{ Id = 81320, IdWell = 4, IdWellSectionType = 2, IdCategory = 1001, IdType = 0, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 14:00"), DurationHours = 3.5}, + new WellOperation{ Id = 43902, IdWell = 2, IdWellSectionType = 2, IdCategory = 1047, IdType = 0, WellDepth = 1100, StartDate = DateTime.Parse("2021-08-24 17:30"), DurationHours = 15}, + new WellOperation{ Id = 62958, IdWell = 4, IdWellSectionType = 2, IdCategory = 1025, IdType = 0, WellDepth = 1000, StartDate = DateTime.Parse("2021-08-24 00:00"), DurationHours = 3.5}, + new WellOperation{ Id = 74174, IdWell = 5, IdWellSectionType = 2, IdCategory = 1046, IdType = 1, WellDepth = 800, StartDate = DateTime.Parse("2021-08-24 10:30"), DurationHours = 3.5}, + new WellOperation{ Id = 76347, IdWell = 1, IdWellSectionType = 1, IdCategory = 1048, IdType = 0, WellDepth = 1250, StartDate = DateTime.Parse("2021-08-26 01:00"), DurationHours = 3.5}, + new WellOperation{ Id = 51329, IdWell = 1, IdWellSectionType = 1, IdCategory = 1026, IdType = 0, WellDepth = 1400, StartDate = DateTime.Parse("2021-08-27 08:30"), DurationHours = 3.5}, + new WellOperation{ Id = 76341, IdWell = 1, IdWellSectionType = 1, IdCategory = 1047, IdType = 0, WellDepth = 1250, StartDate = DateTime.Parse("2021-08-26 11:30"), DurationHours = 3.5}, }); }); diff --git a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj index f87217df..56ac820c 100644 --- a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj +++ b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj @@ -12,6 +12,7 @@ + diff --git a/AsbCloudInfrastructure/DependencyInjection.cs b/AsbCloudInfrastructure/DependencyInjection.cs index 189473eb..a2c91224 100644 --- a/AsbCloudInfrastructure/DependencyInjection.cs +++ b/AsbCloudInfrastructure/DependencyInjection.cs @@ -39,6 +39,7 @@ namespace AsbCloudInfrastructure services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); return services; } diff --git a/AsbCloudInfrastructure/Services/DrillingProgramService.cs b/AsbCloudInfrastructure/Services/DrillingProgramService.cs new file mode 100644 index 00000000..b8ccae5b --- /dev/null +++ b/AsbCloudInfrastructure/Services/DrillingProgramService.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using AsbCloudApp.Data; +using AsbCloudApp.Services; +using AsbCloudDb.Model; +using Microsoft.EntityFrameworkCore; +using NPOI.SS.UserModel; +using NPOI.XSSF.UserModel; + +namespace AsbCloudInfrastructure.Services +{ + public class DrillingProgramService : IDrillingProgramService + { + private readonly IFileService fileService; + private readonly WellService wellService; + private const int idFileCategoryPlan = 13; + + public DrillingProgramService(IFileService fileService, WellService wellService) + { + this.fileService = fileService; + this.wellService = wellService; + } + + public async Task GetAsync(int idWell, CancellationToken token = default) + { + var filesInfos = await fileService.GetInfosByCategoryAsync(idWell, idFileCategoryPlan, token) + .ConfigureAwait(false); + + var well = await wellService.GetAsync(idWell, token) + .ConfigureAwait(false); + + var resultFileName = $"Программа бурения {well.Cluster} {well.Caption}.xlsx"; + + var matchFile = filesInfos.FirstOrDefault(f=>f.Name == resultFileName); + if (matchFile is not null) { + if (filesInfos.All(f => f.UploadDate <= matchFile.UploadDate)) + return matchFile; + else + await fileService.DeletedAsync(matchFile.Id, token); + } + + var fileNames = filesInfos + .Where(f => f.Name != resultFileName) + .Select(f => fileService.GetFileName(f)); + + var stream = new MemoryStream(1024 * 1024); + UniteExcelFiles(fileNames, stream); + stream.Seek(0, SeekOrigin.Begin); + return await fileService.SaveAsync(idWell, 0, idFileCategoryPlan, resultFileName, stream, token) + .ConfigureAwait(false); + } + + private static void UniteExcelFiles(IEnumerable excelFilesNames, Stream stream) + { + IWorkbook product = new XSSFWorkbook(); + + foreach (var excelFileName in excelFilesNames) + { + IWorkbook book = new XSSFWorkbook(new FileStream(excelFileName, FileMode.Open)); + + for (int i = 0; i < book.NumberOfSheets; i++) + { + ISheet sheet = book.GetSheetAt(i); + try + { + sheet.CopyTo(product, sheet.SheetName, true, true); + } + catch + { + //what can't be done - can't be done. ignore it. + } + } + } + product.Write(stream); + } + } +} \ No newline at end of file diff --git a/AsbCloudInfrastructure/Services/FileService.cs b/AsbCloudInfrastructure/Services/FileService.cs index 74185a11..14fd5d8e 100644 --- a/AsbCloudInfrastructure/Services/FileService.cs +++ b/AsbCloudInfrastructure/Services/FileService.cs @@ -23,35 +23,25 @@ namespace AsbCloudInfrastructure.Services this.db = db; } - public IDictionary SaveFileInfos(int idWell, int idUser, - IEnumerable filesInfo) + public async Task SaveAsync(int idWell, int idUser, int idCategory, string fileFullName, Stream fileStream, CancellationToken token = default) { - var fileIdsToNames = new Dictionary(); - - foreach (var fileInfo in filesInfo) + //save info to db + var fileInfo = new AsbCloudDb.Model.FileInfo() { - var file = new AsbCloudDb.Model.FileInfo() - { - Name = fileInfo.Name, - IdWell = idWell, - IdCategory = fileInfo.IdCategory, - UploadDate = fileInfo.UploadDate, - IdAuthor = idUser - }; + IdWell = idWell, + IdAuthor = idUser, + IdCategory = idCategory, + Name = Path.GetFileName(fileFullName), + UploadDate = DateTime.Now, + IsDeleted = false, + }; - db.Files.Add(file); - db.SaveChanges(); - fileIdsToNames.Add(file.Name, file.Id); - } - - return fileIdsToNames; - } - - public async Task SaveFile(int idWell, int idCategory, int fileId, - string fileExtension, Stream fileStream) - { + var entry = db.Files.Add(fileInfo); + db.SaveChanges(); + var fileId = entry.Entity.Id; + //save stream to disk var relativePath = Path.Combine(RootPath, $"{idWell}", - $"{idCategory}", $"{fileId}" + $"{fileExtension}"); + $"{idCategory}", $"{fileId}" + $"{Path.GetExtension(fileFullName)}"); Directory.CreateDirectory(Path.GetDirectoryName(relativePath)); @@ -59,9 +49,30 @@ namespace AsbCloudInfrastructure.Services { await fileStream.CopyToAsync(newfileStream); } + + var dto = entry.Entity.Adapt(); + return dto; } - public async Task> GetFilesInfoAsync(int idWell, + public async Task> GetInfosByCategoryAsync(int idWell, + int idCategory, CancellationToken token = default) + { + var entities = await db.Files + .Include(f => f.Author) + .Where(e => e.IdWell == idWell && e.IdCategory == idCategory) + .AsNoTracking() + .ToListAsync(token) + .ConfigureAwait(false); + + var dtos = entities.Adapt((d,s) => { + d.AuthorName = s.Author?.Name; + d.CompanyId = s.Author?.IdCompany ?? 0; + }); + + return dtos; + } + + public async Task> GetInfosAsync(int idWell, int idCategory, IEnumerable companies = default, DateTime begin = default, DateTime end = default, int skip = 0, int take = 32, CancellationToken token = default) { @@ -115,7 +126,7 @@ namespace AsbCloudInfrastructure.Services return result; } - public async Task GetFileInfoAsync(int fileId, + public async Task GetInfoAsync(int fileId, CancellationToken token = default) { var entity = await db.Files @@ -132,17 +143,42 @@ namespace AsbCloudInfrastructure.Services return dto; } - public async Task DeleteFileAsync(int idFile, + public async Task MarkAsDeletedAsync(int idFile, CancellationToken token = default) { - var fileInfo = db.Files.FirstOrDefault(f => f.Id == idFile); + var fileInfo = await db.Files.FirstOrDefaultAsync(f => f.Id == idFile, token).ConfigureAwait(false); if (fileInfo is null) return 0; fileInfo.IsDeleted = true; - return await db.SaveChangesAsync(token); + return await db.SaveChangesAsync(token).ConfigureAwait(false); + } + + public async Task DeletedAsync(int idFile, CancellationToken token) + { + var fileInfo = await db.Files + .FirstOrDefaultAsync(f => f.Id == idFile, token) + .ConfigureAwait(false); + + if (fileInfo is null) + return 0; + + var fileName = GetFileName(fileInfo.Adapt()); + if (File.Exists(fileName)) + File.Delete(fileName); + + db.Files.Remove(fileInfo); + return await db.SaveChangesAsync(token).ConfigureAwait(false); + } + + public string GetFileName(FileInfoDto fileInfo) + { + var fileName = Path.Combine(fileInfo.Id.ToString(), Path.GetExtension(fileInfo.Name)); + fileName = Path.Combine(RootPath, fileInfo.IdWell.ToString(), fileInfo.IdCategory.ToString(), fileName); + fileName = Path.GetFullPath(fileName); + return fileName; } } } diff --git a/AsbCloudInfrastructure/Services/WellService.cs b/AsbCloudInfrastructure/Services/WellService.cs index 972f55c2..75edf50a 100644 --- a/AsbCloudInfrastructure/Services/WellService.cs +++ b/AsbCloudInfrastructure/Services/WellService.cs @@ -77,6 +77,19 @@ namespace AsbCloudInfrastructure.Services return wellDto; } + public async Task GetAsync(int idWell, CancellationToken token) + { + var entity = await db.Wells + .Include(w=>w.Cluster) + .ThenInclude(c=>c.Deposit) + .FirstOrDefaultAsync(w => w.Id == idWell, token) + .ConfigureAwait(false); + + var dto = entity.Adapt(); + dto.Cluster = entity.Cluster?.Caption; + dto.Deposit = entity.Cluster?.Deposit?.Caption; + return dto; + } public async Task GetWellCaptionByIdAsync(int idWell, CancellationToken token) { var entity = await cacheWells.FirstOrDefaultAsync(w => w.Id == idWell, token).ConfigureAwait(false); diff --git a/AsbCloudWebApi/Controllers/DrillingProgramController.cs b/AsbCloudWebApi/Controllers/DrillingProgramController.cs new file mode 100644 index 00000000..8a48e120 --- /dev/null +++ b/AsbCloudWebApi/Controllers/DrillingProgramController.cs @@ -0,0 +1,34 @@ +using AsbCloudApp.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using System.IO; +using System.Threading; +using System.Threading.Tasks; + +namespace AsbCloudWebApi.Controllers +{ + [Route("api/well/{idWell}/files")] + [ApiController] + [Authorize] + public class DrillingProgramController : ControllerBase + { + private readonly IDrillingProgramService drillingProgramService; + private readonly IFileService fileService; + + public DrillingProgramController(IDrillingProgramService drillingProgramService, IFileService fileService) + { + this.drillingProgramService = drillingProgramService; + this.fileService = fileService; + } + + [HttpGet] + [ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)] + public async Task GetAsync(int idWell, CancellationToken token = default) + { + var fileInfo = await drillingProgramService.GetAsync(idWell, token) + .ConfigureAwait(false); + var relativePath = fileService.GetFileName(fileInfo); + return PhysicalFile(Path.GetFullPath(relativePath), "application/octet-stream", fileInfo.Name); + } + } +} diff --git a/AsbCloudWebApi/Controllers/FileController.cs b/AsbCloudWebApi/Controllers/FileController.cs index c974d709..05dfcaeb 100644 --- a/AsbCloudWebApi/Controllers/FileController.cs +++ b/AsbCloudWebApi/Controllers/FileController.cs @@ -56,20 +56,11 @@ namespace AsbCloudWebApi.Controllers UploadDate = DateTime.Now }); - var fileNamesAndIds = fileService.SaveFileInfos(idWell, (int)idUser, - fileInfoCollection); - - foreach (var file in files) { - var fileExtension = Path.GetExtension(file.FileName); - - var fileId = fileNamesAndIds[file.FileName]; - var fileStream = file.OpenReadStream(); - - await fileService.SaveFile(idWell, idCategory, fileId, - fileExtension, fileStream); + await fileService.SaveAsync(idWell, idUser??0, idCategory, file.FileName, + fileStream); } return Ok(); @@ -100,7 +91,7 @@ namespace AsbCloudWebApi.Controllers idWell, token).ConfigureAwait(false)) return Forbid(); - var filesInfo = await fileService.GetFilesInfoAsync(idWell, idCategory, + var filesInfo = await fileService.GetInfosAsync(idWell, idCategory, companies, begin, end, skip, take, token).ConfigureAwait(false); if (filesInfo is null || !filesInfo.Items.Any()) @@ -133,14 +124,13 @@ namespace AsbCloudWebApi.Controllers idWell, token).ConfigureAwait(false)) return Forbid(); - var fileInfo = await fileService.GetFileInfoAsync(fileId, token); + var fileInfo = await fileService.GetInfoAsync(fileId, token); if (fileInfo is null) throw new FileNotFoundException(); // TODO: словарь content typoв - var relativePath = Path.Combine(fileService.RootPath, $"{idWell}", $"{fileInfo.IdCategory}", - $"{fileInfo.Id}" + Path.GetExtension($"{fileInfo.Name}")); + var relativePath = fileService.GetFileName(fileInfo); return PhysicalFile(Path.GetFullPath(relativePath), "application/octet-stream", fileInfo.Name); } catch (FileNotFoundException ex) @@ -167,7 +157,7 @@ namespace AsbCloudWebApi.Controllers idWell, token).ConfigureAwait(false)) return Forbid(); - var result = await fileService.DeleteFileAsync(idFile, token); + var result = await fileService.MarkAsDeletedAsync(idFile, token); return Ok(result); } diff --git a/ConsoleApp1/ConsoleApp1.csproj b/ConsoleApp1/ConsoleApp1.csproj index 40fd5adb..392da02e 100644 --- a/ConsoleApp1/ConsoleApp1.csproj +++ b/ConsoleApp1/ConsoleApp1.csproj @@ -7,6 +7,7 @@ + diff --git a/ConsoleApp1/Program.cs b/ConsoleApp1/Program.cs index 05e2b497..05546ee7 100644 --- a/ConsoleApp1/Program.cs +++ b/ConsoleApp1/Program.cs @@ -2,6 +2,9 @@ using AsbCloudDb.Model; using AsbCloudInfrastructure.Services; using AsbCloudInfrastructure.Services.Cache; +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Spreadsheet; //using AsbSaubReport; //using AutoMapper; using Microsoft.EntityFrameworkCore; @@ -15,29 +18,38 @@ namespace ConsoleApp1 static void Main(/*string[] args*/) { - var options = new DbContextOptionsBuilder() - .UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True") - .Options; - var context = new AsbCloudDbContext(options); + //var options = new DbContextOptionsBuilder() + // .UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True") + // .Options; + //var context = new AsbCloudDbContext(options); - var mservice = new MeasureService(context, new CacheDb()); - var r = mservice.GetAllLastAsync(1, default).Result; + var fileNames = new string[] { @"d:\temp\1\book1.xlsx", @"d:\temp\1\book2.xlsx" }; - //var idWell = 1; - //var dataSource = new ReportDataSourcePgCloud(context, idWell); - //var generator = new PdfGenerator(dataSource) - //{ - // ReportDirectory = $"{idWell}", - // Begin = DateTime.Now.AddYears(-30), - // End = DateTime.Now.AddYears(30), - // Step = TimeSpan.FromDays(1), - // WithCharts = true, - // WithEvents = true - //}; + using var spreadsheetDocument = SpreadsheetDocument.Create(@"d:\temp\1\b.xlsx", SpreadsheetDocumentType.Workbook); + // Add a WorkbookPart and Workbook objects. + WorkbookPart workbookpart = spreadsheetDocument.AddWorkbookPart(); + workbookpart.Workbook = new Workbook(); - //generator.OnProgress += Generator_OnProgress; - //var s = generator.GetPagesCount(); - //var fileName = generator.Make(); + // Add a WorksheetPart to the WorkbookPart. + WorksheetPart worksheetPart = workbookpart.AddNewPart(); + worksheetPart.Worksheet = new Worksheet(new SheetData()); + + // Add Sheets to the Workbook. + Sheets sheets = spreadsheetDocument.WorkbookPart.Workbook. + AppendChild(new Sheets()); + + // Append a new worksheet and associate it with the workbook. + Sheet sheet = new Sheet() + { + Id = spreadsheetDocument.WorkbookPart. + GetIdOfPart(worksheetPart), + SheetId = 1, + Name = "mySheetNameISHere!" + }; + sheets.Append(sheet); + + spreadsheetDocument.Save(); + spreadsheetDocument.Close(); Console.WriteLine("Done. Press any key to quit."); Console.ReadKey();