コード例 #1
0
        public BaseOutput <dynamic> QueryAppList()
        {
            var list = _adminDbContext.Queryable <AppModel>().ToList();

            return(new BaseOutput <dynamic> {
                Data = list
            });
        }
コード例 #2
0
        public BaseOutput <object> QueryAllRoles([FromQuery] QueryRolesInput input)
        {
            var list = _adminDbContext.Queryable <RoleModel>()
                       .WhereIF(!input.PlatformKey.IsEmpty(), it => it.PlatformKey == input.PlatformKey)
                       .ToList();

            return(new BaseOutput <object> {
                Data = list
            });
        }
コード例 #3
0
        /// <summary>
        /// 查询平台菜单
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <QueryAllMenusOutput> QueryAllMenus(QueryAllMenusInput input)
        {
            var list = await _dbContext.Queryable <MenuInfo>()
                       .WhereIF(input.PlatformId > 0, it => it.PlatformId == input.PlatformId)
                       .ToListAsync();

            return(new QueryAllMenusOutput {
                Data = list
            });
        }
コード例 #4
0
        public BaseOutput <object> QueryAllMenus([FromQuery] QueryAllMenusInput input)
        {
            var list = _adminDbContext.Queryable <MenuModel>()
                       .WhereIF(input.PlatformId > 0, it => it.PlatformId == input.PlatformId)
                       .ToList();

            return(new BaseOutput <object> {
                Data = list
            });
        }
コード例 #5
0
        public async Task <LoginOutput> LoginAsync([FromBody] LoginInput input)
        {
            var redis          = _cachingProviderFactory.GetCachingProvider("default_redis");
            var redis_img_code = await redis.GetAsync <string>($"ImgCode:{input.Guid}");

            if (redis_img_code.SafeString().ToLower() != input.ImgCode.SafeString().ToLower())
            {
                throw new BucketException("GO_2003", "图形验证码错误");
            }
            // 短信验证


            // 用户验证
            var userInfo = _superDbContext.Queryable <UserInfo>().First(it => it.UserName == input.UserName);

            if (userInfo == null)
            {
                throw new BucketException("GO_0004007", "账号不存在");
            }
            if (userInfo.State != 1)
            {
                throw new BucketException("GO_0004008", "账号状态异常");
            }
            if (userInfo.Password != Encrypt.SHA256(input.Password + userInfo.Salt))
            {
                throw new BucketException("GO_4009", "账号或密码错误");
            }
            // 用户角色
            var roleList = _superDbContext.Queryable <RoleInfo, UserRoleInfo>((role, urole) => new object[] { JoinType.Inner, role.Id == urole.RoleId })
                           .Where((role, urole) => urole.Uid == userInfo.Id)
                           .Where((role, urole) => role.IsDel == false)
                           .Select((role, urole) => new { role.Key })
                           .ToList();
            // token返回
            var token = _authService.CreateAccessToken(new UserTokenDto
            {
                Email    = userInfo.Email,
                Id       = userInfo.Id,
                Mobile   = userInfo.Mobile,
                RealName = userInfo.RealName,
                Ids      = userInfo.Id.ToString()
            }, roleList.Select(it => it.Key).ToList());

            return(new LoginOutput
            {
                Data = new
                {
                    AccessToken = $"Bearer {token}",
                    Expire = _authService.GetExpireInValue(4),
                    RealName = userInfo.RealName.SafeString(),
                    Mobile = userInfo.Mobile.SafeString(),
                    userInfo.Id
                }
            });
        }
コード例 #6
0
        public BasePageOutput <object> QueryApiGatewayConfiguration([FromQuery] QueryApiGatewayConfigurationInput input)
        {
            var totalNumber = 0;
            var list        = _adminDbContext.Queryable <ApiGatewayConfigurationModel>().ToPageList(input.PageIndex, input.PageSize, ref totalNumber);

            return(new BasePageOutput <object> {
                CurrentPage = input.PageIndex, Total = totalNumber, Data = list
            });
        }
コード例 #7
0
        public BaseOutput <object> QueryProject()
        {
            var list = _adminDbContext.Queryable <ProjectModel>().ToList();

            return(new BaseOutput <object> {
                Data = list
            });
        }
