Пример #1
0
 /// <summary>
 /// 员工操作完成
 /// </summary>
 /// <param name="operateType">操作类型</param>
 /// <param name="t">员工对象</param>
 /// <param name="result">操作结果</param>
 /// <param name="currUser">当前用户</param>
 /// <param name="otherParams"></param>
 public void OperateCompeletedHandle(ModelRecordOperateType operateType, OrgM_Emp t, bool result, UserInfo currUser, object[] otherParams = null)
 {
     if (result)
     {
         string errMsg   = string.Empty;
         string username = OrgMOperate.GetUserNameByEmp(t);
         if (operateType == ModelRecordOperateType.Add)
         {
             if (!string.IsNullOrEmpty(username))
             {
                 UserOperate.AddUser(out errMsg, username, string.Format("{0}_123456", username), null, t.Name);
             }
         }
         else if (operateType == ModelRecordOperateType.Edit)
         {
             if (!string.IsNullOrEmpty(username))
             {
                 UserOperate.UpdateUserAliasName(username, t.Name);
             }
         }
         else if (operateType == ModelRecordOperateType.Del)
         {
             if (!string.IsNullOrEmpty(username))
             {
                 UserOperate.DelUser(username); //删除账号
             }
         }
     }
 }
Пример #2
0
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="user">用户对象</param>
        /// <returns></returns>
        private static UserInfo GetUserInfo(Sys_User user)
        {
            if (user == null || string.IsNullOrEmpty(user.UserName))
            {
                return(null);
            }
            UserInfo userInfo = new UserInfo()
            {
                UserId         = user.Id,
                UserName       = user.UserName,
                AliasName      = string.IsNullOrEmpty(user.AliasName) ? user.UserName : user.AliasName,
                OrganizationId = user.Sys_OrganizationId
            };
            //员工信息
            OrgM_Emp emp = OrgMOperate.GetEmpByUserName(user.UserName);

            if (emp != null)
            {
                userInfo.EmpId   = emp.Id;
                userInfo.EmpCode = emp.Code;
                userInfo.EmpName = emp.Name;
            }
            userInfo.ExtendUserObject = UserExtendEventHandler.GetUserExtendInfo(userInfo);
            return(userInfo);
        }
Пример #3
0
 /// <summary>
 /// 操作完成后
 /// </summary>
 /// <param name="operateType"></param>
 /// <param name="t"></param>
 /// <param name="result"></param>
 /// <param name="currUser"></param>
 /// <param name="otherParams"></param>
 public void OperateCompeletedHandle(ModelRecordOperateType operateType, OrgM_EmpDeptDuty t, bool result, UserInfo currUser, object[] otherParams = null)
 {
     if (result)
     {
         string errMsg = string.Empty;
         if (operateType == ModelRecordOperateType.Add || operateType == ModelRecordOperateType.Edit)
         {
             if (t.OrgM_EmpId.HasValue && t.OrgM_EmpId.Value != Guid.Empty && t.OrgM_DeptId.HasValue && t.OrgM_DeptId.Value != Guid.Empty)
             {
                 OrgM_Dept dept     = OrgMOperate.GetDeptById(t.OrgM_DeptId.Value);
                 string    username = OrgMOperate.GetUserNameByEmpId(t.OrgM_EmpId.Value);
                 if (!string.IsNullOrEmpty(username) && dept != null)
                 {
                     Sys_User         user = UserOperate.GetUser(username);
                     Sys_Organization org  = UserOperate.GetAllOrgs(x => x.Name == dept.Name && x.Flag == dept.Id.ToString()).FirstOrDefault();
                     if (user != null && org != null && user.Sys_OrganizationId != org.Id)
                     {
                         user.Sys_OrganizationId = org.Id;
                         CommonOperate.OperateRecord <Sys_User>(user, ModelRecordOperateType.Edit, out errMsg, new List <string>()
                         {
                             "Sys_OrganizationId"
                         }, false);
                     }
                 }
             }
         }
     }
 }
Пример #4
0
 /// <summary>
 /// 网格数据处理
 /// </summary>
 /// <param name="data">数据</param>
 /// <param name="otherParams">其他参数</param>
 /// <param name="currUser">当前用户</param>
 public bool PageGridDataHandle(List <OrgM_Emp> data, object[] otherParams = null, UserInfo currUser = null)
 {
     if (data != null && data.Count > 0)
     {
         foreach (OrgM_Emp t in data)
         {
             OrgM_EmpDeptDuty empPosition = OrgMOperate.GetEmpMainPosition(t.Id);
             if (empPosition != null)
             {
                 if (empPosition.OrgM_DeptId.HasValue && empPosition.OrgM_DeptId.Value != Guid.Empty &&
                     empPosition.OrgM_DutyId.HasValue && empPosition.OrgM_DutyId.Value != Guid.Empty)
                 {
                     OrgM_Dept dept = OrgMOperate.GetDeptById(empPosition.OrgM_DeptId.Value);
                     if (dept != null)
                     {
                         t.DeptId   = dept.Id;
                         t.DeptName = string.IsNullOrEmpty(dept.Alias) ? dept.Name : dept.Alias;
                     }
                     OrgM_Duty duty = OrgMOperate.GetDuty(empPosition.OrgM_DutyId.Value);
                     if (duty != null)
                     {
                         t.DutyId   = duty.Id;
                         t.DutyName = duty.Name;
                     }
                 }
             }
         }
     }
     return(false);
 }
