Esempio n. 1
0
        /// <summary>
        /// 快速模糊检索网点(高速缓存)
        ///
        /// 01:所有网点查询的缓存数据方法 prefix = string.empty
        /// 02: 结算中心主键缓存数据方法 prefix = "CostCenterId:" + costCenterId + ":"
        /// 03:按省缓存数据方法 prefix = "ProvinceId:" + provinceId + ":"
        /// 04:按市缓存数据方法 prefix = "CityId:" + cityId + ":"
        /// 05:父级主键缓存数据方法 prefix = "ParentId:" + parentId + ":"
        /// 06:所有下属递归的方式进行快速缓存检索(START WITH CONNECT BY PRIOR) prefix = "StartId:" + startId + ":"
        /// 07:发航空 prefix = "SendAir:"
        /// 08:接收订单 prefix = "IsReceiveOrder:"
        /// 09:接收投诉工单 prefix = "IsReceiveComplain:"
        /// 10: 一级网点主键缓存数据方法 prefix = "CompanyId:" + companyId + ":"
        ///
        /// </summary>
        /// <param name="prefix">搜索前缀</param>
        /// <param name="key">搜搜关键字</param>
        /// <param name="returnId">返回主键</param>
        /// <param name="returnCode">返回编号</param>
        /// <returns>查询结果数组</returns>
        public static List <KeyValuePair <string, string> > GetOrganizesByKey(string prefix, string key, bool returnId = true, bool showCode = false, int topLimit = 20)
        {
            List <KeyValuePair <string, string> > result = new List <KeyValuePair <string, string> >();

            /*
             * var where = "(" + BaseOrganizeEntity.FieldFullName + " LIKE'%" + q
             + "%' OR " + BaseOrganizeEntity.FieldCode + " LIKE '%" + q + "%' OR "
             + BaseOrganizeEntity.FieldSimpleSpelling + " LIKE '%" + q + "%' OR "
             + BaseOrganizeEntity.FieldQuickQuery + " LIKE '%" + q + "%') AND "
             + BaseOrganizeEntity.FieldEnabled + " = 1 "
             + BaseOrganizeEntity.FieldDeletionStateCode + " = 0 ";
             */

            if (string.IsNullOrEmpty(key))
            {
                key = string.Empty;
            }

            // 2016-01-06 吉日嘎拉 优化代码,提高检索效率,全部转小写进行比对
            key = prefix + key.ToLower();

            // 2016-02-19 宋彪 PooledRedisHelper.GetReadOnlyClient() 改为 PooledRedisHelper.GetSpellingClient()
            using (var redisClient = PooledRedisHelper.GetSpellingReadOnlyClient())
            {
                // 每次从有序集合中的消息取出20条信息,返回给客户端,在客户端展示阅读成功后才从内存里去掉。
                List <string> list = redisClient.GetRangeFromSortedSet(key, 0, topLimit);

                if (list != null)
                {
                    for (int i = 0; i < list.Count; i++)
                    {
                        // 从内存里直接获取这个对应的消息
                        string[] organize = list[i].Split(';');
                        string   id       = organize[0];
                        string   code     = organize[1];
                        string   fullName = organize[2];
                        if (returnId)
                        {
                            if (showCode)
                            {
                                result.Add(new KeyValuePair <string, string>(id, fullName + " " + code));
                            }
                            else
                            {
                                result.Add(new KeyValuePair <string, string>(id, fullName));
                            }
                        }
                        else
                        {
                            if (showCode)
                            {
                                result.Add(new KeyValuePair <string, string>(code, fullName + " " + code));
                            }
                            else
                            {
                                result.Add(new KeyValuePair <string, string>(code, fullName));
                            }
                        }
                    }
                }
            }

            return(result);
        }