forked from ddrilling/AsbCloudServer
Crud services moved to Repository directory
This commit is contained in:
parent
9146be1d3f
commit
cf98bd8a20
@ -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?> GetOrDefaultAsync(int id, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Получить запись по id
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns>null if not found</returns>
|
||||
TDto? Get(int id);
|
||||
TDto? GetOrDefault(int id);
|
||||
|
||||
/// <summary>
|
||||
/// Добавление новой записи
|
||||
|
@ -11,7 +11,7 @@ namespace AsbCloudApp.Services
|
||||
Task<IEnumerable<SetpointsRequestDto>> GetAsync(int idWell, CancellationToken token);
|
||||
Task<IEnumerable<SetpointsRequestDto>> GetForPanelAsync(string uid, CancellationToken token);
|
||||
Task<int> TryDelete(int id, CancellationToken token);
|
||||
Task<int> UpdateStateAsync(int id, SetpointsRequestDto setpointsRequestDto, CancellationToken token);
|
||||
Task<int> UpdateStateAsync(SetpointsRequestDto setpointsRequestDto, CancellationToken token);
|
||||
IEnumerable<SetpointInfoDto> GetSetpointsNames();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Repository;
|
||||
using AsbCloudInfrastructure.Services;
|
||||
using AsbCloudInfrastructure.Services.Cache;
|
||||
using AsbCloudInfrastructure.Services.DailyReport;
|
||||
|
@ -7,9 +7,8 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services
|
||||
namespace AsbCloudInfrastructure.Repository
|
||||
{
|
||||
#nullable enable
|
||||
/// <summary>
|
||||
/// CRUD ñåðâèñ ñ êåøåì â îïåðàòèâêå
|
||||
/// </summary>
|
||||
@ -17,7 +16,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
/// <typeparam name="TEntity"></typeparam>
|
||||
public class CrudCacheServiceBase<TDto, TEntity> : CrudServiceBase<TDto, TEntity>
|
||||
where TDto : AsbCloudApp.Data.IId
|
||||
where TEntity : class, AsbCloudDb.Model.IId
|
||||
where TEntity : class, IId
|
||||
{
|
||||
protected string CacheTag = typeof(TDto).Name;
|
||||
protected TimeSpan CacheOlescence = TimeSpan.FromMinutes(5);
|
||||
@ -53,9 +52,8 @@ namespace AsbCloudInfrastructure.Services
|
||||
/// <inheritdoc/>
|
||||
public override async Task<IEnumerable<TDto>> GetAllAsync(CancellationToken token)
|
||||
{
|
||||
var result = await GetQuery()
|
||||
.FromCacheDictionaryAsync(CacheTag, CacheOlescence, KeySelector, Convert, token);
|
||||
return result.Values;
|
||||
var cache = await GetCacheAsync(token);
|
||||
return cache.Values;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -63,19 +61,17 @@ namespace AsbCloudInfrastructure.Services
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public override TDto? Get(int id)
|
||||
public override TDto? GetOrDefault(int id)
|
||||
{
|
||||
var result = GetQuery()
|
||||
.FromCacheDictionary(CacheTag, CacheOlescence, KeySelector, Convert);
|
||||
return result.GetValueOrDefault(id);
|
||||
var cache = GetCache();
|
||||
return cache.GetValueOrDefault(id);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async Task<TDto?> GetAsync(int id, CancellationToken token)
|
||||
public override async Task<TDto?> GetOrDefaultAsync(int id, CancellationToken token)
|
||||
{
|
||||
var result = await GetQuery()
|
||||
.FromCacheDictionaryAsync(CacheTag, CacheOlescence, KeySelector, Convert, token);
|
||||
return result.GetValueOrDefault(id);
|
||||
var cache = await GetCacheAsync(token);
|
||||
return cache.GetValueOrDefault(id);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
@ -8,7 +8,7 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services
|
||||
namespace AsbCloudInfrastructure.Repository
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
@ -18,7 +18,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
/// <typeparam name="TEntity"></typeparam>
|
||||
public class CrudServiceBase<TDto, TEntity> : ICrudService<TDto>
|
||||
where TDto : AsbCloudApp.Data.IId
|
||||
where TEntity : class, AsbCloudDb.Model.IId
|
||||
where TEntity : class, IId
|
||||
{
|
||||
protected readonly IAsbCloudDbContext dbContext;
|
||||
protected readonly DbSet<TEntity> dbSet;
|
||||
@ -26,7 +26,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
public CrudServiceBase(IAsbCloudDbContext context)
|
||||
{
|
||||
this.dbContext = context;
|
||||
dbContext = context;
|
||||
dbSet = context.Set<TEntity>();
|
||||
GetQuery = () => dbSet;
|
||||
}
|
||||
@ -47,7 +47,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
public CrudServiceBase(IAsbCloudDbContext context, Func<DbSet<TEntity>, IQueryable<TEntity>> makeQuery)
|
||||
{
|
||||
this.dbContext = context;
|
||||
dbContext = context;
|
||||
dbSet = context.Set<TEntity>();
|
||||
GetQuery = () => makeQuery(dbSet);
|
||||
}
|
||||
@ -65,7 +65,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual async Task<TDto?> GetAsync(int id, CancellationToken token = default)
|
||||
public virtual async Task<TDto?> GetOrDefaultAsync(int id, CancellationToken token = default)
|
||||
{
|
||||
var entity = await GetQuery()
|
||||
.AsNoTracking()
|
||||
@ -78,7 +78,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual TDto? Get(int id)
|
||||
public virtual TDto? GetOrDefault(int id)
|
||||
{
|
||||
var entity = GetQuery()
|
||||
.AsNoTracking()
|
@ -0,0 +1,51 @@
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudInfrastructure.Repository
|
||||
{
|
||||
#nullable enable
|
||||
public class CrudWellRelatedCacheServiceBase<TDto, TEntity> : CrudCacheServiceBase<TDto, TEntity>, ICrudWellRelatedService<TDto>
|
||||
where TDto : AsbCloudApp.Data.IId, AsbCloudApp.Data.IWellRelated
|
||||
where TEntity : class, IId, IWellRelated
|
||||
{
|
||||
public CrudWellRelatedCacheServiceBase(IAsbCloudDbContext context)
|
||||
: base(context) { }
|
||||
|
||||
public CrudWellRelatedCacheServiceBase(IAsbCloudDbContext dbContext, ISet<string> includes)
|
||||
: base(dbContext, includes) { }
|
||||
|
||||
public CrudWellRelatedCacheServiceBase(IAsbCloudDbContext context, Func<DbSet<TEntity>, IQueryable<TEntity>> makeQuery)
|
||||
: base(context, makeQuery) { }
|
||||
|
||||
public async Task<IEnumerable<TDto>> GetByIdWellAsync(int idWell, CancellationToken token)
|
||||
{
|
||||
var cache = await GetCacheAsync(token);
|
||||
|
||||
var dtos = cache.Values
|
||||
.Where(e => e.IdWell == idWell)
|
||||
.ToList();
|
||||
|
||||
return dtos;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<TDto>> GetByIdWellAsync(IEnumerable<int> idsWells, CancellationToken token)
|
||||
{
|
||||
if (!idsWells.Any())
|
||||
return Enumerable.Empty<TDto>();
|
||||
|
||||
var cache = await GetCacheAsync(token);
|
||||
|
||||
var dtos = cache.Values
|
||||
.Where(e => idsWells.Contains(e.IdWell))
|
||||
.ToList();
|
||||
return dtos;
|
||||
}
|
||||
}
|
||||
#nullable disable
|
||||
}
|
@ -7,12 +7,12 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services
|
||||
namespace AsbCloudInfrastructure.Repository
|
||||
{
|
||||
#nullable enable
|
||||
public class CrudWellRelatedServiceBase<TDto, TEntity> : CrudServiceBase<TDto, TEntity>, ICrudWellRelatedService<TDto>
|
||||
where TDto : AsbCloudApp.Data.IId, AsbCloudApp.Data.IWellRelated
|
||||
where TEntity : class, AsbCloudDb.Model.IId, AsbCloudDb.Model.IWellRelated
|
||||
where TEntity : class, IId, IWellRelated
|
||||
{
|
||||
public CrudWellRelatedServiceBase(IAsbCloudDbContext context)
|
||||
: base(context) { }
|
@ -0,0 +1,36 @@
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
|
||||
namespace AsbCloudInfrastructure.Repository
|
||||
{
|
||||
public class SetpointsRequestRepository : CrudWellRelatedCacheServiceBase<SetpointsRequestDto, SetpointsRequest>
|
||||
{
|
||||
private readonly IWellService wellService;
|
||||
|
||||
public SetpointsRequestRepository(IAsbCloudDbContext dbContext, IWellService wellService)
|
||||
: base(dbContext, q => q.Include(s => s.Author)
|
||||
.Include(s => s.Well))
|
||||
{
|
||||
this.wellService = wellService;
|
||||
}
|
||||
|
||||
protected override SetpointsRequestDto Convert(SetpointsRequest src)
|
||||
{
|
||||
var result = base.Convert(src);
|
||||
var timezoneOffsetHours = wellService.GetTimezone(src.IdWell).Hours;
|
||||
result.UploadDate = src.UploadDate.ToRemoteDateTime(timezoneOffsetHours);
|
||||
return result;
|
||||
}
|
||||
|
||||
protected override SetpointsRequest Convert(SetpointsRequestDto src)
|
||||
{
|
||||
var result = base.Convert(src);
|
||||
var timezoneOffsetHours = wellService.GetTimezone(src.IdWell).Hours;
|
||||
result.UploadDate = src.UploadDate.ToUtcDateTimeOffset(timezoneOffsetHours);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
9
AsbCloudInfrastructure/Repository/readme.md
Normal file
9
AsbCloudInfrastructure/Repository/readme.md
Normal file
@ -0,0 +1,9 @@
|
||||
# Repository
|
||||
`Repository` - CRUD сервис для сущности в проекте. Не содержит бизнес логику.
|
||||
|
||||
Вся логика такого сервиса - преобразование данных полученых из БД в Data Transfer Object (DTO) и обратно.
|
||||
Преобразования осуществляются методами `Convert` с базовым маппингом:
|
||||
|
||||
protected virtual TDto Convert(TEntity src) => src.Adapt<TDto>();
|
||||
protected virtual TEntity Convert(TDto src) => src.Adapt<TEntity>();
|
||||
|
@ -51,7 +51,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
if (identity == default || user.IdState == 0)
|
||||
return null;
|
||||
|
||||
var userDto = await userService.GetAsync(user.Id, token)
|
||||
var userDto = await userService.GetOrDefaultAsync(user.Id, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
var userTokenDto = userDto.Adapt<UserTokenDto>();
|
||||
|
@ -121,7 +121,7 @@ namespace AsbCloudInfrastructure.Services.DailyReport
|
||||
|
||||
private async Task<DailyReportDto> MakeDefaultDailyReportAsync(int idWell, DateTime date, CancellationToken token)
|
||||
{
|
||||
var well = await wellService.GetAsync(idWell, token);
|
||||
var well = await wellService.GetOrDefaultAsync(idWell, token);
|
||||
var offsetHours = wellService.GetTimezone(idWell).Hours;
|
||||
var dto = new DailyReportDto()
|
||||
{
|
||||
|
@ -35,7 +35,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
|
||||
|
||||
public async Task<DetectedOperationListDto> GetAsync(int idWell, DetectedOperationRequest request, CancellationToken token)
|
||||
{
|
||||
var well = await wellService.GetAsync(idWell, token);
|
||||
var well = await wellService.GetOrDefaultAsync(idWell, token);
|
||||
if (well?.IdTelemetry is null || well.Timezone is null)
|
||||
return null;
|
||||
|
||||
@ -80,7 +80,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
|
||||
|
||||
public async Task<int> DeleteAsync(int idWell, DetectedOperationRequest request, CancellationToken token)
|
||||
{
|
||||
var well = await wellService.GetAsync(idWell, token);
|
||||
var well = await wellService.GetOrDefaultAsync(idWell, token);
|
||||
if (well?.IdTelemetry is null || well.Timezone is null)
|
||||
return 0;
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Repository;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
|
@ -1,6 +1,7 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Repository;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
|
@ -1,6 +1,7 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Repository;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
|
@ -224,7 +224,7 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram
|
||||
|
||||
public async Task<int> AddUserAsync(int idWell, int idFileCategory, int idUser, int idUserRole, CancellationToken token = default)
|
||||
{
|
||||
var user = await userService.GetAsync(idUser, token);
|
||||
var user = await userService.GetOrDefaultAsync(idUser, token);
|
||||
if (user is null)
|
||||
throw new ArgumentInvalidException($"User id == {idUser} does not exist", nameof(idUser));
|
||||
|
||||
@ -356,7 +356,7 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram
|
||||
private async Task NotifyPublisherOnFullAccepAsync(FileMarkDto fileMark, CancellationToken token)
|
||||
{
|
||||
var file = await fileService.GetInfoAsync(fileMark.IdFile, token);
|
||||
var well = await wellService.GetAsync(file.IdWell, token);
|
||||
var well = await wellService.GetOrDefaultAsync(file.IdWell, token);
|
||||
var user = file.Author;
|
||||
var factory = new MailBodyFactory(configuration);
|
||||
var subject = MailBodyFactory.MakeSubject(well, "Загруженный вами документ полностью согласован");
|
||||
@ -368,7 +368,7 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram
|
||||
private async Task NotifyPublisherOnRejectAsync(FileMarkDto fileMark, CancellationToken token)
|
||||
{
|
||||
var file = await fileService.GetInfoAsync(fileMark.IdFile, token);
|
||||
var well = await wellService.GetAsync(file.IdWell, token);
|
||||
var well = await wellService.GetOrDefaultAsync(file.IdWell, token);
|
||||
var user = file.Author;
|
||||
var factory = new MailBodyFactory(configuration);
|
||||
var subject = MailBodyFactory.MakeSubject(well, "Загруженный вами документ отклонен");
|
||||
@ -379,7 +379,7 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram
|
||||
|
||||
private async Task NotifyApproversAsync(DrillingProgramPart part, int idFile, string fileName, CancellationToken token)
|
||||
{
|
||||
var well = await wellService.GetAsync(part.IdWell, token);
|
||||
var well = await wellService.GetOrDefaultAsync(part.IdWell, token);
|
||||
var factory = new MailBodyFactory(configuration);
|
||||
var subject = MailBodyFactory.MakeSubject(well, "Загружен новый документ для согласования.");
|
||||
var users = part.RelatedUsers
|
||||
@ -395,7 +395,7 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram
|
||||
|
||||
private async Task NotifyNewPublisherAsync(int idWell, UserDto user, string documentCategory, CancellationToken token)
|
||||
{
|
||||
var well = await wellService.GetAsync(idWell, token);
|
||||
var well = await wellService.GetOrDefaultAsync(idWell, token);
|
||||
var factory = new MailBodyFactory(configuration);
|
||||
var subject = MailBodyFactory.MakeSubject(well, $"От вас ожидается загрузка на портал документа «{documentCategory}»");
|
||||
var body = factory.MakeMailBodyForNewPublisher(well, user.Name, documentCategory);
|
||||
@ -469,7 +469,7 @@ namespace AsbCloudInfrastructure.Services.DrillingProgram
|
||||
var workId = MakeWorkId(idWell);
|
||||
if (!backgroundWorker.Contains(workId))
|
||||
{
|
||||
var well = await wellService.GetAsync(idWell, token);
|
||||
var well = await wellService.GetOrDefaultAsync(idWell, token);
|
||||
var resultFileName = $"Программа бурения {well.Cluster} {well.Caption}.xlsx";
|
||||
var tempResultFilePath = Path.Combine(Path.GetTempPath(), "drillingProgram", resultFileName);
|
||||
var mailService = new EmailService(backgroundWorker, configuration);
|
||||
|
@ -1,6 +1,7 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Repository;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
|
@ -1,6 +1,7 @@
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Repository;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -26,14 +27,12 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
//{ "", new SetpointInfoDto { Name = "", DisplayName = "Обороты ВСП, об/мин" } }, // Оно в ПЛК спинмастера, пока сделать нельзя, позднее можно.
|
||||
//{ "", new SetpointInfoDto { Name = "", DisplayName = "Расход промывочной жидкости, л/с" } }, // Нет в контроллере
|
||||
};
|
||||
private readonly IAsbCloudDbContext db;
|
||||
private readonly SetpointsRequestRepository setpointsRepository;
|
||||
private readonly ITelemetryService telemetryService;
|
||||
private readonly CrudCacheServiceBase<SetpointsRequestDto, SetpointsRequest> setpointsRepository;
|
||||
|
||||
public SetpointsService(IAsbCloudDbContext db, ITelemetryService telemetryService)
|
||||
public SetpointsService(IAsbCloudDbContext db, ITelemetryService telemetryService, IWellService wellService)
|
||||
{
|
||||
setpointsRepository = new CrudCacheServiceBase<SetpointsRequestDto, SetpointsRequest>(db, q => q.Include(s => s.Author).Include(s => s.Well));
|
||||
this.db = db;
|
||||
setpointsRepository = new SetpointsRequestRepository(db, wellService);
|
||||
this.telemetryService = telemetryService;
|
||||
}
|
||||
|
||||
@ -62,25 +61,38 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
var filtered = all.Where(s =>
|
||||
s.IdWell == idWell &&
|
||||
s.IdState == 1 &&
|
||||
s.UploadDate.AddSeconds(s.ObsolescenceSec) > DateTime.Now);
|
||||
s.UploadDate.AddSeconds(s.ObsolescenceSec) > DateTime.UtcNow)
|
||||
.ToList();
|
||||
|
||||
if (!filtered.Any())
|
||||
return null;
|
||||
|
||||
foreach (var entity in filtered)
|
||||
entity.IdState = 2;
|
||||
foreach (var item in filtered)
|
||||
{
|
||||
item.IdState = 2;
|
||||
item.UploadDate = DateTime.SpecifyKind(item.UploadDate, DateTimeKind.Utc);
|
||||
}
|
||||
|
||||
await setpointsRepository.UpdateRangeAsync(filtered, token);
|
||||
|
||||
return filtered;
|
||||
}
|
||||
|
||||
public async Task<int> UpdateStateAsync(int id, SetpointsRequestDto setpointsRequestDto, CancellationToken token)
|
||||
public async Task<int> UpdateStateAsync(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 entity = await setpointsRepository.GetAsync(id, token);
|
||||
if (setpointsRequestDto.Id <= 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(setpointsRequestDto), $"{nameof(setpointsRequestDto.Id)} = {setpointsRequestDto.Id}. Mast be > 0");
|
||||
|
||||
if (setpointsRequestDto.IdWell <= 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(setpointsRequestDto), $"{nameof(setpointsRequestDto.IdWell)} = {setpointsRequestDto.IdWell}. Mast be > 0");
|
||||
|
||||
var entity = await setpointsRepository.GetOrDefaultAsync(setpointsRequestDto.Id, token);
|
||||
|
||||
if (entity.IdWell != setpointsRequestDto.IdWell)
|
||||
return 0;
|
||||
|
||||
if (entity is null)
|
||||
return 0;
|
||||
|
@ -1,6 +1,7 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Repository;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
|
@ -56,7 +56,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
var dtos = entities?.Select(Convert);
|
||||
return dtos;
|
||||
}
|
||||
public UserRoleDto Get(int id)
|
||||
public UserRoleDto GetOrDefault(int id)
|
||||
{
|
||||
var entity = cacheUserRoles.FirstOrDefault(r => r.Id == id);
|
||||
if (entity is null)
|
||||
@ -65,7 +65,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
return dto;
|
||||
}
|
||||
|
||||
public async Task<UserRoleDto> GetAsync(int id, CancellationToken token = default)
|
||||
public async Task<UserRoleDto> GetOrDefaultAsync(int id, CancellationToken token = default)
|
||||
{
|
||||
var entity = await cacheUserRoles.FirstOrDefaultAsync(r => r.Id == id, token)
|
||||
.ConfigureAwait(false);
|
||||
|
@ -81,7 +81,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
return dtos;
|
||||
}
|
||||
|
||||
public UserExtendedDto Get(int id)
|
||||
public UserExtendedDto GetOrDefault(int id)
|
||||
{
|
||||
var entity = cacheUsers.FirstOrDefault(u => u.Id == id);
|
||||
var dto = Convert(entity);
|
||||
@ -89,7 +89,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
return dto;
|
||||
}
|
||||
|
||||
public async Task<UserExtendedDto> GetAsync(int id, CancellationToken token = default)
|
||||
public async Task<UserExtendedDto> GetOrDefaultAsync(int id, CancellationToken token = default)
|
||||
{
|
||||
var entity = await cacheUsers.FirstOrDefaultAsync(u => u.Id == id, token).ConfigureAwait(false);
|
||||
var dto = Convert(entity);
|
||||
|
@ -31,7 +31,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
|
||||
if (!tvd.Any())
|
||||
return null;
|
||||
|
||||
var well = await wellService.GetAsync(idWell, token);
|
||||
var well = await wellService.GetOrDefaultAsync(idWell, token);
|
||||
|
||||
var ecxelTemplateStream = GetExcelTemplateStream();
|
||||
using var workbook = new XLWorkbook(ecxelTemplateStream, XLEventTracking.Disabled);
|
||||
|
@ -3,6 +3,7 @@ using AsbCloudApp.Exceptions;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.EfCache;
|
||||
using AsbCloudInfrastructure.Repository;
|
||||
using AsbCloudInfrastructure.Services.Cache;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@ -62,7 +63,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
public DateTimeOffset GetLastTelemetryDate(int idWell)
|
||||
{
|
||||
var well = Get(idWell);
|
||||
var well = GetOrDefault(idWell);
|
||||
|
||||
if (well?.IdTelemetry is null)
|
||||
return DateTimeOffset.MinValue;
|
||||
@ -154,7 +155,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
public async Task<string> GetWellCaptionByIdAsync(int idWell, CancellationToken token)
|
||||
{
|
||||
var entity = await GetAsync(idWell, token).ConfigureAwait(false);
|
||||
var entity = await GetOrDefaultAsync(idWell, token).ConfigureAwait(false);
|
||||
var dto = Convert(entity);
|
||||
return dto.Caption;
|
||||
}
|
||||
@ -186,7 +187,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
public async Task<IEnumerable<int>> GetClusterWellsIdsAsync(int idWell, CancellationToken token)
|
||||
{
|
||||
var well = await GetAsync(idWell, token);
|
||||
var well = await GetOrDefaultAsync(idWell, token);
|
||||
|
||||
if (well is null)
|
||||
return null;
|
||||
@ -239,7 +240,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
var dto = entity.Adapt<CompanyDto>();
|
||||
dto.CompanyTypeCaption = entity.CompanyType?.Caption
|
||||
?? companyTypesService.Get(entity.IdCompanyType).Caption;
|
||||
?? companyTypesService.GetOrDefault(entity.IdCompanyType).Caption;
|
||||
return dto;
|
||||
}
|
||||
|
||||
@ -265,7 +266,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
public SimpleTimezoneDto GetTimezone(int idWell)
|
||||
{
|
||||
var well = Get(idWell);
|
||||
var well = GetOrDefault(idWell);
|
||||
if (well == null)
|
||||
throw new ArgumentInvalidException($"idWell: {idWell} does not exist.", nameof(idWell));
|
||||
return GetTimezone(well);
|
||||
@ -334,7 +335,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
public DatesRangeDto GetDatesRange(int idWell)
|
||||
{
|
||||
var well = Get(idWell);
|
||||
var well = GetOrDefault(idWell);
|
||||
if (well is null)
|
||||
throw new Exception($"Well id: {idWell} does not exist.");
|
||||
|
||||
|
@ -43,7 +43,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
public async Task GetById()
|
||||
{
|
||||
var id = await Insert();
|
||||
var gotItem = await service.GetAsync(id, CancellationToken.None);
|
||||
var gotItem = await service.GetOrDefaultAsync(id, CancellationToken.None);
|
||||
Assert.True(id > 0);
|
||||
Assert.Equal(id, gotItem.Id);
|
||||
}
|
||||
|
@ -162,7 +162,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
db.DrillingProgramParts.Add(new DrillingProgramPart { IdFileCategory = 1001, IdWell = idWell });
|
||||
db.SaveChanges();
|
||||
|
||||
userServiceMock.Setup((s) => s.GetAsync(It.IsAny<int>(), It.IsAny<CancellationToken>()))
|
||||
userServiceMock.Setup((s) => s.GetOrDefaultAsync(It.IsAny<int>(), It.IsAny<CancellationToken>()))
|
||||
.Returns(Task.FromResult(publisher1.Adapt<UserExtendedDto>()));
|
||||
|
||||
var service = new DrillingProgramService(
|
||||
@ -197,7 +197,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
IdUserRole = idUserRole
|
||||
});
|
||||
db.SaveChanges();
|
||||
userServiceMock.Setup((s) => s.GetAsync(It.IsAny<int>(), It.IsAny<CancellationToken>()))
|
||||
userServiceMock.Setup((s) => s.GetOrDefaultAsync(It.IsAny<int>(), It.IsAny<CancellationToken>()))
|
||||
.Returns(Task.FromResult(publisher1.Adapt<UserExtendedDto>()));
|
||||
|
||||
var service = new DrillingProgramService(
|
||||
@ -346,7 +346,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
wellServiceMock.Setup(s => s.GetAsync(It.IsAny<int>(), It.IsAny<CancellationToken>()))
|
||||
wellServiceMock.Setup(s => s.GetOrDefaultAsync(It.IsAny<int>(), It.IsAny<CancellationToken>()))
|
||||
.Returns(Task.FromResult(new WellDto { Caption = "test well", Cluster = "test cluster" }));
|
||||
|
||||
var service = new DrillingProgramService(
|
||||
@ -376,7 +376,7 @@ namespace AsbCloudWebApi.Tests.ServicesTests
|
||||
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
wellServiceMock.Setup(s => s.GetAsync(It.IsAny<int>(), It.IsAny<CancellationToken>()))
|
||||
wellServiceMock.Setup(s => s.GetOrDefaultAsync(It.IsAny<int>(), It.IsAny<CancellationToken>()))
|
||||
.Returns(Task.FromResult(new WellDto { Caption = "test well", Cluster = "test cluster" }));
|
||||
|
||||
var service = new DrillingProgramService(
|
||||
|
@ -16,7 +16,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
{
|
||||
UpdateForbidAsync = async (dto, token) =>
|
||||
{
|
||||
var role = await service.GetAsync(dto.Id, token);
|
||||
var role = await service.GetOrDefaultAsync(dto.Id, token);
|
||||
return role?.IdType != 1;
|
||||
};
|
||||
|
||||
|
@ -57,7 +57,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
[Permission]
|
||||
public virtual async Task<ActionResult<T>> GetAsync(int id, CancellationToken token)
|
||||
{
|
||||
var result = await service.GetAsync(id, token).ConfigureAwait(false);
|
||||
var result = await service.GetOrDefaultAsync(id, token).ConfigureAwait(false);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
|
@ -112,7 +112,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
[HttpDelete("{id}")]
|
||||
public override async Task<ActionResult<int>> DeleteAsync(int id, CancellationToken token)
|
||||
{
|
||||
var item = await service.GetAsync(id, token);
|
||||
var item = await service.GetOrDefaultAsync(id, token);
|
||||
if (item is null)
|
||||
return NoContent();
|
||||
if (!await UserHasAccesToWellAsync(item.IdWell, token))
|
||||
|
@ -101,7 +101,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> DownloadAsync(int idWell, DateTime date, CancellationToken token = default)
|
||||
{
|
||||
var well = await wellService.GetAsync(idWell, token);
|
||||
var well = await wellService.GetOrDefaultAsync(idWell, token);
|
||||
var stream = await dailyReportService.MakeReportAsync(idWell, date, token);
|
||||
if (stream != null)
|
||||
{
|
||||
|
@ -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(id, setpointsRequestDto, token)
|
||||
var result = await setpointsService.UpdateStateAsync(setpointsRequestDto, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return Ok(result);
|
||||
|
@ -57,7 +57,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync(idCompany ?? default, idWell, token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
|
||||
var well = await wellService.GetAsync(idWell,
|
||||
var well = await wellService.GetOrDefaultAsync(idWell,
|
||||
token).ConfigureAwait(false);
|
||||
|
||||
return Ok(well);
|
||||
|
@ -1,8 +1,8 @@
|
||||
{
|
||||
"files": {
|
||||
"main.css": "/static/css/main.a0664ea6.chunk.css",
|
||||
"main.js": "/static/js/main.02d15bac.chunk.js",
|
||||
"main.js.map": "/static/js/main.02d15bac.chunk.js.map",
|
||||
"main.css": "/static/css/main.61ecfb0d.chunk.css",
|
||||
"main.js": "/static/js/main.2493f2fa.chunk.js",
|
||||
"main.js.map": "/static/js/main.2493f2fa.chunk.js.map",
|
||||
"runtime-main.js": "/static/js/runtime-main.83ebcb38.js",
|
||||
"runtime-main.js.map": "/static/js/runtime-main.83ebcb38.js.map",
|
||||
"static/js/2.ebe1f792.chunk.js": "/static/js/2.ebe1f792.chunk.js",
|
||||
@ -36,7 +36,7 @@
|
||||
"index.html": "/index.html",
|
||||
"static/css/3.f8ac3883.chunk.css.map": "/static/css/3.f8ac3883.chunk.css.map",
|
||||
"static/css/4.f8ac3883.chunk.css.map": "/static/css/4.f8ac3883.chunk.css.map",
|
||||
"static/css/main.a0664ea6.chunk.css.map": "/static/css/main.a0664ea6.chunk.css.map",
|
||||
"static/css/main.61ecfb0d.chunk.css.map": "/static/css/main.61ecfb0d.chunk.css.map",
|
||||
"static/js/2.ebe1f792.chunk.js.LICENSE.txt": "/static/js/2.ebe1f792.chunk.js.LICENSE.txt",
|
||||
"static/media/ClusterIcon.f85713df.svg": "/static/media/ClusterIcon.f85713df.svg",
|
||||
"static/media/DepositIcon.9688e406.svg": "/static/media/DepositIcon.9688e406.svg"
|
||||
@ -44,7 +44,7 @@
|
||||
"entrypoints": [
|
||||
"static/js/runtime-main.83ebcb38.js",
|
||||
"static/js/2.ebe1f792.chunk.js",
|
||||
"static/css/main.a0664ea6.chunk.css",
|
||||
"static/js/main.02d15bac.chunk.js"
|
||||
"static/css/main.61ecfb0d.chunk.css",
|
||||
"static/js/main.2493f2fa.chunk.js"
|
||||
]
|
||||
}
|
@ -1 +1 @@
|
||||
<!doctype html><html lang="ru"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="white"/><meta name="theme-color" media="(prefers-color-scheme: light)" content="white"/><meta name="theme-color" media="(prefers-color-scheme: dark)" content="black"/><meta name="description" content="Онлайн мониторинг процесса бурения в реальном времени в офисе заказчика"/><link rel="manifest" href="/manifest.json"/><title>АСБ Vision</title><link href="/static/css/main.a0664ea6.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(e){function t(t){for(var n,o,u=t[0],f=t[1],i=t[2],l=0,d=[];l<u.length;l++)o=u[l],Object.prototype.hasOwnProperty.call(a,o)&&a[o]&&d.push(a[o][0]),a[o]=0;for(n in f)Object.prototype.hasOwnProperty.call(f,n)&&(e[n]=f[n]);for(s&&s(t);d.length;)d.shift()();return c.push.apply(c,i||[]),r()}function r(){for(var e,t=0;t<c.length;t++){for(var r=c[t],n=!0,o=1;o<r.length;o++){var f=r[o];0!==a[f]&&(n=!1)}n&&(c.splice(t--,1),e=u(u.s=r[0]))}return e}var n={},o={1:0},a={1:0},c=[];function u(t){if(n[t])return n[t].exports;var r=n[t]={i:t,l:!1,exports:{}};return e[t].call(r.exports,r,r.exports,u),r.l=!0,r.exports}u.e=function(e){var t=[];o[e]?t.push(o[e]):0!==o[e]&&{3:1,4:1}[e]&&t.push(o[e]=new Promise((function(t,r){for(var n="static/css/"+({}[e]||e)+"."+{3:"f8ac3883",4:"f8ac3883",5:"31d6cfe0",6:"31d6cfe0",7:"31d6cfe0",8:"31d6cfe0",9:"31d6cfe0",10:"31d6cfe0",11:"31d6cfe0",12:"31d6cfe0",13:"31d6cfe0",14:"31d6cfe0"}[e]+".chunk.css",a=u.p+n,c=document.getElementsByTagName("link"),f=0;f<c.length;f++){var i=(s=c[f]).getAttribute("data-href")||s.getAttribute("href");if("stylesheet"===s.rel&&(i===n||i===a))return t()}var l=document.getElementsByTagName("style");for(f=0;f<l.length;f++){var s;if((i=(s=l[f]).getAttribute("data-href"))===n||i===a)return t()}var d=document.createElement("link");d.rel="stylesheet",d.type="text/css",d.onload=t,d.onerror=function(t){var n=t&&t.target&&t.target.src||a,c=new Error("Loading CSS chunk "+e+" failed.\n("+n+")");c.code="CSS_CHUNK_LOAD_FAILED",c.request=n,delete o[e],d.parentNode.removeChild(d),r(c)},d.href=a,document.getElementsByTagName("head")[0].appendChild(d)})).then((function(){o[e]=0})));var r=a[e];if(0!==r)if(r)t.push(r[2]);else{var n=new Promise((function(t,n){r=a[e]=[t,n]}));t.push(r[2]=n);var c,f=document.createElement("script");f.charset="utf-8",f.timeout=120,u.nc&&f.setAttribute("nonce",u.nc),f.src=function(e){return u.p+"static/js/"+({}[e]||e)+"."+{3:"a763380a",4:"14deb3a9",5:"54daf1dd",6:"2f64a277",7:"8c90cea1",8:"6e937634",9:"3b35991a",10:"69527c71",11:"f8320c6a",12:"7a9654fd",13:"35247644",14:"0f147158"}[e]+".chunk.js"}(e);var i=new Error;c=function(t){f.onerror=f.onload=null,clearTimeout(l);var r=a[e];if(0!==r){if(r){var n=t&&("load"===t.type?"missing":t.type),o=t&&t.target&&t.target.src;i.message="Loading chunk "+e+" failed.\n("+n+": "+o+")",i.name="ChunkLoadError",i.type=n,i.request=o,r[1](i)}a[e]=void 0}};var l=setTimeout((function(){c({type:"timeout",target:f})}),12e4);f.onerror=f.onload=c,document.head.appendChild(f)}return Promise.all(t)},u.m=e,u.c=n,u.d=function(e,t,r){u.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},u.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},u.t=function(e,t){if(1&t&&(e=u(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(u.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)u.d(r,n,function(t){return e[t]}.bind(null,n));return r},u.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return u.d(t,"a",t),t},u.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},u.p="/",u.oe=function(e){throw console.error(e),e};var f=this.webpackJsonpasb_cloud_front_react=this.webpackJsonpasb_cloud_front_react||[],i=f.push.bind(f);f.push=t,f=f.slice();for(var l=0;l<f.length;l++)t(f[l]);var s=i;r()}([])</script><script src="/static/js/2.ebe1f792.chunk.js"></script><script src="/static/js/main.02d15bac.chunk.js"></script></body></html>
|
||||
<!doctype html><html lang="ru"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="white"/><meta name="theme-color" media="(prefers-color-scheme: light)" content="white"/><meta name="theme-color" media="(prefers-color-scheme: dark)" content="black"/><meta name="description" content="Онлайн мониторинг процесса бурения в реальном времени в офисе заказчика"/><title>АСБ Vision</title><script defer="defer" src="/vendors.8b2328d4.js"></script><script defer="defer" src="/main.d469f489.js"></script></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
|
Loading…
Reference in New Issue
Block a user