Former-commit-id: 90c757ba0db46b51b578a26cf6dbbf2461b55de5
Former-commit-id: f4874040f16c2c46c8615bf51a5fb9fbb713e6de
1.0
wanggang 5 years ago
parent 3dec769df2
commit 2ddfaf442c

@ -24,13 +24,14 @@ namespace IoT.Shared.Application.Domain.Entities
[Display(Name = "序号")]
public int DisplayOrder { get; set; }
[Display(Name = "机构Id")]
public Guid OrganId { get; set; }
public Guid? BuildingId { get; set; }
public Organ Organ { get; set; }
public Guid BuildingId { get; set; }
public Building Building { get; set; }
public List<IoTSceneIoTCommand> IoTCommands { get; set; } = new List<IoTSceneIoTCommand>();
public List<IoTTimer> IoTTimers { get; set; } = new List<IoTTimer>();
public List<IoTTigger> IoTTiggers { get; set; } = new List<IoTTigger>();
}
}

@ -21,7 +21,6 @@ namespace IoT.Shared.Application.Domain.Entities
public bool IsReadOnly { get; set; }
public List<Building> Buildings { get; set; } = new List<Building>();
public List<OrganUser> OrganUsers { get; set; } = new List<OrganUser>();
public List<IoTScene> OrganScenes { get; set; } = new List<IoTScene>();
public List<OrganRole> Roles { get; set; } = new List<OrganRole>();
public List<PermissionCategory> Categories { get; set; } = new List<PermissionCategory>();
public List<Title> Titles { get; set; } = new List<Title>();

