Esempio n. 1
0
        /// <summary>
        /// 查询平台列表
        /// </summary>
        /// <returns></returns>
        public async Task <QueryPlatformsOutput> QueryPlatforms()
        {
            var redis     = _redisClient.GetDatabase(_configCenter.Get(SysConfig.RedisConnectionKey, "localhost:6379,allowadmin=true"), 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
                });
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 查询可用角色
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <QueryRolesOutput> QueryRoles(QueryRolesInput input)
        {
            var list  = new List <RoleInfo>();
            var redis = _redisClient.GetDatabase(_configCenter.Get(SysConfig.RedisConnectionKey, "192.168.1.199:6379,allowadmin=true"), 2);

            if (string.IsNullOrWhiteSpace(input.ProjectKey))
            {
                // 查询所有角色
                var redisList = await redis.StringGetAsync(CacheKeys.RoleAllUseKey);

                if (!string.IsNullOrWhiteSpace(redisList))
                {
                    return(new QueryRolesOutput {
                        Data = _jsonHelper.DeserializeObject <List <RoleInfo> >(redisList)
                    });
                }
                else
                {
                    list = await _dbContext.Queryable <RoleInfo>()
                           .Where(it => it.IsDel == false)
                           .WhereIF(!input.ProjectKey.IsEmpty(), it => it.ProjectName == input.ProjectKey)
                           .ToListAsync();

                    await redis.StringSetAsync(CacheKeys.RoleAllUseKey, _jsonHelper.SerializeObject(list));
                }
            }
            else
            {
                // 查询项目对应角色
                list = await _dbContext.Queryable <RoleInfo>()
                       .Where(it => it.IsDel == false)
                       .WhereIF(!input.ProjectKey.IsEmpty(), it => it.ProjectName == input.ProjectKey)
                       .ToListAsync();
            }
            return(new QueryRolesOutput {
                Data = list
            });
        }