Merge pull request 'Запись пользователя, изменившего / создавшего опреацию в БД + запись даты изменения / создания' (#42) from feature/set-user-editor-to-operation into dev

Reviewed-on: http://test.digitaldrilling.ru:8080/DDrilling/AsbCloudServer/pulls/42
This commit is contained in:
Никита Фролов 2023-04-05 10:32:03 +05:00
commit ab30bc9158
11 changed files with 7894 additions and 11 deletions

View File

@ -1,6 +1,6 @@
using System;
namespace AsbCloudApp.Data.DailyReport
namespace AsbCloudApp.Data
{
/// <summary>
/// хранение дополнительной информации о записи

View File

@ -6,7 +6,7 @@ namespace AsbCloudApp.Data
/// <summary>
/// Операции на скважине (заведенные пользователем)
/// </summary>
public class WellOperationDto : IId, IWellRelated
public class WellOperationDto : ItemInfoDto, IId, IWellRelated
{

View File

@ -1,4 +1,5 @@
using AsbCloudApp.Data.DailyReport;
using AsbCloudApp.Data;
using AsbCloudApp.Data.DailyReport;
using System;
using System.Collections.Generic;
using System.IO;
@ -31,7 +32,7 @@ namespace AsbCloudApp.Services
/// <param name="token"></param>
/// <returns></returns>
Task<int> AddAsync(int idWell, DateOnly startDate, int idUser, CancellationToken token);
/// <summary>
/// Сформировать файл рапорта
/// </summary>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,37 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace AsbCloudDb.Migrations
{
public partial class Add_UserEditor_To_WellOperation_Table : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "IdUser",
table: "t_well_operation",
type: "integer",
nullable: true);
migrationBuilder.AddColumn<DateTimeOffset>(
name: "LastUpdateDate",
table: "t_well_operation",
type: "timestamp with time zone",
nullable: false,
defaultValue: new DateTimeOffset(new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), new TimeSpan(0, 0, 0, 0, 0)));
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "IdUser",
table: "t_well_operation");
migrationBuilder.DropColumn(
name: "LastUpdateDate",
table: "t_well_operation");
}
}
}

View File

@ -5047,6 +5047,9 @@ namespace AsbCloudDb.Migrations
.HasColumnName("id_type")
.HasComment("0 = План или 1 = Факт");
b.Property<int?>("IdUser")
.HasColumnType("integer");
b.Property<int>("IdWell")
.HasColumnType("integer")
.HasColumnName("id_well")
@ -5057,6 +5060,9 @@ namespace AsbCloudDb.Migrations
.HasColumnName("id_well_section_type")
.HasComment("Id тип секции скважины");
b.Property<DateTimeOffset>("LastUpdateDate")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.HasIndex("DateStart");

View File

@ -7,7 +7,7 @@ using System.Text.Json.Serialization;
namespace AsbCloudDb.Model
{
[Table("t_well_operation"), Comment("Данные по операциям на скважине")]
public class WellOperation : IId
public class WellOperation : ItemInfo, IId
{
public const int IdOperationTypePlan = 0;
public const int IdOperationTypeFact = 1;

View File

@ -373,7 +373,9 @@ namespace AsbCloudInfrastructure.Repository
.Where(subOp => subOp.IdType == o.IdType)
.Where(subOp => subOp.DateStart <= o.DateStart)
.Min(subOp => subOp.DateStart))
.TotalDays
.TotalDays,
IdUser = o.IdUser,
LastUpdateDate = o.LastUpdateDate.ToOffset(TimeSpan.FromHours(timezone.Hours))
});
if (request.SortFields?.Any() == true)

View File

@ -186,18 +186,24 @@ namespace AsbCloudInfrastructure.Services.DailyReport
var dto = entity.Info.Adapt<DailyReportDto>();
dto.StartDate = entity.StartDate;
var dailyFactOperation = factOperationsForDtos
var dailyFactOperations = factOperationsForDtos
.Where(o => DateOnly.FromDateTime(o.DateStart) == dto.StartDate)
.Where(o => o.IdParentCategory is not null)
.Where(o => o.IdParentCategory is not null);
var lastDailyFactOperation = dailyFactOperations
.OrderByDescending(o => o.LastUpdateDate)
.FirstOrDefault();
dto.TimeBalance.IdUser = lastDailyFactOperation?.IdUser;
dto.TimeBalance.LastUpdateDate = lastDailyFactOperation?.LastUpdateDate;
dto.TimeBalance.OperationsStat = dailyFactOperations
.GroupBy(o => o.IdParentCategory!.Value)
.ToDictionary(g => g.Key, g => g.Sum(o => o.DurationHours));
dto.TimeBalance.OperationsStat = dailyFactOperation;
var blocks = new ItemInfoDto[] {
dto.Head,
dto.Bha,
dto.NoDrilling,
dto.TimeBalance,
dto.Saub,
dto.Sign
};

View File

@ -1,4 +1,5 @@
using AsbCloudApp.Data.DailyReport;
using AsbCloudApp.Data;
using AsbCloudApp.Data.DailyReport;
using AsbCloudApp.Exceptions;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services;

View File

@ -209,7 +209,11 @@ namespace AsbCloudWebApi.Controllers
return Forbid();
foreach (var value in values)
{
value.IdWell = idWell;
value.LastUpdateDate = DateTimeOffset.UtcNow;
value.IdUser = User.GetUserId();
}
var result = await operationRepository.InsertRangeAsync(values, token)
.ConfigureAwait(false);
@ -236,6 +240,8 @@ namespace AsbCloudWebApi.Controllers
value.IdWell = idWell;
value.Id = idOperation;
value.LastUpdateDate = DateTimeOffset.UtcNow;
value.IdUser = User.GetUserId();
var result = await operationRepository.UpdateAsync(value, token)
.ConfigureAwait(false);