Former-commit-id: 14c41a75bbc187fda51b273a6a476bc34293205c
Former-commit-id: 359f156fb6f20756d805b3e7c419c5b11eec6e37
1.0
wanggang 5 years ago
parent b9b0583761
commit 416039c437

@ -1,4 +1,5 @@
using System.Linq;
using System;
using System.Linq;
using System.Security.Claims;
namespace Infrastructure.Extensions
@ -15,9 +16,10 @@ namespace Infrastructure.Extensions
return role == null ? false : user.IsInRole(role.ToString());
}
public static string GetUserData(this ClaimsPrincipal user)
public static Guid? GetOrganId(this ClaimsPrincipal user)
{
return user.Claims.FirstOrDefault(o => o.Type == ClaimTypes.UserData)?.Value;
var value = user.Claims.FirstOrDefault(o => o.Type == ClaimTypes.UserData)?.Value;
return Guid.TryParse(value, out Guid id) ? id : null;
}
}
}

@ -1,4 +1,4 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Tokens;
@ -21,18 +21,18 @@ namespace Infrastructure.Extensions
return $"jwt{httpContext.RequestServices.GetService<IConfiguration>()["jwt:cookie"]}";
}
public static void JwtSignIn(this HttpContext httpContext, string userName, bool rememberMe,string organNumber = null)
public static void JwtSignIn(this HttpContext httpContext, string userName, bool rememberMe, string organId = null)
{
if (httpContext is null)
{
throw new ArgumentNullException(nameof(httpContext));
}
var claims = new List<Claim> {
new Claim(ClaimTypes.Name, userName),
new Claim(ClaimTypes.Name, userName),
};
if (!string.IsNullOrEmpty(organNumber))
if (!string.IsNullOrEmpty(organId))
{
claims.Add(new Claim(ClaimTypes.UserData, organNumber));
claims.Add(new Claim(ClaimTypes.UserData, organId));
}
var token = httpContext.CreateJwtToken(claims, DateTime.Now.AddYears(1));
var cookieOptions = new CookieOptions
@ -83,4 +83,4 @@ namespace Infrastructure.Extensions
return new JwtSecurityTokenHandler().ReadJwtToken(token);
}
}
}
}

@ -0,0 +1,13 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
namespace Infrastructure.Extensions
{
public static class JsonResultExtensions
{
public static SelectList SelectList(this JsonResult result)
{
return result.Value as SelectList;
}
}
}

@ -0,0 +1,7 @@
@{
var key = (Model as Guid?);
if (key.HasValue)
{
@ViewData.Get(key.Value)
}
}

