Former-commit-id: ec6f55a3d5c97b468020d797fd6b743575c7e745
Former-commit-id: fca8a6d5fcc98c93046b5b421ad66293c7a77c25
1.0
wanggang 5 years ago
parent 80967a2813
commit 5bf8382ac0

@ -29,8 +29,8 @@ namespace Application.Domain.Entities
[Display(Name = "数值类型")] [Display(Name = "数值类型")]
public IoTValueType ValueType { get; set; } public IoTValueType ValueType { get; set; }
[Display(Name = "枚举定义")] [Display(Name = "对象模式")]
public String EnumValues { get; set; } public string ValueSchema { get; set; }
[Display(Name = "单位")] [Display(Name = "单位")]
public string Unit { get; set; } public string Unit { get; set; }
@ -52,18 +52,6 @@ namespace Application.Domain.Entities
public List<IoTTigger> IoTTiggers { get; set; } = new List<IoTTigger>(); public List<IoTTigger> IoTTiggers { get; set; } = new List<IoTTigger>();
public Dictionary<int,string> GetEnumValues()
{
return JsonSerializer.Deserialize<Dictionary<int, string>>(this.EnumValues);
}
public void SetEnumValues(Dictionary<int, string> values)
{
this.EnumValues = JsonSerializer.Serialize(values,new JsonSerializerOptions {
Encoder= JavaScriptEncoder.Create(UnicodeRanges.All)
});
}
public dynamic GetValue() public dynamic GetValue()
{ {
if (this.ValueType == IoTValueType.Int) if (this.ValueType == IoTValueType.Int)

@ -20,6 +20,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.1" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.1" />
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" /> <PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Localization" Version="5.0.1" /> <PackageReference Include="Microsoft.Extensions.Localization" Version="5.0.1" />
<PackageReference Include="NJsonSchema" Version="10.3.2" />
<PackageReference Include="System.ServiceModel.Http" Version="4.8.0" /> <PackageReference Include="System.ServiceModel.Http" Version="4.8.0" />
<PackageReference Include="System.ServiceModel.Primitives" Version="4.8.0" /> <PackageReference Include="System.ServiceModel.Primitives" Version="4.8.0" />
<PackageReference Include="Minio" Version="3.1.13" /> <PackageReference Include="Minio" Version="3.1.13" />

@ -260,6 +260,7 @@ namespace Infrastructure.Web.Mvc
return query; return query;
} }
[ApiExplorerSettings(IgnoreApi = true)]
public virtual void EntityToModel(TEntity entity, TEditModel model) public virtual void EntityToModel(TEntity entity, TEditModel model)
{ {

@ -3,6 +3,7 @@ using Application.Domain.Entities;
using IoT.Shared.Areas.IoTCenter.Controlls; using IoT.Shared.Areas.IoTCenter.Controlls;
using System; using System;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
namespace IoT.Shared.Application.Models namespace IoT.Shared.Application.Models
{ {
@ -16,7 +17,7 @@ namespace IoT.Shared.Application.Models
[Display(Name = "网关")] [Display(Name = "网关")]
[ReadOnlyForEdit] [ReadOnlyForEdit]
[SelectList(nameof(DeviceId),nameof(AjaxBaseController.GetIoTDevice))] [SelectList(nameof(DeviceId), nameof(AjaxBaseController.GetIoTDevice))]
public Guid? IoTGatewayId { get; set; } public Guid? IoTGatewayId { get; set; }
[Display(Name = "设备")] [Display(Name = "设备")]
@ -47,6 +48,11 @@ namespace IoT.Shared.Application.Models
[Required(ErrorMessage = nameof(RequiredAttribute))] [Required(ErrorMessage = nameof(RequiredAttribute))]
public IoTValueType? ValueType { get; set; } public IoTValueType? ValueType { get; set; }
[Display(Name = "对象模式")]
[Description("描述枚举、对象和数组的类型定义")]
public string ValueSchema { get; set; }
[Display(Name = "单位")] [Display(Name = "单位")]
[ReadOnlyForEdit] [ReadOnlyForEdit]
public string Unit { get; set; } public string Unit { get; set; }

@ -12,6 +12,8 @@ using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using System.Net.Http;
using Microsoft.Extensions.Logging;
namespace IoTNode.DeviceServices namespace IoTNode.DeviceServices
{ {
@ -88,8 +90,9 @@ namespace IoTNode.DeviceServices
} }
public IoTProduct UpdateProduct(string productName, string productNumber, string path, string productIcon) public IoTProduct UpdateProduct(string productName, string productNumber, string path, string productIcon)
{ {
var scope = _applicationServices.CreateScope(); var scope = _applicationServices.CreateScope();
//
var productRepo = scope.ServiceProvider.GetService<IRepository<IoTProduct>>(); var productRepo = scope.ServiceProvider.GetService<IRepository<IoTProduct>>();
var product = productRepo.ReadOnlyTable().FirstOrDefault(o => o.Number == productNumber); var product = productRepo.ReadOnlyTable().FirstOrDefault(o => o.Number == productNumber);
if (product == null) if (product == null)
@ -106,11 +109,29 @@ namespace IoTNode.DeviceServices
{ {
var iotNodeClient = scope.ServiceProvider.GetService<IoTNodeClient>(); var iotNodeClient = scope.ServiceProvider.GetService<IoTNodeClient>();
product.ApiJson = iotNodeClient.GetApiJson(path); product.ApiJson = iotNodeClient.GetApiJson(path);
OpenApiService.UpdateApi(product); //OpenApiService.UpdateApi(product);
} }
productRepo.Add(product); productRepo.Add(product);
productRepo.SaveChanges(); productRepo.SaveChanges();
} }
//
try
{
var settingRepo = scope.ServiceProvider.GetRequiredService<ISettingService>();
var factory = scope.ServiceProvider.GetRequiredService<IHttpClientFactory>();
var notifyHost = settingRepo.GetValue("notify:host");
var url = $"{notifyHost}/Server/HasProduct/{productNumber}";
var httpClient = factory.CreateClient();
var response = httpClient.GetStringAsync(url).Result.FromJson<bool>();
if (!response)
{
scope.ServiceProvider.GetRequiredService<IoTNodeClient>().ClientToServer(Methods.UpdateProductResponse, product, null);
}
}
catch (Exception ex)
{
scope.ServiceProvider.GetRequiredService<ILogger<BaseDeviceService>>().LogError(ex.ToString());
}
return product; return product;
} }
} }