Пример #5
0
 /// <summary>
 /// 表单数据处理
 /// </summary>
 /// <param name="t">对象</param>
 /// <param name="formType">表单类型</param>
 /// <param name="currUser">当前用户</param>
 public void FormDataHandle(OrgM_Emp t, FormTypeEnum formType, UserInfo currUser = null)
 {
     if (t != null)
     {
         OrgM_EmpDeptDuty empPosition = OrgMOperate.GetEmpMainPosition(t.Id);
         if (empPosition != null)
         {
             if (empPosition.OrgM_DeptId.HasValue && empPosition.OrgM_DeptId.Value != Guid.Empty &&
                 empPosition.OrgM_DutyId.HasValue && empPosition.OrgM_DutyId.Value != Guid.Empty)
             {
                 OrgM_Dept dept = OrgMOperate.GetDeptById(empPosition.OrgM_DeptId.Value);
                 if (dept != null)
                 {
                     t.DeptId   = dept.Id;
                     t.DeptName = string.IsNullOrEmpty(dept.Alias) ? dept.Name : dept.Alias;
                 }
                 OrgM_Duty duty = OrgMOperate.GetDuty(empPosition.OrgM_DutyId.Value);
                 if (duty != null)
                 {
                     t.DutyId   = duty.Id;
                     t.DutyName = duty.Name;
                 }
             }
         }
     }
 }
        /// <summary>
        /// 获取员工的层级部门信息
        /// </summary>
        /// <returns></returns>
        public JsonResult GetEmpLevelDepthDept()
        {
            if (_Request == null)
            {
                _Request = Request;
            }
            SetRequest(_Request);
            string levelDepthStr = _Request.QueryEx("levelDepth").ObjToStr();
            int    levelDepth    = levelDepthStr.ObjToInt();     //层级
            string empIdStr      = _Request.QueryEx("empId").ObjToStr();
            Guid   empId         = empIdStr.ObjToGuid();         //员工ID
            string companyIdStr  = _Request.QueryEx("companyId").ObjToStr();
            Guid?  companyId     = companyIdStr.ObjToGuidNull(); //所属公司,集团模式下用到
            string deptIdStr     = _Request.QueryEx("deptId").ObjToStr();
            Guid?  deptId        = deptIdStr.ObjToGuidNull();    //兼职部门,以兼职部门找

            if (empId == Guid.Empty || levelDepth < 0)
            {
                return(Json(null));
            }
            //层级部门
            OrgM_Dept depthDept = OrgMOperate.GetEmpLevelDepthDept(levelDepth, empId, companyId, deptId);
            //当前部门
            OrgM_Dept currDept = deptId.HasValue && deptId.Value != Guid.Empty ? OrgMOperate.GetDeptById(deptId.Value) : OrgMOperate.GetEmpMainDept(empId, companyId);

            return(Json(new { CurrDept = currDept, DepthDept = depthDept }));
        }
 /// <summary>
 /// 部门操作完成
 /// </summary>
 /// <param name="operateType"></param>
 /// <param name="t"></param>
 /// <param name="result"></param>
 /// <param name="currUser"></param>
 /// <param name="otherParams"></param>
 public void OperateCompeletedHandle(ModelRecordOperateType operateType, OrgM_Dept t, bool result, UserInfo currUser, object[] otherParams = null)
 {
     if (result)
     {
         string errMsg   = string.Empty;
         Guid?  parentId = null;
         if (t.ParentId.HasValue && t.ParentId.Value != Guid.Empty)
         {
             OrgM_Dept parentDept = OrgMOperate.GetParentDept(t.ParentId.Value);
             if (parentDept != null && !string.IsNullOrEmpty(parentDept.Name))
             {
                 Sys_Organization parentOrg = CommonOperate.GetEntity <Sys_Organization>(x => x.Name == parentDept.Name && x.Flag == parentDept.Id.ToString() && !x.IsDeleted, null, out errMsg);
                 if (parentOrg != null)
                 {
                     parentId = parentOrg.Id;
                 }
             }
         }
         //部门新增后增加到系统组织中
         if (operateType == ModelRecordOperateType.Add)
         {
             Sys_Organization org = new Sys_Organization()
             {
                 Name           = t.Name,
                 ParentId       = parentId,
                 Flag           = t.Id.ToString(),
                 Des            = t.Alias,
                 CreateUserId   = t.CreateUserId,
                 CreateUserName = t.CreateUserName,
                 ModifyUserId   = t.ModifyUserId,
                 ModifyUserName = t.ModifyUserName
             };
             CommonOperate.OperateRecord <Sys_Organization>(org, ModelRecordOperateType.Add, out errMsg, null, false);
         }
         else if (operateType == ModelRecordOperateType.Edit)
         {
             Sys_Organization org = CommonOperate.GetEntity <Sys_Organization>(x => x.Name == t.Name && x.Flag == t.Id.ToString() && !x.IsDeleted, null, out errMsg);
             if (org != null)
             {
                 org.ParentId       = parentId;
                 org.ModifyDate     = DateTime.Now;
                 org.ModifyUserId   = t.ModifyUserId;
                 org.ModifyUserName = t.ModifyUserName;
                 List <string> fileNames = new List <string>()
                 {
                     "ParentId", "ModifyDate", "ModifyUserId", "ModifyUserName"
                 };
                 CommonOperate.OperateRecord <Sys_Organization>(org, ModelRecordOperateType.Edit, out errMsg, fileNames, false);
             }
         }
     }
 }
        public ActionResult GetDeptDutys()
        {
            if (_Request == null)
            {
                _Request = Request;
            }
            SetRequest(_Request);
            Guid             deptId = _Request["deptId"].ObjToGuid();
            List <OrgM_Duty> dutys  = OrgMOperate.GetDeptDutys(deptId);

            dutys.Insert(0, new OrgM_Duty()
            {
                Id = Guid.Empty, Name = "请选择"
            });
            return(Json(dutys, JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetDeptDutys()
        {
            if (_Request == null)
            {
                _Request = Request;
            }
            SetRequest(_Request);
            Guid             deptId = _Request.QueryEx("deptId").ObjToGuid();
            List <OrgM_Duty> dutys  = OrgMOperate.GetDeptDutys(deptId);

            dutys.Insert(0, new OrgM_Duty()
            {
                Id = Guid.Empty, Name = "请选择"
            });
            return(Json(dutys));
        }
Пример #10
0
 /// <summary>
 /// 网格条件过滤
 /// </summary>
 /// <param name="where">where</param>
 /// <param name="gridType">网格类型</param>
 /// <param name="condition">条件</param>
 /// <param name="initModule">原始模块,针对表单弹出框</param>
 /// <param name="initField">原始字段,针对表单弹出框</param>
 /// <param name="otherParams">其他参数</param>
 /// <param name="currUser">当前用户</param>
 /// <returns></returns>
 public Expression <Func <OrgM_Emp, bool> > GetGridFilterCondition(out string where, DataGridType gridType, Dictionary <string, string> condition = null, string initModule = null, string initField = null, Dictionary <string, string> otherParams = null, UserInfo currUser = null)
 {
     where = string.Empty;
     if (condition != null && condition.ContainsKey("OrgM_DeptId"))
     {
         OrgM_Dept root   = OrgMOperate.GetDeptRoot();
         Guid      deptId = condition["OrgM_DeptId"].ObjToGuid();
         if (deptId != root.Id)
         {
             List <Guid> childDeptIds = OrgMOperate.GetChildDepts(deptId).Select(x => x.Id).ToList();
             childDeptIds.Add(deptId);
             string deptIdStr = string.Join("','", childDeptIds);
             where = string.Format("Id IN(SELECT OrgM_EmpId FROM dbo.OrgM_EmpDeptDuty WHERE OrgM_DeptId IN('{0}'))", deptIdStr);
             condition.Remove("OrgM_DeptId");
         }
     }
     return(null);
 }
        /// <summary>
        /// 获取员工的层级部门信息
        /// </summary>
        /// <returns></returns>
        public ActionResult GetEmpLevelDepthDept()
        {
            if (_Request == null)
            {
                _Request = Request;
            }
            SetRequest(_Request);
            int  levelDepth = _Request["levelDepth"].ObjToInt();     //层级
            Guid empId      = _Request["empId"].ObjToGuid();         //员工ID
            Guid?companyId  = _Request["companyId"].ObjToGuidNull(); //所属公司,集团模式下用到
            Guid?deptId     = _Request["deptId"].ObjToGuidNull();    //兼职部门,以兼职部门找

            if (empId == Guid.Empty || levelDepth < 0)
            {
                return(Json(null));
            }
            //层级部门
            OrgM_Dept depthDept = OrgMOperate.GetEmpLevelDepthDept(levelDepth, empId, companyId, deptId);
            //当前部门
            OrgM_Dept currDept = deptId.HasValue && deptId.Value != Guid.Empty ? OrgMOperate.GetDeptById(deptId.Value) : OrgMOperate.GetEmpMainDept(empId, companyId);

            return(Json(new { CurrDept = currDept, DepthDept = depthDept }));
        }
Пример #12
0
        /// <summary>
        /// 获取超级管理员用户信息
        /// </summary>
        /// <returns></returns>
        public static UserInfo GetSuperAdmin()
        {
            if (_adminUser != null)
            {
                return(_adminUser);
            }
            string   errMsg = string.Empty;
            Sys_User user   = CommonOperate.GetEntity <Sys_User>(x => x.UserName == "admin", null, out errMsg);

            if (user == null)
            {
                user = new Sys_User()
                {
                    Id = Guid.Empty, UserName = null, AliasName = null
                }
            }
            ;
            UserInfo userInfo = new UserInfo()
            {
                UserId    = user.Id,
                UserName  = user.UserName,
                AliasName = string.IsNullOrEmpty(user.AliasName) ? user.UserName : user.AliasName,
                EmpId     = Guid.Empty,
                EmpName   = "系统管理员"
            };
            OrgM_Emp emp = OrgMOperate.GetEmpByUserName(user.UserName);

            if (emp != null)
            {
                userInfo.EmpId   = emp.Id;
                userInfo.EmpCode = emp.Code;
                userInfo.EmpName = emp.Name;
            }
            _adminUser = userInfo;
            return(_adminUser);
        }
Пример #13
0
 /// <summary>
 /// 网格数据处理
 /// </summary>
 /// <param name="data"></param>
 /// <param name="otherParams"></param>
 /// <param name="currUser"></param>
 public bool PageGridDataHandle(List <Bpm_WorkToDoList> data, object[] otherParams = null, UserInfo currUser = null)
 {
     if (data != null && data.Count > 0)
     {
         string errMsg = string.Empty;
         foreach (Bpm_WorkToDoList todo in data)
         {
             todo.ModuleName = SystemOperate.GetModuleNameById(todo.ModuleId);
             if (!todo.Bpm_WorkFlowInstanceId.HasValue)
             {
                 continue;
             }
             Bpm_WorkFlowInstance flowInst = BpmOperate.GetWorkflowInstanceById(todo.Bpm_WorkFlowInstanceId.Value);
             if (flowInst == null)
             {
                 continue;
             }
             todo.StatusOfEnum = flowInst.StatusOfEnum;
             int status = (int)flowInst.StatusOfEnum;
             Bpm_WorkToDoList tempTodo = CommonOperate.GetEntity <Bpm_WorkToDoList>(x => x.Bpm_WorkFlowInstanceId == todo.Bpm_WorkFlowInstanceId.Value && x.Status == status, null, out errMsg);
             if (tempTodo != null && !string.IsNullOrEmpty(todo.NextNodeHandler))
             {
                 List <Guid> tempEmpIds = tempTodo.NextNodeHandler.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(x => x.ObjToGuid()).Where(x => x != Guid.Empty).ToList();
                 if (tempEmpIds.Count > 0)
                 {
                     todo.OrgM_EmpName = string.Join(",", tempEmpIds.Select(x => OrgMOperate.GetEmpNameContainsQuit(x)).Where(x => !string.IsNullOrEmpty(x)));
                 }
             }
         }
     }
     return(false);
 }
        public JsonResult UserForgetPwd(string username)
        {
            string userTipDes = "用户名";

            if (GlobalSet.EmpUserNameConfigRule == UserNameAndEmpConfigRule.Email)
            {
                userTipDes = "邮箱";
            }
            else if (GlobalSet.EmpUserNameConfigRule == UserNameAndEmpConfigRule.Mobile)
            {
                userTipDes = "手机号";
            }
            if (string.IsNullOrEmpty(username))
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = string.Format("{0}不能为空!", userTipDes)
                }));
            }
            if (GlobalSet.EmpUserNameConfigRule == UserNameAndEmpConfigRule.Email && !Validator.IsEmail(username))
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = "请输入正确的邮箱地址!"
                }));
            }
            if (GlobalSet.EmpUserNameConfigRule == UserNameAndEmpConfigRule.Mobile && !Validator.IsMobilePhoneNumber(username))
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = "请输入正确的手机号码!"
                }));
            }
            string errMsg = string.Empty;
            bool   rs     = UserOperate.UserIsValid(username, out errMsg);

            if (!rs)
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = errMsg
                }));
            }
            string email = username;

            if (GlobalSet.EmpUserNameConfigRule != UserNameAndEmpConfigRule.Email)
            {
                OrgM_Emp emp = OrgMOperate.GetEmpByUserName(username);
                if (emp != null)
                {
                    email = OrgMOperate.GetEmployeeEmails(new List <Guid>()
                    {
                        emp.Id
                    }).Keys.FirstOrDefault();
                }
            }
            if (!email.Contains("@"))
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = "获取用户邮箱失败!"
                }));
            }
            Dictionary <string, string> dicMail = new Dictionary <string, string>();

            dicMail.Add(email, email);
            string   subject = string.Format("重置您在{0}的密码", WebConfigHelper.GetCurrWebName());
            Sys_User user    = UserOperate.GetUser(username);
            string   content = GetForgetPwdSendContent(user);

            errMsg = SystemOperate.EmailSend(subject, content, dicMail, null, null, null, true);
            return(Json(new ReturnResult()
            {
                Success = string.IsNullOrEmpty(errMsg), Message = errMsg
            }));
        }
        /// <summary>
        /// 获取用户名
        /// </summary>
        /// <param name="username">用户名或工号或邮箱或手机号</param>
        /// <returns></returns>
        private string GetUserName(string username)
        {
            string tempUserName = username.Trim();
            string errMsg       = string.Empty;

            if (GlobalSet.IsAllowOtherConfigRuleLogin) //允许其他方式登录
            {
                //先检测默认登录规则账号是否存在
                bool rs = UserOperate.UserIsValid(tempUserName, out errMsg);
                if (rs)
                {
                    return(tempUserName);
                }
                //默认登录规则账号不存在时检测其他方式
                OrgM_Emp emp = null;
                switch (GlobalSet.EmpUserNameConfigRule)
                {
                case UserNameAndEmpConfigRule.EmpCode:
                {
                    emp = OrgMOperate.GetEmpByMobile(tempUserName);         //根据手机号获取员工
                    if (emp == null)
                    {
                        emp = OrgMOperate.GetEmpByEmail(tempUserName);         //根据邮箱获取员工
                        if (emp == null)
                        {
                            emp = OrgMOperate.GetEmpByEmailPrex(tempUserName);         //根据邮箱前缀获取员工
                        }
                    }
                }
                break;

                case UserNameAndEmpConfigRule.Mobile:
                {
                    emp = OrgMOperate.GetEmpByCode(tempUserName);         //根据工号获取员工
                    if (emp == null)
                    {
                        emp = OrgMOperate.GetEmpByEmail(tempUserName);         //根据邮箱获取员工
                        if (emp == null)
                        {
                            emp = OrgMOperate.GetEmpByEmailPrex(tempUserName);         //根据邮箱前缀获取员工
                        }
                    }
                }
                break;

                case UserNameAndEmpConfigRule.Email:
                {
                    emp = OrgMOperate.GetEmpByCode(tempUserName);         //根据工号获取员工
                    if (emp == null)
                    {
                        emp = OrgMOperate.GetEmpByMobile(tempUserName);         //根据手机号获取员工
                        if (emp == null)
                        {
                            emp = OrgMOperate.GetEmpByEmailPrex(tempUserName);         //根据邮箱前缀获取员工
                        }
                    }
                }
                break;

                case UserNameAndEmpConfigRule.EmailPre:
                {
                    emp = OrgMOperate.GetEmpByCode(tempUserName);         //根据工号获取员工
                    if (emp == null)
                    {
                        emp = OrgMOperate.GetEmpByMobile(tempUserName);         //根据手机号获取员工
                        if (emp == null)
                        {
                            emp = OrgMOperate.GetEmpByEmail(tempUserName);         //根据邮箱获取员工
                        }
                    }
                }
                break;
                }
                if (emp != null)
                {
                    return(OrgMOperate.GetUserNameByEmp(emp));
                }
            }
            return(tempUserName);
        }
