Ejemplo n.º 1
0
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="newPwd">新密码</param>
        /// <param name="errMsg">错误信息</param>
        /// <returns></returns>
        public static bool ModifyPassword(Guid userId, string newPwd, out string errMsg)
        {
            errMsg = string.Empty;
            if (ModelConfigHelper.ModelIsViewMode(typeof(Sys_User)))
            {
                errMsg = "用户管理模块为视图模式不允许更新密码!";
                return(false);
            }
            Sys_User user = CommonOperate.GetEntity <Sys_User>(x => x.Id == userId && !x.IsDeleted && x.IsValid && x.IsActivated, string.Empty, out errMsg);

            if (user == null)
            {
                errMsg = "非法用户!";
                return(false);
            }
            //获取混淆码
            string passwordSalt = SecurityHelper.GenerateSalt();
            //获取混淆码加密过的密码
            string passwordHash = SecurityHelper.EncodePassword(newPwd, passwordSalt); //SecurityHelper.EncodePassword(MySecurity.MD5(newPwd), passwordSalt);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;
            Guid rs = CommonOperate.OperateRecord <Sys_User>(user, ModelRecordOperateType.Edit, out errMsg, new List <string>()
            {
                "PasswordHash", "PasswordSalt"
            }, false);

            if (rs != Guid.Empty) //修改密码成功
            {
                errMsg = TempUserOperate(userId, newPwd);
            }
            return(string.IsNullOrEmpty(errMsg));
        }
 /// <summary>
 /// 登录后
 /// </summary>
 /// <param name="resultContext">结果上下文</param>
 public override void OnResultExecuted(ResultExecutedContext resultContext)
 {
     //异步处理
     Task.Factory.StartNew(() =>
     {
         try
         {
             JsonResult result = resultContext.Result as JsonResult;
             if (result != null && result.Value != null)
             {
                 PropertyInfo pSuccess  = result.Value.GetType().GetProperty("Success");
                 PropertyInfo pErrMsg   = result.Value.GetType().GetProperty("Message");
                 bool loginSuccess      = pSuccess.GetValue2(result.Value, null).ObjToBool();
                 loginLog.LoginStatus   = loginSuccess ? "登录成功" : "登录失败";
                 loginLog.FailureReason = pErrMsg.GetValue2(result.Value, null).ObjToStr();
             }
             else
             {
                 loginLog.LoginStatus   = "登录失败";
                 loginLog.FailureReason = "无返回结果";
             }
             string errMsg     = string.Empty;
             long loginNum     = CommonOperate.Count <Log_Login>(out errMsg, false, x => x.LoginName == loginLog.LoginName);
             loginLog.LoginNum = (int)loginNum + 1;
             loginLog.Id       = Guid.NewGuid();
             CommonOperate.OperateRecord <Log_Login>(loginLog, Operate.Base.OperateHandle.ModelRecordOperateType.Add, out errMsg, null, false);
         }
         catch { }
     });
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 修改用户别名
        /// </summary>
        /// <param name="username">用户名</param>
        /// <param name="aliasName">用户别名</param>
        /// <returns></returns>
        public static string UpdateUserAliasName(string username, string aliasName)
        {
            if (ModelConfigHelper.ModelIsViewMode(typeof(Sys_User)))
            {
                return("用户管理模块为视图模式不允许更新用户别名!");
            }
            if (string.IsNullOrWhiteSpace(aliasName))
            {
                return("用户别名不能为空!");
            }
            string   errMsg = string.Empty;
            Sys_User user   = CommonOperate.GetEntity <Sys_User>(x => x.UserName == username, null, out errMsg);

            if (user == null)
            {
                return("用户信息不存在!");
            }
            if (user.AliasName != aliasName)
            {
                user.AliasName = aliasName;
                Guid rs = CommonOperate.OperateRecord <Sys_User>(user, ModelRecordOperateType.Edit, out errMsg, new List <string>()
                {
                    "AliasName"
                }, false);
            }
            return(errMsg);
        }
Ejemplo n.º 4
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);
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 添加操作日志
 /// </summary>
 /// <param name="operateUser">操作用户</param>
 /// <param name="moduleName">模块名称</param>
 /// <param name="opType">操作类型,如新增、修改、删除等</param>
 /// <param name="opContent">操作内容</param>
 /// <param name="IsOpSuccess">是否成功</param>
 /// <param name="opErrMsg">操作异常信息</param>
 public static void AddOperateLog(UserInfo operateUser, string moduleName, string opType, string opContent, bool IsOpSuccess, string opErrMsg)
 {
     try
     {
         if (operateUser == null || string.IsNullOrEmpty(moduleName))
         {
             return;
         }
         //构建操作日志对象
         UserInfo    admin      = UserOperate.GetSuperAdmin();
         Log_Operate operateLog = new Log_Operate();
         operateLog.Id             = Guid.NewGuid();
         operateLog.ModuleName     = moduleName;
         operateLog.OperateType    = opType;
         operateLog.OperateContent = opContent;
         operateLog.OperateResult  = IsOpSuccess ? "操作成功" : "操作失败";
         operateLog.OperateTip     = opErrMsg;
         operateLog.UserId         = operateUser.UserName;
         operateLog.UserAlias      = operateUser.AliasName;
         operateLog.OperateTime    = DateTime.Now;
         operateLog.ClientIp       = operateUser.ClientIP;
         operateLog.CreateDate     = DateTime.Now;
         operateLog.CreateUserId   = admin.UserId;
         operateLog.CreateUserName = admin.AliasName;
         operateLog.ModifyDate     = DateTime.Now;
         operateLog.ModifyUserId   = admin.UserId;
         operateLog.ModifyUserName = admin.AliasName;
         string errMsg = string.Empty;
         //保存日志
         CommonOperate.OperateRecord <Log_Operate>(operateLog, OperateHandle.ModelRecordOperateType.Add, out errMsg, null, false);
     }
     catch { }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 添加异常日志
 /// </summary>
 /// <param name="ex">异常对象</param>
 /// <param name="paramObj">参数</param>
 /// <param name="controlOrClass">控制器或类名</param>
 /// <param name="actionName">方法名</param>
 /// <param name="currUser">当前用户</param>
 public static void AddExceptionLog(Exception ex, string paramObj, string controlOrClass = null, string actionName = null, UserInfo currUser = null)
 {
     if (ex == null)
     {
         return;
     }
     try
     {
         //构造对象
         Log_Exception exceptionLog = new Log_Exception();
         exceptionLog.ExceptionName   = ex.GetType().Name;
         exceptionLog.ExceptionSource = ex.Source;
         exceptionLog.ExceptionMsg    = ex.Message;
         exceptionLog.StackTrace      = ex.StackTrace;
         exceptionLog.ExceptionTime   = DateTime.Now;
         exceptionLog.ControllerName  = controlOrClass;
         exceptionLog.ActionName      = actionName;
         exceptionLog.CreateUserId    = currUser != null ? currUser.UserId : (Guid?)null;
         exceptionLog.CreateUserName  = UserInfo.GetUserAliasName(currUser);
         exceptionLog.CreateDate      = DateTime.Now;
         exceptionLog.ModifyDate      = DateTime.Now;
         exceptionLog.ModifyUserId    = currUser != null ? currUser.UserId : (Guid?)null;
         exceptionLog.ModifyUserName  = UserInfo.GetUserAliasName(currUser);
         exceptionLog.Id = Guid.NewGuid();
         //保存
         string errMsg = string.Empty;
         CommonOperate.OperateRecord <Log_Exception>(exceptionLog, OperateHandle.ModelRecordOperateType.Add, out errMsg, null, false);
     }
     catch { }
 }
        /// <summary>
        /// 添加部门
        /// </summary>
        /// <returns></returns>
        public JsonResult AddDept()
        {
            if (_Request == null)
            {
                _Request = Request;
            }
            string deptname = _Request.QueryEx("deptname").ObjToStr();

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

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

            if (deptId != Guid.Empty)
            {
                SystemOperate.UpdateBillCode(moduleId, code);
                return(Json(new { Success = true, Message = string.Empty, DeptId = deptId, DeptName = deptname }));
            }
            else
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = errMsg
                }));
            }
        }
 /// <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);
             }
         }
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// 添加部门
        /// </summary>
        /// <returns></returns>
        public ActionResult AddDept()
        {
            string deptname = Request["deptname"].ObjToStr();

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

            if (num > 0)
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = "该部门已存在,请不要重复添加"
                }));
            }
            UserInfo  currUser = GetCurrentUser(Request);
            OrgM_Dept dept     = new OrgM_Dept()
            {
                Name           = deptname,
                Alias          = deptname,
                IsValid        = true,
                EffectiveDate  = DateTime.Now,
                CreateDate     = DateTime.Now,
                CreateUserId   = currUser.UserId,
                CreateUserName = currUser.EmpName,
                ModifyDate     = DateTime.Now,
                ModifyUserId   = currUser.UserId,
                ModifyUserName = currUser.EmpName
            };
            Guid deptId = CommonOperate.OperateRecord <OrgM_Dept>(dept, ModelRecordOperateType.Add, out errMsg, null, false);

            if (deptId != Guid.Empty)
            {
                return(Json(new { Success = true, Message = string.Empty, DeptId = deptId, DeptName = deptname }));
            }
            else
            {
                return(Json(new ReturnResult()
                {
                    Success = false, Message = errMsg
                }));
            }
        }
 /// <summary>
 /// 操作执行后
 /// </summary>
 /// <param name="filterContext"></param>
 public override void OnResultExecuted(ResultExecutedContext filterContext)
 {
     //异步处理
     Task.Factory.StartNew(() =>
     {
         try
         {
             base.OnResultExecuted(filterContext);
             opExecuteTime.ExecuteMiniSeconds = (DateTime.Now - startTime).TotalMilliseconds;
             opExecuteTime.Id = Guid.NewGuid();
             if (opExecuteTime.ModuleName != "操作时间监控" && opExecuteTime.ClientIp != "::1")
             {
                 string errMsg = string.Empty;
                 CommonOperate.OperateRecord <Monitor_OpExecuteTime>(opExecuteTime, ModelRecordOperateType.Add, out errMsg, null, false);
             }
         }
         catch { }
     });
 }
