From 774c6cdf6c36d6409809c6a2bfe3e2ba301ee074 Mon Sep 17 00:00:00 2001 From: wanggang <76527413@qq.com> Date: Wed, 7 Aug 2019 15:27:59 +0800 Subject: [PATCH] update Former-commit-id: 999889b790069af9dfb0ff308fc188e934599fd0 --- .../Application/Domain/Entities/LiveRecord.cs | 11 ++++++++++ projects/IoT/IoT.Shared/IoTServiceStartup.cs | 1 + .../IoTCenter/Controllers/AppController.cs | 20 ++++++++++++++++--- 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 projects/IoT/IoT.Shared/Application/Domain/Entities/LiveRecord.cs diff --git a/projects/IoT/IoT.Shared/Application/Domain/Entities/LiveRecord.cs b/projects/IoT/IoT.Shared/Application/Domain/Entities/LiveRecord.cs new file mode 100644 index 00000000..8cf019d1 --- /dev/null +++ b/projects/IoT/IoT.Shared/Application/Domain/Entities/LiveRecord.cs @@ -0,0 +1,11 @@ +using Infrastructure.Domain; + +namespace Application.Domain.Entities +{ + public class LiveRecord : BaseEntity + { + public string DeviceNumber { get; set; } + public string Name { get; set; } + public string Value { get; set; } + } +} \ No newline at end of file diff --git a/projects/IoT/IoT.Shared/IoTServiceStartup.cs b/projects/IoT/IoT.Shared/IoTServiceStartup.cs index 806e38a1..a743a5ae 100644 --- a/projects/IoT/IoT.Shared/IoTServiceStartup.cs +++ b/projects/IoT/IoT.Shared/IoTServiceStartup.cs @@ -92,6 +92,7 @@ namespace IoT.UI.Shard modelBuilder.Entity().HasOne(o => o.Node).WithMany(o => o.Devices).HasForeignKey(o => o.NodeId).OnDelete(DeleteBehavior.Cascade); modelBuilder.Entity().HasOne(o => o.Device).WithMany(o => o.Data).HasForeignKey(o => o.DeviceId); modelBuilder.Entity().HasOne(o => o.Api).WithMany(o => o.Parameters).HasForeignKey(o => o.ApiId); + modelBuilder.Entity().Property(o => o.DeviceNumber).IsRequired(); modelBuilder.Entity().HasOne(o => o.Node).WithMany(o => o.Scenes).HasForeignKey(o => o.NodeId); modelBuilder.Entity().HasOne(o => o.Scene).WithMany(o => o.Commands).HasForeignKey(o => o.SceneId); modelBuilder.Entity().HasOne(o => o.Api).WithMany(o => o.Commands).HasForeignKey(o => o.ApiId); diff --git a/projects/IoTCenter/Controllers/AppController.cs b/projects/IoTCenter/Controllers/AppController.cs index 674f6a92..bf1bd264 100644 --- a/projects/IoTCenter/Controllers/AppController.cs +++ b/projects/IoTCenter/Controllers/AppController.cs @@ -26,18 +26,21 @@ namespace IoTCenter.Controllers private readonly IJwtHelper _jwtHelper; private readonly IRepository _nodeRepo; private readonly IRepository _deviceRepo; + private readonly IRepository _liveRecordRepo; private readonly IHubContext _pageHubContext; public AppController(IConfiguration configuration, IJwtHelper jwtHelper, IRepository nodeRepo, IRepository deviceRepo, + IRepository liveRecordRepo, IHubContext pageHubContext) { this._configuration = configuration; this._jwtHelper = jwtHelper; this._nodeRepo = nodeRepo; this._deviceRepo = deviceRepo; + this._liveRecordRepo = liveRecordRepo; this._pageHubContext = pageHubContext; } @@ -171,9 +174,20 @@ namespace IoTCenter.Controllers { using (var reader = new StreamReader(Request.Body)) { - var body = reader.ReadToEnd(); - - // Do something + var json = reader.ReadToEnd(); + var result = JsonConvert.DeserializeObject>(json); + if (result["action"] == "on_dvr") + { + var streamId = result["stream"]; + var deviceNumber = streamId.StartsWith("main") ? streamId.Substring(4) : streamId.Substring(3); + this._liveRecordRepo.Add(new LiveRecord + { + DeviceNumber = deviceNumber, + Name = "回放", + Value = $"live{result["file"].Substring(result["file"].LastIndexOf('/'))}" + }); + this._liveRecordRepo.SaveChanges(); + } } return Content(string.Empty); }