コード例 #1
0
        /// <summary>
        /// 用户是否在角色里
        /// 2015-12-24 吉日嘎拉 提供高速缓存使用的方法
        /// </summary>
        /// <param name="systemCode">系统编号</param>
        /// <param name="userId">用户主键</param>
        /// <param name="roleCode">角色编号</param>
        /// <param name="companyId">公司主键</param>
        /// <returns>在角色中</returns>
        public static bool IsInRoleByCache(string systemCode, string userId, string roleCode, string companyId = null)
        {
            // 返回值
            var result = false;

            if (!string.IsNullOrEmpty(userId))
            {
                // 从缓存里快速得到角色对应的主键盘
                var roleId = BaseRoleManager.GetIdByCodeByCache(systemCode, roleCode);
                if (!string.IsNullOrEmpty(roleId))
                {
                    var roleIds = GetRoleIdsByCache(systemCode, userId, companyId);
                    if (roleIds != null && roleIds.Length > 0)
                    {
                        result = (Array.IndexOf(roleIds, roleId) >= 0);
                    }
                }
            }

            return(result);
        }
コード例 #2
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////
        /// 用户权限判断相关(需要实现对外调用)
        //////////////////////////////////////////////////////////////////////////////////////////////////////

        #region public bool IsInRole(BaseUserInfo userInfo, string userId, string roleName)
        /// <summary>
        /// 用户是否在指定的角色里
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="UserId">用户主键</param>
        /// <param name="roleName">角色名称</param>
        /// <returns>在角色里</returns>
        public bool IsInRole(BaseUserInfo userInfo, string userId, string roleName)
        {
            bool result = false;

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                // 先获得角色主键
                string tableName = userInfo.SystemCode + "Role";
                var roleManager  = new BaseRoleManager(dbHelper, userInfo, tableName);
                string roleCode  = roleManager.GetProperty(new KeyValuePair <string, object>(BaseRoleEntity.FieldRealName, roleName), BaseRoleEntity.FieldCode);
                // 判断用户的默认角色
                if (!string.IsNullOrEmpty(roleCode))
                {
                    var userManager = new BaseUserManager(dbHelper, userInfo);
                    result          = userManager.IsInRoleByCode(userId, roleCode);
                }
            });
            return(result);
        }
コード例 #3
0
ファイル: RoleService.cs プロジェクト: zanderzhg/STO.Print
        /// <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, BaseRoleEntity 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.ProcessUserCenterWriteDbWithTransaction(userInfo, parameter, (dbHelper) =>
            {
                string tableName = userInfo.SystemCode + "Role";
                var manager      = new BaseRoleManager(dbHelper, userInfo, tableName);
                result           = manager.Update(entity, out returnCode);
                returnMessage    = manager.GetStateMessage(returnCode);
            });
            statusCode    = returnCode;
            statusMessage = returnMessage;

            return(result);
        }
コード例 #4
0
        /// <summary>
        /// 1:默认从只读的缓存服务器获取数据
        /// 2:若读取不到,就会到接口上获取,接口会把数据缓存到只读服务器上,为下次阅读提高性能
        /// </summary>
        /// <param name="userInfo"></param>
        /// <param name="systemCode">系统编号</param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static BaseRoleEntity GetObjectByCache(BaseUserInfo userInfo, string systemCode, string id)
        {
            BaseRoleEntity result = null;

            string key = string.Empty;

            if (!string.IsNullOrEmpty(id))
            {
                key = systemCode + ".Role." + id;
            }

            result = BaseRoleManager.GetCacheByKey(key);

            // 远程通过接口获取数据
            if (result == null)
            {
                result = GetObject(userInfo, systemCode, id);
            }

            return(result);
        }
