Former-commit-id: 13d9d17fec7aeeb3249787551eaab3cfea0ff122
TangShanKaiPing
wanggang 6 years ago
parent 86d23573a9
commit 400ba613c1

@ -8,7 +8,8 @@
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>10.0.20506</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<RootNamespace></RootNamespace>
<RootNamespace>
</RootNamespace>
<ProjectGuid>{EF6565BD-C12A-AF2F-9766-E75AAE388FD9}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
@ -336,6 +337,91 @@
<Compile Include="Assets\UniWebView\Script\UniWebViewTransitionEdge.cs" />
<None Include="Assets\StreamingAssets\haarcascade_frontalface_alt.xml" />
<None Include="Assets\StreamingAssets\lbpcascade_frontalface.xml" />
<None Include="Assets\StreamingAssets\wwwroot\css.meta" />
<None Include="Assets\StreamingAssets\wwwroot\css\app.css.meta" />
<None Include="Assets\StreamingAssets\wwwroot\css\framework7-icons.css.meta" />
<None Include="Assets\StreamingAssets\wwwroot\fonts.meta" />
<None Include="Assets\StreamingAssets\wwwroot\fonts\Framework7Icons-Regular.eot" />
<None Include="Assets\StreamingAssets\wwwroot\fonts\Framework7Icons-Regular.eot.meta" />
<None Include="Assets\StreamingAssets\wwwroot\fonts\Framework7Icons-Regular.ttf" />
<None Include="Assets\StreamingAssets\wwwroot\fonts\Framework7Icons-Regular.ttf.meta" />
<None Include="Assets\StreamingAssets\wwwroot\fonts\Framework7Icons-Regular.woff" />
<None Include="Assets\StreamingAssets\wwwroot\fonts\Framework7Icons-Regular.woff.meta" />
<None Include="Assets\StreamingAssets\wwwroot\fonts\Framework7Icons-Regular.woff2" />
<None Include="Assets\StreamingAssets\wwwroot\fonts\Framework7Icons-Regular.woff2.meta" />
<None Include="Assets\StreamingAssets\wwwroot\fonts\MaterialIcons-Regular.eot" />
<None Include="Assets\StreamingAssets\wwwroot\fonts\MaterialIcons-Regular.eot.meta" />
<None Include="Assets\StreamingAssets\wwwroot\fonts\MaterialIcons-Regular.ttf" />
<None Include="Assets\StreamingAssets\wwwroot\fonts\MaterialIcons-Regular.ttf.meta" />
<None Include="Assets\StreamingAssets\wwwroot\fonts\MaterialIcons-Regular.woff" />
<None Include="Assets\StreamingAssets\wwwroot\fonts\MaterialIcons-Regular.woff.meta" />
<None Include="Assets\StreamingAssets\wwwroot\fonts\MaterialIcons-Regular.woff2" />
<None Include="Assets\StreamingAssets\wwwroot\fonts\MaterialIcons-Regular.woff2.meta" />
<None Include="Assets\StreamingAssets\wwwroot\images.meta" />
<None Include="Assets\StreamingAssets\wwwroot\images\alarm.png.meta" />
<None Include="Assets\StreamingAssets\wwwroot\images\ap.png.meta" />
<None Include="Assets\StreamingAssets\wwwroot\images\back.png.meta" />
<None Include="Assets\StreamingAssets\wwwroot\images\camera.png.meta" />
<None Include="Assets\StreamingAssets\wwwroot\images\co2.png.meta" />
<None Include="Assets\StreamingAssets\wwwroot\images\control.png.meta" />
<None Include="Assets\StreamingAssets\wwwroot\images\curtain.png.meta" />
<None Include="Assets\StreamingAssets\wwwroot\images\door.png.meta" />
<None Include="Assets\StreamingAssets\wwwroot\images\down.png.meta" />
<None Include="Assets\StreamingAssets\wwwroot\images\humidity.png.meta" />
<None Include="Assets\StreamingAssets\wwwroot\images\left.png.meta" />
<None Include="Assets\StreamingAssets\wwwroot\images\light.png.meta" />
<None Include="Assets\StreamingAssets\wwwroot\images\mute.png.meta" />
<None Include="Assets\StreamingAssets\wwwroot\images\pc.png.meta" />
<None Include="Assets\StreamingAssets\wwwroot\images\pm25.png.meta" />
<None Include="Assets\StreamingAssets\wwwroot\images\right.png.meta" />
<None Include="Assets\StreamingAssets\wwwroot\images\socket.png.meta" />
<None Include="Assets\StreamingAssets\wwwroot\images\sp.png.meta" />
<None Include="Assets\StreamingAssets\wwwroot\images\stop.png.meta" />
<None Include="Assets\StreamingAssets\wwwroot\images\switch.png.meta" />
<None Include="Assets\StreamingAssets\wwwroot\images\up.png.meta" />
<None Include="Assets\StreamingAssets\wwwroot\images\volume.png.meta" />
<None Include="Assets\StreamingAssets\wwwroot\images\zoomin.png.meta" />
<None Include="Assets\StreamingAssets\wwwroot\images\zoomout.png.meta" />
<None Include="Assets\StreamingAssets\wwwroot\index.html.meta" />
<None Include="Assets\StreamingAssets\wwwroot\js.meta" />
<None Include="Assets\StreamingAssets\wwwroot\js\app.js.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\Chart.js.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\Chart.js\Chart.bundle.min.js.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\dayjs.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\dayjs\dayjs.min.js.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\flv.js.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\flv.js\flv.min.js.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\framework7.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\framework7\css.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\framework7\css\framework7.bundle.min.css.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\framework7\js.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\framework7\js\framework7-vue.bundle.min.js.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\framework7\js\framework7.bundle.min.js.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\jquery.ajax.unobtrusive.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\jquery.ajax.unobtrusive\jquery.unobtrusive-ajax.min.js.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\jquery.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\jquery.validation.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\jquery.validation.unobtrusive.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\jquery.validation.unobtrusive\jquery.validate.unobtrusive.min.js.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\jquery.validation\jquery.validate.min.js.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\jquery.validation\localization.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\jquery.validation\localization\messages_zh.min.js.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\jquery\jquery.min.js.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\lodash.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\lodash\lodash.min.js.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\mobile.detect.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\mobile.detect\mobile-detect.min.js.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\signalr.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\signalr\signalr.min.js.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\URI.js.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\URI.js\URI.min.js.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\vue.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\vue\vue.min.js.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\weui.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\weui\example.css.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\weui\weui.min.css.meta" />
<None Include="Assets\StreamingAssets\wwwroot\lib\weui\weui.min.js.meta" />
<None Include="Assets\UniversalMediaPlayer\Shaders\UMP-TransparentCanvas.shader" />
<None Include="Assets\OpenCVForUnity\Plugins\macOS\opencvforunity.bundle\Contents\Resources\gl3w\readme.txt" />
<None Include="Assets\UniversalMediaPlayer\Shaders\UMP-QuadrantCanvas(Linear).shader" />
@ -921,6 +1007,56 @@
<HintPath>D:/ProgramFiles/Unity/2018.3.14f1/Editor/Data/NetStandard/compat/2.0.0/shims/netfx/System.Xml.Serialization.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Content Include="Assets\StreamingAssets\wwwroot\css\app.css" />
<Content Include="Assets\StreamingAssets\wwwroot\css\framework7-icons.css" />
<Content Include="Assets\StreamingAssets\wwwroot\images\alarm.png" />
<Content Include="Assets\StreamingAssets\wwwroot\images\ap.png" />
<Content Include="Assets\StreamingAssets\wwwroot\images\back.png" />
<Content Include="Assets\StreamingAssets\wwwroot\images\camera.png" />
<Content Include="Assets\StreamingAssets\wwwroot\images\co2.png" />
<Content Include="Assets\StreamingAssets\wwwroot\images\control.png" />
<Content Include="Assets\StreamingAssets\wwwroot\images\curtain.png" />
<Content Include="Assets\StreamingAssets\wwwroot\images\door.png" />
<Content Include="Assets\StreamingAssets\wwwroot\images\down.png" />
<Content Include="Assets\StreamingAssets\wwwroot\images\humidity.png" />
<Content Include="Assets\StreamingAssets\wwwroot\images\left.png" />
<Content Include="Assets\StreamingAssets\wwwroot\images\light.png" />
<Content Include="Assets\StreamingAssets\wwwroot\images\mute.png" />
<Content Include="Assets\StreamingAssets\wwwroot\images\pc.png" />
<Content Include="Assets\StreamingAssets\wwwroot\images\pm25.png" />
<Content Include="Assets\StreamingAssets\wwwroot\images\right.png" />
<Content Include="Assets\StreamingAssets\wwwroot\images\socket.png" />
<Content Include="Assets\StreamingAssets\wwwroot\images\sp.png" />
<Content Include="Assets\StreamingAssets\wwwroot\images\stop.png" />
<Content Include="Assets\StreamingAssets\wwwroot\images\switch.png" />
<Content Include="Assets\StreamingAssets\wwwroot\images\up.png" />
<Content Include="Assets\StreamingAssets\wwwroot\images\volume.png" />
<Content Include="Assets\StreamingAssets\wwwroot\images\zoomin.png" />
<Content Include="Assets\StreamingAssets\wwwroot\images\zoomout.png" />
<Content Include="Assets\StreamingAssets\wwwroot\index.html" />
<Content Include="Assets\StreamingAssets\wwwroot\js\app.js" />
<Content Include="Assets\StreamingAssets\wwwroot\lib\Chart.js\Chart.bundle.min.js" />
<Content Include="Assets\StreamingAssets\wwwroot\lib\dayjs\dayjs.min.js" />
<Content Include="Assets\StreamingAssets\wwwroot\lib\flv.js\flv.min.js" />
<Content Include="Assets\StreamingAssets\wwwroot\lib\framework7\css\framework7.bundle.min.css" />
<Content Include="Assets\StreamingAssets\wwwroot\lib\framework7\js\framework7-vue.bundle.min.js" />
<Content Include="Assets\StreamingAssets\wwwroot\lib\framework7\js\framework7.bundle.min.js" />
<Content Include="Assets\StreamingAssets\wwwroot\lib\jquery.ajax.unobtrusive\jquery.unobtrusive-ajax.min.js" />
<Content Include="Assets\StreamingAssets\wwwroot\lib\jquery.validation.unobtrusive\jquery.validate.unobtrusive.min.js" />
<Content Include="Assets\StreamingAssets\wwwroot\lib\jquery.validation\jquery.validate.min.js" />
<Content Include="Assets\StreamingAssets\wwwroot\lib\jquery.validation\localization\messages_zh.min.js" />
<Content Include="Assets\StreamingAssets\wwwroot\lib\jquery\jquery.min.js" />
<Content Include="Assets\StreamingAssets\wwwroot\lib\lodash\lodash.min.js" />
<Content Include="Assets\StreamingAssets\wwwroot\lib\mobile.detect\mobile-detect.min.js" />
<Content Include="Assets\StreamingAssets\wwwroot\lib\signalr\signalr.min.js" />
<Content Include="Assets\StreamingAssets\wwwroot\lib\URI.js\URI.min.js" />
<Content Include="Assets\StreamingAssets\wwwroot\lib\vue\vue.min.js" />
<Content Include="Assets\StreamingAssets\wwwroot\lib\weui\example.css" />
<Content Include="Assets\StreamingAssets\wwwroot\lib\weui\weui.min.css" />
<Content Include="Assets\StreamingAssets\wwwroot\lib\weui\weui.min.js" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="GenerateTargetFrameworkMonikerAttribute" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ProjectFiles</ProjectView>
<ProjectView>ShowAllFiles</ProjectView>
</PropertyGroup>
</Project>