Ejemplo n.º 11
0
        /// <summary>
        /// 冻结账号
        /// </summary>
        /// <param name="username">用户名</param>
        /// <returns></returns>
        public static string FrozenUser(string username)
        {
            string errMsg = string.Empty;

            if (ModelConfigHelper.ModelIsViewMode(typeof(Sys_User)))
            {
                errMsg = "用户管理模块为视图模式,不允许冻结!";
                return(errMsg);
            }
            Sys_User user = CommonOperate.GetEntity <Sys_User>(x => x.UserName == username && !x.IsDeleted && x.IsValid && x.IsActivated, string.Empty, out errMsg);

            if (user == null)
            {
                return("非法用户!");
            }
            user.IsValid = false;
            Guid rs = CommonOperate.OperateRecord <Sys_User>(user, ModelRecordOperateType.Edit, out errMsg, new List <string>()
            {
                "IsValid"
            }, false);

            return(errMsg);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 临时用户操作
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="userpwd">用户密码</param>
        private static string TempUserOperate(Guid userId, string userpwd)
        {
            string errMsg = string.Empty;

            try
            {
                ModelRecordOperateType operateType = ModelRecordOperateType.Edit;
                Sys_TempUser           tempUser    = CommonOperate.GetEntity <Sys_TempUser>(x => x.FieldInfo1 == userId.ToString(), string.Empty, out errMsg);
                if (tempUser == null)
                {
                    operateType         = ModelRecordOperateType.Add;
                    tempUser            = new Sys_TempUser();
                    tempUser.FieldInfo1 = userId.ToString();
                }
                tempUser.FieldInfo2 = MySecurity.DES3EncryptString(string.Format("{0}_0123456789", Guid.Empty.ToString()), userpwd, "sy654321");
                CommonOperate.OperateRecord <Sys_TempUser>(tempUser, operateType, out errMsg, null, false);
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
            }
            return(errMsg);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="errMsg">异常信息</param>
        /// <param name="username">用户名</param>
        /// <param name="userpwd">用户密码</param>
        /// <param name="orgId">组织Id</param>
        /// <param name="aliasName">用户别名</param>
        /// <returns></returns>
        public static Guid AddUser(out string errMsg, string username, string userpwd, Guid?orgId = null, string aliasName = null)
        {
            errMsg = string.Empty;
            if (ModelConfigHelper.ModelIsViewMode(typeof(Sys_User)))
            {
                errMsg = "用户管理模块为视图模式,不允许添加!";
                return(Guid.Empty);
            }
            if (string.IsNullOrWhiteSpace(username))
            {
                errMsg = "用户名不能为空!";
                return(Guid.Empty);
            }
            if (string.IsNullOrWhiteSpace(userpwd))
            {
                errMsg = "用户密码不能为空!";
                return(Guid.Empty);
            }
            Sys_User tempUser = CommonOperate.GetEntity <Sys_User>(x => x.UserName.ToLower() == username.Trim().ToLower(), null, out errMsg);

            if (tempUser != null)
            {
                errMsg = string.Format("用户【{0}】已存在!", username);
                return(Guid.Empty);
            }
            UserInfo adminUser = GetSuperAdmin(); //超级管理员用户
            //获取混淆码
            string passwordSalt = SecurityHelper.GenerateSalt();
            //获取混淆码加密过的密码
            string   passwordHash = SecurityHelper.EncodePassword(userpwd, passwordSalt); //SecurityHelper.EncodePassword(MySecurity.MD5(userpwd), passwordSalt);
            Sys_User user         = new Sys_User()
            {
                UserName      = username,
                AliasName     = aliasName,
                PasswordHash  = passwordHash,
                PasswordSalt  = passwordSalt,
                IsValid       = true,
                IsActivated   = true,
                ActivatedDate = DateTime.Now
            };

            if (orgId.HasValue && orgId.Value != Guid.Empty)
            {
                user.Sys_OrganizationId = orgId.Value;
            }
            if (adminUser != null)
            {
                user.CreateUserName = adminUser.AliasName;
                user.CreateDate     = DateTime.Now;
                user.CreateUserId   = adminUser.UserId;
                user.ModifyUserName = adminUser.AliasName;
                user.ModifyDate     = DateTime.Now;
                user.ModifyUserId   = adminUser.UserId;
            }
            Guid userId = CommonOperate.OperateRecord <Sys_User>(user, ModelRecordOperateType.Add, out errMsg, null, false);

            //临时用户操作
            if (userId != Guid.Empty)
            {
                TempUserOperate(userId, userpwd);
            }
            return(userId);
        }
Ejemplo n.º 14
0
        /// <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
                }));
            }
        }
