Beispiel #1
0
        public int AfterDeleted(object[] ids, bool enabled = false, bool modifiedUser = false)
        {
            int result = 0;

            for (int i = 0; i < ids.Length; i++)
            {
                string         id     = ids[i].ToString();
                BaseUserEntity entity = GetObjectByCache(id);

                // 2016-02-19 宋彪 PooledRedisHelper.GetClient() 改为 PooledRedisHelper.GetSpellingClient()
                using (var redisClient = PooledRedisHelper.GetSpellingClient())
                {
                    // 2016-02-02 吉日嘎拉,修改数据后重新设置缓存。
                    BaseUserManager.CachePreheatingSpelling(redisClient, entity);
                }
            }

            if (ids != null && ids.Length > 0)
            {
                // 删除后把已经删除的数据搬迁到被删除表里去。

                /*
                 * string where = BaseUserEntity.FieldId + " IN (" + StringUtil.ArrayToList((string[])ids, "") + ") ";
                 *
                 * string commandText = @"INSERT INTO BASEUSER_DELETED SELECT * FROM " + BaseUserEntity.TableName + " WHERE " + where;
                 * IDbHelper dbHelper1 = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType, BaseSystemInfo.UserCenterDbConnection);
                 * dbHelper1.ExecuteNonQuery(commandText);
                 */

                // 进行删除操作
                this.Delete(ids);
            }

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// 添加之后,需要重新刷新缓存,否则其他读取数据的地方会乱了,或者不及时了
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>影响行数</returns>
        public int AfterAdd(BaseOrganizeEntity entity)
        {
            int result = 0;

            // 2016-01-28 更新用户缓存
            // 2016-02-19 宋彪 PooledRedisHelper.GetClient() 改为 PooledRedisHelper.GetSpellingClient()
            using (var redisClient = PooledRedisHelper.GetSpellingClient())
            {
                BaseOrganizeManager.CachePreheatingSpelling(redisClient, entity);
            }

            return(result);
        }
        /// <summary>
        /// 添加之后,需要重新刷新缓存,否则其他读取数据的地方会乱了,或者不及时了
        /// </summary>
        /// <param name="entity">用户实体</param>
        /// <returns></returns>
        public int AfterAdd(BaseUserEntity entity)
        {
            int result = 0;

            // 2016-01-28 更新用户缓存
            BaseUserManager.SetCache(entity);

            // 2016-02-19 宋彪 PooledRedisHelper.GetClient() 改为 PooledRedisHelper.GetSpellingClient()
            using (var redisClient = PooledRedisHelper.GetSpellingClient())
            {
                BaseUserManager.CachePreheatingSpelling(redisClient, entity);
            }
            // AfterAddSynchronous(entity);

            return(result);
        }
Beispiel #4
0
        public static void CachePreheatingSpelling(bool flushDb = false)
        {
            // 组织机构数据缓存预热实现
            BaseOrganizeManager organizeManager = new Business.BaseOrganizeManager();

            // 减少数据库连接、减少内存站用、一边度取、一边设置缓存,只读取需要的数据
            organizeManager.SelectFields = BaseOrganizeEntity.FieldId
                                           + ", " + BaseOrganizeEntity.FieldCode
                                           + ", " + BaseOrganizeEntity.FieldFullName
                                           + " , " + BaseOrganizeEntity.FieldSimpleSpelling
                                           + " , " + BaseOrganizeEntity.FieldCostCenterId
                                           + " , " + BaseOrganizeEntity.FieldProvinceId
                                           + " , " + BaseOrganizeEntity.FieldCompanyId
                                           + " , " + BaseOrganizeEntity.FieldCityId
                                           + " , " + BaseOrganizeEntity.FieldParentId
                                           + " , " + BaseOrganizeEntity.FieldSendAir
                                           + " , " + BaseOrganizeEntity.FieldEnabled
                                           + " , " + BaseOrganizeEntity.FieldDeletionStateCode
                                           + " , " + BaseOrganizeEntity.FieldSortCode;

            // 读取有效的,没有被删除的网点数据
            // List<KeyValuePair<string, object>> parameters = new List<KeyValuePair<string, object>>();
            // parameters.Add(new KeyValuePair<string, object>(BaseOrganizeEntity.FieldEnabled, 1));
            // parameters.Add(new KeyValuePair<string, object>(BaseOrganizeEntity.FieldDeletionStateCode, 0));

            // 2016-02-19 宋彪 PooledRedisHelper.GetClient() 改为 PooledRedisHelper.GetSpellingClient()
            using (var redisClient = PooledRedisHelper.GetSpellingClient())
            {
                if (flushDb)
                {
                    redisClient.FlushDb();
                }

                double score = 0;

                using (IDataReader dataReader = organizeManager.ExecuteReader(0, BaseOrganizeEntity.FieldFullName))
                {
                    while (dataReader.Read())
                    {
                        score++;

                        // 读取到的数据直接强制设置到缓存里
                        BaseOrganizeEntity entity = new BaseOrganizeEntity();
                        entity.Id             = dataReader[BaseOrganizeEntity.FieldId].ToString();
                        entity.Code           = dataReader[BaseOrganizeEntity.FieldCode].ToString();
                        entity.FullName       = dataReader[BaseOrganizeEntity.FieldFullName].ToString();
                        entity.SimpleSpelling = dataReader[BaseOrganizeEntity.FieldSimpleSpelling].ToString().ToLower();

                        entity.CostCenterId      = dataReader[BaseOrganizeEntity.FieldCostCenterId].ToString();
                        entity.ProvinceId        = dataReader[BaseOrganizeEntity.FieldProvinceId].ToString();
                        entity.CompanyId         = dataReader[BaseOrganizeEntity.FieldCompanyId].ToString();
                        entity.CityId            = dataReader[BaseOrganizeEntity.FieldCityId].ToString();
                        entity.ParentId          = dataReader[BaseOrganizeEntity.FieldParentId].ToString();
                        entity.SendAir           = BaseBusinessLogic.ConvertToInt(dataReader[BaseOrganizeEntity.FieldSendAir]);
                        entity.Enabled           = BaseBusinessLogic.ConvertToInt(dataReader[BaseOrganizeEntity.FieldEnabled]);
                        entity.DeletionStateCode = BaseBusinessLogic.ConvertToInt(dataReader[BaseOrganizeEntity.FieldDeletionStateCode]);
                        entity.SortCode          = BaseBusinessLogic.ConvertToInt(dataReader[BaseOrganizeEntity.FieldSortCode]);

                        if (!flushDb)
                        {
                            score = entity.SortCode.Value;
                        }

                        CachePreheatingSpelling(redisClient, entity, score);

                        if (flushDb)
                        {
                            // 2016-02-02 吉日嘎拉 设置一下排序属性
                            new Business.BaseManager(BaseOrganizeEntity.TableName).SetProperty(entity.Id, new KeyValuePair <string, object>(BaseOrganizeEntity.FieldSortCode, score));
                        }
                    }
                }
            }
        }