コード例 #8
0
        public BaseOutput <object> QueryPlatforms()
        {
            var list = _adminDbContext.Queryable <PlatformModel>().OrderBy(it => it.SortId, OrderByType.Asc).ToList();

            return(new BaseOutput <object> {
                Data = list
            });
        }
コード例 #9
0
        /// <summary>
        /// 查看项目列表信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <QueryProjectOutput> QueryProject()
        {
            var list = await _dbContext.Queryable <ProjectInfo>()
                       .ToListAsync();

            return(new QueryProjectOutput {
                Data = list
            });
        }
コード例 #10
0
        public BasePageOutput <object> QueryApiList([FromQuery] QueryApiListInput input)
        {
            var totalNumber = 0;
            var list        = _adminDbContext.Queryable <ApiModel>()
                              .WhereIF(!input.ProjectKey.IsEmpty(), it => it.ProjectName == input.ProjectKey)
                              .ToPageList(input.PageIndex, input.PageSize, ref totalNumber);

            return(new BasePageOutput <object> {
                Data = list, CurrentPage = input.PageIndex, Total = totalNumber
            });
        }
コード例 #11
0
        /// <summary>
        /// 查询Api资源
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <QueryApisOutput> QueryApis(QueryApisInput input)
        {
            var pageNumber = 0;
            var query      = await _dbContext.Queryable <ApiInfo>()
                             .WhereIF(!input.ProjectKey.IsEmpty(), it => it.ProjectName == input.ProjectKey)
                             .ToPageListAsync(input.PageIndex, input.PageSize, pageNumber);

            return(new QueryApisOutput {
                Data = query, CurrentPage = input.PageIndex, Total = query.Count
            });
        }
コード例 #12
0
ファイル: ConfigBusiness.cs プロジェクト: zz110/FamilyBucket
        public async Task <QueryAppConfigListOutput> QueryAppConfigList(QueryAppConfigListInput input)
        {
            var totalNumber = 0;

            // 环境库
            Enum.TryParse <Env>(input.Environment, out var env);
            var tableName = string.Empty;

            switch (env)
            {
            case Env.dev:
                tableName = $"tb_appconfig_{Env.dev.ToString()}";
                break;

            case Env.pro:
                tableName = $"tb_appconfig_{Env.pro.ToString()}";
                break;

            case Env.prepro:
                tableName = $"tb_appconfig_{Env.prepro.ToString()}";
                break;

            case Env.uat:
                tableName = $"tb_appconfig_{Env.uat.ToString()}";
                break;

            default:
                throw new BucketException("plm_001", "环境不存在");
            }
            // 执行
            var result = await _dbContext.Queryable <AppConfigInfo>().AS(tableName)
                         .WhereIF(!string.IsNullOrWhiteSpace(input.AppId), it => it.ConfigAppId == input.AppId)
                         .WhereIF(!string.IsNullOrWhiteSpace(input.NameSpace), it => it.ConfigNamespaceName == input.NameSpace)
                         .ToPageListAsync(input.PageIndex, input.PageSize, totalNumber);

            return(new QueryAppConfigListOutput {
                Data = result.Key, CurrentPage = input.PageIndex, Total = result.Value
            });
        }
コード例 #13
0
        /// <summary>
        /// 查询所有角色
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <QueryRolesOutput> QueryAllRoles(QueryRolesInput input)
        {
            var list = await _dbContext.Queryable <RoleInfo>()
                       .WhereIF(!input.PlatformKey.IsEmpty(), it => it.PlatformKey == input.PlatformKey)
                       .ToListAsync();

            return(new QueryRolesOutput {
                Data = list
            });
        }
コード例 #14
0
        /// <summary>
        /// 查询平台列表
        /// </summary>
        /// <returns></returns>
        public async Task <QueryPlatformsOutput> QueryPlatforms()
        {
            var redis     = _redisClient.GetDatabase(_configCenter.StringGet(SysConfig.RedisConnectionKey), 2);
            var redisList = await redis.StringGetAsync(CacheKeys.PlatformKey);

            if (!string.IsNullOrWhiteSpace(redisList))
            {
                return(new QueryPlatformsOutput {
                    Data = _jsonHelper.DeserializeObject <List <PlatformInfo> >(redisList)
                });
            }
            else
            {
                var list = await _dbContext.Queryable <PlatformInfo>().OrderBy(it => it.SortId, OrderByType.Asc).ToListAsync();

                await redis.StringSetAsync(CacheKeys.PlatformKey, _jsonHelper.SerializeObject(list));

                return(new QueryPlatformsOutput {
                    Data = list
                });
            }
        }