Ejemplo n.º 15
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);
                 }
             }
         }
     }
 }
Ejemplo n.º 16
0
 /// <summary>
 /// 取分布式锁(基于DB方式)
 /// </summary>
 /// <param name="moduleFlag">模块标识,模块表名/类名</param>
 /// <param name="method_Flag">方法名标识</param>
 /// <param name="expirtime">自定义过期时间(秒)</param>
 /// <param name="des">锁描述</param>
 /// <returns></returns>
 public static string DistributeDbLock(string moduleFlag, string method_Flag, double?expirtime = null, string des = null)
 {
     try
     {
         if (WebConfigHelper.GetAppSettingValue("EnabledDistributeLock") != "true") //未启用分布式锁
         {
             return(string.Empty);
         }
         string hostname  = System.Net.Dns.GetHostName();            //当前服务器
         string processId = ApplicationObject.GetCurrentProcessId(); //当前进程
         string threadId  = ApplicationObject.GetCurrentThreadId();  //当前线程
         lock (tempObjDistriLock)
         {
             string       errMsg   = string.Empty;
             int          timeout  = 30; //30秒超时
             DateTime     initTime = DateTime.Now;
             DatabaseType dbType   = DatabaseType.MsSqlServer;
             string       connStr  = ModelConfigHelper.GetModelConnStr(typeof(Other_DistributedLock), out dbType, false);
             while ((DateTime.Now - initTime).TotalSeconds <= timeout)
             {
                 double updateTimesamp            = Globals.GetTimestamp(DateTime.Now);                                                                 //当前时间戳
                 double invalidTimesamp           = expirtime.HasValue && expirtime.Value > 0 ? updateTimesamp + expirtime.Value : updateTimesamp + 20; //过期时间戳
                 Other_DistributedLock methodLock = CommonOperate.GetEntity <Other_DistributedLock>(x => x.ModuleFlag == moduleFlag && x.Method_Flag == method_Flag && x.Invalid_Timesamp > updateTimesamp, null, out errMsg);
                 //锁存在,继续循环再取
                 if (methodLock != null)
                 {
                     Thread.Sleep(10);
                     continue;
                 }
                 //锁不存在,取得锁成功,插入锁标识
                 methodLock = new Other_DistributedLock()
                 {
                     ModuleFlag       = moduleFlag,
                     Method_Flag      = method_Flag,
                     Update_Timesamp  = updateTimesamp,
                     Invalid_Timesamp = invalidTimesamp,
                     Maching          = hostname,
                     ProcessId        = processId,
                     ThreadId         = threadId,
                     Des = des
                 };
                 TransactionTask tranAction = (conn) =>
                 {
                     CommonOperate.DeleteRecordsByExpression <Other_DistributedLock>(x => x.ModuleFlag == moduleFlag && x.Method_Flag == method_Flag, out errMsg, false, connStr, dbType, conn);
                     if (!string.IsNullOrEmpty(errMsg))
                     {
                         throw new Exception(errMsg);
                     }
                     CommonOperate.OperateRecord <Other_DistributedLock>(methodLock, ModelRecordOperateType.Add, out errMsg, null, false, false, connStr, dbType, conn);
                     if (!string.IsNullOrEmpty(errMsg))
                     {
                         throw new Exception(errMsg);
                     }
                 };
                 CommonOperate.TransactionHandle(tranAction, out errMsg, connStr, dbType);
                 //取锁成功
                 if (string.IsNullOrEmpty(errMsg))
                 {
                     return(string.Empty);
                 }
                 else
                 {
                     WritLockLog(moduleFlag, method_Flag, errMsg);
                 }
                 //取锁失败,继续循环取
                 Thread.Sleep(10);
             }
             return("获取分布式锁超时"); //取锁失败
         }
     }
     catch
     {
         return(string.Empty);
     }
 }
Ejemplo n.º 17
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);
             }
         }
     }
 }