|
|
|
@ -27,6 +27,8 @@ namespace IoTCenter.Controllers
|
|
|
|
|
private readonly IJwtHelper _jwtHelper;
|
|
|
|
|
private readonly IRepository<Node> _nodeRepo;
|
|
|
|
|
private readonly IRepository<Scene> _sceneRepo;
|
|
|
|
|
private readonly IRepository<SceneCommand> _sceneCommandRepo;
|
|
|
|
|
private readonly IRepository<Command> _commandRepo;
|
|
|
|
|
private readonly IRepository<Device> _deviceRepo;
|
|
|
|
|
private readonly IRepository<LiveRecord> _liveRecordRepo;
|
|
|
|
|
private readonly IHubContext<IoTCenterHub> _hub;
|
|
|
|
@ -35,6 +37,8 @@ namespace IoTCenter.Controllers
|
|
|
|
|
IJwtHelper jwtHelper,
|
|
|
|
|
IRepository<Node> nodeRepo,
|
|
|
|
|
IRepository<Scene> sceneRepo,
|
|
|
|
|
IRepository<SceneCommand> sceneCommandRepo,
|
|
|
|
|
IRepository<Command> commandRepo,
|
|
|
|
|
IRepository<Device> deviceRepo,
|
|
|
|
|
IRepository<LiveRecord> liveRecordRepo,
|
|
|
|
|
IHubContext<IoTCenterHub> hub)
|
|
|
|
@ -43,6 +47,8 @@ namespace IoTCenter.Controllers
|
|
|
|
|
this._jwtHelper = jwtHelper;
|
|
|
|
|
this._nodeRepo = nodeRepo;
|
|
|
|
|
this._sceneRepo = sceneRepo;
|
|
|
|
|
this._sceneCommandRepo = sceneCommandRepo;
|
|
|
|
|
this._commandRepo = commandRepo;
|
|
|
|
|
this._deviceRepo = deviceRepo;
|
|
|
|
|
this._liveRecordRepo = liveRecordRepo;
|
|
|
|
|
this._hub = hub;
|
|
|
|
@ -74,6 +80,15 @@ namespace IoTCenter.Controllers
|
|
|
|
|
return Json(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult GetSceneList(string token)
|
|
|
|
|
{
|
|
|
|
|
var userName = this._jwtHelper.GetPayload(token)["UserName"].ToString();
|
|
|
|
|
var model = this._sceneRepo.ReadOnlyTable()
|
|
|
|
|
.Where(o => o.NodeId == null)
|
|
|
|
|
.ToList();
|
|
|
|
|
return Json(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult GetNode(string token, string number)
|
|
|
|
|
{
|
|
|
|
|
var userName = this._jwtHelper.GetPayload(token)["UserName"].ToString();
|
|
|
|
@ -81,6 +96,8 @@ namespace IoTCenter.Controllers
|
|
|
|
|
.Include(o => o.Scenes)
|
|
|
|
|
.Include(o => o.Devices)
|
|
|
|
|
.ThenInclude(o => o.Data)
|
|
|
|
|
.Include(o => o.Devices)
|
|
|
|
|
.ThenInclude(o => o.Commands)
|
|
|
|
|
.FirstOrDefault(o => o.Number == number);
|
|
|
|
|
return Json(model);
|
|
|
|
|
}
|
|
|
|
@ -157,6 +174,52 @@ namespace IoTCenter.Controllers
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:不捕获常规异常类型", Justification = "<挂起>")]
|
|
|
|
|
public IActionResult ExecGlobalScene(string connectionId, Guid id)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var commands = this._sceneCommandRepo.ReadOnlyTable()
|
|
|
|
|
.Include(o => o.Command).ThenInclude(o => o.Device).ThenInclude(o => o.Node)
|
|
|
|
|
.Where(o => o.SceneId == id)
|
|
|
|
|
.Select(o => o.Command)
|
|
|
|
|
.ToList();
|
|
|
|
|
foreach (var command in commands)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
this._hub.ServerToClient(command.Device.Node.Number, Methods.ExecCommand, command.Id, connectionId);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ex.PrintStack();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Json(ApiResponse.AsyncSuccess());
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ex.PrintStack();
|
|
|
|
|
return Json(ApiResponse.Error(ex));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:不捕获常规异常类型", Justification = "<挂起>")]
|
|
|
|
|
public IActionResult ExecCommand(string connectionId, Guid id)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var command = this._commandRepo.ReadOnlyTable().Include(o => o.Device).ThenInclude(o => o.Node).FirstOrDefault(o => o.Id == id);
|
|
|
|
|
this._hub.ServerToClient(command.Device.Node.Number, Methods.ExecCommand, command.Id, connectionId);
|
|
|
|
|
return Json(ApiResponse.AsyncSuccess());
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ex.PrintStack();
|
|
|
|
|
return Json(ApiResponse.Error(ex));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult Data(Guid id, string time = "10m")
|
|
|
|
|
{
|
|
|
|
|
var device = this._deviceRepo.ReadOnlyTable().Include(o => o.Node).Include(o => o.Data).FirstOrDefault(o => o.Id == id);
|
|
|
|
|