forked from ddrilling/AsbCloudServer
autoclean.
This commit is contained in:
parent
341375bf1f
commit
7080b3e855
@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AsbCloudApp.Data
|
||||
{
|
||||
@ -31,7 +29,7 @@ namespace AsbCloudApp.Data
|
||||
public double? AverageTargetValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Коэффициент эффективности
|
||||
/// Коэффициент эффективности, %
|
||||
/// </summary>
|
||||
public double? Efficiency { get; set; }
|
||||
|
||||
|
@ -1,6 +1,4 @@
|
||||
using System;
|
||||
|
||||
namespace AsbCloudApp.Data
|
||||
namespace AsbCloudApp.Data
|
||||
{
|
||||
/// <summary>
|
||||
/// Описание целевых/нормативных показателей операций
|
||||
|
@ -14,9 +14,11 @@ namespace AsbCloudApp.Data
|
||||
/// <summary>
|
||||
/// час
|
||||
/// </summary>
|
||||
public int Hour {
|
||||
public int Hour
|
||||
{
|
||||
get => hour;
|
||||
set {
|
||||
set
|
||||
{
|
||||
if (value > 23 || value < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(Hour), "hour should be in [0; 23]");
|
||||
hour = value;
|
||||
|
@ -1,5 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AsbCloudApp.Requests
|
||||
{
|
||||
|
@ -9,9 +9,9 @@ namespace AsbCloudApp.Services
|
||||
/// <summary>
|
||||
/// Сервис получения, добавления, изменения, удаления данных
|
||||
/// </summary>
|
||||
/// <typeparam name="Tdto"></typeparam>
|
||||
public interface ICrudService<Tdto>
|
||||
where Tdto : Data.IId
|
||||
/// <typeparam name="TDto"></typeparam>
|
||||
public interface ICrudService<TDto>
|
||||
where TDto : Data.IId
|
||||
{
|
||||
/// <summary>
|
||||
/// Код возврата ошибки: Id не найден в БД.
|
||||
@ -23,7 +23,7 @@ namespace AsbCloudApp.Services
|
||||
/// </summary>
|
||||
/// <param name="token"></param>
|
||||
/// <returns>emptyList if nothing found</returns>
|
||||
Task<IEnumerable<Tdto>> GetAllAsync(CancellationToken token);
|
||||
Task<IEnumerable<TDto>> GetAllAsync(CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Получить запись по id
|
||||
@ -31,14 +31,14 @@ namespace AsbCloudApp.Services
|
||||
/// <param name="id"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns>null if not found</returns>
|
||||
Task<Tdto?> GetAsync(int id, CancellationToken token);
|
||||
Task<TDto?> GetAsync(int id, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Получить запись по id
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns>null if not found</returns>
|
||||
Tdto? Get(int id);
|
||||
TDto? Get(int id);
|
||||
|
||||
/// <summary>
|
||||
/// Добавление новой записи
|
||||
@ -46,7 +46,7 @@ namespace AsbCloudApp.Services
|
||||
/// <param name="newItem"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns>Id новой записи</returns>
|
||||
Task<int> InsertAsync(Tdto newItem, CancellationToken token);
|
||||
Task<int> InsertAsync(TDto newItem, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Добавление нескольких записей
|
||||
@ -54,7 +54,7 @@ namespace AsbCloudApp.Services
|
||||
/// <param name="newItems"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns>количество добавленных</returns>
|
||||
Task<int> InsertRangeAsync(IEnumerable<Tdto> newItems, CancellationToken token);
|
||||
Task<int> InsertRangeAsync(IEnumerable<TDto> newItems, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Отредактировать запись
|
||||
@ -62,7 +62,7 @@ namespace AsbCloudApp.Services
|
||||
/// <param name="item"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns>если больше 0 - Id записи, если меньше 0 - код ошибки</returns>
|
||||
Task<int> UpdateAsync(Tdto item, CancellationToken token);
|
||||
Task<int> UpdateAsync(TDto item, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Удалить запись
|
||||
|
@ -1,6 +1,5 @@
|
||||
using AsbCloudApp.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
@ -10,8 +10,8 @@ namespace AsbCloudApp.Services
|
||||
Task<int> InsertAsync(SetpointsRequestDto setpoints, CancellationToken token);
|
||||
Task<IEnumerable<SetpointsRequestDto>> GetAsync(int idWell, CancellationToken token);
|
||||
Task<IEnumerable<SetpointsRequestDto>> GetForPanelAsync(string uid, CancellationToken token);
|
||||
Task<int> TryDelete(int idWell, int id, CancellationToken token);
|
||||
Task<int> UpdateStateAsync(string uid, int id, SetpointsRequestDto setpointsRequestDto, CancellationToken token);
|
||||
IEnumerable<SetpointInfoDto> GetSetpointsNames(int idWell);
|
||||
Task<int> TryDelete(int id, CancellationToken token);
|
||||
Task<int> UpdateStateAsync(int id, SetpointsRequestDto setpointsRequestDto, CancellationToken token);
|
||||
IEnumerable<SetpointInfoDto> GetSetpointsNames();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text.Json.Serialization;
|
||||
|
@ -84,7 +84,8 @@ namespace AsbCloudInfrastructure.EfCache
|
||||
{
|
||||
if (semaphore.Wait(0))
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
cache = new CacheItem();
|
||||
caches.Add(tag, cache);
|
||||
}
|
||||
|
@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Mapster
|
||||
namespace Mapster
|
||||
{
|
||||
public static class MapsterExtension
|
||||
{
|
||||
|
@ -87,6 +87,15 @@ namespace AsbCloudInfrastructure.Services
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async Task<int> UpdateRangeAsync(IEnumerable<TDto> dtos, CancellationToken token)
|
||||
{
|
||||
var result = await base.UpdateRangeAsync(dtos, token);
|
||||
if (result > 0)
|
||||
DropCache();
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async Task<int> DeleteAsync(int id, CancellationToken token)
|
||||
{
|
||||
|
@ -3,7 +3,6 @@ using AsbCloudDb.Model;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
@ -37,7 +36,8 @@ namespace AsbCloudInfrastructure.Services
|
||||
this.dbContext = dbContext;
|
||||
dbSet = dbContext.Set<TEntity>();
|
||||
|
||||
GetQuery = () => {
|
||||
GetQuery = () =>
|
||||
{
|
||||
IQueryable<TEntity> query = dbSet;
|
||||
foreach (var include in includes)
|
||||
query = query.Include(include);
|
||||
@ -140,6 +140,29 @@ namespace AsbCloudInfrastructure.Services
|
||||
return entry.Entity.Id;
|
||||
}
|
||||
|
||||
public virtual async Task<int> UpdateRangeAsync(IEnumerable<TDto> dtos, CancellationToken token)
|
||||
{
|
||||
var ids = dtos.Select(d => d.Id);
|
||||
var existingEntities = await dbSet
|
||||
.AsNoTracking()
|
||||
.Where(d => ids.Contains(d.Id))
|
||||
.Select(d => d.Id)
|
||||
.ToListAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (ids.Count() > existingEntities.Count)
|
||||
return ICrudService<TDto>.ErrorIdNotFound;
|
||||
|
||||
foreach (var dto in dtos)
|
||||
{
|
||||
var entity = Convert(dto);
|
||||
var entry = dbSet.Update(entity);
|
||||
}
|
||||
|
||||
var affected = await dbContext.SaveChangesAsync(token);
|
||||
return affected;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual Task<int> DeleteAsync(int id, CancellationToken token = default)
|
||||
{
|
||||
|
@ -1,14 +1,14 @@
|
||||
using System;
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Mapster;
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.DailyReport
|
||||
{
|
||||
|
@ -4,10 +4,10 @@ using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.DetectOperations
|
||||
{
|
||||
@ -115,7 +115,8 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
|
||||
var query = db.TelemetryDataSaub
|
||||
.AsNoTracking()
|
||||
.Where(d => d.IdTelemetry == idTelemetry)
|
||||
.Select(d => new DetectableTelemetry{
|
||||
.Select(d => new DetectableTelemetry
|
||||
{
|
||||
DateTime = d.DateTime,
|
||||
IdUser = d.IdUser,
|
||||
WellDepth = d.WellDepth,
|
||||
|
@ -1,11 +1,6 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Services.Cache;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
|
@ -1,8 +1,7 @@
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Services.Cache;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -11,7 +10,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.SAUB
|
||||
{
|
||||
public class SetpointsService : ISetpointsService, IConverter<SetpointsRequestDto, SetpointsRequest>
|
||||
public class SetpointsService : ISetpointsService
|
||||
{
|
||||
// ## Инфо от АПГ от 26.11.2021, дополнения ШОВ от 26.11.2021
|
||||
private static readonly Dictionary<string, SetpointInfoDto> SetpointInfos = new()
|
||||
@ -23,38 +22,33 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
{ "speedRotorSp", new SetpointInfoDto { Name = "speedRotorSp", DisplayName = "Скорость бурения в роторе, м/ч" } },
|
||||
{ "speedSlideSp", new SetpointInfoDto { Name = "speedSlideSp", DisplayName = "Скорость бурения в слайде, м/ч" } },
|
||||
{ "speedDevelopSp", new SetpointInfoDto { Name = "speedDevelopSp", DisplayName = "Скорость проработки, м/ч" } },
|
||||
{ "torque_pid_out_limit", new SetpointInfoDto { Name = "torque_pid_out_limit", DisplayName = "Торк мастер. Допустимый процент отклонения от заданой скорости вращения" } }, // Такая же что и прямой
|
||||
{ "torque_pid_out_limit", new SetpointInfoDto { Name = "torque_pid_out_limit", DisplayName = "Торк мастер. Допустимый процент отклонения от заданной скорости вращения" } }, // Такая же что и прямой
|
||||
//{ "", new SetpointInfoDto { Name = "", DisplayName = "Обороты ВСП, об/мин" } }, // Оно в ПЛК спинмастера, пока сделать нельзя, позднее можно.
|
||||
//{ "", new SetpointInfoDto { Name = "", DisplayName = "Расход промывочной жидкости, л/с" } }, // Нет в контроллере
|
||||
};
|
||||
|
||||
private readonly CacheTable<SetpointsRequest> cacheSetpoints;
|
||||
private readonly IAsbCloudDbContext db;
|
||||
private readonly ITelemetryService telemetryService;
|
||||
private readonly CrudCacheServiceBase<SetpointsRequestDto, SetpointsRequest> setpointsRepository;
|
||||
|
||||
public SetpointsService(IAsbCloudDbContext db, CacheDb cacheDb, ITelemetryService telemetryService)
|
||||
public SetpointsService(IAsbCloudDbContext db, ITelemetryService telemetryService)
|
||||
{
|
||||
cacheSetpoints = cacheDb.GetCachedTable<SetpointsRequest>(
|
||||
(AsbCloudDbContext)db,
|
||||
nameof(SetpointsRequest.Author),
|
||||
nameof(SetpointsRequest.Well));
|
||||
setpointsRepository = new CrudCacheServiceBase<SetpointsRequestDto, SetpointsRequest>(db, q => q.Include(s => s.Author).Include(s => s.Well));
|
||||
this.db = db;
|
||||
this.telemetryService = telemetryService;
|
||||
}
|
||||
|
||||
public async Task<int> InsertAsync(SetpointsRequestDto setpoints, CancellationToken token)
|
||||
public async Task<int> InsertAsync(SetpointsRequestDto setpointsRequest, CancellationToken token)
|
||||
{
|
||||
setpoints.IdState = 1;
|
||||
setpoints.UploadDate = DateTime.UtcNow;
|
||||
var dto = Convert(setpoints);
|
||||
var inserted = await cacheSetpoints.InsertAsync(dto, token)
|
||||
.ConfigureAwait(false);
|
||||
return inserted?.Id ?? 0;
|
||||
setpointsRequest.IdState = 1;
|
||||
setpointsRequest.UploadDate = DateTime.UtcNow;
|
||||
var result = await setpointsRepository.InsertAsync(setpointsRequest, token);
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<SetpointsRequestDto>> GetAsync(int idWell, CancellationToken token)
|
||||
{
|
||||
var entities = await cacheSetpoints.WhereAsync(s => s.IdWell == idWell, token)
|
||||
.ConfigureAwait(false);
|
||||
var dtos = entities.Select(s => Convert(s));
|
||||
var all = await setpointsRepository.GetAllAsync(token);
|
||||
var dtos = all.Where(s => s.IdWell == idWell);
|
||||
return dtos;
|
||||
}
|
||||
|
||||
@ -64,79 +58,45 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
|
||||
if (idWell < 0)
|
||||
return null;
|
||||
var all = await setpointsRepository.GetAllAsync(token);
|
||||
var filtered = all.Where(s =>
|
||||
s.IdWell == idWell &&
|
||||
s.IdState == 1 &&
|
||||
s.UploadDate.AddSeconds(s.ObsolescenceSec) > DateTime.Now);
|
||||
|
||||
var entities = (await cacheSetpoints.WhereAsync(s =>
|
||||
s.IdWell == idWell && s.IdState == 1 && s.UploadDate.AddSeconds(s.ObsolescenceSec) > DateTime.Now,
|
||||
token)
|
||||
.ConfigureAwait(false))
|
||||
.ToList();// без .ToList() работает не правильно.
|
||||
|
||||
if (!entities.Any())
|
||||
if (!filtered.Any())
|
||||
return null;
|
||||
|
||||
foreach (var entity in entities)
|
||||
foreach (var entity in filtered)
|
||||
entity.IdState = 2;
|
||||
|
||||
await cacheSetpoints.UpsertAsync(entities, token)
|
||||
.ConfigureAwait(false);
|
||||
await setpointsRepository.UpdateRangeAsync(filtered, token);
|
||||
|
||||
var dtos = entities.Select(Convert);
|
||||
|
||||
return dtos;
|
||||
return filtered;
|
||||
}
|
||||
|
||||
public async Task<int> UpdateStateAsync(string uid, int id, SetpointsRequestDto setpointsRequestDto, CancellationToken token)
|
||||
public async Task<int> UpdateStateAsync(int id, SetpointsRequestDto setpointsRequestDto, CancellationToken token)
|
||||
{
|
||||
if (setpointsRequestDto.IdState != 3 && setpointsRequestDto.IdState != 4)
|
||||
throw new ArgumentOutOfRangeException(nameof(setpointsRequestDto), $"{nameof(setpointsRequestDto.IdState)} = {setpointsRequestDto.IdState}. Mast be 3 or 4.");
|
||||
|
||||
var idWell = telemetryService.GetIdWellByTelemetryUid(uid) ?? -1;
|
||||
|
||||
if (idWell < 0)
|
||||
return 0;
|
||||
|
||||
bool Predicate(SetpointsRequest s) => s.Id == id && s.IdWell == idWell && s.IdState == 2;
|
||||
|
||||
var entity = await cacheSetpoints.FirstOrDefaultAsync(Predicate, token)
|
||||
.ConfigureAwait(false);
|
||||
var entity = await setpointsRepository.GetAsync(id, token);
|
||||
|
||||
if (entity is null)
|
||||
return 0;
|
||||
|
||||
entity.IdState = setpointsRequestDto.IdState;
|
||||
await cacheSetpoints.UpsertAsync(entity, token)
|
||||
.ConfigureAwait(false);
|
||||
return 1;
|
||||
var affected = await setpointsRepository.UpdateAsync(entity, token);
|
||||
return affected;
|
||||
}
|
||||
|
||||
public async Task<int> TryDelete(int idWell, int id, CancellationToken token)
|
||||
public async Task<int> TryDelete(int id, CancellationToken token)
|
||||
{
|
||||
bool Predicate(SetpointsRequest s) => s.Id == id && s.IdWell == idWell && s.IdState == 1;
|
||||
var isExist = await cacheSetpoints.ContainsAsync(Predicate, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (!isExist)
|
||||
return 0;
|
||||
|
||||
await cacheSetpoints.RemoveAsync(Predicate, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return 1;
|
||||
var affected = await setpointsRepository.DeleteAsync(id, token);
|
||||
return affected;
|
||||
}
|
||||
|
||||
public SetpointsRequest Convert(SetpointsRequestDto src)
|
||||
{
|
||||
var entity = src.Adapt<SetpointsRequest>();
|
||||
return entity;
|
||||
}
|
||||
|
||||
public SetpointsRequestDto Convert(SetpointsRequest src)
|
||||
{
|
||||
var dto = src.Adapt<SetpointsRequestDto>();
|
||||
return dto;
|
||||
}
|
||||
|
||||
public IEnumerable<SetpointInfoDto> GetSetpointsNames(int idWell)
|
||||
public IEnumerable<SetpointInfoDto> GetSetpointsNames()
|
||||
=> SetpointInfos.Values;
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ using AsbCloudApp.Services;
|
||||
using AsbCloudDb;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.EfCache;
|
||||
using AsbCloudInfrastructure.Services.Cache;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
@ -4,7 +4,6 @@ using AsbCloudDb.Model;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -2,8 +2,8 @@
|
||||
using AsbCloudApp.Exceptions;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Services.Cache;
|
||||
using AsbCloudInfrastructure.EfCache;
|
||||
using AsbCloudInfrastructure.Services.Cache;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
|
@ -1,17 +1,4 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudWebApi.Controllers.SAUB;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Moq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Claims;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace AsbCloudWebApi.Tests.ControllersTests
|
||||
namespace AsbCloudWebApi.Tests.ControllersTests
|
||||
{
|
||||
//public class AnalyticsControllerTests
|
||||
//{
|
||||
|
@ -1,11 +1,6 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudWebApi.Tests.ControllersTests
|
||||
{
|
||||
|
@ -1,17 +1,8 @@
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudWebApi.Controllers;
|
||||
using AsbCloudWebApi.SignalR;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Moq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace AsbCloudWebApi.Tests.ControllersTests
|
||||
{
|
||||
|
@ -1,11 +1,11 @@
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Services;
|
||||
using Moq;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
using AsbCloudApp.Services;
|
||||
|
||||
namespace AsbCloudWebApi.Tests.ServicesTests;
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
using AsbCloudApp.Services;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -1,5 +1,4 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Services;
|
||||
@ -7,9 +6,6 @@ using AsbCloudInfrastructure.Services.Cache;
|
||||
using AsbCloudInfrastructure.Services.DetectOperations;
|
||||
using Moq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
@ -1,11 +1,7 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Services;
|
||||
using AsbCloudInfrastructure.Services.Cache;
|
||||
using Moq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -1,17 +1,16 @@
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Services;
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Services.DrillingProgram;
|
||||
using Mapster;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Moq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudInfrastructure.Services.DrillingProgram;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Threading;
|
||||
using AsbCloudApp.Data;
|
||||
using Mapster;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
{
|
||||
@ -185,7 +184,8 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
{
|
||||
const int idUserRole = 1;
|
||||
const int idFileCategory = 1001;
|
||||
var entry = db.DrillingProgramParts.Add(new DrillingProgramPart {
|
||||
var entry = db.DrillingProgramParts.Add(new DrillingProgramPart
|
||||
{
|
||||
IdFileCategory = idFileCategory,
|
||||
IdWell = idWell
|
||||
});
|
||||
|
@ -1,14 +1,13 @@
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Services.Cache;
|
||||
using AsbCloudInfrastructure.Services;
|
||||
using AsbCloudInfrastructure.Services.SAUB;
|
||||
using Moq;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Services;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudInfrastructure.Services.SAUB;
|
||||
|
||||
namespace AsbCloudWebApi.Tests.ServicesTests;
|
||||
|
||||
|
@ -41,7 +41,8 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
};
|
||||
}
|
||||
|
||||
private Well well = new Well {
|
||||
private Well well = new Well
|
||||
{
|
||||
Id = 1,
|
||||
Caption = "Test well 1",
|
||||
IdCluster = 1,
|
||||
|
@ -2,7 +2,6 @@
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Services;
|
||||
using AsbCloudInfrastructure.Services.Cache;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
@ -62,7 +61,8 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
~UserRoleServiceTest(){
|
||||
~UserRoleServiceTest()
|
||||
{
|
||||
context.UserRoles.RemoveRange(roles);
|
||||
context.Permissions.RemoveRange(permissions);
|
||||
context.RelationUserRoleUserRoles.RemoveRange(relationRoleRole);
|
||||
|
@ -22,7 +22,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
where T : IId, IWellRelated
|
||||
where TService : ICrudWellRelatedService<T>
|
||||
{
|
||||
private readonly IWellService wellService;
|
||||
protected readonly IWellService wellService;
|
||||
|
||||
protected CrudWellRelatedController(IWellService wellService, TService service)
|
||||
: base(service)
|
||||
@ -130,6 +130,4 @@ namespace AsbCloudWebApi.Controllers
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
@ -6,7 +7,6 @@ using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Services;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers
|
||||
{
|
||||
|
@ -1,12 +1,7 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ProtoBuf.Meta;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers
|
||||
{
|
||||
|
@ -1,10 +1,10 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Requests;
|
||||
using AsbCloudApp.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
using AsbCloudApp.Requests;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers.SAUB
|
||||
{
|
||||
|
@ -34,7 +34,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
[AllowAnonymous]
|
||||
public IActionResult GetSetpointsNamesByIdWellAsync([FromRoute] int idWell)
|
||||
{
|
||||
var result = setpointsService.GetSetpointsNames(idWell);
|
||||
var result = setpointsService.GetSetpointsNames();
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
@ -115,7 +115,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
[AllowAnonymous]
|
||||
public async Task<IActionResult> UpdateByTelemetryUidAsync([FromRoute] string uid, int id, SetpointsRequestDto setpointsRequestDto, CancellationToken token = default)
|
||||
{
|
||||
var result = await setpointsService.UpdateStateAsync(uid, id, setpointsRequestDto, token)
|
||||
var result = await setpointsService.UpdateStateAsync(id, setpointsRequestDto, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return Ok(result);
|
||||
@ -156,7 +156,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
if (idCompany is null || idUser is null)
|
||||
return Forbid();
|
||||
|
||||
var result = await setpointsService.TryDelete(idWell, id, token)
|
||||
var result = await setpointsService.TryDelete(id, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return Ok(result);
|
||||
|
@ -3,7 +3,6 @@ using AsbCloudApp.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -12,37 +11,16 @@ namespace AsbCloudWebApi.Controllers
|
||||
[Route("api/schedule")]
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
public class ScheduleController : CrudController<ScheduleDto, IScheduleService>
|
||||
public class ScheduleController : CrudWellRelatedController<ScheduleDto, IScheduleService>
|
||||
{
|
||||
private readonly IScheduleService scheduleService;
|
||||
private readonly IWellService wellService;
|
||||
|
||||
public ScheduleController(IScheduleService scheduleService, IWellService wellService)
|
||||
:base(scheduleService)
|
||||
: base(wellService, scheduleService)
|
||||
{
|
||||
this.scheduleService = service;
|
||||
this.wellService = wellService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// список расписаний бурильщиков по скважине
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("byWellId/{idWell}")]
|
||||
[ProducesResponseType(typeof(IEnumerable<ScheduleDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetByIdWellAsync(int idWell, CancellationToken token)
|
||||
{
|
||||
var idCompany = User.GetCompanyId();
|
||||
if(idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
||||
return Forbid();
|
||||
|
||||
var result = await scheduleService.GetByIdWellAsync(idWell, token);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Получить бурильщика работавшего на скважине в определенное время.
|
||||
/// </summary>
|
||||
@ -53,8 +31,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
[HttpGet("driller")]
|
||||
public async Task<ActionResult<DrillerDto>> GetDrillerAsync(int idWell, DateTime workTime, CancellationToken token)
|
||||
{
|
||||
var idCompany = User.GetCompanyId();
|
||||
if (idCompany is null || !wellService.IsCompanyInvolvedInWell((int)idCompany, idWell))
|
||||
if (!await UserHasAccesToWellAsync(idWell, token))
|
||||
return Forbid();
|
||||
|
||||
var result = await scheduleService.GetDrillerAsync(idWell, workTime, token);
|
||||
|
@ -1,5 +1,4 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.WITS;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudWebApi.SignalR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
@ -1,5 +1,4 @@
|
||||
using AsbCloudInfrastructure.Services;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
@ -3,7 +3,6 @@ using AsbCloudApp.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
@ -24,7 +24,8 @@ namespace AsbCloudWebApi
|
||||
{
|
||||
options.JsonSerializerOptions.NumberHandling =
|
||||
System.Text.Json.Serialization.JsonNumberHandling.AllowNamedFloatingPointLiterals |
|
||||
System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString;}))
|
||||
System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString;
|
||||
}))
|
||||
.AddProtoBufNet();
|
||||
|
||||
ProtobufModel.EnshureRegistered();
|
||||
|
@ -1,10 +1,7 @@
|
||||
using AsbCloudDb.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConsoleApp1
|
||||
{
|
||||
|
@ -1,12 +1,11 @@
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConsoleApp1
|
||||
{
|
||||
|
@ -1,13 +1,6 @@
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Services;
|
||||
using AsbCloudInfrastructure.Services.Cache;
|
||||
using AsbCloudInfrastructure.Services.WellOperationService;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConsoleApp1
|
||||
{
|
||||
|
@ -1,14 +1,6 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Services;
|
||||
using AsbCloudInfrastructure.Services.Cache;
|
||||
using AsbCloudInfrastructure.Services.WellOperationService;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ConsoleApp1
|
||||
{
|
||||
|
@ -2,11 +2,10 @@ using Google.Apis.Auth.OAuth2;
|
||||
using Google.Apis.Auth.OAuth2.Flows;
|
||||
using Google.Apis.Auth.OAuth2.Responses;
|
||||
using Google.Apis.Drive.v3;
|
||||
using Google.Apis.Drive.v3.Data;
|
||||
using Google.Apis.Services;
|
||||
using Google.Apis.Util.Store;
|
||||
using Google.Apis.Drive.v3.Data;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
// usage example at the very bottom
|
||||
|
@ -1,9 +1,5 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.EfCache;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using AsbCloudInfrastructure.EfCache;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@ -21,7 +17,8 @@ namespace ConsoleApp1
|
||||
|
||||
for (int i = 0; i < 24; i++)
|
||||
{
|
||||
var t = new Thread(_ => {
|
||||
var t = new Thread(_ =>
|
||||
{
|
||||
for (int j = 0; j < 32; j++)
|
||||
//Task.Run(GetDataAsync).Wait();
|
||||
GetData();
|
||||
|
@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Mail;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Net.Mail;
|
||||
|
||||
namespace ConsoleApp1
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user