コード例 #15
0
        /// <summary>
        /// 查询微信小程序openid
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public async Task <QueryOpenIdOutput> QueryAppletOpenIdAsync(string code, string appid)
        {
            var apibaseurl = _config.StringGet("WxMiniApiUrl");
            // app信息
            var appinfo = _superDbContext.Queryable <WechatAppInfo>().First(it => it.AppId == appid);

            if (appinfo == null)
            {
                throw new NotImplementedException();
            }
            var wxapiurl = $"{apibaseurl}/sns/jscode2session?appid={appid}&secret={appinfo.AppSecret}&js_code={code}&grant_type=authorization_code";
            var client   = _httpClientFactory.CreateClient();
            var response = await client.GetAsync(wxapiurl);

            response.EnsureSuccessStatusCode();
            var jobject = JObject.Parse(await response.Content.ReadAsStringAsync());

            if (jobject.Property("errcode") != null)
            {
                throw new BucketException($"wxmini_{jobject.GetValue("errcode")}", "微信小程序code无效");
            }
            var output = new QueryOpenIdOutput();

            if (jobject.Property("openid") != null)
            {
                output.OpenId = jobject.GetValue("openid").SafeString();
            }
            if (jobject.Property("session_key") != null)
            {
                output.SessionKey = jobject.GetValue("session_key").SafeString();
            }
            if (jobject.Property("unionid") != null)
            {
                output.UnionId = jobject.GetValue("unionid").SafeString();
            }
            return(output);
        }
コード例 #16
0
        /// <summary>
        /// 查询项目配置信息
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <QueryConfigOutput> QueryConfig(QueryConfigInput input)
        {
            // 验证
            if (input.AppId.IsEmpty())
            {
                throw new BucketException("config_001", "AppId不能为空");
            }
            if (input.Sign.IsEmpty())
            {
                throw new BucketException("config_002", "签名不能为空");
            }
            if (input.NamespaceName.IsEmpty())
            {
                throw new BucketException("config_005", "NamespaceName不能为空");
            }
            // 返回结果
            var result = new QueryConfigOutput()
            {
                KV = new Dictionary <string, string>(), Version = input.Version
            };
            // 项目与签名验证
            var project = await _dbContext.Queryable <AppInfo>().Where(it => it.AppId == input.AppId).FirstAsync();

            if (project == null)
            {
                throw new BucketException("config_003", "项目不存在");
            }
            var signstr = $"appId={project.AppId}&appSecret={project.Secret}&namespaceName={input.NamespaceName}";
            var sign    = Bucket.Utility.Helpers.Encrypt.SHA256(signstr);

            if (sign.ToLower() != input.Sign)
            {
                throw new BucketException("config_004", "签名错误");
            }
            // 环境库
            Enum.TryParse <Env>(input.Env.SafeString().ToLower(), out var env);
            var tableName = "tb_appconfig_test";

            switch (env)
            {
            case Env.dev:
                tableName = $"tb_appconfig_{Env.dev.ToString()}";
                break;

            case Env.pro:
                tableName = $"tb_appconfig_{Env.pro.ToString()}";
                break;

            case Env.prepro:
                tableName = $"tb_appconfig_{Env.prepro.ToString()}";
                break;

            case Env.uat:
                tableName = $"tb_appconfig_{Env.uat.ToString()}";
                break;

            default:
                throw new BucketException("config_06", "环境不存在");
            }
            // 配置查询
            var namespaceList = await _dbContext.Queryable <AppNamespaceInfo>()
                                .Where(it => it.AppId == project.AppId && it.IsDeleted == false && it.IsPublic == true)
                                .Select(it => new { it.Name })
                                .ToListAsync();

            var namespaceKeyList = namespaceList.Select(it => it.Name).ToList();

            namespaceKeyList.Add(input.NamespaceName);
            if (namespaceKeyList.Count > 0)
            {
                var config = await _dbContext.Queryable <AppConfigInfo>().AS(tableName)
                             .Where(it => it.ConfigAppId == project.AppId && it.IsDeleted == false && namespaceKeyList.Contains(it.ConfigNamespaceName) && it.Version > input.Version)
                             .ToListAsync();

                if (config.Count > 0)
                {
                    result.Version = config.Max(it => it.Version);
                    config.ForEach(p =>
                    {
                        result.KV.Add(p.ConfigKey, p.ConfigValue);
                    });
                }
            }
            result.AppName = project.Name;
            return(result);
        }
