From b242a7b805213526bb449fb1d03c36b22732b97e Mon Sep 17 00:00:00 2001 From: wanggang <76527413@qq.com> Date: Thu, 18 Mar 2021 14:56:02 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E6=98=BE=E7=A4=BA=E5=92=8C?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E5=88=86=E7=A6=BB=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: 003803579fecd5439133a0fedad8d72ca6080d8e Former-commit-id: f1ff5eead9942195686e84d2c3047b727adfcf82 --- labs/LCDAUE800DDebug/Program.cs | 2 +- .../LiChuang/LCDAUE800DService.cs | 63 +++++++++++-------- projects/IoTNode/Services/IoTNodeClient.cs | 10 +-- projects/IoTNode/Startup.cs | 6 +- .../EventHandlers/StatisticEventHandler.cs | 56 ++++++++--------- projects/Platform/Views/Shared/_Layout.cshtml | 3 +- .../wwwroot/components/devices/collector.html | 58 +++++++++++++++++ projects/Platform/wwwroot/js/app.js | 8 ++- projects/Platform/wwwroot/js/site.js | 5 +- 9 files changed, 143 insertions(+), 68 deletions(-) create mode 100644 projects/Platform/wwwroot/components/devices/collector.html diff --git a/labs/LCDAUE800DDebug/Program.cs b/labs/LCDAUE800DDebug/Program.cs index 24efa7d9..8d10aae4 100644 --- a/labs/LCDAUE800DDebug/Program.cs +++ b/labs/LCDAUE800DDebug/Program.cs @@ -18,4 +18,4 @@ namespace ConsoleApp3 listener.Stop(); } } -} \ No newline at end of file +} diff --git a/projects/IoTNode/DeviceServices/LiChuang/LCDAUE800DService.cs b/projects/IoTNode/DeviceServices/LiChuang/LCDAUE800DService.cs index 40f406a8..1b1d061c 100644 --- a/projects/IoTNode/DeviceServices/LiChuang/LCDAUE800DService.cs +++ b/projects/IoTNode/DeviceServices/LiChuang/LCDAUE800DService.cs @@ -6,6 +6,7 @@ using IoT.Shared.Services; using Microsoft.AspNetCore.Hosting; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Globalization; @@ -99,10 +100,12 @@ namespace IoTNode.DeviceServices.LiChuang private CancellationToken _cancellationToken; private string _mac; + private readonly ILogger _logger; - public LCDAUE800DService(IServiceProvider applicationServices, IWebHostEnvironment env) + public LCDAUE800DService(IServiceProvider applicationServices, IWebHostEnvironment env, ILogger logger) : base(applicationServices, env) { + this._logger = logger; } public override Task StartAsync(CancellationToken cancellationToken) @@ -462,39 +465,45 @@ namespace IoTNode.DeviceServices.LiChuang var gateway_id = doc.SelectSingleNode("//gateway_id").InnerText.Trim(); var time = doc.SelectSingleNode("//time").InnerText.Trim(); - var meters = doc.SelectNodes("//meter"); - foreach (XmlNode meter in meters) + try { - var deviceNo = meter.SelectSingleNode("//functionex"); - var equipidex = deviceNo.Attributes["equipidex"].Value.Trim(); - var tpex = deviceNo.Attributes["tpex"].Value.Trim(); - var functions = meter.SelectNodes("//function"); - foreach (XmlNode function in functions) + var meters = doc.SelectNodes("//meter"); + foreach (XmlNode meter in meters) { - var key = function.Attributes["id"].Value.Trim(); - var name = Keys[key]; - var value = function.InnerText.Trim(); - this._env.Debug($"type:{type},time:{time},equipidex:{equipidex},item:{name},value:{value}"); - //add for iotnode start - if (!string.IsNullOrEmpty(this._mac)) + var deviceNo = meter.SelectSingleNode("//functionex"); + var equipidex = deviceNo.Attributes["equipidex"].Value.Trim(); + var tpex = deviceNo.Attributes["tpex"].Value.Trim(); + var functions = meter.SelectNodes("//function"); + foreach (XmlNode function in functions) { - var timestamp = (type == "report" ? DateTimeOffset.Now : DateTime.ParseExact(time, "yyyyMMddHHmmss", CultureInfo.InvariantCulture)).ToUnixTimeMilliseconds(); - using var scope = _applicationServices.CreateScope(); - var deviceRepo = scope.ServiceProvider.GetService>(); - var dataRepo = scope.ServiceProvider.GetService>(); - var deviceId = this.GetIoTDeviceId(this._mac); - if (deviceId.HasValue) + var key = function.Attributes["id"].Value.Trim(); + var name = Keys[key]; + var value = function.InnerText.Trim(); + this._logger.LogDebug($"type:{type},time:{time},equipidex:{equipidex},item:{name},value:{value}"); + //add for iotnode start + if (!string.IsNullOrEmpty(this._mac)) { - var dataKey = GetKey(equipidex); - var unit = this.GetUnit(name)?.ToString(); - var dataName = $"{dataKey.GetDisplayName():unit}"; - this.UpdateIoTData(deviceId.Value, dataKey, value, name: dataName, unit: unit); + var timestamp = (type == "report" ? DateTimeOffset.Now : DateTime.ParseExact(time, "yyyyMMddHHmmss", CultureInfo.InvariantCulture)).ToUnixTimeMilliseconds(); + using var scope = _applicationServices.CreateScope(); + var deviceRepo = scope.ServiceProvider.GetService>(); + var dataRepo = scope.ServiceProvider.GetService>(); + var deviceId = this.GetIoTDeviceId(this._mac); + if (deviceId.HasValue) + { + var dataKey = GetKey(key); + var unit = this.GetUnit(name)?.ToString(); + var dataName = $"{dataKey.GetDisplayName():unit}"; + this.UpdateIoTData(deviceId.Value, dataKey, value, name: dataName, unit: unit); + } } + //add for iotnode end } - - //add for iotnode end } } + catch (Exception ex) + { + this._logger.LogError(ex, ex.Message); + } //上传数据响应 var doc2 = new XmlDocument(); var xml2 = @$"{building_id}{gateway_id}report_ackpass"; @@ -504,7 +513,7 @@ namespace IoTNode.DeviceServices.LiChuang private DataKeys GetKey(string equipidex) { - var value = $"设备{equipidex}"; + var value = $"Device{equipidex}"; return Enum.Parse(value); } diff --git a/projects/IoTNode/Services/IoTNodeClient.cs b/projects/IoTNode/Services/IoTNodeClient.cs index a9f90be7..352d7088 100644 --- a/projects/IoTNode/Services/IoTNodeClient.cs +++ b/projects/IoTNode/Services/IoTNodeClient.cs @@ -73,7 +73,7 @@ namespace IoT.Shared.Services var enable = GetSetting("notify:enabled"); if (enable == "true") { - this._logger.LogDebug("notify is enabled"); + //this._logger.LogDebug("notify is enabled"); try { var host = this.GetSetting("notify:host"); @@ -99,10 +99,10 @@ namespace IoT.Shared.Services { this.ReConnect(null); } - else - { - this._logger.LogDebug($"connection has connected"); - } + //else + //{ + // this._logger.LogDebug($"connection has connected"); + //} } } catch (Exception ex) diff --git a/projects/IoTNode/Startup.cs b/projects/IoTNode/Startup.cs index 8661f8ce..21c05464 100644 --- a/projects/IoTNode/Startup.cs +++ b/projects/IoTNode/Startup.cs @@ -44,10 +44,10 @@ namespace IoTNode services.AddTransient(); if (Env.IsDevelopment()) { - //services.AddHostedService(o => o.GetService()); - //services.AddHostedService(o => o.GetService()); + services.AddHostedService(o => o.GetService()); + services.AddHostedService(o => o.GetService()); services.AddHostedService(o => o.GetService()); - //services.AddHostedService(o => o.GetService()); + services.AddHostedService(o => o.GetService()); } else { diff --git a/projects/Platform/EventHandlers/StatisticEventHandler.cs b/projects/Platform/EventHandlers/StatisticEventHandler.cs index 9c0755c3..413c88e1 100644 --- a/projects/Platform/EventHandlers/StatisticEventHandler.cs +++ b/projects/Platform/EventHandlers/StatisticEventHandler.cs @@ -1,32 +1,32 @@ -//using Application.Domain.Entities; -//using Infrastructure.Events; -//using Microsoft.AspNetCore.SignalR; -//using Platform.Services; +using Application.Domain.Entities; +using Infrastructure.Events; +using Microsoft.AspNetCore.SignalR; +using Platform.Services; -//namespace Platform.EventHandlers -//{ -// public class StatisticEventHandler : BaseEventHandler, -// IEventHander>, -// IEventHander>, -// IEventHander> -// { -// public StatisticEventHandler(IHubContext hub) : base(hub) -// { -// } +namespace Platform.EventHandlers +{ + public class StatisticEventHandler : BaseEventHandler, + IEventHander>, + IEventHander>, + IEventHander> + { + public StatisticEventHandler(IHubContext hub) : base(hub) + { + } -// public void Handle(EntityInserted message) -// { -// this.Notify(message); -// } + public void Handle(EntityInserted message) + { + this.Notify(message); + } -// public void Handle(EntityUpdated message) -// { -// this.Notify(message); -// } + public void Handle(EntityUpdated message) + { + this.Notify(message); + } -// public void Handle(EntityDeleted message) -// { -// this.Notify(message); -// } -// } -//} \ No newline at end of file + public void Handle(EntityDeleted message) + { + this.Notify(message); + } + } +} \ No newline at end of file diff --git a/projects/Platform/Views/Shared/_Layout.cshtml b/projects/Platform/Views/Shared/_Layout.cshtml index 9e036b7e..b644f9e0 100644 --- a/projects/Platform/Views/Shared/_Layout.cshtml +++ b/projects/Platform/Views/Shared/_Layout.cshtml @@ -85,7 +85,6 @@ } } @{ - if (hasOrgan) { var organImage = organs.FirstOrDefault(o => o.Id == organId)?.Image ?? model.Logo; @@ -94,7 +93,7 @@
- + @Html.DropDownList("UserCurrentOrganNumber", list, new { @class = "organ submit", style = "height:30px;width:160px;font-size:15px;background-color:#343a40;color: rgba(255,255,255,.8);font-size:14px;" })
diff --git a/projects/Platform/wwwroot/components/devices/collector.html b/projects/Platform/wwwroot/components/devices/collector.html new file mode 100644 index 00000000..a45c5d21 --- /dev/null +++ b/projects/Platform/wwwroot/components/devices/collector.html @@ -0,0 +1,58 @@ + + \ No newline at end of file diff --git a/projects/Platform/wwwroot/js/app.js b/projects/Platform/wwwroot/js/app.js index 2ce98c13..9c8673d7 100644 --- a/projects/Platform/wwwroot/js/app.js +++ b/projects/Platform/wwwroot/js/app.js @@ -15,7 +15,12 @@ function parseModel(response) { var script = html.getElementsByTagName('script')[0].innerHTML; script = '(' + script.replace(/^\s*export\s*default\s*/, '').replace(/;?\s*$/, '') + ')\n//# sourceURL=' + response.config.url; var model = eval(script); - model.template = template; + if (model) { + model.template = template; + } + else { + console.error('eval error'); + } return model; } //循环添加vue组件 @@ -170,6 +175,7 @@ addVueComponents({ 'camera', 'serialport', 'control', + 'collector' ] }); diff --git a/projects/Platform/wwwroot/js/site.js b/projects/Platform/wwwroot/js/site.js index 76f52ce5..578f2929 100644 --- a/projects/Platform/wwwroot/js/site.js +++ b/projects/Platform/wwwroot/js/site.js @@ -321,4 +321,7 @@ function reset() { $('form').removeData('validator'); $('form').removeData('unobtrusiveValidation'); $.validator.unobtrusive.parse('form'); -} \ No newline at end of file +} +$('body').on('change', 'select.submit', function () { + $(this).parents('form').submit(); +}); \ No newline at end of file