|
|
|
@ -417,40 +417,6 @@ namespace IoTCenter.Controllers
|
|
|
|
|
|
|
|
|
|
/************************************************************/
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
var url = this._configuration["influxdb:url"];
|
|
|
|
|
var usr = this._configuration["influxdb:usr"];
|
|
|
|
|
var pwd = this._configuration["influxdb:pwd"];
|
|
|
|
|
var dbName = "iot";
|
|
|
|
|
var measurementName = "data";
|
|
|
|
|
var list = new List<object>();
|
|
|
|
|
using (var client = new InfluxClient(new Uri(url), usr, pwd))
|
|
|
|
|
{
|
|
|
|
|
var fileds = String.Join(',', device.Data
|
|
|
|
|
.Where(o => o.Type == DeviceDataType.Int || o.Type == DeviceDataType.Float)
|
|
|
|
|
.Select(o => o.Key));
|
|
|
|
|
var query = $"select {fileds} from {measurementName} where time>now()-{time} and DeviceNumber = '{device.Number}' limit 10000";
|
|
|
|
|
var result = client.ReadAsync<DynamicInfluxRow>(dbName, query).Result;
|
|
|
|
|
var rows = result.Results.FirstOrDefault()?
|
|
|
|
|
.Series.FirstOrDefault()?
|
|
|
|
|
.Rows;
|
|
|
|
|
var labels = rows?.Select(o => o.Timestamp.Value).Select(o => o.ToString("MM-dd HH:mm:ss")).ToList() ?? new List<string>();
|
|
|
|
|
foreach (var data in device.Data.Where(o => o.Type == DeviceDataType.Int || o.Type == DeviceDataType.Float))
|
|
|
|
|
{
|
|
|
|
|
list.Add(new
|
|
|
|
|
{
|
|
|
|
|
id = data.Key,
|
|
|
|
|
label = data.Name,
|
|
|
|
|
labels,
|
|
|
|
|
data = rows?.Select(o => o.GetField(data.Key)).ToList() ?? new List<object>()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Json(list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult AllPowerOn(string connectionId, string[] nodes)
|
|
|
|
|
{
|
|
|
|
|
this.Power(connectionId, nodes, "On", o => o.Name.Contains("开关") || o.Name.Contains("插座"));
|
|
|
|
@ -465,25 +431,7 @@ namespace IoTCenter.Controllers
|
|
|
|
|
|
|
|
|
|
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 AllSwitch3On(string connectionId, string[] nodes)
|
|
|
|
|
{
|
|
|
|
|
this.Power(connectionId, nodes, "On", o => o.Name.Contains("三路开关"));
|
|
|
|
|
return Json(ApiResponse.AsyncSuccess());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult AllSwitch3Off(string connectionId, string[] nodes)
|
|
|
|
|
{
|
|
|
|
|
this.Power(connectionId, nodes, "Off", o => o.Name.Contains("三路开关"));
|
|
|
|
|
this.Power(connectionId, nodes, "On", o => o.Name.Contains("开关"));
|
|
|
|
|
return Json(ApiResponse.AsyncSuccess());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -499,54 +447,6 @@ namespace IoTCenter.Controllers
|
|
|
|
|
return Json(ApiResponse.AsyncSuccess());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult NodePowerOn(string connectionId, string node)
|
|
|
|
|
{
|
|
|
|
|
this.Power(connectionId, new string[] { node }, "On", o => o.Name.Contains("开关") || o.Name.Contains("插座"));
|
|
|
|
|
return Json(ApiResponse.AsyncSuccess());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult NodePowerOff(string connectionId, string node)
|
|
|
|
|
{
|
|
|
|
|
this.Power(connectionId, new string[] { node }, "Off", o => o.Name.Contains("开关") || o.Name.Contains("插座"));
|
|
|
|
|
return Json(ApiResponse.AsyncSuccess());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult NodeSwitchOn(string connectionId, string node)
|
|
|
|
|
{
|
|
|
|
|
this.Power(connectionId, new string[] { node }, "On", o => o.Name.Contains("一路开关"));
|
|
|
|
|
return Json(ApiResponse.AsyncSuccess());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult NodeSwitchOff(string connectionId, string node)
|
|
|
|
|
{
|
|
|
|
|
this.Power(connectionId, new string[] { node }, "Off", o => o.Name.Contains("一路开关"));
|
|
|
|
|
return Json(ApiResponse.AsyncSuccess());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult NodeSwitch3On(string connectionId, string node)
|
|
|
|
|
{
|
|
|
|
|
this.Power(connectionId, new string[] { node }, "On", o => o.Name.Contains("三路开关"));
|
|
|
|
|
return Json(ApiResponse.AsyncSuccess());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult NodeSwitch3Off(string connectionId, string node)
|
|
|
|
|
{
|
|
|
|
|
this.Power(connectionId, new string[] { node }, "Off", o => o.Name.Contains("三路开关"));
|
|
|
|
|
return Json(ApiResponse.AsyncSuccess());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult NodeSocketOn(string connectionId, string node)
|
|
|
|
|
{
|
|
|
|
|
this.Power(connectionId, new string[] { node }, "On", o => o.Name.Contains("插座"));
|
|
|
|
|
return Json(ApiResponse.AsyncSuccess());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IActionResult NodeSocketOff(string connectionId, string node)
|
|
|
|
|
{
|
|
|
|
|
this.Power(connectionId, new string[] { node }, "Off", o => o.Name.Contains("插座"));
|
|
|
|
|
return Json(ApiResponse.AsyncSuccess());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:不捕获常规异常类型", Justification = "<挂起>")]
|
|
|
|
|
private void Power(string connectionId, string[] nodes, string command, Func<Device, bool> func)
|
|
|
|
|
{
|
|
|
|
|