diff --git a/docs/物联网中心.EAP b/docs/物联网中心.EAP index a2f05173..322e3c07 100644 Binary files a/docs/物联网中心.EAP and b/docs/物联网中心.EAP differ diff --git a/docs/物联网中心.ldb b/docs/物联网中心.ldb deleted file mode 100644 index a0ee1012..00000000 Binary files a/docs/物联网中心.ldb and /dev/null differ diff --git a/docs/设计/原型.rp b/docs/设计/原型.rp index 85c7cd40..d4050424 100644 Binary files a/docs/设计/原型.rp and b/docs/设计/原型.rp differ diff --git a/docs/设计/物联网中心.EAP b/docs/设计/物联网中心.EAP index 0c39e11c..79cc6548 100644 Binary files a/docs/设计/物联网中心.EAP and b/docs/设计/物联网中心.EAP differ diff --git a/docs/设计/物联网中心.ldb b/docs/设计/物联网中心.ldb deleted file mode 100644 index a0ee1012..00000000 Binary files a/docs/设计/物联网中心.ldb and /dev/null differ diff --git a/projects/IoT/IoT.Shared/Application/Domain/Entities/Node.cs b/projects/IoT/IoT.Shared/Application/Domain/Entities/Node.cs index 5cdda649..3a0544cb 100644 --- a/projects/IoT/IoT.Shared/Application/Domain/Entities/Node.cs +++ b/projects/IoT/IoT.Shared/Application/Domain/Entities/Node.cs @@ -37,6 +37,9 @@ namespace Application.Domain.Entities [Display(Name = "禁用")] public bool Disabled { get; set; } + [Display(Name = "类型")] + public string Type { get; set; } + public List Devices { get; set; } = new List(); public List Scenes { get; set; } = new List(); } diff --git a/projects/IoT/IoT.Shared/Application/Models/EditNodeModel.cs b/projects/IoT/IoT.Shared/Application/Models/EditNodeModel.cs index 41cdbd5e..53826153 100644 --- a/projects/IoT/IoT.Shared/Application/Models/EditNodeModel.cs +++ b/projects/IoT/IoT.Shared/Application/Models/EditNodeModel.cs @@ -20,6 +20,9 @@ namespace Application.Models [Required(ErrorMessage = nameof(RequiredAttribute))] public string Icon { get; set; } + [Display(Name = "图片")] + public string Image { get; set; } + [Display(Name = "是否在线")] public bool IsOnline { get; set; } @@ -32,6 +35,12 @@ namespace Application.Models [Display(Name = "海拔")] public decimal Altitude { get; set; } + [Display(Name = "类型")] + public string Type { get; set; } + + [Display(Name = "标记")] + public string Tag { get; set; } + [Display(Name = "禁用")] public bool Disabled { get; set; } } diff --git a/projects/IoT/IoT.Shared/IoT.Shared.csproj b/projects/IoT/IoT.Shared/IoT.Shared.csproj index 71e5557d..9c380583 100644 --- a/projects/IoT/IoT.Shared/IoT.Shared.csproj +++ b/projects/IoT/IoT.Shared/IoT.Shared.csproj @@ -20,6 +20,7 @@   + diff --git a/projects/IoT/IoT.Shared/wwwroot/iot/classroom.jpg b/projects/IoT/IoT.Shared/wwwroot/iot/classroom.jpg new file mode 100644 index 00000000..568059da Binary files /dev/null and b/projects/IoT/IoT.Shared/wwwroot/iot/classroom.jpg differ diff --git a/projects/IoT/IoTNode/Startup.cs b/projects/IoT/IoTNode/Startup.cs index d4990862..da34a634 100644 --- a/projects/IoT/IoTNode/Startup.cs +++ b/projects/IoT/IoTNode/Startup.cs @@ -54,7 +54,9 @@ namespace IoTNode Name = $"ڵ{cpuid}", Number = cpuid, Icon = "classroom", - IsOnline = true + IsOnline = true, + Type = "ǻ۽", + Image = "/iot/classroom.jpg" }); dbContext.SaveChanges(); base.Seed(dbContext, serviceProvider, configuration); diff --git a/projects/IoTCenter/Controllers/AppController.cs b/projects/IoTCenter/Controllers/AppController.cs index 448e9e19..2c456019 100644 --- a/projects/IoTCenter/Controllers/AppController.cs +++ b/projects/IoTCenter/Controllers/AppController.cs @@ -53,10 +53,8 @@ namespace IoTCenter.Controllers public IActionResult GetNodeList(string token) { var userName = this._jwtHelper.GetPayload(token)["UserName"].ToString(); - var nodes = this._nodeRepo.ReadOnlyTable() + var model = this._nodeRepo.ReadOnlyTable() .Include(o => o.Scenes) - .ToList(); - var model = nodes .Select(o => new { o.Id, @@ -64,9 +62,9 @@ namespace IoTCenter.Controllers o.Name, o.DisplayOrder, o.Icon, - Image = this._deviceRepo.ReadOnlyTable().Include(d => d.Data).FirstOrDefault(c => c.Name == "摄像头" && c.Tag == "front")?.Data.FirstOrDefault(d => d.Key == "Snapshot")?.Value, - Scenes = o.Scenes.Where(s => s.Tag == "front"), - Count = this._deviceRepo.ReadOnlyTable().Where(d => d.NodeId == o.Id).Count() + o.Image, + o.Scenes, + Count = o.Devices.Count }) .ToList(); return Json(model); diff --git a/projects/IoTCenter/Controllers/HomeController.cs b/projects/IoTCenter/Controllers/HomeController.cs index 69729fe2..a02e13be 100644 --- a/projects/IoTCenter/Controllers/HomeController.cs +++ b/projects/IoTCenter/Controllers/HomeController.cs @@ -13,18 +13,79 @@ namespace IoTCenter.Controllers { private readonly IRepository _nodeRepo; private readonly IRepository _deviceRepo; + private readonly IRepository _dataRepo; + private readonly IRepository _categoryRepo; + private readonly IRepository _productRepo; - public HomeController(IRepository nodeRepo, IRepository deviceRepo) + public HomeController(IRepository nodeRepo, IRepository deviceRepo, IRepository dataRepo, IRepository categoryRepo, IRepository productRepo) { this._nodeRepo = nodeRepo; this._deviceRepo = deviceRepo; + this._dataRepo = dataRepo; + this._categoryRepo = categoryRepo; + this._productRepo = productRepo; } + [Authorize] public IActionResult Index() { return View(); } + public IActionResult GetNodeList() + { + var categorys = this._deviceRepo.ReadOnlyTable() + .GroupBy(o => o.Product.Category.Name) + .Select(g => new { g.Key, Count = g.Count() }); + + var nodes = this._nodeRepo.ReadOnlyTable() + .GroupBy(o => o.Type) + .Select(g => new { g.Key, Count = g.Count() }); + + var energy = this._dataRepo.ReadOnlyTable() + .Where(o => o.Key == "Electricity") + .Select(o => new + { + o.Device.Node.Name, + o.Value + }).ToList() + .Select(o => new + { + o.Name, + Value = Convert.ToDouble(o.Value) + }) + .GroupBy(o => o.Name) + .Select(g => new { g.Key, Sum = g.Sum(o => o.Value) }); + + var model = new + { + NodeChart = new + { + total = this._nodeRepo.ReadOnlyTable().Count(), + online = this._nodeRepo.ReadOnlyTable().Count(o => o.IsOnline), + offline = this._nodeRepo.ReadOnlyTable().Count(o => !o.IsOnline), + data = nodes.Select(o => o.Count), + labels = nodes.Select(o => o.Key) + }, + DeviceChart = new + { + total = this._deviceRepo.ReadOnlyTable().Count(), + online = this._deviceRepo.ReadOnlyTable().Count(o => o.IsOnline), + offline = this._deviceRepo.ReadOnlyTable().Count(o => !o.IsOnline), + data = categorys.Select(o => o.Count), + labels = categorys.Select(o => o.Key) + }, + EnergyChart = new + { + total = energy.Sum(o => o.Sum), + data = energy.Select(o => o.Sum), + labels = energy.Select(o => o.Key) + }, + Nodes = this._nodeRepo.ReadOnlyTable().Where(o => !o.Disabled).Include(o => o.Scenes).ToList() + }; + return Json(model, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); + } + //public IActionResult GetNodes() //{ // var model = this._nodeRepo.ReadOnlyTable() @@ -33,11 +94,21 @@ namespace IoTCenter.Controllers // return Json(model, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); //} - //public IActionResult Node(Guid id) - //{ - // var model = this._nodeRepo.ReadOnlyTable().FirstOrDefault(o => o.Id == id); - // return View(model); - //} + [Route("/Node")] + public IActionResult Node(string number) + { + return View(model: number); + } + + public IActionResult GetNode(string number) + { + 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 GetNode(Guid id) //{ diff --git a/projects/IoTCenter/IoTCenter.csproj b/projects/IoTCenter/IoTCenter.csproj index 145ead94..531ada5d 100644 --- a/projects/IoTCenter/IoTCenter.csproj +++ b/projects/IoTCenter/IoTCenter.csproj @@ -3,6 +3,14 @@ netcoreapp2.2 true + + + + + + + + diff --git a/projects/IoTCenter/Views/Home/Index.cshtml b/projects/IoTCenter/Views/Home/Index.cshtml index b0e6ef0d..e8a68587 100644 --- a/projects/IoTCenter/Views/Home/Index.cshtml +++ b/projects/IoTCenter/Views/Home/Index.cshtml @@ -1,1407 +1,164 @@ -@{ +@inject IConfiguration cfg +@{ Layout = null; } - + - - - - - - - - 首页 - - - + + + + + + + + + + + + + + + - - -
- - - - - -
- - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/projects/IoTCenter/Views/Home/Node.cshtml b/projects/IoTCenter/Views/Home/Node.cshtml new file mode 100644 index 00000000..4df02eea --- /dev/null +++ b/projects/IoTCenter/Views/Home/Node.cshtml @@ -0,0 +1,165 @@ +@model string +@inject IConfiguration cfg +@{ + Layout = null; +} + + + + + + + + + + + + + + + + + + + + @HtmlTitle | @cfg["name"] + + +
+
+ +
+ +
+
+
+
+
+
+
+
+
+ @Html.Raw(cfg["copyright"].Replace("{now}", DateTime.Now.Year.ToString())) +
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/projects/IoTCenter/wwwroot/home.default.html b/projects/IoTCenter/wwwroot/home.default.html new file mode 100644 index 00000000..75220bd5 --- /dev/null +++ b/projects/IoTCenter/wwwroot/home.default.html @@ -0,0 +1,162 @@ +
+
+
+
+
+ +
+ 节点:{{ViewModel.NodeChart.total}} 在线:{{ViewModel.NodeChart.online}} 离线:{{ViewModel.NodeChart.offline}} +
+
+
+ +
+ 设备:{{ViewModel.DeviceChart.total}} 在线:{{ViewModel.DeviceChart.online}} 离线:{{ViewModel.DeviceChart.offline}} +
+
+
+
+
+
+
+
+
+ +
+ 总电量:{{ViewModel.EnergyChart.total}} 千瓦时 +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+
+

{{node.Name}}

+
+ +
+
+
+ +
+ +
+
+
+ + \ No newline at end of file diff --git a/projects/IoTCenter/wwwroot/node.default.html b/projects/IoTCenter/wwwroot/node.default.html new file mode 100644 index 00000000..40e04e9d --- /dev/null +++ b/projects/IoTCenter/wwwroot/node.default.html @@ -0,0 +1,75 @@ +
+
+
+
+
+
+ 节点详情 +
+ + \ No newline at end of file