コード例 #5
0
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <returns>数据表</returns>
        public DataTable GetDataTable(BaseUserInfo userInfo)
        {
            var dt = new DataTable(BaseRoleEntity.TableName);

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                string tableName = userInfo.SystemCode + "Role";
                // 获得角色列表
                var manager = new BaseRoleManager(dbHelper, userInfo, tableName);
                List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();
                // parameters.Add(new KeyValuePair<string, object>(BaseRoleEntity.FieldDeletionStateCode, 0));
                // parameters.Add(new KeyValuePair<string, object>(BaseRoleEntity.FieldEnabled, 1)); //如果1 只显示有效用户
                // parameters.Add(new KeyValuePair<string, object>(BaseRoleEntity.FieldIsVisible, 1));
                // dt = manager.GetDataTable(parameters, BaseRoleEntity.FieldSortCode);
                dt           = manager.GetDataTable(0, BaseRoleEntity.FieldSortCode);
                dt.TableName = BaseRoleEntity.TableName;
            });
            return(dt);
        }
コード例 #6
0
        /// <summary>
        /// 获取用户群组列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <returns>数据表</returns>
        public DataTable GetUserGroupByUser(BaseUserInfo userInfo)
        {
            var dt = new DataTable(BaseRoleEntity.CurrentTableName);

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var tableName = userInfo.SystemCode + "Role";
                // 获得角色列表
                var manager    = new BaseRoleManager(dbHelper, userInfo, tableName);
                var parameters = new List <KeyValuePair <string, object> >
                {
                    new KeyValuePair <string, object>(BaseRoleEntity.FieldCategoryCode, "UserGroup"),
                    new KeyValuePair <string, object>(BaseRoleEntity.FieldDeleted, 0),
                    new KeyValuePair <string, object>(BaseRoleEntity.FieldCreateUserId, userInfo.Id)
                };
                dt           = manager.GetDataTable(parameters, BaseRoleEntity.FieldSortCode);
                dt.TableName = tableName;
            });
            return(dt);
        }
コード例 #7
0
        /// <summary>
        /// 撤销角色权限
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="roleName">角色名</param>
        /// <param name="permissionItemCode">权限编号</param>
        /// <returns>主键</returns>
        public int RevokeRolePermission(BaseUserInfo userInfo, string roleName, string permissionItemCode)
        {
            // 加强安全验证防止未授权匿名调用
            #if (!DEBUG)
            LogOnService.UserIsLogOn(userInfo);
            #endif

            int returnValue = 0;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseRoleManager           roleManager           = new BaseRoleManager(dbHelper, userInfo);
                    string                    roleId                = roleManager.GetId(new KeyValuePair <string, object>(BaseRoleEntity.FieldRealName, roleName));
                    BasePermissionItemManager permissionItemManager = new BasePermissionItemManager(dbHelper, userInfo);
                    string                    permissionItemId      = permissionItemManager.GetId(new KeyValuePair <string, object>(BasePermissionItemEntity.FieldCode, permissionItemCode));
                    if (!String.IsNullOrEmpty(roleId) && !String.IsNullOrEmpty(permissionItemId))
                    {
                        BaseRolePermissionManager rolePermissionManager = new BaseRolePermissionManager(dbHelper, userInfo);
                        returnValue = rolePermissionManager.Revoke(roleId, permissionItemId);
                    }
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            return(returnValue);
        }
コード例 #8
0
ファイル: RoleService.cs プロジェクト: zanderzhg/STO.Print
        /// <summary>
        /// 获取业务角色列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <returns>数据表</returns>
        public DataTable GetApplicationRole(BaseUserInfo userInfo)
        {
            var dt = new DataTable(BaseRoleEntity.TableName);

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                string tableName = BaseRoleEntity.TableName;
                if (!string.IsNullOrEmpty(userInfo.SystemCode))
                {
                    tableName = userInfo.SystemCode + "Role";
                }
                // 获得角色列表
                var manager = new BaseRoleManager(dbHelper, userInfo, tableName);
                List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();
                parameters.Add(new KeyValuePair <string, object>(BaseRoleEntity.FieldCategoryCode, "ApplicationRole"));
                parameters.Add(new KeyValuePair <string, object>(BaseRoleEntity.FieldDeletionStateCode, 0));
                parameters.Add(new KeyValuePair <string, object>(BaseRoleEntity.FieldIsVisible, 1));
                dt           = manager.GetDataTable(parameters, BaseRoleEntity.FieldSortCode);
                dt.TableName = tableName;
            });
            return(dt);
        }
