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.
129 lines
5.3 KiB
129 lines
5.3 KiB
using Infrastructure.Data;
|
|
using Infrastructure.Extensions;
|
|
using IoT.Shared.Application.Domain.Entities;
|
|
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 = null, Guid? currentId = null, string search = null)
|
|
{
|
|
using var scope = this._services.CreateScope();
|
|
var repo = scope.ServiceProvider.GetRequiredService<IRepository<Area>>();
|
|
var list = repo.ReadOnlyTable()
|
|
.Where(o => o.ParentId != null)
|
|
.WhereIf(selected.HasValue, o => o.Id == selected.Value)
|
|
.WhereIf(!string.IsNullOrEmpty(search), o => o.Name.Contains(search) || o.Number.Contains(search))
|
|
.WhereIf(currentId.HasValue, o => o.Id != currentId.Value)
|
|
.OrderBy(o => o.Parent)
|
|
.ThenBy(o => o.DisplayOrder)
|
|
.Select(o => new { o.Id, Name = $"{o.Name}:{o.Number}" })
|
|
.Take(20)
|
|
.ToList();
|
|
return new JsonResult(new SelectList(list, "Id", "Name", selected));
|
|
}
|
|
|
|
public JsonResult GetOrganBuilding(Guid parentId, Guid? selected = null, Guid? currentId = null)
|
|
{
|
|
using var scope = this._services.CreateScope();
|
|
var repo = scope.ServiceProvider.GetRequiredService<IRepository<Building>>();
|
|
var list = repo.ReadOnlyTable()
|
|
.Where(o => o.ParentId != null)
|
|
.Where(o => o.OrganId == parentId)
|
|
.WhereIf(currentId.HasValue, o => o.Id != currentId.Value)
|
|
.OrderBy(o => o.Parent)
|
|
.ThenBy(o => o.DisplayOrder)
|
|
.Select(o => new { o.Id, Name = $"{o.Name}({o.Number})" })
|
|
.ToList();
|
|
return new JsonResult(new SelectList(list, "Id", "Name", selected));
|
|
}
|
|
|
|
public JsonResult GetUser(Guid? parentId, Guid? selected = null, string search = null)
|
|
{
|
|
using var scope = this._services.CreateScope();
|
|
var repo = scope.ServiceProvider.GetRequiredService<IRepository<OrganUser>>();
|
|
|
|
var list = repo.ReadOnlyTable()
|
|
.WhereIf(parentId.HasValue, o => o.OrganId == parentId.Value)
|
|
.WhereIf(!string.IsNullOrEmpty(search), o => o.User.UserName.Contains(search)
|
|
|| o.User.NickName.Contains(search)
|
|
|| o.User.Email.Contains(search)
|
|
|| o.User.PhoneNumber.Contains(search)
|
|
|| o.User.RealName.Contains(search)
|
|
|| o.User.IdentityNumber.Contains(search))
|
|
.WhereIf(selected.HasValue, o => o.UserId == selected.Value)
|
|
.Select(o => new { Id = o.UserId, Name = $"{o.User.UserName} {o.User.RealName}" })
|
|
.Take(20)
|
|
.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<Role>>();
|
|
var list = repo.ReadOnlyTable()
|
|
.Select(o => new { o.Id, o.Name })
|
|
.ToList();
|
|
return new MultiSelectList(list, "Id", "Name", selected);
|
|
}
|
|
}
|
|
}
|