场景命令同步

Former-commit-id: 9f915a924170d0080e43c78a44af21ba6f507062
TangShanKaiPing
wanggang 6 years ago
parent ecb5eda905
commit ca111caa20

@ -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; }

@ -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; }

@ -210,6 +210,40 @@ namespace IoT.Shared.Infrastructure
}
this.ClientToServer(Methods.DeleteCommandResponse, message);
}
else if (method == Methods.EditSceneCommandRequest)
{
var model = message.FromJson<EditSceneCommandModel>();
var sceneRepo = scope.ServiceProvider.GetService<IRepository<Scene>>();
var commandRepo = scope.ServiceProvider.GetService<IRepository<Command>>();
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<IRepository<SceneCommand>>();
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<EditCommandModel>();
var sceneCommandRepo = scope.ServiceProvider.GetService<IRepository<SceneCommand>>();
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()

@ -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<SceneCommand> Query(PagedListModel<EditSceneCommandModel> model, IQueryable<SceneCommand> 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);

@ -24,8 +24,8 @@
<li class="@GetClass("Api")"><a href="@Url.Action("Index","Api")"><i class="fa fa-circle-o"></i><span>接口管理</span></a></li>
<li class="@GetClass("Parameter")"><a href="@Url.Action("Index","Parameter")"><i class="fa fa-circle-o"></i><span>参数管理</span></a></li>
<li class="@GetClass("Command")"><a href="@Url.Action("Index","Command")"><i class="fa fa-circle-o"></i><span>命令管理</span></a></li>
<li class="@GetClass("Scene")"><a href="@Url.Action("Index","Scene")"><i class="fa fa-circle-o"></i><span>节点场景管理</span></a></li>
<li class="@GetClass("SceneCommand")"><a href="@Url.Action("Index","SceneCommand")"><i class="fa fa-circle-o"></i><span>节点场景命令管理</span></a></li>
<li class="@GetClass("Scene")"><a href="@Url.Action("Index","Scene")"><i class="fa fa-circle-o"></i><span>场景管理</span></a></li>
<li class="@GetClass("SceneCommand")"><a href="@Url.Action("Index","SceneCommand")"><i class="fa fa-circle-o"></i><span>场景命令管理</span></a></li>
<li class="@GetClass("GlobalScene")"><a href="@Url.Action("Index","GlobalScene")"><i class="fa fa-circle-o"></i><span>全局场景管理</span></a></li>
<li class="@GetClass("GlobalSceneCommand")"><a href="@Url.Action("Index","GlobalSceneCommand")"><i class="fa fa-circle-o"></i><span>全局场景命令管理</span></a></li>
</ul>

@ -27,6 +27,9 @@ namespace IoTCenter.Services
private readonly IRepository<Category> _categoryRepo;
private readonly IRepository<Product> _productRepo;
private readonly IRepository<Scene> _sceneRepo;
private readonly IRepository<SceneCommand> _sceneCommandRepo;
private readonly IRepository<Timer> _timerRepo;
private readonly IRepository<Tigger> _tiggerRepo;
public PageHub(IConfiguration cfg,
IRepository<Node> nodeRepo,
@ -36,7 +39,10 @@ namespace IoTCenter.Services
IRepository<Command> commandRepo,
IRepository<Category> categoryRepo,
IRepository<Product> productRepo,
IRepository<Scene> sceneRepo)
IRepository<Scene> sceneRepo,
IRepository<SceneCommand> sceneCommandRepo,
IRepository<Timer> timerRepo,
IRepository<Tigger> 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<EditSceneCommandModel>();
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<EditSceneCommandModel>();
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))

Loading…
Cancel
Save