@ -1,8 +1,15 @@
@{
var scope = ViewBag.ControllerScope as string;
}
<div class="card">
<div class="form-horizontal">
<div class="card-body">
@foreach (var prop in ViewData.ModelMetadata.Properties.Where(pm => pm.ShowForEdit && !pm.HideSurroundingHtml))
{
if(scope=="Organ"&&prop.PropertyName=="OrganId")
{
continue;
}
var uihit = prop.DataTypeName ?? prop.TemplateHint;
<div class="form-group row" title="@uihit">
@Html.Label(prop.PropertyName, prop.GetDisplayName() + "", new { @class = "col-sm-2 col-form-label" })

@ -1,5 +1,5 @@
@{
HtmlTitle = "编辑" + ViewContext.ViewData.ModelMetadata.ModelType.GetDisplayName();
HtmlTitle = "编辑" + ViewContext.ViewData.ModelMetadata.ModelType.GetDisplayName();
}
@Html.EditorForModel()
@section scripts{

@ -0,0 +1,5 @@
@{
var htmlClass = "form-control select2bs4 search";
var list = (ViewData[ViewData.ModelMetadata.PropertyName + "SelectList"] as SelectList) ?? new SelectList(new List<SelectListItem>());
@Html.DropDownList("", list, "请选择", new { @class = htmlClass })
}

@ -2,11 +2,17 @@
@using System.Linq
@{
var inputClass = "form-control";
var scope = ViewBag.ControllerScope as string;
}
@foreach (var prop in ViewData.ModelMetadata.Properties.Where(pm => pm.ShowForEdit))
{
var metadata = prop as Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadata;
object propValue = Model == null ? (prop.ModelType.IsValueType ? Activator.CreateInstance(prop.ModelType) : null) : ViewData.ModelMetadata.ModelType.GetProperty(prop.PropertyName).GetValue(ViewData.Model);
if(scope=="Organ"&&prop.PropertyName=="OrganId")
{
@Html.Hidden(prop.PropertyName)
continue;
}
if (prop.HideSurroundingHtml)
{
@Html.Hidden(prop.PropertyName)

@ -1,6 +1,6 @@
@{
var list = new SelectList(new List<SelectListItem>());
var htmlClass = "form-control select2bs4 search";
var htmlClass = "form-control search";
if (!string.IsNullOrEmpty(ViewData.ModelMetadata.TemplateHint))
{
htmlClass += " " + ViewData.ModelMetadata.TemplateHint;

@ -57,7 +57,7 @@
}
</div>
<div class="card-body" style="overflow-x:auto;">
<table class="table table-bordered table-striped dataTable dtr-inline projects">
<table class="table table-hover text-nowrap table-bordered dataTable dtr-inline projects">
<tr>
<th><input type="checkbox" class="select_all" /></th>
<th>行号</th>
@ -67,6 +67,10 @@
{
continue;
}
if(scope=="Organ"&&item.Name=="OrganId")
{
continue;
}
<th>@item.GetDisplayName()</th>
}
@if (User.IsInRole($"Read-{scope}-{entityType.Name}"))

@ -1,6 +1,12 @@
@{var props = ViewData.ModelMetadata.Properties.Where(pm => pm.ShowForEdit && !pm.HideSurroundingHtml && !pm.IsComplexType && !pm.IsCollectionType && pm.PropertyName != "Id").ToList();
@{
var scope = ViewBag.ControllerScope as string;
var props = ViewData.ModelMetadata.Properties.Where(pm => pm.ShowForEdit && !pm.HideSurroundingHtml && !pm.IsComplexType && !pm.IsCollectionType && pm.PropertyName != "Id").ToList();
foreach (var prop in props)
{
if(scope=="Organ"&&prop.PropertyName=="OrganId")
{
continue;
}
var templateName = prop.DataTypeName ?? prop.TemplateHint ?? (prop.ModelType == typeof(string) ? typeof(string).Name : null);
<td style="max-width:10em;" data-ext="@templateName">
@if (prop.UnderlyingOrModelType == typeof(bool))

@ -0,0 +1,53 @@
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
using Microsoft.AspNetCore.Mvc.Routing;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using System.Collections.Generic;
namespace System.ComponentModel.DataAnnotations
{
public class AjaxSelectAttribute : UIHintAttribute, IClientModelValidator
{
protected string RouteName { get; set; }
protected RouteValueDictionary RouteData { get; } = new RouteValueDictionary();
public AjaxSelectAttribute(string action, string controller, string areaName = null) : base("AjaxSelect")
{
if (action != null)
{
RouteData["action"] = action;
}
if (controller != null)
{
RouteData["controller"] = controller;
}
if (controller != null)
{
RouteData["area"] = areaName;
}
}
public void AddValidation(ClientModelValidationContext context)
{
MergeAttribute(context.Attributes, "data-ajax-url", GetUrl(context));
}
private string GetUrl(ClientModelValidationContext context)
{
return context.ActionContext.HttpContext.RequestServices.GetRequiredService<IUrlHelperFactory>()
.GetUrlHelper(context.ActionContext).RouteUrl(new UrlRouteContext
{
RouteName = RouteName,
Values = RouteData
});
}
private static void MergeAttribute(IDictionary<string, string> attributes, string key, string value)
{
if (!attributes.ContainsKey(key))
{
attributes.Add(key, value);
}
}
}
}

@ -5,8 +5,8 @@ namespace Infrastructure.Web
{
public interface IUserService
{
List<string> GetOrganNumbers(string userName);
List<string> GetOrgans(string userName);
List<Claim> GetRoles(string userName);
}
}
}

@ -3,8 +3,8 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Tokens;
using System;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Linq;
using System.Security.Claims;
namespace Infrastructure.Web
{
@ -33,11 +33,11 @@ namespace Infrastructure.Web
using var scope = this._serviceProvider.CreateScope();
var userService = scope.ServiceProvider.GetService<IUserService>();
var organNumber = claims.FirstOrDefault(o => o.Type == ClaimTypes.UserData)?.Value;
if (!string.IsNullOrEmpty(organNumber))
var organId = claims.FirstOrDefault(o => o.Type == ClaimTypes.UserData)?.Value;
if (!string.IsNullOrEmpty(organId))
{
var organNumbers = userService.GetOrganNumbers(userName);
if (!organNumbers.Any(o => o == organNumber))
var organNumbers = userService.GetOrgans(userName);
if (!organNumbers.Any(o => o == organId))
{
validatedToken = null;
return null;
@ -57,4 +57,4 @@ namespace Infrastructure.Web
return null;
}
}
}
}

@ -16,9 +16,12 @@ namespace Infrastructure.Web.Mvc
{
protected IRepository<TEntity> Repo { get; }
private readonly ControllerScopeType? _scope;
public CrudController(IRepository<TEntity> repo)
{
this.Repo = repo;
this._scope = (this.GetType().GetCustomAttributes(false).FirstOrDefault(o => o.GetType() == typeof(ControllerScopeAttribute)) as ControllerScopeAttribute)?.Scope;
}
[HttpGet]
@ -253,6 +256,14 @@ namespace Infrastructure.Web.Mvc
[ApiExplorerSettings(IgnoreApi = true)]
public virtual void ToEditModel(TEntity entity, TEditModel model)
{
if (_scope == ControllerScopeType.Organ)
{
var organId = User.GetOrganId();
if (organId.HasValue)
{
typeof(TEditModel).GetProperty("OrganId").SetValue(model, organId);
}
}
}
[ApiExplorerSettings(IgnoreApi = true)]
@ -272,29 +283,28 @@ namespace Infrastructure.Web.Mvc
{
throw new ArgumentNullException(nameof(context));
}
var scope = (this.GetType().GetCustomAttributes(false).FirstOrDefault(o => o.GetType() == typeof(ControllerScopeAttribute)) as ControllerScopeAttribute)?.Scope;
var type = scope.ToString();
var type = _scope.ToString();
var name = (context.ActionDescriptor as ControllerActionDescriptor).ActionName;
var permission = string.Empty;
if (name == "Index")
{
permission = $"Read-{scope}-{typeof(TEntity).Name}";
permission = $"Read-{_scope}-{typeof(TEntity).Name}";
}
else if (name == "Details")
{
permission = $"Read-{scope}-{typeof(TEntity).Name}";
permission = $"Read-{_scope}-{typeof(TEntity).Name}";
}
else if (name == "Add")
{
permission = $"Add-{scope}-{typeof(TEntity).Name}";
permission = $"Add-{_scope}-{typeof(TEntity).Name}";
}
else if (name == "Edit" || name == "Remove" || name == "Restore")
{
permission = $"Edit-{scope}-{typeof(TEntity).Name}";
permission = $"Edit-{_scope}-{typeof(TEntity).Name}";
}
else if (name == "Delete")
{
permission = $"Delete-{scope}-{typeof(TEntity).Name}";
permission = $"Delete-{_scope}-{typeof(TEntity).Name}";
}
if (!string.IsNullOrEmpty(permission))
{

@ -1,7 +1,7 @@
using Infrastructure.Domain;
using System.ComponentModel.DataAnnotations;
namespace Platform.Application.Domain
namespace IoT.Shared.Application.Domain.Entities
{
[Display(Name = "回放")]
public class LiveRecord : BaseEntity
@ -11,4 +11,4 @@ namespace Platform.Application.Domain
public string Name { get; set; }
public string Value { get; set; }
}
}
}

@ -86,16 +86,18 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls
#region Organ
public SelectList GetOrganSelectList(Guid? selected = null, Guid? currentId = null)
public JsonResult GetOrgan(Guid? selected = null, Guid? currentId = null, string search = null)
{
var list = this._organRepo.ReadOnlyTable()
.Where(o => o.ParentId != null)
.WhereIf(!string.IsNullOrEmpty(search), o => o.Name.Contains(search) || o.Number.Contains(search))
.WhereIf(selected.HasValue, o => o.Id == selected.Value)
.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 SelectList(list, "Id", "Name", selected);
return new JsonResult(new SelectList(list, "Id", "Name", selected));
}
#endregion Organ

@ -149,10 +149,29 @@ function InitControls() {
$(this).treeMultiselect({ enableSelectAll: true, searchable: true, selectAllText: "全选", unselectAllText: "反选" });
});
//
//$('select.search').select2({
// theme: "bootstrap4",
// language: "zh-CN"
//});
$('select.select2bs4').select2({
theme: "bootstrap4",
language: "zh-CN",
placeholder: '请选择',
allowClear: true,
minimumInputLength: 2,
ajax: {
url: $(this).attr('data-ajax-url'),
data: function (params) {
var query = {
search: params.term,
type: 'public'
}
return query;
},
dataType: 'json',
processResults: function (data) {
return {
results: Enumerable.from(data).select(function (o) { return { id: o.value, text: o.text }; }).toArray()
};
}
}
});
//
$('input.cron').each(function () {
var cron = $(this).jqCron({

@ -16,7 +16,7 @@ namespace IoTNode
this._userRepo = userRepo;
}
public List<string> GetOrganNumbers(string userName)
public List<string> GetOrgans(string userName)
{
throw new System.NotImplementedException();
}

@ -3,7 +3,6 @@ using IoT.Shared.Application.Domain.Entities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Platform.Application.Domain;
using System;
using System.Collections.Generic;
using System.Diagnostics;

@ -28,7 +28,7 @@ namespace Platform.Application.Models
public string CustomType { get; set; }
[Display(Name = "上级")]
[DataType("SelectList")]
[AjaxSelect("GetArea", "Ajax", "IoTCenter")]
public Guid? ParentId { get; set; }
[Display(Name = "序号")]

@ -9,11 +9,11 @@ namespace Platform.Application.Models
[Display(Name = "机构")]
public class EditOrganModel : EditModel
{
[DataType("SelectList")]
[AjaxSelect("GetArea", "Ajax", "IoTCenter")]
[Display(Name = "所属区域")]
public Guid? AreaId { get; set; }
[DataType("SelectList")]
[AjaxSelect("GetOrgan", "Ajax", "IoTCenter")]
[Display(Name = "上级机构")]
public Guid? ParentId { get; set; }

@ -0,0 +1,34 @@
using Infrastructure.Application;
using IoT.Shared.Application.Domain.Entities;
using System;
using System.ComponentModel.DataAnnotations;
using UoN.ExpressiveAnnotations.NetCore.Attributes;
namespace Platform.Application.Models
{
[Display(Name = "机构用户")]
public class EditOrganUserModel : EditModel
{
[Display(Name = "机构")]
[DataType("SelectList")]
[Required]
public Guid? OrganId { get; set; }
[Display(Name = "用户")]
[DataType("SelectList")]
[Required]
public Guid? UserId { get; set; }
[Display(Name = "类型")]
[DataType("SelectList")]
[Required]
public OrganUserType? Type { get; set; }
[Display(Name = "自定义类型")]
[RequiredIf("Type==1000", ErrorMessage = "类型为自定时必须填写此字段")]
public string CustomType { get; set; }
[Display(Name = "默认机构")]
public bool? IsDefault { get; set; }
}
}

@ -55,16 +55,19 @@ namespace Platform.Areas.IoTCenter.Controllers
this._roleRepo = roleRepo;
}
public SelectList GetAreaSelectList(Guid? selected = null, Guid? currentId = null)
public JsonResult GetArea(Guid? selected = null, Guid? currentId = null, string search = null)
{
var list = this._areaRepo.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})" })
.Select(o => new { o.Id, Name = $"{o.Name}:{o.Number}" })
.Take(20)
.ToList();
return new SelectList(list, "Id", "Name", selected);
return new JsonResult(new SelectList(list, "Id", "Name", selected));
}
public JsonResult GetOrganBuilding(Guid parentId, Guid? selected = null, Guid? currentId = null)

@ -2,11 +2,11 @@
using Infrastructure.Data;
using Infrastructure.Extensions;
using Infrastructure.Web.Mvc;
using IoT.Shared.Areas.IoTCenter.Controlls;
using IoT.Shared.Application.Domain.Entities;
using IoT.Shared.Application.Models;
using IoT.Shared.Areas.IoTCenter.Controlls;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Platform.Application.Domain;
using System.Linq;
namespace Platform.Areas.IoTCenter.Controllers

@ -2,8 +2,8 @@
using Infrastructure.Data;
using Infrastructure.Extensions;
using Infrastructure.Web.Mvc;
using IoT.Shared.Areas.IoTCenter.Controlls;
using IoT.Shared.Application.Domain.Entities;
using IoT.Shared.Areas.IoTCenter.Controlls;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
@ -43,7 +43,7 @@ namespace Platform.Areas.IoTCenter.Controllers
public override void ToEditModel(OrganIoTSceneIoTCommand entity, EditOrganSceneCommandModel model)
{
this.ToDisplayModel(entity, model);
ViewData.SelectList(o => model.OrganId, () => this._ajax.GetOrganSelectList(model.OrganId));
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.NodeId, () => this._ajax.GetOrganNodeSelectList(model.OrganId.Value, model.NodeId), model.OrganId.HasValue);
ViewData.SelectList(o => model.CommandId, () => this._ajax.GetCommandSelectList(model.NodeId.Value, model.CommandId), model.NodeId.HasValue);

@ -2,8 +2,8 @@
using Infrastructure.Data;
using Infrastructure.Extensions;
using Infrastructure.Web.Mvc;
using IoT.Shared.Areas.IoTCenter.Controlls;
using IoT.Shared.Application.Domain.Entities;
using IoT.Shared.Areas.IoTCenter.Controlls;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
@ -32,7 +32,7 @@ namespace Platform.Areas.IoTCenter.Controllers
public override IQueryable<OrganIoTScene> Query(PagedListModel<EditOrganSceneModel> model, IQueryable<OrganIoTScene> query)
{
ViewData.SelectList(o => model.Query.OrganId, () => this._ajax.GetOrganSelectList(model.Query.OrganId));
ViewData.SelectList(o => model.Query.OrganId, () => this._ajax.GetOrgan(model.Query.OrganId).SelectList());
return query
.WhereIf(model.Query.OrganId.HasValue, o => o.OrganId == model.Query.OrganId.Value)
.WhereIf(!string.IsNullOrEmpty(model.Query.Name), o => o.Name.Contains(model.Query.Name))
@ -50,7 +50,7 @@ namespace Platform.Areas.IoTCenter.Controllers
public override void ToEditModel(OrganIoTScene entity, EditOrganSceneModel model)
{
ViewData.SelectList(o => model.OrganId, () => this._ajax.GetOrganSelectList(model.OrganId));
ViewData.SelectList(o => model.OrganId, () => this._ajax.GetOrgan(model.OrganId).SelectList());
}
}
}

@ -2,8 +2,8 @@
using Infrastructure.Data;
using Infrastructure.Extensions;
using Infrastructure.Web.Mvc;
using IoT.Shared.Areas.IoTCenter.Controlls;
using IoT.Shared.Application.Domain.Entities;
using IoT.Shared.Areas.IoTCenter.Controlls;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
@ -53,7 +53,7 @@ namespace Platform.Areas.IoTCenter.Controllers
public override void ToEditModel(OrganIoTSceneTigger entity, EditOrganSceneTiggerModel model)
{
this.ToDisplayModel(entity, model);
ViewData.SelectList(o => model.OrganId, () => this._ajax.GetOrganSelectList(model.OrganId));
ViewData.SelectList(o => model.OrganId, () => this._ajax.GetOrgan(model.OrganId).SelectList());
ViewData.SelectList(o => model.NodeId, () => this._ajax.GetNodeSelectList(model.NodeId), 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.GetDeviceSelectList(model.NodeId.Value), model.NodeId.HasValue);

@ -2,8 +2,8 @@
using Infrastructure.Data;
using Infrastructure.Extensions;
using Infrastructure.Web.Mvc;
using IoT.Shared.Areas.IoTCenter.Controlls;
using IoT.Shared.Application.Domain.Entities;
using IoT.Shared.Areas.IoTCenter.Controlls;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
@ -46,7 +46,7 @@ namespace Platform.Areas.IoTCenter.Controllers
public override void ToEditModel(OrganIoTSceneTimer entity, EditOrganSceneTimerModel model)
{
this.ToDisplayModel(entity, model);
ViewData.SelectList(o => model.OrganId, () => this._ajax.GetOrganSelectList(model.OrganId));
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);
}

@ -53,7 +53,7 @@ namespace Platform.Areas.UserCenter.Controllers
public override void ToEditModel(Area entity, EditAreaModel model)
{
ViewData.SelectList(o => model.ParentId, () => this._ajax.GetAreaSelectList(model.ParentId, model.Id));
ViewData.SelectList(o => model.ParentId, () => this._ajax.GetArea(model.ParentId, model.Id).SelectList());
}
public override void ToEntity(EditAreaModel model, Area entity)

@ -5,7 +5,6 @@ using Infrastructure.Web.Mvc;
using IoT.Shared.Application.Domain.Entities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using Platform.Application.Models;
using Platform.Areas.IoTCenter.Controllers;
@ -62,15 +61,16 @@ namespace Platform.Areas.UserCenter.Controllers
public override void ToEditModel(Building entity, EditBuildingModel model)
{
base.ToEditModel(entity, model);
if (entity != null)
{
model.IoTGateways = entity.BuildingIoTGateways.Select(o => o.IoTGatewayId).ToList();
}
this.ViewData.MultiSelectList(o => model.IoTGateways, () => this._ajax.GetNodeMultiSelectList(model.IoTGateways));
ViewData.SelectList(o => model.OrganId, () => this._ajax.GetOrganSelectList(model.OrganId));
ViewData.SelectList(o => model.OrganId, () => this._ajax.GetOrgan(model.OrganId).SelectList());
if (model.OrganId.HasValue)
{
ViewData.SelectList(o => model.ParentId, () => this._ajax.GetOrganBuilding(model.OrganId.Value, model.ParentId, model.Id).Value as SelectList);
ViewData.SelectList(o => model.ParentId, () => this._ajax.GetOrganBuilding(model.OrganId.Value, model.ParentId, model.Id).SelectList());
}
}

@ -24,9 +24,9 @@ namespace Platform.Areas.UserCenter.Controllers
public override IQueryable<Building> Query(PagedListModel<EditBuildingModel> model, IQueryable<Building> query)
{
var currentOrganNumber = User.GetUserData();
var organId = User.GetOrganId();
return base.Query(model, query)
.Where(o => o.Organ.Number == currentOrganNumber);
.WhereIf(organId.HasValue, o => o.Organ.Id == organId.Value);
}
}
}

@ -60,8 +60,8 @@ namespace Platform.Areas.UserCenter.Controllers
public override void ToEditModel(Organ entity, EditOrganModel model)
{
this.ViewData.SelectList(o => model.AreaId, () => this._ajax.GetAreaSelectList(model.AreaId));
this.ViewData.SelectList(o => model.ParentId, () => this._ajax.GetOrganSelectList(model.ParentId, model.Id));
this.ViewData.SelectList(o => model.AreaId, () => this._ajax.GetArea(model.AreaId).SelectList());
this.ViewData.SelectList(o => model.ParentId, () => this._ajax.GetOrgan(model.ParentId, model.Id).SelectList());
}
public override void ToEntity(EditOrganModel model, Organ entity)

@ -24,9 +24,9 @@ namespace Platform.Areas.UserCenter.Controllers
public override IQueryable<Organ> Query(PagedListModel<EditOrganModel> model, IQueryable<Organ> query)
{
var currentOrganNumber = User.GetUserData();
var organId = User.GetOrganId();
return base.Query(model, query)
.Where(o => o.Number == currentOrganNumber);
.WhereIf(organId.HasValue, o => o.Id == organId.Value);
}
}

@ -0,0 +1,48 @@
using Infrastructure.Data;
using Infrastructure.Extensions;
using Infrastructure.Web.Mvc;
using IoT.Shared.Application.Domain.Entities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Platform.Application.Models;
using Platform.Areas.IoTCenter.Controllers;
using System.Linq;
namespace Platform.Areas.UserCenter.Controllers
{
[Authorize]
[ApiController]
[Route("UserCenter/[controller]/[action]")]
[Area("UserCenter")]
[ControllerScope(ControllerScopeType.Platform)]
public class OrganUserController : CrudController<OrganUser, EditOrganUserModel>
{
private readonly AjaxController _ajax;
public OrganUserController(IRepository<OrganUser> repo, AjaxController ajax) : base(repo)
{
this._ajax = ajax;
}
public override IQueryable<OrganUser> Include(IQueryable<OrganUser> query)
{
return query
.Include(o => o.Organ)
.Include(o => o.User);
}
public override void ToDisplayModel(OrganUser entity, EditOrganUserModel model)
{
ViewData.Add(entity.OrganId, entity.Organ.Name);
ViewData.Add(entity.UserId, $"{entity.User.UserName}({entity.User.NickName})");
}
public override void ToEditModel(OrganUser entity, EditOrganUserModel model)
{
base.ToEditModel(entity, model);
this.ViewData.SelectList(o => model.OrganId, () => this._ajax.GetOrgan(model.OrganId).SelectList());
//this.ViewData.SelectList(o => model.UserId, () => this._ajax.GetUser(model.UserId).SelectList());
}
}
}

@ -19,6 +19,10 @@
{
<li class="nav-item"><a class="@GetLinkClass("User")" href="@Url.Action("Index","User")"><i class="far fa-circle nav-icon"></i><p>用户管理</p></a></li>
}
@if (HasPermission("Read-Platform-OrganUser"))
{
<li class="nav-item"><a class="@GetLinkClass("OrganUser")" href="@Url.Action("Index","OrganUser")"><i class="far fa-circle nav-icon"></i><p>机构用户</p></a></li>
}
@if (HasPermission("Read-Platform-Role"))
{
<li class="nav-item"><a class="@GetLinkClass("Role")" href="@Url.Action("Index","Role")"><i class="far fa-circle nav-icon"></i><p>角色管理</p></a></li>

@ -198,7 +198,7 @@ namespace Platform.Controllers
}
else
{
HttpContext.JwtSignIn(model.UserName, model.RememberMe, mainOrgan?.Number);
HttpContext.JwtSignIn(model.UserName, model.RememberMe, mainOrgan?.Id.ToString());
if (string.IsNullOrEmpty(returnUrl))
{
returnUrl = Url.Action("Index", "Home");

@ -65,15 +65,16 @@ namespace Platform.Controllers
public IActionResult Index2(HomeModel model)
{
var currentOrganNumber = User.GetUserData();
var organId = User.GetOrganId();
var organ = this._organRepo.ReadOnlyTable()
.FirstOrDefault(o => o.Number == currentOrganNumber);
.WhereIf(organId.HasValue, o => o.Id == organId.Value)
.FirstOrDefault();
var children = this._organRepo.Table()
.Where(o => o.Left >= organ.Left && o.Right <= organ.Right)
.Include(o => o.Buildings)
.ToList();
var root = children.FirstOrDefault(o => o.Number == currentOrganNumber);
var root = children.FirstOrDefault(o => o.Id == organId.Value);
model.Organ = root;
if (string.IsNullOrEmpty(model.OrganNumber))

@ -5,7 +5,6 @@ using Infrastructure.Security;
using IoT.Shared;
using IoT.Shared.Application.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Platform.Application.Domain;
using System.Collections.Generic;
using System.Linq;

@ -17,11 +17,11 @@ namespace Platform
this._userRepo = userRepo;
}
public List<string> GetOrganNumbers(string userName)
public List<string> GetOrgans(string userName)
{
var list = this._userRepo.ReadOnlyTable().Where(o => o.UserName == userName)
.SelectMany(o => o.OrganUsers)
.Select(o => o.Organ.Number)
.Select(o => o.OrganId.ToString())
.ToList();
return list;
}
@ -46,4 +46,4 @@ namespace Platform
return list;
}
}
}
}

