diff --git a/projects/Infrastructure/Views/Shared/EditorTemplates/Object.cshtml b/projects/Infrastructure/Views/Shared/EditorTemplates/Object.cshtml index aff793fd..f14af7ac 100644 --- a/projects/Infrastructure/Views/Shared/EditorTemplates/Object.cshtml +++ b/projects/Infrastructure/Views/Shared/EditorTemplates/Object.cshtml @@ -57,7 +57,7 @@ @{ if (metadata != null) { - var attr = metadata.Attributes.Attributes.OfType().FirstOrDefault() as System.ComponentModel.DescriptionAttribute; + var attr = metadata.Attributes.Attributes.OfType().FirstOrDefault() as DescriptionAttribute; if (attr != null && attr.Description != null) { @attr.Description diff --git a/projects/IoT.Shared/Application/Models/EditDeviceModel.cs b/projects/IoT.Shared/Application/Models/EditDeviceModel.cs index 52c17886..0731d56b 100644 --- a/projects/IoT.Shared/Application/Models/EditDeviceModel.cs +++ b/projects/IoT.Shared/Application/Models/EditDeviceModel.cs @@ -1,6 +1,5 @@ using Infrastructure.Application; using System; -using System.ComponentModel; using System.ComponentModel.DataAnnotations; namespace IoT.Shared.Application.Models @@ -8,12 +7,24 @@ namespace IoT.Shared.Application.Models [Display(Name = "设备")] public class EditDeviceModel : EditModel { + [ReadOnlyForEdit] + [Display(Name = "产品分类")] + [SelectList(nameof(ProductId), "GetIoTProduct")] + public Guid? ProductCategoryId { get; set; } + [ReadOnlyForEdit] [Display(Name = "产品")] [SelectList] - [Required(ErrorMessage = nameof(RequiredAttribute))] public Guid? ProductId { get; set; } + [Display(Name = "机构")] + [SelectList(nameof(BuildingId), "GetBuilding")] + public Guid? OrganId { get; set; } + + [Display(Name = "建筑")] + [SelectList(nameof(NodeId), "GetIoTGateway")] + public Guid? BuildingId { get; set; } + [ReadOnlyForEdit] [SelectList] [Display(Name = "网关")] diff --git a/projects/IoT.Shared/Application/Models/EditApiModel.cs b/projects/IoT.Shared/Application/Models/EditIoTApiModel.cs similarity index 92% rename from projects/IoT.Shared/Application/Models/EditApiModel.cs rename to projects/IoT.Shared/Application/Models/EditIoTApiModel.cs index 3e4cda19..ab85c984 100644 --- a/projects/IoT.Shared/Application/Models/EditApiModel.cs +++ b/projects/IoT.Shared/Application/Models/EditIoTApiModel.cs @@ -4,12 +4,12 @@ using System.ComponentModel.DataAnnotations; namespace IoT.Shared.Application.Models { - [Display(Name = "Api")] - public class EditApiModel : EditModel + [Display(Name = "接口")] + public class EditIoTApiModel : EditModel { [Display(Name = "产品")] - [SelectList] [ReadOnlyForEdit] + [SelectList] [Required(ErrorMessage = nameof(RequiredAttribute))] public Guid? ProductId { get; set; } diff --git a/projects/IoT.Shared/Application/Models/SearchApiModel.cs b/projects/IoT.Shared/Application/Models/SearchApiModel.cs index 4c100d27..88f12493 100644 --- a/projects/IoT.Shared/Application/Models/SearchApiModel.cs +++ b/projects/IoT.Shared/Application/Models/SearchApiModel.cs @@ -4,7 +4,7 @@ using System.ComponentModel.DataAnnotations; namespace IoT.Shared.Application.Models { - public class SearchApiModel : PagedListModel + public class SearchApiModel : PagedListModel { [SelectList] [Display(Name = "产品")] diff --git a/projects/IoTNode/Areas/IoTCenter/Controllers/IoTApiController.cs b/projects/IoTNode/Areas/IoTCenter/Controllers/IoTApiController.cs index 9b7af79f..c2c97dc8 100644 --- a/projects/IoTNode/Areas/IoTCenter/Controllers/IoTApiController.cs +++ b/projects/IoTNode/Areas/IoTCenter/Controllers/IoTApiController.cs @@ -17,7 +17,7 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls [Route("IoTCenter/[controller]/[action]")] [Area("IoTCenter")] [ControllerScope(ControllerScopeType.Platform)] - public class IoTApiController : CrudController + public class IoTApiController : CrudController { private readonly AjaxBaseController _ajax; @@ -31,7 +31,7 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls return query.Include(o => o.Product); } - public override IQueryable Query(PagedListModel model, IQueryable query) + public override IQueryable Query(PagedListModel model, IQueryable query) { ViewData.SelectList(o => model.Query.ProductId, () => this._ajax.GetIoTProduct(model.Query.ProductId).SelectList()); return query @@ -42,12 +42,12 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls .WhereIf(!string.IsNullOrEmpty(model.Query.Method), o => o.Method.Contains(model.Query.Method)); } - public override void ToDisplayModel(IoTApi entity, EditApiModel model) + public override void ToDisplayModel(IoTApi entity, EditIoTApiModel model) { ViewData.Add(model.ProductId, entity?.Product?.Name); } - public override void ToEditModel(IoTApi entity, EditApiModel model) + public override void ToEditModel(IoTApi entity, EditIoTApiModel model) { this.ToDisplayModel(entity, model); ViewData.SelectList(o => model.ProductId, () => this._ajax.GetIoTProduct(model.ProductId).SelectList()); diff --git a/projects/Platform/Application/Models/IoTCenter/EditPlatformIoTApiModel.cs b/projects/Platform/Application/Models/IoTCenter/EditPlatformIoTApiModel.cs new file mode 100644 index 00000000..d6fa9273 --- /dev/null +++ b/projects/Platform/Application/Models/IoTCenter/EditPlatformIoTApiModel.cs @@ -0,0 +1,15 @@ +using System; +using IoT.Shared.Application.Models; +using System.ComponentModel.DataAnnotations; + +namespace Platform.Application.Models.IoTCenter +{ + [Display(Name = "接口")] + public class EditPlatformIoTApiModel : EditIoTApiModel + { + [Display(Name = "分类")] + [ReadOnlyForEdit] + [SelectList(nameof(ProductId),"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 8149959b..fdbc7e80 100644 --- a/projects/Platform/Application/Models/IoTCenter/EditPlatformIoTGatewayModel.cs +++ b/projects/Platform/Application/Models/IoTCenter/EditPlatformIoTGatewayModel.cs @@ -9,12 +9,10 @@ namespace Platform.Application.Models.IoTCenter { [Display(Name = "机构")] [SelectList(nameof(BuildingId),"GetBuilding")] - [Required(ErrorMessage = nameof(RequiredAttribute))] public Guid? OrganId { get; set; } [Display(Name = "建筑")] [SelectList] - [Required(ErrorMessage = nameof(RequiredAttribute))] public Guid? BuildingId { get; set; } } } diff --git a/projects/Platform/Areas/IoTCenter/Controllers/IoTApiController.cs b/projects/Platform/Areas/IoTCenter/Controllers/IoTApiController.cs index 9b7af79f..1f019e1d 100644 --- a/projects/Platform/Areas/IoTCenter/Controllers/IoTApiController.cs +++ b/projects/Platform/Areas/IoTCenter/Controllers/IoTApiController.cs @@ -7,6 +7,8 @@ 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; @@ -17,24 +19,27 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls [Route("IoTCenter/[controller]/[action]")] [Area("IoTCenter")] [ControllerScope(ControllerScopeType.Platform)] - public class IoTApiController : CrudController + public class IoTApiController : CrudController { - private readonly AjaxBaseController _ajax; + private readonly AjaxController _ajax; + private readonly IRepository _categoryRepo; - public IoTApiController(IRepository repo, AjaxBaseController ajax) : base(repo) + public IoTApiController(IRepository repo, AjaxController ajax, IRepository categoryRepo) : base(repo) { this._ajax = ajax; + this._categoryRepo = categoryRepo; } public override IQueryable Include(IQueryable query) { - return query.Include(o => o.Product); + return query.Include(o => o.Product).ThenInclude(o => o.Category); } - public override IQueryable Query(PagedListModel model, IQueryable query) + public override IQueryable Query(PagedListModel model, IQueryable query) { ViewData.SelectList(o => model.Query.ProductId, () => this._ajax.GetIoTProduct(model.Query.ProductId).SelectList()); return query + .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.Path), o => o.Path.Contains(model.Query.Path)) @@ -42,15 +47,37 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls .WhereIf(!string.IsNullOrEmpty(model.Query.Method), o => o.Method.Contains(model.Query.Method)); } - public override void ToDisplayModel(IoTApi entity, EditApiModel model) + public override void ToDisplayModel(IoTApi entity, EditPlatformIoTApiModel model) { - ViewData.Add(model.ProductId, entity?.Product?.Name); + model.CategoryId = entity?.Product?.CategoryId; + if (entity != null) + { + ViewData.Add(model.ProductId.Value, entity.Product.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.Value, name); + } } - public override void ToEditModel(IoTApi entity, EditApiModel model) + public override void ToEditModel(IoTApi entity, EditPlatformIoTApiModel model) { - this.ToDisplayModel(entity, model); - ViewData.SelectList(o => model.ProductId, () => this._ajax.GetIoTProduct(model.ProductId).SelectList()); + model.CategoryId = entity?.Product?.CategoryId; + ViewData.SelectList(o => model.CategoryId, () => this._ajax.GetIoTProductCategory(model.CategoryId).SelectList()); + if (model.CategoryId.HasValue) + { + ViewData.SelectList(o => model.ProductId, () => this._ajax.GetIoTProductByCategory(model.CategoryId.Value, model.ProductId).SelectList()); + } + else + { + ViewData.Add(model.ProductId, entity?.Product?.Name); + } } } } diff --git a/projects/Platform/Areas/IoTCenter/Controllers/IoTDeviceController.cs b/projects/Platform/Areas/IoTCenter/Controllers/IoTDeviceController.cs index 9b978ff9..cb80ce6b 100644 --- a/projects/Platform/Areas/IoTCenter/Controllers/IoTDeviceController.cs +++ b/projects/Platform/Areas/IoTCenter/Controllers/IoTDeviceController.cs @@ -7,6 +7,7 @@ using IoT.Shared.Application.Models; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using Platform.Areas.IoTCenter.Controllers; using System; using System.Linq; @@ -19,31 +20,24 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls [ControllerScope(ControllerScopeType.Platform)] public class IoTDeviceController : IoTSharedController { - private readonly AjaxBaseController _ajax; + private readonly AjaxController _ajax; - public IoTDeviceController(IRepository repo, AjaxBaseController ajax, IServiceProvider sp) : base(repo, sp) + public IoTDeviceController(IRepository repo, AjaxController ajax, IServiceProvider sp) : base(repo, sp) { this._ajax = ajax; } public override IQueryable Include(IQueryable query) { - return query.Include(o => o.Product).Include(o => o.Node); + return query.Include(o => o.Product) + .Include(o => o.Node).ThenInclude(o=>o.Building).ThenInclude(o=>o.Organ); } public override IQueryable Query(PagedListModel model, IQueryable query) { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - //if (this.HttpContext.Request.Query.TryGetValue("query.organNumber", out StringValues value)) - //{ - // var organNumber = value.ToString(); - // //query = query.WhereIf(!string.IsNullOrWhiteSpace(organNumber), o => o.Node.BuildingIoTGateways.Any(o => o.Building.Organ.Number == organNumber)); - //} - 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.ProductId.HasValue, o => o.ProductId == model.Query.ProductId.Value) .WhereIf(!string.IsNullOrEmpty(model.Query.Name), o => o.Name.Contains(model.Query.Name)) @@ -68,8 +62,10 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls public override void ToEditModel(IoTDevice entity, EditDeviceModel model) { - ViewData.SelectList(o => model.NodeId, () => this._ajax.GetIoTGateway(model.NodeId).SelectList()); - ViewData.SelectList(o => model.ProductId, () => this._ajax.GetIoTProduct(model.ProductId).SelectList()); + 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()); } public override string GetNodeNumber(EditDeviceModel model) diff --git a/projects/Platform/Controllers/AjaxController.cs b/projects/Platform/Controllers/AjaxController.cs index 65eb25ea..6d382d44 100644 --- a/projects/Platform/Controllers/AjaxController.cs +++ b/projects/Platform/Controllers/AjaxController.cs @@ -147,6 +147,18 @@ namespace Platform.Areas.IoTCenter.Controllers return new JsonResult(new SelectList(list, "Id", "Name", selected)); } + public JsonResult GetIoTProductByCategory(Guid parentId,Guid? selected=null) + { + using var scope = this._services.CreateScope(); + var repo = scope.ServiceProvider.GetRequiredService>(); + var list = repo.ReadOnlyTable() + .Where(o=>o.CategoryId==parentId) + .Select(o => new { o.Id, o.Name }) + .ToList(); + return new JsonResult(new SelectList(list, "Id", "Name", selected)); + + } + public SelectList GetOrganNodeSelectList(Guid parentId, Guid? selected = null) { using var scope = this._services.CreateScope(); diff --git a/projects/projects.sln b/projects/projects.sln index 3a557ad8..51acd2a4 100644 --- a/projects/projects.sln +++ b/projects/projects.sln @@ -29,7 +29,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebSPA", "WebSPA\WebSPA.csp EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IoTDameon", "IoTDameon\IoTDameon.csproj", "{60596088-3C4E-4EA2-933A-B66CD269845B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Application", "Application\Application.csproj", "{9AEB7CA3-CB61-40D2-8009-1BA93842FE69}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Application", "Application\Application.csproj", "{9AEB7CA3-CB61-40D2-8009-1BA93842FE69}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -140,7 +140,7 @@ Global HideSolutionNode = FALSE EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution - BuildVersion_StartDate = 2000/1/1 SolutionGuid = {0B7095FB-5E70-4EF8-805A-CB4A91AE4B0A} + BuildVersion_StartDate = 2000/1/1 EndGlobalSection EndGlobal