|
|
|
@ -7,6 +7,7 @@ using IoT.Shared.Application.Models;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Platform.Application.Models.IoTCenter;
|
|
|
|
|
using Platform.Areas.IoTCenter.Controllers;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
@ -18,27 +19,39 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls
|
|
|
|
|
[Route("IoTCenter/[controller]/[action]")]
|
|
|
|
|
[Area("IoTCenter")]
|
|
|
|
|
[ControllerScope(ControllerScopeType.Platform)]
|
|
|
|
|
public class IoTDeviceController : IoTSharedController<IoTDevice, EditDeviceModel>
|
|
|
|
|
public class IoTDeviceController : IoTSharedController<IoTDevice, EditPlatformIoTDeviceModel>
|
|
|
|
|
{
|
|
|
|
|
private readonly AjaxController _ajax;
|
|
|
|
|
private readonly IRepository<IoTProductCategory> _categoryRepo;
|
|
|
|
|
private readonly IRepository<Organ> _organRepo;
|
|
|
|
|
private readonly IRepository<Building> _buildingRepo;
|
|
|
|
|
|
|
|
|
|
public IoTDeviceController(IRepository<IoTDevice> repo, AjaxController ajax, IServiceProvider sp) : base(repo, sp)
|
|
|
|
|
public IoTDeviceController(IRepository<IoTDevice> repo,
|
|
|
|
|
AjaxController ajax,
|
|
|
|
|
IRepository<IoTProductCategory> categoryRepo,
|
|
|
|
|
IRepository<Organ> organRepo,
|
|
|
|
|
IRepository<Building> buildingRepo,
|
|
|
|
|
IServiceProvider sp) : base(repo, sp)
|
|
|
|
|
{
|
|
|
|
|
this._ajax = ajax;
|
|
|
|
|
this._categoryRepo = categoryRepo;
|
|
|
|
|
this._organRepo = organRepo;
|
|
|
|
|
this._buildingRepo = buildingRepo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override IQueryable<IoTDevice> Include(IQueryable<IoTDevice> query)
|
|
|
|
|
{
|
|
|
|
|
return query.Include(o => o.Product)
|
|
|
|
|
return query.Include(o => o.Product).ThenInclude(o=>o.Category)
|
|
|
|
|
.Include(o => o.Node).ThenInclude(o=>o.Building).ThenInclude(o=>o.Organ);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override IQueryable<IoTDevice> Query(PagedListModel<EditDeviceModel> model, IQueryable<IoTDevice> query)
|
|
|
|
|
public override IQueryable<IoTDevice> Query(PagedListModel<EditPlatformIoTDeviceModel> model, IQueryable<IoTDevice> query)
|
|
|
|
|
{
|
|
|
|
|
return query
|
|
|
|
|
.WhereIf(model.Query.OrganId.HasValue, o => o.Node.Building.OrganId == model.Query.OrganId.Value)
|
|
|
|
|
.WhereIf(model.Query.BuildingId.HasValue, o => o.Node.BuildingId == model.Query.BuildingId.Value)
|
|
|
|
|
.WhereIf(model.Query.NodeId.HasValue, o => o.NodeId == model.Query.NodeId.Value)
|
|
|
|
|
.WhereIf(model.Query.CategoryId.HasValue, o => o.Product.CategoryId == model.Query.CategoryId.Value)
|
|
|
|
|
.WhereIf(model.Query.ProductId.HasValue, o => o.ProductId == model.Query.ProductId.Value)
|
|
|
|
|
.WhereIf(!string.IsNullOrEmpty(model.Query.Name), o => o.Name.Contains(model.Query.Name))
|
|
|
|
|
.WhereIf(!string.IsNullOrEmpty(model.Query.DisplayName), o => o.DisplayName.Contains(model.Query.DisplayName))
|
|
|
|
@ -54,21 +67,69 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls
|
|
|
|
|
.WhereIf(model.Query.Disabled.HasValue, o => o.Disabled == model.Query.Disabled.Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void ToDisplayModel(IoTDevice entity, EditDeviceModel model)
|
|
|
|
|
public override void ToDisplayModel(IoTDevice entity, EditPlatformIoTDeviceModel model)
|
|
|
|
|
{
|
|
|
|
|
ViewData.Add(model.NodeId, entity?.Node?.Name);
|
|
|
|
|
ViewData.Add(model.ProductId, entity?.Product?.Name);
|
|
|
|
|
if(entity!=null)
|
|
|
|
|
{
|
|
|
|
|
model.BuildingId = entity.Node.BuildingId;
|
|
|
|
|
model.OrganId = entity.Node.Building.OrganId;
|
|
|
|
|
model.CategoryId = entity.Product.CategoryId;
|
|
|
|
|
}
|
|
|
|
|
if(model.BuildingId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var name = this._buildingRepo.ReadOnlyTable()
|
|
|
|
|
.Where(o => o.ParentId != null)
|
|
|
|
|
.Where(o => o.Left <= entity.Node.Building.Left && o.Right >= entity.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.Node.Building.Organ.Left && o.Right >= entity.Node.Building.Organ.Right)
|
|
|
|
|
.ToList()
|
|
|
|
|
.ToTree()
|
|
|
|
|
.FirstOrDefault(o => o.Id == entity.Node.Building.OrganId)?.GetDisplayName();
|
|
|
|
|
ViewData.Add(model.OrganId, name);
|
|
|
|
|
}
|
|
|
|
|
if (model.CategoryId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
var name = this._categoryRepo.ReadOnlyTable()
|
|
|
|
|
.Where(o => o.ParentId != null)
|
|
|
|
|
.Where(o => o.Left <= entity.Product.Category.Left && o.Right >= entity.Product.Category.Right)
|
|
|
|
|
.ToList()
|
|
|
|
|
.ToTree()
|
|
|
|
|
.FirstOrDefault(o => o.Id == model.CategoryId.Value)?.GetDisplayName();
|
|
|
|
|
ViewData.Add(model.CategoryId, name);
|
|
|
|
|
}
|
|
|
|
|
if (model.ProductId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
ViewData.Add(model.ProductId, entity.Product.Name);
|
|
|
|
|
}
|
|
|
|
|
if(model.NodeId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
ViewData.Add(model.NodeId, entity.Node.Name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void ToEditModel(IoTDevice entity, EditDeviceModel model)
|
|
|
|
|
public override void ToEditModel(IoTDevice entity, EditPlatformIoTDeviceModel model)
|
|
|
|
|
{
|
|
|
|
|
ViewData.SelectList(o => model.ProductCategoryId, () => this._ajax.GetIoTProductCategory(model.ProductCategoryId).SelectList());
|
|
|
|
|
ViewData.SelectList(o => model.ProductId, () => this._ajax.GetIoTProduct(model.ProductCategoryId).SelectList());
|
|
|
|
|
//ViewData.SelectList(o => model.NodeId, () => this._ajax.GetIoTGateway(model.NodeId).SelectList());
|
|
|
|
|
//ViewData.SelectList(o => model.ProductId, () => this._ajax.GetIoTProduct(model.ProductId).SelectList());
|
|
|
|
|
if (entity != null)
|
|
|
|
|
{
|
|
|
|
|
model.BuildingId = entity.Node.BuildingId;
|
|
|
|
|
model.OrganId = entity.Node.Building.OrganId;
|
|
|
|
|
model.CategoryId = entity.Product.CategoryId;
|
|
|
|
|
}
|
|
|
|
|
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.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(EditDeviceModel model)
|
|
|
|
|
public override string GetNodeNumber(EditPlatformIoTDeviceModel model)
|
|
|
|
|
{
|
|
|
|
|
return this.Repo.ReadOnlyTable().Where(o => o.NodeId == model.NodeId).Select(o => o.Node.Number).FirstOrDefault();
|
|
|
|
|
}
|
|
|
|
|