From 0d0b07d5dd853b6e5588d2a5c93d691db227ad88 Mon Sep 17 00:00:00 2001 From: wq1234wq Date: Tue, 11 Oct 2022 18:38:54 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=81=E4=B9=A6=E7=AE=A1=E7=90=86=EF=BC=8C?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E5=9C=A8=E7=BA=BF=EF=BC=8C=E4=BA=A7=E5=93=81?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devicelist/devicelist.component.html | 296 +++++++++--------- .../devicelist/devicelist.component.ts | 2 + .../settings/certmgr/certmgr.component.html | 34 +- .../settings/certmgr/certmgr.component.ts | 3 + IoTSharp/Controllers/DevicesController.cs | 2 +- IoTSharp/Controllers/ProducesController.cs | 149 ++++++++- IoTSharp/Dtos/ProduceAddDto.cs | 61 ++++ IoTSharp/IoTSharp.xml | 93 ++++++ 8 files changed, 466 insertions(+), 174 deletions(-) create mode 100644 IoTSharp/Dtos/ProduceAddDto.cs diff --git a/IoTSharp/ClientApp/src/app/routes/devices/devicelist/devicelist.component.html b/IoTSharp/ClientApp/src/app/routes/devices/devicelist/devicelist.component.html index 84dc13b3..f12b99c4 100644 --- a/IoTSharp/ClientApp/src/app/routes/devices/devicelist/devicelist.component.html +++ b/IoTSharp/ClientApp/src/app/routes/devices/devicelist/devicelist.component.html @@ -1,111 +1,103 @@ - -
-
-
- - 设备名称 - - - - -
- -
- - - - -
+ + +
+
+ + 设备名称 + + + + +
+ +
+ + 仅显示在线 + + + + + +
+ +
+ + + + +
-
+
- - - - -
- - - -
- 显示的列: - -
- - - - + + +
+ + + +
+ 显示的列: +
- - - - - - - - - 属性名称 - 属性值 - 数据侧 - 时间 操作 - - - - {{ _item.keyName }} - {{ _item.value }} - {{ _item.dataSide }} - {{ _item.dateTime | date: 'yyyy-MM-dd HH:mm:ss' }} - - - - - - - - - - - - + - - - - - - 遥测名称 - 遥测值 - 时间 - - - - {{ _item.keyName }} - {{ _item.value }} - {{ _item.dateTime | date: 'yyyy-MM-dd HH:mm:ss' }} - - - - - - - - - - - 规则名称 - 备注 - 操作 - - - - {{ _item.name }} - {{ _item.ruleDesc }} - - - - - - - - - - - - \ No newline at end of file + + + \ No newline at end of file diff --git a/IoTSharp/ClientApp/src/app/routes/devices/devicelist/devicelist.component.ts b/IoTSharp/ClientApp/src/app/routes/devices/devicelist/devicelist.component.ts index ecf43354..39062485 100644 --- a/IoTSharp/ClientApp/src/app/routes/devices/devicelist/devicelist.component.ts +++ b/IoTSharp/ClientApp/src/app/routes/devices/devicelist/devicelist.component.ts @@ -73,6 +73,7 @@ export class DevicelistComponent implements OnInit, OnDestroy { pi: number; ps: number; sorter: string; + onlyActive:boolean; customerId: string; name: string; // anothor query field:The type you expect @@ -80,6 +81,7 @@ export class DevicelistComponent implements OnInit, OnDestroy { pi: 0, ps: 20, sorter: '', + onlyActive:false, customerId: '', name: '' }; diff --git a/IoTSharp/ClientApp/src/app/routes/settings/certmgr/certmgr.component.html b/IoTSharp/ClientApp/src/app/routes/settings/certmgr/certmgr.component.html index b4bde811..82325f03 100644 --- a/IoTSharp/ClientApp/src/app/routes/settings/certmgr/certmgr.component.html +++ b/IoTSharp/ClientApp/src/app/routes/settings/certmgr/certmgr.component.html @@ -1,14 +1,24 @@ -
- - - - - - - - - - -
+
+
+
+ + + + + + + + + + +
+
+
+ +
+
+ +
+
\ No newline at end of file diff --git a/IoTSharp/ClientApp/src/app/routes/settings/certmgr/certmgr.component.ts b/IoTSharp/ClientApp/src/app/routes/settings/certmgr/certmgr.component.ts index 22b381ae..4e65c406 100644 --- a/IoTSharp/ClientApp/src/app/routes/settings/certmgr/certmgr.component.ts +++ b/IoTSharp/ClientApp/src/app/routes/settings/certmgr/certmgr.component.ts @@ -12,6 +12,7 @@ import { appmessage } from 'src/app/models/appmessage'; export class CertmgrComponent implements OnInit { form!: FormGroup; installed = true; + caCertificate=false; constructor(private http: _HttpClient, private msg: NzMessageService, private fb: FormBuilder,) { } ngOnInit(): void { @@ -31,9 +32,11 @@ export class CertmgrComponent implements OnInit { next: next => { if (next.data.installed) { this.installed = true; + this.caCertificate=next.data.caCertificate; this.form.patchValue(next.data); } else { this.installed = false; + this.caCertificate=next.data.caCertificate; this.form.patchValue(next.data); } }, diff --git a/IoTSharp/Controllers/DevicesController.cs b/IoTSharp/Controllers/DevicesController.cs index b5e38ff3..8ea35ffb 100644 --- a/IoTSharp/Controllers/DevicesController.cs +++ b/IoTSharp/Controllers/DevicesController.cs @@ -131,7 +131,7 @@ namespace IoTSharp.Controllers var query=from c in _context.Device.Include(c => c.DeviceIdentity) where c.Customer.Id == m.customerId && !c.Deleted && c.Tenant.Id == profile.Tenant select c; if (m.OnlyActive) { - var al = from a in _context.AttributeLatest where a.KeyName == Constants._Active select a.DeviceId; + var al = from a in _context.AttributeLatest where a.KeyName == Constants._Active &&a.Value_Boolean==true select a.DeviceId; query = from x in query where al.Contains( x.Id) select x; } if (!string.IsNullOrEmpty(m.Name)) diff --git a/IoTSharp/Controllers/ProducesController.cs b/IoTSharp/Controllers/ProducesController.cs index cc1747c9..0f69b48c 100644 --- a/IoTSharp/Controllers/ProducesController.cs +++ b/IoTSharp/Controllers/ProducesController.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; +using System.Security.Cryptography; using System.Threading.Tasks; using IoTSharp.Contracts; using IoTSharp.Controllers.Models; @@ -30,7 +31,11 @@ namespace IoTSharp.Controllers _context = context; _logger = logger; } - + /// + /// 产品列表 + /// + /// + /// [HttpGet] public async Task>> List([FromQuery] ProduceParam m) { @@ -49,19 +54,153 @@ namespace IoTSharp.Controllers total = await _context.Produces.CountAsync(condition), rows = _context.Produces.Where(condition).Where(condition).Skip((m.offset) * m.limit).Take(m.limit) .ToList().Select(c => new ProduceDto - { Id = c.Id, DefaultIdentityType = c.DefaultIdentityType, DefaultTimeout=c.DefaultTimeout, Description= c.Description, Name=c.Name}).ToList() + { Id = c.Id, DefaultIdentityType = c.DefaultIdentityType, DefaultTimeout = c.DefaultTimeout, Description = c.Description, Name = c.Name }).ToList() }); } + /// + /// + /// + /// + /// [HttpGet] public async Task>> ProduceDatas(Guid produceid) { - var result = await _context.ProduceDatas.Include(c => c.Owner).Where(p=>p.Owner.Id==produceid).AsSplitQuery().ToListAsync(); + var result = await _context.ProduceDatas.Include(c => c.Owner).Where(p => p.Owner.Id == produceid).AsSplitQuery().ToListAsync(); return new ApiResult>(ApiCode.Success, "OK", result); } - + /// + /// 获取产品 + /// + /// + /// + + [HttpGet] + public async Task> Get(Guid id) + { + var result = await _context.Produces.SingleOrDefaultAsync(c => c.Id == id); + if (result != null) + { + return new ApiResult(ApiCode.Success, "OK", new ProduceAddDto + { + + Id = result.Id, + Customer = result.Customer.Id, + Tenant = result.Tenant.Id, + Icon = result.Icon, + DefaultDeviceType = result.DefaultDeviceType, + DefaultIdentityType = result.DefaultIdentityType, + DefaultTimeout = result.DefaultTimeout, + Description = result.Description, + GatewayConfiguration = result.GatewayConfiguration, + GatewayType = result.GatewayType, + Name = result.Name + + }); + } + else + { + return new ApiResult(ApiCode.CantFindObject, "Produce is not found", null); + } + + } + /// + /// 删除产品 + /// + /// + /// + + [HttpGet] + public async Task> Delete(Guid produceid) + { + try + { + var produce = await _context.Produces.SingleOrDefaultAsync(c => c.Id == produceid); + if (produce != null) + { + _context.ProduceDatas.RemoveRange(_context.ProduceDatas.Where(c => c.Owner == produce)); + await _context.SaveChangesAsync(); + _context.Produces.Remove(produce); + await _context.SaveChangesAsync(); + return new ApiResult(ApiCode.Success, "OK", true); + } + return new ApiResult(ApiCode.CantFindObject, "Produce is not found", false); + } + catch (Exception e) + { + return new ApiResult(ApiCode.Exception, e.Message, false); + } + } + + /// + /// 新增产品 + /// + /// + /// + [HttpGet] + public async Task> Save(ProduceAddDto dto) + { + + try + { + var profile = this.GetUserProfile(); + var produce = new Produce(); + produce.Customer = _context.Customer.Find(profile.Customer); + produce.Tenant = _context.Tenant.Find(profile.Tenant); + produce.DefaultDeviceType = dto.DefaultDeviceType; + produce.DefaultIdentityType=dto.DefaultIdentityType; + produce.DefaultTimeout=dto.DefaultTimeout; + produce.Description=dto.Description; + produce.Name= + dto.Name; + produce.GatewayConfiguration=dto.GatewayConfiguration; + produce.Icon=dto.Icon; + produce.GatewayType=dto.GatewayType; + _context.Produces.Add(produce); + await _context.SaveChangesAsync(); + return new ApiResult(ApiCode.Success, "OK", true); + } + catch (Exception e) + { + return new ApiResult(ApiCode.Exception, e.Message, false); + } + + } + + /// + /// 修改产品 + /// + /// + /// + [HttpGet] + public async Task> Update(ProduceAddDto dto) + { + + try + { + var produce = await _context.Produces.SingleOrDefaultAsync(c => c.Id == dto.Id); + if (produce != null) + { + produce.DefaultIdentityType = dto.DefaultIdentityType; + produce.DefaultIdentityType = dto.DefaultIdentityType; + produce.DefaultTimeout = dto.DefaultTimeout; + produce.Description = dto.Description; + produce.GatewayConfiguration = dto.GatewayConfiguration; + produce.Name = dto.Name; + produce.Icon = dto.Icon; + _context.Produces.Update(produce); + await _context.SaveChangesAsync(); + } + return new ApiResult(ApiCode.CantFindObject, "Produce is not found", false); + } + catch (Exception e) + { + return new ApiResult(ApiCode.Exception, e.Message, false); + } + + } } -} +} diff --git a/IoTSharp/Dtos/ProduceAddDto.cs b/IoTSharp/Dtos/ProduceAddDto.cs new file mode 100644 index 00000000..8f1a1ab0 --- /dev/null +++ b/IoTSharp/Dtos/ProduceAddDto.cs @@ -0,0 +1,61 @@ +using IoTSharp.Contracts; +using IoTSharp.Data; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System; + +namespace IoTSharp.Dtos +{ + public class ProduceAddDto + { + + public Guid Id { get; set; } + + /// + /// 设备名称 + /// + public string Name { get; set; } + + /// + /// ICON file full path + /// + public string Icon { get; set; } + + /// + /// 网关类型 根据不通网关来处理相关配置 + /// + public GatewayType GatewayType { get; set; } = GatewayType.Unknow; + + /// + /// 网关配置信息, 如果是Unknow 则不使用, 如果是自定义 ,则这里是json字符串。 + /// 如果是其他对应的网关, 则这里是 对应的配置文件名。 + /// + public string GatewayConfiguration { get; set; } = string.Empty; + /// + /// 超时时间 秒数 + /// + public int DefaultTimeout { get; set; } = 300; + /// + /// 租户 + /// + public Guid Tenant { get; set; } + /// + /// 客户 + /// + public Guid Customer { get; set; } + /// + /// 默认认证类型 + /// + [EnumDataType(typeof(IdentityType))] + public IdentityType DefaultIdentityType { get; set; } = IdentityType.AccessToken; + /// + /// 描述 + /// + public string Description { get; set; } + /// + /// 默认设备类型 + /// + public DeviceType DefaultDeviceType { get; set; } + + } +} diff --git a/IoTSharp/IoTSharp.xml b/IoTSharp/IoTSharp.xml index f350d642..a3addda3 100644 --- a/IoTSharp/IoTSharp.xml +++ b/IoTSharp/IoTSharp.xml @@ -514,6 +514,48 @@ + + + 产品列表 + + + + + + + + + + + + + + 获取产品 + + + + + + + 删除产品 + + + + + + + 新增产品 + + + + + + + 修改产品 + + + + 更新节点的条件表达式 @@ -745,6 +787,57 @@ http://localhost/ + + + 设备名称 + + + + + ICON file full path + + + + + 网关类型 根据不通网关来处理相关配置 + + + + + 网关配置信息, 如果是Unknow 则不使用, 如果是自定义 ,则这里是json字符串。 + 如果是其他对应的网关, 则这里是 对应的配置文件名。 + + + + + 超时时间 秒数 + + + + + 租户 + + + + + 客户 + + + + + 默认认证类型 + + + + + 描述 + + + + + 默认设备类型 + + 查询历史遥测数据请求结构体 -- GitLab