设备显示和操作分离完成

Former-commit-id: 003803579fecd5439133a0fedad8d72ca6080d8e
Former-commit-id: f1ff5eead9942195686e84d2c3047b727adfcf82
1.0
wanggang 4 years ago
parent fe0aa43c73
commit b242a7b805

@ -18,4 +18,4 @@ namespace ConsoleApp3
listener.Stop();
}
}
}
}

@ -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<LCDAUE800DService> _logger;
public LCDAUE800DService(IServiceProvider applicationServices, IWebHostEnvironment env)
public LCDAUE800DService(IServiceProvider applicationServices, IWebHostEnvironment env, ILogger<LCDAUE800DService> 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<IRepository<IoTDevice>>();
var dataRepo = scope.ServiceProvider.GetService<IRepository<IoTData>>();
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<IRepository<IoTDevice>>();
var dataRepo = scope.ServiceProvider.GetService<IRepository<IoTData>>();
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 = @$"<?xml version=""1.0"" encoding=""UTF-8"" ?><root><common><building_id>{building_id}</building_id><gateway_id>{gateway_id}</gateway_id><type>report_ack</type></common><report_config operation=""report_ack""><report_ack>pass</report_ack></report_config></root>";
@ -504,7 +513,7 @@ namespace IoTNode.DeviceServices.LiChuang
private DataKeys GetKey(string equipidex)
{
var value = $"设备{equipidex}";
var value = $"Device{equipidex}";
return Enum.Parse<DataKeys>(value);
}

@ -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)

@ -44,10 +44,10 @@ namespace IoTNode
services.AddTransient<IEmailSender, EmptyEmailSender>();
if (Env.IsDevelopment())
{
//services.AddHostedService(o => o.GetService<SerialPortService>());
//services.AddHostedService(o => o.GetService<OnvifService>());
services.AddHostedService(o => o.GetService<SerialPortService>());
services.AddHostedService(o => o.GetService<OnvifService>());
services.AddHostedService(o => o.GetService<FBeeService>());
//services.AddHostedService(o => o.GetService<LCDAUE800DService>());
services.AddHostedService(o => o.GetService<LCDAUE800DService>());
}
else
{

@ -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<EntityInserted<Statistic>>,
// IEventHander<EntityUpdated<Statistic>>,
// IEventHander<EntityDeleted<Statistic>>
// {
// public StatisticEventHandler(IHubContext<IoTCenterHub> hub) : base(hub)
// {
// }
namespace Platform.EventHandlers
{
public class StatisticEventHandler : BaseEventHandler,
IEventHander<EntityInserted<Statistic>>,
IEventHander<EntityUpdated<Statistic>>,
IEventHander<EntityDeleted<Statistic>>
{
public StatisticEventHandler(IHubContext<IoTCenterHub> hub) : base(hub)
{
}
// public void Handle(EntityInserted<Statistic> message)
// {
// this.Notify<Statistic>(message);
// }
public void Handle(EntityInserted<Statistic> message)
{
this.Notify<Statistic>(message);
}
// public void Handle(EntityUpdated<Statistic> message)
// {
// this.Notify<Statistic>(message);
// }
public void Handle(EntityUpdated<Statistic> message)
{
this.Notify<Statistic>(message);
}
// public void Handle(EntityDeleted<Statistic> message)
// {
// this.Notify<Statistic>(message);
// }
// }
//}
public void Handle(EntityDeleted<Statistic> message)
{
this.Notify<Statistic>(message);
}
}
}

@ -85,7 +85,6 @@
}
}
@{
if (hasOrgan)
{
var organImage = organs.FirstOrDefault(o => o.Id == organId)?.Image ?? model.Logo;
@ -94,7 +93,7 @@
<img class="logo" src="@Url.Content2(organImage)" />
<form method="get" action="@Url.Action("ChangeOrgan","Account",new{area=""})">
<span class="brand-text font-weight-light">
<input type="hidden" name="ReturnUrl" value="@ViewContext.HttpContext.Request.GetDisplayUrl()" />
<input type="hidden" name="ReturnUrl" value="@Url.Action("Index","Home",new{area=""})/" />
@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;" })
</span>
</form>

@ -0,0 +1,58 @@
<template>
<div class="card device-component">
<div class="card-header">
<h3 class="card-title">
{{device.displayName}}
</h3>
<div class="card-tools">
<span @click="visible = true" title="操作"><i class="ion ion-md-settings"></i></span>
</div>
</div>
<div class="card-body">
<div class="row">
<div class="col-4 align-self-center">
<img class="device-image" :src="device.ioTProduct.image" style="width:48px;" />
</div>
<div class="col-8 align-self-center">
<div class="row">
<span>型号:{{type}}</span>
</div>
<div class="row">
<span>设备:{{count}}</span>
</div>
</div>
</div>
</div>
<a-modal v-model="visible" :title="device.displayName" :footer="null" width="50%">
<div class="row">
<div class="col-sm-3" v-for="item in list">
<div class="card">
<div class="card-body bg-gray">{{item.name}}: {{item.value}} {{item.unit}}</div>
</div>
</div>
</div>
</a-modal>
</div>
</template>
<script>
({
props: ['device'],
data: function () {
return {
visible: false,
model:null
}
},
computed: {
type: function () {
return getIoTDataValue(this.device, '型号');
},
count: function () {
return Enumerable.from(this.device.data).where(o => o.key.indexOf('Device') === 0).count();
},
list: function () {
return Enumerable.from(this.device.data).where(o => o.key.indexOf('Device') === 0).orderBy(o => o.key).toArray();
}
}
});
</script>

@ -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'
]
});

@ -321,4 +321,7 @@ function reset() {
$('form').removeData('validator');
$('form').removeData('unobtrusiveValidation');
$.validator.unobtrusive.parse('form');
}
}
$('body').on('change', 'select.submit', function () {
$(this).parents('form').submit();
});
Loading…
Cancel
Save