diff --git a/projects/Infrastructure/Views/Shared/_Index_Row.cshtml b/projects/Infrastructure/Views/Shared/_Index_Row.cshtml index 7115e653..a1a25cda 100644 --- a/projects/Infrastructure/Views/Shared/_Index_Row.cshtml +++ b/projects/Infrastructure/Views/Shared/_Index_Row.cshtml @@ -1,6 +1,6 @@ @{var props = ViewData.ModelMetadata.Properties.Where(pm => pm.ShowForEdit && !pm.HideSurroundingHtml && !pm.IsComplexType && !pm.IsCollectionType && pm.PropertyName != "Id").ToList(); foreach (var prop in props) { - @Html.Display(prop.PropertyName, prop.DataTypeName ?? prop.TemplateHint) + @Html.Display(prop.PropertyName, prop.DataTypeName ?? prop.TemplateHint) } } \ No newline at end of file diff --git a/projects/IoT/IoT.Shared/Application/Models/DataDto.cs b/projects/IoT/IoT.Shared/Application/Models/DataDto.cs index d8a2cf76..ebf51f13 100644 --- a/projects/IoT/IoT.Shared/Application/Models/DataDto.cs +++ b/projects/IoT/IoT.Shared/Application/Models/DataDto.cs @@ -1,6 +1,6 @@ using Application.Domain.Entities; -namespace IoT.Shared.Application.Models +namespace Application.Models { public class DataDto { diff --git a/projects/IoT/IoT.Shared/Application/Models/DeviceDto.cs b/projects/IoT/IoT.Shared/Application/Models/DeviceDto.cs index f2ff7b7b..ce258e06 100644 --- a/projects/IoT/IoT.Shared/Application/Models/DeviceDto.cs +++ b/projects/IoT/IoT.Shared/Application/Models/DeviceDto.cs @@ -1,4 +1,4 @@ -namespace IoT.Shared.Application.Models +namespace Application.Models { public class DeviceDto { diff --git a/projects/IoT/IoT.Shared/Application/Models/EditDataModel.cs b/projects/IoT/IoT.Shared/Application/Models/EditDataModel.cs index 3c8a30a6..1513cb0a 100644 --- a/projects/IoT/IoT.Shared/Application/Models/EditDataModel.cs +++ b/projects/IoT/IoT.Shared/Application/Models/EditDataModel.cs @@ -1,31 +1,41 @@ -using System.ComponentModel.DataAnnotations; using Application.Domain.Entities; using Infrastructure.Application; +using Microsoft.AspNetCore.Mvc; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; namespace Application.Models { [Display(Name = "数据")] public class EditDataModel : EditModel { - [Display(Name = "类型")] - [Required(ErrorMessage = nameof(RequiredAttribute))] - public DeviceDataType Type { get; set; } - - [Display(Name = "名称")] - [Required(ErrorMessage = nameof(RequiredAttribute))] - public string Name { get; set; } - [Display(Name = "键")] - [Required(ErrorMessage = nameof(RequiredAttribute))] + [ReadOnly(true)] public string Key { get; set; } [Display(Name = "值")] public string Value { get; set; } + [Display(Name = "名称")] + public string Name { get; set; } + + [Display(Name = "类型")] + public DeviceDataType Type { get; set; } + [Display(Name = "单位")] public string Unit { get; set; } [Display(Name = "描述")] public string Description { get; set; } + + [Display(Name = "时间戳")] + public long Timestamp { get; set; } + + [Display(Name = "隐藏")] + public bool Hidden { get; set; } + + [HiddenInput(DisplayValue = false)] + [ScaffoldColumn(true)] + public string DeviceNumber { get; set; } } } \ No newline at end of file diff --git a/projects/IoT/IoT.Shared/Application/Models/EditProductModel.cs b/projects/IoT/IoT.Shared/Application/Models/EditProductModel.cs new file mode 100644 index 00000000..91873e62 --- /dev/null +++ b/projects/IoT/IoT.Shared/Application/Models/EditProductModel.cs @@ -0,0 +1,24 @@ +using Infrastructure.Application; +using System.ComponentModel.DataAnnotations; + +namespace Application.Models +{ + [Display(Name = "产品")] + public class EditProductModel : EditModel + { + [Display(Name = "产品名称")] + public string Name { get; set; } + + [Display(Name = "产品型号")] + public string Number { get; set; } + + [Display(Name = "图标")] + public string Icon { get; set; } + + [Display(Name = "ApiJson")] + public string ApiJson { get; set; } + + [Display(Name = "产品分类")] + public string CategoryName { get; set; } + } +} \ No newline at end of file diff --git a/projects/IoT/IoT.Shared/Application/Models/Methods.cs b/projects/IoT/IoT.Shared/Application/Models/Methods.cs index 8782eaef..aab09d82 100644 --- a/projects/IoT/IoT.Shared/Application/Models/Methods.cs +++ b/projects/IoT/IoT.Shared/Application/Models/Methods.cs @@ -1,4 +1,4 @@ -namespace IoT.Shared.Application.Models +namespace Application.Models { public class Methods { @@ -28,5 +28,11 @@ public const string DeleteDeviceRequest = nameof(DeleteDeviceRequest); public const string DeleteDeviceResponse = nameof(DeleteDeviceResponse); + + public const string EditDataRequest = nameof(EditDataRequest); + public const string EditDataResponse = nameof(EditDataResponse); + + public const string DeleteDataRequest = nameof(DeleteDataRequest); + public const string DeleteDataResponse = nameof(DeleteDataResponse); } } \ No newline at end of file diff --git a/projects/IoT/IoT.Shared/Application/Models/NodeDto.cs b/projects/IoT/IoT.Shared/Application/Models/NodeDto.cs index 1732911f..f680fde0 100644 --- a/projects/IoT/IoT.Shared/Application/Models/NodeDto.cs +++ b/projects/IoT/IoT.Shared/Application/Models/NodeDto.cs @@ -1,6 +1,6 @@ using System.ComponentModel.DataAnnotations; -namespace IoT.Shared.Application.Models +namespace Application.Models { public class NodeDto { diff --git a/projects/IoT/IoT.Shared/Application/Models/ProductDto.cs b/projects/IoT/IoT.Shared/Application/Models/ProductDto.cs index 991ea899..5295d202 100644 --- a/projects/IoT/IoT.Shared/Application/Models/ProductDto.cs +++ b/projects/IoT/IoT.Shared/Application/Models/ProductDto.cs @@ -1,6 +1,6 @@ using Application.Domain.Entities; -namespace IoT.Shared.Application.Models +namespace Application.Models { public class ProductDto : Product { diff --git a/projects/IoT/IoT.Shared/DeviceServices/FBee/FBeeService.cs b/projects/IoT/IoT.Shared/DeviceServices/FBee/FBeeService.cs index 3b153000..6c727f11 100644 --- a/projects/IoT/IoT.Shared/DeviceServices/FBee/FBeeService.cs +++ b/projects/IoT/IoT.Shared/DeviceServices/FBee/FBeeService.cs @@ -1,7 +1,7 @@ using Application.Domain.Entities; using Infrastructure.Data; using Infrastructure.Extensions; -using IoT.Shared.Application.Models; +using Application.Models; using IoT.Shared.Infrastructure; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; diff --git a/projects/IoT/IoT.Shared/DeviceServices/Onvif/OnvifService.cs b/projects/IoT/IoT.Shared/DeviceServices/Onvif/OnvifService.cs index 5252d055..12c37877 100644 --- a/projects/IoT/IoT.Shared/DeviceServices/Onvif/OnvifService.cs +++ b/projects/IoT/IoT.Shared/DeviceServices/Onvif/OnvifService.cs @@ -1,7 +1,7 @@ using Application.Domain.Entities; using Infrastructure.Data; using Infrastructure.Extensions; -using IoT.Shared.Application.Models; +using Application.Models; using IoT.Shared.Infrastructure; using Microsoft.AspNetCore.Hosting; using Microsoft.EntityFrameworkCore; diff --git a/projects/IoT/IoT.Shared/DeviceServices/SerialPort/SerialPortService.cs b/projects/IoT/IoT.Shared/DeviceServices/SerialPort/SerialPortService.cs index 30e0d005..1b9e67d3 100644 --- a/projects/IoT/IoT.Shared/DeviceServices/SerialPort/SerialPortService.cs +++ b/projects/IoT/IoT.Shared/DeviceServices/SerialPort/SerialPortService.cs @@ -12,7 +12,7 @@ using System.Linq; using System.Runtime.InteropServices; using System.Threading.Tasks; using System.IO.Ports; -using IoT.Shared.Application.Models; +using Application.Models; namespace IoT.Shared.DeviceServices.SerialPort { diff --git a/projects/IoT/IoT.Shared/Infrastructure/BaseClientService.cs b/projects/IoT/IoT.Shared/Infrastructure/BaseClientService.cs index d2dde1ad..1c886cfc 100644 --- a/projects/IoT/IoT.Shared/Infrastructure/BaseClientService.cs +++ b/projects/IoT/IoT.Shared/Infrastructure/BaseClientService.cs @@ -1,5 +1,5 @@ using Infrastructure.Extensions; -using IoT.Shared.Application.Models; +using Application.Models; using Microsoft.AspNetCore.SignalR.Client; using Microsoft.Extensions.Configuration; using System; diff --git a/projects/IoT/IoT.Shared/Infrastructure/BaseDeviceService.cs b/projects/IoT/IoT.Shared/Infrastructure/BaseDeviceService.cs index 2612a34c..087f75f6 100644 --- a/projects/IoT/IoT.Shared/Infrastructure/BaseDeviceService.cs +++ b/projects/IoT/IoT.Shared/Infrastructure/BaseDeviceService.cs @@ -1,6 +1,6 @@ using Application.Domain.Entities; using Infrastructure.Extensions; -using IoT.Shared.Application.Models; +using Application.Models; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Newtonsoft.Json; diff --git a/projects/IoT/IoT.Shared/Infrastructure/ClientService.cs b/projects/IoT/IoT.Shared/Infrastructure/ClientService.cs index ffffa4df..a53be412 100644 --- a/projects/IoT/IoT.Shared/Infrastructure/ClientService.cs +++ b/projects/IoT/IoT.Shared/Infrastructure/ClientService.cs @@ -2,7 +2,6 @@ using Application.Models; using Infrastructure.Data; using Infrastructure.Extensions; -using IoT.Shared.Application.Models; using Microsoft.AspNetCore.SignalR.Client; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; @@ -146,6 +145,37 @@ namespace IoT.Shared.Infrastructure } } } + else if (method == Methods.EditDataRequest) + { + var model = message.FromJson(); + using (var scope = this.applicationServices.CreateScope()) + { + var dataRepo = scope.ServiceProvider.GetService>(); + var data = dataRepo.Table().FirstOrDefault(o => o.Key == model.Key); + if (data != null) + { + data.From(model); + dataRepo.SaveChanges(); + var dataDto = data.To(); + dataDto.DeviceNumber = model.DeviceNumber; + this.ClientToServer(Methods.EditDataResponse, dataDto.ToJson()); + } + } + } + else if (method == Methods.DeleteDataRequest) + { + using (var scope = this.applicationServices.CreateScope()) + { + var dataRepo = scope.ServiceProvider.GetService>(); + var data = dataRepo.Table().FirstOrDefault(o => o.Key == message); + if (data != null) + { + dataRepo.Delete(data); + dataRepo.SaveChanges(); + this.ClientToServer(Methods.DeleteDataResponse, message); + } + } + } } public void SendNode(NodeDto node) diff --git a/projects/IoTCenter/Areas/Admin/Controllers/IoT/DataController.cs b/projects/IoTCenter/Areas/Admin/Controllers/IoT/DataController.cs index 2eb0834f..16a777dd 100644 --- a/projects/IoTCenter/Areas/Admin/Controllers/IoT/DataController.cs +++ b/projects/IoTCenter/Areas/Admin/Controllers/IoT/DataController.cs @@ -1,12 +1,17 @@ +using System; +using System.Collections.Generic; using System.Linq; using Application.Domain.Entities; using Application.Models; using Infrastructure.Data; using Infrastructure.Extensions; using Infrastructure.Web.Mvc; +using IoTCenter.Services; using IoTShared.Controllers; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.SignalR; +using Microsoft.EntityFrameworkCore; namespace IoTCenter.Areas.Admin.Controllers { @@ -15,10 +20,17 @@ namespace IoTCenter.Areas.Admin.Controllers public class DataController : CrudController { private readonly AjaxController _ajax; + private readonly IHubContext _pageHubContext; - public DataController(IRepository repo, AjaxController ajax) : base(repo) + public DataController(IRepository repo, AjaxController ajax, IHubContext pageHubContext) : base(repo) { this._ajax = ajax; + this._pageHubContext = pageHubContext; + } + + public override IQueryable Include(IQueryable query) + { + return query.Include(o => o.Device); } public override IQueryable Query(DataSearchModel model, IQueryable query) @@ -29,5 +41,41 @@ namespace IoTCenter.Areas.Admin.Controllers .WhereIf(model.DeviceId.HasValue, o => o.DeviceId == model.DeviceId.Value) .WhereIf(!string.IsNullOrEmpty(model.Keyword), o => o.Name.Contains(model.Keyword)); } + + public override void ToModel(Data entity, EditDataModel model) + { + model.DeviceNumber = entity.Device.Number; + } + + public override IActionResult Edit(EditDataModel model) + { + if (ModelState.IsValid) + { + var dataDto = model.To(); + this._pageHubContext.Clients.Group(model.DeviceNumber).SendAsync(Methods.ServerToClient, Methods.EditDataRequest, dataDto.ToJson(), null); + return RedirectTo(); + } + ModelState.AddModelError("", "쳣Ժ"); + return View(model); + } + + public override IActionResult Delete(List list) + { + foreach (var id in list) + { + try + { + var entity = this.repo.Table().Include(o => o.Device).FirstOrDefault(o => o.Id == id); + var number = entity.Device.Number; + this._pageHubContext.Clients.Group(number).SendAsync(Methods.ServerToClient, Methods.DeleteDataRequest, entity.Key, null); + } + catch (Exception ex) + { + ex.PrintStack(); + return RedirectTo(message: ex.Message); + } + } + return RedirectTo(); + } } } \ No newline at end of file diff --git a/projects/IoTCenter/Areas/Admin/Controllers/IoT/DeviceController.cs b/projects/IoTCenter/Areas/Admin/Controllers/IoT/DeviceController.cs index 1ef89544..890be3c1 100644 --- a/projects/IoTCenter/Areas/Admin/Controllers/IoT/DeviceController.cs +++ b/projects/IoTCenter/Areas/Admin/Controllers/IoT/DeviceController.cs @@ -3,7 +3,6 @@ using Application.Models; using Infrastructure.Data; using Infrastructure.Extensions; using Infrastructure.Web.Mvc; -using IoT.Shared.Application.Models; using IoTCenter.Services; using IoTShared.Controllers; using Microsoft.AspNetCore.Authorization; diff --git a/projects/IoTCenter/Areas/Admin/Controllers/IoT/NodeController.cs b/projects/IoTCenter/Areas/Admin/Controllers/IoT/NodeController.cs index fd7adeb7..e8a2493d 100644 --- a/projects/IoTCenter/Areas/Admin/Controllers/IoT/NodeController.cs +++ b/projects/IoTCenter/Areas/Admin/Controllers/IoT/NodeController.cs @@ -4,7 +4,6 @@ using Infrastructure.Application; using Infrastructure.Data; using Infrastructure.Extensions; using Infrastructure.Web.Mvc; -using IoT.Shared.Application.Models; using IoTCenter.Services; using IoTShared.Services; using Microsoft.AspNetCore.Authorization; diff --git a/projects/IoTCenter/Areas/Admin/Controllers/IoT/ProductController.cs b/projects/IoTCenter/Areas/Admin/Controllers/IoT/ProductController.cs new file mode 100644 index 00000000..a1f94380 --- /dev/null +++ b/projects/IoTCenter/Areas/Admin/Controllers/IoT/ProductController.cs @@ -0,0 +1,40 @@ +using System.Linq; +using Application.Domain.Entities; +using Application.Models; +using Infrastructure.Application; +using Infrastructure.Data; +using Infrastructure.Extensions; +using Infrastructure.Web.Mvc; +using IoTCenter.Services; +using IoTShared.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.SignalR; +using Microsoft.EntityFrameworkCore; + +namespace IoTCenter.Areas.Admin.Controllers +{ + [Authorize] + [Area(nameof(Admin))] + public class ProductController : CrudController, EditProductModel, EditProductModel> + { + public ProductController(IRepository repo) : base(repo) + { + } + + public override IQueryable Include(IQueryable query) + { + return query.Include(o => o.Category); + } + + public override void ToModel(Product entity, EditProductModel model) + { + model.CategoryName = entity.Category.Name; + } + + public override void ToDisplayModel(Product entity, EditProductModel model) + { + this.ToModel(entity, model); + } + } +} \ No newline at end of file diff --git a/projects/IoTCenter/Areas/Admin/Views/Shared/_Menu.cshtml b/projects/IoTCenter/Areas/Admin/Views/Shared/_Menu.cshtml index ff034510..2f959a61 100644 --- a/projects/IoTCenter/Areas/Admin/Views/Shared/_Menu.cshtml +++ b/projects/IoTCenter/Areas/Admin/Views/Shared/_Menu.cshtml @@ -5,7 +5,7 @@
  • - 权限管理 + 用户管理 @@ -16,7 +16,7 @@
  • 权限管理
  • -
  • +
  • 设备管理 @@ -25,13 +25,15 @@
  • diff --git a/projects/IoTCenter/Controllers/AppController.cs b/projects/IoTCenter/Controllers/AppController.cs index 6175555f..96ba11d2 100644 --- a/projects/IoTCenter/Controllers/AppController.cs +++ b/projects/IoTCenter/Controllers/AppController.cs @@ -3,7 +3,6 @@ using Application.Models; using Infrastructure.Data; using Infrastructure.Extensions; using Infrastructure.Jwt; -using IoT.Shared.Application.Models; using IoTCenter.Services; using IoTShared.Services; using Microsoft.AspNetCore.Authorization; diff --git a/projects/IoTCenter/Services/HealthCheckService.cs b/projects/IoTCenter/Services/HealthCheckService.cs index be52955e..d5c74eaa 100644 --- a/projects/IoTCenter/Services/HealthCheckService.cs +++ b/projects/IoTCenter/Services/HealthCheckService.cs @@ -1,7 +1,7 @@ using Application.Domain.Entities; +using Application.Models; using Infrastructure.Data; using Infrastructure.Extensions; -using IoT.Shared.Application.Models; using Microsoft.AspNetCore.SignalR; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; diff --git a/projects/IoTCenter/Services/PageHub.cs b/projects/IoTCenter/Services/PageHub.cs index 41971b21..e5a50bbc 100644 --- a/projects/IoTCenter/Services/PageHub.cs +++ b/projects/IoTCenter/Services/PageHub.cs @@ -3,7 +3,6 @@ using Application.Models; using Infrastructure.Data; using Infrastructure.Extensions; using Infrastructure.Web.SignalR; -using IoT.Shared.Application.Models; using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; diff --git a/projects/IoTClient/Assets/StreamingAssets/wwwroot/index.html b/projects/IoTClient/Assets/StreamingAssets/wwwroot/index.html index b556be24..6d5203da 100644 --- a/projects/IoTClient/Assets/StreamingAssets/wwwroot/index.html +++ b/projects/IoTClient/Assets/StreamingAssets/wwwroot/index.html @@ -350,7 +350,7 @@
    {{device.DisplayName||device.Name}}
    - {{getData(device,"电量")}} + {{getData(device,"电量")}} {{getData(device,"状态")}}