コード例 #9
0
ファイル: UserService.cs プロジェクト: zanderzhg/STO.Print
        private void GetUserRoles(BaseUserInfo userInfo, IDbHelper dbHelper, DataTable dt)
        {
            string[] roleIds = null;
            // 这里是获取角色列表
            string          tableName   = userInfo.SystemCode + "Role";
            BaseRoleManager roleManager = new BaseRoleManager(dbHelper, userInfo, tableName);

            if (!dt.Columns.Contains("RoleName"))
            {
                dt.Columns.Add("RoleName");
            }
            // 友善的显示属于多个角色的功能
            string roleName = string.Empty;

            foreach (DataRow dr in dt.Rows)
            {
                roleName = string.Empty;
                // 获取所在角色
                var userManager = new BaseUserManager(dbHelper, userInfo);
                roleIds = userManager.GetRoleIds(dr[BaseUserEntity.FieldId].ToString());
                if (roleIds != null && roleIds.Length > 0)
                {
                    for (int i = 0; i < roleIds.Length; i++)
                    {
                        roleName = roleName + BaseRoleManager.GetRealNameByCache(userInfo.SystemCode, roleIds[i]) + ", ";
                    }
                }
                // 设置角色的名称
                if (!string.IsNullOrEmpty(roleName))
                {
                    roleName       = roleName.Substring(0, roleName.Length - 2);
                    dr["RoleName"] = roleName;
                }
            }
            dt.AcceptChanges();
        }
コード例 #10
0
        /// <summary>
        /// 自由审批退回
        /// </summary>
        /// <param name="workFlowManager">流程控制管理器</param>
        /// <param name="workFlowAuditInfo">流程信息</param>
        /// <returns>影响行数</returns>
        public int FreeAuditReject(IWorkFlowManager workFlowManager, BaseWorkFlowAuditInfo workFlowAuditInfo)
        {
            // 返回值
            int result = 0;

            // 这里用锁的机制,提高并发控制能力
            lock (WorkFlowCurrentLock)
            {
                try
                {
                    // 开始事务
                    this.DbHelper.BeginTransaction();
                    BaseWorkFlowStepEntity workFlowStepEntity = new BaseWorkFlowStepEntity();
                    if (!string.IsNullOrEmpty(workFlowAuditInfo.ActivityId))
                    {
                        workFlowStepEntity.ActivityId       = int.Parse(workFlowAuditInfo.ActivityId);
                        workFlowStepEntity.ActivityCode     = workFlowAuditInfo.ActivityCode;
                        workFlowStepEntity.ActivityFullName = workFlowAuditInfo.ActivityFullName;
                    }
                    // 是否提交给用户审批
                    if (!string.IsNullOrEmpty(workFlowAuditInfo.ToUserId))
                    {
                        workFlowStepEntity.AuditUserId       = workFlowAuditInfo.ToUserId;
                        workFlowStepEntity.AuditUserRealName = BaseUserManager.GetRealNameByCache(workFlowAuditInfo.ToUserId);
                    }
                    // 是否提交给部门审批
                    if (!string.IsNullOrEmpty(workFlowAuditInfo.ToDepartmentId))
                    {
                        workFlowStepEntity.AuditDepartmentId   = workFlowAuditInfo.ToDepartmentId;
                        workFlowStepEntity.AuditDepartmentName = BaseOrganizeManager.GetNameByCache(workFlowAuditInfo.ToDepartmentId);
                    }
                    // 是否提交给角色审批
                    if (!string.IsNullOrEmpty(workFlowAuditInfo.ToRoleId))
                    {
                        workFlowStepEntity.AuditRoleId       = workFlowAuditInfo.ToRoleId;
                        workFlowStepEntity.AuditRoleRealName = BaseRoleManager.GetRealNameByCache(this.UserInfo.SystemCode, workFlowAuditInfo.ToRoleId);
                    }
                    // 获取排序码
                    workFlowStepEntity.SortCode = int.Parse(new BaseSequenceManager().Increment("WorkFlow", 10000000));
                    // 进行更新操作
                    result = this.StepAuditReject(workFlowAuditInfo.Id, workFlowAuditInfo.AuditIdea, workFlowStepEntity);
                    if (result == 0)
                    {
                        // 数据可能被删除
                        this.StatusCode = Status.ErrorDeleted.ToString();
                    }
                    BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetObject(workFlowAuditInfo.Id);
                    // 发送提醒信息
                    if (workFlowManager != null)
                    {
                        if (!string.IsNullOrEmpty(workFlowStepEntity.AuditUserId))
                        {
                            workFlowStepEntity.AuditDepartmentId = null;
                            workFlowStepEntity.AuditRoleId       = null;
                        }
                        workFlowManager.OnAutoAuditReject(workFlowCurrentEntity);
                        workFlowManager.SendRemindMessage(workFlowCurrentEntity, AuditStatus.AuditReject, new string[] { workFlowCurrentEntity.CreateUserId, workFlowStepEntity.AuditUserId }, workFlowStepEntity.AuditDepartmentId, workFlowStepEntity.AuditRoleId);
                    }
                    this.StatusMessage = this.GetStateMessage(this.StatusCode);
                    this.DbHelper.CommitTransaction();
                }
                catch (Exception ex)
                {
                    this.DbHelper.RollbackTransaction();
                    BaseExceptionManager.LogException(dbHelper, this.UserInfo, ex);
                    this.StatusCode = Status.Error.ToString();
                    // throw;
                }
                finally
                {
                    this.DbHelper.Close();
                }
                return(result);
            }
        }
