/// <summary>
        /// 添加员工
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="entity">实体</param>
        /// <param name="statusCode">返回状态码</param>
        /// <param name="statusMessage">返回消息</param>
        /// <param name="organizeId">组织机构主键</param>
        /// <returns>主鍵</returns>
        public string Add(UserInfo userInfo, PiStaffEntity entity, out string statusCode, out string statusMessage, string organizeId = "")
        {
            string returnValue   = string.Empty;
            string returnCode    = string.Empty;
            string returnMessage = string.Empty;
            var    parameter     = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.StaffService_AddStaff);

            ServiceUtil.ProcessRDIWriteDbWithTran(userInfo, parameter, dbProvider =>
            {
                var manager   = new PiStaffManager(dbProvider, userInfo);
                returnValue   = manager.Add(entity, out returnCode);
                returnMessage = manager.GetStateMessage(returnCode);

                if (returnValue.Length > 0 && returnCode == StatusCode.OKAdd.ToString() && !string.IsNullOrEmpty(organizeId.Trim()))
                {
                    var staffOrganizeEntity = new PiStaffOrganizeEntity
                    {
                        StaffId    = BusinessLogic.ConvertToString(returnValue),
                        OrganizeId = BusinessLogic.ConvertToString(organizeId),
                        Enabled    = 1,
                        DeleteMark = 0
                    };
                    var staffOrganizeManager = new PiStaffOrganizeManager(dbProvider, userInfo);
                    staffOrganizeManager.Add(staffOrganizeEntity);
                }
            });

            statusCode    = returnCode;
            statusMessage = returnMessage;
            return(returnValue);
        }
        /// <summary>
        /// 员工关联用户
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="staffId">员工主键</param>
        /// <param name="userId">用户主键</param>
        /// <returns>影响行数</returns>
        public int SetStaffUser(UserInfo userInfo, string staffId, string userId)
        {
            int returnValue = 0;
            var parameter   = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.StaffService_SetStaffUser, "员工主键:" + staffId + ",用户主键:" + userId);

            ServiceUtil.ProcessRDIWriteDbWithTran(userInfo, parameter, dbProvider =>
            {
                var staffManager = new PiStaffManager(dbProvider, userInfo);
                if (string.IsNullOrEmpty(userId))
                {
                    returnValue = staffManager.SetProperty(staffId, PiStaffTable.FieldUserId, userId);
                }
                else
                {
                    // 一个用户只能帮定到一个帐户上,检查是否已经绑定过这个用户了。
                    string[] staffIds = staffManager.GetIds(new KeyValuePair <string, object>(PiStaffTable.FieldUserId, userId), new KeyValuePair <string, object>(PiStaffTable.FieldDeleteMark, 0));
                    if (staffIds == null || staffIds.Length == 0)
                    {
                        returnValue     = staffManager.SetProperty(staffId, PiStaffTable.FieldUserId, userId);
                        var userManager = new PiUserManager(dbProvider, userInfo);
                        var userEntity  = userManager.GetEntity(userId);
                        returnValue     = staffManager.SetProperty(staffId, PiStaffTable.FieldUserName, userEntity.UserName);
                    }
                }
            });
            return(returnValue);
        }
        /// <summary>
        /// 批量打删除标志
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="ids">主键数组</param>
        /// <returns>影响行数</returns>
        public int SetDeleted(UserInfo userInfo, string[] ids)
        {
            int returnValue = 0;
            var parameter   = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.StaffService_SetDeleted);

            ServiceUtil.ProcessRDIWriteDbWithTran(userInfo, parameter, dbProvider =>
            {
                var userManager           = new PiUserManager(dbProvider, userInfo);
                var staffManager          = new PiStaffManager(dbProvider, userInfo);
                PiStaffEntity staffEntity = null;
                for (int i = 0; i < ids.Length; i++)
                {
                    // 删除相应的用户
                    staffEntity = staffManager.GetEntity(ids[i]);
                    if (staffEntity.UserId != null)
                    {
                        userManager.SetDeleted(staffEntity.UserId);
                    }
                    // 删除职员
                    returnValue += staffManager.SetDeleted(ids[i], true);
                    var staffOrganizeManager = new PiStaffOrganizeManager(dbProvider, userInfo);
                    returnValue += staffOrganizeManager.SetDeleted(new string[] { PiStaffOrganizeTable.FieldStaffId }, new string[] { ids[i] });
                }
            });

            return(returnValue);
        }
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="ids">主键数组</param>
        /// <returns>影响行数</returns>
        public int BatchDelete(UserInfo userInfo, string[] ids)
        {
            int returnValue = 0;
            var parameter   = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.StaffService_BatchDelete);

            ServiceUtil.ProcessRDIReadDb(userInfo, parameter, dbProvider =>
            {
                returnValue = new PiStaffManager(dbProvider, userInfo).BatchDelete(ids);
            });
            return(returnValue);
        }
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">主鍵</param>
        /// <returns>实体</returns>
        public PiStaffEntity GetEntity(UserInfo userInfo, string id)
        {
            PiStaffEntity entity    = null;
            var           parameter = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.StaffService_GetEntity);

            ServiceUtil.ProcessRDIReadDb(userInfo, parameter, dbProvider =>
            {
                entity = new PiStaffManager(dbProvider, userInfo).GetEntity(id);
            });
            return(entity);
        }
        /// <summary>
        /// 获取员工列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <returns>数据表</returns>
        public DataTable GetDT(UserInfo userInfo)
        {
            var dataTable = new DataTable(PiStaffTable.TableName);
            var parameter = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.StaffService_GetDT);

            ServiceUtil.ProcessRDIReadDb(userInfo, parameter, dbProvider =>
            {
                dataTable           = new PiStaffManager(dbProvider, userInfo).GetDT(PiStaffTable.FieldDeleteMark, 0, PiStaffTable.FieldSortCode);
                dataTable.TableName = PiStaffTable.TableName;
            });
            return(dataTable);
        }
        /// <summary>
        /// 获取主键
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="name">查询的参数</param>
        /// <param name="value">参数值</param>
        /// <returns>影响行数</returns>
        public string GetId(UserInfo userInfo, string name, object value)
        {
            string returnValue = string.Empty;
            var    parameter   = ParameterUtil.CreateWithLog(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessRDIReadDb(userInfo, parameter, dbProvider =>
            {
                returnValue = new PiStaffManager(dbProvider).GetId(new KeyValuePair <string, object>(name, value));
            });

            return(returnValue);
        }
        /// <summary>
        /// 获得未设置组织机构的员工列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="organizeId">组织机构主键</param>
        /// <param name="containChildren">含子部门</param>
        /// <returns>数据表</returns>
        public DataTable GetDTNotOrganize(UserInfo userInfo)
        {
            var dataTable = new DataTable(PiStaffTable.TableName);
            var parameter = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.StaffService_GetDTNotOrganize);

            ServiceUtil.ProcessRDIReadDb(userInfo, parameter, dbProvider =>
            {
                var staffManager    = new PiStaffManager(dbProvider, userInfo);
                dataTable           = staffManager.GetStaffDTNotOrganzie();
                dataTable.TableName = PiStaffTable.TableName;
            });
            return(dataTable);
        }
        /// <summary>
        /// 获得员工列表通过组织机构
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="organizeId">组织机构主键</param>
        /// <param name="containChildren">含子部门</param>
        /// <returns>数据表</returns>
        public DataTable GetDTByOrganize(UserInfo userInfo, string organizeId, bool containChildren)
        {
            var dataTable = new DataTable(PiStaffTable.TableName);
            var parameter = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.StaffService_GetDTByOrganize);

            ServiceUtil.ProcessRDIReadDb(userInfo, parameter, dbProvider =>
            {
                // 用户已经不存在的需要整理干净,防止数据不完整。
                string sqlQuery = "UPDATE PISTAFF SET USERID = NULL WHERE (USERID NOT IN (SELECT ID FROM PIUSER))";
                dbProvider.ExecuteNonQuery(sqlQuery);
                var staffManager    = new PiStaffManager(dbProvider, userInfo);
                dataTable           = containChildren ? staffManager.GetChildrenStaffs(organizeId) : staffManager.GetDTByOrganize(organizeId);
                dataTable.TableName = PiStaffTable.TableName;
            });
            return(dataTable);
        }
        /// <summary>
        /// 更新员工
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="entity">实体</param>
        /// <param name="statusCode">返回状态码</param>
        /// <param name="statusMessage">返回状态信息</param>
        /// <returns>影响行数</returns>
        public int UpdateStaff(UserInfo userInfo, PiStaffEntity entity, out string statusCode, out string statusMessage)
        {
            int    returnValue   = 0;
            string returnCode    = string.Empty;
            string returnMessage = string.Empty;
            var    parameter     = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.StaffService_UpdateStaff);

            ServiceUtil.ProcessRDIReadDb(userInfo, parameter, dbProvider =>
            {
                var manager   = new PiStaffManager(dbProvider, userInfo);
                returnValue   = manager.Update(entity, out returnCode);
                returnMessage = manager.GetStateMessage(returnCode);
            });
            statusCode    = returnCode;
            statusMessage = returnMessage;
            return(returnValue);
        }