@ -679,7 +679,6 @@
</div>
</div>
</template>
<template v-if="getDevices('串口控制器').length">
<div class="block-title">串口控制器</div>
<div class="block block-strong">

@ -1,162 +1,164 @@
//using Application.Domain.Entities;
//using Application.Models;
//using Application.Services;
//using Infrastructure.Data;
//using Infrastructure.Extensions;
//using Infrastructure.Jwt;
//using IoTShared;
//using Microsoft.AspNetCore.Authorization;
//using Microsoft.AspNetCore.Mvc;
//using Microsoft.AspNetCore.SignalR;
//using Microsoft.EntityFrameworkCore;
//using Microsoft.Extensions.Configuration;
//using Newtonsoft.Json;
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using Vibrant.InfluxDB.Client;
//using Vibrant.InfluxDB.Client.Rows;
using Application.Domain.Entities;
using Application.Models;
using Application.Services;
using Infrastructure.Data;
using Infrastructure.Extensions;
using Infrastructure.Jwt;
using IoTShared;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using Vibrant.InfluxDB.Client;
using Vibrant.InfluxDB.Client.Rows;
//namespace IoTCenter.Controllers
//{
// public class AppController : Controller
// {
// private readonly IConfiguration _configuration;
// private readonly IJwtHelper _jwtHelper;
// private readonly IRepository<Node> _nodeRepo;
// private readonly IRepository<Device> _deviceRepo;
// private readonly IHubContext<PageHub> _pageHubContext;
namespace IoTCenter.Controllers
{
public class AppController : Controller
{
private readonly IConfiguration _configuration;
private readonly IJwtHelper _jwtHelper;
private readonly IRepository<Node> _nodeRepo;
private readonly IRepository<Device> _deviceRepo;
private readonly IHubContext<PageHub> _pageHubContext;
// public AppController(IConfiguration configuration,
// IJwtHelper jwtHelper,
// IRepository<Node> nodeRepo,
// IRepository<Device> deviceRepo,
// IHubContext<PageHub> pageHubContext)
// {
// this._configuration = configuration;
// this._jwtHelper = jwtHelper;
// this._nodeRepo = nodeRepo;
// this._deviceRepo = deviceRepo;
// this._pageHubContext = pageHubContext;
// }
public AppController(IConfiguration configuration,
IJwtHelper jwtHelper,
IRepository<Node> nodeRepo,
IRepository<Device> deviceRepo,
IHubContext<PageHub> pageHubContext)
{
this._configuration = configuration;
this._jwtHelper = jwtHelper;
this._nodeRepo = nodeRepo;
this._deviceRepo = deviceRepo;
this._pageHubContext = pageHubContext;
}
// [Authorize]
// public IActionResult Index()
// {
// return View();
// }
[Authorize]
public IActionResult Index()
{
return View();
}
// public IActionResult GetNodes(string token)
// {
// var userName = this._jwtHelper.GetPayload(token)["UserName"].ToString();
// var model = this._nodeRepo.ReadOnlyTable()
// .Select(o => new { o.Id, o.Number, o.Name, o.DisplayOrder, Count = o.Devices.Count })
// .ToList();
// return Json(model);
// }
public IActionResult GetNodes(string token)
{
var userName = this._jwtHelper.GetPayload(token)["UserName"].ToString();
var model = this._nodeRepo.ReadOnlyTable()
.Select(o => new { o.Id, o.Number, o.Name, o.DisplayOrder, Count = o.Devices.Count })
.ToList();
return Json(model);
}
// public IActionResult GetNode(string token, string number)
// {
// var userName = this._jwtHelper.GetPayload(token)["UserName"].ToString();
// var model = this._nodeRepo.ReadOnlyTable()
// .Include(o => o.Sences)
// .Include(o => o.Devices).ThenInclude(o => o.Data)
// .FirstOrDefault(o => o.Number == number);
// return Json(model, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
// }
public IActionResult GetNode(string token, string number)
{
var userName = this._jwtHelper.GetPayload(token)["UserName"].ToString();
var model = this._nodeRepo.ReadOnlyTable()
.Include(o => o.Scenes)
.Include(o => o.Devices).ThenInclude(o => o.Data)
.FirstOrDefault(o => o.Number == number);
return Json(model, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
}
// public IActionResult GetDevice(string token, string number)
// {
// var userName = this._jwtHelper.GetPayload(token)["UserName"].ToString();
// var model = this._deviceRepo.ReadOnlyTable()
// .Include(o => o.Data)
// .Include(o => o.Apis).ThenInclude(o => o.Parameters)
// .FirstOrDefault(o => o.Number == number);
// return Json(model, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
// }
public IActionResult GetDevice(string token, string number)
{
var userName = this._jwtHelper.GetPayload(token)["UserName"].ToString();
var model = this._deviceRepo.ReadOnlyTable()
.Include(o => o.Data)
//.Include(o => o.Apis).ThenInclude(o => o.Parameters)
.FirstOrDefault(o => o.Number == number);
return Json(model, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
}
// public IActionResult Exec(string connectionId, string node, string cmd, Guid id)
// {
// try
// {
// var query = string.Empty;
// foreach (var item in Request.Query.Where(o => o.Key != "node" && o.Key != "cmd" && !o.Key.StartsWith("id")))
// {
// query = query.SetParam(item.Key, item.Value);
// }
// this._pageHubContext.Clients.Group(node).SendAsync(nameof(INodeService.Exec), connectionId, id, cmd, query);
// return Json(ApiResponse.AsyncSuccess());
// }
// catch (Exception ex)
// {
// ex.PrintStack();
// return Json(ApiResponse.Error(ex));
// }
// }
public IActionResult Exec(string connectionId, string node, string cmd, Guid id)
{
try
{
var query = string.Empty;
foreach (var item in Request.Query.Where(o => o.Key != "node" && o.Key != "cmd" && !o.Key.StartsWith("id")))
{
query = query.SetParam(item.Key, item.Value);
}
this._pageHubContext.Clients.Group(node).SendAsync(nameof(INodeService.Exec), connectionId, id, cmd, query);
return Json(ApiResponse.AsyncSuccess());
}
catch (Exception ex)
{
ex.PrintStack();
return Json(ApiResponse.Error(ex));
}
}
// public IActionResult ExecAll(string connectionId, string node, string cmd, List<Guid> id)
// {
// try
// {
// var query = string.Empty;
// foreach (var item in Request.Query.Where(o => o.Key != "node" && o.Key != "cmd" && !o.Key.StartsWith("id[")))
// {
// query = query.SetParam(item.Key, item.Value);
// }
// this._pageHubContext.Clients.Group(node).SendAsync(nameof(INodeService.ExecAll), connectionId, id, cmd, query);
// return Json(ApiResponse.AsyncSuccess());
// }
// catch (Exception ex)
// {
// ex.PrintStack();
// return Json(ApiResponse.Error(ex));
// }
// }
public IActionResult ExecAll(string connectionId, string node, string cmd, List<Guid> id)
{
try
{
var query = string.Empty;
foreach (var item in Request.Query.Where(o => o.Key != "node" && o.Key != "cmd" && !o.Key.StartsWith("id[")))
{
query = query.SetParam(item.Key, item.Value);
}
this._pageHubContext.Clients.Group(node).SendAsync(nameof(INodeService.ExecAll), connectionId, id, cmd, query);
return Json(ApiResponse.AsyncSuccess());
}
catch (Exception ex)
{
ex.PrintStack();
return Json(ApiResponse.Error(ex));
}
}
// public IActionResult Sence(string connectionId, string node, Guid id)
// {
// try
// {
// this._pageHubContext.Clients.Group(node).SendAsync(nameof(INodeService.Sence), connectionId, id);
// return Json(ApiResponse.AsyncSuccess());
// }
// catch (Exception ex)
// {
// ex.PrintStack();
// return Json(ApiResponse.Error(ex));
// }
// }
public IActionResult Sence(string connectionId, string node, Guid id)
{
try
{
this._pageHubContext.Clients.Group(node).SendAsync(nameof(INodeService.Sence), connectionId, id);
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);
// 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 == "Int" || o.Type == "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 == "Int" || o.Type == "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 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.Long || 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.Long || 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);
}
}
}
Loading…
Cancel
Save