forked from ddrilling/AsbCloudServer
1. Сохранение суточного рапорта по частям.
2. Обновление типа данных поля "Дата отчета" в таблице "Суточный рапорт" (timestamp with time zone изменен на date)
This commit is contained in:
parent
24764f2fd4
commit
b6181ab82f
@ -1,10 +1,17 @@
|
||||
namespace AsbCloudApp.Data.DailyReport
|
||||
using System;
|
||||
|
||||
namespace AsbCloudApp.Data.DailyReport
|
||||
{
|
||||
/// <summary>
|
||||
/// Блоки для формирования суточного рапорта
|
||||
/// </summary>
|
||||
public class DailyReportDto
|
||||
{
|
||||
/// <summary>
|
||||
/// дата отчёта
|
||||
/// </summary>
|
||||
public DateOnly StartDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// блок заголовка
|
||||
/// </summary>
|
||||
|
@ -35,10 +35,10 @@ namespace AsbCloudApp.Services
|
||||
/// Добавить новый рапорт
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="dto"></param>
|
||||
/// <param name="startDate"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> AddAsync(int idWell, DailyReportDto dto, CancellationToken token = default);
|
||||
Task<int> AddAsync(int idWell, DateTime startDate, CancellationToken token = default);
|
||||
|
||||
/// <summary>
|
||||
/// изменить данные для суточного рапорта
|
||||
@ -58,5 +58,16 @@ namespace AsbCloudApp.Services
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<Stream?> MakeReportAsync(int idWell, DateTime date, CancellationToken token = default);
|
||||
|
||||
/// <summary>
|
||||
/// изменить блок данных для суточного рапорта
|
||||
/// </summary>
|
||||
/// <typeparam name="Tdto"></typeparam>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="date"></param>
|
||||
/// <param name="dto"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> UpdateBlockAsync<Tdto>(int idWell, DateTime date, Tdto dto, CancellationToken token);
|
||||
}
|
||||
}
|
||||
|
7028
AsbCloudDb/Migrations/20230306085943_UpdateTable_t_daily_report_UpdateType_startDate_toDateOnly.Designer.cs
generated
Normal file
7028
AsbCloudDb/Migrations/20230306085943_UpdateTable_t_daily_report_UpdateType_startDate_toDateOnly.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace AsbCloudDb.Migrations
|
||||
{
|
||||
public partial class UpdateTable_t_daily_report_UpdateType_startDate_toDateOnly : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<DateOnly>(
|
||||
name: "start_date",
|
||||
table: "t_daily_report",
|
||||
type: "date",
|
||||
nullable: false,
|
||||
comment: "Дата отчёта",
|
||||
oldClrType: typeof(DateTimeOffset),
|
||||
oldType: "timestamp with time zone",
|
||||
oldComment: "Дата отчёта");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterColumn<DateTimeOffset>(
|
||||
name: "start_date",
|
||||
table: "t_daily_report",
|
||||
type: "timestamp with time zone",
|
||||
nullable: false,
|
||||
comment: "Дата отчёта",
|
||||
oldClrType: typeof(DateOnly),
|
||||
oldType: "date",
|
||||
oldComment: "Дата отчёта");
|
||||
}
|
||||
}
|
||||
}
|
@ -148,8 +148,8 @@ namespace AsbCloudDb.Migrations
|
||||
.HasColumnName("id_well")
|
||||
.HasComment("ID скважины");
|
||||
|
||||
b.Property<DateTimeOffset>("StartDate")
|
||||
.HasColumnType("timestamp with time zone")
|
||||
b.Property<DateOnly>("StartDate")
|
||||
.HasColumnType("date")
|
||||
.HasColumnName("start_date")
|
||||
.HasComment("Дата отчёта");
|
||||
|
||||
|
@ -10,8 +10,8 @@ namespace AsbCloudDb.Model.DailyReport
|
||||
[Column("id_well"), Comment("ID скважины")]
|
||||
public int IdWell { get; set; }
|
||||
|
||||
[Column("start_date", TypeName = "timestamp with time zone"), Comment("Дата отчёта")]
|
||||
public DateTimeOffset StartDate { get; set; }
|
||||
[Column("start_date", TypeName = "date"), Comment("Дата отчёта")]
|
||||
public DateOnly StartDate { get; set; }
|
||||
|
||||
[Column("info", TypeName = "jsonb"), Comment("Список параметров для отчёта")]
|
||||
public DailyReportInfo Info { get; set; } = null!;
|
||||
|
@ -10,6 +10,7 @@ using AsbCloudDb.Model;
|
||||
using System.Collections.Generic;
|
||||
using AsbCloudApp.Data.DailyReport;
|
||||
using AsbCloudApp.Exceptions;
|
||||
using AsbCloudDb.Model.DailyReport;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.DailyReport
|
||||
{
|
||||
@ -44,17 +45,19 @@ namespace AsbCloudInfrastructure.Services.DailyReport
|
||||
if (begin is not null)
|
||||
{
|
||||
var beginUTC = ExtractDate(begin.Value);
|
||||
query = query.Where(d => d.StartDate >= beginUTC);
|
||||
var beginDateOnly = new DateOnly(beginUTC.Date.Year, beginUTC.Date.Month, beginUTC.Date.Day);
|
||||
query = query.Where(d => d.StartDate >= beginDateOnly);
|
||||
}
|
||||
|
||||
if (end is not null)
|
||||
{
|
||||
var endUTC = ExtractDate(end.Value);
|
||||
query = query.Where(d => d.StartDate <= endUTC);
|
||||
var endDateOnly = new DateOnly(endUTC.Date.Year, endUTC.Date.Month, endUTC.Date.Day);
|
||||
query = query.Where(d => d.StartDate <= endDateOnly);
|
||||
}
|
||||
|
||||
var entities = await query
|
||||
.OrderBy(e => e.StartDate)
|
||||
.OrderByDescending(e => e.StartDate)
|
||||
.ToListAsync(token);
|
||||
return entities.Select(r => Convert(r));
|
||||
}
|
||||
@ -67,14 +70,29 @@ namespace AsbCloudInfrastructure.Services.DailyReport
|
||||
return dailyReportDto;
|
||||
}
|
||||
|
||||
public async Task<int> AddAsync(int idWell, DailyReportDto dto, CancellationToken token = default)
|
||||
public async Task<int> AddAsync(int idWell, System.DateTime startDate, CancellationToken token = default)
|
||||
{
|
||||
var info = Convert(dto);
|
||||
var well = wellService.GetOrDefault(idWell);
|
||||
if (well is null || well.Timezone is null)
|
||||
throw new ArgumentInvalidException("idWell doesn`t exist", nameof(idWell));
|
||||
|
||||
var customer = well.Companies.FirstOrDefault(company => company.IdCompanyType == 1);
|
||||
var contractor = well.Companies.FirstOrDefault(company => company.IdCompanyType == 2);
|
||||
|
||||
var entity = new AsbCloudDb.Model.DailyReport.DailyReport
|
||||
{
|
||||
IdWell = idWell,
|
||||
StartDate = info.Head.ReportDate,
|
||||
Info = info
|
||||
StartDate = new DateOnly(startDate.Date.Year, startDate.Date.Month, startDate.Date.Day),
|
||||
Info = new DailyReportInfo() {
|
||||
Head = new Head()
|
||||
{
|
||||
ReportDate = startDate.Date,
|
||||
WellName = well.Caption,
|
||||
ClusterName = well.Cluster,
|
||||
Customer = customer?.Caption ?? String.Empty,
|
||||
Contractor = contractor?.Caption ?? String.Empty,
|
||||
}
|
||||
}
|
||||
};
|
||||
db.DailyReports.Add(entity);
|
||||
var result = await db.SaveChangesAsync(token);
|
||||
@ -99,6 +117,36 @@ namespace AsbCloudInfrastructure.Services.DailyReport
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<int> UpdateBlockAsync<Tdto>(int idWell, DateTime date, Tdto dto, CancellationToken token)
|
||||
{
|
||||
var dateOffset = date.Date;
|
||||
var entity = await db.DailyReports
|
||||
.FirstOrDefaultAsync(r => r.IdWell == idWell &&
|
||||
r.StartDate.Year == dateOffset.Year &&
|
||||
r.StartDate.DayOfYear == dateOffset.DayOfYear
|
||||
, token);
|
||||
|
||||
if (entity is null)
|
||||
return 0;
|
||||
|
||||
if (dto is HeadDto headDto)
|
||||
entity.Info.Head = headDto.Adapt<Head>();
|
||||
if (dto is BhaDto bhaDto)
|
||||
entity.Info.Bha = bhaDto.Adapt<Bha>();
|
||||
if (dto is NoDrillingDto noDrillingDto)
|
||||
entity.Info.NoDrilling = noDrillingDto.Adapt<NoDrilling>();
|
||||
if (dto is TimeBalanceDto timeBalanceDto)
|
||||
entity.Info.TimeBalance = timeBalanceDto.Adapt<TimeBalance>();
|
||||
if (dto is SaubDto saubDto)
|
||||
entity.Info.Saub = saubDto.Adapt<Saub>();
|
||||
if (dto is SignDto signDto)
|
||||
entity.Info.Sign = signDto.Adapt<Sign>();
|
||||
|
||||
db.DailyReports.Update(entity);
|
||||
var result = await db.SaveChangesAsync(token);
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<Stream?> MakeReportAsync(int idWell, DateTime date, CancellationToken token = default)
|
||||
{
|
||||
var dailyReportDto = await GetOrDefaultAsync(idWell, date, token);
|
||||
@ -160,7 +208,7 @@ namespace AsbCloudInfrastructure.Services.DailyReport
|
||||
private static DailyReportDto Convert(AsbCloudDb.Model.DailyReport.DailyReport entity)
|
||||
{
|
||||
var dto = entity.Info.Adapt<DailyReportDto>();
|
||||
dto.Head.ReportDate = entity.StartDate.Date;
|
||||
dto.StartDate = entity.StartDate;
|
||||
return dto;
|
||||
}
|
||||
|
||||
@ -169,7 +217,7 @@ namespace AsbCloudInfrastructure.Services.DailyReport
|
||||
var entity = dto.Adapt<DailyReportInfo>();
|
||||
entity.Head.ReportDate = dto.Head.ReportDate.Date.Date;
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
}
|
||||
#nullable disable
|
||||
}
|
||||
|
@ -61,35 +61,116 @@ namespace AsbCloudWebApi.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сохранение нового набора данных для формирования рапорта
|
||||
/// Создание суточного рапорта
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="dto"></param>
|
||||
/// <param name="startDate"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
//[Permission]
|
||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> AddAsync(int idWell, [Required][FromBody] DailyReportDto dto, CancellationToken token = default)
|
||||
public async Task<IActionResult> AddAsync(int idWell, [Required] DateTime startDate, CancellationToken token = default)
|
||||
{
|
||||
var result = await dailyReportService.AddAsync(idWell, dto, token);
|
||||
var result = await dailyReportService.AddAsync(idWell, startDate, token);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Сохранение изменений набора данных для формирования рапорта
|
||||
/// Сохранение изменений набора данных для формирования рапорта (заголовок)
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="date"></param>
|
||||
/// <param name="dto"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("{date}")]
|
||||
//[Permission]
|
||||
[HttpPut("{date}/head")]
|
||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> UpdateAsync(int idWell, [Required] DateTime date, [Required] DailyReportDto dto, CancellationToken token = default)
|
||||
public async Task<IActionResult> UpdateHeadAsync(int idWell, [Required] DateTime date, [Required] HeadDto dto, CancellationToken token = default)
|
||||
{
|
||||
var result = await dailyReportService.UpdateAsync(idWell, date, dto, token);
|
||||
var result = await dailyReportService.UpdateBlockAsync(idWell, date, dto, token);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сохранение изменений набора данных для формирования рапорта (блок КНБК)
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="date"></param>
|
||||
/// <param name="dto"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("{date}/bha")]
|
||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> UpdateBhaAsync(int idWell, [Required] DateTime date, [Required] BhaDto dto, CancellationToken token = default)
|
||||
{
|
||||
var result = await dailyReportService.UpdateBlockAsync(idWell, date, dto, token);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сохранение изменений набора данных для формирования рапорта (безметражные работы)
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="date"></param>
|
||||
/// <param name="dto"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("{date}/noDrilling")]
|
||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> UpdateNoDrillingAsync(int idWell, [Required] DateTime date, [Required] NoDrillingDto dto, CancellationToken token = default)
|
||||
{
|
||||
var result = await dailyReportService.UpdateBlockAsync(idWell, date, dto, token);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сохранение изменений набора данных для формирования рапорта (баланс времени)
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="date"></param>
|
||||
/// <param name="dto"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("{date}/timeBalance")]
|
||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> UpdateTimeBalanceAsync(int idWell, [Required] DateTime date, [Required] TimeBalanceDto dto, CancellationToken token = default)
|
||||
{
|
||||
var result = await dailyReportService.UpdateBlockAsync(idWell, date, dto, token);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сохранение изменений набора данных для формирования рапорта (САУБ)
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="date"></param>
|
||||
/// <param name="dto"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("{date}/saub")]
|
||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> UpdateSaubAsync(int idWell, [Required] DateTime date, [Required] SaubDto dto, CancellationToken token = default)
|
||||
{
|
||||
var result = await dailyReportService.UpdateBlockAsync(idWell, date, dto, token);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сохранение изменений набора данных для формирования рапорта (подпись)
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="date"></param>
|
||||
/// <param name="dto"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut("{date}/sign")]
|
||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> UpdateSignAsync(int idWell, [Required] DateTime date, [Required] SignDto dto, CancellationToken token = default)
|
||||
{
|
||||
var result = await dailyReportService.UpdateBlockAsync(idWell, date, dto, token);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
@ -109,7 +190,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
var stream = await dailyReportService.MakeReportAsync(idWell, date, token);
|
||||
if (stream != null)
|
||||
{
|
||||
var fileName = $"Суточный рапорт по скважине {well.Caption} куст {well.Cluster}.xlsx";
|
||||
var fileName = $"Суточный рапорт по скважине {well.Caption} куст {well.Cluster}.xlsx";
|
||||
return File(stream, "application/octet-stream", fileName);
|
||||
}
|
||||
else
|
||||
|
22
AsbCloudWebApi/Converters/DateOnlyJsonConverter.cs
Normal file
22
AsbCloudWebApi/Converters/DateOnlyJsonConverter.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace AsbCloudWebApi.Converters
|
||||
{
|
||||
#nullable enable
|
||||
public class DateOnlyJsonConverter : JsonConverter<DateOnly>
|
||||
{
|
||||
public override DateOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
return DateOnly.FromDateTime(reader.GetDateTime());
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, DateOnly value, JsonSerializerOptions options)
|
||||
{
|
||||
var isoDate = value.ToString("O");
|
||||
writer.WriteStringValue(isoDate);
|
||||
}
|
||||
}
|
||||
#nullable disable
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using AsbCloudInfrastructure;
|
||||
using AsbCloudWebApi.Converters;
|
||||
using AsbCloudWebApi.Middlewares;
|
||||
using AsbCloudWebApi.SignalR;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
@ -25,6 +26,8 @@ namespace AsbCloudWebApi
|
||||
options.JsonSerializerOptions.NumberHandling =
|
||||
System.Text.Json.Serialization.JsonNumberHandling.AllowNamedFloatingPointLiterals |
|
||||
System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString;
|
||||
|
||||
options.JsonSerializerOptions.Converters.Add(new DateOnlyJsonConverter());
|
||||
}))
|
||||
.AddProtoBufNet();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user