Add MQTT runtime control and device data pipeline
This commit is contained in:
1 parent
96d8309793
commit
8a0aa8f7cb
31 files changed
+30842
-20
No files matched your search
@@ -0,0 +1,66 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using HHWMS.Web.Models;
|
||||
using HHWMS.Web.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using WalkingTec.Mvvm.Core;
|
||||
using WalkingTec.Mvvm.Mvc;
|
||||
|
||||
namespace HHWMS.Web.Areas.System.Controllers
|
||||
{
|
||||
[Area("System")]
|
||||
[Route("api/mqtt")]
|
||||
[ApiController]
|
||||
public class MqttRuntimeController : BaseController
|
||||
{
|
||||
private readonly IUnitWork _unitwork;
|
||||
private readonly MqttRuntimeState _runtimeState;
|
||||
private readonly MqttRuntimeStateRefresher _runtimeStateRefresher;
|
||||
|
||||
public MqttRuntimeController(
|
||||
IUnitWork unitwork,
|
||||
MqttRuntimeState runtimeState,
|
||||
MqttRuntimeStateRefresher runtimeStateRefresher)
|
||||
{
|
||||
_unitwork = unitwork;
|
||||
_runtimeState = runtimeState;
|
||||
_runtimeStateRefresher = runtimeStateRefresher;
|
||||
}
|
||||
|
||||
[HttpGet("status")]
|
||||
public IActionResult Status()
|
||||
{
|
||||
var enabledSubscriptionCount = _unitwork.GetCount<MqttSubscription>(x => x.IsEnabled);
|
||||
return Ok(new
|
||||
{
|
||||
enabled = _runtimeState.Enabled,
|
||||
enabledSubscriptionCount,
|
||||
lastChangedAt = _runtimeState.LastChangedAt,
|
||||
lastChangedBy = _runtimeState.LastChangedBy
|
||||
});
|
||||
}
|
||||
|
||||
[HttpPost("refresh")]
|
||||
public async Task<IActionResult> Refresh()
|
||||
{
|
||||
await _runtimeStateRefresher.RefreshFromSubscriptionsAsync(Wtm?.LoginUserInfo?.ITCode, HttpContext.RequestAborted);
|
||||
return Status();
|
||||
}
|
||||
|
||||
[HttpPost("subscriptions/{id:int}/enabled")]
|
||||
public async Task<IActionResult> SetSubscriptionEnabled(int id, [FromQuery] bool enabled)
|
||||
{
|
||||
var subscription = _unitwork.Find<MqttSubscription>(x => x.ID == id).FirstOrDefault();
|
||||
if (subscription == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
subscription.IsEnabled = enabled;
|
||||
_unitwork.Update(subscription);
|
||||
|
||||
await _runtimeStateRefresher.RefreshFromSubscriptionsAsync(Wtm?.LoginUserInfo?.ITCode, HttpContext.RequestAborted);
|
||||
return Status();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user