@ -135,16 +135,6 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls
return new JsonResult(this.GetProductApiSelectList(parentId, selected));
}
public SelectList GetCameraSelectList(string deviceNumber)
{
var list = this._deviceRepo.ReadOnlyTable()
.Where(o => o.Product.Number == "onvifcamera")
.WhereIf(!string.IsNullOrEmpty(deviceNumber), o => o.Number == deviceNumber)
.Select(o => new { Id = o.Number, Name = o.DisplayName })
.ToList();
return new SelectList(list, "Id", "Name", deviceNumber);
}
#pragma warning disable CA1822 // Mark members as static
public JsonResult CronValid(string cron)
{

@ -167,9 +167,9 @@ CREATE TABLE "iot_IoTScene" (
"Image" TEXT NOT NULL,
"Hidden" INTEGER NOT NULL,
"DisplayOrder" INTEGER NOT NULL,
"OrganId" TEXT NOT NULL,
"BuildingId" TEXT NULL,
CONSTRAINT "FK_iot_IoTScene_iot_Organ_OrganId" FOREIGN KEY ("OrganId") REFERENCES "iot_Organ" ("Id") ON DELETE CASCADE
"BuildingId" TEXT NOT NULL,
"OrganId" TEXT NULL,
CONSTRAINT "FK_iot_IoTScene_iot_Organ_OrganId" FOREIGN KEY ("OrganId") REFERENCES "iot_Organ" ("Id") ON DELETE RESTRICT
);
CREATE TABLE "iot_OrganRole" (

@ -27,8 +27,8 @@ namespace Platform.Apis.Controllers
try
{
var model = this._sceneRepo.ReadOnlyTable()
.Include(o => o.Organ)
.WhereIf(organId.HasValue, o => o.OrganId == organId.Value)
.Include(o => o.Building).ThenInclude(o=>o.Organ)
.WhereIf(organId.HasValue, o => o.Building.OrganId == organId.Value)
.Where(o => !o.Hidden)
.OrderBy(o => o.DisplayOrder);
return Ok(model);

@ -16,6 +16,7 @@ namespace Platform.Application.Models
[Display(Name = "建筑")]
[SelectList]
[ReadOnlyForEdit]
[Required(ErrorMessage = nameof(RequiredAttribute))]
public Guid? BuildingId { get; set; }
[Display(Name = "场景名称")]

@ -36,14 +36,14 @@ namespace Platform.Areas.IoTCenter.Controllers
public override IQueryable<IoTScene> Include(IQueryable<IoTScene> query)
{
return query.Include(o => o.Organ).Include(o => o.Building);
return query.Include(o => o.Building).ThenInclude(o => o.Organ);
}
public override IQueryable<IoTScene> Query(PagedListModel<EditIoTSceneModel> model, IQueryable<IoTScene> query)
{
ViewData.SelectList(o => model.Query.OrganId, () => this._ajax.GetOrgan(model.Query.OrganId).SelectList());
return query
.WhereIf(model.Query.OrganId.HasValue, o => o.OrganId == model.Query.OrganId.Value)
.WhereIf(model.Query.OrganId.HasValue, o => o.Building.OrganId == model.Query.OrganId.Value)
.WhereIf(model.Query.BuildingId.HasValue, o => o.BuildingId == model.Query.BuildingId.Value)
.WhereIf(!string.IsNullOrEmpty(model.Query.Name), o => o.Name.Contains(model.Query.Name))
.WhereIf(model.Query.Hidden.HasValue, o => o.Hidden == model.Query.Hidden.Value)
@ -52,6 +52,10 @@ namespace Platform.Areas.IoTCenter.Controllers
public override void ToDisplayModel(IoTScene entity, EditIoTSceneModel model)
{
if(entity!=null)
{
model.OrganId = entity.Building.OrganId;
}
if (model.BuildingId.HasValue)
{
var name = this._buildingRepo.ReadOnlyTable()
@ -66,16 +70,20 @@ namespace Platform.Areas.IoTCenter.Controllers
{
var name = this._organRepo.ReadOnlyTable()
.Where(o => o.ParentId != null)
.Where(o => o.Left <= entity.Organ.Left && o.Right >= entity.Organ.Right)
.Where(o => o.Left <= entity.Building.Organ.Left && o.Right >= entity.Building.Organ.Right)
.ToList()
.ToTree()
.FirstOrDefault(o => o.Id == entity.OrganId)?.GetDisplayName();
.FirstOrDefault(o => o.Id == entity.Building.OrganId)?.GetDisplayName();
ViewData.Add(model.OrganId, name);
}
}
public override void ToEditModel(IoTScene entity, EditIoTSceneModel model)
{
if (entity != null)
{
model.OrganId = entity.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);
}

@ -30,7 +30,7 @@ namespace Platform.Areas.IoTCenter.Controllers
public override IQueryable<IoTSceneIoTCommand> Include(IQueryable<IoTSceneIoTCommand> query)
{
return query
.Include(o => o.IoTScene).ThenInclude(o => o.Organ)
.Include(o => o.IoTScene).ThenInclude(o=>o.Building).ThenInclude(o => o.Organ)
.Include(o => o.IoTCommand).ThenInclude(o => o.Device).ThenInclude(o => o.IoTGateway);
}
@ -53,9 +53,9 @@ namespace Platform.Areas.IoTCenter.Controllers
public override void ToDisplayModel(IoTSceneIoTCommand entity, EditIoTSceneIoTCommandModel model)
{
model.OrganId = entity?.IoTScene.OrganId;
model.OrganId = entity?.IoTScene?.Building?.OrganId;
model.IoTGatewayId = entity?.IoTCommand.Device.IoTGatewayId;
ViewData.Add(model.OrganId, entity?.IoTScene?.Organ?.Name);
ViewData.Add(model.OrganId, entity?.IoTScene?.Building?.Organ?.Name);
ViewData.Add(model.IoTSceneId, entity?.IoTScene?.Name);
ViewData.Add(model.IoTGatewayId, entity?.IoTCommand?.Device?.IoTGateway?.Name);
ViewData.Add(model.CommandId, entity?.IoTCommand?.Name);

@ -40,7 +40,7 @@ namespace Platform.Areas.IoTCenter.Controllers
public override IQueryable<IoTTigger> Query(PagedListModel<EditIoTTiggerModel> model, IQueryable<IoTTigger> query)
{
return query
.WhereIf(model.Query.OrganId.HasValue, o => o.IoTScene.OrganId == model.Query.OrganId.Value)
.WhereIf(model.Query.OrganId.HasValue, o => o.IoTScene.Building.OrganId == model.Query.OrganId.Value)
.WhereIf(model.Query.IoTGatewayId.HasValue, o => o.Data.Device.IoTGatewayId == model.Query.IoTGatewayId.Value)
.WhereIf(model.Query.OrganSceneId.HasValue, o => o.IoTSceneId == model.Query.OrganSceneId.Value)
.WhereIf(model.Query.DeviceId.HasValue, o => o.Data.DeviceId == model.Query.DeviceId.Value)
@ -57,13 +57,13 @@ namespace Platform.Areas.IoTCenter.Controllers
ViewData.SelectList(o => model.OrganId, () => this._ajax.GetOrgan(model.OrganId).SelectList());
ViewData.SelectList(o => model.IoTGatewayId, () => this._ajax.GetIoTGateway(model.IoTGatewayId).SelectList(), model.OrganId.HasValue);
ViewData.SelectList(o => model.OrganSceneId, () => this._ajax.GetOrganSceneSelectList(model.OrganId.Value, model.OrganSceneId), model.OrganId.HasValue);
ViewData.SelectList(o => model.DeviceId, () => this._ajax.GetIoTDevice(model.IoTGatewayId.Value, model.DeviceId).SelectList());
ViewData.SelectList(o => model.DeviceId, () => this._ajax.GetIoTDevice(model.IoTGatewayId.Value, model.DeviceId).SelectList(), model.IoTGatewayId.HasValue);
ViewData.SelectList(o => model.DataId, () => this._ajax.GetDataSelectList(model.DeviceId.Value), model.DeviceId.HasValue);
}
public override void ToDisplayModel(IoTTigger entity, EditIoTTiggerModel model)
{
model.OrganId = entity?.IoTScene?.OrganId;
model.OrganId = entity?.IoTScene?.Building?.OrganId;
model.DeviceId = entity?.Data?.DeviceId;
model.IoTGatewayId = entity?.Data?.Device?.IoTGatewayId;
ViewData.Add(model.IoTGatewayId, entity?.Data?.Device?.IoTGateway?.Name);

@ -33,7 +33,7 @@ namespace Platform.Areas.IoTCenter.Controllers
public override IQueryable<IoTTimer> Query(PagedListModel<EditIoTTimerModel> model, IQueryable<IoTTimer> query)
{
return query
.WhereIf(model.Query.OrganId.HasValue, o => o.IoTScene.OrganId == model.Query.OrganId.Value)
.WhereIf(model.Query.OrganId.HasValue, o => o.IoTScene.Building.OrganId == model.Query.OrganId.Value)
.WhereIf(model.Query.OrganSceneId.HasValue, o => o.IoTSceneId == model.Query.OrganSceneId.Value)
.WhereIf(!string.IsNullOrEmpty(model.Query.Name), o => o.Name.Contains(model.Query.Name))
.WhereIf(model.Query.Disabled.HasValue, o => o.Disabled == model.Query.Disabled.Value);
@ -41,7 +41,7 @@ namespace Platform.Areas.IoTCenter.Controllers
public override IQueryable<IoTTimer> Include(IQueryable<IoTTimer> query)
{
return query.Include(o => o.IoTScene).ThenInclude(o => o.Organ);
return query.Include(o => o.IoTScene).ThenInclude(o=>o.Building).ThenInclude(o => o.Organ);
}
public override void ToEditModel(IoTTimer entity, EditIoTTimerModel model)
@ -53,8 +53,8 @@ namespace Platform.Areas.IoTCenter.Controllers
public override void ToDisplayModel(IoTTimer entity, EditIoTTimerModel model)
{
model.OrganId = entity?.IoTScene.OrganId;
ViewData.Add(model.OrganId, entity?.IoTScene?.Organ?.Name);
model.OrganId = entity?.IoTScene?.Building.OrganId;
ViewData.Add(model.OrganId, entity?.IoTScene?.Building?.Organ?.Name);
ViewData.Add(model.OrganSceneId, entity?.IoTScene?.Name);
}
}

@ -203,7 +203,17 @@ namespace Platform.Areas.IoTCenter.Controllers
}
return new JsonResult(new SelectList(list, "Id", "Name", selected));
}
public SelectList GetCameraSelectList(string deviceNumber)
{
using var scope = this._services.CreateScope();
var repo = scope.ServiceProvider.GetRequiredService<IRepository<IoTDevice>>();
var list = repo.ReadOnlyTable()
.Where(o => o.Product.Number == "onvifcamera")
.WhereIf(!string.IsNullOrEmpty(deviceNumber), o => o.Number == deviceNumber)
.Select(o => new { Id = o.Number, Name = o.DisplayName })
.ToList();
return new SelectList(list, "Id", "Name", deviceNumber);
}
public SelectList GetOrganNodeSelectList(Guid parentId, Guid? selected = null)
{
using var scope = this._services.CreateScope();
@ -221,7 +231,7 @@ namespace Platform.Areas.IoTCenter.Controllers
using var scope = this._services.CreateScope();
var repo = scope.ServiceProvider.GetRequiredService<IRepository<IoTScene>>();
var list = repo.ReadOnlyTable()
.Where(o => o.OrganId == parentId)
.Where(o => o.Building.OrganId == parentId)
.Select(o => new { o.Id, o.Name })
.ToList();
return new SelectList(list, "Id", "Name", selected);

@ -74,11 +74,11 @@ namespace Platform.Controllers
{//即未选中建筑也未选中机构,则用户所在机构为当前机构
model.Organ = organList.FirstOrDefault(o => o.Id == userOrganId);
}
model.Scenes = this._organRepo.ReadOnlyTable()
.Where(o => o.Id == model.Organ.Id)
.SelectMany(o => o.OrganScenes)
model.Scenes = this._buildingRepo.ReadOnlyTable()
.Where(o => o.OrganId == model.Organ.Id)
.SelectMany(o=>o.Scenes)
.Where(o => o.Hidden == false)
.Where(o => o.BuildingId == null)
.WhereIf(model.BuildingId.HasValue,o => o.BuildingId == model.BuildingId.Value)
.ToList();
}
model.OrganId = model.Organ.Id;

@ -92,15 +92,14 @@ namespace Platform.Data
//modelBuilder.Entity<IoTProductCategoryIoTProduct>().HasIndex(o => o.ProductId).IsUnique();//通过唯一约束,保证一个商品只有一个分类
//IoTCommand
modelBuilder.Entity<IoTCommand>().HasOne(o => o.Api).WithMany().HasForeignKey(o => o.ApiId);
//OrganIoTScene
modelBuilder.Entity<IoTScene>().HasOne(o => o.Organ).WithMany(o => o.OrganScenes).HasForeignKey(o => o.OrganId);
modelBuilder.Entity<IoTScene>().HasOne(o => o.Building).WithMany(o => o.Scenes).HasForeignKey(o => o.BuildingId).OnDelete(DeleteBehavior.Cascade);
//OrganIoTSceneIoTCommand
//IoTScene
modelBuilder.Entity<IoTScene>().HasOne(o => o.Building).WithMany(o => o.Scenes).HasForeignKey(o => o.BuildingId);
//IoTSceneIoTCommand
modelBuilder.Entity<IoTSceneIoTCommand>().HasOne(o => o.IoTScene).WithMany(o => o.IoTCommands).HasForeignKey(o => o.IoTSceneId);
modelBuilder.Entity<IoTSceneIoTCommand>().HasOne(o => o.IoTCommand).WithMany().HasForeignKey(o => o.IoTCommandId);
//OrganIoTSceneTimer
//IoTTimer
modelBuilder.Entity<IoTTimer>().HasOne(o => o.IoTScene).WithMany(o => o.IoTTimers).HasForeignKey(o => o.IoTSceneId);
//OrganIoTSceneTigger
//IoTTigger
modelBuilder.Entity<IoTTigger>().HasOne(o => o.IoTScene).WithMany(o => o.IoTTiggers).HasForeignKey(o => o.IoTSceneId);
modelBuilder.Entity<IoTTigger>().HasOne(o => o.Data).WithMany().HasForeignKey(o => o.DataId);
//LiveRecord

@ -243,11 +243,9 @@ CREATE TABLE `iot_IoTScene` (
`Image` longtext CHARACTER SET utf8mb4 NOT NULL,
`Hidden` tinyint(1) NOT NULL,
`DisplayOrder` int NOT NULL,
`OrganId` char(36) NOT NULL,
`BuildingId` char(36) NULL,
`BuildingId` char(36) NOT NULL,
CONSTRAINT `PK_iot_IoTScene` PRIMARY KEY (`Id`),
CONSTRAINT `FK_iot_IoTScene_iot_Building_BuildingId` FOREIGN KEY (`BuildingId`) REFERENCES `iot_Building` (`Id`) ON DELETE CASCADE,
CONSTRAINT `FK_iot_IoTScene_iot_Organ_OrganId` FOREIGN KEY (`OrganId`) REFERENCES `iot_Organ` (`Id`) ON DELETE CASCADE
CONSTRAINT `FK_iot_IoTScene_iot_Building_BuildingId` FOREIGN KEY (`BuildingId`) REFERENCES `iot_Building` (`Id`) ON DELETE CASCADE
);
CREATE TABLE `iot_OrganUserRole` (
@ -470,8 +468,6 @@ CREATE INDEX `IX_iot_IoTProductCategory_ParentId` ON `iot_IoTProductCategory` (`
CREATE INDEX `IX_iot_IoTScene_BuildingId` ON `iot_IoTScene` (`BuildingId`);
CREATE INDEX `IX_iot_IoTScene_OrganId` ON `iot_IoTScene` (`OrganId`);
CREATE INDEX `IX_iot_IoTSceneIoTCommand_IoTCommandId` ON `iot_IoTSceneIoTCommand` (`IoTCommandId`);
CREATE INDEX `IX_iot_IoTSceneIoTCommand_IoTCommandId1` ON `iot_IoTSceneIoTCommand` (`IoTCommandId1`);

Loading…
Cancel
Save