Exemplo n.º 1
0
        /// <summary>
        /// 更新离职申请记录
        /// </summary>
        /// <param name="entity">离职申请记录实体</param>
        public void LeftOfficeUpdate(T_HR_LEFTOFFICE entity, ref string strMsg)
        {
            try
            {
                SMT.SaaS.BLLCommonServices.PermissionWS.PermissionServiceClient perclient = new SMT.SaaS.BLLCommonServices.PermissionWS.PermissionServiceClient();
                string employeeId = entity.T_HR_EMPLOYEE.EMPLOYEEID;
                var    t_sys_user = perclient.GetUserByEmployeeID(employeeId);

                var tmp = from c in dal.GetObjects()
                          where c.T_HR_EMPLOYEE.EMPLOYEEID == entity.T_HR_EMPLOYEE.EMPLOYEEID && (c.CHECKSTATE == "0" || c.CHECKSTATE == "1") &&
                          c.T_HR_EMPLOYEEPOST.EMPLOYEEPOSTID == entity.T_HR_EMPLOYEEPOST.EMPLOYEEPOSTID && c.DIMISSIONID != entity.DIMISSIONID
                          select c;
                if (tmp.Count() > 0)
                {
                    //throw new Exception("LEFTOFFICESUBMITTED");
                    strMsg = "LEFTOFFICESUBMITTED";
                    return;
                }
                T_HR_LEFTOFFICE ent = dal.GetTable().FirstOrDefault(s => s.DIMISSIONID == entity.DIMISSIONID);
                if (ent != null)
                {
                    if (entity.CHECKSTATE == Convert.ToInt32(CheckStates.Approved).ToString())
                    {
                        //如果是代理岗位  就将代理岗设为无效   并添加异动记录

                        EmployeePostBLL   epbll = new EmployeePostBLL();
                        T_HR_EMPLOYEEPOST epost = dal.GetObjects <T_HR_EMPLOYEEPOST>().Include("T_HR_POST").FirstOrDefault(ep => ep.EMPLOYEEPOSTID == entity.T_HR_EMPLOYEEPOST.EMPLOYEEPOSTID);
                        if (epost != null && epost.ISAGENCY == "1")
                        {
                            epost.EDITSTATE = "0";
                            epbll.EmployeePostUpdate(epost);
                            //删除岗位
                            #region 添加异动记录
                            var tmpInfo = from c in dal.GetObjects <T_HR_POST>()
                                          join b in dal.GetObjects <T_HR_DEPARTMENT>() on c.T_HR_DEPARTMENT.DEPARTMENTID equals b.DEPARTMENTID
                                          where c.POSTID == epost.T_HR_POST.POSTID
                                          select new
                            {
                                c.POSTID,
                                b.DEPARTMENTID,
                                b.T_HR_COMPANY.COMPANYID
                            };
                            EmployeePostChangeBLL   epchangeBLL = new EmployeePostChangeBLL();
                            T_HR_EMPLOYEEPOSTCHANGE postChange  = new T_HR_EMPLOYEEPOSTCHANGE();
                            postChange = new T_HR_EMPLOYEEPOSTCHANGE();
                            postChange.T_HR_EMPLOYEE            = new T_HR_EMPLOYEE();
                            postChange.T_HR_EMPLOYEE.EMPLOYEEID = entity.T_HR_EMPLOYEE.EMPLOYEEID;
                            postChange.EMPLOYEECODE             = entity.T_HR_EMPLOYEE.EMPLOYEECODE;
                            postChange.EMPLOYEENAME             = entity.T_HR_EMPLOYEE.EMPLOYEECNAME;
                            postChange.POSTCHANGEID             = Guid.NewGuid().ToString();
                            postChange.CHECKSTATE = Convert.ToInt32(CheckStates.Approved).ToString();
                            postChange.ISAGENCY   = "1";
                            if (tmpInfo.Count() > 0)
                            {
                                postChange.FROMCOMPANYID    = tmpInfo.FirstOrDefault().COMPANYID;
                                postChange.FROMDEPARTMENTID = tmpInfo.FirstOrDefault().DEPARTMENTID;
                                postChange.FROMPOSTID       = tmpInfo.FirstOrDefault().POSTID;

                                postChange.OWNERCOMPANYID    = tmpInfo.FirstOrDefault().COMPANYID;
                                postChange.OWNERDEPARTMENTID = tmpInfo.FirstOrDefault().DEPARTMENTID;
                                postChange.OWNERPOSTID       = tmpInfo.FirstOrDefault().POSTID;
                            }
                            postChange.OWNERID           = entity.T_HR_EMPLOYEE.EMPLOYEEID;
                            postChange.POSTCHANGREASON   = entity.LEFTOFFICEREASON;
                            postChange.CHANGEDATE        = entity.LEFTOFFICEDATE.ToString();
                            postChange.CREATEUSERID      = entity.CREATEUSERID;
                            postChange.POSTCHANGCATEGORY = "3";
                            string Msg = string.Empty;
                            epchangeBLL.EmployeePostChangeAdd(postChange, ref Msg);
                            #endregion
                            //通知及时通讯
                            DelImstantMember(entity.T_HR_EMPLOYEE.EMPLOYEEID, epost.T_HR_POST.POSTID);
                        }
                        else
                        {
                            //员工状态修改为离职中
                            string tmpstr       = "";
                            var    employeetmps = from c in dal.GetObjects <T_HR_EMPLOYEE>()
                                                  where c.EMPLOYEEID == entity.T_HR_EMPLOYEE.EMPLOYEEID
                                                  select c;
                            if (employeetmps.Count() > 0)
                            {
                                EmployeeBLL bll         = new EmployeeBLL();
                                var         employeetmp = employeetmps.FirstOrDefault();
                                if (employeetmp.EMPLOYEESTATE != "2") //已离职,如果已经离职则不要再改为离职中
                                {
                                    employeetmp.EMPLOYEESTATE = "3";  //离职中
                                }
                                bll.EmployeeUpdate(employeetmp, ref tmpstr);
                            }
                        }

                        #region 员工离职通知流程管理员进行修改相应的流程
                        try
                        {
                            SMT.Foundation.Log.Tracer.Debug(System.DateTime.Now.ToString() + " 员工离职审核通过通知流程管理员进行修改相应的流程");
                            StringBuilder sb = new StringBuilder();
                            sb.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
                            sb.Append("<Root>");
                            //查出用户的所有角色
                            var roleUserList = perclient.GetSysUserRoleByUser(t_sys_user.SYSUSERID).ToList();
                            if (roleUserList != null && roleUserList.Any())
                            {
                                bool hasRole = false;
                                sb.Append("<Roles>");
                                foreach (var roleUser in roleUserList)
                                {
                                    //查出改用户所在的角色,还有没有其它用户,如果没有则调流程
                                    string roleId = roleUser.T_SYS_ROLE.ROLEID;
                                    var    roleUserIncludeSource = perclient.GetSysUserByRoleToEmployeeLeave(roleId);
                                    if (roleUserIncludeSource == null)
                                    {
                                        hasRole = true;
                                        sb.Append("<Role RoleID=\"" + roleUser.T_SYS_ROLE.ROLEID + "\" RoleName=\"" + roleUser.T_SYS_ROLE.ROLENAME + "\" />");
                                    }
                                    else
                                    {
                                        var roleUserInclude = roleUserIncludeSource.Where(t => t.EMPLOYEEID != employeeId).ToList();
                                        if (roleUserInclude.Count == 0)
                                        {
                                            hasRole = true;
                                            sb.Append("<Role RoleID=\"" + roleUser.T_SYS_ROLE.ROLEID + "\" RoleName=\"" + roleUser.T_SYS_ROLE.ROLENAME + "\" />");
                                        }
                                    }
                                }
                                sb.Append("</Roles>");
                                //如果存在角色
                                if (hasRole)
                                {
                                    var empInfo = from c in dal.GetObjects <T_HR_POST>()
                                                  join b in dal.GetObjects <T_HR_DEPARTMENT>() on c.T_HR_DEPARTMENT.DEPARTMENTID equals b.DEPARTMENTID
                                                  join d in dal.GetObjects <T_HR_COMPANY>() on b.T_HR_COMPANY.COMPANYID equals d.COMPANYID
                                                  where c.POSTID == entity.T_HR_EMPLOYEE.OWNERPOSTID
                                                  select new
                                    {
                                        c.T_HR_DEPARTMENT.T_HR_DEPARTMENTDICTIONARY.DEPARTMENTNAME,
                                        b.T_HR_COMPANY.BRIEFNAME,
                                        c.T_HR_POSTDICTIONARY.POSTNAME
                                    };
                                    string companyName = "";
                                    string deptName    = "";
                                    string postName    = "";
                                    if (empInfo != null)
                                    {
                                        companyName = empInfo.FirstOrDefault().BRIEFNAME;
                                        deptName    = empInfo.FirstOrDefault().DEPARTMENTNAME;
                                        postName    = empInfo.FirstOrDefault().POSTNAME;
                                    }
                                    sb.Append(" <User UserID=\"" + entity.T_HR_EMPLOYEE.EMPLOYEEID + "\" UserName=\"" + entity.T_HR_EMPLOYEE.EMPLOYEECNAME + "\" CompanyID=\"" + entity.T_HR_EMPLOYEE.OWNERCOMPANYID + "\" CompanyName=\"" + companyName + "\" DeparmentID=\"" + entity.T_HR_EMPLOYEE.OWNERDEPARTMENTID + "\" DeparmentName=\"" + deptName + "\" PostID=\"" + entity.T_HR_EMPLOYEE.OWNERPOSTID + "\" PostName=\"" + postName + "\" />");

                                    bool hasManagerEmail = false;
                                    var  flowManagers    = perclient.GetFlowManagers(new string[] { entity.T_HR_EMPLOYEE.OWNERCOMPANYID });
                                    if (flowManagers != null)
                                    {
                                        sb.Append("<Admins>");
                                        foreach (var mangers in flowManagers)
                                        {
                                            string email    = "";
                                            var    employee = from c in dal.GetObjects <T_HR_EMPLOYEE>()
                                                              where c.EMPLOYEEID == mangers.EMPLOYEEID
                                                              select c;
                                            if (employee != null)
                                            {
                                                email = employee.FirstOrDefault().EMAIL;
                                            }
                                            if (!string.IsNullOrEmpty(email))
                                            {
                                                hasManagerEmail = true;
                                                sb.Append("<Admin ID=\"" + mangers.EMPLOYEEID + "\" Name=\"" + mangers.EMPLOYEENAME + "\" Email=\"" + email + "\" />");
                                            }
                                        }
                                        sb.Append("</Admins>");
                                    }
                                    sb.Append("</Root>");
                                    if (hasManagerEmail)
                                    {
                                        SMT.Foundation.Log.Tracer.Debug(System.DateTime.Now.ToString() + "调用CheckFlowByRole:" + sb.ToString());
                                        SMT.SaaS.BLLCommonServices.WFPlatformWS.OutInterfaceClient outClient = new SaaS.BLLCommonServices.WFPlatformWS.OutInterfaceClient();
                                        outClient.CheckFlowByRole(sb.ToString());
                                    }
                                    else
                                    {
                                        SMT.Foundation.Log.Tracer.Debug(System.DateTime.Now.ToString() + "流程管理员没有设置邮箱,不调用CheckFlowByRole");
                                    }
                                }
                                else
                                {
                                    SMT.Foundation.Log.Tracer.Debug(System.DateTime.Now.ToString() + "当前用户id:(" + employeeId + ")所在角色还有用户,不调用CheckFlowByRole");
                                }
                            }
                            else
                            {
                                SMT.Foundation.Log.Tracer.Debug(System.DateTime.Now.ToString() + "没有找到用户的角色");
                            }
                        }
                        catch (Exception ex)
                        {
                            SMT.Foundation.Log.Tracer.Debug(System.DateTime.Now.ToString() + "调用员工离职审核通过通知流程管理员进行修改相应的流程异常:" + ex.Message.ToString());
                        }
                        #endregion
                    }
                    Utility.CloneEntity <T_HR_LEFTOFFICE>(entity, ent);
                    if (entity.T_HR_EMPLOYEE != null)
                    {
                        ent.T_HR_EMPLOYEEReference.EntityKey =
                            new System.Data.EntityKey(qualifiedEntitySetName + "T_HR_EMPLOYEE", "EMPLOYEEID", entity.T_HR_EMPLOYEE.EMPLOYEEID);
                    }
                    if (entity.T_HR_EMPLOYEEPOST != null)
                    {
                        ent.T_HR_EMPLOYEEPOSTReference.EntityKey =
                            new System.Data.EntityKey(qualifiedEntitySetName + "T_HR_EMPLOYEEPOST", "EMPLOYEEPOSTID", entity.T_HR_EMPLOYEEPOST.EMPLOYEEPOSTID);
                    }
                    //dal.Update(ent);
                    Update(ent, ent.CREATEUSERID);
                }
            }
            catch (Exception ex)
            {
                strMsg = ex.Message;
                SMT.Foundation.Log.Tracer.Debug(System.DateTime.Now.ToString() + " LeftOfficeUpdate:" + ex.Message);
                throw ex;
            }
        }
