diff --git a/projects/IoT/IoT.Shared/Application/Domain/Entities/Tigger.cs b/projects/IoT/IoT.Shared/Application/Domain/Entities/Tigger.cs index f61cbc95..eb57b212 100644 --- a/projects/IoT/IoT.Shared/Application/Domain/Entities/Tigger.cs +++ b/projects/IoT/IoT.Shared/Application/Domain/Entities/Tigger.cs @@ -6,17 +6,14 @@ namespace Application.Domain.Entities { public class Tigger : BaseEntity { - [Required] public string Name { get; set; } public string Condition { get; set; } - [Required] public Guid DataId { get; set; } public Data Data { get; set; } - [Required] public Guid SceneId { get; set; } public Scene Scene { get; set; } diff --git a/projects/IoT/IoT.Shared/Application/Domain/Entities/Timer.cs b/projects/IoT/IoT.Shared/Application/Domain/Entities/Timer.cs index 4789a129..3bdf72ee 100644 --- a/projects/IoT/IoT.Shared/Application/Domain/Entities/Timer.cs +++ b/projects/IoT/IoT.Shared/Application/Domain/Entities/Timer.cs @@ -6,12 +6,10 @@ namespace Application.Domain.Entities { public class Timer : BaseEntity { - [Required] public string Name { get; set; } public string Cron { get; set; } - [Required] public Guid SceneId { get; set; } public Scene Scene { get; set; } diff --git a/projects/IoT/IoT.Shared/Infrastructure/ClientService.cs b/projects/IoT/IoT.Shared/Infrastructure/ClientService.cs index 5e377d90..5030b875 100644 --- a/projects/IoT/IoT.Shared/Infrastructure/ClientService.cs +++ b/projects/IoT/IoT.Shared/Infrastructure/ClientService.cs @@ -210,6 +210,40 @@ namespace IoT.Shared.Infrastructure } this.ClientToServer(Methods.DeleteCommandResponse, message); } + else if (method == Methods.EditSceneCommandRequest) + { + var model = message.FromJson(); + var sceneRepo = scope.ServiceProvider.GetService>(); + var commandRepo = scope.ServiceProvider.GetService>(); + var scene = sceneRepo.Table().FirstOrDefault(o => o.Id == model.Id); + var command = commandRepo.Table().FirstOrDefault(o => o.Id == model.Id); + var sceneCommandRepo = scope.ServiceProvider.GetService>(); + var sceneCommand = sceneCommandRepo.Table().FirstOrDefault(o => o.Id == model.Id); + if (sceneCommand == null) + { + sceneCommand = new SceneCommand + { + Id = model.Id + }; + sceneCommandRepo.Add(sceneCommand); + } + sceneCommand.SceneId = model.SceneId.Value; + sceneCommand.CommandId = model.CommandId.Value; + sceneCommandRepo.SaveChanges(); + this.ClientToServer(Methods.EditSceneCommandResponse, message); + } + else if (method == Methods.DeleteSceneCommandRequest) + { + var model = message.FromJson(); + var sceneCommandRepo = scope.ServiceProvider.GetService>(); + var sceneCommand = sceneCommandRepo.Table().FirstOrDefault(o => o.Id == model.Id); + if (sceneCommand != null) + { + sceneCommandRepo.Delete(sceneCommand); + sceneCommandRepo.SaveChanges(); + } + this.ClientToServer(Methods.DeleteSceneCommandResponse, message); + } } private void UpdateServer() diff --git a/projects/IoTCenter/Areas/Admin/Controllers/IoT/SceneCommandController.cs b/projects/IoTCenter/Areas/Admin/Controllers/IoT/SceneCommandController.cs index 9905945c..d0ec1df2 100644 --- a/projects/IoTCenter/Areas/Admin/Controllers/IoT/SceneCommandController.cs +++ b/projects/IoTCenter/Areas/Admin/Controllers/IoT/SceneCommandController.cs @@ -43,12 +43,18 @@ namespace IoTCenter.Areas.Admin.Controllers { return query.Include(o => o.Scene).ThenInclude(o => o.Node).Include(o => o.Command).ThenInclude(o => o.Device); } + public override IQueryable Query(PagedListModel model, IQueryable query) { return query.Where(o => o.Scene.NodeId != null); } + public override void ToModel(SceneCommand entity, EditSceneCommandModel model) { + if (entity != null) + { + model.NodeId = entity.Scene.NodeId; + } ViewData.SelectList(o => model.NodeId, () => this._ajax.GetNodeSelectList(model.SceneId)); ViewData.SelectList(o => model.SceneId, () => this._ajax.GetSceneSelectList(model.NodeId.Value, model.SceneId), model.NodeId.HasValue); ViewData.SelectList(o => model.CommandId, () => this._ajax.GetCommandSelectList(model.NodeId.Value, model.CommandId), model.NodeId.HasValue); diff --git a/projects/IoTCenter/Areas/Admin/Views/Shared/_Menu.cshtml b/projects/IoTCenter/Areas/Admin/Views/Shared/_Menu.cshtml index e09cc122..c6543f90 100644 --- a/projects/IoTCenter/Areas/Admin/Views/Shared/_Menu.cshtml +++ b/projects/IoTCenter/Areas/Admin/Views/Shared/_Menu.cshtml @@ -24,8 +24,8 @@
  • 接口管理
  • 参数管理
  • 命令管理
  • -
  • 节点场景管理
  • -
  • 节点场景命令管理
  • +
  • 场景管理
  • +
  • 场景命令管理
  • 全局场景管理
  • 全局场景命令管理
  • diff --git a/projects/IoTCenter/Services/PageHub.cs b/projects/IoTCenter/Services/PageHub.cs index 87983e88..1911652a 100644 --- a/projects/IoTCenter/Services/PageHub.cs +++ b/projects/IoTCenter/Services/PageHub.cs @@ -27,6 +27,9 @@ namespace IoTCenter.Services private readonly IRepository _categoryRepo; private readonly IRepository _productRepo; private readonly IRepository _sceneRepo; + private readonly IRepository _sceneCommandRepo; + private readonly IRepository _timerRepo; + private readonly IRepository _tiggerRepo; public PageHub(IConfiguration cfg, IRepository nodeRepo, @@ -36,7 +39,10 @@ namespace IoTCenter.Services IRepository commandRepo, IRepository categoryRepo, IRepository productRepo, - IRepository sceneRepo) + IRepository sceneRepo, + IRepository sceneCommandRepo, + IRepository timerRepo, + IRepository tiggerRepo) { this._cfg = cfg; this._nodeRepo = nodeRepo; @@ -47,6 +53,9 @@ namespace IoTCenter.Services this._categoryRepo = categoryRepo; this._productRepo = productRepo; this._sceneRepo = sceneRepo; + this._sceneCommandRepo = sceneCommandRepo; + this._timerRepo = timerRepo; + this._tiggerRepo = tiggerRepo; } public override void ClientToServer(string method, string message, string connectionId) @@ -115,6 +124,14 @@ namespace IoTCenter.Services { this.DeleteCommand(message); } + else if (method == Methods.EditSceneCommandResponse) + { + this.UpdateSceneCommand(message); + } + else if (method == Methods.DeleteSceneCommandResponse) + { + this.DeleteSceneCommand(message); + } } private void RefreshDeviceList(string message, string connectionId) @@ -409,6 +426,52 @@ namespace IoTCenter.Services } } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:不捕获常规异常类型", Justification = "<挂起>")] + private void UpdateSceneCommand(string message) + { + try + { + Console.WriteLine("iot center> receive edit scene command message"); + var model = message.FromJson(); + var sceneCommand = _sceneCommandRepo.Table().FirstOrDefault(o => o.Id == model.Id); + if (sceneCommand == null) + { + sceneCommand = new SceneCommand + { + Id = model.Id + }; + _sceneCommandRepo.Add(sceneCommand); + } + sceneCommand.SceneId = model.SceneId.Value; + sceneCommand.CommandId = model.CommandId.Value; + _sceneCommandRepo.SaveChanges(); + } + catch (Exception ex) + { + ex.PrintStack(); + } + } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:不捕获常规异常类型", Justification = "<挂起>")] + private void DeleteSceneCommand(string message) + { + try + { + Console.WriteLine("iot center> receive delete scene command message"); + var model = message.FromJson(); + var sceneCommand = _sceneCommandRepo.Table().FirstOrDefault(o => o.Id == model.Id); + if (sceneCommand != null) + { + _sceneCommandRepo.Delete(sceneCommand); + _sceneCommandRepo.SaveChanges(); + } + } + catch (Exception ex) + { + ex.PrintStack(); + } + } + public void ApiCallback(string message, string connectionId) { if (!string.IsNullOrEmpty(connectionId)) diff --git a/projects/IoTCenter/iotcenter.db-shm b/projects/IoTCenter/iotcenter.db-shm deleted file mode 100644 index 31767073..00000000 Binary files a/projects/IoTCenter/iotcenter.db-shm and /dev/null differ diff --git a/projects/IoTCenter/iotcenter.db-wal b/projects/IoTCenter/iotcenter.db-wal deleted file mode 100644 index 298f4a4c..00000000 Binary files a/projects/IoTCenter/iotcenter.db-wal and /dev/null differ