コード例 #17
0
        /// <summary>
        /// 查询用户列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <QueryUsersOutput> QueryUsers(QueryUsersInput input)
        {
            var list   = new List <QueryUserDTO>();
            var result = new QueryUsersOutput {
                Data = new List <QueryUserDTO>()
            };
            var totalNumber = 0;

            if (input.RoleId > 0)
            {
                var query = await _dbContext.Queryable <UserInfo, UserRoleInfo>((u, urole) => new object[] { JoinType.Inner, u.Id == urole.Uid })
                            .Where((u, urole) => urole.RoleId == input.RoleId)
                            .WhereIF(input.State > -1, (u, urole) => u.State == input.State)
                            .WhereIF(!input.RealName.IsEmpty(), (u, urole) => u.RealName == input.RealName)
                            .WhereIF(!input.UserName.IsEmpty(), (u, urole) => u.UserName == input.UserName)
                            .WhereIF(!input.Mobile.IsEmpty(), (u, urole) => u.Mobile == input.Mobile)
                            .Select((u, urole) => new QueryUserDTO {
                    Id = u.Id, Mobile = u.Mobile, RealName = u.RealName, State = u.State, UpdateTime = u.UpdateTime, UserName = u.UserName, Email = u.Email
                })
                            .ToPageListAsync(input.PageIndex, input.PageSize, totalNumber);

                list        = query;
                totalNumber = query.Count;
            }
            else if (!input.PlatformKey.IsEmpty())
            {
                // 项目角色Id数组
                var prlist    = _dbContext.Queryable <RoleInfo>().Where(it => it.PlatformKey == input.PlatformKey && it.IsDel == false).Select(it => new { it.Id }).ToList();
                var roleIdArr = prlist.Select(it => it.Id).ToArray();
                // 查询
                var query = await _dbContext.Queryable <UserInfo, UserRoleInfo>((u, urole) => new object[] { JoinType.Inner, u.Id == urole.Uid })
                            .Where((u, urole) => roleIdArr.Contains(urole.RoleId))
                            .WhereIF(input.State > -1, (u, urole) => u.State == input.State)
                            .WhereIF(!input.RealName.IsEmpty(), (u, urole) => u.RealName == input.RealName)
                            .WhereIF(!input.UserName.IsEmpty(), (u, urole) => u.UserName == input.UserName)
                            .WhereIF(!input.Mobile.IsEmpty(), (u, urole) => u.Mobile == input.Mobile)
                            .GroupBy((u, urole) => u.Id)
                            .Select((u, urole) => new QueryUserDTO {
                    Id = u.Id, Mobile = u.Mobile, RealName = u.RealName, State = u.State, UpdateTime = u.UpdateTime, UserName = u.UserName, Email = u.Email
                })
                            .ToPageListAsync(input.PageIndex, input.PageSize, totalNumber);

                list        = query;
                totalNumber = query.Count;
            }
            else
            {
                var query = await _dbContext.Queryable <UserInfo>()
                            .WhereIF(input.State > -1, f => f.State == input.State)
                            .WhereIF(!input.RealName.IsEmpty(), f => f.RealName == input.RealName)
                            .WhereIF(!input.UserName.IsEmpty(), f => f.UserName == input.UserName)
                            .WhereIF(!input.Mobile.IsEmpty(), f => f.Mobile == input.Mobile)
                            .Select(u => new QueryUserDTO {
                    Id = u.Id, Mobile = u.Mobile, RealName = u.RealName, State = u.State, UpdateTime = u.UpdateTime, UserName = u.UserName, Email = u.Email
                })
                            .ToPageListAsync(input.PageIndex, input.PageSize, totalNumber);

                list        = query;
                totalNumber = query.Count;
            }
            var canUseRoleList = await _roleBusiness.QueryRoles(new QueryRolesInput());

            var canUseRole = canUseRoleList.Data as List <RoleInfo>;

            result.CurrentPage = input.PageIndex;
            result.Total       = totalNumber;
            result.Data        = list;
            result.Data.ForEach(m =>
            {
                var useRole = _dbContext.Queryable <UserRoleInfo>()
                              .Where(it => it.Uid == m.Id)
                              .Select(it => new { Id = it.RoleId })
                              .ToList();
                var idList = useRole.GroupBy(p => p.Id).Select(it => it.First().Id).ToList();
                m.RoleList = canUseRole.Where(it => idList.Contains(it.Id)).Select(it => new { Id = it.Id, ProjectName = it.PlatformKey, Name = it.Name }).ToList();
            });
            return(result);
        }
