You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
170 lines
7.4 KiB
170 lines
7.4 KiB
using Infrastructure.Data;
|
|
using Infrastructure.Extensions;
|
|
using Infrastructure.Web.Mvc;
|
|
using IoT.Shared.Application.Domain.Entities;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Platform.Areas.IoTCenter.Controllers
|
|
{
|
|
[Area("IoTCenter")]
|
|
public class AjaxController : IoT.Shared.Areas.IoTCenter.Controlls.AjaxBaseController
|
|
{
|
|
public AjaxController(IServiceProvider services,
|
|
ILogger<AjaxController> logger,
|
|
IRepository<IoTProductCategory> categoryRepo,
|
|
IRepository<IoTProduct> productRepo,
|
|
IRepository<Organ> organRepo,
|
|
IRepository<BuildingIoTGateway> buildingIoTGatewayRepo,
|
|
IRepository<OrganIoTScene> organSceneRepo,
|
|
IRepository<IoTGateway> nodeRepo,
|
|
IRepository<IoTScene> sceneRepo,
|
|
IRepository<IoTCommand> commandRepo,
|
|
IRepository<IoTDevice> deviceRepo,
|
|
IRepository<IoTData> dataRepo,
|
|
IRepository<IoTApi> apiRepo,
|
|
IRepository<IoTSceneTigger> sceneTiggerRepo)
|
|
: base(services,
|
|
logger,
|
|
categoryRepo,
|
|
productRepo,
|
|
organRepo,
|
|
buildingIoTGatewayRepo,
|
|
organSceneRepo,
|
|
nodeRepo,
|
|
sceneRepo,
|
|
commandRepo,
|
|
deviceRepo,
|
|
dataRepo,
|
|
apiRepo,
|
|
sceneTiggerRepo)
|
|
{
|
|
}
|
|
|
|
public JsonResult GetArea(Guid? selected)
|
|
{
|
|
using var scope = this._services.CreateScope();
|
|
var repo = scope.ServiceProvider.GetRequiredService<IRepository<Area>>();
|
|
var list = repo.ReadOnlyTable()
|
|
.Where(o => o.ParentId != null)
|
|
.OrderBy(o => o.ParentId)
|
|
.ThenBy(o => o.DisplayOrder)
|
|
.ToList()
|
|
.ToTree()
|
|
.Select(o => new Area { Id = o.Id, Name = o.GetDisplayName() })
|
|
.ToList();
|
|
return new JsonResult(new SelectList(list, "Id", "Name", selected));
|
|
}
|
|
|
|
public JsonResult GetOrganBuilding(Guid? parentId, Guid? selected)
|
|
{
|
|
using var scope = this._services.CreateScope();
|
|
var repo = scope.ServiceProvider.GetRequiredService<IRepository<Building>>();
|
|
var list = repo.ReadOnlyTable()
|
|
.Where(o => o.ParentId != null)
|
|
.WhereIf(parentId.HasValue,o => o.OrganId == parentId.Value)
|
|
.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 GetUser(Guid? parentId, Guid? selected = null, string search = null, ControllerScopeType? range = null)
|
|
{
|
|
using var scope = this._services.CreateScope();
|
|
var repo = scope.ServiceProvider.GetRequiredService<IRepository<User>>();
|
|
var organId = scope.ServiceProvider.GetRequiredService<IHttpContextAccessor>().HttpContext.User.GetOrganId();
|
|
|
|
var list = repo.ReadOnlyTable()
|
|
.WhereIf(range.HasValue && range == ControllerScopeType.Organ && organId.HasValue, o => o.OrganUsers.Any(o => o.OrganId == organId.Value))
|
|
.WhereIf(parentId.HasValue, o => o.OrganUsers.Any(o => o.OrganId == parentId.Value))
|
|
.WhereIf(!string.IsNullOrEmpty(search), o => o.UserName.Contains(search)
|
|
|| o.NickName.Contains(search)
|
|
|| o.Email.Contains(search)
|
|
|| o.PhoneNumber.Contains(search)
|
|
|| o.RealName.Contains(search)
|
|
|| o.IdentityNumber.Contains(search))
|
|
.WhereIf(selected.HasValue, o => o.Id == selected.Value)
|
|
.Select(o => new { o.Id, Name = $"{o.UserName} {o.RealName}" })
|
|
.Take(20)
|
|
.ToList();
|
|
return new JsonResult(new SelectList(list, "Id", "Name", selected));
|
|
}
|
|
|
|
public JsonResult GetRole(Guid parentId, List<Guid> selected = null)
|
|
{
|
|
using var scope = this._services.CreateScope();
|
|
var repo = scope.ServiceProvider.GetRequiredService<IRepository<OrganRole>>();
|
|
var list = repo.ReadOnlyTable()
|
|
.Where(o => o.OrganId == parentId)
|
|
.Select(o => new { o.Id, Name = $"{o.Name} {o.Number}" })
|
|
.ToList();
|
|
return new JsonResult(new MultiSelectList(list, "Id", "Name", selected));
|
|
}
|
|
|
|
public JsonResult GetPermission(Guid parentId, List<Guid> selected = null)
|
|
{
|
|
using var scope = this._services.CreateScope();
|
|
var repo = scope.ServiceProvider.GetRequiredService<IRepository<OrganRolePermission>>();
|
|
var list = repo.ReadOnlyTable()
|
|
//.Where(o => o.Permission.OrganId == parentId)
|
|
.Select(o => new { o.Permission.Id, o.Permission.Name })
|
|
.ToList();
|
|
return new JsonResult(new MultiSelectList(list, "Id", "Name", selected));
|
|
}
|
|
|
|
|
|
[ApiExplorerSettings(IgnoreApi = true)]
|
|
public JsonResult GetPermissionCategory(Guid? organId,Guid? selected)
|
|
{
|
|
using var scope = this._services.CreateScope();
|
|
var repo = scope.ServiceProvider.GetRequiredService<IRepository<PermissionCategory>>();
|
|
//var organId = scope.ServiceProvider.GetRequiredService<IHttpContextAccessor>().HttpContext.User.GetOrganId();
|
|
var list = repo.ReadOnlyTable()
|
|
.Where(o => o.ParentId != null)
|
|
.WhereIf(organId.HasValue,o => o.OrganId == organId.Value)
|
|
.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 MultiSelectList GetOrganMultiSelectList(List<Guid> selected)
|
|
{
|
|
if (selected == null)
|
|
{
|
|
selected = new List<Guid>();
|
|
}
|
|
var list = this._organRepo.ReadOnlyTable()
|
|
.Where(o => o.ParentId != null)
|
|
.Select(o => new { o.Id, o.Name })
|
|
.ToList();
|
|
return new MultiSelectList(list, "Id", "Name", selected);
|
|
}
|
|
|
|
[ApiExplorerSettings(IgnoreApi = true)]
|
|
public MultiSelectList GetRoleMultiSelectList(IEnumerable<Guid> selected)
|
|
{
|
|
if (selected == null)
|
|
{
|
|
selected = new List<Guid>();
|
|
}
|
|
using var scope = this._services.CreateScope();
|
|
var repo = scope.ServiceProvider.GetRequiredService<IRepository<OrganRole>>();
|
|
var list = repo.ReadOnlyTable()
|
|
.Select(o => new { o.Id, o.Name })
|
|
.ToList();
|
|
return new MultiSelectList(list, "Id", "Name", selected);
|
|
}
|
|
}
|
|
} |