Esempio n. 1
0
        public static BaseDepartmentEntity GetObjectByCodeByCache(string code)
        {
            BaseDepartmentEntity result = null;

            if (string.IsNullOrEmpty(code))
            {
                return(result);
            }

            // string key = "DepartmentByCode:" + code;
            string key = "DBC:" + code;
            string id  = string.Empty;

            using (var redisClient = PooledRedisHelper.GetReadOnlyClient())
            {
                id = redisClient.Get <string>(key);
            }
            if (!string.IsNullOrWhiteSpace(id))
            {
                result = GetObjectByCache(id);
            }
            else
            {
                // 从数据库读取数据
                BaseDepartmentManager departmentManager = new BaseDepartmentManager();
                result = departmentManager.GetObjectByCode(code);
                // 设置缓存,没必要来个空操作
                if (result != null)
                {
                    SetCache(result);
                }
            }

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// 从缓存获取获取实体
        /// </summary>
        /// <param name="companyId">公司主键</param>
        /// <param name="fullName">部门名称</param>
        /// <returns>实体</returns>
        public static BaseDepartmentEntity GetObjectByNameByCache(string companyId, string fullName)
        {
            BaseDepartmentEntity result = null;

            if (!string.IsNullOrEmpty(companyId) && !string.IsNullOrEmpty(fullName))
            {
                string id  = string.Empty;
                string key = "DBN:" + companyId + ":" + fullName;
                using (var redisClient = PooledRedisHelper.GetReadOnlyClient())
                {
                    id = redisClient.Get <string>(key);
                    if (!string.IsNullOrWhiteSpace(id))
                    {
                        result = GetObjectByCache(id);
                    }
                    if (result == null)
                    {
                        BaseDepartmentManager departmentManager = new BaseDepartmentManager();
                        result = departmentManager.GetObjectByName(companyId, fullName);
                        // 若是空的不用缓存,继续读取实体
                        if (result != null)
                        {
                            SetCache(result);
                        }
                    }
                }
            }

            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// 从缓存获取获取实体
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>实体</returns>
        public static BaseDepartmentEntity GetObjectByCache(string id, bool fefreshCache = false)
        {
            BaseDepartmentEntity result = null;

            if (!string.IsNullOrEmpty(id))
            {
                string key = "D:" + id;

                if (!fefreshCache)
                {
                    result = GetCacheByKey(key);
                }

                if (result == null)
                {
                    BaseDepartmentManager manager = new BaseDepartmentManager();
                    result = manager.GetObject(id);
                    // 若是空的不用缓存,继续读取实体
                    if (result != null)
                    {
                        SetCache(result);
                    }
                }
            }

            return(result);
        }
        public static int RefreshCache(string userId)
        {
            int result = 0;

            // 刷新用户的缓存
            BaseUserEntity userEntity = BaseUserManager.GetObjectByCache(userId, true);

            if (userEntity != null)
            {
                // 刷新用户的登录限制
                BaseUserManager.ResetIPAddressByCache(userId);
                BaseUserManager.ResetMACAddressByCache(userId);
                // 刷新组织机构缓存
                BaseOrganizeManager.GetObjectByCache(userEntity.CompanyId, true);
                // 刷新部门缓存
                BaseDepartmentManager.GetObjectByCache(userEntity.DepartmentId, true);
                // 2016-02-18 吉日嘎拉 刷新拒绝权限(把用户的权限放在一起方便直接移除、刷新)
                string key = "User:IsAuthorized:" + userId;
                using (var redisClient = PooledRedisHelper.GetPermissionClient())
                {
                    redisClient.Remove(key);
                }
                // 每个子系统都可以循环一次
                string[] systemCodes = BaseSystemManager.GetSystemCodes();
                for (int i = 0; i < systemCodes.Length; i++)
                {
                    BaseUserPermissionManager.ResetPermissionByCache(systemCodes[i], userId);
                }
            }

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

            // 2016-01-28 更新用户缓存
            using (var redisClient = PooledRedisHelper.GetClient())
            {
                BaseDepartmentManager.CacheContractAreaPreheatingSpelling(redisClient, entity);
            }

            return(result);
        }
Esempio n. 6
0
        /// <summary>
        /// 移动数据
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">主键</param>
        /// <param name="parentId">父主键</param>
        /// <returns>影响行数</returns>
        public int MoveTo(BaseUserInfo userInfo, string id, string parentId)
        {
            int result = 0;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                var manager = new BaseDepartmentManager(dbHelper, userInfo);
                result      = manager.MoveTo(id, parentId);
            });
            return(result);
        }
Esempio n. 7
0
        /// <summary>
        /// 批量保存数据
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="result">数据表</param>
        /// <returns>影响行数</returns>
        public int BatchSave(BaseUserInfo userInfo, DataTable dt)
        {
            int result = 0;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                var manager = new BaseDepartmentManager(dbHelper, userInfo);
                result      = manager.BatchSave(dt);
            });
            return(result);
        }
Esempio n. 8
0
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">主键</param>
        /// <returns>实体</returns>
        public BaseDepartmentEntity GetObject(BaseUserInfo userInfo, string id)
        {
            BaseDepartmentEntity result = null;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var manager = new BaseDepartmentManager(dbHelper, userInfo);
                result      = manager.GetObject(id);
            });

            return(result);
        }
Esempio n. 9
0
        /// <summary>
        /// 按主键获取列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="ids">主键数组</param>
        /// <returns>数据表</returns>
        public List <BaseDepartmentEntity> GetListByIds(BaseUserInfo userInfo, string[] ids)
        {
            List <BaseDepartmentEntity> result = new List <BaseDepartmentEntity>();

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var userManager = new BaseDepartmentManager(dbHelper, userInfo);
                result          = userManager.GetList <BaseDepartmentEntity>(BaseDepartmentEntity.FieldId, ids, BaseDepartmentEntity.FieldSortCode);
            });

            return(result);
        }