コード例 #11
0
        /// <summary>
        /// 下个流程发送给谁
        /// </summary>
        /// <param name="id">当前主键</param>
        /// <returns>影响行数</returns>
        private int StepAuditTransmit(string currentId, string workFlowCategory, string sendToId, string auditIdea)
        {
            BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetEntity(currentId);

            // 1.记录当前的审核时间、审核人信息
            workFlowCurrentEntity.ToDepartmentId   = this.UserInfo.DepartmentId;
            workFlowCurrentEntity.ToDepartmentName = this.UserInfo.DepartmentName;
            workFlowCurrentEntity.ToUserId         = this.UserInfo.Id;
            workFlowCurrentEntity.ToUserRealName   = this.UserInfo.RealName;
            workFlowCurrentEntity.AuditStatus      = AuditStatus.Transmit.ToString();
            workFlowCurrentEntity.AuditStatusName  = AuditStatus.Transmit.ToDescription();

            // 2.记录审核日志
            this.AddHistory(workFlowCurrentEntity);

            // 3.上一个审核结束了,新的审核又开始了,更新待审核情况
            workFlowCurrentEntity.AuditUserId       = this.UserInfo.Id;
            workFlowCurrentEntity.AuditUserRealName = this.UserInfo.RealName;
            workFlowCurrentEntity.AuditDate         = DateTime.Now;
            workFlowCurrentEntity.AuditIdea         = auditIdea;

            // 是否提交给部门审批
            if (workFlowCategory.Equals("ByOrganize"))
            {
                BaseOrganizeManager organizeManager = new BaseOrganizeManager(UserInfo);
                BaseOrganizeEntity  organizeEntity  = organizeManager.GetEntity(sendToId);
                // 设置审批部门主键
                workFlowCurrentEntity.ToDepartmentId = sendToId;
                // 设置审批部门名称
                workFlowCurrentEntity.ToDepartmentName = organizeEntity.FullName;
            }
            // 是否提交给角色审批
            if (workFlowCategory.Equals("ByRole"))
            {
                BaseRoleManager roleManger = new BaseRoleManager(this.UserInfo);
                BaseRoleEntity  roleEntity = roleManger.GetEntity(sendToId);
                // 设置审批角色主键
                workFlowCurrentEntity.ToRoleId = sendToId;
                // 设置审批角色名称
                workFlowCurrentEntity.ToRoleRealName = roleEntity.RealName;
            }
            // 是否提交给用户审批
            if (workFlowCategory.Equals("ByUser"))
            {
                BaseUserManager userManager = new BaseUserManager(UserInfo);
                BaseUserEntity  userEntity  = userManager.GetEntity(sendToId);
                // 设置审批用户主键
                workFlowCurrentEntity.ToUserId = sendToId;
                // 设置审批用户名称
                workFlowCurrentEntity.ToUserRealName = userEntity.RealName;
                // TODO 用户的部门信息需要处理
                if (!string.IsNullOrEmpty(userEntity.DepartmentId))
                {
                    BaseOrganizeManager organizeManager = new BaseOrganizeManager(UserInfo);
                    BaseOrganizeEntity  organizeEntity  = organizeManager.GetEntity(userEntity.DepartmentId);
                    workFlowCurrentEntity.ToDepartmentId   = userEntity.DepartmentId;
                    workFlowCurrentEntity.ToDepartmentName = organizeEntity.FullName;
                }
            }
            workFlowCurrentEntity.AuditStatus     = AuditStatus.WaitForAudit.ToString();
            workFlowCurrentEntity.AuditStatusName = AuditStatus.WaitForAudit.ToDescription();
            // 当前审核人的信息写入当前工作流
            workFlowCurrentEntity.Enabled           = 0;
            workFlowCurrentEntity.DeletionStateCode = 0;
            return(this.UpdateEntity(workFlowCurrentEntity));
        }
