Former-commit-id: 017f9096fe9a0eb972b8b129c68ab23f3166c53b
Former-commit-id: f4cc58e32fa8b1dbfb6716aa6b80315dc9726b7d
1.0
wanggang 5 years ago
parent 5a72130b56
commit ee5233bcc0

@ -1,8 +1,8 @@
using Infrastructure.Domain;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text.Json;
namespace Application.Domain.Entities
{
@ -21,8 +21,14 @@ namespace Application.Domain.Entities
[Display(Name = "名称")]
public string Name { get; set; }
[Display(Name = "类型")]
public IoTValueType Type { get; set; }
[Display(Name = "数据类型")]
public IoTDataType DataType { get; set; }
[Display(Name = "数值类型")]
public IoTValueType ValueType { get; set; }
[Display(Name = "枚举定义")]
public String EnumValues { get; set; }
[Display(Name = "单位")]
public string Unit { get; set; }
@ -44,17 +50,27 @@ namespace Application.Domain.Entities
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);
}
public dynamic GetValue()
{
if (this.Type == IoTValueType.Int)
if (this.ValueType == IoTValueType.Int)
{
return Convert.ToInt32(this.Value);
}
else if (this.Type == IoTValueType.Float)
else if (this.ValueType == IoTValueType.Float)
{
return Convert.ToSingle(this.Value);
}
else if (this.Type == IoTValueType.Long)
else if (this.ValueType == IoTValueType.Long)
{
return Convert.ToInt64(this.Value);
}

@ -1,9 +1,14 @@
namespace Application.Domain.IoTCenter
using System.ComponentModel.DataAnnotations;
namespace Application.Domain.Entities
{
public enum IoTDataType
{
Info,
Data,
Event
[Display(Name="设备信息")]
Info=10,
[Display(Name = "设备数据")]
Data=20,
[Display(Name = "设备事件")]
Event=30
}
}
}

@ -89,7 +89,7 @@ namespace Application.Domain.Entities
IoTDeviceId = this.Id,
Key = key,
Value = Convert.ToString(value),
Type = type,
ValueType = type,
Name = name,
Unit = unit,
Description = description,

@ -4,15 +4,23 @@ namespace Application.Domain.Entities
{
public enum IoTValueType
{
[Display(Name = "整数")]
[Display(Name = "整数32")]
Int = 10,
[Display(Name = "浮点数")]
[Display(Name = "单精度浮点数32")]
Float = 20,
[Display(Name = "长整数")]
Long = 30,
[Display(Name = "日期")]
Timestamp = 40,
[Display(Name = "双精度浮点数64")]
Double = 30,
[Display(Name = "长整数64")]
Long = 40,
[Display(Name = "时间戳String格式UTC毫秒")]
Timestamp = 50,
[Display(Name = "字符串")]
String = 50
String = 60,
[Display(Name = "枚举(整数)")]
Enum=70,
[Display(Name = "对象String格式JSON")]
Object=80,
[Display(Name = "数组(单一其他格式)")]
Array = 90
}
}

@ -35,12 +35,17 @@ namespace IoT.Shared.Application.Models
[Display(Name = "名称")]
[ReadOnlyForEdit]
[Required(ErrorMessage = nameof(RequiredAttribute))]
public string Name { get; set; }
[Display(Name = "数据类型")]
[ReadOnlyForEdit]
[Required(ErrorMessage = nameof(RequiredAttribute))]
public IoTDataType? DataType { get; set; }
[Display(Name = "类型")]
[Display(Name = "数值类型")]
[ReadOnlyForEdit]
[Required(ErrorMessage = nameof(RequiredAttribute))]
public IoTValueType? Type { get; set; }
public IoTValueType? ValueType { get; set; }
[Display(Name = "单位")]
[ReadOnlyForEdit]

@ -42,7 +42,7 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls
.WhereIf(!string.IsNullOrEmpty(model.Query.Name), o => o.Name.Contains(model.Query.Name))
.WhereIf(!string.IsNullOrEmpty(model.Query.Key), o => o.Key.Contains(model.Query.Key))
.WhereIf(!string.IsNullOrEmpty(model.Query.Value), o => o.Value.Contains(model.Query.Value))
.WhereIf(model.Query.Type.HasValue, o => o.Type == model.Query.Type.Value)
.WhereIf(model.Query.ValueType.HasValue, o => o.ValueType == model.Query.ValueType.Value)
.WhereIf(!string.IsNullOrEmpty(model.Query.Unit), o => o.Unit.Contains(model.Query.Unit))
.WhereIf(!string.IsNullOrEmpty(model.Query.Description), o => o.Description.Contains(model.Query.Description))
.WhereIf(model.Query.Timestamp.HasValue, o => o.Timestamp == model.Query.Timestamp.Value)

