Merge branch 'dev' into feature/radius-targets-on-plan-trajectory

This commit is contained in:
on.nemtina 2023-05-31 16:55:24 +05:00
commit 5e008244b7
2 changed files with 31 additions and 16 deletions

View File

@ -85,6 +85,15 @@ namespace AsbCloudInfrastructure.Services.SAUB
if (telemetry is null)
throw new Exception($"Telemetry id: {idTelemetry} does not exist.");
if (telemetry.Well?.Timezone is not null)
{
telemetry.TimeZone = telemetry.Well.Timezone;
db.Telemetries.Upsert(telemetry);
db.SaveChanges();
DropTelemetryCache();
return telemetry.TimeZone.Adapt<SimpleTimezoneDto>();
}
if (telemetry.TimeZone is not null)
return telemetry.TimeZone.Adapt<SimpleTimezoneDto>();
@ -102,14 +111,6 @@ namespace AsbCloudInfrastructure.Services.SAUB
return telemetry.TimeZone.Adapt<SimpleTimezoneDto>();
}
if (telemetry.Well?.Timezone is not null)
{
telemetry.TimeZone = telemetry.Well.Timezone;
db.Telemetries.Upsert(telemetry);
db.SaveChanges();
DropTelemetryCache();
return telemetry.TimeZone.Adapt<SimpleTimezoneDto>();
}
throw new Exception($"Telemetry id: {idTelemetry} can't find timezone.");
}

View File

@ -1,17 +1,17 @@
using AsbCloudApp.Data.ProcessMap;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services;
using AsbCloudWebApi.SignalR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudWebApi.Controllers
{
/// <summary>
/// РТК
/// </summary>
@ -21,18 +21,23 @@ namespace AsbCloudWebApi.Controllers
public class ProcessMapController : CrudWellRelatedController<ProcessMapPlanDto, IProcessMapPlanRepository>
{
private readonly ITelemetryService telemetryService;
private readonly IHubContext<TelemetryHub> telemetryHubContext;
private readonly IProcessMapReportMakerService processMapReportService;
private readonly IProcessMapReportService processMapService;
private const string SirnalRMethodGetDataName = "UpdateProcessMap";
public ProcessMapController(
IWellService wellService,
IProcessMapPlanRepository repository,
IProcessMapReportMakerService processMapReportService,
IProcessMapReportService processMapService,
ITelemetryService telemetryService)
ITelemetryService telemetryService,
IHubContext<TelemetryHub> telemetryHubContext)
: base(wellService, repository)
{
this.telemetryService = telemetryService;
this.telemetryHubContext = telemetryHubContext;
this.processMapReportService = processMapReportService;
this.processMapService = processMapService;
@ -56,8 +61,7 @@ namespace AsbCloudWebApi.Controllers
if (idWell is null)
return BadRequest($"Wrong uid {uid}");
var dto = Enumerable.Empty<ProcessMapPlanDto>();
return Ok(dto);
throw new NotImplementedException();
}
/// <summary>
@ -136,7 +140,9 @@ namespace AsbCloudWebApi.Controllers
public override async Task<ActionResult<int>> InsertAsync([FromBody] ProcessMapPlanDto value, CancellationToken token)
{
value.IdUser = User.GetUserId() ?? -1;
return await base.InsertAsync(value, token);
var result = await base.InsertAsync(value, token);
await NotifyUsersBySignalR(value.IdWell, token);
return result;
}
/// <summary>
@ -149,8 +155,16 @@ namespace AsbCloudWebApi.Controllers
public override async Task<ActionResult<int>> UpdateAsync([FromBody] ProcessMapPlanDto value, CancellationToken token)
{
value.IdUser = User.GetUserId() ?? -1;
return await base.UpdateAsync(value, token);
var result = await base.UpdateAsync(value, token);
await NotifyUsersBySignalR(value.IdWell, token);
return result;
}
private async Task NotifyUsersBySignalR(int idWell, CancellationToken token)
{
var dtos = await service.GetAllAsync(idWell, null, token);
_ = Task.Run(() => telemetryHubContext.Clients.Group($"well_{idWell}")
.SendAsync(SirnalRMethodGetDataName, dtos), CancellationToken.None);
}
}
}