|
|
|
@ -206,23 +206,47 @@ namespace IoTCenter.Controllers
|
|
|
|
|
|
|
|
|
|
public IActionResult AllPowerOn(string connectionId, string[] nodes)
|
|
|
|
|
{
|
|
|
|
|
this.Power(connectionId, nodes, "On");
|
|
|
|
|
this.Power(connectionId, nodes, "On", o => o.Name.Contains("开关") || o.Name.Contains("插座"));
|
|
|
|
|
return Json(ApiResponse.AsyncSuccess());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult AllPowerOff(string connectionId, string[] nodes)
|
|
|
|
|
{
|
|
|
|
|
this.Power(connectionId, nodes, "Off");
|
|
|
|
|
this.Power(connectionId, nodes, "Off", o => o.Name.Contains("开关") || o.Name.Contains("插座"));
|
|
|
|
|
return Json(ApiResponse.AsyncSuccess());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Power(string connectionId, string[] nodes, string command)
|
|
|
|
|
public IActionResult AllSwitchOn(string connectionId, string[] nodes)
|
|
|
|
|
{
|
|
|
|
|
this.Power(connectionId, nodes, "On", o => o.Name.Contains("开关"));
|
|
|
|
|
return Json(ApiResponse.AsyncSuccess());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult AllSwitchOff(string connectionId, string[] nodes)
|
|
|
|
|
{
|
|
|
|
|
this.Power(connectionId, nodes, "Off", o => o.Name.Contains("开关"));
|
|
|
|
|
return Json(ApiResponse.AsyncSuccess());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult AllSocketOn(string connectionId, string[] nodes)
|
|
|
|
|
{
|
|
|
|
|
this.Power(connectionId, nodes, "On", o => o.Name.Contains("插座"));
|
|
|
|
|
return Json(ApiResponse.AsyncSuccess());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult AllSocketOff(string connectionId, string[] nodes)
|
|
|
|
|
{
|
|
|
|
|
this.Power(connectionId, nodes, "Off", o => o.Name.Contains("插座"));
|
|
|
|
|
return Json(ApiResponse.AsyncSuccess());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Power(string connectionId, string[] nodes, string command, Func<Device, bool> func)
|
|
|
|
|
{
|
|
|
|
|
var devices = this._deviceRepo.ReadOnlyTable()
|
|
|
|
|
.Include(o => o.Node)
|
|
|
|
|
.Include(o => o.Product.Apis)
|
|
|
|
|
.Where(o => nodes.Contains(o.Node.Number))
|
|
|
|
|
.Where(o => o.Name.Contains("开关") || o.Name.Contains("插座"))
|
|
|
|
|
.Where(func)
|
|
|
|
|
.ToList();
|
|
|
|
|
foreach (var device in devices)
|
|
|
|
|
{
|
|
|
|
|