Esempio n. 10
0
        /// <summary>
        /// 按主键数组获取列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="ids">组织机构主键</param>
        /// <returns>数据表</returns>
        public DataTable GetDataTableByIds(BaseUserInfo userInfo, string[] ids)
        {
            var dt = new DataTable(BaseDepartmentEntity.TableName);

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var manager  = new BaseDepartmentManager(dbHelper, userInfo);
                dt           = manager.GetDataTable(BaseDepartmentEntity.FieldId, ids, BaseDepartmentEntity.FieldSortCode);
                dt.TableName = BaseDepartmentEntity.TableName;
            });
            return(dt);
        }
Esempio n. 11
0
        /// <summary>
        /// 批量移动数据
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="ids">主键数组</param>
        /// <param name="parentId">父节点主键</param>
        /// <returns>影响行数</returns>
        public int BatchMoveTo(BaseUserInfo userInfo, string[] organizeIds, string parentId)
        {
            int result = 0;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                var manager = new BaseDepartmentManager(dbHelper, userInfo);
                for (int i = 0; i < organizeIds.Length; i++)
                {
                    result += manager.MoveTo(organizeIds[i], parentId);
                }
            });
            return(result);
        }
Esempio n. 12
0
        /// <summary>
        /// 查询组织机构
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="organizeId">组织机构</param>
        /// <param name="searchValue">查询</param>
        /// <returns>数据表</returns>
        public DataTable Search(BaseUserInfo userInfo, string organizeId, string searchValue)
        {
            var dt = new DataTable(BaseDepartmentEntity.TableName);

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                // 获得组织机构列表
                var manager = new BaseDepartmentManager(dbHelper, userInfo);
                // dt = manager.Search(string.Empty, searchValue);
                dt.DefaultView.Sort = BaseDepartmentEntity.FieldSortCode;
                dt.TableName        = BaseDepartmentEntity.TableName;
            });
            return(dt);
        }
Esempio n. 13
0
        /// <summary>
        /// 获取部门列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="parameters">参数</param>
        /// <returns>数据表</returns>
        public DataTable GetDataTable(BaseUserInfo userInfo, List <KeyValuePair <string, object> > parameters)
        {
            var dt = new DataTable(BaseDepartmentEntity.TableName);

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                // 获得组织机构列表
                var manager         = new BaseDepartmentManager(dbHelper, userInfo);
                dt                  = manager.GetDataTable(parameters, BaseDepartmentEntity.FieldSortCode);
                dt.DefaultView.Sort = BaseDepartmentEntity.FieldSortCode;
                dt.TableName        = BaseDepartmentEntity.TableName;
            });
            return(dt);
        }
Esempio n. 14
0
        /// <summary>
        /// 更新组织机构
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="entity">实体</param>
        /// <param name="statusCode">状态码</param>
        /// <param name="statusMessage">状态信息</param>
        /// <returns>影响行数</returns>
        public int Update(BaseUserInfo userInfo, BaseDepartmentEntity entity, out string statusCode, out string statusMessage)
        {
            int result = 0;

            string returnCode    = string.Empty;
            string returnMessage = string.Empty;
            var    parameter     = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                var manager   = new BaseDepartmentManager(dbHelper, userInfo);
                result        = manager.Update(entity, out returnCode);
                returnMessage = manager.GetStateMessage(returnCode);
            });
            statusCode    = returnCode;
            statusMessage = returnMessage;
            return(result);
        }
Esempio n. 15
0
        /// <summary>
        /// 按父节点获取列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="parentId">父节点</param>
        /// <returns>数据表</returns>
        public DataTable GetDataTableByParent(BaseUserInfo userInfo, string parentId)
        {
            var dt = new DataTable(BaseDepartmentEntity.TableName);

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                // 这里可以缓存起来,提高效率
                var manager = new BaseDepartmentManager(dbHelper, userInfo);
                // 这里是条件字段
                List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();
                parameters.Add(new KeyValuePair <string, object>(BaseDepartmentEntity.FieldParentId, parentId));
                parameters.Add(new KeyValuePair <string, object>(BaseDepartmentEntity.FieldEnabled, 1));
                parameters.Add(new KeyValuePair <string, object>(BaseDepartmentEntity.FieldDeletionStateCode, 0));
                // 获取列表,指定排序字段
                dt = manager.GetDataTable(parameters, BaseDepartmentEntity.FieldSortCode);
                dt.DefaultView.Sort = BaseDepartmentEntity.FieldSortCode;
                dt.TableName        = BaseDepartmentEntity.TableName;
            });

            return(dt);
        }
Esempio n. 16
0
        /// <summary>
        /// 批量打删除标志
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="ids">主键数组</param>
        /// <returns>影响行数</returns>
        public int SetDeleted(BaseUserInfo userInfo, string[] ids)
        {
            int result = 0;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                var manager = new BaseDepartmentManager(dbHelper, userInfo);
                for (int i = 0; i < ids.Length; i++)
                {
                    // 设置部门为删除状态
                    result += manager.SetDeleted(ids[i]);
                    // 相应的用户也需要处理
                    var userManager = new BaseUserManager(dbHelper, userInfo);
                    List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();
                    parameters = new List <KeyValuePair <string, object> >();
                    parameters.Add(new KeyValuePair <string, object>(BaseUserEntity.FieldDepartmentId, null));
                    parameters.Add(new KeyValuePair <string, object>(BaseUserEntity.FieldDepartmentName, null));
                    userManager.SetProperty(new KeyValuePair <string, object>(BaseUserEntity.FieldDepartmentId, ids[i]), parameters);
                }
            });
            return(result);
        }