Former-commit-id: 3bcdd3b3e016b7c683690742f9647d305a35c8f8
Former-commit-id: 09b0305c5848d32c1120904df79a15550b782fcb
1.0
wanggang 5 years ago
parent 2136268b28
commit e88c48f8ba

@ -57,7 +57,7 @@
@{
if (metadata != null)
{
var attr = metadata.Attributes.Attributes.OfType<System.ComponentModel.DescriptionAttribute>().FirstOrDefault() as System.ComponentModel.DescriptionAttribute;
var attr = metadata.Attributes.Attributes.OfType<DescriptionAttribute>().FirstOrDefault() as DescriptionAttribute;
if (attr != null && attr.Description != null)
{
<span class="form-control form-control-display">@attr.Description</span>

@ -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 = "网关")]

@ -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; }

@ -4,7 +4,7 @@ using System.ComponentModel.DataAnnotations;
namespace IoT.Shared.Application.Models
{
public class SearchApiModel : PagedListModel<EditApiModel>
public class SearchApiModel : PagedListModel<EditIoTApiModel>
{
[SelectList]
[Display(Name = "产品")]

@ -17,7 +17,7 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls
[Route("IoTCenter/[controller]/[action]")]
[Area("IoTCenter")]
[ControllerScope(ControllerScopeType.Platform)]
public class IoTApiController : CrudController<IoTApi, EditApiModel>
public class IoTApiController : CrudController<IoTApi, EditIoTApiModel>
{
private readonly AjaxBaseController _ajax;
@ -31,7 +31,7 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls
return query.Include(o => o.Product);
}
public override IQueryable<IoTApi> Query(PagedListModel<EditApiModel> model, IQueryable<IoTApi> query)
public override IQueryable<IoTApi> Query(PagedListModel<EditIoTApiModel> model, IQueryable<IoTApi> 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());

@ -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; }
}
}

@ -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; }
}
}

@ -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<IoTApi, EditApiModel>
public class IoTApiController : CrudController<IoTApi, EditPlatformIoTApiModel>
{
private readonly AjaxBaseController _ajax;
private readonly AjaxController _ajax;
private readonly IRepository<IoTProductCategory> _categoryRepo;
public IoTApiController(IRepository<IoTApi> repo, AjaxBaseController ajax) : base(repo)
public IoTApiController(IRepository<IoTApi> repo, AjaxController ajax, IRepository<IoTProductCategory> categoryRepo) : base(repo)
{
this._ajax = ajax;
this._categoryRepo = categoryRepo;
}
public override IQueryable<IoTApi> Include(IQueryable<IoTApi> query)
{
return query.Include(o => o.Product);
return query.Include(o => o.Product).ThenInclude(o => o.Category);
}
public override IQueryable<IoTApi> Query(PagedListModel<EditApiModel> model, IQueryable<IoTApi> query)
public override IQueryable<IoTApi> Query(PagedListModel<EditPlatformIoTApiModel> model, IQueryable<IoTApi> 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);
}
}
}
}

@ -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<IoTDevice, EditDeviceModel>
{
private readonly AjaxBaseController _ajax;
private readonly AjaxController _ajax;
public IoTDeviceController(IRepository<IoTDevice> repo, AjaxBaseController ajax, IServiceProvider sp) : base(repo, sp)
public IoTDeviceController(IRepository<IoTDevice> repo, AjaxController ajax, IServiceProvider sp) : base(repo, sp)
{
this._ajax = ajax;
}
public override IQueryable<IoTDevice> Include(IQueryable<IoTDevice> 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<IoTDevice> Query(PagedListModel<EditDeviceModel> model, IQueryable<IoTDevice> 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)

@ -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<IRepository<IoTProduct>>();
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();

@ -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

Loading…
Cancel
Save