diff --git a/AsbCloudDb/EFExtensionsInitialization.cs b/AsbCloudDb/EFExtensionsInitialization.cs
index 7f9ba0ea..b2f41aff 100644
--- a/AsbCloudDb/EFExtensionsInitialization.cs
+++ b/AsbCloudDb/EFExtensionsInitialization.cs
@@ -10,6 +10,8 @@ namespace AsbCloudDb
{
public static void EnsureCreatedAndMigrated(this DatabaseFacade db)
{
+ var connectionString = db.GetConnectionString();
+ Trace.TraceInformation($"connectionString: {connectionString}");
db.SetCommandTimeout(TimeSpan.FromMinutes(5));
if (db.EnsureCreated())
{
diff --git a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs
index ea9a6975..c9d3c7fc 100644
--- a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs
+++ b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs
@@ -223,8 +223,10 @@ public class WellOperationRepository : IWellOperationRepository
{
var query = BuildQuery(request)
.AsNoTracking();
- var result = await query.ToArrayAsync(token);
- return result;
+
+ var dtos = await query.ToArrayAsync(token);
+
+ return dtos;
}
///
@@ -383,13 +385,6 @@ public class WellOperationRepository : IWellOperationRepository
new[] { nameof(wellOperationDtos) });
}
- //if (previousDateEnd > currentDateStart)
- //{
- // yield return new ValidationResult(
- // "Предыдущая операция не завершена",
- // new[] { nameof(wellOperationDtos) });
- //}
-
previous = current;
}
}
@@ -411,8 +406,9 @@ public class WellOperationRepository : IWellOperationRepository
{
var entity = dto.Adapt();
entity.Id = default;
- entity.DateStart = dto.DateStart.ToUniversalTime();
+ entity.DateStart = dto.DateStart.DateTime.ToUtcDateTimeOffset(timezone.Hours);
entity.IdWell = idWell;
+ entity.LastUpdateDate = DateTimeOffset.UtcNow;
db.WellOperations.Add(entity);
}
@@ -429,7 +425,8 @@ public class WellOperationRepository : IWellOperationRepository
{
var timezone = wellService.GetTimezone(dto.IdWell);
var entity = dto.Adapt();
- entity.DateStart = dto.DateStart.ToUniversalTime();
+ entity.DateStart = dto.DateStart.DateTime.ToUtcDateTimeOffset(timezone.Hours);
+ entity.LastUpdateDate = DateTimeOffset.UtcNow;
db.WellOperations.Update(entity);
var result = await db.SaveChangesAsync(token);
@@ -501,7 +498,7 @@ public class WellOperationRepository : IWellOperationRepository
.Where(subOp => subOp.IdType == 1)
.Where(subOp => WellOperationCategory.NonProductiveTimeSubIds.Contains(subOp.IdCategory));
- var result = query.Select(o => new WellOperationDto
+ var dtos = query.Select(o => new WellOperationDto
{
Id = o.Id,
IdPlan = o.IdPlan,
@@ -531,21 +528,21 @@ public class WellOperationRepository : IWellOperationRepository
.Min(subOp => subOp.DateStart))
.TotalDays,
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)
{
- result = result.SortBy(request.SortFields);
+ dtos = dtos.SortBy(request.SortFields);
}
else
{
- result = result
+ dtos = dtos
.OrderBy(e => e.DateStart)
.ThenBy(e => e.DepthEnd)
.ThenBy(e => e.Id);
- };
-
- return result;
+ }
+
+ return dtos;
}
}
diff --git a/AsbCloudWebApi.IntegrationTests/Clients/IWellOperationClient.cs b/AsbCloudWebApi.IntegrationTests/Clients/IWellOperationClient.cs
index 2db55d36..07754ed1 100644
--- a/AsbCloudWebApi.IntegrationTests/Clients/IWellOperationClient.cs
+++ b/AsbCloudWebApi.IntegrationTests/Clients/IWellOperationClient.cs
@@ -1,5 +1,5 @@
using AsbCloudApp.Data;
-using Microsoft.AspNetCore.Mvc;
+using AsbCloudApp.Requests;
using Refit;
namespace AsbCloudWebApi.IntegrationTests.Clients;
@@ -12,6 +12,10 @@ public interface IWellOperationClient
Task> InsertRangeAsync(int idWell, int idType, bool deleteBeforeInsert, [Body] IEnumerable dtos);
[Put(BaseRoute + "/{idOperation}")]
- Task> UpdateAsync(int idWell, int idOperation, [FromBody] WellOperationDto value, CancellationToken token);
+ Task> UpdateAsync(int idWell, int idOperation, [Body] WellOperationDto value, CancellationToken token);
+ [Get(BaseRoute + "/plan")]
+ Task>> GetPageOperationsPlanAsync(int idWell,
+ [Query] WellOperationRequestBase request,
+ CancellationToken token);
}
\ No newline at end of file
diff --git a/AsbCloudWebApi.IntegrationTests/Controllers/WellOperationControllerTest.cs b/AsbCloudWebApi.IntegrationTests/Controllers/WellOperationControllerTest.cs
index 3ac32e40..a5e0064a 100644
--- a/AsbCloudWebApi.IntegrationTests/Controllers/WellOperationControllerTest.cs
+++ b/AsbCloudWebApi.IntegrationTests/Controllers/WellOperationControllerTest.cs
@@ -2,45 +2,43 @@ using AsbCloudApp.Data;
using AsbCloudDb.Model;
using AsbCloudWebApi.IntegrationTests.Clients;
using System.Net;
+using AsbCloudApp.Requests;
using Xunit;
namespace AsbCloudWebApi.IntegrationTests.Controllers;
-
public class WellOperationControllerTest : BaseIntegrationTest
{
private static int idWell = 1;
- private readonly WellOperationDto[] dtos = new WellOperationDto[]
- {
- new WellOperationDto()
- {
- Id = 2,
- IdWell = idWell,
- IdType = 1,
- DateStart = DateTimeOffset.Now,
- CategoryInfo = "1",
- CategoryName = "1",
- Comment = "1",
- Day = 1,
- DepthEnd = 20,
- DepthStart = 10,
- DurationHours = 1,
- IdCategory = 5000,
- IdParentCategory = null,
- IdPlan = null,
- IdUser = 1,
- IdWellSectionType = 1,
- LastUpdateDate = DateTimeOffset.Now,
- NptHours = 1,
- WellSectionTypeName = null,
- UserName = null
- }
- };
+ private readonly WellOperationDto[] dtos = new WellOperationDto[]
+ {
+ new()
+ {
+ IdWell = 1,
+ IdWellSectionType = 1,
+ WellSectionTypeName = "Пилотный ствол",
+ IdCategory = 5000,
+ IdPlan = null,
+ CategoryName = "Разборка КНБК",
+ IdParentCategory = 4000,
+ CategoryInfo = "1",
+ IdType = 0,
+ DepthStart = 10.0,
+ DepthEnd = 20.0,
+ Day = 0.0,
+ NptHours = 0.0,
+ DateStart = new DateTimeOffset(new DateTime(2023, 02, 03, 1, 0, 0, DateTimeKind.Unspecified)),
+ DurationHours = 1.0,
+ Comment = "1",
+ IdUser = 1,
+ UserName = null,
+ }
+ };
private readonly WellOperationDto[] dtosWithError = new WellOperationDto[]
{
- new WellOperationDto()
+ new()
{
Id = 3,
IdWell = idWell,
@@ -63,7 +61,7 @@ public class WellOperationControllerTest : BaseIntegrationTest
WellSectionTypeName = null,
UserName = null
},
- new WellOperationDto()
+ new()
{
Id = 4,
IdWell = idWell,
@@ -88,12 +86,12 @@ public class WellOperationControllerTest : BaseIntegrationTest
}
};
- private IWellOperationClient wellOperationClient;
+ private IWellOperationClient client;
public WellOperationControllerTest(WebAppFactoryFixture factory)
: base(factory)
{
- wellOperationClient = factory.GetAuthorizedHttpClient();
+ client = factory.GetAuthorizedHttpClient();
}
///
@@ -105,7 +103,7 @@ public class WellOperationControllerTest : BaseIntegrationTest
{
dbContext.CleanupDbSet();
//act
- var response = await wellOperationClient.InsertRangeAsync(idWell, 1, false, dtos);
+ var response = await client.InsertRangeAsync(idWell, 1, false, dtos);
//assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
@@ -120,7 +118,7 @@ public class WellOperationControllerTest : BaseIntegrationTest
public async Task InsertRange_returns_error()
{
//act
- var response = await wellOperationClient.InsertRangeAsync(idWell, 1, false, dtosWithError);
+ var response = await client.InsertRangeAsync(idWell, 1, false, dtosWithError);
//assert
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
@@ -134,7 +132,7 @@ public class WellOperationControllerTest : BaseIntegrationTest
public async Task InsertRangeWithDeleteBefore_returns_success()
{
//act
- var response = await wellOperationClient.InsertRangeAsync(idWell, 1, true, dtos);
+ var response = await client.InsertRangeAsync(idWell, 1, true, dtos);
//assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
@@ -148,7 +146,7 @@ public class WellOperationControllerTest : BaseIntegrationTest
public async Task InsertRangeWithDeleteBefore_returns_error()
{
//act
- var response = await wellOperationClient.InsertRangeAsync(idWell, 1, true, dtosWithError);
+ var response = await client.InsertRangeAsync(idWell, 1, true, dtosWithError);
//assert
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
@@ -163,7 +161,7 @@ public class WellOperationControllerTest : BaseIntegrationTest
{
//act
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.Equal(HttpStatusCode.OK, response.StatusCode);
@@ -178,9 +176,39 @@ public class WellOperationControllerTest : BaseIntegrationTest
{
//act
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.Equal(HttpStatusCode.BadRequest, response.StatusCode);
}
+
+ ///
+ /// Получение плановых операций
+ ///
+ ///
+ [Fact]
+ public async Task GetPageOperationsPlanAsync_returns_success()
+ {
+ //arrange
+ dbContext.CleanupDbSet();
+ 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);
+ }
}
\ No newline at end of file
diff --git a/AsbCloudWebApi/Controllers/WellOperationController.cs b/AsbCloudWebApi/Controllers/WellOperationController.cs
index 74d4e16f..27827a62 100644
--- a/AsbCloudWebApi/Controllers/WellOperationController.cs
+++ b/AsbCloudWebApi/Controllers/WellOperationController.cs
@@ -233,7 +233,6 @@ namespace AsbCloudWebApi.Controllers
return Forbid();
wellOperation.IdWell = idWell;
- wellOperation.LastUpdateDate = DateTimeOffset.UtcNow;
wellOperation.IdUser = User.GetUserId();
wellOperation.IdType = idType;