后台管理部分完成

Former-commit-id: 740f96251dbcd0b19abce138885c0fc772546d55
TangShanKaiPing
wanggang 6 years ago
parent 76e46f0afc
commit 5f9ef2bb86

Binary file not shown.

@ -25,11 +25,6 @@ namespace Application.Domain.Entities
/// </summary>
public Node Node { get; set; }
/// <summary>
/// 命令
/// </summary>
public List<Command> Commands { get; set; } = new List<Command>();
public List<SceneCommand> SceneCommands { get; set; } = new List<SceneCommand>();
}
}

@ -179,7 +179,7 @@ namespace IoTCenter.Services
this._dataService.Edit<Data, EditDataModel>(model);
this._eventPublisher.Publish(new EntityUpdatedEvent<Data>(model.To<Data>()));
//
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)}")//删除数据返回

@ -27,6 +27,8 @@ namespace IoTCenter.Controllers
private readonly IJwtHelper _jwtHelper;
private readonly IRepository<Node> _nodeRepo;
private readonly IRepository<Scene> _sceneRepo;
private readonly IRepository<SceneCommand> _sceneCommandRepo;
private readonly IRepository<Command> _commandRepo;
private readonly IRepository<Device> _deviceRepo;
private readonly IRepository<LiveRecord> _liveRecordRepo;
private readonly IHubContext<IoTCenterHub> _hub;
@ -35,6 +37,8 @@ namespace IoTCenter.Controllers
IJwtHelper jwtHelper,
IRepository<Node> nodeRepo,
IRepository<Scene> sceneRepo,
IRepository<SceneCommand> sceneCommandRepo,
IRepository<Command> commandRepo,
IRepository<Device> deviceRepo,
IRepository<LiveRecord> liveRecordRepo,
IHubContext<IoTCenterHub> 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);

@ -19,6 +19,7 @@ namespace IoTCenter.Controllers
public class HomeController : Controller
{
private readonly IConfiguration _cfg;
private readonly IRepository<Scene> _sceneRepo;
private readonly IRepository<Node> _nodeRepo;
private readonly IRepository<Device> _deviceRepo;
private readonly IRepository<Data> _dataRepo;
@ -27,6 +28,7 @@ namespace IoTCenter.Controllers
private readonly IEventPublisher _eventPublisher;
public HomeController(IConfiguration cfg,
IRepository<Scene> sceneRepo,
IRepository<Node> nodeRepo,
IRepository<Device> deviceRepo,
IRepository<Data> 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);

@ -115,6 +115,13 @@
</table>
</div>
</div>
<div class="col-md-12">
<div class="box box-solid">
<div class="row">
<button class="btn btn-block btn-info ajax GlobalScene" v-for="scene in ViewModel.Scenes" :data-scene-id="scene.Id">{{scene.Name}}</button>
</div>
</div>
</div>
</div>
<div class="row" v-if="ViewModel">
<div class="col-md-4" v-for="node in ViewModel.Nodes">
@ -141,7 +148,7 @@
<div class="row" v-if="node.Scenes.length">
<template v-for="scene in node.Scenes">
<div class="col-md-3" v-if="scene.Tag=='home'">
<button class="btn btn-block btn-info ajax Scene" :data-node-number="node.Number" :data-scene-name="scene.Name">{{scene.Name}}</button>
<button class="btn btn-block btn-info ajax Scene" :data-scene-id="scene.Id">{{scene.Name}}</button>
</div>
</template>
</div>
@ -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;
});

@ -450,6 +450,10 @@
<button class="btn bg-olive margin ajax SocketOff">插座关</button>
<br />
<button class="btn bg-olive margin ajax Scene" v-for="scene in ViewModel.Scenes" :data-scene-id="scene.Id">{{scene.Name}}</button>
<br />
<template v-for="device in ViewModel.Devices">
<button class="btn bg-olive margin ajax Command" v-for="command in device.Commands" :data-command-id="command.Id">{{command.Name}}</button>
</template>
</div>
</div>
</div>
@ -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;
});

Loading…
Cancel
Save