コード例 #12
0
ファイル: RoleService.cs プロジェクト: zanderzhg/STO.Print
 /// <summary>
 /// 刷新列表
 /// 2015-12-11 吉日嘎拉 刷新缓存功能优化
 /// </summary>
 /// <param name="userInfo">用户</param>
 /// <returns>数据表</returns>
 public void CachePreheating(BaseUserInfo userInfo)
 {
     BaseRoleManager.CachePreheating();
 }
コード例 #13
0
        /// <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);
        }
コード例 #14
0
        /// <summary>
        /// 获取权限审核
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="startDate">开始日期</param>
        /// <param name="endDate">结束日期</param>
        /// <param name="companyId">公司主键</param>
        /// <param name="userId">用户主键</param>
        /// <param name="permissionId">权限主键</param>
        /// <param name="recordCount">记录数</param>
        /// <param name="pageNo">当前页</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 pageNo = 1, int pageSize = 20)
        {
            DataTable result = null;

            recordCount = 0;
            var myRecordCount = 0;

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var condition    = string.Empty;
                var dbParameters = new List <KeyValuePair <string, object> >();

                if (!string.IsNullOrEmpty(condition))
                {
                    condition += " AND ";
                }
                condition += BasePermissionEntity.FieldCreateTime + " >= " + DbUtil.GetParameter(BaseSystemInfo.UserCenterDbType, "startDate");
                dbParameters.Add(new KeyValuePair <string, object>("startDate", startDate));

                if (!string.IsNullOrEmpty(condition))
                {
                    condition += " AND ";
                }
                condition += BasePermissionEntity.FieldCreateTime + " <= " + DbUtil.GetParameter(BaseSystemInfo.UserCenterDbType, "endDate");
                dbParameters.Add(new KeyValuePair <string, object>("endDate", endDate));

                var tableName = BasePermissionEntity.CurrentTableName;
                if (userInfo != null)
                {
                    tableName = userInfo.SystemCode + "Permission";
                }

                myRecordCount = dbHelper.GetCount(tableName, condition, dbHelper.MakeParameters(dbParameters));
                result        = DbUtil.GetDataTableByPage(dbHelper, tableName, "*", pageNo, pageSize, condition, dbHelper.MakeParameters(dbParameters), BasePermissionEntity.FieldCreateTime + " 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)
                {
                    var id           = dr["PermissionId"].ToString();
                    var moduleEntity = new BaseModuleManager().GetEntityByCache(userInfo, id);
                    if (moduleEntity != null)
                    {
                        dr["PermissionName"] = moduleEntity.Name;
                        dr["PermissionCode"] = moduleEntity.Code;
                    }
                    if (dr["ResourceCategory"].ToString().Equals(BaseUserEntity.CurrentTableName))
                    {
                        id             = dr["ResourceId"].ToString();
                        var userEntity = BaseUserManager.GetEntityByCache(id);
                        if (userEntity != null)
                        {
                            dr["ResourceName"]         = userEntity.RealName;
                            dr["CompanyName"]          = userEntity.CompanyName;
                            dr["ResourceCategoryName"] = "用户";
                        }
                    }
                    else if (dr["ResourceCategory"].ToString().Equals(BaseOrganizationEntity.CurrentTableName))
                    {
                        id = dr["ResourceId"].ToString();
                        var organizationEntity = BaseOrganizationManager.GetEntityByCache(id);
                        if (organizationEntity != null)
                        {
                            dr["ResourceName"]         = organizationEntity.Name;
                            dr["ResourceCategoryName"] = "网点";
                        }
                    }
                    else if (dr["ResourceCategory"].ToString().Equals(BaseRoleEntity.CurrentTableName))
                    {
                        id             = dr["ResourceId"].ToString();
                        var roleEntity = BaseRoleManager.GetEntityByCache(userInfo, id);
                        if (roleEntity != null)
                        {
                            dr["ResourceName"]         = roleEntity.Name;
                            dr["ResourceCategoryName"] = "角色";
                        }
                    }
                }
            });

            recordCount = myRecordCount;
            return(result);
        }