Exemple #11
0
        /// <summary>
        /// 扮演用户
        /// </summary>
        /// <param name="id">用户主键</param>
        /// <returns>用户类</returns>
        public UserInfo Impersonation(string id, out string statusCode)
        {
            UserInfo userInfo = null;
            // 获得登录信息
            PiUserLogOnEntity entity = new PiUserLogOnManager(this.DBProvider, this.UserInfo).GetEntity(id);

            // 只允许登录一次,需要检查是否自己重新登录了,或者自己扮演自己了
            if (!UserInfo.Id.Equals(id))
            {
                if (SystemInfo.CheckOnLine)
                {
                    if (entity.UserOnLine > 0)
                    {
                        statusCode = StatusCode.ErrorOnLine.ToString();
                        return(userInfo);
                    }
                }
            }

            PiUserEntity userEntity = this.GetEntity(id);

            userInfo = this.ConvertToUserInfo(userEntity);
            if (userEntity.IsStaff.Equals("1"))
            {
                // 获得员工的信息
                PiStaffEntity  staffEntity    = new PiStaffEntity();
                PiStaffManager staffManager   = new PiStaffManager(DBProvider, UserInfo);
                DataTable      dataTableStaff = staffManager.GetDTById(id);
                staffEntity.GetFrom(dataTableStaff);
                userInfo = staffManager.ConvertToUserInfo(staffEntity, userInfo);
            }
            statusCode = StatusCode.OK.ToString();
            // 登录、重新登录、扮演时的在线状态进行更新
            PiUserLogOnManager userLogOnManager = new PiUserLogOnManager(this.DBProvider, this.UserInfo);

            userLogOnManager.ChangeOnLine(id);
            return(userInfo);
        }
        /// <summary>
        /// 获取员工分页列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="recordCount">所有员工数</param>
        /// <param name="pageIndex">当前页</param>
        /// <param name="pageSize">分页大小(默认20条)</param>
        /// <param name="whereConditional">条件表达式</param>
        /// <param name="order">排序字段</param>
        /// <returns>数据表</returns>
        public DataTable GetDTByPage(UserInfo userInfo, out int recordCount, int pageIndex = 1, int pageSize = 20, string whereConditional = "", string order = "")
        {
            var dataTable         = new DataTable(PiStaffTable.TableName);
            var returnRecordCount = 0;
            var parameter         = ParameterUtil.CreateWithLog(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessRDIReadDb(userInfo, parameter, dbProvider =>
            {
                var manager = new PiStaffManager(dbProvider, userInfo);
                if (string.IsNullOrEmpty(whereConditional))
                {
                    whereConditional = PiStaffTable.FieldDeleteMark + " = 0 ";
                }
                else
                {
                    whereConditional += " AND " + PiStaffTable.FieldDeleteMark + " = 0 ";
                }

                dataTable           = manager.GetDTByPage(out returnRecordCount, pageIndex, pageSize, whereConditional, order);
                dataTable.TableName = PiStaffTable.TableName;
            });
            recordCount = returnRecordCount;
            return(dataTable);
        }