Реализовать хранение технологических сообщений
This commit is contained in:
parent
23e2f86957
commit
153f5894ad
44
Persistence.API/Controllers/TechMessagesController.cs
Normal file
44
Persistence.API/Controllers/TechMessagesController.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Persistence.Models;
|
||||
using Persistence.Repositories;
|
||||
|
||||
namespace Persistence.API.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class TechMessagesController : ControllerBase, ITechMessages
|
||||
{
|
||||
private readonly ITechMessagesRepository techMessagesRepository;
|
||||
|
||||
public TechMessagesController(ITechMessagesRepository techMessagesRepository)
|
||||
{
|
||||
this.techMessagesRepository = techMessagesRepository;
|
||||
}
|
||||
|
||||
public Task<ActionResult<PaginationContainer<TechMessageDto>>> GetPage(RequestDto request, CancellationToken token)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<ActionResult<int>> GetStatistics(int importantId, string autoDrillingSystem, CancellationToken token)
|
||||
{
|
||||
var result = await techMessagesRepository.GetStatistics(importantId, autoDrillingSystem, token);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
public async Task<ActionResult<IEnumerable<string>>> GetSystems(CancellationToken token)
|
||||
{
|
||||
var result = await techMessagesRepository.GetSystems(token);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
public async Task<ActionResult<int>> InsertRange(IEnumerable<TechMessageDto> dtos, CancellationToken token)
|
||||
{
|
||||
var result = await techMessagesRepository.InsertRange(dtos, token);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Persistence.Database.Entity;
|
||||
using System.Data.Common;
|
||||
|
||||
namespace Persistence.Database.Model;
|
||||
@ -8,7 +9,9 @@ public partial class PersistenceDbContext : DbContext, IPersistenceDbContext
|
||||
|
||||
public DbSet<Setpoint> Setpoint => Set<Setpoint>();
|
||||
|
||||
public PersistenceDbContext()
|
||||
public DbSet<TechMessage> TechMessage => Set<TechMessage>();
|
||||
|
||||
public PersistenceDbContext()
|
||||
: base()
|
||||
{
|
||||
|
||||
|
30
Persistence.Database/Entity/TechMessage.cs
Normal file
30
Persistence.Database/Entity/TechMessage.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Persistence.Database.Entity
|
||||
{
|
||||
public class TechMessage
|
||||
{
|
||||
[Key, Comment("Id события")]
|
||||
public Guid EventId { get; set; }
|
||||
|
||||
[Comment("Id Категории важности")]
|
||||
public int ImportantId { get; set; }
|
||||
|
||||
[Comment("Дата возникновения")]
|
||||
public DateTimeOffset OccurrenceDate { get; set; }
|
||||
|
||||
[Comment("Глубина забоя")]
|
||||
public double? Depth { get; set; }
|
||||
|
||||
[Column(TypeName = "varchar(512)"), Comment("Текст сообщения")]
|
||||
public string? MessageText { get; set; }
|
||||
|
||||
[Column(TypeName = "varchar(256)"), Comment("Система автобурения, к которой относится сообщение")]
|
||||
public string? AutoDrillingSystem { get; set; }
|
||||
|
||||
[Comment("Id пользователя за пультом бурильщика")]
|
||||
public Guid UserId { get; set; }
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Persistence.Database.Entity;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Metrics;
|
||||
@ -12,6 +13,7 @@ public interface IPersistenceDbContext : IDisposable
|
||||
{
|
||||
DbSet<DataSaub> DataSaub { get; }
|
||||
DbSet<Setpoint> Setpoint { get; }
|
||||
DbSet<TechMessage> TechMessage { get; }
|
||||
DatabaseFacade Database { get; }
|
||||
Task<int> SaveChangesAsync(CancellationToken cancellationToken);
|
||||
}
|
||||
|
@ -0,0 +1,51 @@
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Persistence.Database.Entity;
|
||||
using Persistence.Models;
|
||||
using Persistence.Repositories;
|
||||
|
||||
namespace Persistence.Repository.Repositories
|
||||
{
|
||||
public class TechMessagesRepository : ITechMessagesRepository
|
||||
{
|
||||
private DbContext db;
|
||||
public TechMessagesRepository(DbContext db)
|
||||
{
|
||||
this.db = db;
|
||||
}
|
||||
|
||||
protected virtual IQueryable<TechMessage> GetQueryReadOnly() => db.Set<TechMessage>();
|
||||
|
||||
public async Task<int> GetStatistics(int importantId, string autoDrillingSystem, CancellationToken token)
|
||||
{
|
||||
var query = GetQueryReadOnly();
|
||||
var count = await query
|
||||
.Where(e => e.ImportantId == importantId && e.AutoDrillingSystem == autoDrillingSystem)
|
||||
.CountAsync();
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<string>> GetSystems(CancellationToken token)
|
||||
{
|
||||
var query = GetQueryReadOnly();
|
||||
var entities = await query
|
||||
.Select(e => e.AutoDrillingSystem ?? string.Empty)
|
||||
.Distinct()
|
||||
.ToArrayAsync(token);
|
||||
var dtos = entities.Order();
|
||||
|
||||
return dtos;
|
||||
}
|
||||
|
||||
public async Task<int> InsertRange(IEnumerable<TechMessageDto> dtos, CancellationToken token)
|
||||
{
|
||||
var entities = dtos.Select(d => d.Adapt<TechMessage>());
|
||||
|
||||
await db.Set<TechMessage>().AddRangeAsync(entities, token);
|
||||
var result = await db.SaveChangesAsync(token);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
35
Persistence/API/ITechMessages.cs
Normal file
35
Persistence/API/ITechMessages.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Persistence.Models;
|
||||
|
||||
namespace Persistence.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Интерфейс для API сообщений о состояниях работы систем автобурения (АБ)
|
||||
/// </summary>
|
||||
public interface ITechMessages : ITableDataApi<TechMessageDto, RequestDto>
|
||||
{
|
||||
/// <summary>
|
||||
/// Добавление новых сообщений
|
||||
/// </summary>
|
||||
/// <param name="dtos"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<ActionResult<int>> InsertRange(IEnumerable<TechMessageDto> dtos, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Получение списка систем АБ
|
||||
/// </summary>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<ActionResult<IEnumerable<string>>> GetSystems(CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Получение статистики
|
||||
/// </summary>
|
||||
/// <param name="importantId">Id Категории важности</param>
|
||||
/// <param name="autoDrillingSystem">Система АБ</param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<ActionResult<int>> GetStatistics(int importantId, string autoDrillingSystem, CancellationToken token);
|
||||
}
|
||||
}
|
40
Persistence/Models/TechMessageDto.cs
Normal file
40
Persistence/Models/TechMessageDto.cs
Normal file
@ -0,0 +1,40 @@
|
||||
namespace Persistence.Models
|
||||
{
|
||||
public class TechMessageDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Id события
|
||||
/// </summary>
|
||||
public Guid EventId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Id Категории важности
|
||||
/// </summary>
|
||||
public int ImportantId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Дата возникновения
|
||||
/// </summary>
|
||||
public DateTimeOffset OccurrenceDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Глубина забоя
|
||||
/// </summary>
|
||||
public double? Depth { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Текст сообщения
|
||||
/// </summary>
|
||||
public string? MessageText { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Система автобурения, к которой относится сообщение
|
||||
/// </summary>
|
||||
public string? AutoDrillingSystem { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Id пользователя за пультом бурильщика
|
||||
/// </summary>
|
||||
public Guid UserId { get; set; }
|
||||
}
|
||||
}
|
34
Persistence/Repositories/ITechMessagesRepository.cs
Normal file
34
Persistence/Repositories/ITechMessagesRepository.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using Persistence.Models;
|
||||
|
||||
namespace Persistence.Repositories
|
||||
{
|
||||
/// <summary>
|
||||
/// Интерфейс по работе с технологическими сообщениями
|
||||
/// </summary>
|
||||
public interface ITechMessagesRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// Добавление новых сообщений
|
||||
/// </summary>
|
||||
/// <param name="dtos"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> InsertRange(IEnumerable<TechMessageDto> dtos, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Получение списка уникальных названий систем АБ
|
||||
/// </summary>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<string>> GetSystems(CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Получение количества сообщений по категориям и системам автобурения
|
||||
/// </summary>
|
||||
/// <param name="importantId">Id Категории важности</param>
|
||||
/// <param name="autoDrillingSystem">Система автобурения</param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> GetStatistics(int importantId, string autoDrillingSystem, CancellationToken token);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user