forked from ddrilling/AsbCloudServer
Merge branch 'master' into dev
This commit is contained in:
commit
27e65d1b33
@ -10,6 +10,8 @@ namespace AsbCloudDb
|
|||||||
{
|
{
|
||||||
public static void EnsureCreatedAndMigrated(this DatabaseFacade db)
|
public static void EnsureCreatedAndMigrated(this DatabaseFacade db)
|
||||||
{
|
{
|
||||||
|
var connectionString = db.GetConnectionString();
|
||||||
|
Trace.TraceInformation($"connectionString: {connectionString}");
|
||||||
db.SetCommandTimeout(TimeSpan.FromMinutes(5));
|
db.SetCommandTimeout(TimeSpan.FromMinutes(5));
|
||||||
if (db.EnsureCreated())
|
if (db.EnsureCreated())
|
||||||
{
|
{
|
||||||
|
@ -223,8 +223,10 @@ public class WellOperationRepository : IWellOperationRepository
|
|||||||
{
|
{
|
||||||
var query = BuildQuery(request)
|
var query = BuildQuery(request)
|
||||||
.AsNoTracking();
|
.AsNoTracking();
|
||||||
var result = await query.ToArrayAsync(token);
|
|
||||||
return result;
|
var dtos = await query.ToArrayAsync(token);
|
||||||
|
|
||||||
|
return dtos;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
@ -383,13 +385,6 @@ public class WellOperationRepository : IWellOperationRepository
|
|||||||
new[] { nameof(wellOperationDtos) });
|
new[] { nameof(wellOperationDtos) });
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (previousDateEnd > currentDateStart)
|
|
||||||
//{
|
|
||||||
// yield return new ValidationResult(
|
|
||||||
// "Предыдущая операция не завершена",
|
|
||||||
// new[] { nameof(wellOperationDtos) });
|
|
||||||
//}
|
|
||||||
|
|
||||||
previous = current;
|
previous = current;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -411,8 +406,9 @@ public class WellOperationRepository : IWellOperationRepository
|
|||||||
{
|
{
|
||||||
var entity = dto.Adapt<WellOperation>();
|
var entity = dto.Adapt<WellOperation>();
|
||||||
entity.Id = default;
|
entity.Id = default;
|
||||||
entity.DateStart = dto.DateStart.ToUniversalTime();
|
entity.DateStart = dto.DateStart.DateTime.ToUtcDateTimeOffset(timezone.Hours);
|
||||||
entity.IdWell = idWell;
|
entity.IdWell = idWell;
|
||||||
|
entity.LastUpdateDate = DateTimeOffset.UtcNow;
|
||||||
db.WellOperations.Add(entity);
|
db.WellOperations.Add(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -429,7 +425,8 @@ public class WellOperationRepository : IWellOperationRepository
|
|||||||
{
|
{
|
||||||
var timezone = wellService.GetTimezone(dto.IdWell);
|
var timezone = wellService.GetTimezone(dto.IdWell);
|
||||||
var entity = dto.Adapt<WellOperation>();
|
var entity = dto.Adapt<WellOperation>();
|
||||||
entity.DateStart = dto.DateStart.ToUniversalTime();
|
entity.DateStart = dto.DateStart.DateTime.ToUtcDateTimeOffset(timezone.Hours);
|
||||||
|
entity.LastUpdateDate = DateTimeOffset.UtcNow;
|
||||||
db.WellOperations.Update(entity);
|
db.WellOperations.Update(entity);
|
||||||
|
|
||||||
var result = await db.SaveChangesAsync(token);
|
var result = await db.SaveChangesAsync(token);
|
||||||
@ -501,7 +498,7 @@ public class WellOperationRepository : IWellOperationRepository
|
|||||||
.Where(subOp => subOp.IdType == 1)
|
.Where(subOp => subOp.IdType == 1)
|
||||||
.Where(subOp => WellOperationCategory.NonProductiveTimeSubIds.Contains(subOp.IdCategory));
|
.Where(subOp => WellOperationCategory.NonProductiveTimeSubIds.Contains(subOp.IdCategory));
|
||||||
|
|
||||||
var result = query.Select(o => new WellOperationDto
|
var dtos = query.Select(o => new WellOperationDto
|
||||||
{
|
{
|
||||||
Id = o.Id,
|
Id = o.Id,
|
||||||
IdPlan = o.IdPlan,
|
IdPlan = o.IdPlan,
|
||||||
@ -531,21 +528,21 @@ public class WellOperationRepository : IWellOperationRepository
|
|||||||
.Min(subOp => subOp.DateStart))
|
.Min(subOp => subOp.DateStart))
|
||||||
.TotalDays,
|
.TotalDays,
|
||||||
IdUser = o.IdUser,
|
IdUser = o.IdUser,
|
||||||
LastUpdateDate = o.LastUpdateDate.ToOffset(TimeSpan.FromHours(timezone.Hours))
|
LastUpdateDate = DateTime.SpecifyKind(o.LastUpdateDate.UtcDateTime + timeZoneOffset, DateTimeKind.Unspecified)
|
||||||
});
|
});
|
||||||
|
|
||||||
if (request.SortFields?.Any() == true)
|
if (request.SortFields?.Any() == true)
|
||||||
{
|
{
|
||||||
result = result.SortBy(request.SortFields);
|
dtos = dtos.SortBy(request.SortFields);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result = result
|
dtos = dtos
|
||||||
.OrderBy(e => e.DateStart)
|
.OrderBy(e => e.DateStart)
|
||||||
.ThenBy(e => e.DepthEnd)
|
.ThenBy(e => e.DepthEnd)
|
||||||
.ThenBy(e => e.Id);
|
.ThenBy(e => e.Id);
|
||||||
};
|
}
|
||||||
|
|
||||||
return result;
|
return dtos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using AsbCloudApp.Requests;
|
||||||
using Refit;
|
using Refit;
|
||||||
|
|
||||||
namespace AsbCloudWebApi.IntegrationTests.Clients;
|
namespace AsbCloudWebApi.IntegrationTests.Clients;
|
||||||
@ -12,6 +12,10 @@ public interface IWellOperationClient
|
|||||||
Task<IApiResponse<int>> InsertRangeAsync(int idWell, int idType, bool deleteBeforeInsert, [Body] IEnumerable<WellOperationDto> dtos);
|
Task<IApiResponse<int>> InsertRangeAsync(int idWell, int idType, bool deleteBeforeInsert, [Body] IEnumerable<WellOperationDto> dtos);
|
||||||
|
|
||||||
[Put(BaseRoute + "/{idOperation}")]
|
[Put(BaseRoute + "/{idOperation}")]
|
||||||
Task<IApiResponse<int>> UpdateAsync(int idWell, int idOperation, [FromBody] WellOperationDto value, CancellationToken token);
|
Task<IApiResponse<int>> UpdateAsync(int idWell, int idOperation, [Body] WellOperationDto value, CancellationToken token);
|
||||||
|
|
||||||
|
[Get(BaseRoute + "/plan")]
|
||||||
|
Task<IApiResponse<PaginationContainer<WellOperationDto>>> GetPageOperationsPlanAsync(int idWell,
|
||||||
|
[Query] WellOperationRequestBase request,
|
||||||
|
CancellationToken token);
|
||||||
}
|
}
|
@ -2,45 +2,43 @@ using AsbCloudApp.Data;
|
|||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
using AsbCloudWebApi.IntegrationTests.Clients;
|
using AsbCloudWebApi.IntegrationTests.Clients;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace AsbCloudWebApi.IntegrationTests.Controllers;
|
namespace AsbCloudWebApi.IntegrationTests.Controllers;
|
||||||
|
|
||||||
|
|
||||||
public class WellOperationControllerTest : BaseIntegrationTest
|
public class WellOperationControllerTest : BaseIntegrationTest
|
||||||
{
|
{
|
||||||
private static int idWell = 1;
|
private static int idWell = 1;
|
||||||
|
|
||||||
private readonly WellOperationDto[] dtos = new WellOperationDto[]
|
private readonly WellOperationDto[] dtos = new WellOperationDto[]
|
||||||
{
|
{
|
||||||
new WellOperationDto()
|
new()
|
||||||
{
|
{
|
||||||
Id = 2,
|
IdWell = 1,
|
||||||
IdWell = idWell,
|
IdWellSectionType = 1,
|
||||||
IdType = 1,
|
WellSectionTypeName = "Пилотный ствол",
|
||||||
DateStart = DateTimeOffset.Now,
|
IdCategory = 5000,
|
||||||
CategoryInfo = "1",
|
IdPlan = null,
|
||||||
CategoryName = "1",
|
CategoryName = "Разборка КНБК",
|
||||||
Comment = "1",
|
IdParentCategory = 4000,
|
||||||
Day = 1,
|
CategoryInfo = "1",
|
||||||
DepthEnd = 20,
|
IdType = 0,
|
||||||
DepthStart = 10,
|
DepthStart = 10.0,
|
||||||
DurationHours = 1,
|
DepthEnd = 20.0,
|
||||||
IdCategory = 5000,
|
Day = 0.0,
|
||||||
IdParentCategory = null,
|
NptHours = 0.0,
|
||||||
IdPlan = null,
|
DateStart = new DateTimeOffset(new DateTime(2023, 02, 03, 1, 0, 0, DateTimeKind.Unspecified)),
|
||||||
IdUser = 1,
|
DurationHours = 1.0,
|
||||||
IdWellSectionType = 1,
|
Comment = "1",
|
||||||
LastUpdateDate = DateTimeOffset.Now,
|
IdUser = 1,
|
||||||
NptHours = 1,
|
UserName = null,
|
||||||
WellSectionTypeName = null,
|
}
|
||||||
UserName = null
|
};
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private readonly WellOperationDto[] dtosWithError = new WellOperationDto[]
|
private readonly WellOperationDto[] dtosWithError = new WellOperationDto[]
|
||||||
{
|
{
|
||||||
new WellOperationDto()
|
new()
|
||||||
{
|
{
|
||||||
Id = 3,
|
Id = 3,
|
||||||
IdWell = idWell,
|
IdWell = idWell,
|
||||||
@ -63,7 +61,7 @@ public class WellOperationControllerTest : BaseIntegrationTest
|
|||||||
WellSectionTypeName = null,
|
WellSectionTypeName = null,
|
||||||
UserName = null
|
UserName = null
|
||||||
},
|
},
|
||||||
new WellOperationDto()
|
new()
|
||||||
{
|
{
|
||||||
Id = 4,
|
Id = 4,
|
||||||
IdWell = idWell,
|
IdWell = idWell,
|
||||||
@ -88,12 +86,12 @@ public class WellOperationControllerTest : BaseIntegrationTest
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private IWellOperationClient wellOperationClient;
|
private IWellOperationClient client;
|
||||||
|
|
||||||
public WellOperationControllerTest(WebAppFactoryFixture factory)
|
public WellOperationControllerTest(WebAppFactoryFixture factory)
|
||||||
: base(factory)
|
: base(factory)
|
||||||
{
|
{
|
||||||
wellOperationClient = factory.GetAuthorizedHttpClient<IWellOperationClient>();
|
client = factory.GetAuthorizedHttpClient<IWellOperationClient>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -105,7 +103,7 @@ public class WellOperationControllerTest : BaseIntegrationTest
|
|||||||
{
|
{
|
||||||
dbContext.CleanupDbSet<WellOperation>();
|
dbContext.CleanupDbSet<WellOperation>();
|
||||||
//act
|
//act
|
||||||
var response = await wellOperationClient.InsertRangeAsync(idWell, 1, false, dtos);
|
var response = await client.InsertRangeAsync(idWell, 1, false, dtos);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
@ -120,7 +118,7 @@ public class WellOperationControllerTest : BaseIntegrationTest
|
|||||||
public async Task InsertRange_returns_error()
|
public async Task InsertRange_returns_error()
|
||||||
{
|
{
|
||||||
//act
|
//act
|
||||||
var response = await wellOperationClient.InsertRangeAsync(idWell, 1, false, dtosWithError);
|
var response = await client.InsertRangeAsync(idWell, 1, false, dtosWithError);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
||||||
@ -134,7 +132,7 @@ public class WellOperationControllerTest : BaseIntegrationTest
|
|||||||
public async Task InsertRangeWithDeleteBefore_returns_success()
|
public async Task InsertRangeWithDeleteBefore_returns_success()
|
||||||
{
|
{
|
||||||
//act
|
//act
|
||||||
var response = await wellOperationClient.InsertRangeAsync(idWell, 1, true, dtos);
|
var response = await client.InsertRangeAsync(idWell, 1, true, dtos);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
@ -148,7 +146,7 @@ public class WellOperationControllerTest : BaseIntegrationTest
|
|||||||
public async Task InsertRangeWithDeleteBefore_returns_error()
|
public async Task InsertRangeWithDeleteBefore_returns_error()
|
||||||
{
|
{
|
||||||
//act
|
//act
|
||||||
var response = await wellOperationClient.InsertRangeAsync(idWell, 1, true, dtosWithError);
|
var response = await client.InsertRangeAsync(idWell, 1, true, dtosWithError);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
||||||
@ -163,7 +161,7 @@ public class WellOperationControllerTest : BaseIntegrationTest
|
|||||||
{
|
{
|
||||||
//act
|
//act
|
||||||
var dto = dtos.FirstOrDefault()!;
|
var dto = dtos.FirstOrDefault()!;
|
||||||
var response = await wellOperationClient.UpdateAsync(idWell, 1, dto, CancellationToken.None);
|
var response = await client.UpdateAsync(idWell, 1, dto, CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||||
@ -178,9 +176,39 @@ public class WellOperationControllerTest : BaseIntegrationTest
|
|||||||
{
|
{
|
||||||
//act
|
//act
|
||||||
var dto = dtosWithError.LastOrDefault()!;
|
var dto = dtosWithError.LastOrDefault()!;
|
||||||
var response = await wellOperationClient.UpdateAsync(idWell, 1, dto, CancellationToken.None);
|
var response = await client.UpdateAsync(idWell, 1, dto, CancellationToken.None);
|
||||||
|
|
||||||
//assert
|
//assert
|
||||||
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение плановых операций
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[Fact]
|
||||||
|
public async Task GetPageOperationsPlanAsync_returns_success()
|
||||||
|
{
|
||||||
|
//arrange
|
||||||
|
dbContext.CleanupDbSet<WellOperation>();
|
||||||
|
await client.InsertRangeAsync(idWell, WellOperation.IdOperationTypePlan, false, dtos);
|
||||||
|
|
||||||
|
var request = new WellOperationRequestBase
|
||||||
|
{
|
||||||
|
OperationType = WellOperation.IdOperationTypePlan
|
||||||
|
};
|
||||||
|
|
||||||
|
//act
|
||||||
|
var response = await client.GetPageOperationsPlanAsync(idWell, request, CancellationToken.None);
|
||||||
|
|
||||||
|
//assert
|
||||||
|
Assert.NotNull(response.Content);
|
||||||
|
Assert.Single(response.Content.Items);
|
||||||
|
|
||||||
|
var dto = dtos[0];
|
||||||
|
var wellOperation = response.Content.Items.First();
|
||||||
|
|
||||||
|
var excludeProps = new[] { nameof(WellOperationDto.Id) };
|
||||||
|
MatchHelper.Match(dto, wellOperation, excludeProps);
|
||||||
|
}
|
||||||
}
|
}
|
@ -233,7 +233,6 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
wellOperation.IdWell = idWell;
|
wellOperation.IdWell = idWell;
|
||||||
wellOperation.LastUpdateDate = DateTimeOffset.UtcNow;
|
|
||||||
wellOperation.IdUser = User.GetUserId();
|
wellOperation.IdUser = User.GetUserId();
|
||||||
wellOperation.IdType = idType;
|
wellOperation.IdType = idType;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user