zhaolei
8 days ago 4a2e5b9a21940f11757be37d99f0944e240e908b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
 
namespace Bootstrap.Security
{
    /// <summary>
    /// BA 后台多数据库适配帮助类
    /// </summary>
    public static class BAAdapterHelper
    {
#nullable disable
        // 读取配置文件中 AuthHost 配置
        private static Lazy<BootstrapAdminHttpClient> _client;
 
        internal static void AddBootstrapAdminInterface(this IServiceCollection services)
        {
            _client = new Lazy<BootstrapAdminHttpClient>(() => services.BuildServiceProvider().GetRequiredService<BootstrapAdminHttpClient>());
        }
 
        private static T ExecuteRemoteAction<T>(string actionName, object data = null)
        {
            var task = _client.Value.PostAsJsonAsync<T>(actionName, data);
            task.Wait();
            return task.Result;
        }
#nullable restore
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="appId"></param>
        /// <param name="userName"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        public static IEnumerable<BootstrapMenu> RetrieveAppMenus(string appId, string userName, string? url) => ExecuteRemoteAction<IEnumerable<BootstrapMenu>>("RetrieveAppMenus", new AppMenuOption() { UserName = userName, AppId = appId, Url = url });
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static IEnumerable<string> RetrieveRolesByUrl(string url) => ExecuteRemoteAction<IEnumerable<string>>("RetrieveRolesByUrl", url);
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public static IEnumerable<string> RetrieveRolesByUserName(string userName) => ExecuteRemoteAction<IEnumerable<string>>("RetrieveRolesByUserName", userName);
 
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<BootstrapDict> RetrieveDicts() => ExecuteRemoteAction<IEnumerable<BootstrapDict>>("RetrieveDicts");
 
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<BootstrapGroup> RetrieveGroups() => ExecuteRemoteAction<IEnumerable<BootstrapGroup>>("RetrieveGroups");
 
        /// <summary>
        ///
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public static BootstrapUser RetrieveUserByUserName(string userName) => ExecuteRemoteAction<BootstrapUser>("RetrieveUserByUserName", userName);
    }
}