コード例 #15
0
        /// <summary>
        /// 启动工作流(自由流转)
        /// </summary>
        /// <param name="workFlowManager"></param>
        /// <param name="activityId">丢到第几部审核哪里去了</param>
        /// <param name="objectId"></param>
        /// <param name="objectFullName"></param>
        /// <param name="categoryCode"></param>
        /// <param name="categoryFullName"></param>
        /// <param name="toUserId"></param>
        /// <param name="toDepartmentId"></param>
        /// <param name="toRoleId"></param>
        /// <param name="auditIdea"></param>
        /// <returns></returns>
        public string FreeAudit(IWorkFlowManager workFlowManager, BaseWorkFlowAuditInfo workFlowAuditInfo)
        {
            // 是否提交给用户审批
            if (!string.IsNullOrEmpty(workFlowAuditInfo.ToUserId))
            {
                workFlowAuditInfo.ToUserRealName = BaseUserManager.GetRealNameByCache(workFlowAuditInfo.ToUserId);
            }
            // 是否提交给部门审批
            if (!string.IsNullOrEmpty(workFlowAuditInfo.ToDepartmentId))
            {
                workFlowAuditInfo.ToDepartmentName = BaseOrganizeManager.GetNameByCache(workFlowAuditInfo.ToDepartmentId);
            }
            // 是否提交给角色审批
            if (!string.IsNullOrEmpty(workFlowAuditInfo.ToRoleId))
            {
                workFlowAuditInfo.ToRoleRealName = BaseRoleManager.GetRealNameByCache(this.UserInfo.SystemCode, workFlowAuditInfo.ToRoleId);
            }
            // 计算第几步审核
            if (!string.IsNullOrEmpty(workFlowAuditInfo.ActivityId))
            {
                BaseWorkFlowActivityEntity workFlowActivityEntity = new BaseWorkFlowActivityManager().GetObject(workFlowAuditInfo.ActivityId);
                workFlowAuditInfo.ProcessId        = workFlowActivityEntity.ProcessId;
                workFlowAuditInfo.ActivityCode     = workFlowActivityEntity.Code;
                workFlowAuditInfo.ActivityType     = workFlowActivityEntity.ActivityType;
                workFlowAuditInfo.ActivityFullName = workFlowActivityEntity.FullName;
                BaseWorkFlowProcessEntity workFlowProcessEntity = new BaseWorkFlowProcessManager().GetObject(workFlowActivityEntity.ProcessId.ToString());
                workFlowAuditInfo.ProcessCode   = workFlowProcessEntity.Code;
                workFlowAuditInfo.CallBackClass = workFlowProcessEntity.CallBackClass;
                workFlowAuditInfo.CallBackTable = workFlowProcessEntity.CallBackTable;
                // 若没有分类信息,分类信息可以按流程的信息保存
                if (string.IsNullOrEmpty(workFlowAuditInfo.CategoryCode))
                {
                    workFlowAuditInfo.CategoryCode     = workFlowProcessEntity.Code;
                    workFlowAuditInfo.CategoryFullName = workFlowProcessEntity.FullName;
                }

                // 不需要反复从数据库读取的方法
                workFlowManager = GetWorkFlowManager(workFlowAuditInfo);
            }

            // 获取当前工作流步骤
            BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetObjectBy(workFlowAuditInfo.CategoryCode, workFlowAuditInfo.ObjectId);

            // 已经在审批里了,那不需要重新审批,直接进入另外一个审批流程
            if (workFlowCurrentEntity != null && !string.IsNullOrEmpty(workFlowCurrentEntity.Id))
            {
                workFlowAuditInfo.Id = workFlowCurrentEntity.Id;

                // 判断现在是在什么流程节点上?
                int?sortCode = BaseWorkFlowActivityManager.GetEntity(workFlowCurrentEntity.ActivityId.ToString()).SortCode;

                // 与现在发送的流程节点比,是前进了,还是倒退了?
                // 这里是判断是退回还是前进了?排序码小的,就是在前面的步骤里,是退回了,否则是继续通过前进了
                if (BaseWorkFlowActivityManager.GetEntity(workFlowAuditInfo.ActivityId).SortCode <= sortCode)
                {
                    // 自由审批退回
                    this.FreeAuditReject(workFlowManager, workFlowAuditInfo);
                }
                else
                {
                    // 自由审批通过
                    this.FreeAuditPass(workFlowManager, workFlowAuditInfo);
                }
                return(workFlowCurrentEntity.Id);
            }

            // 提交自由审批
            this.FreeAuditStatr(workFlowAuditInfo);

            return(workFlowAuditInfo.Id);
        }
