|
|
|
@ -8,7 +8,8 @@ using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.Primitives;
|
|
|
|
|
using Platform.Application.Models.IoTCenter;
|
|
|
|
|
using Platform.Areas.IoTCenter.Controllers;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Vibrant.InfluxDB.Client;
|
|
|
|
@ -21,27 +22,46 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls
|
|
|
|
|
[Route("IoTCenter/[controller]/[action]")]
|
|
|
|
|
[Area("IoTCenter")]
|
|
|
|
|
[ControllerScope(ControllerScopeType.Platform)]
|
|
|
|
|
public class IoTDataController : IoTSharedController<IoTData, EditDataModel>
|
|
|
|
|
public class IoTDataController : IoTSharedController<IoTData, EditPlatformIoTDataModel>
|
|
|
|
|
{
|
|
|
|
|
private readonly IConfiguration _configuration;
|
|
|
|
|
private readonly IRepository<IoTGateway> _nodeRepo;
|
|
|
|
|
private readonly AjaxBaseController _ajax;
|
|
|
|
|
private readonly AjaxController _ajax;
|
|
|
|
|
private readonly IRepository<IoTProductCategory> _categoryRepo;
|
|
|
|
|
private readonly IRepository<Organ> _organRepo;
|
|
|
|
|
private readonly IRepository<Building> _buildingRepo;
|
|
|
|
|
|
|
|
|
|
public IoTDataController(IConfiguration configuration, IRepository<IoTGateway> nodeRepo, IRepository<IoTData> repo, AjaxBaseController ajax, IServiceProvider sp) : base(repo, sp)
|
|
|
|
|
public IoTDataController(IConfiguration configuration,
|
|
|
|
|
IRepository<IoTGateway> nodeRepo,
|
|
|
|
|
IRepository<IoTData> repo,
|
|
|
|
|
AjaxController ajax,
|
|
|
|
|
IRepository<IoTProductCategory> categoryRepo,
|
|
|
|
|
IRepository<Organ> organRepo,
|
|
|
|
|
IRepository<Building> buildingRepo,
|
|
|
|
|
IServiceProvider sp) : base(repo, sp)
|
|
|
|
|
{
|
|
|
|
|
this._configuration = configuration;
|
|
|
|
|
this._nodeRepo = nodeRepo;
|
|
|
|
|
this._ajax = ajax;
|
|
|
|
|
this._categoryRepo = categoryRepo;
|
|
|
|
|
this._organRepo = organRepo;
|
|
|
|
|
this._buildingRepo = buildingRepo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override IQueryable<IoTData> Include(IQueryable<IoTData> query)
|
|
|
|
|
{
|
|
|
|
|
return query.Include(o => o.Device).ThenInclude(o => o.Node);
|
|
|
|
|
return query.Include(o => o.Device).ThenInclude(o => o.Node).ThenInclude(o => o.Building).ThenInclude(o => o.Organ)
|
|
|
|
|
.Include(o => o.Device).ThenInclude(o => o.Product).ThenInclude(o => o.Category);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override IQueryable<IoTData> Query(PagedListModel<EditDataModel> model, IQueryable<IoTData> query)
|
|
|
|
|
public override IQueryable<IoTData> Query(PagedListModel<EditPlatformIoTDataModel> model, IQueryable<IoTData> query)
|
|
|
|
|
{
|
|
|
|
|
return query.WhereIf(model.Query.IoTGatewayId.HasValue, o => o.Device.NodeId == model.Query.IoTGatewayId.Value)
|
|
|
|
|
return query.WhereIf(model.Query.NodeId.HasValue, o => o.Device.NodeId == model.Query.NodeId.Value)
|
|
|
|
|
.WhereIf(model.Query.OrganId.HasValue, o => o.Device.Node.Building.OrganId == model.Query.OrganId.Value)
|
|
|
|
|
.WhereIf(model.Query.BuildingId.HasValue, o => o.Device.Node.BuildingId == model.Query.BuildingId.Value)
|
|
|
|
|
.WhereIf(model.Query.NodeId.HasValue, o => o.Device.NodeId == model.Query.NodeId.Value)
|
|
|
|
|
.WhereIf(model.Query.CategoryId.HasValue, o => o.Device.Product.CategoryId == model.Query.CategoryId.Value)
|
|
|
|
|
.WhereIf(model.Query.ProductId.HasValue, o => o.Device.ProductId == model.Query.ProductId.Value)
|
|
|
|
|
.WhereIf(model.Query.DeviceId.HasValue, o => o.DeviceId == model.Query.DeviceId.Value)
|
|
|
|
|
.WhereIf(!string.IsNullOrEmpty(model.Query.Name), o => o.Name.Contains(model.Query.Name))
|
|
|
|
|
.WhereIf(!string.IsNullOrEmpty(model.Query.Key), o => o.Key.Contains(model.Query.Key))
|
|
|
|
@ -51,29 +71,84 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls
|
|
|
|
|
.WhereIf(!string.IsNullOrEmpty(model.Query.Description), o => o.Description.Contains(model.Query.Description))
|
|
|
|
|
.WhereIf(model.Query.Timestamp.HasValue, o => o.Timestamp == model.Query.Timestamp.Value)
|
|
|
|
|
.WhereIf(model.Query.Hidden.HasValue, o => o.Hidden == model.Query.Hidden.Value)
|
|
|
|
|
.OrderBy(o => o.Device.ProductId).ThenBy(o=>o.Device.NodeId).ThenBy(o => o.DeviceId);
|
|
|
|
|
.OrderBy(o => o.Device.ProductId).ThenBy(o => o.Device.NodeId).ThenBy(o => o.DeviceId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void ToDisplayModel(IoTData entity, EditDataModel model)
|
|
|
|
|
public override void ToDisplayModel(IoTData entity, EditPlatformIoTDataModel model)
|
|
|
|
|
{
|
|
|
|
|
model.IoTGatewayId = entity?.Device?.NodeId;
|
|
|
|
|
ViewData.Add(model.DeviceId, entity?.Device?.Name);
|
|
|
|
|
ViewData.Add(model.IoTGatewayId, entity?.Device?.Node?.Name);
|
|
|
|
|
if (entity != null)
|
|
|
|
|
{
|
|
|
|
|
model.ProductId = entity.Device.ProductId;
|
|
|
|
|
model.CategoryId = entity.Device.Product.CategoryId;
|
|
|
|
|
model.NodeId = entity.Device.NodeId;
|
|
|
|
|
model.BuildingId = entity.Device.Node.BuildingId;
|
|
|
|
|
model.OrganId = entity.Device.Node.Building.OrganId;
|
|
|
|
|
}
|
|
|
|
|
if (model.BuildingId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var name = this._buildingRepo.ReadOnlyTable()
|
|
|
|
|
.Where(o => o.ParentId != null)
|
|
|
|
|
.Where(o => o.Left <= entity.Device.Node.Building.Left && o.Right >= entity.Device.Node.Building.Right)
|
|
|
|
|
.ToList()
|
|
|
|
|
.ToTree()
|
|
|
|
|
.FirstOrDefault(o => o.Id == model.BuildingId.Value)?.GetDisplayName();
|
|
|
|
|
ViewData.Add(model.BuildingId.Value, name);
|
|
|
|
|
}
|
|
|
|
|
if (model.OrganId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var name = this._organRepo.ReadOnlyTable()
|
|
|
|
|
.Where(o => o.ParentId != null)
|
|
|
|
|
.Where(o => o.Left <= entity.Device.Node.Building.Organ.Left && o.Right >= entity.Device.Node.Building.Organ.Right)
|
|
|
|
|
.ToList()
|
|
|
|
|
.ToTree()
|
|
|
|
|
.FirstOrDefault(o => o.Id == entity.Device.Node.Building.OrganId)?.GetDisplayName();
|
|
|
|
|
ViewData.Add(model.OrganId, name);
|
|
|
|
|
}
|
|
|
|
|
if (model.ProductId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
ViewData.Add(model.ProductId, entity.Device.Product.Name);
|
|
|
|
|
}
|
|
|
|
|
if (model.CategoryId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var name = this._categoryRepo.ReadOnlyTable()
|
|
|
|
|
.Where(o => o.ParentId != null)
|
|
|
|
|
.Where(o => o.Left <= entity.Device.Product.Category.Left && o.Right >= entity.Device.Product.Category.Right)
|
|
|
|
|
.ToList()
|
|
|
|
|
.ToTree()
|
|
|
|
|
.FirstOrDefault(o => o.Id == model.CategoryId.Value)?.GetDisplayName();
|
|
|
|
|
ViewData.Add(model.CategoryId, name);
|
|
|
|
|
}
|
|
|
|
|
if (model.DeviceId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
ViewData.Add(model.DeviceId, entity.Device.Name);
|
|
|
|
|
}
|
|
|
|
|
if (model.NodeId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
ViewData.Add(model.NodeId, entity.Device.Node.Name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void ToEditModel(IoTData entity, EditDataModel model)
|
|
|
|
|
public override void ToEditModel(IoTData entity, EditPlatformIoTDataModel model)
|
|
|
|
|
{
|
|
|
|
|
model.IoTGatewayId = entity?.Device?.NodeId;
|
|
|
|
|
ViewData.SelectList(o => model.IoTGatewayId, () => this._ajax.GetIoTGateway(model.IoTGatewayId).SelectList());
|
|
|
|
|
if(model.IoTGatewayId.HasValue)
|
|
|
|
|
if (entity != null)
|
|
|
|
|
{
|
|
|
|
|
ViewData.SelectList(o => model.DeviceId, () => this._ajax.GetIoTDevice(model.IoTGatewayId.Value, model.DeviceId).SelectList());
|
|
|
|
|
model.BuildingId = entity.Device.Node.BuildingId;
|
|
|
|
|
model.OrganId = entity.Device.Node.Building.OrganId;
|
|
|
|
|
model.CategoryId = entity.Device.Product.CategoryId;
|
|
|
|
|
model.BuildingId = entity.Device.Node.BuildingId;
|
|
|
|
|
model.OrganId = entity.Device.Node.Building.OrganId;
|
|
|
|
|
}
|
|
|
|
|
ViewData.SelectList(o => model.OrganId, () => this._ajax.GetOrgan(model.OrganId).SelectList());
|
|
|
|
|
ViewData.SelectList(o => model.BuildingId, () => this._ajax.GetBuilding(model.OrganId.Value, model.BuildingId).SelectList(), model.OrganId.HasValue);
|
|
|
|
|
ViewData.SelectList(o => model.NodeId, () => this._ajax.GetIoTGatewayByBuilding(model.BuildingId.Value, model.NodeId).SelectList(), model.BuildingId.HasValue);
|
|
|
|
|
ViewData.SelectList(o => model.DeviceId, () => this._ajax.GetIoTDevice(model.NodeId.Value, model.DeviceId).SelectList(), model.NodeId.HasValue);
|
|
|
|
|
ViewData.SelectList(o => model.CategoryId, () => this._ajax.GetIoTProductCategory(model.CategoryId).SelectList());
|
|
|
|
|
ViewData.SelectList(o => model.ProductId, () => this._ajax.GetIoTProductByCategory(model.CategoryId.Value, model.ProductId).SelectList(), model.CategoryId.HasValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string GetNodeNumber(EditDataModel model)
|
|
|
|
|
public override string GetNodeNumber(EditPlatformIoTDataModel model)
|
|
|
|
|
{
|
|
|
|
|
return this._nodeRepo.ReadOnlyTable().Where(o => o.Id == model.IoTGatewayId).Select(o => o.Number).FirstOrDefault();
|
|
|
|
|
return this._nodeRepo.ReadOnlyTable().Where(o => o.Id == model.NodeId).Select(o => o.Number).FirstOrDefault();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|