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); }
/// <summary> /// 添加短信,可以发给多个人 /// </summary> /// <param name="entity">实体</param> /// <param name="receiverIds">接收者主键组</param> /// <param name="saveSend">保存每个发送记录</param> /// <returns>影响行数</returns> public int Send(IRedisClient redisClient, BaseMessageEntity entity, string[] receiverIds, bool saveSend = true, DateTime?expireAt = null) { // 每发一条短信,数据库中需要记录两条记录,他们的CreateUserId都为创建者ID。 // 接收者多人的话,不要重复设置创建人的记录了,即对发送者来说,只要记录一条记录就够了 int result = 0; entity.CategoryCode = MessageCategory.Receiver.ToString(); entity.IsNew = (int)MessageStateCode.New; BaseUserEntity userEntity = null; for (int i = 0; i < receiverIds.Length; i++) { entity.ReceiverId = receiverIds[i]; // 没必要给自己发了, 其实给自己也需要发,否则不知道是否发送成功了没 //if (entity.ReceiverId.Equals(UserInfo.Id)) //{ // entity.IsNew = (int)MessageStateCode.Old; // continue; //} // messageEntity.ParentId = null; entity.Id = Guid.NewGuid().ToString("N"); entity.CategoryCode = MessageCategory.Receiver.ToString(); userEntity = BaseUserManager.GetObjectByCache(receiverIds[i]); if (userEntity != null && !string.IsNullOrEmpty(userEntity.Id)) { entity.ReceiverRealName = userEntity.RealName; // 发给了哪个部门的人,意义不大,是来自哪个部门的人,意义更大一些 entity.ReceiverDepartmentId = userEntity.DepartmentId; entity.ReceiverDepartmentName = userEntity.DepartmentName; } entity.IsNew = 1; // 接收信息 //string parentId = this.Add(entity, this.Identity, false); string parentId = this.AddObject(entity); # if Redis // 20151018 吉日嘎拉 进行缓存处理, 让程序兼容不用缓存也可以用 CacheProcessing(redisClient, entity, expireAt); #endif if (saveSend) { // 已发送信息 entity.Id = Guid.NewGuid().ToString("N"); entity.ParentId = parentId; entity.IsNew = (int)MessageStateCode.Old; entity.CategoryCode = MessageCategory.Send.ToString(); entity.DeletionStateCode = 0; //this.Add(entity, this.Identity, false); this.AddObject(entity); } result++; }
/// <summary> /// 获取用户实体 /// </summary> /// <param name="userInfo">用户</param> /// <param name="id">主键</param> /// <returns>实体</returns> public BaseUserEntity GetObjectByCache(BaseUserInfo userInfo, string id) { BaseUserEntity entity = null; var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) => { // var userManager = new BaseUserManager(dbHelper, userInfo); // 判断是否已经登录的用户? // if (userManager.UserIsLogOn(userInfo)) // { entity = BaseUserManager.GetObjectByCache(id); // } }); return(entity); }
/// <summary> /// 获取最近联系人 /// </summary> /// <param name="userInfo">用户</param> /// <returns>用户列表</returns> public DataTable GetRecentContacts(BaseUserInfo userInfo) { DataTable result = null; var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessMessageDb(userInfo, parameter, (dbHelper) => { /* * var manager = new BaseMessageRecentManager(dbHelper, userInfo); * string sqlQuery = string.Empty; * if (dbHelper.CurrentDbType == CurrentDbType.Oracle) * { * sqlQuery = "SELECT " + BaseMessageRecentEntity.FieldTargetId + " AS " + BaseUserEntity.FieldId + "," + BaseMessageRecentEntity.FieldRealName + "," + BaseMessageRecentEntity.FieldCompanyName + "," + BaseMessageRecentEntity.FieldDepartmentName + " FROM " + BaseMessageRecentEntity.TableName + " WHERE " + BaseMessageRecentEntity.FieldUserId + "= '" + userInfo.Id + "'" + " AND ROWNUM < = 50 " + " ORDER BY " + BaseMessageRecentEntity.FieldModifiedOn + " DESC "; + } + else + { + sqlQuery = "SELECT TOP 50 " + BaseMessageRecentEntity.FieldTargetId + " AS " + BaseUserEntity.FieldId + "," + BaseMessageRecentEntity.FieldRealName + "," + BaseMessageRecentEntity.FieldCompanyName + "," + BaseMessageRecentEntity.FieldDepartmentName + " FROM " + BaseMessageRecentEntity.TableName + " WHERE " + BaseMessageRecentEntity.FieldUserId + "= '" + userInfo.Id + "'" + " ORDER BY " + BaseMessageRecentEntity.FieldModifiedOn + " DESC "; + } */ // 2015-09-27 吉日嘎拉 最新联系人方式,从缓存服务器里读取 result = new DataTable(BaseUserEntity.TableName); result.Columns.Add(BaseUserEntity.FieldId.ToUpper()); result.Columns.Add(BaseUserEntity.FieldRealName.ToUpper()); result.Columns.Add(BaseUserEntity.FieldCompanyName.ToUpper()); result.Columns.Add(BaseUserEntity.FieldDepartmentName.ToUpper()); result.Columns.Add(BaseUserEntity.FieldSortCode.ToUpper()); # if Redis // 2015-11-20 吉日嘎拉 为了让程序能编译通过 using (var redisClient = PooledRedisHelper.GetMessageClient()) { List <string> list = redisClient.GetAllItemsFromSortedSetDesc(("r" + userInfo.Id)); for (int i = 0; i < list.Count && i < 100; i++) { BaseUserEntity userEntity = BaseUserManager.GetObjectByCache(list[i]); if (userEntity != null) { DataRow dr = result.NewRow(); dr[BaseUserEntity.FieldId] = userEntity.Id; dr[BaseUserEntity.FieldRealName] = userEntity.RealName; dr[BaseUserEntity.FieldCompanyName] = userEntity.CompanyName; dr[BaseUserEntity.FieldDepartmentName] = userEntity.DepartmentName; dr[BaseUserEntity.FieldSortCode] = i; result.Rows.Add(dr); } } } #endif result.AcceptChanges(); });
/// <summary> /// 获取用户的通知列表 /// </summary> /// <param name="userId">用户主键</param> /// <param name="parentId">那个类别</param> /// <param name="topLimit">获取前几个</param> /// <param name="containContents">是否包含内容</param> /// <returns>通知列表</returns> public List <BaseContactEntity> GetTopListByUser(string userId, string parentId, int topLimit, bool containContents = false) { List <BaseContactEntity> result = new List <BaseContactEntity>(); // 获取用户信息 string commandText = string.Empty; BaseUserEntity userEntity = BaseUserManager.GetObjectByCache(userId); if (userEntity != null) { commandText = " (Enabled = 1 AND DeletionStateCode = 0 AND AuditStatus=2 AND IsOpen = 1) OR (Enabled = 1 AND AuditStatus=2 AND DeletionStateCode = 0 AND Id IN ("; if (!string.IsNullOrEmpty(parentId)) { commandText = " (ParentId = '" + parentId + "' AND Enabled = 1 AND DeletionStateCode = 0 AND AuditStatus=2 AND IsOpen = 1) OR (ParentId = '" + parentId + "' AND Enabled = 1 AND DeletionStateCode = 0 AND Id IN ("; } // 获取用户所在的单位的信息 BaseOrganizeEntity organizeEntity = BaseOrganizeManager.GetObjectByCache(userEntity.CompanyId); if (organizeEntity != null) { // 所在省 if (!string.IsNullOrEmpty(organizeEntity.ProvinceId)) { commandText += " SELECT (ContactId FROM BaseContactDetails WHERE Category = '0' AND ReceiverId = '" + organizeEntity.ProvinceId + "') "; } // 所在市 if (!string.IsNullOrEmpty(organizeEntity.CityId)) { commandText += " UNION SELECT (ContactId FROM BaseContactDetails WHERE Category = '1' AND ReceiverId = '" + organizeEntity.CityId + "') "; } // 所在县 if (!string.IsNullOrEmpty(organizeEntity.DistrictId)) { commandText += " UNION SELECT (ContactId FROM BaseContactDetails WHERE Category = '2' AND ReceiverId = '" + organizeEntity.DistrictId + "') "; } } // 发给所在单位的 if (!string.IsNullOrEmpty(userEntity.CompanyId)) { commandText += " UNION SELECT (ContactId FROM BaseContactDetails WHERE Category = '3' AND ReceiverId = '" + userEntity.CompanyId + "') "; } // 发给自己的 if (!string.IsNullOrEmpty(userEntity.Id)) { commandText += " UNION SELECT (ContactId FROM BaseContactDetails WHERE Category = '4' AND ReceiverId = '" + userEntity.Id + "') ) )"; } string order = BaseContactEntity.FieldPriority + "," + BaseContactEntity.FieldCreateOn + " DESC "; using (IDataReader dataReader = this.ExecuteReaderByWhere(commandText, null, topLimit, order)) { while (dataReader.Read()) { // 2015-11-18 吉日嘎拉 消息的内容不能有,否则会出错,缓存的内容也太大 BaseContactEntity contactEntity = BaseEntity.Create <BaseContactEntity>(dataReader, false); // 是否要内容 if (!containContents) { contactEntity.Contents = null; } result.Add(contactEntity); } } } return(result); }
/// <summary> /// 获取权限审核 /// </summary> /// <param name="userInfo">用户</param> /// <param name="startDate">开始日期</param> /// <param name="endDate">结束日期</param> /// <param name="companyId">公司主键</param> /// <param name="userId">用户主键</param> /// <param name="result">权限主键</param> /// <param name="recordCount">记录数</param> /// <param name="pageIndex">当前页</param> /// <param name="pageSize">每页显示条数</param> /// <returns>数据表</returns> public DataTable PermissionMonitor(BaseUserInfo userInfo, DateTime startDate, DateTime endDate, string companyId, string userId, string permissionId, out int recordCount, int pageIndex = 0, int pageSize = 20) { DataTable result = null; recordCount = 0; int myRecordCount = 0; var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) => { string whereClause = string.Empty; List <KeyValuePair <string, object> > dbParameters = new List <KeyValuePair <string, object> >(); if (startDate != null) { if (!string.IsNullOrEmpty(whereClause)) { whereClause += " AND "; } whereClause += BasePermissionEntity.FieldCreateOn + " >= " + DotNet.Utilities.DbHelper.GetParameter(BaseSystemInfo.ServerDbType, "startDate"); dbParameters.Add(new KeyValuePair <string, object>("startDate", startDate)); } if (endDate != null) { if (!string.IsNullOrEmpty(whereClause)) { whereClause += " AND "; } whereClause += BasePermissionEntity.FieldCreateOn + " <= " + DotNet.Utilities.DbHelper.GetParameter(BaseSystemInfo.ServerDbType, "endDate"); dbParameters.Add(new KeyValuePair <string, object>("endDate", endDate)); } string tableName = BasePermissionEntity.TableName; if (userInfo != null) { tableName = userInfo.SystemCode + "Permission"; } myRecordCount = DbLogic.GetCount(dbHelper, tableName, whereClause, dbHelper.MakeParameters(dbParameters)); result = DbLogic.GetDataTableByPage(dbHelper, tableName, "*", pageIndex, pageSize, whereClause, dbHelper.MakeParameters(dbParameters), BasePermissionEntity.FieldCreateOn + " DESC"); if (!result.Columns.Contains("ResourceCategoryName")) { result.Columns.Add("ResourceCategoryName".ToUpper()); } if (!result.Columns.Contains("PermissionName")) { result.Columns.Add("PermissionName".ToUpper()); } if (!result.Columns.Contains("PermissionCode")) { result.Columns.Add("PermissionCode".ToUpper()); } if (!result.Columns.Contains("ResourceName")) { result.Columns.Add("ResourceName".ToUpper()); } if (!result.Columns.Contains("CompanyName")) { result.Columns.Add("CompanyName".ToUpper()); } foreach (DataRow dr in result.Rows) { string id = dr["PermissionId"].ToString(); BaseModuleEntity moduleEntity = BaseModuleManager.GetObjectByCache(userInfo, id); if (moduleEntity != null) { dr["PermissionName"] = moduleEntity.FullName; dr["PermissionCode"] = moduleEntity.Code; } if (dr["ResourceCategory"].ToString().Equals(BaseUserEntity.TableName)) { id = dr["ResourceId"].ToString(); BaseUserEntity userEntity = BaseUserManager.GetObjectByCache(id); if (userEntity != null) { dr["ResourceName"] = userEntity.RealName; dr["CompanyName"] = userEntity.CompanyName; dr["ResourceCategoryName"] = "用户"; } } else if (dr["ResourceCategory"].ToString().Equals(BaseOrganizeEntity.TableName)) { id = dr["ResourceId"].ToString(); BaseOrganizeEntity organizeEntity = BaseOrganizeManager.GetObjectByCache(id); if (organizeEntity != null) { dr["ResourceName"] = organizeEntity.FullName; dr["ResourceCategoryName"] = "网点"; } } else if (dr["ResourceCategory"].ToString().Equals(BaseRoleEntity.TableName)) { id = dr["ResourceId"].ToString(); BaseRoleEntity roleEntity = BaseRoleManager.GetObjectByCache(userInfo, id); if (roleEntity != null) { dr["ResourceName"] = roleEntity.RealName; dr["ResourceCategoryName"] = "角色"; } } } }); recordCount = myRecordCount; return(result); }
// // 授予权限的实现部分 // #region public string Grant(string systemCode, string userId, string permissionId, bool chekExists = true) 为了提高授权的运行速度 /// <summary> /// 为了提高授权的运行速度 /// </summary> /// <param name="systemCode">系统编号</param> /// <param name="userId">用户主键</param> /// <param name="result">权限主键</param> /// <param name="chekExists">判断是否存在</param> /// <returns>主键</returns> public string Grant(string systemCode, string userId, string permissionId, bool chekExists = true) { string result = string.Empty; if (String.IsNullOrEmpty(userId) && String.IsNullOrEmpty(permissionId)) { return(result); } this.CurrentTableName = systemCode + "Permission"; string currentId = string.Empty; // 判断是否已经存在这个权限,若已经存在就不重复增加了 if (chekExists) { List <KeyValuePair <string, object> > whereParameters = new List <KeyValuePair <string, object> >(); whereParameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceCategory, BaseUserEntity.TableName)); whereParameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceId, userId)); whereParameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldPermissionId, permissionId)); currentId = this.GetId(whereParameters); if (!string.IsNullOrEmpty(currentId)) { List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldEnabled, 1)); parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldDeletionStateCode, 0)); parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldModifiedUserId, this.UserInfo.Id)); parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldModifiedBy, this.UserInfo.RealName)); parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldModifiedOn, DateTime.Now)); // 更新状态,设置为有效、并取消删除标志,权限也不是天天变动的,所以可以更新一下 this.SetProperty(currentId, parameters); result = currentId; } } if (string.IsNullOrEmpty(currentId)) { BasePermissionEntity permissionEntity = new BasePermissionEntity(); permissionEntity.ResourceCategory = BaseUserEntity.TableName; permissionEntity.ResourceId = userId; permissionEntity.PermissionId = permissionId; permissionEntity.Enabled = 1; // 2015-07-03 吉日嘎拉 若是没有公司相关的信息,就把公司区分出来,每个公司可以看每个公司的数据 if (string.IsNullOrEmpty(permissionEntity.CompanyId)) { BaseUserEntity entity = BaseUserManager.GetObjectByCache(userId); if (entity != null) { permissionEntity.CompanyId = entity.CompanyId; permissionEntity.CompanyName = entity.CompanyName; } } BasePermissionManager permissionManager = new BasePermissionManager(DbHelper, UserInfo, this.CurrentTableName); result = permissionManager.Add(permissionEntity); } // 2015-09-21 吉日嘎拉 这里增加变更日志 string tableName = systemCode + ".Permission.User"; SQLBuilder sqlBuilder = new SQLBuilder(this.DbHelper); sqlBuilder.BeginInsert(BaseModifyRecordEntity.TableName); sqlBuilder.SetValue(BaseModifyRecordEntity.FieldTableCode, tableName); if (this.DbHelper.CurrentDbType == CurrentDbType.Oracle) { sqlBuilder.SetFormula(BaseModifyRecordEntity.FieldId, "SEQ_" + BaseModifyRecordEntity.TableName + ".NEXTVAL"); } sqlBuilder.SetValue(BaseModifyRecordEntity.FieldRecordKey, userId); sqlBuilder.SetValue(BaseModifyRecordEntity.FieldColumnCode, "授权"); sqlBuilder.SetValue(BaseModifyRecordEntity.FieldColumnDescription, BaseModuleManager.GetNameByCache(systemCode, permissionId)); sqlBuilder.SetValue(BaseModifyRecordEntity.FieldOldValue, null); sqlBuilder.SetValue(BaseModifyRecordEntity.FieldNewValue, permissionId); sqlBuilder.SetValue(BaseModifyRecordEntity.FieldCreateUserId, this.UserInfo.Id); sqlBuilder.SetValue(BaseModifyRecordEntity.FieldCreateBy, this.UserInfo.RealName); sqlBuilder.SetDBNow(BaseModifyRecordEntity.FieldCreateOn); sqlBuilder.SetValue(BaseModifyRecordEntity.FieldIPAddress, this.UserInfo.IPAddress); sqlBuilder.EndInsert(); return(result); }