You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
115 lines
5.7 KiB
115 lines
5.7 KiB
using Infrastructure.Application;
|
|
using Infrastructure.Data;
|
|
using Infrastructure.Extensions;
|
|
using Infrastructure.Web.Mvc;
|
|
using Application.Domain.Entities;
|
|
using IoT.Shared.Areas.IoTCenter.Controlls;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Platform.Application.Models;
|
|
using System.Linq;
|
|
|
|
namespace Platform.Areas.IoTCenter.Controllers
|
|
{
|
|
[Authorize]
|
|
[ApiController]
|
|
[Route("IoTCenter/[controller]/[action]")]
|
|
[Area("IoTCenter")]
|
|
[ControllerScope(ControllerScopeType.Platform)]
|
|
|
|
public class IoTSceneIoTCommandController : CrudController<IoTSceneIoTCommand, EditIoTSceneIoTCommandModel>
|
|
{
|
|
private readonly AjaxController _ajax;
|
|
private readonly IRepository<Organ> _organRepo;
|
|
|
|
private readonly IRepository<Building> _buildingRepo;
|
|
|
|
|
|
public IoTSceneIoTCommandController(IRepository<IoTSceneIoTCommand> repo,
|
|
AjaxController ajax,
|
|
IRepository<Organ> organRepo,
|
|
IRepository<Building> buildingRepo) : base(repo)
|
|
{
|
|
this._ajax = ajax;
|
|
this._organRepo = organRepo;
|
|
this._buildingRepo = buildingRepo;
|
|
}
|
|
|
|
public override IQueryable<IoTSceneIoTCommand> Include(IQueryable<IoTSceneIoTCommand> query)
|
|
{
|
|
return query
|
|
.Include(o => o.IoTScene).ThenInclude(o=>o.Building).ThenInclude(o => o.Organ)
|
|
.Include(o => o.IoTCommand).ThenInclude(o => o.IoTDevice).ThenInclude(o => o.IoTGateway).ThenInclude(o=>o.Building)
|
|
.Include(o=>o.IoTCommand).ThenInclude(o=>o.Api);
|
|
}
|
|
|
|
public override IQueryable<IoTSceneIoTCommand> Query(PagedListModel<EditIoTSceneIoTCommandModel> model, IQueryable<IoTSceneIoTCommand> query)
|
|
{
|
|
return query
|
|
.WhereIf(model.Query.OrganId.HasValue,o=>o.IoTScene.Building.OrganId==model.Query.OrganId.Value)
|
|
.WhereIf(model.Query.IoTSceneBuildingId.HasValue, o => o.IoTScene.BuildingId == model.Query.IoTSceneBuildingId.Value)
|
|
.WhereIf(model.Query.IoTSceneId.HasValue, o => o.IoTSceneId == model.Query.IoTSceneId.Value)
|
|
.WhereIf(model.Query.DeviceBuildingId.HasValue, o => o.IoTCommand.IoTDevice.IoTGateway.BuildingId == model.Query.DeviceBuildingId.Value)
|
|
.WhereIf(model.Query.IoTCommandId.HasValue, o => o.IoTCommandId == model.Query.IoTCommandId.Value)
|
|
.OrderBy(o => o.IoTSceneId);
|
|
}
|
|
|
|
public override void EntityToModel(IoTSceneIoTCommand entity, EditIoTSceneIoTCommandModel model)
|
|
{
|
|
model.OrganId = entity.IoTScene?.Building?.OrganId;
|
|
model.IoTSceneBuildingId = entity.IoTScene?.BuildingId;
|
|
model.DeviceBuildingId = entity.IoTCommand?.IoTDevice?.IoTGateway?.BuildingId;
|
|
}
|
|
|
|
public override void ToDisplayModel(IoTSceneIoTCommand entity, EditIoTSceneIoTCommandModel model)
|
|
{
|
|
if (model.OrganId.HasValue)
|
|
{
|
|
var name = this._organRepo.ReadOnlyTable()
|
|
.Where(o => o.ParentId != null)
|
|
.Where(o => o.Left <= entity.IoTScene.Building.Organ.Left && o.Right >= entity.IoTScene.Building.Organ.Right)
|
|
.ToList()
|
|
.ToTree()
|
|
.FirstOrDefault(o => o.Id == entity.IoTScene.Building.OrganId)?.GetDisplayName();
|
|
ViewData.Add(model.OrganId, name);
|
|
}
|
|
|
|
if (model.IoTSceneBuildingId.HasValue)
|
|
{
|
|
var name = this._buildingRepo.ReadOnlyTable()
|
|
.Where(o => o.ParentId != null)
|
|
.Where(o => o.Left <= entity.IoTScene.Building.Left && o.Right >= entity.IoTScene.Building.Right)
|
|
.ToList()
|
|
.ToTree()
|
|
.FirstOrDefault(o => o.Id == model.IoTSceneBuildingId.Value)?.GetDisplayName();
|
|
ViewData.Add(model.IoTSceneBuildingId.Value, name);
|
|
}
|
|
|
|
if (model.DeviceBuildingId.HasValue)
|
|
{
|
|
var name = this._buildingRepo.ReadOnlyTable()
|
|
.Where(o => o.ParentId != null)
|
|
.Where(o => o.Left <= entity.IoTCommand.IoTDevice.IoTGateway.Building.Left && o.Right >= entity.IoTCommand.IoTDevice.IoTGateway.Building.Right)
|
|
.ToList()
|
|
.ToTree()
|
|
.FirstOrDefault(o => o.Id == model.DeviceBuildingId.Value)?.GetDisplayName();
|
|
ViewData.Add(model.DeviceBuildingId.Value, name);
|
|
}
|
|
|
|
ViewData.Add(model.IoTSceneId, entity?.IoTScene?.Name);
|
|
ViewData.Add(model.IoTCommandId, entity?.IoTCommand?.Name??entity?.IoTCommand?.Api?.Name);
|
|
}
|
|
public override void ToEditModel(IoTSceneIoTCommand entity, EditIoTSceneIoTCommandModel model)
|
|
{
|
|
ViewData.SelectList(o => model.OrganId, () => this._ajax.GetOrgan(model.OrganId).SelectList());
|
|
ViewData.SelectList(o => model.IoTSceneId, () => this._ajax.GetIoTScene(model.IoTSceneBuildingId.Value, model.IoTSceneId).SelectList(), model.IoTSceneBuildingId.HasValue);
|
|
ViewData.SelectList(o => model.IoTSceneBuildingId, () => this._ajax.GetBuilding(model.OrganId.Value, model.IoTSceneBuildingId).SelectList(), model.OrganId.HasValue);
|
|
ViewData.SelectList(o => model.DeviceBuildingId, () => this._ajax.GetBuildingByScene(model.IoTSceneId.Value, model.DeviceBuildingId).SelectList(), model.IoTSceneId.HasValue);
|
|
ViewData.SelectList(o => model.IoTCommandId, () => this._ajax.GetIoTCommand(model.DeviceBuildingId.Value, model.IoTCommandId).SelectList(), model.DeviceBuildingId.HasValue);
|
|
}
|
|
|
|
|
|
}
|
|
}
|