diff --git a/AsbCloudApp/Services/IPlannedTrajectoryImportService.cs b/AsbCloudApp/Services/IPlannedTrajectoryImportService.cs index 92e878f6..e1a9b328 100644 --- a/AsbCloudApp/Services/IPlannedTrajectoryImportService.cs +++ b/AsbCloudApp/Services/IPlannedTrajectoryImportService.cs @@ -19,7 +19,7 @@ namespace AsbCloudApp.Services /// Получить имя файла (исходя из названия скважины) /// /// - string GetFileName(int idWell, CancellationToken token); + string GetFileNameAsync(int idWell, CancellationToken token); /// /// загрузить текущую плановую траекторию в .xlsx @@ -35,8 +35,8 @@ namespace AsbCloudApp.Services /// /// /// - /// Очистить старые координаты перед импортом (если файл проходит валидацию) - Task ImportAsync(int idWell, int idUser, Stream stream, CancellationToken token, bool deletePlannedTrajectoryBeforeImport = false); + /// Очистить старые координаты перед импортом (если файл проходит валидацию) + Task ImportAsync(int idWell, int idUser, Stream stream, bool deleteBeforeImport, CancellationToken token); } #nullable disable } diff --git a/AsbCloudApp/Services/IPlannedTrajectoryService.cs b/AsbCloudApp/Services/IPlannedTrajectoryService.cs index 573d53b5..d6541fcc 100644 --- a/AsbCloudApp/Services/IPlannedTrajectoryService.cs +++ b/AsbCloudApp/Services/IPlannedTrajectoryService.cs @@ -38,12 +38,11 @@ namespace AsbCloudApp.Services /// /// Обновить строку с координатами - /// - /// + /// /// /// /// - Task UpdateAsync(int idRow, PlannedTrajectoryDto row, + Task UpdateAsync(PlannedTrajectoryDto row, CancellationToken token); /// diff --git a/AsbCloudDb/Model/AsbCloudDbContext.cs b/AsbCloudDb/Model/AsbCloudDbContext.cs index e28f6cde..22e58374 100644 --- a/AsbCloudDb/Model/AsbCloudDbContext.cs +++ b/AsbCloudDb/Model/AsbCloudDbContext.cs @@ -13,7 +13,7 @@ namespace AsbCloudDb.Model public virtual DbSet DailyReports => Set (); public virtual DbSet Deposits => Set(); public virtual DbSet DetectedOperations => Set(); - public virtual DbSet PlannedTrajectorys => Set(); + public virtual DbSet PlannedTrajectories => Set(); public virtual DbSet ProcessMap => Set(); public virtual DbSet DrillingProgramParts => Set(); public virtual DbSet FileCategories => Set(); diff --git a/AsbCloudDb/Model/IAsbCloudDbContext.cs b/AsbCloudDb/Model/IAsbCloudDbContext.cs index 1d5917d8..c092c803 100644 --- a/AsbCloudDb/Model/IAsbCloudDbContext.cs +++ b/AsbCloudDb/Model/IAsbCloudDbContext.cs @@ -15,7 +15,7 @@ namespace AsbCloudDb.Model DbSet DailyReports { get; } DbSet Deposits { get; } DbSet DetectedOperations { get; } - DbSet PlannedTrajectorys { get; } + DbSet PlannedTrajectories { get; } DbSet ProcessMap { get; } DbSet DrillingProgramParts { get; } DbSet FileCategories { get; } diff --git a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj index e60d19f5..f932c782 100644 --- a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj +++ b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj @@ -12,7 +12,7 @@ - + @@ -29,7 +29,7 @@ - + diff --git a/AsbCloudInfrastructure/Services/PlannedTrajectoryService/PlannedTrajectoryImportService.cs b/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryImportService.cs similarity index 97% rename from AsbCloudInfrastructure/Services/PlannedTrajectoryService/PlannedTrajectoryImportService.cs rename to AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryImportService.cs index 0165b54d..97be473a 100644 --- a/AsbCloudInfrastructure/Services/PlannedTrajectoryService/PlannedTrajectoryImportService.cs +++ b/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryImportService.cs @@ -56,7 +56,7 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory return stream; } - public string GetFileName (int idWell, CancellationToken token) + public string GetFileNameAsync (int idWell, CancellationToken token) { var fileName = wellService.GetWellCaptionByIdAsync(idWell, token) + "_plannedTrajectory.xlsx"; return fileName; @@ -118,18 +118,18 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory row.Cell(ColumnComment).Value = trajectory.Comment; } - public async Task ImportAsync(int idWell, int idUser, Stream stream, CancellationToken token, bool deletePrevRows = false) + public async Task ImportAsync(int idWell, int idUser, Stream stream, bool deletePrevRows, CancellationToken token) { using var workbook = new XLWorkbook(stream, XLEventTracking.Disabled); var trajectoryRows = ParseFileStream(stream); foreach (var row in trajectoryRows) row.IdWell = idWell; - var rowsCount = await SavePlannedTrajectoryAsync(idWell,trajectoryRows, token, deletePrevRows); + var rowsCount = await SavePlannedTrajectoryAsync(idWell,trajectoryRows, deletePrevRows, token); return rowsCount; } - private async Task SavePlannedTrajectoryAsync(int idWell, IEnumerable newRows, CancellationToken token, bool deletePrevRow = false) + private async Task SavePlannedTrajectoryAsync(int idWell, IEnumerable newRows, bool deletePrevRow, CancellationToken token) { if (deletePrevRow) { diff --git a/AsbCloudInfrastructure/Services/PlannedTrajectoryService/PlannedTrajectoryService.cs b/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryService.cs similarity index 66% rename from AsbCloudInfrastructure/Services/PlannedTrajectoryService/PlannedTrajectoryService.cs rename to AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryService.cs index 54335204..965b653a 100644 --- a/AsbCloudInfrastructure/Services/PlannedTrajectoryService/PlannedTrajectoryService.cs +++ b/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryService.cs @@ -22,96 +22,93 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory this.db = db; this.wellService = wellService; } + /// public async Task AddRangeAsync(IEnumerable plannedTrajectoryRows, CancellationToken token) - { + { + var idWell = plannedTrajectoryRows.First().IdWell; + var offsetHours = wellService.GetTimezone(idWell).Hours; var entitys = plannedTrajectoryRows - .Select(e => Convert(e)); - db.PlannedTrajectorys.AddRange(entitys); + .Select(e => Convert(e, offsetHours)); + foreach(var item in entitys) + { + item.Id = 0; + } + db.PlannedTrajectories.AddRange(entitys); return await db.SaveChangesAsync(token) .ConfigureAwait(false); } + /// public async Task AddAsync(PlannedTrajectoryDto plannedTrajectoryRow, CancellationToken token) - { - var entity = Convert(plannedTrajectoryRow); - db.PlannedTrajectorys.Add(entity); + { + var offsetHours = wellService.GetTimezone(plannedTrajectoryRow.IdWell).Hours; + var entity = Convert(plannedTrajectoryRow, offsetHours); + entity.Id = 0; + db.PlannedTrajectories.Add(entity); return await db.SaveChangesAsync(token) .ConfigureAwait(false); } - + /// public async Task DeleteRangeAsync(IEnumerable ids, CancellationToken token) { - var query = db.PlannedTrajectorys + var query = db.PlannedTrajectories .Where(e => ids.Contains(e.Id)); - db.PlannedTrajectorys.RemoveRange(query); + db.PlannedTrajectories.RemoveRange(query); return await db.SaveChangesAsync(token) .ConfigureAwait(false); } + /// public async Task DeleteByIdWellAsync(int idWell, CancellationToken token) { - var query = db.PlannedTrajectorys + var query = db.PlannedTrajectories .Where(e => e.IdWell == idWell); - db.PlannedTrajectorys.RemoveRange(query); + db.PlannedTrajectories.RemoveRange(query); return await db.SaveChangesAsync(token) .ConfigureAwait(false); } - + /// public async Task> GetAsync(int idWell, CancellationToken token) { var well = wellService.GetOrDefault(idWell); - var timezone = wellService.GetTimezone(idWell); + var offsetHours = wellService.GetTimezone(idWell).Hours; if (well is null || well.Timezone is null) throw new ArgumentInvalidException("idWell doesn`t exist", nameof(idWell)); - var query = db.PlannedTrajectorys + var query = db.PlannedTrajectories .AsNoTracking() .Where(x => x.IdWell == idWell); var entities = await query .OrderBy(e => e.UpdateDate) .ToListAsync(token); var result = entities - .Select(r => Convert(r)); + .Select(r => Convert(r, offsetHours)); return result; } - public async Task UpdateAsync(int idRow, PlannedTrajectoryDto row, CancellationToken token) + /// + public async Task UpdateAsync(PlannedTrajectoryDto row, CancellationToken token) { - var entity = Convert(row, idRow); - db.PlannedTrajectorys.Update(entity); + var entity = Convert(row, row.Id); + db.PlannedTrajectories.Update(entity); return await db.SaveChangesAsync(token) .ConfigureAwait(false); } - private PlannedTrajectoryDto Convert(AsbCloudDb.Model.PlannedTrajectory entity) - { - var timezone = wellService.GetTimezone(entity.IdWell); + private PlannedTrajectoryDto Convert(AsbCloudDb.Model.PlannedTrajectory entity, double offsetHours) + { var dto = entity.Adapt(); - dto.UpdateDate = entity.UpdateDate.ToRemoteDateTime(timezone.Hours); + dto.UpdateDate = entity.UpdateDate.ToRemoteDateTime(offsetHours); return dto; } - private AsbCloudDb.Model.PlannedTrajectory Convert(PlannedTrajectoryDto dto) - { - var timezone = wellService.GetTimezone(dto.IdWell); + private AsbCloudDb.Model.PlannedTrajectory Convert(PlannedTrajectoryDto dto, double offsetHours) + { var entity = dto.Adapt(); - entity.IdWell = dto.IdWell; - entity.Id = 0; - entity.UpdateDate = DateTime.Now.ToUtcDateTimeOffset(timezone.Hours); - entity.IdUser = dto.IdUser; + entity.UpdateDate = DateTime.Now.ToUtcDateTimeOffset(offsetHours); return entity; - } - private AsbCloudDb.Model.PlannedTrajectory Convert(PlannedTrajectoryDto dto, int idRow) - { - var timezone = wellService.GetTimezone(dto.IdWell); - var entity = dto.Adapt(); - entity.IdWell = dto.IdWell; - entity.Id = idRow; - entity.UpdateDate = DateTime.Now.ToUtcDateTimeOffset(timezone.Hours); - entity.IdUser = dto.IdUser; - return entity; - } + } } #nullable disable } diff --git a/AsbCloudInfrastructure/Services/PlannedTrajectoryService/PlannedTrajectoryTemplate.xlsx b/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryTemplate.xlsx similarity index 100% rename from AsbCloudInfrastructure/Services/PlannedTrajectoryService/PlannedTrajectoryTemplate.xlsx rename to AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryTemplate.xlsx diff --git a/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs b/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs index c4e65f2f..80349b6f 100644 --- a/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs +++ b/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs @@ -61,7 +61,7 @@ namespace AsbCloudWebApi.Controllers token).ConfigureAwait(false)) return Forbid(); var stream = await plannedTrajectoryImportService.ExportAsync(idWell, token); - var fileName = plannedTrajectoryImportService.GetFileName(idWell, token); + var fileName = plannedTrajectoryImportService.GetFileNameAsync(idWell, token); return File(stream, "application/octet-stream", fileName); } @@ -76,6 +76,7 @@ namespace AsbCloudWebApi.Controllers [HttpPost] [Permission] [Route("import/{options}")] + [ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)] public async Task ImportAsync(int idWell, [FromForm] IFormFileCollection files, int options = 0, @@ -96,7 +97,7 @@ namespace AsbCloudWebApi.Controllers try { - var result = plannedTrajectoryImportService.ImportAsync(idWell, idUser.Value, stream, token, (options & 1) > 0); + var result = plannedTrajectoryImportService.ImportAsync(idWell, idUser.Value, stream, (options & 1) > 0, token); return Ok(result); } catch (FileFormatException ex) @@ -110,12 +111,12 @@ namespace AsbCloudWebApi.Controllers /// /// id скважины /// Токен отмены задачи - /// Запрашиваемый файл + /// Список добавленных координат плановой траектории [HttpGet] - [Route("allRows")] + [Route("getRows")] [Permission] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] - public async Task GetRows([FromRoute] int idWell, CancellationToken token = default) + public async Task GetAsync([FromRoute] int idWell, CancellationToken token = default) { if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) @@ -134,13 +135,13 @@ namespace AsbCloudWebApi.Controllers [HttpPost] [Route("addRow")] [Permission] - [ProducesResponseType(typeof(PlannedTrajectoryDto), (int)System.Net.HttpStatusCode.OK)] - public async Task AddRowAsync(int idWell, [FromBody] PlannedTrajectoryDto row, + [ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)] + public async Task AddAsync(int idWell, [FromBody] PlannedTrajectoryDto row, CancellationToken token = default) { if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) return Forbid(); - int? idUser = User.GetUserId(); + var idUser = User.GetUserId(); if (!idUser.HasValue) return Forbid(); row.IdUser = idUser.Value; @@ -160,8 +161,8 @@ namespace AsbCloudWebApi.Controllers [HttpPost] [Route("addRangeRows")] [Permission] - [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] - public async Task AddRangeRowsAsync(int idWell, [FromBody] IEnumerable rows, + [ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)] + public async Task AddRangeAsync(int idWell, [FromBody] IEnumerable rows, CancellationToken token = default) { if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) @@ -183,14 +184,13 @@ namespace AsbCloudWebApi.Controllers /// Изменить выбранную строку с координатами /// /// - /// /// /// /// количество успешно обновленных строк в БД [HttpPut("{idRow}")] [Permission] - [ProducesResponseType(typeof(PlannedTrajectoryDto), (int)System.Net.HttpStatusCode.OK)] - public async Task UpdateRowAsync(int idWell, int idRow, + [ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)] + public async Task UpdateAsync(int idWell, [FromBody] PlannedTrajectoryDto row, CancellationToken token = default) { if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) @@ -200,7 +200,7 @@ namespace AsbCloudWebApi.Controllers return Forbid(); row.IdUser = idUser.Value; row.IdWell = idWell; - var result = await plannedTrajectoryService.UpdateAsync(idRow, row, token) + var result = await plannedTrajectoryService.UpdateAsync(row, token) .ConfigureAwait(false); return Ok(result); } @@ -215,7 +215,7 @@ namespace AsbCloudWebApi.Controllers [HttpDelete("{idRow}")] [Permission] [ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)] - public async Task DeleteRowAsync(int idWell, int idRow, CancellationToken token = default) + public async Task DeleteAsync(int idWell, int idRow, CancellationToken token = default) { if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))