diff --git a/projects/IoT.Shared/Application/Domain/Entities/IoTCenter/IoTApi.cs b/projects/IoT.Shared/Application/Domain/Entities/IoTCenter/IoTApi.cs index 95c22f75..ad7be5fa 100644 --- a/projects/IoT.Shared/Application/Domain/Entities/IoTCenter/IoTApi.cs +++ b/projects/IoT.Shared/Application/Domain/Entities/IoTCenter/IoTApi.cs @@ -17,6 +17,6 @@ namespace IoT.Shared.Application.Domain.Entities public Guid ProductId { get; set; } public IoTProduct Product { get; set; } public List Parameters { get; set; } = new List(); - //public List Commands { get; set; } = new List(); + public List IoTCommands { get; set; } = new List(); } } diff --git a/projects/IoT.Shared/Application/Domain/Entities/IoTCenter/IoTCommand.cs b/projects/IoT.Shared/Application/Domain/Entities/IoTCenter/IoTCommand.cs index e5ccd3df..27c24625 100644 --- a/projects/IoT.Shared/Application/Domain/Entities/IoTCenter/IoTCommand.cs +++ b/projects/IoT.Shared/Application/Domain/Entities/IoTCenter/IoTCommand.cs @@ -50,7 +50,7 @@ namespace IoT.Shared.Application.Domain.Entities /// /// API /// - public IoTDevice Device { get; set; } + public IoTDevice IoTDevice { get; set; } public List IoTSceneIoTCommands { get; set; } = new List(); } diff --git a/projects/IoT.Shared/Application/Domain/Entities/IoTCenter/IoTDevice.cs b/projects/IoT.Shared/Application/Domain/Entities/IoTCenter/IoTDevice.cs index 53da8a0b..ed7e1f8c 100644 --- a/projects/IoT.Shared/Application/Domain/Entities/IoTCenter/IoTDevice.cs +++ b/projects/IoT.Shared/Application/Domain/Entities/IoTCenter/IoTDevice.cs @@ -69,8 +69,8 @@ namespace IoT.Shared.Application.Domain.Entities [Display(Name = "数据")] public List Data { get; set; } = new List(); - //[Display(Name = "命令")] - //public List Commands { get; set; } = new List(); + [Display(Name = "命令")] + public List IoTCommands { get; set; } = new List(); public IoTData GetData(string key) { diff --git a/projects/IoT.Shared/Application/Domain/Entities/IoTCenter/IoTScene.cs b/projects/IoT.Shared/Application/Domain/Entities/IoTCenter/IoTScene.cs index 4f8f9152..b8eda874 100644 --- a/projects/IoT.Shared/Application/Domain/Entities/IoTCenter/IoTScene.cs +++ b/projects/IoT.Shared/Application/Domain/Entities/IoTCenter/IoTScene.cs @@ -28,7 +28,7 @@ namespace IoT.Shared.Application.Domain.Entities public Building Building { get; set; } - public List IoTCommands { get; set; } = new List(); + public List IoTSceneIoTCommands { get; set; } = new List(); public List IoTTimers { get; set; } = new List(); diff --git a/projects/IoT.Shared/Application/Models/EditIoTDataModel.cs b/projects/IoT.Shared/Application/Models/EditIoTDataModel.cs index 0fcba741..994cce2b 100644 --- a/projects/IoT.Shared/Application/Models/EditIoTDataModel.cs +++ b/projects/IoT.Shared/Application/Models/EditIoTDataModel.cs @@ -1,5 +1,6 @@ using Infrastructure.Application; using IoT.Shared.Application.Domain.Entities; +using IoT.Shared.Areas.IoTCenter.Controlls; using System; using System.ComponentModel.DataAnnotations; @@ -15,7 +16,7 @@ namespace IoT.Shared.Application.Models [Display(Name = "网关")] [ReadOnlyForEdit] - [SelectList(nameof(DeviceId), "GetIoTDevice")] + [SelectList(nameof(DeviceId),nameof(AjaxBaseController.GetIoTDevice))] public Guid? IoTGatewayId { get; set; } [Display(Name = "设备")] diff --git a/projects/IoT.Shared/Application/Models/EditIoTParameterModel.cs b/projects/IoT.Shared/Application/Models/EditIoTParameterModel.cs index 236a2030..780b5039 100644 --- a/projects/IoT.Shared/Application/Models/EditIoTParameterModel.cs +++ b/projects/IoT.Shared/Application/Models/EditIoTParameterModel.cs @@ -1,4 +1,5 @@ using Infrastructure.Application; +using IoT.Shared.Areas.IoTCenter.Controlls; using System; using System.ComponentModel.DataAnnotations; @@ -8,7 +9,7 @@ namespace IoT.Shared.Application.Models public class EditIoTParameterModel : EditModel { [Display(Name = "产品")] - [SelectList(nameof(ApiId),"GetIoTApi")] + [SelectList(nameof(ApiId),nameof(AjaxBaseController.GetIoTApi))] [ReadOnlyForEdit] [Required(ErrorMessage = nameof(RequiredAttribute))] public Guid? ProductId { get; set; } diff --git a/projects/IoTNode/Data/IoTNodeDbContext.cs b/projects/IoTNode/Data/IoTNodeDbContext.cs index e6108328..9a3dc2d8 100644 --- a/projects/IoTNode/Data/IoTNodeDbContext.cs +++ b/projects/IoTNode/Data/IoTNodeDbContext.cs @@ -39,10 +39,28 @@ namespace IoTNode.Data //Setting modelBuilder.Entity().HasIndex(o => o.Name).IsUnique(); //ignore + modelBuilder.Ignore(); modelBuilder.Ignore(); - modelBuilder.Entity().Ignore(o => o.Building); + modelBuilder.Ignore(); + modelBuilder.Ignore(); + modelBuilder.Ignore(); + modelBuilder.Ignore(); + modelBuilder.Ignore(); + modelBuilder.Ignore<OrganUser>(); + modelBuilder.Ignore<OrganRole>(); + modelBuilder.Ignore<OrganRolePermission>(); + modelBuilder.Ignore<OrganUserRole>(); + modelBuilder.Ignore<PermissionCategory>(); modelBuilder.Ignore<IoTProductCategory>(); + modelBuilder.Ignore<IoTCommand>(); + modelBuilder.Ignore<IoTSceneIoTCommand>(); + modelBuilder.Ignore<IoTScene>(); + modelBuilder.Ignore<IoTTimer>(); + modelBuilder.Ignore<IoTTigger>(); modelBuilder.Entity<IoTProduct>().Ignore(o => o.DisplayOrder); + modelBuilder.Entity<IoTApi>().Ignore(o => o.IoTCommands); + modelBuilder.Entity<IoTGateway>().Ignore(o => o.Building); + modelBuilder.Entity<IoTDevice>().Ignore(o => o.IoTCommands); modelBuilder.Ignore<IoT.Shared.Application.Domain.Entities.User>(); modelBuilder.Ignore<IoT.Shared.Application.Domain.Entities.PermissionCategory>(); modelBuilder.Ignore<IoT.Shared.Application.Domain.Entities.Permission>(); diff --git a/projects/IoTNode/db.sql b/projects/IoTNode/db.sql index 078ea966..b6a246ac 100644 --- a/projects/IoTNode/db.sql +++ b/projects/IoTNode/db.sql @@ -1,18 +1,4 @@ -CREATE TABLE "iot_Area" ( - "Id" TEXT NOT NULL CONSTRAINT "PK_iot_Area" PRIMARY KEY, - "IsDeleted" TEXT NULL, - "Name" TEXT NULL, - "Number" TEXT NULL, - "DisplayOrder" INTEGER NOT NULL, - "Left" INTEGER NOT NULL, - "Right" INTEGER NOT NULL, - "ParentId" TEXT NULL, - "Type" INTEGER NOT NULL, - "CustomType" TEXT NULL, - CONSTRAINT "FK_iot_Area_iot_Area_ParentId" FOREIGN KEY ("ParentId") REFERENCES "iot_Area" ("Id") ON DELETE RESTRICT -); - -CREATE TABLE "iot_IoTGateway" ( +CREATE TABLE "iot_IoTGateway" ( "Id" TEXT NOT NULL CONSTRAINT "PK_iot_IoTGateway" PRIMARY KEY, "IsDeleted" TEXT NULL, "Name" TEXT NULL, @@ -74,25 +60,6 @@ CREATE TABLE "iot_User" ( "Email" TEXT NULL ); -CREATE TABLE "iot_Organ" ( - "Id" TEXT NOT NULL CONSTRAINT "PK_iot_Organ" PRIMARY KEY, - "IsDeleted" TEXT NULL, - "Name" TEXT NULL, - "Number" TEXT NULL, - "DisplayOrder" INTEGER NOT NULL, - "Left" INTEGER NOT NULL, - "Right" INTEGER NOT NULL, - "ParentId" TEXT NULL, - "Type" INTEGER NOT NULL, - "CustomType" TEXT NULL, - "Image" TEXT NULL, - "Description" TEXT NULL, - "AreaId" TEXT NULL, - "IsReadOnly" INTEGER NOT NULL, - CONSTRAINT "FK_iot_Organ_iot_Area_AreaId" FOREIGN KEY ("AreaId") REFERENCES "iot_Area" ("Id") ON DELETE RESTRICT, - CONSTRAINT "FK_iot_Organ_iot_Organ_ParentId" FOREIGN KEY ("ParentId") REFERENCES "iot_Organ" ("Id") ON DELETE RESTRICT -); - CREATE TABLE "iot_IoTApi" ( "Id" TEXT NOT NULL CONSTRAINT "PK_iot_IoTApi" PRIMARY KEY, "IsDeleted" TEXT NULL, @@ -144,66 +111,6 @@ CREATE TABLE "iot_UserRole" ( CONSTRAINT "FK_iot_UserRole_iot_User_UserId" FOREIGN KEY ("UserId") REFERENCES "iot_User" ("Id") ON DELETE CASCADE ); -CREATE TABLE "iot_Department" ( - "Id" TEXT NOT NULL CONSTRAINT "PK_iot_Department" PRIMARY KEY, - "IsDeleted" TEXT NULL, - "Name" TEXT NULL, - "Number" TEXT NULL, - "DisplayOrder" INTEGER NOT NULL, - "Left" INTEGER NOT NULL, - "Right" INTEGER NOT NULL, - "ParentId" TEXT NULL, - "Type" INTEGER NOT NULL, - "CustomType" TEXT NULL, - "OrganId" TEXT NOT NULL, - CONSTRAINT "FK_iot_Department_iot_Organ_OrganId" FOREIGN KEY ("OrganId") REFERENCES "iot_Organ" ("Id") ON DELETE CASCADE, - CONSTRAINT "FK_iot_Department_iot_Department_ParentId" FOREIGN KEY ("ParentId") REFERENCES "iot_Department" ("Id") ON DELETE RESTRICT -); - -CREATE TABLE "iot_IoTScene" ( - "Id" TEXT NOT NULL CONSTRAINT "PK_iot_IoTScene" PRIMARY KEY, - "IsDeleted" TEXT NULL, - "Name" TEXT NOT NULL, - "Image" TEXT NOT NULL, - "Hidden" INTEGER NOT NULL, - "DisplayOrder" INTEGER NOT NULL, - "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" ( - "Id" TEXT NOT NULL CONSTRAINT "PK_iot_OrganRole" PRIMARY KEY, - "IsDeleted" TEXT NULL, - "Name" TEXT NULL, - "Number" TEXT NULL, - "IsReadOnly" INTEGER NOT NULL, - "OrganId" TEXT NOT NULL, - CONSTRAINT "FK_iot_OrganRole_iot_Organ_OrganId" FOREIGN KEY ("OrganId") REFERENCES "iot_Organ" ("Id") ON DELETE CASCADE -); - -CREATE TABLE "iot_OrganUser" ( - "Id" TEXT NOT NULL CONSTRAINT "PK_iot_OrganUser" PRIMARY KEY, - "IsDeleted" TEXT NULL, - "Type" INTEGER NOT NULL, - "CustomType" TEXT NULL, - "OrganId" TEXT NOT NULL, - "UserId" TEXT NOT NULL, - "IsDefault" INTEGER NOT NULL, - "IsReadOnly" INTEGER NOT NULL, - CONSTRAINT "FK_iot_OrganUser_iot_Organ_OrganId" FOREIGN KEY ("OrganId") REFERENCES "iot_Organ" ("Id") ON DELETE CASCADE -); - -CREATE TABLE "iot_Title" ( - "Id" TEXT NOT NULL CONSTRAINT "PK_iot_Title" PRIMARY KEY, - "IsDeleted" TEXT NULL, - "Name" TEXT NULL, - "MinLevel" INTEGER NOT NULL, - "MaxLevel" INTEGER NOT NULL, - "OrganId" TEXT NOT NULL, - CONSTRAINT "FK_iot_Title_iot_Organ_OrganId" FOREIGN KEY ("OrganId") REFERENCES "iot_Organ" ("Id") ON DELETE CASCADE -); - CREATE TABLE "iot_IoTParameter" ( "Id" TEXT NOT NULL CONSTRAINT "PK_iot_IoTParameter" PRIMARY KEY, "IsDeleted" TEXT NULL, @@ -217,20 +124,6 @@ CREATE TABLE "iot_IoTParameter" ( CONSTRAINT "FK_iot_IoTParameter_iot_IoTApi_ApiId" FOREIGN KEY ("ApiId") REFERENCES "iot_IoTApi" ("Id") ON DELETE CASCADE ); -CREATE TABLE "iot_IoTCommand" ( - "Id" TEXT NOT NULL CONSTRAINT "PK_iot_IoTCommand" PRIMARY KEY, - "IsDeleted" TEXT NULL, - "Name" TEXT NULL, - "DisplayOrder" INTEGER NOT NULL, - "Disabled" INTEGER NOT NULL, - "Delay" INTEGER NOT NULL, - "QueryString" TEXT NULL, - "ApiId" TEXT NOT NULL, - "DeviceId" TEXT NOT NULL, - CONSTRAINT "FK_iot_IoTCommand_iot_IoTApi_ApiId" FOREIGN KEY ("ApiId") REFERENCES "iot_IoTApi" ("Id") ON DELETE CASCADE, - CONSTRAINT "FK_iot_IoTCommand_iot_IoTDevice_DeviceId" FOREIGN KEY ("DeviceId") REFERENCES "iot_IoTDevice" ("Id") ON DELETE CASCADE -); - CREATE TABLE "iot_IoTData" ( "Id" TEXT NOT NULL CONSTRAINT "PK_iot_IoTData" PRIMARY KEY, "IsDeleted" TEXT NULL, @@ -256,101 +149,8 @@ CREATE TABLE "iot_RolePermission" ( CONSTRAINT "FK_iot_RolePermission_iot_Role_RoleId" FOREIGN KEY ("RoleId") REFERENCES "iot_Role" ("Id") ON DELETE CASCADE ); -CREATE TABLE "iot_IoTTimer" ( - "Id" TEXT NOT NULL CONSTRAINT "PK_iot_IoTTimer" PRIMARY KEY, - "IsDeleted" TEXT NULL, - "Name" TEXT NULL, - "Cron" TEXT NULL, - "Disabled" INTEGER NOT NULL, - "IoTSceneId" TEXT NOT NULL, - CONSTRAINT "FK_iot_IoTTimer_iot_IoTScene_IoTSceneId" FOREIGN KEY ("IoTSceneId") REFERENCES "iot_IoTScene" ("Id") ON DELETE CASCADE -); - -CREATE TABLE "iot_OrganRolePermission" ( - "Id" TEXT NOT NULL CONSTRAINT "PK_iot_OrganRolePermission" PRIMARY KEY, - "IsDeleted" TEXT NULL, - "RoleId" TEXT NOT NULL, - "PermissionId" TEXT NOT NULL, - "IsReadOnly" INTEGER NOT NULL, - CONSTRAINT "FK_iot_OrganRolePermission_iot_OrganRole_RoleId" FOREIGN KEY ("RoleId") REFERENCES "iot_OrganRole" ("Id") ON DELETE CASCADE -); - -CREATE TABLE "iot_OrganUserRole" ( - "Id" TEXT NOT NULL CONSTRAINT "PK_iot_OrganUserRole" PRIMARY KEY, - "IsDeleted" TEXT NULL, - "IsReadOnly" INTEGER NOT NULL, - "OrganUserId" TEXT NOT NULL, - "OrganRoleId" TEXT NOT NULL, - CONSTRAINT "FK_iot_OrganUserRole_iot_OrganRole_OrganRoleId" FOREIGN KEY ("OrganRoleId") REFERENCES "iot_OrganRole" ("Id") ON DELETE CASCADE, - CONSTRAINT "FK_iot_OrganUserRole_iot_OrganUser_OrganUserId" FOREIGN KEY ("OrganUserId") REFERENCES "iot_OrganUser" ("Id") ON DELETE CASCADE -); - -CREATE TABLE "iot_Job" ( - "Id" TEXT NOT NULL CONSTRAINT "PK_iot_Job" PRIMARY KEY, - "IsDeleted" TEXT NULL, - "Name" TEXT NULL, - "Level" INTEGER NOT NULL, - "TitleId" TEXT NOT NULL, - "DepartmentId" TEXT NOT NULL, - CONSTRAINT "FK_iot_Job_iot_Department_DepartmentId" FOREIGN KEY ("DepartmentId") REFERENCES "iot_Department" ("Id") ON DELETE CASCADE, - CONSTRAINT "FK_iot_Job_iot_Title_TitleId" FOREIGN KEY ("TitleId") REFERENCES "iot_Title" ("Id") ON DELETE CASCADE -); - -CREATE TABLE "iot_IoTSceneIoTCommand" ( - "Id" TEXT NOT NULL CONSTRAINT "PK_iot_IoTSceneIoTCommand" PRIMARY KEY, - "IsDeleted" TEXT NULL, - "IoTSceneId" TEXT NOT NULL, - "IoTCommandId" TEXT NOT NULL, - CONSTRAINT "FK_iot_IoTSceneIoTCommand_iot_IoTCommand_IoTCommandId" FOREIGN KEY ("IoTCommandId") REFERENCES "iot_IoTCommand" ("Id") ON DELETE CASCADE, - CONSTRAINT "FK_iot_IoTSceneIoTCommand_iot_IoTScene_IoTSceneId" FOREIGN KEY ("IoTSceneId") REFERENCES "iot_IoTScene" ("Id") ON DELETE CASCADE -); - -CREATE TABLE "iot_IoTTigger" ( - "Id" TEXT NOT NULL CONSTRAINT "PK_iot_IoTTigger" PRIMARY KEY, - "IsDeleted" TEXT NULL, - "Name" TEXT NULL, - "Condition" TEXT NULL, - "Disabled" INTEGER NOT NULL, - "DataId" TEXT NOT NULL, - "IoTSceneId" TEXT NOT NULL, - CONSTRAINT "FK_iot_IoTTigger_iot_IoTData_DataId" FOREIGN KEY ("DataId") REFERENCES "iot_IoTData" ("Id") ON DELETE CASCADE, - CONSTRAINT "FK_iot_IoTTigger_iot_IoTScene_IoTSceneId" FOREIGN KEY ("IoTSceneId") REFERENCES "iot_IoTScene" ("Id") ON DELETE CASCADE -); - -CREATE TABLE "iot_DepartmentUser" ( - "Id" TEXT NOT NULL CONSTRAINT "PK_iot_DepartmentUser" PRIMARY KEY, - "IsDeleted" TEXT NULL, - "Position" TEXT NULL, - "Type" INTEGER NOT NULL, - "CustomType" TEXT NULL, - "UserId" TEXT NOT NULL, - "DeparementId" TEXT NOT NULL, - "JobId" TEXT NULL, - "DepartmentId" TEXT NULL, - "OrganUserId" TEXT NULL, - CONSTRAINT "FK_iot_DepartmentUser_iot_Department_DepartmentId" FOREIGN KEY ("DepartmentId") REFERENCES "iot_Department" ("Id") ON DELETE RESTRICT, - CONSTRAINT "FK_iot_DepartmentUser_iot_Job_JobId" FOREIGN KEY ("JobId") REFERENCES "iot_Job" ("Id") ON DELETE RESTRICT, - CONSTRAINT "FK_iot_DepartmentUser_iot_OrganUser_OrganUserId" FOREIGN KEY ("OrganUserId") REFERENCES "iot_OrganUser" ("Id") ON DELETE RESTRICT -); - -CREATE INDEX "IX_iot_Area_ParentId" ON "iot_Area" ("ParentId"); - -CREATE INDEX "IX_iot_Department_OrganId" ON "iot_Department" ("OrganId"); - -CREATE INDEX "IX_iot_Department_ParentId" ON "iot_Department" ("ParentId"); - -CREATE INDEX "IX_iot_DepartmentUser_DepartmentId" ON "iot_DepartmentUser" ("DepartmentId"); - -CREATE INDEX "IX_iot_DepartmentUser_JobId" ON "iot_DepartmentUser" ("JobId"); - -CREATE INDEX "IX_iot_DepartmentUser_OrganUserId" ON "iot_DepartmentUser" ("OrganUserId"); - CREATE UNIQUE INDEX "IX_iot_IoTApi_ProductId_Name" ON "iot_IoTApi" ("ProductId", "Name"); -CREATE INDEX "IX_iot_IoTCommand_ApiId" ON "iot_IoTCommand" ("ApiId"); - -CREATE INDEX "IX_iot_IoTCommand_DeviceId" ON "iot_IoTCommand" ("DeviceId"); - CREATE INDEX "IX_iot_IoTData_DeviceId" ON "iot_IoTData" ("DeviceId"); CREATE INDEX "IX_iot_IoTDevice_IoTGatewayId" ON "iot_IoTDevice" ("IoTGatewayId"); @@ -365,36 +165,6 @@ CREATE INDEX "IX_iot_IoTParameter_ApiId" ON "iot_IoTParameter" ("ApiId"); CREATE UNIQUE INDEX "IX_iot_IoTProduct_Number" ON "iot_IoTProduct" ("Number"); -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_IoTSceneId" ON "iot_IoTSceneIoTCommand" ("IoTSceneId"); - -CREATE INDEX "IX_iot_IoTTigger_DataId" ON "iot_IoTTigger" ("DataId"); - -CREATE INDEX "IX_iot_IoTTigger_IoTSceneId" ON "iot_IoTTigger" ("IoTSceneId"); - -CREATE INDEX "IX_iot_IoTTimer_IoTSceneId" ON "iot_IoTTimer" ("IoTSceneId"); - -CREATE INDEX "IX_iot_Job_DepartmentId" ON "iot_Job" ("DepartmentId"); - -CREATE INDEX "IX_iot_Job_TitleId" ON "iot_Job" ("TitleId"); - -CREATE INDEX "IX_iot_Organ_AreaId" ON "iot_Organ" ("AreaId"); - -CREATE INDEX "IX_iot_Organ_ParentId" ON "iot_Organ" ("ParentId"); - -CREATE INDEX "IX_iot_OrganRole_OrganId" ON "iot_OrganRole" ("OrganId"); - -CREATE INDEX "IX_iot_OrganRolePermission_RoleId" ON "iot_OrganRolePermission" ("RoleId"); - -CREATE INDEX "IX_iot_OrganUser_OrganId" ON "iot_OrganUser" ("OrganId"); - -CREATE INDEX "IX_iot_OrganUserRole_OrganRoleId" ON "iot_OrganUserRole" ("OrganRoleId"); - -CREATE INDEX "IX_iot_OrganUserRole_OrganUserId" ON "iot_OrganUserRole" ("OrganUserId"); - CREATE INDEX "IX_iot_Permission_CategoryId" ON "iot_Permission" ("CategoryId"); CREATE UNIQUE INDEX "IX_iot_Permission_Number" ON "iot_Permission" ("Number"); @@ -411,8 +181,6 @@ CREATE UNIQUE INDEX "IX_iot_RolePermission_RoleId_PermissionId" ON "iot_RolePerm CREATE UNIQUE INDEX "IX_iot_Setting_Name" ON "iot_Setting" ("Name"); -CREATE INDEX "IX_iot_Title_OrganId" ON "iot_Title" ("OrganId"); - CREATE UNIQUE INDEX "IX_iot_User_Email" ON "iot_User" ("Email"); CREATE UNIQUE INDEX "IX_iot_User_UserName" ON "iot_User" ("UserName"); diff --git a/projects/Platform/Api/SceneController.cs b/projects/Platform/Api/SceneController.cs index b4e03ecf..aae021bc 100644 --- a/projects/Platform/Api/SceneController.cs +++ b/projects/Platform/Api/SceneController.cs @@ -46,7 +46,7 @@ namespace Platform.Apis.Controllers try { var model = this._sceneRepo.ReadOnlyTable() - .Include(o => o.IoTCommands) + .Include(o => o.IoTSceneIoTCommands) .Include(o => o.IoTTimers) .Include(o => o.IoTTiggers) .Where(o => o.Id == id) diff --git a/projects/Platform/Application/Models/EditBuildingModel.cs b/projects/Platform/Application/Models/EditBuildingModel.cs index dcc5a8c2..5ea60b00 100644 --- a/projects/Platform/Application/Models/EditBuildingModel.cs +++ b/projects/Platform/Application/Models/EditBuildingModel.cs @@ -1,5 +1,6 @@ using Infrastructure.Application; using IoT.Shared.Application.Domain.Entities; +using Platform.Areas.IoTCenter.Controllers; using System; using System.ComponentModel.DataAnnotations; using UoN.ExpressiveAnnotations.NetCore.Attributes; @@ -9,7 +10,7 @@ namespace Platform.Application.Models [Display(Name = "建筑")] public class EditBuildingModel : EditModel { - [SelectList(nameof(ParentId), "GetBuilding")] + [SelectList(nameof(ParentId), nameof(AjaxController.GetBuilding))] [Display(Name = "机构")] [Required(ErrorMessage = nameof(RequiredAttribute))] public Guid? OrganId { get; set; } diff --git a/projects/Platform/Application/Models/EditIoTSceneIoTCommandModel.cs b/projects/Platform/Application/Models/EditIoTSceneIoTCommandModel.cs index ffc13687..15ae39b1 100644 --- a/projects/Platform/Application/Models/EditIoTSceneIoTCommandModel.cs +++ b/projects/Platform/Application/Models/EditIoTSceneIoTCommandModel.cs @@ -1,4 +1,5 @@ using Infrastructure.Application; +using Platform.Areas.IoTCenter.Controllers; using System; using System.ComponentModel.DataAnnotations; @@ -8,28 +9,30 @@ namespace Platform.Application.Models public class EditIoTSceneIoTCommandModel : EditModel { [Display(Name = "机构")] - [SelectList(nameof(BuildingId), "GetBuilding")] + [SelectList(nameof(IoTSceneBuildingId), nameof(AjaxController.GetBuilding))] [ReadOnlyForEdit] public Guid? OrganId { get; set; } - [Display(Name = "建筑")] - [SelectList(nameof(IoTGatewayId), "GetIoTGateway")] + [Display(Name = "场景建筑")] + [SelectList(nameof(IoTSceneId), nameof(AjaxController.GetIoTScene))] [ReadOnlyForEdit] - public Guid? BuildingId { get; set; } + public Guid? IoTSceneBuildingId { get; set; } - [Display(Name = "机构场景")] - [SelectList] + [Display(Name = "场景")] + [SelectList(nameof(DeviceBuildingId), nameof(AjaxController.GetBuildingByScene))] [Required(ErrorMessage = nameof(RequiredAttribute))] + [ReadOnlyForEdit] public Guid? IoTSceneId { get; set; } - [Display(Name = "网关")] - [SelectList] - [Required(ErrorMessage = nameof(RequiredAttribute))] - public Guid? IoTGatewayId { get; set; } + [Display(Name = "设备建筑")] + [SelectList(nameof(IoTCommandId), nameof(AjaxController.GetIoTCommand))] + [ReadOnlyForEdit] + public Guid? DeviceBuildingId { get; set; } [Display(Name = "命令")] [SelectList] [Required(ErrorMessage = nameof(RequiredAttribute))] - public Guid? CommandId { get; set; } + [ReadOnlyForEdit] + public Guid? IoTCommandId { get; set; } } } \ No newline at end of file diff --git a/projects/Platform/Application/Models/EditIoTSceneModel.cs b/projects/Platform/Application/Models/EditIoTSceneModel.cs index 90dc268a..e93d3c33 100644 --- a/projects/Platform/Application/Models/EditIoTSceneModel.cs +++ b/projects/Platform/Application/Models/EditIoTSceneModel.cs @@ -1,4 +1,5 @@ using Infrastructure.Application; +using Platform.Areas.IoTCenter.Controllers; using System; using System.ComponentModel.DataAnnotations; @@ -8,7 +9,7 @@ namespace Platform.Application.Models public class EditIoTSceneModel : EditModel { [Display(Name = "机构")] - [SelectList(nameof(BuildingId), "GetBuilding")] + [SelectList(nameof(BuildingId), nameof(AjaxController.GetBuilding))] [ReadOnlyForEdit] [Required(ErrorMessage = nameof(RequiredAttribute))] public Guid? OrganId { get; set; } diff --git a/projects/IoT.Shared/Application/Models/EditIoTCommandModel.cs b/projects/Platform/Application/Models/IoTCenter/EditIoTCommandModel.cs similarity index 85% rename from projects/IoT.Shared/Application/Models/EditIoTCommandModel.cs rename to projects/Platform/Application/Models/IoTCenter/EditIoTCommandModel.cs index 1b5c95c7..a4aa68aa 100644 --- a/projects/IoT.Shared/Application/Models/EditIoTCommandModel.cs +++ b/projects/Platform/Application/Models/IoTCenter/EditIoTCommandModel.cs @@ -1,5 +1,6 @@ using Infrastructure.Application; using Microsoft.AspNetCore.Mvc; +using Platform.Areas.IoTCenter.Controllers; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; @@ -11,21 +12,21 @@ namespace IoT.Shared.Application.Models public class EditIoTCommandModel : EditModel { [Display(Name = "机构")] - [SelectList(nameof(BuildingId), "GetBuilding")] + [SelectList(nameof(BuildingId),nameof(AjaxController.GetBuilding))] [ReadOnlyForEdit] public Guid? OrganId { get; set; } [Display(Name = "建筑")] - [SelectList(nameof(IoTGatewayId), "GetIoTGateway")] + [SelectList(nameof(IoTGatewayId), nameof(AjaxController.GetIoTGateway))] [ReadOnlyForEdit] public Guid? BuildingId { get; set; } - [SelectList(nameof(DeviceId),"GetIoTDevice")] + [SelectList(nameof(DeviceId), nameof(AjaxController.GetIoTDevice))] [Display(Name = "网关")] [Required(ErrorMessage = nameof(RequiredAttribute))] public Guid? IoTGatewayId { get; set; } - [SelectList(nameof(ApiId),"GetIoTApiByDevice")] + [SelectList(nameof(ApiId), nameof(AjaxController.GetIoTApiByDevice))] [Display(Name = "设备")] [Required(ErrorMessage = nameof(RequiredAttribute))] public Guid? DeviceId { get; set; } diff --git a/projects/Platform/Application/Models/IoTCenter/EditPlatformIoTApiModel.cs b/projects/Platform/Application/Models/IoTCenter/EditPlatformIoTApiModel.cs index d6fa9273..5b01c9bc 100644 --- a/projects/Platform/Application/Models/IoTCenter/EditPlatformIoTApiModel.cs +++ b/projects/Platform/Application/Models/IoTCenter/EditPlatformIoTApiModel.cs @@ -1,6 +1,7 @@ using System; using IoT.Shared.Application.Models; using System.ComponentModel.DataAnnotations; +using Platform.Areas.IoTCenter.Controllers; namespace Platform.Application.Models.IoTCenter { @@ -9,7 +10,7 @@ namespace Platform.Application.Models.IoTCenter { [Display(Name = "分类")] [ReadOnlyForEdit] - [SelectList(nameof(ProductId),"GetIoTProductByCategory")] + [SelectList(nameof(ProductId), nameof(AjaxController.GetIoTProductByCategory))] public Guid? CategoryId { get; set; } } } diff --git a/projects/Platform/Application/Models/IoTCenter/EditPlatformIoTDataModel.cs b/projects/Platform/Application/Models/IoTCenter/EditPlatformIoTDataModel.cs index b4277320..191c8742 100644 --- a/projects/Platform/Application/Models/IoTCenter/EditPlatformIoTDataModel.cs +++ b/projects/Platform/Application/Models/IoTCenter/EditPlatformIoTDataModel.cs @@ -1,4 +1,5 @@ using IoT.Shared.Application.Models; +using Platform.Areas.IoTCenter.Controllers; using System; using System.ComponentModel.DataAnnotations; @@ -8,18 +9,18 @@ namespace Platform.Application.Models.IoTCenter public class EditPlatformIoTDataModel : EditIoTDataModel { [Display(Name = "机构")] - [SelectList(nameof(BuildingId), "GetBuilding")] + [SelectList(nameof(BuildingId), nameof(AjaxController.GetBuilding))] [ReadOnlyForEdit] public Guid? OrganId { get; set; } [Display(Name = "建筑")] - [SelectList(nameof(IoTGatewayId), "GetIoTGateway")] + [SelectList(nameof(IoTGatewayId), nameof(AjaxController.GetIoTGateway))] [ReadOnlyForEdit] public Guid? BuildingId { get; set; } [Display(Name = "分类")] [ReadOnlyForEdit] - [SelectList(nameof(ProductId), "GetIoTProductByCategory")] + [SelectList(nameof(ProductId), nameof(AjaxController.GetIoTProductByCategory))] public Guid? CategoryId { get; set; } } } diff --git a/projects/Platform/Application/Models/IoTCenter/EditPlatformIoTDeviceModel.cs b/projects/Platform/Application/Models/IoTCenter/EditPlatformIoTDeviceModel.cs index 4e65e8bc..702a0ee3 100644 --- a/projects/Platform/Application/Models/IoTCenter/EditPlatformIoTDeviceModel.cs +++ b/projects/Platform/Application/Models/IoTCenter/EditPlatformIoTDeviceModel.cs @@ -1,4 +1,5 @@ using IoT.Shared.Application.Models; +using Platform.Areas.IoTCenter.Controllers; using System; using System.ComponentModel.DataAnnotations; @@ -8,18 +9,18 @@ namespace Platform.Application.Models.IoTCenter public class EditPlatformIoTDeviceModel : EditIoTDeviceModel { [Display(Name = "机构")] - [SelectList(nameof(BuildingId), "GetBuilding")] + [SelectList(nameof(BuildingId), nameof(AjaxController.GetBuilding))] [ReadOnlyForEdit] public Guid? OrganId { get; set; } [Display(Name = "建筑")] - [SelectList(nameof(IoTGatewayId), "GetIoTGateway")] + [SelectList(nameof(IoTGatewayId), nameof(AjaxController.GetIoTGateway))] [ReadOnlyForEdit] public Guid? BuildingId { get; set; } [Display(Name = "分类")] [ReadOnlyForEdit] - [SelectList(nameof(ProductId), "GetIoTProductByCategory")] + [SelectList(nameof(ProductId), nameof(AjaxController.GetIoTProductByCategory))] public Guid? CategoryId { get; set; } } } diff --git a/projects/Platform/Application/Models/IoTCenter/EditPlatformIoTGatewayModel.cs b/projects/Platform/Application/Models/IoTCenter/EditPlatformIoTGatewayModel.cs index fdbc7e80..34c2c116 100644 --- a/projects/Platform/Application/Models/IoTCenter/EditPlatformIoTGatewayModel.cs +++ b/projects/Platform/Application/Models/IoTCenter/EditPlatformIoTGatewayModel.cs @@ -1,6 +1,7 @@ using System; using IoT.Shared.Application.Models; using System.ComponentModel.DataAnnotations; +using Platform.Areas.IoTCenter.Controllers; namespace Platform.Application.Models.IoTCenter { @@ -8,7 +9,7 @@ namespace Platform.Application.Models.IoTCenter public class EditPlatformIoTGatewayModel : EditIoTGatewayModel { [Display(Name = "机构")] - [SelectList(nameof(BuildingId),"GetBuilding")] + [SelectList(nameof(BuildingId), nameof(AjaxController.GetBuilding))] public Guid? OrganId { get; set; } [Display(Name = "建筑")] diff --git a/projects/Platform/Application/Models/IoTCenter/EditPlatformIoTParameterModel.cs b/projects/Platform/Application/Models/IoTCenter/EditPlatformIoTParameterModel.cs index cf07ff2d..a3477171 100644 --- a/projects/Platform/Application/Models/IoTCenter/EditPlatformIoTParameterModel.cs +++ b/projects/Platform/Application/Models/IoTCenter/EditPlatformIoTParameterModel.cs @@ -1,6 +1,7 @@ using System; using IoT.Shared.Application.Models; using System.ComponentModel.DataAnnotations; +using Platform.Areas.IoTCenter.Controllers; namespace Platform.Application.Models.IoTCenter { @@ -9,7 +10,7 @@ namespace Platform.Application.Models.IoTCenter { [Display(Name = "分类")] [ReadOnlyForEdit] - [SelectList(nameof(ProductId),"GetIoTProductByCategory")] + [SelectList(nameof(ProductId), nameof(AjaxController.GetIoTProductByCategory))] public Guid? CategoryId { get; set; } } } diff --git a/projects/Platform/Areas/IoTCenter/Controllers/IoTCommandController.cs b/projects/Platform/Areas/IoTCenter/Controllers/IoTCommandController.cs index 38646578..1e7b9a65 100644 --- a/projects/Platform/Areas/IoTCenter/Controllers/IoTCommandController.cs +++ b/projects/Platform/Areas/IoTCenter/Controllers/IoTCommandController.cs @@ -53,16 +53,16 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls public override IQueryable<IoTCommand> Include(IQueryable<IoTCommand> query) { return query - .Include(o => o.Device).ThenInclude(o => o.IoTGateway).ThenInclude(o => o.Building).ThenInclude(o => o.Organ) + .Include(o => o.IoTDevice).ThenInclude(o => o.IoTGateway).ThenInclude(o => o.Building).ThenInclude(o => o.Organ) .Include(o => o.Api); } public override IQueryable<IoTCommand> Query(PagedListModel<EditIoTCommandModel> model, IQueryable<IoTCommand> query) { return query - .WhereIf(model.Query.OrganId.HasValue, o => o.Device.IoTGateway.Building.OrganId == model.Query.OrganId.Value) - .WhereIf(model.Query.BuildingId.HasValue, o => o.Device.IoTGateway.BuildingId == model.Query.BuildingId.Value) - .WhereIf(model.Query.IoTGatewayId.HasValue, o => o.Device.IoTGatewayId == model.Query.IoTGatewayId.Value) + .WhereIf(model.Query.OrganId.HasValue, o => o.IoTDevice.IoTGateway.Building.OrganId == model.Query.OrganId.Value) + .WhereIf(model.Query.BuildingId.HasValue, o => o.IoTDevice.IoTGateway.BuildingId == model.Query.BuildingId.Value) + .WhereIf(model.Query.IoTGatewayId.HasValue, o => o.IoTDevice.IoTGatewayId == model.Query.IoTGatewayId.Value) .WhereIf(model.Query.DeviceId.HasValue, o => o.DeviceId == model.Query.DeviceId.Value) .WhereIf(model.Query.ApiId.HasValue, o => o.ApiId == model.Query.ApiId.Value) .WhereIf(!string.IsNullOrEmpty(model.Query.Name), o => o.Name.Contains(model.Query.Name)) @@ -110,15 +110,15 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls { if (entity != null) { - model.IoTGatewayId = entity.Device?.IoTGatewayId; - model.BuildingId = entity.Device?.IoTGateway?.BuildingId; - model.OrganId = entity.Device?.IoTGateway?.Building?.OrganId; + model.IoTGatewayId = entity.IoTDevice?.IoTGatewayId; + model.BuildingId = entity.IoTDevice?.IoTGateway?.BuildingId; + model.OrganId = entity.IoTDevice?.IoTGateway?.Building?.OrganId; } if (model.BuildingId.HasValue) { var name = this._buildingRepo.ReadOnlyTable() .Where(o => o.ParentId != null) - .Where(o => o.Left <= entity.Device.IoTGateway.Building.Left && o.Right >= entity.Device.IoTGateway.Building.Right) + .Where(o => o.Left <= entity.IoTDevice.IoTGateway.Building.Left && o.Right >= entity.IoTDevice.IoTGateway.Building.Right) .ToList() .ToTree() .FirstOrDefault(o => o.Id == model.BuildingId.Value)?.GetDisplayName(); @@ -128,19 +128,19 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls { var name = this._organRepo.ReadOnlyTable() .Where(o => o.ParentId != null) - .Where(o => o.Left <= entity.Device.IoTGateway.Building.Organ.Left && o.Right >= entity.Device.IoTGateway.Building.Organ.Right) + .Where(o => o.Left <= entity.IoTDevice.IoTGateway.Building.Organ.Left && o.Right >= entity.IoTDevice.IoTGateway.Building.Organ.Right) .ToList() .ToTree() - .FirstOrDefault(o => o.Id == entity.Device.IoTGateway.Building.OrganId)?.GetDisplayName(); + .FirstOrDefault(o => o.Id == entity.IoTDevice.IoTGateway.Building.OrganId)?.GetDisplayName(); ViewData.Add(model.OrganId, name); } if (model.IoTGatewayId.HasValue) { - ViewData.Add(model.IoTGatewayId, entity.Device.IoTGateway.Name); + ViewData.Add(model.IoTGatewayId, entity.IoTDevice.IoTGateway.Name); } if (model.DeviceId.HasValue) { - ViewData.Add(model.DeviceId, entity.Device.Name); + ViewData.Add(model.DeviceId, entity.IoTDevice.Name); } if (model.ApiId.HasValue) { @@ -152,9 +152,9 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls { if (entity != null) { - model.IoTGatewayId = entity.Device?.IoTGatewayId; - model.BuildingId = entity.Device?.IoTGateway?.BuildingId; - model.OrganId = entity.Device?.IoTGateway?.Building?.OrganId; + model.IoTGatewayId = entity.IoTDevice?.IoTGatewayId; + model.BuildingId = entity.IoTDevice?.IoTGateway?.BuildingId; + model.OrganId = entity.IoTDevice?.IoTGateway?.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); diff --git a/projects/Platform/Areas/IoTCenter/Controllers/IoTSceneIoTCommandController.cs b/projects/Platform/Areas/IoTCenter/Controllers/IoTSceneIoTCommandController.cs index 93624429..0b96f834 100644 --- a/projects/Platform/Areas/IoTCenter/Controllers/IoTSceneIoTCommandController.cs +++ b/projects/Platform/Areas/IoTCenter/Controllers/IoTSceneIoTCommandController.cs @@ -20,45 +20,98 @@ namespace Platform.Areas.IoTCenter.Controllers public class IoTSceneIoTCommandController : CrudController<IoTSceneIoTCommand, EditIoTSceneIoTCommandModel> { - private readonly AjaxController _ajax; + private readonly AjaxController _ajax; + private readonly IRepository<Organ> _organRepo; - public IoTSceneIoTCommandController(IRepository<IoTSceneIoTCommand> repo, AjaxController ajax) : base(repo) + 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.Device).ThenInclude(o => o.IoTGateway); + .Include(o => o.IoTCommand).ThenInclude(o => o.IoTDevice).ThenInclude(o => o.IoTGateway).ThenInclude(o=>o.Building); } public override IQueryable<IoTSceneIoTCommand> Query(PagedListModel<EditIoTSceneIoTCommandModel> model, IQueryable<IoTSceneIoTCommand> query) { - return query.WhereIf(model.Query.IoTGatewayId.HasValue, o => o.IoTCommand.Device.IoTGatewayId == model.Query.IoTGatewayId.Value) + 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.CommandId.HasValue, o => o.IoTCommandId == model.Query.CommandId.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 ToDisplayModel(IoTSceneIoTCommand entity, EditIoTSceneIoTCommandModel model) + { + if(entity!=null) + { + model.OrganId = entity.IoTScene?.Building?.OrganId; + model.IoTSceneBuildingId = entity.IoTScene?.BuildingId; + model.DeviceBuildingId = entity.IoTCommand?.IoTDevice?.IoTGateway?.BuildingId; + } + 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) { - this.ToDisplayModel(entity, model); + if (entity != null) + { + model.OrganId = entity.IoTScene?.Building?.OrganId; + model.IoTSceneBuildingId = entity.IoTScene?.BuildingId; + model.DeviceBuildingId = entity.IoTCommand?.IoTDevice?.IoTGateway?.BuildingId; + } ViewData.SelectList(o => model.OrganId, () => this._ajax.GetOrgan(model.OrganId).SelectList()); - ViewData.SelectList(o => model.IoTSceneId, () => this._ajax.GetOrganSceneSelectList(model.OrganId.Value, model.IoTSceneId), model.OrganId.HasValue); - ViewData.SelectList(o => model.IoTGatewayId, () => this._ajax.GetOrganNodeSelectList(model.OrganId.Value, model.IoTGatewayId), model.OrganId.HasValue); - //ViewData.SelectList(o => model.CommandId, () => this._ajax.GetCommandSelectList(model.NodeId.Value, model.CommandId), model.NodeId.HasValue); + 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); } - public override void ToDisplayModel(IoTSceneIoTCommand entity, EditIoTSceneIoTCommandModel model) - { - model.OrganId = entity?.IoTScene?.Building?.OrganId; - model.IoTGatewayId = entity?.IoTCommand.Device.IoTGatewayId; - 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); - } + } } diff --git a/projects/Platform/Areas/IoTCenter/Controllers/IoTTiggerController.cs b/projects/Platform/Areas/IoTCenter/Controllers/IoTTiggerController.cs index dba17adf..b7c500ee 100644 --- a/projects/Platform/Areas/IoTCenter/Controllers/IoTTiggerController.cs +++ b/projects/Platform/Areas/IoTCenter/Controllers/IoTTiggerController.cs @@ -56,7 +56,7 @@ namespace Platform.Areas.IoTCenter.Controllers this.ToDisplayModel(entity, model); 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.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(), model.IoTGatewayId.HasValue); ViewData.SelectList(o => model.DataId, () => this._ajax.GetDataSelectList(model.DeviceId.Value), model.DeviceId.HasValue); } diff --git a/projects/Platform/Areas/IoTCenter/Controllers/IoTTimerController.cs b/projects/Platform/Areas/IoTCenter/Controllers/IoTTimerController.cs index f28f70f5..658142e3 100644 --- a/projects/Platform/Areas/IoTCenter/Controllers/IoTTimerController.cs +++ b/projects/Platform/Areas/IoTCenter/Controllers/IoTTimerController.cs @@ -48,7 +48,7 @@ namespace Platform.Areas.IoTCenter.Controllers { this.ToDisplayModel(entity, model); ViewData.SelectList(o => model.OrganId, () => this._ajax.GetOrgan(model.OrganId).SelectList()); - ViewData.SelectList(o => model.OrganSceneId, () => this._ajax.GetOrganSceneSelectList(model.OrganId.Value, model.OrganSceneId), model.OrganId.HasValue); + //ViewData.SelectList(o => model.OrganSceneId, () => this._ajax.GetOrganSceneSelectList(model.OrganId.Value, model.OrganSceneId), model.OrganId.HasValue); } public override void ToDisplayModel(IoTTimer entity, EditIoTTimerModel model) diff --git a/projects/Platform/Areas/IoTCenter/Views/IoTSceneIoTCommand/_Script.cshtml b/projects/Platform/Areas/IoTCenter/Views/IoTSceneIoTCommand/_Script.cshtml new file mode 100644 index 00000000..aa70a4ba --- /dev/null +++ b/projects/Platform/Areas/IoTCenter/Views/IoTSceneIoTCommand/_Script.cshtml @@ -0,0 +1,65 @@ +<script> + $(function () { + //change('GatewayId', 'DeviceId', '@Url.Action("GetIoTDeviceForCommand", "Ajax",new { area=""})'); + //change('DeviceId', 'ApiId', '@Url.Action("GetIoTApiByDevice", "Ajax",new { area=""})'); + $('#ApiId').change(function () { + var id = $(this).find(':selected').val(); + $('#Url').parent().find('#ajax').html(''); + var url = '@Url.Action("Ajax")?apiId=' + encodeURI(id) + '&deviceId=' + encodeURI($('#DeviceId').val()); + $.get(url, function (html) { + $('#ajax').html(html); + reset(); + }); + }); + $('body').on('change','.irKeyType',function () { + var id = $(this).find(':selected').val(); + $('#ajax2').html(''); + if (id) { + var url = '@Url.Action("Code")?type=' + encodeURI(id) + '&code=' + encodeURI($('#ircodeid').val())+ '&name=' + encodeURI($('#ajax2').attr('data-name'))+ '&deviceId=' + encodeURI($('#DeviceId').val()); + $.get(url, function (html) { + $('#ajax2').html(html); + reset(); + }); + } + }); + $('body').on('change', "input[type='range']", function (e) { + $(this).prev().find('span').html(parseInt(e.target.value) + 15); + }); + }); + function AirChange(e) { + var form = $('#ircodediv'); + var list = {}; + list['power'] = form.find("[name = 'power']:checked").val(); + list['pattern'] = form.find("[name = 'pattern']:checked").val(); + list['direction'] = form.find("[name = 'direction']:checked").val(); + list['wind'] = form.find("[name = 'wind']:checked").val(); + list['temperature'] = form.find("[name = 'temperature']").val(); + list[event.target.name] = event.target.value; + var code = 0; + if (list['power'] === "1") { + code = 1; + } + else { + for (var name in list) { + code += parseInt(list[name]); + } + } + + $('#ircodeid').val(code); + } + function CodeChange(e) { + var form = $('#ircodediv'); + var list = {}; + list['power'] = form.find("[name = 'power']:checked").val(); + list['pattern'] = form.find("[name = 'pattern']:checked").val(); + list['direction'] = form.find("[name = 'direction']:checked").val(); + list['wind'] = form.find("[name = 'wind']:checked").val(); + list['temperature'] = form.find("[name = 'temperature']").val(); + list[event.target.name] = event.target.value; + code = 0; + for (var name in list) { + code += parseInt(list[name]); + } + $('#ircodeid').val(code); + } +</script> \ No newline at end of file diff --git a/projects/Platform/Controllers/AjaxController.cs b/projects/Platform/Controllers/AjaxController.cs index 04ae9172..4fa06e0c 100644 --- a/projects/Platform/Controllers/AjaxController.cs +++ b/projects/Platform/Controllers/AjaxController.cs @@ -66,6 +66,37 @@ namespace Platform.Areas.IoTCenter.Controllers return new JsonResult(new SelectList(list, "Id", "Name", selected)); } + public JsonResult GetBuildingByScene(Guid parentId, Guid? selected) + { + using var serviceScope = this._services.CreateScope(); + var sceneRepo = serviceScope.ServiceProvider.GetRequiredService<IRepository<IoTScene>>(); + var building = sceneRepo.ReadOnlyTable() + .Where(o => o.Id == parentId) + .Select(o => o.Building) + .FirstOrDefault(); + var repo = serviceScope.ServiceProvider.GetRequiredService<IRepository<Building>>(); + var list = repo.ReadOnlyTable() + .Where(o => o.ParentId != null) + .Where(o => o.Left >=building.Left&&o.Right<= building.Right) + .OrderBy(o => o.ParentId) + .ThenBy(o => o.DisplayOrder) + .ToList() + .ToTree().Select(o => new Building { Id = o.Id, Name = o.GetDisplayName() }) + .ToList(); + return new JsonResult(new SelectList(list, "Id", "Name", selected)); + } + public JsonResult GetIoTCommand(Guid parentId, Guid? selected) + { + using var serviceScope = this._services.CreateScope(); + var repo = serviceScope.ServiceProvider.GetRequiredService<IRepository<IoTCommand>>(); + var list = repo.ReadOnlyTable() + .Where(o => o.IoTDevice.IoTGateway.BuildingId == parentId) + .OrderBy(o => o.ApiId) + .ThenBy(o => o.DisplayOrder) + .Select(o => new { o.Id, Name=$"{o.IoTDevice.IoTGateway.Name}-{o.IoTDevice.DisplayName??o.IoTDevice.Name}-{o.Name??o.Api.Name}"}) + .ToList(); + return new JsonResult(new SelectList(list, "Id", "Name", selected)); + } public JsonResult GetUser(Guid? parentId, Guid? selected = null, string search = null, ControllerScopeType? range = null) { using var scope = this._services.CreateScope(); @@ -183,6 +214,17 @@ namespace Platform.Areas.IoTCenter.Controllers return new JsonResult(new SelectList(list, "Id", "Name", selected)); } + public JsonResult GetIoTScene(Guid parentId, Guid? selected = null) + { + using var scope = this._services.CreateScope(); + var repo = scope.ServiceProvider.GetRequiredService<IRepository<IoTScene>>(); + var list = repo.ReadOnlyTable() + .Where(o => o.BuildingId == parentId) + .Select(o => new { o.Id, o.Name }) + .ToList(); + return new JsonResult(new SelectList(list, "Id", "Name", selected)); + } + public JsonResult GetIoTApiByDevice(Guid parentId, Guid? selected = null) { using var scope = this._services.CreateScope(); @@ -203,6 +245,7 @@ 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(); @@ -214,32 +257,5 @@ namespace Platform.Areas.IoTCenter.Controllers .ToList(); return new SelectList(list, "Id", "Name", deviceNumber); } - public SelectList GetOrganNodeSelectList(Guid parentId, Guid? selected = null) - { - using var scope = this._services.CreateScope(); - var repo = scope.ServiceProvider.GetRequiredService<IRepository<BuildingIoTGateway>>(); - var list = repo.ReadOnlyTable() - .Where(o => o.Building.OrganId == parentId) - .Select(o => o.IoTGateway) - .Select(o => new { o.Id, Name = $"{o.Name}({o.Number})" }) - .ToList(); - return new SelectList(list, "Id", "Name", selected); - } - - public SelectList GetOrganSceneSelectList(Guid parentId, Guid? selected = null) - { - using var scope = this._services.CreateScope(); - var repo = scope.ServiceProvider.GetRequiredService<IRepository<IoTScene>>(); - var list = repo.ReadOnlyTable() - .Where(o => o.Building.OrganId == parentId) - .Select(o => new { o.Id, o.Name }) - .ToList(); - return new SelectList(list, "Id", "Name", selected); - } - - public JsonResult GetOrganSceneJson(Guid parentId, Guid? selected) - { - return new JsonResult(this.GetOrganSceneSelectList(parentId, selected)); - } } } diff --git a/projects/Platform/Controllers/HomeController.cs b/projects/Platform/Controllers/HomeController.cs index 19a4f2f5..23d3eee2 100644 --- a/projects/Platform/Controllers/HomeController.cs +++ b/projects/Platform/Controllers/HomeController.cs @@ -74,12 +74,6 @@ namespace Platform.Controllers {//即未选中建筑也未选中机构,则用户所在机构为当前机构 model.Organ = organList.FirstOrDefault(o => o.Id == userOrganId); } - model.Scenes = this._buildingRepo.ReadOnlyTable() - .Where(o => o.OrganId == model.Organ.Id) - .SelectMany(o=>o.Scenes) - .Where(o => o.Hidden == false) - .WhereIf(model.BuildingId.HasValue,o => o.BuildingId == model.BuildingId.Value) - .ToList(); } model.OrganId = model.Organ.Id; diff --git a/projects/Platform/Data/PlatformDbContext.cs b/projects/Platform/Data/PlatformDbContext.cs index fde6e4c9..2596c5d7 100644 --- a/projects/Platform/Data/PlatformDbContext.cs +++ b/projects/Platform/Data/PlatformDbContext.cs @@ -86,17 +86,14 @@ namespace Platform.Data modelBuilder.Entity<IoTProduct>().HasOne(o => o.Category).WithMany(o => o.Products).HasForeignKey(o => o.CategoryId).OnDelete(DeleteBehavior.SetNull); //IoTGateway modelBuilder.Entity<IoTGateway>().HasOne(o => o.Building).WithMany(o => o.IoTGateways).HasForeignKey(o => o.BuildingId).OnDelete(DeleteBehavior.SetNull); - //IoTProductCategoryIoTProduct - //modelBuilder.Entity<IoTProductCategoryIoTProduct>().HasOne(o => o.Category).WithMany(o => o.CategoryProducts).HasForeignKey(o => o.CategoryId); - //modelBuilder.Entity<IoTProductCategoryIoTProduct>().HasOne(o => o.Product).WithMany().HasForeignKey(o => o.ProductId); - //modelBuilder.Entity<IoTProductCategoryIoTProduct>().HasIndex(o => o.ProductId).IsUnique();//通过唯一约束,保证一个商品只有一个分类 //IoTCommand - modelBuilder.Entity<IoTCommand>().HasOne(o => o.Api).WithMany().HasForeignKey(o => o.ApiId); + modelBuilder.Entity<IoTCommand>().HasOne(o => o.Api).WithMany(o=>o.IoTCommands).HasForeignKey(o => o.ApiId); + modelBuilder.Entity<IoTCommand>().HasOne(o => o.IoTDevice).WithMany(o=>o.IoTCommands).HasForeignKey(o => o.DeviceId); //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); + modelBuilder.Entity<IoTSceneIoTCommand>().HasOne(o => o.IoTScene).WithMany(o => o.IoTSceneIoTCommands).HasForeignKey(o => o.IoTSceneId); + modelBuilder.Entity<IoTSceneIoTCommand>().HasOne(o => o.IoTCommand).WithMany(o=>o.IoTSceneIoTCommands).HasForeignKey(o => o.IoTCommandId); //IoTTimer modelBuilder.Entity<IoTTimer>().HasOne(o => o.IoTScene).WithMany(o => o.IoTTimers).HasForeignKey(o => o.IoTSceneId); //IoTTigger diff --git a/projects/Platform/Services/IoTCenterEventHandler.cs b/projects/Platform/Services/IoTCenterEventHandler.cs index 11d797a8..996c82b8 100644 --- a/projects/Platform/Services/IoTCenterEventHandler.cs +++ b/projects/Platform/Services/IoTCenterEventHandler.cs @@ -307,13 +307,13 @@ namespace Platform.Services { this._logger.LogDebug($"global tigger exec:{tiggerId}"); var tigger = this._sceneTiggerRepo.ReadOnlyTable() - .Include(o => o.IoTScene).ThenInclude(o => o.IoTCommands).ThenInclude(o => o.IoTCommand).ThenInclude(o => o.Device).ThenInclude(o => o.IoTGateway) + .Include(o => o.IoTScene).ThenInclude(o => o.IoTSceneIoTCommands).ThenInclude(o => o.IoTCommand).ThenInclude(o => o.IoTDevice).ThenInclude(o => o.IoTGateway) .FirstOrDefault(o => o.Id == tiggerId); - foreach (var sceneCommand in tigger.IoTScene.IoTCommands.OrderBy(o => o.IoTCommand.DisplayOrder)) + foreach (var sceneCommand in tigger.IoTScene.IoTSceneIoTCommands.OrderBy(o => o.IoTCommand.DisplayOrder)) { try { - this._hub.ServerToClient(Methods.ExecCommand, sceneCommand.IoTCommandId, sceneCommand.IoTCommand.Device.IoTGateway.Number, null); + this._hub.ServerToClient(Methods.ExecCommand, sceneCommand.IoTCommandId, sceneCommand.IoTCommand.IoTDevice.IoTGateway.Number, null); Delay(_settingService, sceneCommand.IoTCommand.Delay); } catch (Exception ex) @@ -398,15 +398,15 @@ namespace Platform.Services { _logger.LogInformation($"global timer exec at {DateTime.Now.ToString("G")}:{id}"); var timer = _organSceneTimerRepo.ReadOnlyTable() - .Include(o => o.IoTScene).ThenInclude(o => o.IoTCommands).ThenInclude(o => o.IoTCommand).ThenInclude(o => o.Device).ThenInclude(o => o.IoTGateway) + .Include(o => o.IoTScene).ThenInclude(o => o.IoTSceneIoTCommands).ThenInclude(o => o.IoTCommand).ThenInclude(o => o.IoTDevice).ThenInclude(o => o.IoTGateway) .FirstOrDefault(o => o.Id == id); if (timer != null) { - foreach (var sceneCommand in timer.IoTScene.IoTCommands.OrderBy(o => o.IoTCommand.DisplayOrder)) + foreach (var sceneCommand in timer.IoTScene.IoTSceneIoTCommands.OrderBy(o => o.IoTCommand.DisplayOrder)) { try { - _hub.ServerToClient(Methods.ExecCommand, sceneCommand.IoTCommandId, sceneCommand.IoTCommand.Device.IoTGateway.Number, null); + _hub.ServerToClient(Methods.ExecCommand, sceneCommand.IoTCommandId, sceneCommand.IoTCommand.IoTDevice.IoTGateway.Number, null); Delay(_settingService, sceneCommand.IoTCommand.Delay); } catch (Exception ex) diff --git a/projects/Platform/db.sql b/projects/Platform/db.sql index 254843e9..5eec6191 100644 --- a/projects/Platform/db.sql +++ b/projects/Platform/db.sql @@ -396,10 +396,8 @@ CREATE TABLE `iot_IoTSceneIoTCommand` ( `IsDeleted` longtext CHARACTER SET utf8mb4 NULL, `IoTSceneId` char(36) NOT NULL, `IoTCommandId` char(36) NOT NULL, - `IoTCommandId1` char(36) NULL, CONSTRAINT `PK_iot_IoTSceneIoTCommand` PRIMARY KEY (`Id`), CONSTRAINT `FK_iot_IoTSceneIoTCommand_iot_IoTCommand_IoTCommandId` FOREIGN KEY (`IoTCommandId`) REFERENCES `iot_IoTCommand` (`Id`) ON DELETE CASCADE, - CONSTRAINT `FK_iot_IoTSceneIoTCommand_iot_IoTCommand_IoTCommandId1` FOREIGN KEY (`IoTCommandId1`) REFERENCES `iot_IoTCommand` (`Id`) ON DELETE RESTRICT, CONSTRAINT `FK_iot_IoTSceneIoTCommand_iot_IoTScene_IoTSceneId` FOREIGN KEY (`IoTSceneId`) REFERENCES `iot_IoTScene` (`Id`) ON DELETE CASCADE ); @@ -470,8 +468,6 @@ CREATE INDEX `IX_iot_IoTScene_BuildingId` ON `iot_IoTScene` (`BuildingId`); CREATE INDEX `IX_iot_IoTSceneIoTCommand_IoTCommandId` ON `iot_IoTSceneIoTCommand` (`IoTCommandId`); -CREATE INDEX `IX_iot_IoTSceneIoTCommand_IoTCommandId1` ON `iot_IoTSceneIoTCommand` (`IoTCommandId1`); - CREATE INDEX `IX_iot_IoTSceneIoTCommand_IoTSceneId` ON `iot_IoTSceneIoTCommand` (`IoTSceneId`); CREATE INDEX `IX_iot_IoTTigger_DataId` ON `iot_IoTTigger` (`DataId`);