diff --git a/docs/研发/v1.0任务分解.xlsx b/docs/研发/v1.0任务分解.xlsx index bf032897..67ef239e 100644 Binary files a/docs/研发/v1.0任务分解.xlsx and b/docs/研发/v1.0任务分解.xlsx differ diff --git a/projects/IoT.Shared/Application/Domain/Entities/Scene.cs b/projects/IoT.Shared/Application/Domain/Entities/Scene.cs index c0c31c93..835fafd3 100644 --- a/projects/IoT.Shared/Application/Domain/Entities/Scene.cs +++ b/projects/IoT.Shared/Application/Domain/Entities/Scene.cs @@ -25,11 +25,6 @@ namespace Application.Domain.Entities /// public Node Node { get; set; } - /// - /// 命令 - /// - public List Commands { get; set; } = new List(); - public List SceneCommands { get; set; } = new List(); } } \ No newline at end of file diff --git a/projects/IoT.Shared/Services/IoTCenter/IoTCenterHub.cs b/projects/IoT.Shared/Services/IoTCenter/IoTCenterHub.cs index 915c4426..194ab8b7 100644 --- a/projects/IoT.Shared/Services/IoTCenter/IoTCenterHub.cs +++ b/projects/IoT.Shared/Services/IoTCenter/IoTCenterHub.cs @@ -179,7 +179,7 @@ namespace IoTCenter.Services this._dataService.Edit(model); this._eventPublisher.Publish(new EntityUpdatedEvent(model.To())); // - var device = _deviceRepo.ReadOnlyTable().Include(o => o.Data).Where(o => o.Id == model.DeviceId).FirstOrDefault(); + var device = _deviceRepo.ReadOnlyTable().Include(o => o.Data).Include(o => o.Commands).Where(o => o.Id == model.DeviceId).FirstOrDefault(); this.Clients.Group("page").SendAsync("UpdateDevice", device.ToJson()); } else if (method == $"Delete{nameof(Data)}")//删除数据返回 diff --git a/projects/IoTCenter/Controllers/AppController.cs b/projects/IoTCenter/Controllers/AppController.cs index 28924954..9528eaa0 100644 --- a/projects/IoTCenter/Controllers/AppController.cs +++ b/projects/IoTCenter/Controllers/AppController.cs @@ -27,6 +27,8 @@ namespace IoTCenter.Controllers private readonly IJwtHelper _jwtHelper; private readonly IRepository _nodeRepo; private readonly IRepository _sceneRepo; + private readonly IRepository _sceneCommandRepo; + private readonly IRepository _commandRepo; private readonly IRepository _deviceRepo; private readonly IRepository _liveRecordRepo; private readonly IHubContext _hub; @@ -35,6 +37,8 @@ namespace IoTCenter.Controllers IJwtHelper jwtHelper, IRepository nodeRepo, IRepository sceneRepo, + IRepository sceneCommandRepo, + IRepository commandRepo, IRepository deviceRepo, IRepository liveRecordRepo, IHubContext hub) @@ -43,6 +47,8 @@ namespace IoTCenter.Controllers this._jwtHelper = jwtHelper; this._nodeRepo = nodeRepo; this._sceneRepo = sceneRepo; + this._sceneCommandRepo = sceneCommandRepo; + this._commandRepo = commandRepo; this._deviceRepo = deviceRepo; this._liveRecordRepo = liveRecordRepo; this._hub = hub; @@ -74,6 +80,15 @@ namespace IoTCenter.Controllers return Json(model); } + public IActionResult GetSceneList(string token) + { + var userName = this._jwtHelper.GetPayload(token)["UserName"].ToString(); + var model = this._sceneRepo.ReadOnlyTable() + .Where(o => o.NodeId == null) + .ToList(); + return Json(model); + } + public IActionResult GetNode(string token, string number) { var userName = this._jwtHelper.GetPayload(token)["UserName"].ToString(); @@ -81,6 +96,8 @@ namespace IoTCenter.Controllers .Include(o => o.Scenes) .Include(o => o.Devices) .ThenInclude(o => o.Data) + .Include(o => o.Devices) + .ThenInclude(o => o.Commands) .FirstOrDefault(o => o.Number == number); return Json(model); } @@ -157,6 +174,52 @@ namespace IoTCenter.Controllers } } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:不捕获常规异常类型", Justification = "<挂起>")] + public IActionResult ExecGlobalScene(string connectionId, Guid id) + { + try + { + var commands = this._sceneCommandRepo.ReadOnlyTable() + .Include(o => o.Command).ThenInclude(o => o.Device).ThenInclude(o => o.Node) + .Where(o => o.SceneId == id) + .Select(o => o.Command) + .ToList(); + foreach (var command in commands) + { + try + { + this._hub.ServerToClient(command.Device.Node.Number, Methods.ExecCommand, command.Id, connectionId); + } + catch (Exception ex) + { + ex.PrintStack(); + } + } + return Json(ApiResponse.AsyncSuccess()); + } + catch (Exception ex) + { + ex.PrintStack(); + return Json(ApiResponse.Error(ex)); + } + } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:不捕获常规异常类型", Justification = "<挂起>")] + public IActionResult ExecCommand(string connectionId, Guid id) + { + try + { + var command = this._commandRepo.ReadOnlyTable().Include(o => o.Device).ThenInclude(o => o.Node).FirstOrDefault(o => o.Id == id); + this._hub.ServerToClient(command.Device.Node.Number, Methods.ExecCommand, command.Id, connectionId); + return Json(ApiResponse.AsyncSuccess()); + } + catch (Exception ex) + { + ex.PrintStack(); + return Json(ApiResponse.Error(ex)); + } + } + public IActionResult Data(Guid id, string time = "10m") { var device = this._deviceRepo.ReadOnlyTable().Include(o => o.Node).Include(o => o.Data).FirstOrDefault(o => o.Id == id); diff --git a/projects/IoTCenter/Controllers/HomeController.cs b/projects/IoTCenter/Controllers/HomeController.cs index 4c3e49ab..917e13ed 100644 --- a/projects/IoTCenter/Controllers/HomeController.cs +++ b/projects/IoTCenter/Controllers/HomeController.cs @@ -19,6 +19,7 @@ namespace IoTCenter.Controllers public class HomeController : Controller { private readonly IConfiguration _cfg; + private readonly IRepository _sceneRepo; private readonly IRepository _nodeRepo; private readonly IRepository _deviceRepo; private readonly IRepository _dataRepo; @@ -27,6 +28,7 @@ namespace IoTCenter.Controllers private readonly IEventPublisher _eventPublisher; public HomeController(IConfiguration cfg, + IRepository sceneRepo, IRepository nodeRepo, IRepository deviceRepo, IRepository dataRepo, @@ -35,6 +37,7 @@ namespace IoTCenter.Controllers IEventPublisher eventPublisher) { this._cfg = cfg; + this._sceneRepo = sceneRepo; this._nodeRepo = nodeRepo; this._deviceRepo = deviceRepo; this._dataRepo = dataRepo; @@ -117,7 +120,8 @@ namespace IoTCenter.Controllers data = energy.Select(o => o.Sum), labels = energy.Select(o => o.Key) }, - Nodes = this._nodeRepo.ReadOnlyTable().Where(o => !o.Disabled).Include(o => o.Scenes).ToList() + Nodes = this._nodeRepo.ReadOnlyTable().Where(o => !o.Disabled).Include(o => o.Scenes).ToList(), + Scenes = this._sceneRepo.ReadOnlyTable().Where(o => o.NodeId == null).ToList() }; return Json(model); } @@ -136,6 +140,8 @@ namespace IoTCenter.Controllers .Include(o => o.Scenes) .Include(o => o.Devices) .ThenInclude(o => o.Data) + .Include(o => o.Devices) + .ThenInclude(o => o.Commands) .Where(o => o.Number == number) .FirstOrDefault(); return Json(model); diff --git a/projects/IoTCenter/wwwroot/home.html b/projects/IoTCenter/wwwroot/home.html index 776b9edd..0db2d434 100644 --- a/projects/IoTCenter/wwwroot/home.html +++ b/projects/IoTCenter/wwwroot/home.html @@ -115,6 +115,13 @@ +
+
+
+ +
+
+
@@ -141,7 +148,7 @@
@@ -289,7 +296,9 @@ } else if ($(this).hasClass('NodeSocketOff')) { ajax('/App/NodeSocketOff', { node: $(this).attr('data-node-number') }, 'post'); } else if ($(this).hasClass('Scene')) { - ajax('/App/Scene', { node: $(this).attr('data-node-number'), name: $(this).attr('data-scene-name') }, 'post'); + ajax('/App/ExecScene', { connectionId: connectionId, id: $(this).attr('data-scene-id') }, 'post'); + } else if ($(this).hasClass('GlobalScene')) { + ajax('/App/ExecGlobalScene', { connectionId: connectionId, id: $(this).attr('data-scene-id') }, 'post'); } return false; }); diff --git a/projects/IoTCenter/wwwroot/node.html b/projects/IoTCenter/wwwroot/node.html index 48e9404c..4413cb90 100644 --- a/projects/IoTCenter/wwwroot/node.html +++ b/projects/IoTCenter/wwwroot/node.html @@ -450,6 +450,10 @@
+
+
@@ -858,6 +862,8 @@ ajax('/App/NodeSocketOff', { node: $(this).attr('data-node-number') }, 'post'); } else if ($(this).hasClass('Scene')) { ajax('/App/ExecScene', { connectionId: connectionId, id: $(this).attr('data-scene-id') }, 'post'); + }else if ($(this).hasClass('Command')) { + ajax('/App/ExecCommand', { connectionId: connectionId, id: $(this).attr('data-command-id') }, 'post'); } return false; });