コード例 #18
0
        public BasePageOutput <List <QueryUserDto> > QueryUsers([FromQuery] QueryUsersInput input)
        {
            var userList    = new List <QueryUserDto>();
            var totalNumber = 0;

            if (input.RoleId > 0)
            {
                userList = _adminDbContext.Queryable <UserModel, UserRoleModel>((u, urole) => new object[] { JoinType.Inner, u.Id == urole.Uid })
                           .Where((u, urole) => urole.RoleId == input.RoleId)
                           .WhereIF(input.State > -1, (u, urole) => u.State == input.State)
                           .WhereIF(!input.RealName.IsEmpty(), (u, urole) => u.RealName == input.RealName)
                           .WhereIF(!input.UserName.IsEmpty(), (u, urole) => u.UserName == input.UserName)
                           .WhereIF(!input.Mobile.IsEmpty(), (u, urole) => u.Mobile == input.Mobile)
                           .Select((u, urole) => new QueryUserDto {
                    Id = u.Id, Mobile = u.Mobile, RealName = u.RealName, State = u.State, UpdateTime = u.UpdateTime, UserName = u.UserName, Email = u.Email
                })
                           .ToPageList(input.PageIndex, input.PageSize, ref totalNumber);
            }
            else if (!input.PlatformKey.IsEmpty())
            {
                // 项目角色Id数组
                var roleIdList = _adminDbContext.Queryable <RoleModel>().Where(it => it.PlatformKey == input.PlatformKey && it.IsDel == false).Select(it => it.Id).ToList();
                // 查询
                userList = _adminDbContext.Queryable <UserModel, UserRoleModel>((u, urole) => new object[] { JoinType.Inner, u.Id == urole.Uid })
                           .Where((u, urole) => roleIdList.Contains(urole.RoleId))
                           .WhereIF(input.State > -1, (u, urole) => u.State == input.State)
                           .WhereIF(!input.RealName.IsEmpty(), (u, urole) => u.RealName == input.RealName)
                           .WhereIF(!input.UserName.IsEmpty(), (u, urole) => u.UserName == input.UserName)
                           .WhereIF(!input.Mobile.IsEmpty(), (u, urole) => u.Mobile == input.Mobile)
                           .GroupBy((u, urole) => u.Id)
                           .Select((u, urole) => new QueryUserDto {
                    Id = u.Id, Mobile = u.Mobile, RealName = u.RealName, State = u.State, UpdateTime = u.UpdateTime, UserName = u.UserName, Email = u.Email
                })
                           .ToPageList(input.PageIndex, input.PageSize, ref totalNumber);
            }
            else
            {
                userList = _adminDbContext.Queryable <UserModel>()
                           .WhereIF(input.State > -1, f => f.State == input.State)
                           .WhereIF(!input.RealName.IsEmpty(), f => f.RealName == input.RealName)
                           .WhereIF(!input.UserName.IsEmpty(), f => f.UserName == input.UserName)
                           .WhereIF(!input.Mobile.IsEmpty(), f => f.Mobile == input.Mobile)
                           .Select(u => new QueryUserDto {
                    Id = u.Id, Mobile = u.Mobile, RealName = u.RealName, State = u.State, UpdateTime = u.UpdateTime, UserName = u.UserName, Email = u.Email
                })
                           .ToPageList(input.PageIndex, input.PageSize, ref totalNumber);
            }
            // 当前所有用户id
            var userIdList = userList.Select(it => it.Id);
            // 查询用户及对应角色列表
            var userRoleList = _adminDbContext.Queryable <RoleModel, UserRoleModel>((role, urole) => new object[] { JoinType.Inner, role.Id == urole.RoleId })
                               .Where((role, urole) => userIdList.Contains(urole.Uid))
                               .Select((role, urole) => new { role.Id, role.Name, ProjectName = role.PlatformKey, urole.Uid })
                               .ToList();

            // 组合用户对应角色
            userList.ForEach(m =>
            {
                m.RoleList = userRoleList.Where(it => it.Uid == m.Id);
            });
            return(new BasePageOutput <List <QueryUserDto> > {
                Data = userList, CurrentPage = input.PageIndex, Total = totalNumber
            });
        }