Пример #16
0
 /// <summary>
 /// 员工操作完成
 /// </summary>
 /// <param name="operateType">操作类型</param>
 /// <param name="t">员工对象</param>
 /// <param name="result">操作结果</param>
 /// <param name="currUser">当前用户</param>
 /// <param name="otherParams"></param>
 public void OperateCompeletedHandle(ModelRecordOperateType operateType, OrgM_Emp t, bool result, UserInfo currUser, object[] otherParams = null)
 {
     if (result)
     {
         string errMsg      = string.Empty;
         string username    = OrgMOperate.GetUserNameByEmp(t);
         string userInitPwd = WebConfigHelper.GetAppSettingValue("UserInitPwd");
         if (string.IsNullOrEmpty(userInitPwd))
         {
             userInitPwd = "123456";
         }
         if (operateType == ModelRecordOperateType.Add)
         {
             if (!string.IsNullOrEmpty(username))
             {
                 UserOperate.AddUser(out errMsg, username, userInitPwd, null, t.Name);
             }
         }
         else if (operateType == ModelRecordOperateType.Edit)
         {
             if (!string.IsNullOrEmpty(username))
             {
                 Sys_User user = UserOperate.GetUser(username);
                 if (user != null) //用户已存在
                 {
                     UserOperate.UpdateUserAliasName(username, t.Name);
                 }
                 else //用户不存在
                 {
                     UserOperate.AddUser(out errMsg, username, userInitPwd, null, t.Name);
                 }
             }
         }
         else if (operateType == ModelRecordOperateType.Del)
         {
             if (!string.IsNullOrEmpty(username))
             {
                 UserOperate.DelUser(username); //删除账号
             }
             //删除员工同时删除员工岗位
             CommonOperate.DeleteRecordsByExpression <OrgM_EmpDeptDuty>(x => x.OrgM_EmpId == t.Id, out errMsg, t.IsDeleted);
         }
         if (operateType == ModelRecordOperateType.Add || operateType == ModelRecordOperateType.Edit)
         {
             //新增编辑时同时设置员工主职岗位
             if (t.DeptId.HasValue && t.DeptId.Value != Guid.Empty && t.DutyId.HasValue && t.DutyId.Value != Guid.Empty)
             {
                 OrgM_EmpDeptDuty empPosition = null;
                 if (operateType == ModelRecordOperateType.Edit)
                 {
                     empPosition = CommonOperate.GetEntity <OrgM_EmpDeptDuty>(x => x.OrgM_EmpId == t.Id && x.IsMainDuty == true, null, out errMsg);
                     if (empPosition != null)
                     {
                         empPosition.OrgM_DeptId    = t.DeptId.Value;
                         empPosition.OrgM_DutyId    = t.DutyId.Value;
                         empPosition.IsValid        = true;
                         empPosition.ModifyDate     = DateTime.Now;
                         empPosition.ModifyUserId   = currUser.UserId;
                         empPosition.ModifyUserName = currUser.EmpName;
                         CommonOperate.OperateRecord <OrgM_EmpDeptDuty>(empPosition, ModelRecordOperateType.Edit, out errMsg, null, false);
                         return;
                     }
                 }
                 Guid   moduleId = SystemOperate.GetModuleIdByModelType(typeof(OrgM_EmpDeptDuty));
                 string code     = SystemOperate.GetBillCode(moduleId);
                 empPosition = new OrgM_EmpDeptDuty()
                 {
                     Code           = code,
                     OrgM_DeptId    = t.DeptId.Value,
                     OrgM_DutyId    = t.DutyId.Value,
                     OrgM_EmpId     = t.Id,
                     IsMainDuty     = true,
                     IsValid        = true,
                     EffectiveDate  = DateTime.Now,
                     CreateDate     = DateTime.Now,
                     CreateUserId   = currUser.UserId,
                     CreateUserName = currUser.EmpName,
                     ModifyDate     = DateTime.Now,
                     ModifyUserId   = currUser.UserId,
                     ModifyUserName = currUser.EmpName
                 };
                 Guid rs = CommonOperate.OperateRecord <OrgM_EmpDeptDuty>(empPosition, ModelRecordOperateType.Add, out errMsg, null, false);
                 if (rs != Guid.Empty)
                 {
                     SystemOperate.UpdateBillCode(moduleId, code);
                 }
             }
         }
     }
 }
        /// <summary>
        /// 添加职务
        /// </summary>
        /// <returns></returns>
        public JsonResult AddDuty()
        {
            if (_Request == null)
            {
                _Request = Request;
            }
            Guid deptId = _Request.QueryEx("deptId").ObjToGuid();

            if (deptId == Guid.Empty)
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = "请先选择部门"
                }));
            }
            OrgM_Dept dept = OrgMOperate.GetDeptById(deptId);

            if (dept == null)
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = "选择的部门不存在"
                }));
            }
            string dutyname = _Request.QueryEx("dutyname").ObjToStr();

            if (string.IsNullOrWhiteSpace(dutyname))
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = "职务名称不能为空"
                }));
            }
            string errMsg = string.Empty;
            long   num    = CommonOperate.Count <OrgM_Dept>(out errMsg, false, x => x.Name == dutyname);

            if (num > 0)
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = "该职务已存在,请不要重复添加"
                }));
            }
            UserInfo  currUser = GetCurrentUser(_Request);
            Guid      moduleId = SystemOperate.GetModuleIdByTableName("OrgM_Duty");
            string    code     = SystemOperate.GetBillCode(moduleId);
            OrgM_Duty duty     = new OrgM_Duty()
            {
                Code           = code,
                Name           = dutyname,
                IsValid        = true,
                EffectiveDate  = DateTime.Now,
                CreateDate     = DateTime.Now,
                CreateUserId   = currUser.UserId,
                CreateUserName = currUser.EmpName,
                ModifyDate     = DateTime.Now,
                ModifyUserId   = currUser.UserId,
                ModifyUserName = currUser.EmpName
            };
            Guid dutyId = CommonOperate.OperateRecord <OrgM_Duty>(duty, ModelRecordOperateType.Add, out errMsg, null, false);

            if (dutyId != Guid.Empty)
            {
                SystemOperate.UpdateBillCode(moduleId, code);
                Guid?parentId = null;
                List <OrgM_DeptDuty> positions = OrgMOperate.GetDeptPositions(deptId);
                if (positions.Count > 0)
                {
                    OrgM_DeptDuty leaderPosition = positions.Where(x => x.IsDeptCharge).FirstOrDefault();
                    if (leaderPosition != null)
                    {
                        parentId = leaderPosition.Id;
                    }
                }
                Guid          gwModuleId   = SystemOperate.GetModuleIdByTableName("OrgM_DeptDuty");
                string        positionCode = SystemOperate.GetBillCode(gwModuleId);
                OrgM_DeptDuty position     = new OrgM_DeptDuty()
                {
                    Code        = positionCode,
                    Name        = string.Format("{0}-{1}", string.IsNullOrEmpty(dept.Alias) ? dept.Name : dept.Alias, dutyname),
                    OrgM_DeptId = deptId,
                    OrgM_DutyId = dutyId,
                    ParentId    = parentId,
                    IsValid     = true
                };
                Guid positionId = CommonOperate.OperateRecord <OrgM_DeptDuty>(position, ModelRecordOperateType.Add, out errMsg, null, false);
                if (positionId != Guid.Empty)
                {
                    SystemOperate.UpdateBillCode(gwModuleId, positionCode);
                }
                return(Json(new { Success = true, Message = string.Empty, DutyId = dutyId }));
            }
            else
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = errMsg
                }));
            }
        }
