forked from ddrilling/AsbCloudServer
повторный рефакт
после ревью
This commit is contained in:
parent
ec97b02480
commit
46453b3893
@ -19,11 +19,11 @@ namespace AsbCloudApp.Data
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Дата загрузки
|
/// Дата загрузки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTimeOffset UpdateDate { get; set; }
|
public DateTime UpdateDate { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ИД пользователя
|
/// ИД пользователя
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double IdUser { get; set; }
|
public int IdUser { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Глубина по стволу
|
/// Глубина по стволу
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -35,8 +35,8 @@ namespace AsbCloudApp.Services
|
|||||||
/// <param name="idUser"></param>
|
/// <param name="idUser"></param>
|
||||||
/// <param name="stream"></param>
|
/// <param name="stream"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <param name="deleteWellOperationsBeforeImport">Очистить старые координаты перед импортом (если файл проходит валидацию)</param>
|
/// <param name="deletePlannedTrajectoryBeforeImport">Очистить старые координаты перед импортом (если файл проходит валидацию)</param>
|
||||||
Task<int> ImportAsync(int idWell, int idUser, Stream stream, CancellationToken token, bool deleteWellOperationsBeforeImport = false);
|
Task<int> ImportAsync(int idWell, int idUser, Stream stream, CancellationToken token, bool deletePlannedTrajectoryBeforeImport = false);
|
||||||
}
|
}
|
||||||
#nullable disable
|
#nullable disable
|
||||||
}
|
}
|
||||||
|
@ -18,40 +18,32 @@ namespace AsbCloudApp.Services
|
|||||||
/// <param name="idWell"></param>
|
/// <param name="idWell"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<PlannedTrajectoryDto>> GetOrDefaultAsync(int idWell, CancellationToken token);
|
Task<IEnumerable<PlannedTrajectoryDto>> GetAsync(int idWell, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавить строки с координатами
|
/// Добавить строки с координатами
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell"></param>
|
|
||||||
/// <param name="idUser"></param>
|
|
||||||
/// <param name="plannedTrajectoryRows"></param>
|
/// <param name="plannedTrajectoryRows"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<int> AddRangeAsync(int idWell, int idUser,
|
Task<int> AddRangeAsync(IEnumerable<PlannedTrajectoryDto> plannedTrajectoryRows, CancellationToken token);
|
||||||
IEnumerable<PlannedTrajectoryDto> plannedTrajectoryRows, CancellationToken token);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавить одну строку с координатами
|
/// Добавить одну строку с координатами
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell"></param>
|
|
||||||
/// <param name="idUser"></param>
|
|
||||||
/// <param name="plannedTrajectoryRow"></param>
|
/// <param name="plannedTrajectoryRow"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<int> AddAsync(int idWell, int idUser,
|
Task<int> AddAsync(PlannedTrajectoryDto plannedTrajectoryRow, CancellationToken token);
|
||||||
PlannedTrajectoryDto plannedTrajectoryRow, CancellationToken token);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Обновить строку с координатами
|
/// Обновить строку с координатами
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell"></param>
|
|
||||||
/// <param name="idUser"></param>
|
|
||||||
/// <param name="idRow"></param>
|
/// <param name="idRow"></param>
|
||||||
/// <param name="row"></param>
|
/// <param name="row"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<int> UpdateAsync(int idWell, int idUser, int idRow, PlannedTrajectoryDto row,
|
Task<int> UpdateAsync(int idRow, PlannedTrajectoryDto row,
|
||||||
CancellationToken token);
|
CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -68,7 +60,7 @@ namespace AsbCloudApp.Services
|
|||||||
/// <param name="idWell"></param>
|
/// <param name="idWell"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task DeleteAllByIdWellAsync(int idWell, CancellationToken token);
|
Task<int> DeleteByIdWellAsync(int idWell, CancellationToken token);
|
||||||
}
|
}
|
||||||
#nullable disable
|
#nullable disable
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using ClosedXML.Excel;
|
using ClosedXML.Excel;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -19,6 +20,8 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory
|
|||||||
private readonly IWellService wellService;
|
private readonly IWellService wellService;
|
||||||
private readonly IPlannedTrajectoryService plannedTrajectoryService;
|
private readonly IPlannedTrajectoryService plannedTrajectoryService;
|
||||||
|
|
||||||
|
private const string templateFileName = "PlannedTrajectoryTemplate.xlsx";
|
||||||
|
private const string usingTemplateFile = "AsbCloudInfrastructure.Services.PlannedTrajectoryService";
|
||||||
private const string sheetNamePlannedTrajectory = "Плановая траектория";
|
private const string sheetNamePlannedTrajectory = "Плановая траектория";
|
||||||
private const int headerRowsCount = 2;
|
private const int headerRowsCount = 2;
|
||||||
private const int ColumnWellboreDepth = 1;
|
private const int ColumnWellboreDepth = 1;
|
||||||
@ -47,7 +50,9 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory
|
|||||||
public Stream GetTemplateFile()
|
public Stream GetTemplateFile()
|
||||||
{
|
{
|
||||||
var stream = System.Reflection.Assembly.GetExecutingAssembly()
|
var stream = System.Reflection.Assembly.GetExecutingAssembly()
|
||||||
.GetManifestResourceStream("AsbCloudInfrastructure.Services.PlannedTrajectoryService.PlannedTrajectoryTemplate.xlsx");
|
.GetManifestResourceStream($"{usingTemplateFile}.{templateFileName}");
|
||||||
|
if (stream is null)
|
||||||
|
throw new Exception($"Область {usingTemplateFile} не содержит файла с названием {templateFileName}");
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,9 +64,7 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory
|
|||||||
|
|
||||||
public async Task<Stream> ExportAsync(int idWell, CancellationToken token)
|
public async Task<Stream> ExportAsync(int idWell, CancellationToken token)
|
||||||
{
|
{
|
||||||
var plannedTrajectorys = await plannedTrajectoryService.GetOrDefaultAsync(idWell, token);
|
var plannedTrajectorys = await plannedTrajectoryService.GetAsync(idWell, token);
|
||||||
if (!plannedTrajectorys.Any())
|
|
||||||
return null;
|
|
||||||
return MakeExelFileStream(plannedTrajectorys);
|
return MakeExelFileStream(plannedTrajectorys);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,32 +72,34 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory
|
|||||||
{
|
{
|
||||||
using Stream ecxelTemplateStream = GetTemplateFile();
|
using Stream ecxelTemplateStream = GetTemplateFile();
|
||||||
using var workbook = new XLWorkbook(ecxelTemplateStream, XLEventTracking.Disabled);
|
using var workbook = new XLWorkbook(ecxelTemplateStream, XLEventTracking.Disabled);
|
||||||
AddOperationsToWorkbook(workbook, plannedTrajectories);
|
AddPlannedTrajecoryToWorkbook(workbook, plannedTrajectories);
|
||||||
MemoryStream memoryStream = new MemoryStream();
|
MemoryStream memoryStream = new MemoryStream();
|
||||||
workbook.SaveAs(memoryStream, new SaveOptions { });
|
workbook.SaveAs(memoryStream, new SaveOptions { });
|
||||||
memoryStream.Seek(0, SeekOrigin.Begin);
|
memoryStream.Seek(0, SeekOrigin.Begin);
|
||||||
return memoryStream;
|
return memoryStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void AddOperationsToWorkbook(XLWorkbook workbook, IEnumerable<PlannedTrajectoryDto> plannedTrajectories)
|
private static void AddPlannedTrajecoryToWorkbook(XLWorkbook workbook, IEnumerable<PlannedTrajectoryDto> plannedTrajectories)
|
||||||
{
|
{
|
||||||
if (plannedTrajectories.Any())
|
if (plannedTrajectories.Any())
|
||||||
{
|
{
|
||||||
var sheet = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetNamePlannedTrajectory);
|
var sheet = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetNamePlannedTrajectory);
|
||||||
AddOperationsToSheet(sheet, plannedTrajectories);
|
if (sheet is null)
|
||||||
|
throw new FileFormatException($"Лист с именем {sheetNamePlannedTrajectory} отсутствует, либо имеет некорректное название");
|
||||||
|
AddPlannedTrajecoryToSheet(sheet, plannedTrajectories);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void AddOperationsToSheet(IXLWorksheet sheet, IEnumerable<PlannedTrajectoryDto> plannedTrajectories)
|
private static void AddPlannedTrajecoryToSheet(IXLWorksheet sheet, IEnumerable<PlannedTrajectoryDto> plannedTrajectories)
|
||||||
{
|
{
|
||||||
var rowList = plannedTrajectories.ToList();
|
var rowList = plannedTrajectories.ToList();
|
||||||
for (int i = 0; i < rowList.Count; i++)
|
for (int i = 0; i < rowList.Count; i++)
|
||||||
{
|
{
|
||||||
var row = sheet.Row(1 + i + headerRowsCount);
|
var row = sheet.Row(1 + i + headerRowsCount);
|
||||||
AddOperationToRow(row, rowList[i]);
|
AddCoordinatesToRow(row, rowList[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static void AddOperationToRow(IXLRow row, PlannedTrajectoryDto trajectory)
|
private static void AddCoordinatesToRow(IXLRow row, PlannedTrajectoryDto trajectory)
|
||||||
{
|
{
|
||||||
row.Cell(ColumnWellboreDepth).Value = trajectory.WellboreDepth;
|
row.Cell(ColumnWellboreDepth).Value = trajectory.WellboreDepth;
|
||||||
row.Cell(ColumnZenithAngle).Value = trajectory.ZenithAngle;
|
row.Cell(ColumnZenithAngle).Value = trajectory.ZenithAngle;
|
||||||
@ -120,17 +125,17 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory
|
|||||||
foreach (var row in trajectoryRows)
|
foreach (var row in trajectoryRows)
|
||||||
row.IdWell = idWell;
|
row.IdWell = idWell;
|
||||||
|
|
||||||
var rowsCount = await SavePlannedTrajectoryAsync(idWell, idUser, trajectoryRows, token, deletePrevRows);
|
var rowsCount = await SavePlannedTrajectoryAsync(idWell,trajectoryRows, token, deletePrevRows);
|
||||||
return rowsCount;
|
return rowsCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<int> SavePlannedTrajectoryAsync(int idWell, int idUser, IEnumerable<PlannedTrajectoryDto> newRows, CancellationToken token, bool deletePrevRow = false)
|
private async Task<int> SavePlannedTrajectoryAsync(int idWell, IEnumerable<PlannedTrajectoryDto> newRows, CancellationToken token, bool deletePrevRow = false)
|
||||||
{
|
{
|
||||||
if (deletePrevRow)
|
if (deletePrevRow)
|
||||||
{
|
{
|
||||||
await plannedTrajectoryService.DeleteAllByIdWellAsync(idWell, token);
|
await plannedTrajectoryService.DeleteByIdWellAsync(idWell, token);
|
||||||
}
|
}
|
||||||
var rowsCount = await plannedTrajectoryService.AddRangeAsync(idWell, idUser, newRows, token);
|
var rowsCount = await plannedTrajectoryService.AddRangeAsync(newRows, token);
|
||||||
return rowsCount;
|
return rowsCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +162,7 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory
|
|||||||
var count = sheet.RowsUsed().Count() - headerRowsCount;
|
var count = sheet.RowsUsed().Count() - headerRowsCount;
|
||||||
|
|
||||||
if (count > 1024)
|
if (count > 1024)
|
||||||
throw new FileFormatException($"Лист {sheet.Name} содержит слишком большое количество операций.");
|
throw new FileFormatException($"Лист {sheet.Name} содержит слишком большое количество строк.");
|
||||||
|
|
||||||
if (count <= 0)
|
if (count <= 0)
|
||||||
throw new FileFormatException($"Лист {sheet.Name} некорректного формата либо пустой");
|
throw new FileFormatException($"Лист {sheet.Name} некорректного формата либо пустой");
|
||||||
|
@ -22,20 +22,18 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory
|
|||||||
this.db = db;
|
this.db = db;
|
||||||
this.wellService = wellService;
|
this.wellService = wellService;
|
||||||
}
|
}
|
||||||
public async Task<int> AddRangeAsync(int idWell, int idUser,IEnumerable<PlannedTrajectoryDto> plannedTrajectoryRows, CancellationToken token)
|
public async Task<int> AddRangeAsync(IEnumerable<PlannedTrajectoryDto> plannedTrajectoryRows, CancellationToken token)
|
||||||
{
|
{
|
||||||
var timezone = wellService.GetTimezone(idWell);
|
|
||||||
var entitys = plannedTrajectoryRows
|
var entitys = plannedTrajectoryRows
|
||||||
.Select(e => Convert(e, timezone, idWell, idUser));
|
.Select(e => Convert(e));
|
||||||
db.PlannedTrajectorys.AddRange(entitys);
|
db.PlannedTrajectorys.AddRange(entitys);
|
||||||
return await db.SaveChangesAsync(token)
|
return await db.SaveChangesAsync(token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<int> AddAsync(int idWell, int idUser, PlannedTrajectoryDto plannedTrajectoryRow, CancellationToken token)
|
public async Task<int> AddAsync(PlannedTrajectoryDto plannedTrajectoryRow, CancellationToken token)
|
||||||
{
|
{
|
||||||
var timezone = wellService.GetTimezone(idWell);
|
var entity = Convert(plannedTrajectoryRow);
|
||||||
var entity = Convert(plannedTrajectoryRow, timezone, idWell, idUser);
|
|
||||||
db.PlannedTrajectorys.Add(entity);
|
db.PlannedTrajectorys.Add(entity);
|
||||||
return await db.SaveChangesAsync(token)
|
return await db.SaveChangesAsync(token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
@ -51,21 +49,20 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory
|
|||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task DeleteAllByIdWellAsync(int idWell, CancellationToken token)
|
public async Task<int> DeleteByIdWellAsync(int idWell, CancellationToken token)
|
||||||
{
|
{
|
||||||
var query = db.PlannedTrajectorys
|
var query = db.PlannedTrajectorys
|
||||||
.AsNoTracking()
|
|
||||||
.Where(e => e.IdWell == idWell);
|
.Where(e => e.IdWell == idWell);
|
||||||
var ids = await query
|
db.PlannedTrajectorys.RemoveRange(query);
|
||||||
.Select(r => r.IdWell)
|
return await db.SaveChangesAsync(token)
|
||||||
.ToListAsync(token);
|
.ConfigureAwait(false);
|
||||||
var result = await DeleteRangeAsync(ids, token);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task<IEnumerable<PlannedTrajectoryDto>> GetOrDefaultAsync(int idWell, CancellationToken token)
|
public async Task<IEnumerable<PlannedTrajectoryDto>> GetAsync(int idWell, CancellationToken token)
|
||||||
{
|
{
|
||||||
var well = wellService.GetOrDefault(idWell);
|
var well = wellService.GetOrDefault(idWell);
|
||||||
|
var timezone = wellService.GetTimezone(idWell);
|
||||||
if (well is null || well.Timezone is null)
|
if (well is null || well.Timezone is null)
|
||||||
throw new ArgumentInvalidException("idWell doesn`t exist", nameof(idWell));
|
throw new ArgumentInvalidException("idWell doesn`t exist", nameof(idWell));
|
||||||
var query = db.PlannedTrajectorys
|
var query = db.PlannedTrajectorys
|
||||||
@ -79,36 +76,42 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<int> UpdateAsync(int idWell, int idUser, int idRow, PlannedTrajectoryDto row, CancellationToken token)
|
public async Task<int> UpdateAsync(int idRow, PlannedTrajectoryDto row, CancellationToken token)
|
||||||
{
|
{
|
||||||
var timezone = wellService.GetTimezone(idWell);
|
var entity = Convert(row, idRow);
|
||||||
var entity = row.Adapt<AsbCloudDb.Model.PlannedTrajectory>();
|
|
||||||
entity.IdWell = idWell;
|
|
||||||
entity.Id = idUser;
|
|
||||||
entity.UpdateDate = DateTime.Today.ToUtcDateTimeOffset(timezone.Hours);
|
|
||||||
entity.IdUser = idUser;
|
|
||||||
db.PlannedTrajectorys.Update(entity);
|
db.PlannedTrajectorys.Update(entity);
|
||||||
return await db.SaveChangesAsync(token)
|
return await db.SaveChangesAsync(token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PlannedTrajectoryDto Convert(AsbCloudDb.Model.PlannedTrajectory entity)
|
private PlannedTrajectoryDto Convert(AsbCloudDb.Model.PlannedTrajectory entity)
|
||||||
{
|
{
|
||||||
|
var timezone = wellService.GetTimezone(entity.IdWell);
|
||||||
var dto = entity.Adapt<PlannedTrajectoryDto>();
|
var dto = entity.Adapt<PlannedTrajectoryDto>();
|
||||||
|
dto.UpdateDate = entity.UpdateDate.ToRemoteDateTime(timezone.Hours);
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static AsbCloudDb.Model.PlannedTrajectory Convert(PlannedTrajectoryDto dto, SimpleTimezoneDto timezone, int idWell, int idUser)
|
private AsbCloudDb.Model.PlannedTrajectory Convert(PlannedTrajectoryDto dto)
|
||||||
{
|
{
|
||||||
|
var timezone = wellService.GetTimezone(dto.IdWell);
|
||||||
var entity = dto.Adapt<AsbCloudDb.Model.PlannedTrajectory>();
|
var entity = dto.Adapt<AsbCloudDb.Model.PlannedTrajectory>();
|
||||||
entity.IdWell = idWell;
|
entity.IdWell = dto.IdWell;
|
||||||
entity.Id = default;
|
entity.Id = 0;
|
||||||
entity.UpdateDate = DateTime.Today.ToUtcDateTimeOffset(timezone.Hours);
|
entity.UpdateDate = DateTime.Now.ToUtcDateTimeOffset(timezone.Hours);
|
||||||
entity.IdUser = idUser;
|
entity.IdUser = dto.IdUser;
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
private AsbCloudDb.Model.PlannedTrajectory Convert(PlannedTrajectoryDto dto, int idRow)
|
||||||
|
{
|
||||||
|
var timezone = wellService.GetTimezone(dto.IdWell);
|
||||||
|
var entity = dto.Adapt<AsbCloudDb.Model.PlannedTrajectory>();
|
||||||
|
entity.IdWell = dto.IdWell;
|
||||||
|
entity.Id = idRow;
|
||||||
|
entity.UpdateDate = DateTime.Now.ToUtcDateTimeOffset(timezone.Hours);
|
||||||
|
entity.IdUser = dto.IdUser;
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
#nullable disable
|
#nullable disable
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
@ -72,7 +72,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <param name="files">Коллекция из одного файла xlsx</param>
|
/// <param name="files">Коллекция из одного файла xlsx</param>
|
||||||
/// <param name="options">Удалить операции перед импортом = 1, если фал валидный</param>
|
/// <param name="options">Удалить операции перед импортом = 1, если фал валидный</param>
|
||||||
/// <param name="token"> Токен отмены задачи </param>
|
/// <param name="token"> Токен отмены задачи </param>
|
||||||
/// <returns></returns>
|
/// <returns>количество успешно записанных строк в БД</returns>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Permission]
|
[Permission]
|
||||||
[Route("import/{options}")]
|
[Route("import/{options}")]
|
||||||
@ -81,20 +81,14 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
int options = 0,
|
int options = 0,
|
||||||
CancellationToken token = default)
|
CancellationToken token = default)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
|
||||||
int? idUser = User.GetUserId();
|
int? idUser = User.GetUserId();
|
||||||
if (!idUser.HasValue)
|
if (!idUser.HasValue)
|
||||||
return Forbid();
|
return Forbid();
|
||||||
if (idCompany is null || idUser is null)
|
if (!await CanUserAccessToWellAsync(idWell,
|
||||||
|
token).ConfigureAwait(false))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
||||||
idWell, token).ConfigureAwait(false))
|
|
||||||
return Forbid();
|
|
||||||
|
|
||||||
if (files.Count < 1)
|
if (files.Count < 1)
|
||||||
return BadRequest("нет файла");
|
return BadRequest("нет файла");
|
||||||
|
|
||||||
var file = files[0];
|
var file = files[0];
|
||||||
if (Path.GetExtension(file.FileName).ToLower() != ".xlsx")
|
if (Path.GetExtension(file.FileName).ToLower() != ".xlsx")
|
||||||
return BadRequest("Требуется xlsx файл.");
|
return BadRequest("Требуется xlsx файл.");
|
||||||
@ -123,16 +117,10 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
[ProducesResponseType(typeof(IEnumerable<PlannedTrajectoryDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<PlannedTrajectoryDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> GetRows([FromRoute] int idWell, CancellationToken token = default)
|
public async Task<IActionResult> GetRows([FromRoute] int idWell, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
if (!await CanUserAccessToWellAsync(idWell,
|
||||||
|
token).ConfigureAwait(false))
|
||||||
if (idCompany is null)
|
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
var result = plannedTrajectoryService.GetAsync(idWell, token);
|
||||||
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
||||||
idWell, token).ConfigureAwait(false))
|
|
||||||
return Forbid();
|
|
||||||
|
|
||||||
var result = plannedTrajectoryService.GetOrDefaultAsync(idWell,token);
|
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,8 +130,9 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <param name="idWell"></param>
|
/// <param name="idWell"></param>
|
||||||
/// <param name="row"></param>
|
/// <param name="row"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns>количество успешно записанных строк в БД</returns>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
|
[Route("addRow")]
|
||||||
[Permission]
|
[Permission]
|
||||||
[ProducesResponseType(typeof(PlannedTrajectoryDto), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(PlannedTrajectoryDto), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> AddRowAsync(int idWell, [FromBody] PlannedTrajectoryDto row,
|
public async Task<IActionResult> AddRowAsync(int idWell, [FromBody] PlannedTrajectoryDto row,
|
||||||
@ -154,7 +143,9 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
int? idUser = User.GetUserId();
|
int? idUser = User.GetUserId();
|
||||||
if (!idUser.HasValue)
|
if (!idUser.HasValue)
|
||||||
return Forbid();
|
return Forbid();
|
||||||
var result = await plannedTrajectoryService.AddAsync(idWell, idUser.Value, row, token)
|
row.IdUser = idUser.Value;
|
||||||
|
row.IdWell = idWell;
|
||||||
|
var result = await plannedTrajectoryService.AddAsync(row, token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
@ -165,11 +156,12 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <param name="idWell"></param>
|
/// <param name="idWell"></param>
|
||||||
/// <param name="rows"></param>
|
/// <param name="rows"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns>количество успешно записанных строк в БД</returns>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
|
[Route("addRangeRows")]
|
||||||
[Permission]
|
[Permission]
|
||||||
[ProducesResponseType(typeof(PlannedTrajectoryDto), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<PlannedTrajectoryDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> AddRowAsync(int idWell, [FromBody] IEnumerable<PlannedTrajectoryDto> rows,
|
public async Task<IActionResult> AddRangeRowsAsync(int idWell, [FromBody] IEnumerable<PlannedTrajectoryDto> rows,
|
||||||
CancellationToken token = default)
|
CancellationToken token = default)
|
||||||
{
|
{
|
||||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||||
@ -177,7 +169,12 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
int? idUser = User.GetUserId();
|
int? idUser = User.GetUserId();
|
||||||
if (!idUser.HasValue)
|
if (!idUser.HasValue)
|
||||||
return Forbid();
|
return Forbid();
|
||||||
var result = await plannedTrajectoryService.AddRangeAsync(idWell, idUser.Value, rows, token)
|
foreach (var item in rows)
|
||||||
|
{
|
||||||
|
item.IdUser = idUser.Value;
|
||||||
|
item.IdWell = idWell;
|
||||||
|
}
|
||||||
|
var result = await plannedTrajectoryService.AddRangeAsync(rows, token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
@ -189,7 +186,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <param name="idRow"></param>
|
/// <param name="idRow"></param>
|
||||||
/// <param name="row"></param>
|
/// <param name="row"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns>количество успешно обновленных строк в БД</returns>
|
||||||
[HttpPut("{idRow}")]
|
[HttpPut("{idRow}")]
|
||||||
[Permission]
|
[Permission]
|
||||||
[ProducesResponseType(typeof(PlannedTrajectoryDto), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(PlannedTrajectoryDto), (int)System.Net.HttpStatusCode.OK)]
|
||||||
@ -201,7 +198,9 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
int? idUser = User.GetUserId();
|
int? idUser = User.GetUserId();
|
||||||
if (!idUser.HasValue)
|
if (!idUser.HasValue)
|
||||||
return Forbid();
|
return Forbid();
|
||||||
var result = await plannedTrajectoryService.UpdateAsync(idWell, idUser.Value, idRow, row, token)
|
row.IdUser = idUser.Value;
|
||||||
|
row.IdWell = idWell;
|
||||||
|
var result = await plannedTrajectoryService.UpdateAsync(idRow, row, token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
@ -212,8 +211,8 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// <param name="idWell"></param>
|
/// <param name="idWell"></param>
|
||||||
/// <param name="idRow"></param>
|
/// <param name="idRow"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns>количество успешно удаленных строк из БД</returns>
|
||||||
[HttpDelete("{idOperation}")]
|
[HttpDelete("{idRow}")]
|
||||||
[Permission]
|
[Permission]
|
||||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> DeleteRowAsync(int idWell, int idRow, CancellationToken token = default)
|
public async Task<IActionResult> DeleteRowAsync(int idWell, int idRow, CancellationToken token = default)
|
||||||
@ -234,6 +233,6 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||||||
idWell, token).ConfigureAwait(false);
|
idWell, token).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#nullable disable
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user