diff --git a/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryImportService.cs b/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryImportService.cs index 5dd1c414..8e2278fa 100644 --- a/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryImportService.cs +++ b/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryImportService.cs @@ -21,7 +21,7 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory private readonly IPlannedTrajectoryService plannedTrajectoryService; private const string templateFileName = "PlannedTrajectoryTemplate.xlsx"; - private const string usingTemplateFile = "AsbCloudInfrastructure.Services.PlannedTrajectoryService"; + private const string usingTemplateFile = "AsbCloudInfrastructure.Services.PlannedTrajectory"; private const string sheetNamePlannedTrajectory = "Плановая траектория"; private const int headerRowsCount = 2; private const int ColumnWellboreDepth = 1; @@ -123,7 +123,10 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory using var workbook = new XLWorkbook(stream, XLEventTracking.Disabled); var trajectoryRows = ParseFileStream(stream); foreach (var row in trajectoryRows) - row.IdWell = idWell; + { + row.IdWell = idWell; + row.IdUser = idUser; + } var rowsCount = await SavePlannedTrajectoryAsync(idWell,trajectoryRows, deletePrevRows, token); return rowsCount; @@ -132,9 +135,7 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory private async Task SavePlannedTrajectoryAsync(int idWell, IEnumerable newRows, bool deletePrevRow, CancellationToken token) { if (deletePrevRow) - { await plannedTrajectoryService.DeleteByIdWellAsync(idWell, token); - } var rowsCount = await plannedTrajectoryService.AddRangeAsync(newRows, token); return rowsCount; } diff --git a/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryService.cs b/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryService.cs index 7466cde3..d00a9563 100644 --- a/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryService.cs +++ b/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryService.cs @@ -29,13 +29,13 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory if (!plannedTrajectoryRows.All(r => r.IdWell == idWell)) throw new ArgumentInvalidException("Все строки должны относиться к одной скважине", nameof(plannedTrajectoryRows)); var offsetHours = wellService.GetTimezone(idWell).Hours; - var entitys = plannedTrajectoryRows - .Select(e => Convert(e, offsetHours)); - foreach(var item in entitys) - { - item.Id = 0; - } - db.PlannedTrajectories.AddRange(entitys); + var entities = plannedTrajectoryRows + .Select(e => { + var entity = Convert(e, offsetHours); + entity.Id = 0; + return entity;}); + + db.PlannedTrajectories.AddRange(entities); return await db.SaveChangesAsync(token) .ConfigureAwait(false); } @@ -82,7 +82,7 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory .AsNoTracking() .Where(x => x.IdWell == idWell); var entities = await query - .OrderBy(e => e.UpdateDate) + .OrderBy(e => e.WellboreDepth) .ToListAsync(token); var result = entities .Select(r => Convert(r, offsetHours)); diff --git a/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs b/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs index 362211c2..f3d5e8e2 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.GetFileNameAsync(idWell, token).Result.ToString(); + var fileName = await plannedTrajectoryImportService.GetFileNameAsync(idWell, token); return File(stream, "application/octet-stream", fileName); } @@ -75,12 +75,12 @@ namespace AsbCloudWebApi.Controllers /// количество успешно записанных строк в БД [HttpPost] [Permission] - [Route("import/{options}")] + [Route("import/{deleteBeforeImport}")] [ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)] public async Task ImportAsync(int idWell, [FromForm] IFormFileCollection files, - int options = 0, - CancellationToken token = default) + bool deleteBeforeImport, + CancellationToken token) { int? idUser = User.GetUserId(); if (!idUser.HasValue) @@ -97,7 +97,7 @@ namespace AsbCloudWebApi.Controllers try { - var result = plannedTrajectoryImportService.ImportAsync(idWell, idUser.Value, stream, (options & 1) > 0, token); + var result = await plannedTrajectoryImportService.ImportAsync(idWell, idUser.Value, stream, deleteBeforeImport, token); return Ok(result); } catch (FileFormatException ex) @@ -121,7 +121,7 @@ namespace AsbCloudWebApi.Controllers if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) return Forbid(); - var result = plannedTrajectoryService.GetAsync(idWell, token); + var result = await plannedTrajectoryService.GetAsync(idWell, token); return Ok(result); } @@ -146,8 +146,7 @@ namespace AsbCloudWebApi.Controllers return Forbid(); row.IdUser = idUser.Value; row.IdWell = idWell; - var result = await plannedTrajectoryService.AddAsync(row, token) - .ConfigureAwait(false); + var result = await plannedTrajectoryService.AddAsync(row, token); return Ok(result); } @@ -175,8 +174,7 @@ namespace AsbCloudWebApi.Controllers item.IdUser = idUser.Value; item.IdWell = idWell; } - var result = await plannedTrajectoryService.AddRangeAsync(rows, token) - .ConfigureAwait(false); + var result = await plannedTrajectoryService.AddRangeAsync(rows, token); return Ok(result); } @@ -184,13 +182,14 @@ namespace AsbCloudWebApi.Controllers /// Изменить выбранную строку с координатами /// /// + /// /// /// /// количество успешно обновленных строк в БД [HttpPut("{idRow}")] [Permission] [ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)] - public async Task UpdateAsync(int idWell, + public async Task UpdateAsync(int idWell, int idRow, [FromBody] PlannedTrajectoryDto row, CancellationToken token = default) { if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) @@ -198,10 +197,10 @@ namespace AsbCloudWebApi.Controllers int? idUser = User.GetUserId(); if (!idUser.HasValue) return Forbid(); + row.Id = idRow; row.IdUser = idUser.Value; row.IdWell = idWell; - var result = await plannedTrajectoryService.UpdateAsync(row, token) - .ConfigureAwait(false); + var result = await plannedTrajectoryService.UpdateAsync(row, token); return Ok(result); } @@ -221,8 +220,7 @@ namespace AsbCloudWebApi.Controllers token).ConfigureAwait(false)) return Forbid(); - var result = await plannedTrajectoryService.DeleteRangeAsync(new int[] { idRow }, token) - .ConfigureAwait(false); + var result = await plannedTrajectoryService.DeleteRangeAsync(new int[] { idRow }, token); return Ok(result); }