Пример #18
0
 /// <summary>
 /// 获取用户扩展信息
 /// </summary>
 /// <param name="userInfo">用户信息</param>
 /// <returns></returns>
 public static UserExtendBase GetUserExtend(UserInfo userInfo)
 {
     if (userInfo == null)
     {
         return(null);
     }
     if (userInfo.ExtendUserObject != null)
     {
         return(userInfo.ExtendUserObject);
     }
     if (userInfo.EmpId.HasValue)
     {
         List <EmpExtendInfo> empExtends = new List <EmpExtendInfo>();
         List <Guid>          companyIds = OrgMOperate.GetEmpCompanys(userInfo.EmpId.Value).Select(x => x.Id).ToList();
         if (companyIds.Count > 0)
         {
             foreach (Guid companyId in companyIds)
             {
                 OrgM_Dept            mainDept         = OrgMOperate.GetEmpMainDept(userInfo.EmpId.Value, companyId);
                 OrgM_Duty            mainDuty         = OrgMOperate.GetEmpMainDuty(userInfo.EmpId.Value, companyId);
                 List <OrgM_Dept>     partimeDepts     = OrgMOperate.GetEmpPartTimeDepts(userInfo.EmpId.Value, companyId);
                 List <OrgM_DeptDuty> partimePositions = OrgMOperate.GetPartTimePositions(userInfo.EmpId.Value, companyId);
                 empExtends.Add(new EmpExtendInfo()
                 {
                     CompanyId            = companyId,
                     DeptId               = mainDept != null ? mainDept.Id : (Guid?)null,
                     DeptName             = mainDept != null ? (string.IsNullOrEmpty(mainDept.Alias) ? mainDept.Name : mainDept.Alias) : string.Empty,
                     DutyId               = mainDuty != null ? mainDuty.Id : (Guid?)null,
                     DutyName             = mainDuty != null ? mainDuty.Name : string.Empty,
                     PartimeDeptIds       = partimeDepts != null && partimeDepts.Count > 0 ? partimeDepts.Select(x => x.Id).ToList() : null,
                     PartimeDeptNames     = partimeDepts != null && partimeDepts.Count > 0 ? partimeDepts.Select(x => x.Name).ToList() : null,
                     PartimePositionIds   = partimePositions != null && partimePositions.Count > 0 ? partimePositions.Select(x => x.Id).ToList() : null,
                     PartimePositionNames = partimePositions != null && partimePositions.Count > 0 ? partimePositions.Select(x => x.Name).ToList() : null
                 });
             }
         }
         else
         {
             OrgM_Dept            mainDept         = OrgMOperate.GetEmpMainDept(userInfo.EmpId.Value);
             OrgM_Duty            mainDuty         = OrgMOperate.GetEmpMainDuty(userInfo.EmpId.Value);
             List <OrgM_Dept>     partimeDepts     = OrgMOperate.GetEmpPartTimeDepts(userInfo.EmpId.Value);
             List <OrgM_DeptDuty> partimePositions = OrgMOperate.GetPartTimePositions(userInfo.EmpId.Value);
             empExtends.Add(new EmpExtendInfo()
             {
                 CompanyId            = null,
                 DeptId               = mainDept != null ? mainDept.Id : (Guid?)null,
                 DeptName             = mainDept != null ? (string.IsNullOrEmpty(mainDept.Alias) ? mainDept.Name : mainDept.Alias) : string.Empty,
                 DutyId               = mainDuty != null ? mainDuty.Id : (Guid?)null,
                 DutyName             = mainDuty != null ? mainDuty.Name : string.Empty,
                 PartimeDeptIds       = partimeDepts != null && partimeDepts.Count > 0 ? partimeDepts.Select(x => x.Id).ToList() : null,
                 PartimeDeptNames     = partimeDepts != null && partimeDepts.Count > 0 ? partimeDepts.Select(x => x.Name).ToList() : null,
                 PartimePositionIds   = partimePositions != null && partimePositions.Count > 0 ? partimePositions.Select(x => x.Id).ToList() : null,
                 PartimePositionNames = partimePositions != null && partimePositions.Count > 0 ? partimePositions.Select(x => x.Name).ToList() : null
             });
         }
         UserExtendInfo userExtendInfo = new UserExtendInfo()
         {
             EmpExtend = empExtends
         };
         List <Sys_UserRole> userRoles = PermissionOperate.GetAllUserRoles(x => x.Sys_RoleId != null && x.Sys_UserId == userInfo.UserId);
         if (userRoles.Count > 0)
         {
             userExtendInfo.RoleIds   = userRoles.Select(x => x.Sys_RoleId).ToList();
             userExtendInfo.RoleNames = userRoles.Select(x => x.Sys_RoleName).ToList();
         }
         return(userExtendInfo);
     }
     else
     {
         UserExtendInfo      userExtendInfo = new UserExtendInfo();
         List <Sys_UserRole> userRoles      = PermissionOperate.GetAllUserRoles(x => x.Sys_RoleId != null && x.Sys_UserId == userInfo.UserId);
         if (userRoles.Count > 0)
         {
             userExtendInfo.RoleIds   = userRoles.Select(x => x.Sys_RoleId).ToList();
             userExtendInfo.RoleNames = userRoles.Select(x => x.Sys_RoleName).ToList();
         }
         return(userExtendInfo);
     }
 }