コード例 #19
0
        public GetConfigOutput GetConfigs(string appId, string namespaceName, long version, string env, string sign)
        {
            #region 验证
            if (appId.IsEmpty())
            {
                throw new BucketException("config_001", "AppId不能为空");
            }
            if (sign.IsEmpty())
            {
                throw new BucketException("config_002", "签名不能为空");
            }
            if (namespaceName.IsEmpty())
            {
                throw new BucketException("config_005", "NamespaceName不能为空");
            }
            #endregion

            #region 项目与签名验证
            var project = _superDbContext.Queryable <AppInfo>().First(it => it.AppId == appId);
            if (project == null)
            {
                throw new BucketException("config_003", "项目不存在");
            }
            var sign_str = $"appId={project.AppId}&appSecret={project.Secret}&namespaceName={namespaceName}";
            var sign_res = Bucket.Utility.Helpers.Encrypt.SHA256(sign_str);
            if (sign.ToLower() != sign_res)
            {
                throw new BucketException("config_004", "签名错误");
            }
            #endregion

            var tableName = _configService.GetConfigTableName(env.SafeString().ToLower());

            // 同一AppId的公共参数分类
            var public_namespace_list = _superDbContext.Queryable <AppNamespaceInfo>()
                                        .Where(it => it.AppId == project.AppId && it.IsDeleted == false && it.IsPublic == true)
                                        .Select(it => it.Name)
                                        .ToList();
            // 公共配置信息
            var public_config = _superDbContext.Queryable <AppConfigInfo>().AS(tableName)
                                .Where(it => it.ConfigAppId == project.AppId && it.IsDeleted == false && public_namespace_list.Contains(it.ConfigNamespaceName) && it.Version > version)
                                .Select(it => new { it.ConfigKey, it.ConfigValue, it.Version })
                                .ToList();
            // 私有配置信息
            var private_config = _superDbContext.Queryable <AppConfigInfo>().AS(tableName)
                                 .Where(it => it.ConfigAppId == project.AppId && it.IsDeleted == false && it.ConfigNamespaceName == namespaceName && it.Version > version)
                                 .Select(it => new { it.ConfigKey, it.ConfigValue, it.Version })
                                 .ToList();
            // 当前最大版本号
            var maxVersion = version;
            // 配置赋值
            var dic_config = new ConcurrentDictionary <string, string>();
            public_config.ForEach(p =>
            {
                if (p.Version > maxVersion)
                {
                    maxVersion = p.Version;
                }
                dic_config.AddOrUpdate(p.ConfigKey, p.ConfigValue, (x, y) => p.ConfigValue);
            });
            private_config.ForEach(p =>
            {
                if (p.Version > maxVersion)
                {
                    maxVersion = p.Version;
                }
                dic_config.AddOrUpdate(p.ConfigKey, p.ConfigValue, (x, y) => p.ConfigValue);
            });
            // 返回
            return(new GetConfigOutput {
                KV = dic_config, Version = maxVersion, AppName = project.Name
            });
        }