/// <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="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="id">员工主键</param>
        /// <param name="organizeId">组织机构主键</param>
        /// <returns>影响行数</returns>
        public int MoveTo(UserInfo userInfo, string id, string organizeId)
        {
            int returnValue = 0;
            var parameter   = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.StaffService_MoveTo, "员工主键:" + id + ",组织机构主键:" + organizeId);

            ServiceUtil.ProcessRDIReadDb(userInfo, parameter, dbProvider =>
            {
                returnValue = new PiStaffOrganizeManager(dbProvider, userInfo).SetProperty(PiStaffOrganizeTable.FieldStaffId, id, PiStaffOrganizeTable.FieldOrganizeId, organizeId);
            });

            return(returnValue);
        }
        /// <summary>
        /// 批量移动员工到指定组织机构
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="ids">员工主键数组</param>
        /// <param name="organizeId">组织机构主键</param>
        /// <returns>影响行数</returns>
        public int BatchMoveTo(UserInfo userInfo, string[] ids, string organizeId)
        {
            int returnValue = 0;
            var parameter   = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.StaffService_BatchMoveTo);

            ServiceUtil.ProcessRDIWriteDbWithTran(userInfo, parameter, dbProvider =>
            {
                var manager  = new PiStaffOrganizeManager(dbProvider, userInfo);
                returnValue += ids.Sum(t => manager.SetProperty(PiStaffOrganizeTable.FieldStaffId, t, PiStaffOrganizeTable.FieldOrganizeId, organizeId));
            });

            return(returnValue);
        }
        /// <summary>
        /// 删除标志
        ///
        /// 删除员工时,需要把用户也给删除掉
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>影响行数</returns>
        public int SetDeleted(string id)
        {
            int returnValue = 0;
            // 先把用户设置为删除标记
            string userId = this.GetProperty(id, PiStaffTable.FieldUserId);

            if (!String.IsNullOrEmpty(userId))
            {
                PiUserManager userManager = new PiUserManager(DBProvider, UserInfo);
                returnValue += userManager.SetDeleted(userId);
            }

            PiStaffOrganizeManager staffOrganizeManager = new PiStaffOrganizeManager(DBProvider, UserInfo);

            returnValue += staffOrganizeManager.SetProperty(PiStaffOrganizeTable.FieldStaffId, id, BusinessLogic.FieldDeleteMark, "1");

            // 再把员工设置为删除标记
            returnValue += this.SetProperty(BusinessLogic.FieldId, id, BusinessLogic.FieldDeleteMark, "1");

            return(returnValue);
        }
Exemple #6
0
        /// <summary>
        /// 批量置删除标志
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="ids">主键数组</param>
        /// <returns>影响的行数</returns>
        public int SetDeleted(UserInfo userInfo, string[] ids)
        {
            int returnValue = 0;

            if (ids == null || ids.Length <= 0)
            {
                return(returnValue);
            }

            var parameter = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.OrganizeService_SetDeleted);

            ServiceUtil.ProcessRDIWriteDbWithTran(userInfo, parameter, dbProvider =>
            {
                var manager = new PiOrganizeManager(dbProvider, userInfo);
                for (int pos = 0; pos < ids.Length; pos++)
                {
                    //逻辑删除组织机构
                    returnValue += manager.SetDeleted(ids[pos]);
                    //同步处理用户表组织机构相关数据
                    var userManager = new PiUserManager(dbProvider, userInfo);
                    var parameters  = new List <KeyValuePair <string, object> >
                    {
                        new KeyValuePair <string, object>(PiUserTable.FieldCompanyId, null),
                        new KeyValuePair <string, object>(PiUserTable.FieldCompanyName, null)
                    };
                    userManager.SetProperty(new KeyValuePair <string, object>(PiUserTable.FieldCompanyId, ids[pos]), parameters);
                    parameters = new List <KeyValuePair <string, object> >
                    {
                        new KeyValuePair <string, object>(PiUserTable.FieldSubCompanyId, null),
                        new KeyValuePair <string, object>(PiUserTable.FieldSubCompanyName, null)
                    };
                    userManager.SetProperty(new KeyValuePair <string, object>(PiUserTable.FieldSubCompanyId, ids[pos]), parameters);
                    parameters = new List <KeyValuePair <string, object> >
                    {
                        new KeyValuePair <string, object>(PiUserTable.FieldDepartmentId, null),
                        new KeyValuePair <string, object>(PiUserTable.FieldDepartmentName, null)
                    };
                    userManager.SetProperty(new KeyValuePair <string, object>(PiUserTable.FieldDepartmentId, ids[pos]), parameters);
                    parameters = new List <KeyValuePair <string, object> >
                    {
                        new KeyValuePair <string, object>(PiUserTable.FieldSubDepartmentId, null),
                        new KeyValuePair <string, object>(PiUserTable.FieldSubDepartmentName, null)
                    };
                    userManager.SetProperty(new KeyValuePair <string, object>(PiUserTable.FieldSubDepartmentId, ids[pos]), parameters);
                    parameters = new List <KeyValuePair <string, object> >
                    {
                        new KeyValuePair <string, object>(PiUserTable.FieldWorkgroupId, null),
                        new KeyValuePair <string, object>(PiUserTable.FieldWorkgroupName, null)
                    };
                    userManager.SetProperty(new KeyValuePair <string, object>(PiUserTable.FieldWorkgroupId, ids[pos]), parameters);
                    //同步处理员工表组织机构相关数据
                    var staffOrganizeManager = new PiStaffOrganizeManager(dbProvider, userInfo);
                    parameters = new List <KeyValuePair <string, object> >
                    {
                        new KeyValuePair <string, object>(PiStaffOrganizeTable.FieldOrganizeId, ids[pos])
                    };
                    staffOrganizeManager.SetDeleted(parameters, true);
                }
            });
            return(returnValue);
        }