Exemplo n.º 2
0
        public void SetOrganizationFilter(ref string filterString, ref List <object> queryParas, string employeeID, string entityName)
        {
            //注意,用户总是能看到自己创建的记录

            //获取正常的角色用户权限

            int maxPerm = -1;

            //获取用户
            PermissionWS.T_SYS_USER user = PermClient.GetUserByEmployeeID(employeeID);
            //获取员工
            T_HR_EMPLOYEE emp = PersonClient.GetEmployeeByID(user.EMPLOYEEID);

            PermissionWS.V_Permission[] perms = PermClient.GetUserMenuPerms(entityName, user.SYSUSERID);

            bool hasPerms = true;

            if (perms == null)
            {
                // hasPerms = false;
                return;
            }
            else
            {
                //获取查询的权限,值越小,权限越大
                var tmpperms = perms.Where(p => p.Permission.PERMISSIONVALUE == "3").ToList();
                if (tmpperms == null || tmpperms.Count <= 0)
                {
                    hasPerms = false;
                }
                else
                {
                    maxPerm = tmpperms.Min(p => Convert.ToInt32(p.RoleMenuPermission.DATARANGE));
                }
            }

            if (hasPerms == false)
            {
                //if (!string.IsNullOrEmpty(filterString))
                //    filterString += " AND ";
                //filterString += " (1==0 OR CREATEUSERID==@" + queryParas.Count().ToString() + ")";
                //queryParas.Add(employeeID);
                filterString += "1 != 1";
                return;
            }


            //取员工岗位
            V_EMPLOYEEPOST emppost = PersonClient.GetEmployeeDetailByID(emp.EMPLOYEEID);

            emp.T_HR_EMPLOYEEPOST = emppost.EMPLOYEEPOSTS;


            //获取自定义权限
            int custPerm = GetCustomPerms(entityName, emp);

            if (custPerm < maxPerm)
            {
                maxPerm = custPerm;
            }

            //看整个集团的
            if (Convert.ToInt32(maxPerm) == Convert.ToInt32(AssignObjectType.Organize))
            {
                return;
            }

            //看整个公司的
            if (Convert.ToInt32(maxPerm) == Convert.ToInt32(AssignObjectType.Company))
            {
                if (!string.IsNullOrEmpty(filterString))
                {
                    filterString += " AND ";
                }

                filterString += " ((";
                int i = 0;
                foreach (T_HR_EMPLOYEEPOST ep in emp.T_HR_EMPLOYEEPOST)
                {
                    if (i > 0)
                    {
                        filterString += " OR ";
                    }

                    filterString += "OWNERCOMPANYID==@" + queryParas.Count().ToString();

                    queryParas.Add(ep.T_HR_POST.T_HR_DEPARTMENT.T_HR_COMPANY.COMPANYID);

                    i++;
                }
                filterString += ") OR CREATEUSERID==@" + queryParas.Count().ToString() + ")";
                queryParas.Add(employeeID);
            }


            //看部门的
            if (Convert.ToInt32(maxPerm) == Convert.ToInt32(AssignObjectType.Department))
            {
                if (!string.IsNullOrEmpty(filterString))
                {
                    filterString += " AND ";
                }

                filterString += " ((";
                int i = 0;
                foreach (T_HR_EMPLOYEEPOST ep in emp.T_HR_EMPLOYEEPOST)
                {
                    if (i > 0)
                    {
                        filterString += " OR ";
                    }

                    filterString += "OWNERDEPARTMENTID==@" + queryParas.Count().ToString();

                    queryParas.Add(ep.T_HR_POST.T_HR_DEPARTMENT.DEPARTMENTID);

                    i++;
                }

                filterString += ") OR CREATEUSERID==@" + queryParas.Count().ToString() + ")";
                queryParas.Add(employeeID);
            }


            //看岗位的
            if (Convert.ToInt32(maxPerm) == Convert.ToInt32(AssignObjectType.Post))
            {
                if (!string.IsNullOrEmpty(filterString))
                {
                    filterString += " AND ";
                }

                filterString += " ((";
                int i = 0;
                foreach (T_HR_EMPLOYEEPOST ep in emp.T_HR_EMPLOYEEPOST)
                {
                    if (i > 0)
                    {
                        filterString += " OR ";
                    }

                    filterString += "OWNERPOSTID==@" + queryParas.Count().ToString();

                    queryParas.Add(ep.T_HR_POST.POSTID);

                    i++;
                }
                filterString += ") OR CREATEUSERID==@" + queryParas.Count().ToString() + ")";
                queryParas.Add(employeeID);
            }

            //看员工
            if (Convert.ToInt32(maxPerm) == Convert.ToInt32(AssignObjectType.Employee))
            {
                if (!string.IsNullOrEmpty(filterString))
                {
                    filterString += " AND ";
                }

                filterString += " (( OWNERID==@" + queryParas.Count().ToString();
                queryParas.Add(employeeID);

                filterString += ") OR CREATEUSERID==@" + queryParas.Count().ToString() + ")";
                queryParas.Add(employeeID);
            }
        }