/// <summary> /// 获取用户的件约束表达式 /// </summary> /// <param name="userInfo">用户</param> /// <param name="tableName">表名</param> /// <returns>主键</returns> public string GetUserConstraint(string tableName, string permissionCode = "Resource.AccessPermission") { string returnValue = string.Empty; // 这里是获取用户的条件表达式 // 1: 首先用户在哪些角色里是有效的? // 2: 这些角色都有哪些哪些条件约束? // 3: 组合约束条件? // 4:用户本身的约束条件? string permissionId = string.Empty; BasePermissionItemManager permissionItemManager = new BasePermissionItemManager(this.UserInfo); permissionId = permissionItemManager.GetIdByAdd(permissionCode); BaseUserManager manager = new BaseUserManager(this.DbHelper, this.UserInfo); string[] roleIds = manager.GetAllRoleIds(UserInfo.Id); if (roleIds == null || roleIds.Length == 0) { return(returnValue); } BasePermissionScopeManager scopeManager = new BasePermissionScopeManager(this.DbHelper, this.UserInfo); List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BasePermissionScopeEntity.FieldResourceCategory, BaseRoleEntity.TableName)); parameters.Add(new KeyValuePair <string, object>(BasePermissionScopeEntity.FieldResourceId, roleIds)); parameters.Add(new KeyValuePair <string, object>(BasePermissionScopeEntity.FieldTargetCategory, "Table")); parameters.Add(new KeyValuePair <string, object>(BasePermissionScopeEntity.FieldTargetId, tableName)); parameters.Add(new KeyValuePair <string, object>(BasePermissionScopeEntity.FieldPermissionItemId, permissionId)); parameters.Add(new KeyValuePair <string, object>(BasePermissionScopeEntity.FieldEnabled, 1)); parameters.Add(new KeyValuePair <string, object>(BasePermissionScopeEntity.FieldDeletionStateCode, 0)); DataTable dtPermissionScope = scopeManager.GetDataTable(parameters); string permissionConstraint = string.Empty; foreach (DataRow dataRow in dtPermissionScope.Rows) { permissionConstraint = dataRow[BasePermissionScopeEntity.FieldPermissionConstraint].ToString(); permissionConstraint = permissionConstraint.Trim(); if (!string.IsNullOrEmpty(permissionConstraint)) { returnValue += " AND " + permissionConstraint; } } if (!string.IsNullOrEmpty(returnValue)) { returnValue = returnValue.Substring(5); // 解析替换约束表达式标准函数 returnValue = ConstraintUtil.PrepareParameter(this.UserInfo, returnValue); } return(returnValue); }
/// <summary> /// 获取待审批 /// </summary> /// <param name="userInfo">用户信息</param> /// <param name="userId">用户主键</param> /// <param name="categoryCode">分类代码</param> /// <param name="categorybillFullName">单据分类名称</param> /// <param name="searchValue">查询字符串</param> /// <returns></returns> public DataTable GetWaitForAudit(BaseUserInfo userInfo, string userId = null, string categoryCode = null, string categorybillFullName = null, string searchValue = null) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif DataTable dataTable = null; using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.WorkFlowDbType)) { try { // 这个是获取用户的角色信息 dbHelper.Open(UserCenterDbConnection); BaseUserManager userManager = new BaseUserManager(dbHelper); string[] roleIds = userManager.GetAllRoleIds(userInfo.Id); dbHelper.Close(); // 这里是获取待审核信息 dbHelper.Open(WorkFlowDbConnection); BaseWorkFlowCurrentManager workFlowCurrentManager = new BaseWorkFlowCurrentManager(dbHelper, userInfo); dataTable = workFlowCurrentManager.GetWaitForAudit(userId, categoryCode, categorybillFullName, searchValue); dataTable.TableName = BaseWorkFlowCurrentEntity.TableName; BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, MethodBase.GetCurrentMethod()); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return(dataTable); }
/// <summary> /// 获取用户的角色主键数组 /// </summary> /// <param name="userInfo">用户</param> /// <param name="userId">员工主键</param> /// <returns>主键数组</returns> public string[] GetUserRoleIds(BaseUserInfo userInfo, string userId) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif string[] returnValue = null; using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo); returnValue = userManager.GetAllRoleIds(userId); // returnValue = userRoleManager.GetRoleIds(userId); BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, MethodBase.GetCurrentMethod()); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return(returnValue); }
/// <summary> /// 获取等审核信息 /// </summary> /// <param name="userId">用户主键</param> /// <param name="categoryCode">分类代码</param> /// <param name="searchValue">查询字符串</param> /// <param name="showAuditReject">显示退回的</param> /// <returns>数据表</returns> public DataTable GetWaitForAudit(string userId = null, string categoryCode = null, string categorybillFullName = null, string searchValue = null, bool showAuditReject = true) { if (string.IsNullOrEmpty(userId)) { userId = this.UserInfo.Id; } string sqlQuery = " SELECT * " + " FROM " + BaseWorkFlowCurrentEntity.TableName // 未被删除的,有效的数据,还没能审核结束的 + " WHERE (" + BaseWorkFlowCurrentEntity.FieldDeletionStateCode + " = 0) " // Enabled 0 表示,审核还没结束 + " AND (" + BaseWorkFlowCurrentEntity.FieldEnabled + " = 0) "; if (!showAuditReject) { sqlQuery += " AND (" + BaseWorkFlowCurrentEntity.FieldAuditStatus + " != 'AuditReject') "; } if (!string.IsNullOrEmpty(userId)) { // 待审核的工作流(指向用户的) switch (BaseSystemInfo.UserCenterDbType) { case CurrentDbType.Access: sqlQuery += " AND (" + BaseWorkFlowCurrentEntity.FieldToUserId + "= '" + userId + "' "; break; default: sqlQuery += " AND (" + BaseWorkFlowCurrentEntity.FieldToUserId + "=" + userId + " "; break; } //(指向角色的) BaseUserManager userManager = new BaseUserManager(this.UserInfo); string[] roleIds = userManager.GetAllRoleIds(userId); if (roleIds != null && roleIds.Length > 0) { sqlQuery += " OR " + BaseWorkFlowCurrentEntity.FieldToRoleId + " IN (" + StringUtil.ArrayToList(roleIds) + ")"; } //(指向部门的) string[] organizeIds = userManager.GetAllOrganizeIds(userId); if (organizeIds != null && organizeIds.Length > 0) { sqlQuery += " OR (" + BaseWorkFlowCurrentEntity.FieldToUserId + " IS NULL AND + " + BaseWorkFlowCurrentEntity.FieldToDepartmentId + " IN (" + StringUtil.ArrayToList(organizeIds) + "))"; } sqlQuery += " ) "; } if (!string.IsNullOrEmpty(categoryCode)) { BaseWorkFlowBillTemplateManager templateManager = new BaseWorkFlowBillTemplateManager(this.DbHelper, this.UserInfo); DataTable dataTable = templateManager.Search(string.Empty, categoryCode, string.Empty, null, false); string categoryCodes = BaseBusinessLogic.FieldToList(dataTable, BaseWorkFlowBillTemplateEntity.FieldCode); if (!string.IsNullOrEmpty(categoryCodes)) { sqlQuery += " AND (BaseWorkFlowCurrent.CategoryCode IN (" + categoryCodes + ")) "; } } if (!string.IsNullOrEmpty(categorybillFullName)) { sqlQuery += " AND (" + BaseWorkFlowCurrentEntity.TableName + "." + BaseWorkFlowCurrentEntity.FieldCategoryFullName + " ='" + categorybillFullName + "') "; } List <IDbDataParameter> dbParameters = new List <IDbDataParameter>(); if (!String.IsNullOrEmpty(searchValue)) { searchValue = searchValue.Trim(); sqlQuery += " AND (" + BaseWorkFlowCurrentEntity.FieldObjectFullName + " LIKE " + DbHelper.GetParameter(BaseWorkFlowCurrentEntity.FieldObjectFullName); sqlQuery += " OR " + BaseWorkFlowCurrentEntity.FieldAuditUserRealName + " LIKE " + DbHelper.GetParameter(BaseWorkFlowCurrentEntity.FieldAuditUserRealName); sqlQuery += " OR " + BaseWorkFlowCurrentEntity.FieldAuditIdea + " LIKE " + DbHelper.GetParameter(BaseWorkFlowCurrentEntity.FieldAuditIdea); sqlQuery += " OR " + BaseWorkFlowCurrentEntity.FieldAuditStatusName + " LIKE " + DbHelper.GetParameter(BaseWorkFlowCurrentEntity.FieldAuditStatusName); sqlQuery += " OR " + BaseWorkFlowCurrentEntity.FieldToDepartmentName + " LIKE " + DbHelper.GetParameter(BaseWorkFlowCurrentEntity.FieldToDepartmentName); sqlQuery += " OR " + BaseWorkFlowCurrentEntity.FieldToUserRealName + " LIKE " + DbHelper.GetParameter(BaseWorkFlowCurrentEntity.FieldToUserRealName) + ")"; if (searchValue.IndexOf("%") < 0) { searchValue = "%" + searchValue + "%"; } dbParameters.Add(DbHelper.MakeParameter(BaseWorkFlowCurrentEntity.FieldObjectFullName, searchValue)); dbParameters.Add(DbHelper.MakeParameter(BaseWorkFlowCurrentEntity.FieldAuditUserRealName, searchValue)); dbParameters.Add(DbHelper.MakeParameter(BaseWorkFlowCurrentEntity.FieldAuditIdea, searchValue)); dbParameters.Add(DbHelper.MakeParameter(BaseWorkFlowCurrentEntity.FieldAuditStatusName, searchValue)); dbParameters.Add(DbHelper.MakeParameter(BaseWorkFlowCurrentEntity.FieldToDepartmentName, searchValue)); dbParameters.Add(DbHelper.MakeParameter(BaseWorkFlowCurrentEntity.FieldToUserRealName, searchValue)); } // 排序字段 sqlQuery += " ORDER BY " + BaseWorkFlowCurrentEntity.FieldSendDate; return(DbHelper.Fill(sqlQuery, dbParameters.ToArray())); }