@ -23,7 +23,7 @@ namespace IoTNode.Controllers
{ {
return this.AsyncAction(() => return this.AsyncAction(() =>
{ {
this._deviceService.Exec(number, name); this._deviceService.SendMessage(number, name);
}); });
} }

@ -9,6 +9,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO.Ports; using System.IO.Ports;
using System.Linq; using System.Linq;
using NJsonSchema;
namespace IoTNode.DeviceServices.SerialPortManager namespace IoTNode.DeviceServices.SerialPortManager
{ {
@ -27,7 +28,7 @@ namespace IoTNode.DeviceServices.SerialPortManager
this.Notify(); this.Notify();
} }
public void Exec(string deviceNumber, string name) public void SendMessage(string deviceNumber, string name)
{ {
using var scope = _applicationServices.CreateScope(); using var scope = _applicationServices.CreateScope();
var repo = scope.ServiceProvider.GetService<IRepository<IoTDevice>>(); var repo = scope.ServiceProvider.GetService<IRepository<IoTDevice>>();
@ -107,8 +108,32 @@ namespace IoTNode.DeviceServices.SerialPortManager
}; };
repo.Add(device); repo.Add(device);
repo.SaveChanges(); repo.SaveChanges();
var buttons = new List<SPCommandModel>() { new SPCommandModel { Name = "测试", PortName = "/dev/ttyS0", BaudRate = 9600, Parity = 0, DataBits = 8, StopBits = 1, Message = "0123456789ABCDEF" } }.ToJson(true); var buttons = new List<SPCommandModel>() {
this.UpdateData(repo, device, device.CreateData("Buttons", buttons, IoTValueType.String, "指令", timestamp: DateTimeOffset.Now.ToUnixTimeMilliseconds())); new SPCommandModel {
Name = "测试",
PortName = "/dev/ttyS0",
BaudRate = 9600,
Parity = 0,
DataBits = 8,
StopBits = 1,
Message = "0123456789ABCDEF"
}
}.ToJson(true);
var data = device.Data.FirstOrDefault(o => o.Key == "Buttons");
if(data==null)
{
data = new IoTData {
Key="Buttons",
Name="指令",
DataType= IoTDataType.Data,
ValueType= IoTValueType.Array,
ValueSchema= JsonSchema.FromType( typeof(SPCommandModel)).ToJson(),
Value=buttons.ToJson(true),
Timestamp= DateTimeOffset.Now.ToUnixTimeMilliseconds()
};
device.Data.Add(data);
}
repo.SaveChanges();
} }
} }
} }