@ -88,7 +88,9 @@ CREATE TABLE "iot_IoTData" (
"Key" TEXT NOT NULL,
"Value" TEXT NULL,
"Name" TEXT NULL,
"Type" INTEGER NOT NULL,
"DataType" INTEGER NOT NULL,
"ValueType" INTEGER NOT NULL,
"EnumValues" TEXT NULL,
"Unit" TEXT NULL,
"Description" TEXT NULL,
"Timestamp" INTEGER NOT NULL,

@ -66,7 +66,7 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls
.WhereIf(!string.IsNullOrEmpty(model.Query.Name), o => o.Name.Contains(model.Query.Name))
.WhereIf(!string.IsNullOrEmpty(model.Query.Key), o => o.Key.Contains(model.Query.Key))
.WhereIf(!string.IsNullOrEmpty(model.Query.Value), o => o.Value.Contains(model.Query.Value))
.WhereIf(model.Query.Type.HasValue, o => o.Type == model.Query.Type.Value)
.WhereIf(model.Query.ValueType.HasValue, o => o.ValueType == model.Query.ValueType.Value)
.WhereIf(!string.IsNullOrEmpty(model.Query.Unit), o => o.Unit.Contains(model.Query.Unit))
.WhereIf(!string.IsNullOrEmpty(model.Query.Description), o => o.Description.Contains(model.Query.Description))
.WhereIf(model.Query.Timestamp.HasValue, o => o.Timestamp == model.Query.Timestamp.Value)

@ -2,7 +2,7 @@
@{
HtmlTitle = "查看" + ViewContext.ViewData.ModelMetadata.ModelType.GetDisplayName();
}
@if (Model.Type == IoTValueType.Int || Model.Type == IoTValueType.Float)
@if (Model.ValueType == IoTValueType.Int || Model.ValueType == IoTValueType.Float)
{
<div class="row col-md-12">
<a class="btn btn-info btn-sm" href="@Url.Action("DataHistory","Data",new { id=Model.Id})">查看历史数据</a>

@ -108,7 +108,7 @@ namespace Platform.Areas.IoTCenter.Controllers
var repo = serviceScope.ServiceProvider.GetRequiredService<IRepository<IoTData>>();
var list = repo.ReadOnlyTable()
.Where(o => !o.Hidden && o.IoTDeviceId == parentId)
.Select(o => new { o.Id, Name = $"{o.Name}[{o.Type}]" })
.Select(o => new { o.Id, Name = $"{o.Name}[{o.ValueType}]" })
.ToList();
return new JsonResult(new SelectList(list, "Id", "Name", selected));
}
@ -120,7 +120,7 @@ namespace Platform.Areas.IoTCenter.Controllers
var data = repo.ReadOnlyTable().FirstOrDefault(o => o.Id == parentId);
var list = new List<SelectListItem>();
if (data.Type != IoTValueType.String)
if (data.ValueType != IoTValueType.String)
{
list.Add(new SelectListItem { Value = IoTOperationType.GreaterThan.GetValue().ToString(), Text = "大于" });
list.Add(new SelectListItem { Value = IoTOperationType.LessThan.GetValue().ToString(), Text = "小于" });
@ -309,7 +309,7 @@ namespace Platform.Areas.IoTCenter.Controllers
var expression = "";
if (type != IoTOperationType.Other)
{
if (data.Type == IoTValueType.String)
if (data.ValueType == IoTValueType.String)
{
condition = $"\"{condition}\"";
}

@ -342,7 +342,7 @@ namespace Platform.Services
{
return;
}
if (data.Type != IoTValueType.Int && data.Type != IoTValueType.Float && data.Type != IoTValueType.String)
if (data.ValueType != IoTValueType.Int && data.ValueType != IoTValueType.Float && data.ValueType != IoTValueType.String)
{
return;
}
@ -382,7 +382,7 @@ namespace Platform.Services
private object GetDataValue(IoTData model)
{
return model.Type switch
return model.ValueType switch
{
IoTValueType.Int => Convert.ToInt32(model.Value),

@ -407,7 +407,7 @@ namespace Platform.Services
{
return;
}
if (data.Type != IoTValueType.Int && data.Type != IoTValueType.Float)
if (data.ValueType != IoTValueType.Int && data.ValueType != IoTValueType.Float)
{
return;
}
@ -439,7 +439,7 @@ namespace Platform.Services
private object GetDataValue(IoTData model)
{
return model.Type switch
return model.ValueType switch
{
IoTValueType.Int => Convert.ToInt32(model.Value),

@ -381,7 +381,9 @@ CREATE TABLE "iot_IoTData" (
"Key" TEXT NOT NULL,
"Value" TEXT NULL,
"Name" TEXT NULL,
"Type" INTEGER NOT NULL,
"DataType" INTEGER NOT NULL,
"ValueType" INTEGER NOT NULL,
"EnumValues" TEXT NULL,
"Unit" TEXT NULL,
"Description" TEXT NULL,
"Timestamp" INTEGER NOT NULL,

Loading…
Cancel
Save