コード例 #16
0
        /// <summary>
        /// 自由审批通过
        /// </summary>
        /// <param name="workFlowManager">流程控制管理器</param>
        /// <param name="workFlowAuditInfo">流程信息</param>
        /// <returns>影响行数</returns>
        public int FreeAuditPass(IWorkFlowManager workFlowManager, BaseWorkFlowAuditInfo workFlowAuditInfo)
        {
            // 返回值
            int result = 0;

            // 这里用锁的机制,提高并发控制能力
            lock (WorkFlowCurrentLock)
            {
                try
                {
                    // 开始事务
                    this.DbHelper.BeginTransaction();

                    // 这里需要循环产生前面的没有审批的人的记录,默认都要让他们审批通过才可以?
                    // 在这里处理连续跳过好几个审批的,自动能生成审批记录的功能?
                    BaseWorkFlowCurrentEntity workFlowCurrentEntity = null;
                    workFlowCurrentEntity = this.GetObject(workFlowAuditInfo.Id);
                    // 当前是什么步骤主键?
                    int?startSortCode = BaseWorkFlowActivityManager.GetEntity(workFlowCurrentEntity.ActivityId).SortCode;
                    // 现在要到什么步骤主键?
                    int?endSortCode = BaseWorkFlowActivityManager.GetEntity(workFlowAuditInfo.ActivityId).SortCode;
                    // 中间还有几个步骤被跳过了?
                    var listEntity = BaseWorkFlowActivityManager.GetEntities().Where(entity => entity.SortCode > startSortCode && entity.SortCode <= endSortCode && entity.Enabled == 1 && entity.DeletionStateCode == 0).OrderBy(entity => entity.SortCode);
                    int i          = 0;
                    foreach (var entity in listEntity)
                    {
                        // 这里是需要自动模拟产生的审批用的
                        BaseWorkFlowAuditInfo workFlowInfo = new BaseWorkFlowAuditInfo();
                        // 是最后一步了
                        if (entity.SortCode == endSortCode)
                        {
                            workFlowInfo           = workFlowAuditInfo;
                            workFlowInfo.AuditDate = DateTime.Now.AddMinutes(i * 10);
                        }
                        else
                        {
                            workFlowInfo.Id               = workFlowAuditInfo.Id;
                            workFlowInfo.ActivityId       = entity.Id.ToString();
                            workFlowInfo.ActivityCode     = entity.Code;
                            workFlowInfo.ActivityFullName = entity.FullName;
                            // 这个是默认写入的审核意见
                            workFlowInfo.AuditIdea         = "通过";
                            workFlowInfo.AuditUserId       = entity.DefaultAuditUserId;
                            workFlowInfo.AuditUserCode     = BaseUserManager.GetUserCodeByCache(entity.DefaultAuditUserId);
                            workFlowInfo.AuditUserRealName = BaseUserManager.GetRealNameByCache(entity.DefaultAuditUserId);
                            i++;
                            // 这里是生成不一样的审核人日期的方法
                            workFlowInfo.AuditDate       = DateTime.Now.AddMinutes(i * 10);
                            workFlowInfo.AuditStatus     = AuditStatus.AuditPass.ToString();
                            workFlowInfo.AuditStatusName = AuditStatus.AuditPass.ToDescription();
                            // workFlowInfo.ToUserId = entity.DefaultAuditUserId;
                            // workFlowInfo.ToRoleId = string.Empty;
                            // workFlowInfo.ToDepartmentId = string.Empty;
                        }

                        BaseWorkFlowStepEntity workFlowStepEntity = new BaseWorkFlowStepEntity();
                        if (!string.IsNullOrEmpty(workFlowInfo.ActivityId))
                        {
                            workFlowStepEntity.ActivityId       = int.Parse(workFlowInfo.ActivityId);
                            workFlowStepEntity.ActivityCode     = workFlowInfo.ActivityCode;
                            workFlowStepEntity.ActivityFullName = workFlowInfo.ActivityFullName;
                        }
                        // 是否提交给用户审批
                        if (!string.IsNullOrEmpty(workFlowInfo.ToUserId))
                        {
                            workFlowStepEntity.AuditUserId       = workFlowInfo.ToUserId;
                            workFlowStepEntity.AuditUserCode     = BaseUserManager.GetUserCodeByCache(workFlowInfo.ToUserId);
                            workFlowStepEntity.AuditUserRealName = BaseUserManager.GetRealNameByCache(workFlowInfo.ToUserId);
                        }
                        // 是否提交给部门审批
                        if (!string.IsNullOrEmpty(workFlowInfo.ToDepartmentId))
                        {
                            workFlowStepEntity.AuditDepartmentId   = workFlowInfo.ToDepartmentId;
                            workFlowStepEntity.AuditDepartmentName = BaseOrganizeManager.GetNameByCache(workFlowInfo.ToDepartmentId);
                        }
                        // 是否提交给角色审批
                        if (!string.IsNullOrEmpty(workFlowInfo.ToRoleId))
                        {
                            workFlowStepEntity.AuditRoleId       = workFlowInfo.ToRoleId;
                            workFlowStepEntity.AuditRoleRealName = BaseRoleManager.GetRealNameByCache(this.UserInfo.SystemCode, workFlowInfo.ToRoleId);
                        }
                        // 获取排序码
                        workFlowStepEntity.SortCode = int.Parse(new BaseSequenceManager().Increment("WorkFlow", 10000000));
                        // 进行更新操作,这里有时候需要模拟别人登录
                        result = this.StepAuditPass(workFlowInfo.Id, workFlowInfo.AuditIdea, workFlowStepEntity, workFlowInfo);
                        if (result == 0)
                        {
                            // 数据可能被删除
                            this.StatusCode = Status.ErrorDeleted.ToString();
                        }
                        workFlowCurrentEntity = this.GetObject(workFlowInfo.Id);
                        // 发送提醒信息
                        if (workFlowManager != null)
                        {
                            if (!string.IsNullOrEmpty(workFlowStepEntity.AuditUserId))
                            {
                                workFlowStepEntity.AuditDepartmentId = null;
                                workFlowStepEntity.AuditRoleId       = null;
                            }
                            workFlowManager.OnAutoAuditPass(workFlowCurrentEntity);
                            workFlowManager.SendRemindMessage(workFlowCurrentEntity, AuditStatus.AuditPass, new string[] { workFlowCurrentEntity.CreateUserId, workFlowStepEntity.AuditUserId }, workFlowStepEntity.AuditDepartmentId, workFlowStepEntity.AuditRoleId);
                        }
                    }
                    this.StatusMessage = this.GetStateMessage(this.StatusCode);
                    this.DbHelper.CommitTransaction();
                }
                catch (Exception ex)
                {
                    this.DbHelper.RollbackTransaction();
                    BaseExceptionManager.LogException(dbHelper, this.UserInfo, ex);
                    this.StatusCode = Status.Error.ToString();
                    // throw;
                }
                finally
                {
                    this.DbHelper.Close();
                }

                return(result);
            }
        }