@ -219,11 +219,11 @@ namespace IoT.Shared.Services
//上传产品 //上传产品
this.UpdateEntityIdList<IoTProduct>(null, Methods.UpdateProductResponse); this.UpdateEntityIdList<IoTProduct>(null, Methods.UpdateProductResponse);
//上传接口 ////上传接口
this.UpdateEntityIdList<IoTApi>(null, Methods.UpdateApiResponse); //this.UpdateEntityIdList<IoTApi>(null, Methods.UpdateApiResponse);
//上传参数 ////上传参数
this.UpdateEntityIdList<IoTParameter>(null, Methods.UpdateParameterResponse); //this.UpdateEntityIdList<IoTParameter>(null, Methods.UpdateParameterResponse);
//上传设备Id列表、设备 //上传设备Id列表、设备
this.UpdateEntityIdList<IoTDevice>(Methods.UpdateDeviceIdListResponse, Methods.UpdateDeviceResponse); this.UpdateEntityIdList<IoTDevice>(Methods.UpdateDeviceIdListResponse, Methods.UpdateDeviceResponse);
@ -447,7 +447,7 @@ namespace IoT.Shared.Services
// return url; // return url;
//} //}
private void UpdateEntityIdList<T>(string updateIdListMethod, string updateEntityMethod, Func<IQueryable<T>, IQueryable<T>> include = null, Func<T, bool> predicate = null) where T : BaseEntity public void UpdateEntityIdList<T>(string updateIdListMethod, string updateEntityMethod, Func<IQueryable<T>, IQueryable<T>> include = null, Func<T, bool> predicate = null) where T : BaseEntity
{ {
using var scope = this._applicationServices.CreateScope(); using var scope = this._applicationServices.CreateScope();
var repo = scope.ServiceProvider.GetService<IRepository<T>>(); var repo = scope.ServiceProvider.GetService<IRepository<T>>();

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

@ -90,7 +90,7 @@ CREATE TABLE "iot_IoTData" (
"Name" TEXT NULL, "Name" TEXT NULL,
"DataType" INTEGER NOT NULL, "DataType" INTEGER NOT NULL,
"ValueType" INTEGER NOT NULL, "ValueType" INTEGER NOT NULL,
"EnumValues" TEXT NULL, "ValueSchema" TEXT NULL,
"Unit" TEXT NULL, "Unit" TEXT NULL,
"Description" TEXT NULL, "Description" TEXT NULL,
"Timestamp" INTEGER NOT NULL, "Timestamp" INTEGER NOT NULL,

@ -0,0 +1,34 @@
using Application.Domain.Entities;
using Infrastructure.Data;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Linq;
namespace Platform.Controllers
{
/// <summary>
/// 作为平台服务器响应网关节点的HTTP请求
/// </summary>
public class ServerController : ControllerBase
{
private readonly IServiceProvider _services;
public ServerController(IServiceProvider services)
{
this._services = services;
}
/// <summary>
/// 根据编号查询设备是否存在
/// </summary>
/// <param name="number"></param>
/// <returns></returns>
public bool HasProduct(string number)
{
using var scope = this._services.CreateScope();
var repo = scope.ServiceProvider.GetRequiredService<IRepository<IoTProduct>>();
return repo.ReadOnlyTable().Any(o => o.Number == number);
}
}
}

@ -20,6 +20,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Vibrant.InfluxDB.Client; using Vibrant.InfluxDB.Client;
using Vibrant.InfluxDB.Client.Rows; using Vibrant.InfluxDB.Client.Rows;
using IoT.Shared.Services;
namespace Platform.Services namespace Platform.Services
{ {
@ -34,8 +35,8 @@ namespace Platform.Services
IEventHander<EntityUpdatedEvent<IoTGateway>>, IEventHander<EntityUpdatedEvent<IoTGateway>>,
IEventHander<EntityDeletedEvent<IoTGateway>>, IEventHander<EntityDeletedEvent<IoTGateway>>,
IEventHander<EntityInsertedEvent<IoTProduct>>, IEventHander<EntityInsertedEvent<IoTProduct>>,
IEventHander<EntityUpdatedEvent<IoTProduct>>, //IEventHander<EntityUpdatedEvent<IoTProduct>>,
IEventHander<EntityDeletedEvent<IoTProduct>>, //IEventHander<EntityDeletedEvent<IoTProduct>>,
IEventHander<EntityInsertedEvent<IoTDevice>>, IEventHander<EntityInsertedEvent<IoTDevice>>,
IEventHander<EntityUpdatedEvent<IoTDevice>>, IEventHander<EntityUpdatedEvent<IoTDevice>>,
IEventHander<EntityDeletedEvent<IoTDevice>>, IEventHander<EntityDeletedEvent<IoTDevice>>,
@ -49,6 +50,7 @@ namespace Platform.Services
private readonly IConfiguration _cfg; private readonly IConfiguration _cfg;
private readonly ISettingService _settingService; private readonly ISettingService _settingService;
private readonly ILogger<IoTCenterEventHandler> _logger; private readonly ILogger<IoTCenterEventHandler> _logger;
private readonly IRepository<IoTProduct> _productrepo;
private readonly IRepository<IoTGateway> _nodeRepo; private readonly IRepository<IoTGateway> _nodeRepo;
private readonly IRepository<Organ> _organRepo; private readonly IRepository<Organ> _organRepo;
private readonly IRepository<BuildingIoTGateway> _buildingIoTGatewayRepo; private readonly IRepository<BuildingIoTGateway> _buildingIoTGatewayRepo;
@ -62,6 +64,7 @@ namespace Platform.Services
public IoTCenterEventHandler(IConfiguration cfg, public IoTCenterEventHandler(IConfiguration cfg,
ISettingService settingService, ISettingService settingService,
ILogger<IoTCenterEventHandler> logger, ILogger<IoTCenterEventHandler> logger,
IRepository<IoTProduct> productRepo,
IRepository<IoTGateway> nodeRepo, IRepository<IoTGateway> nodeRepo,
IRepository<Organ> organRepo, IRepository<Organ> organRepo,
IRepository<BuildingIoTGateway> buildingIoTGatewayRepo, IRepository<BuildingIoTGateway> buildingIoTGatewayRepo,
@ -75,6 +78,7 @@ namespace Platform.Services
this._cfg = cfg; this._cfg = cfg;
this._settingService = settingService; this._settingService = settingService;
this._logger = logger; this._logger = logger;
this._productrepo = productRepo;
this._nodeRepo = nodeRepo; this._nodeRepo = nodeRepo;
this._organRepo = organRepo; this._organRepo = organRepo;
this._buildingIoTGatewayRepo = buildingIoTGatewayRepo; this._buildingIoTGatewayRepo = buildingIoTGatewayRepo;
@ -135,18 +139,26 @@ namespace Platform.Services
public void Handle(EntityInsertedEvent<IoTProduct> message) public void Handle(EntityInsertedEvent<IoTProduct> message)
{ {
var product = this._productrepo.Table()
.Include(o=>o.IoTApis)
.ThenInclude(o=>o.IoTParameters)
.FirstOrDefault(o => o.Number == message.Data.Number);
if(product!=null)
{
OpenApiService.UpdateApi(product);
}
this.Notify(message); this.Notify(message);
} }
public void Handle(EntityUpdatedEvent<IoTProduct> message) //public void Handle(EntityUpdatedEvent<IoTProduct> message)
{ //{
this.Notify(message); // this.Notify(message);
} //}
public void Handle(EntityDeletedEvent<IoTProduct> message) //public void Handle(EntityDeletedEvent<IoTProduct> message)
{ //{
this.Notify(message); // this.Notify(message);
} //}
#endregion Product #endregion Product

File diff suppressed because it is too large Load Diff

@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="/lib/element-ui/theme-chalk/index.min.css">
<link rel="stylesheet" href="/lib/ant-design-vue/antd.min.css">
<title>前端测试页</title>
</head>
<body>
<div id="app">
</div>
<script src="/lib/jquery/jquery.min.js"></script>
<script src="/lib/linq/linq.min.js"></script>
<script src="/lib/vue/vue.min.js"></script>
<script src="/lib/element-ui/index.min.js"></script>
<script src="/lib/element-ui/locale/zh-CN.min.js"></script>
<script src="/lib/element-ui/index.min.js"></script>
<script src="/lib/element-ui/locale/zh-CN.min.js"></script>
<script src="/lib/ant-design-vue/antd.min.js"></script>
<script>
var app = new Vue({
el: '#app',
data() {
return {
treeData,
};
},
methods: {
onSelect(selectedKeys, info) {
console.log('selected', selectedKeys, info);
}
}
});
</script>
</body>
</html>
Loading…
Cancel
Save