@ -66,23 +66,24 @@
@{
var hasOrgan = false;
var organs = new List<Organ>();
var organNumber = User.Claims.FirstOrDefault(o => o.Type == System.Security.Claims.ClaimTypes.UserData)?.Value;
if (!string.IsNullOrEmpty(organNumber) && User.Identity.IsAuthenticated)
var organIdValue = User.Claims.FirstOrDefault(o => o.Type == System.Security.Claims.ClaimTypes.UserData)?.Value;
var organId = Guid.Empty;
if (User.Identity.IsAuthenticated && Guid.TryParse(organIdValue ,out organId))
{
var userName = User.Identity.Name;
organs = organUserRepo.ReadOnlyTable()
.Where(o => o.User.UserName == userName)
.Select(o => o.Organ)
.ToList();
if (organs != null && organs.Any(o => o.Number == organNumber))
if (organs != null && organs.Any(o => o.Id == organId))
{
hasOrgan = true;
}
}
if (hasOrgan)
{
var organImage = organs.FirstOrDefault(o => o.Number == organNumber)?.Image ?? logo;
var list = new SelectList(organs, "Number", "Name", organNumber);
var organImage = organs.FirstOrDefault(o => o.Id == organId)?.Image ?? logo;
var list = new SelectList(organs, "Id", "Name", organId);
<img class="logo" src="@Url.Content2(organImage)" />
<span class="brand-text font-weight-light">
<form method="get" action="@Url.Action("ChangeOrgan","Account",new{area=""})">

Loading…
Cancel
Save