Пример #19
0
 /// <summary>
 /// 员工操作完成
 /// </summary>
 /// <param name="operateType">操作类型</param>
 /// <param name="t">员工对象</param>
 /// <param name="result">操作结果</param>
 /// <param name="currUser">当前用户</param>
 /// <param name="otherParams"></param>
 public void OperateCompeletedHandle(ModelRecordOperateType operateType, OrgM_Emp t, bool result, UserInfo currUser, object[] otherParams = null)
 {
     if (result)
     {
         string errMsg   = string.Empty;
         string username = OrgMOperate.GetUserNameByEmp(t);
         if (operateType == ModelRecordOperateType.Add)
         {
             if (!string.IsNullOrEmpty(username))
             {
                 UserOperate.AddUser(out errMsg, username, string.Format("{0}_123456", username), null, t.Name);
             }
         }
         else if (operateType == ModelRecordOperateType.Edit)
         {
             if (!string.IsNullOrEmpty(username))
             {
                 UserOperate.UpdateUserAliasName(username, t.Name);
             }
         }
         else if (operateType == ModelRecordOperateType.Del)
         {
             if (!string.IsNullOrEmpty(username))
             {
                 UserOperate.DelUser(username); //删除账号
             }
             //删除员工同时删除员工岗位
             CommonOperate.DeleteRecordsByExpression <OrgM_EmpDeptDuty>(x => x.OrgM_EmpId == t.Id, out errMsg, t.IsDeleted);
         }
         if (operateType == ModelRecordOperateType.Add || operateType == ModelRecordOperateType.Edit)
         {
             //新增编辑时同时设置员工主职岗位
             if (t.DeptId.HasValue && t.DeptId.Value != Guid.Empty && t.DutyId.HasValue && t.DutyId.Value != Guid.Empty)
             {
                 OrgM_EmpDeptDuty empPosition = null;
                 if (operateType == ModelRecordOperateType.Edit)
                 {
                     empPosition = CommonOperate.GetEntity <OrgM_EmpDeptDuty>(x => x.OrgM_EmpId == t.Id && x.IsMainDuty == true, null, out errMsg);
                     if (empPosition != null)
                     {
                         empPosition.OrgM_DeptId    = t.DeptId.Value;
                         empPosition.OrgM_DutyId    = t.DutyId.Value;
                         empPosition.IsValid        = true;
                         empPosition.ModifyDate     = DateTime.Now;
                         empPosition.ModifyUserId   = currUser.UserId;
                         empPosition.ModifyUserName = currUser.EmpName;
                         CommonOperate.OperateRecord <OrgM_EmpDeptDuty>(empPosition, ModelRecordOperateType.Edit, out errMsg, null, false);
                         return;
                     }
                 }
                 empPosition = new OrgM_EmpDeptDuty()
                 {
                     OrgM_DeptId    = t.DeptId.Value,
                     OrgM_DutyId    = t.DutyId.Value,
                     OrgM_EmpId     = t.Id,
                     IsMainDuty     = true,
                     IsValid        = true,
                     EffectiveDate  = DateTime.Now,
                     CreateDate     = DateTime.Now,
                     CreateUserId   = currUser.UserId,
                     CreateUserName = currUser.EmpName,
                     ModifyDate     = DateTime.Now,
                     ModifyUserId   = currUser.UserId,
                     ModifyUserName = currUser.EmpName
                 };
                 CommonOperate.OperateRecord <OrgM_EmpDeptDuty>(empPosition, ModelRecordOperateType.Add, out errMsg, null, false);
             }
         }
     }
 }