123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- using IdentityModel;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using TEAMModelOS.Model.Core.Models;
- using TEAMModelOS.SDK.Extension.DataResult.JsonRpcRequest;
- using TEAMModelOS.SDK.Extension.DataResult.JsonRpcResponse;
- using TEAMModelOS.SDK.Helper.Common.CollectionHelper;
- using TEAMModelOS.Service.Core.Interfaces;
- namespace TEAMModelOS.Controllers.Core
- {
- /// <summary>
- /// 获得学校信息
- /// </summary>
- [Route("api/[controller]")]
- [ApiController]
- [Authorize]
- public class RoleController : BaseController
- {
- private readonly IRoleService _roleSeservice;
- public RoleController(IRoleService roleService)
- {
- _roleSeservice = roleService;
- }
- [HttpPost("FindRoleByDict")]
- public async Task<BaseJosnRPCResponse> FindRoleByDict(JosnRPCRequest<Dictionary<string, object>> request)
- {
- // request.@params.TryAdd("PartitionKey", request.lang);
- JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
- List<Role> roles = await _roleSeservice.FindListByDictHasAll<Role>(request.@params);
- return builder.Data(roles).build();
- }
- [HttpPost("GetLoginRoles")]
- public async Task<BaseJosnRPCResponse> GetLoginRoles(JosnRPCRequest<Dictionary<string, object>> request)
- {
- JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
- List<string> rolecodes = GetLoginUser(JwtClaimTypes.Role);
- List<Role> roles = new List<Role>();
- if (rolecodes.IsNotEmpty()) {
- foreach (string code in rolecodes)
- {
- Role role = await _roleSeservice.FindByRowKey<Role>(code);
- if (role != null && !string.IsNullOrEmpty(role.RowKey))
- {
- List<RoleIdentityClaim> identityClaims = await _roleSeservice.FindListByDict<RoleIdentityClaim>(new Dictionary<string, object> {
- // {"PartitionKey",request.lang },
- { "RoleCode",role.RowKey },{"RoleLevel",role.Level }
- });
- roles.Add(role);
- }
- }
- }
- return builder.Data(roles).build();
- }
- [HttpPost("GetLoginClaim")]
- public async Task<BaseJosnRPCResponse> GetLoginClaim(JosnRPCRequest<Dictionary<string, object>> request)
- {
- JsonRPCResponseBuilder builder = JsonRPCResponseBuilder.custom();
- List<string> rolecodes = GetLoginUser(JwtClaimTypes.Role);
- List<string> Id = GetLoginUser(JwtClaimTypes.Id);
- List<Role> roles = new List<Role>();
- List<Dictionary<string, object>> roleClaims = new List<Dictionary<string, object>>();
- if (rolecodes.IsNotEmpty())
- {
- foreach (string code in rolecodes)
- {
- List<RoleIdentityClaimValue> claimValues= await _roleSeservice.FindListByDict<RoleIdentityClaimValue>(
- new Dictionary<string, object> { { "RoleCode", code },{ "TeamModelId", Id[0]}
- // , { "PartitionKey", request.lang}
- }
- );
- List<string> keys = new List<string>();
- List<Dictionary<string, object>> claims = new List<Dictionary<string, object>>();
- foreach (IGrouping<string, RoleIdentityClaimValue> group in claimValues.GroupBy(c =>c.GroupKey))
- {
- List<RoleIdentityClaimValue> claimValue = claimValues.Where(x => x.GroupKey.Equals(group.Key)).ToList();
- claimValue= claimValue.OrderBy(s => s.ClaimOrder).ToList() ;
- Dictionary<string, object> claim = new Dictionary<string, object>
- {
- { "claim", claimValue },
- { "group", group.Key }
- };
- claims.Add(claim);
- }
- Dictionary<string, object> roleClaim = new Dictionary<string, object>
- {
- { "roleClaim", claims },
- { "role", await _roleSeservice.FindOneByDict<Role>(new Dictionary<string, object> { { "RowKey", code },
- //{ "PartitionKey", request.lang }
- }) }
- };
- roleClaims.Add(roleClaim);
- }
- }
- return builder.Data(roleClaims).build();
- }
- }
- }
|