Esempio n. 1
0
        /// <summary>
        /// 更新离职确认
        /// </summary>
        /// <param name="entity">离职申请记录实体</param>
        public void LeftOfficeConfirmUpdate(T_HR_LEFTOFFICECONFIRM entity)
        {
            try
            {
                //根据离职确认ID查询离职确认表
                T_HR_LEFTOFFICECONFIRM ent = (from c in dal.GetObjects <T_HR_LEFTOFFICECONFIRM>().Include("T_HR_LEFTOFFICE").Include("T_HR_LEFTOFFICE.T_HR_EMPLOYEE").Include("T_HR_LEFTOFFICE.T_HR_EMPLOYEEPOST").Include("T_HR_LEFTOFFICE.T_HR_EMPLOYEEPOST.T_HR_POST")
                                              where c.CONFIRMID == entity.CONFIRMID
                                              select c).FirstOrDefault();

                if (ent != null)
                {
                    //更新离职确认状态
                    dal.UpdateCheckState("T_HR_LEFTOFFICECONFIRM", "CONFIRMID", entity.CONFIRMID, entity.CHECKSTATE);
                    SMT.Foundation.Log.Tracer.Debug(System.DateTime.Now.ToString() + " LeftOfficeConfirmUpdate:" + "1231231");
                    #region 审核通过
                    if (entity.CHECKSTATE == Convert.ToInt32(CheckStates.Approved).ToString())
                    {
                        //根据员工岗位ID查询员工岗位表
                        var employeepost = from ep in dal.GetObjects <T_HR_EMPLOYEEPOST>()
                                           where ep.EMPLOYEEPOSTID == ent.EMPLOYEEPOSTID
                                           select ep;
                        if (employeepost.Count() > 0)
                        {
                            //根据员工ID查询员工基本信息表
                            var employee = (from c in dal.GetObjects <T_HR_EMPLOYEE>()
                                            where c.EMPLOYEEID == ent.EMPLOYEEID
                                            select c).FirstOrDefault();
                            //是否代理:0非代理,1代理岗位
                            if (employeepost.FirstOrDefault().ISAGENCY == "0")
                            {
                                //更新员工状态为离职
                                //string strMsg = "";
                                //EmployeeBLL bll = new EmployeeBLL();
                                //T_HR_EMPLOYEE empoyee = ent.T_HR_LEFTOFFICE.T_HR_EMPLOYEE;
                                //empoyee.EMPLOYEESTATE = "2";
                                //bll.EmployeeUpdate(empoyee, ref strMsg);

                                #region 修改员工基本信息表

                                if (employee != null)
                                {
                                    //员工状态:0试用 1在职 2已离职 3离职中
                                    employee.EMPLOYEESTATE = "2";
                                    //更新员工基本信息表
                                    dal.UpdateFromContext(employee);
                                    dal.SaveContextChanges();
                                }
                                #endregion
                                #region 修改岗位状态
                                //根据员工ID查询员工岗位表
                                var employeeallposts = from epall in dal.GetObjects <T_HR_EMPLOYEEPOST>()
                                                       where epall.EDITSTATE == "1" && epall.T_HR_EMPLOYEE.EMPLOYEEID == ent.EMPLOYEEID
                                                       select epall;
                                if (employeeallposts.Count() > 0)
                                {
                                    foreach (var item in employeeallposts)
                                    {
                                        //if (item.ISAGENCY == "0")
                                        //{
                                        //    item.EDITSTATE = "0";
                                        //    dal.UpdateFromContext(item);
                                        //}
                                        //else
                                        //{
                                        //    dal.DeleteFromContext(item);
                                        //}

                                        //编辑状态:0未生效,1生效中
                                        item.EDITSTATE = "0";
                                        //更新员工岗位表
                                        dal.UpdateFromContext(item);
                                    }
                                    dal.SaveContextChanges();
                                }
                                #endregion
                                #region 添加异动记录
                                //根据岗位ID连表查询岗位表和部门表
                                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 == employeepost.FirstOrDefault().T_HR_POST.POSTID
                                              select new
                                {
                                    c.POSTID,
                                    b.DEPARTMENTID,
                                    b.T_HR_COMPANY.COMPANYID
                                };
                                //by luojie
                                EmployeePostBLL   epostBll = new EmployeePostBLL();
                                T_HR_EMPLOYEEPOST emppost  = (from ep in dal.GetObjects <T_HR_EMPLOYEEPOST>()
                                                              where ep.EMPLOYEEPOSTID == ent.EMPLOYEEPOSTID
                                                              select ep).FirstOrDefault();
                                emppost.CHECKSTATE = Convert.ToInt32(CheckStates.Approved).ToString();
                                emppost.EDITSTATE  = Convert.ToInt32(EditStates.UnActived).ToString();
                                epostBll.EmployeePostUpdate(emppost);
                                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 = employee.EMPLOYEEID;
                                postChange.EMPLOYEECODE             = employee.EMPLOYEECODE;
                                postChange.EMPLOYEENAME             = employee.EMPLOYEECNAME;
                                postChange.POSTCHANGEID             = Guid.NewGuid().ToString();
                                postChange.CHECKSTATE        = Convert.ToInt32(CheckStates.Approved).ToString();
                                postChange.ISAGENCY          = "0";
                                postChange.POSTCHANGCATEGORY = "3";

                                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 = ent.EMPLOYEEID;

                                postChange.POSTCHANGREASON = ent.LEFTOFFICEREASON;
                                postChange.CHANGEDATE      = ent.LEFTOFFICEDATE.ToString();
                                postChange.CREATEUSERID    = ent.CREATEUSERID;
                                string Msg = string.Empty;
                                epchangeBLL.EmployeePostChangeAdd(postChange, ref Msg);
                                #endregion
                                #region 修改社保为无效
                                PensionMasterBLL   penbll  = new PensionMasterBLL();
                                T_HR_PENSIONMASTER pension = penbll.GetPensionMasterByEmployeeID(ent.EMPLOYEEID);
                                if (pension != null)
                                {
                                    pension.ISVALID = "0";
                                    penbll.PensionMasterUpdate(pension);
                                }
                                #endregion
                                #region 修改员工薪资档案
                                //-by luojie 20120910
                                try
                                {
                                    //根据employid查薪资档案。
                                    var salaryArchive = from sa in dal.GetObjects <T_HR_SALARYARCHIVE>()
                                                        where sa.EMPLOYEEID == entity.EMPLOYEEID && sa.CHECKSTATE == "2" && sa.EDITSTATE == "1"
                                                        select sa;
                                    SalaryArchiveBLL salaryArchiveBll = new SalaryArchiveBLL();
                                    if (salaryArchive != null)
                                    {
                                        foreach (var sa in salaryArchive.ToList())
                                        {
                                            sa.EDITSTATE  = "0";// EditStates.UnActived.ToString();
                                            sa.UPDATEDATE = System.DateTime.Now;
                                            salaryArchiveBll.Update(sa);
                                            SMT.Foundation.Log.Tracer.Debug(System.DateTime.Now.ToString() + "LeftOfficeConfirmBll-LeftOfficeConfirmUpdate-薪资档案修改成功:" + sa.SALARYARCHIVEID);
                                        }
                                    }
                                    else
                                    {
                                        SMT.Foundation.Log.Tracer.Debug(System.DateTime.Now.ToString() + "LeftOfficeConfirmBll-LeftOfficeConfirmUpdate-没有可用薪资档案,未修改");
                                    }
                                }
                                catch (Exception ex)
                                {
                                    SMT.Foundation.Log.Tracer.Debug(System.DateTime.Now.ToString() + "LeftOfficeConfirmBll-LeftOfficeConfirmUpdate:" + ex.ToString());
                                }
                                #endregion
                                #region 合同终止
                                EmployeeContractBLL   conbll   = new EmployeeContractBLL();
                                T_HR_EMPLOYEECONTRACT contract = conbll.GetEmployeeContractByEmployeeID(ent.EMPLOYEEID);
                                if (contract != null)
                                {
                                    contract.ENDDATE   = ent.LEFTOFFICEDATE;
                                    contract.EDITSTATE = "0";
                                    conbll.EmployeeContractUpdate(contract);
                                }
                                #endregion
                                #region  除员工合同到期提醒的定时触发
                                List <T_HR_EMPLOYEECONTRACT> contractList = conbll.GetListEmpContractByEmpID(ent.EMPLOYEEID);
                                if (contractList != null && contractList.Count > 0)
                                {
                                    contractList.ForEach(it =>
                                    {
                                        Utility.DeleteTrigger("T_HR_EMPLOYEECONTRACT", it.EMPLOYEECONTACTID);
                                    });
                                }
                                #endregion
                                #region 入职信息设为无效
                                //根据员工ID查询员工入职表
                                var employeeEntrys = from c in dal.GetObjects <T_HR_EMPLOYEEENTRY>()
                                                     where c.T_HR_EMPLOYEE.EMPLOYEEID == ent.EMPLOYEEID && c.EDITSTATE != "2"
                                                     select c;
                                if (employeeEntrys.Count() > 0)
                                {
                                    foreach (var entEntry in employeeEntrys)
                                    {
                                        //编辑状态
                                        entEntry.EDITSTATE = "2";
                                        //更新员工入职表
                                        dal.UpdateFromContext(entEntry);
                                    }
                                    dal.SaveContextChanges();
                                }
                                #endregion
                                #region 人员离职后服务同步 weirui 2012-7-10
                                try
                                {
                                    T_HR_EMPLOYEECHANGEHISTORY employeeEntity = new T_HR_EMPLOYEECHANGEHISTORY();
                                    employeeEntity.RECORDID = Guid.NewGuid().ToString();
                                    //员工ID
                                    //employeeEntity.T_HR_EMPLOYEE.EMPLOYEEID = ent.EMPLOYEEID;
                                    employeeEntity.T_HR_EMPLOYEEReference.EntityKey =
                                        new System.Data.EntityKey(qualifiedEntitySetName + "T_HR_EMPLOYEE", "EMPLOYEEID", ent.EMPLOYEEID);
                                    //员工姓名
                                    employeeEntity.EMPOLYEENAME = ent.EMPLOYEECNAME;
                                    //指纹编号
                                    employeeEntity.FINGERPRINTID = employee.FINGERPRINTID;
                                    //0.入职1.异动2.离职3.薪资级别变更4.签订合同
                                    employeeEntity.FORMTYPE = "2";
                                    //记录原始单据id(员工入职表ID)
                                    employeeEntity.FORMID = ent.CONFIRMID;
                                    //主岗位非主岗位
                                    employeeEntity.ISMASTERPOSTCHANGE = "0";
                                    //包括 异动类型及离职类型 0:1=异动类型:离职类型
                                    employeeEntity.CHANGETYPE = "1";

                                    //异动时间
                                    employeeEntity.CHANGETIME = DateTime.Now;
                                    //异动原因
                                    employeeEntity.CHANGEREASON = ent.LEFTOFFICEREASON;

                                    //异动前岗位id
                                    employeeEntity.OLDPOSTID = ent.EMPLOYEEPOSTID;
                                    //根据异动前岗位ID查找岗位表,查询岗位字典ID
                                    //var oldPostInfo = dal.GetObjects<T_HR_POST>().FirstOrDefault(s => s.POSTID == employeeEntity.OLDPOSTID);
                                    var oldPostInfo = (from c in dal.GetObjects <T_HR_POST>()
                                                       join m in dal.GetObjects <T_HR_POSTDICTIONARY>()
                                                       on c.T_HR_POSTDICTIONARY.POSTDICTIONARYID equals m.POSTDICTIONARYID
                                                       where c.POSTID == ent.OWNERPOSTID
                                                       select new
                                    {
                                        OLDPOSTNAME = m.POSTNAME
                                    }).FirstOrDefault();


                                    if (oldPostInfo != null)
                                    {
                                        //根据岗位字典ID查询字典表,查询岗位名称
                                        //var oldPostDictionary = dal.GetObjects<T_HR_POSTDICTIONARY>().FirstOrDefault(s => s.POSTDICTIONARYID == oldPostInfo.T_HR_POSTDICTIONARY.POSTDICTIONARYID);
                                        //异动前岗位名称
                                        employeeEntity.OLDPOSTNAME = oldPostInfo.OLDPOSTNAME;
                                    }

                                    var employeealName = (from epall in dal.GetObjects <T_HR_EMPLOYEEPOST>()
                                                          where epall.EDITSTATE == "1" && epall.T_HR_EMPLOYEE.EMPLOYEEID == ent.EMPLOYEEID
                                                          select epall).FirstOrDefault();
                                    if (employeealName != null)
                                    {
                                        //异动前岗位级别
                                        employeeEntity.OLDPOSTLEVEL = employeealName.POSTLEVEL.ToString();
                                        //异动前薪资级别
                                        employeeEntity.OLDSALARYLEVEL = employeealName.SALARYLEVEL.ToString();
                                    }

                                    //异动前部门id
                                    employeeEntity.OLDDEPARTMENTID = ent.OWNERDEPARTMENTID;
                                    //根据异动前部门ID查找部门表,查询部门字典ID
                                    //var oldDepartment = dal.GetObjects<T_HR_DEPARTMENT>().FirstOrDefault(s => s.DEPARTMENTID == employeeEntity.OLDDEPARTMENTID);
                                    var oldDepartment = (from c in dal.GetObjects <T_HR_DEPARTMENT>()
                                                         join m in dal.GetObjects <T_HR_DEPARTMENTDICTIONARY>()
                                                         on c.T_HR_DEPARTMENTDICTIONARY.DEPARTMENTDICTIONARYID equals m.DEPARTMENTDICTIONARYID
                                                         where c.DEPARTMENTID == ent.OWNERDEPARTMENTID
                                                         select new
                                    {
                                        OLDDEPARTMENTNAME = m.DEPARTMENTNAME
                                    }).FirstOrDefault();
                                    if (oldDepartment != null)
                                    {
                                        //根据部门字典ID查询部门字典表,查询部门名称
                                        //var oldDepartmentDictionary = dal.GetObjects<T_HR_DEPARTMENTDICTIONARY>().FirstOrDefault(s => s.DEPARTMENTDICTIONARYID == oldDepartment.T_HR_DEPARTMENTDICTIONARY.DEPARTMENTDICTIONARYID);
                                        //异动前部门名称
                                        employeeEntity.OLDDEPARTMENTNAME = oldDepartment.OLDDEPARTMENTNAME;
                                    }

                                    //异动前公司id
                                    employeeEntity.OLDCOMPANYID = ent.OWNERCOMPANYID;
                                    //根据异动前公司ID查找公司表,查询公司字典ID
                                    //var oldCompany = dal.GetObjects<T_HR_COMPANY>().FirstOrDefault(s => s.COMPANYID == employeeEntity.OLDCOMPANYID);
                                    var oldCompany = (from c in dal.GetObjects <T_HR_COMPANY>()
                                                      where c.COMPANYID == ent.OWNERCOMPANYID
                                                      select new
                                    {
                                        OLDCOMPANYNAMECH = c.CNAME,
                                        OLDCOMPANYNAMEEN = c.ENAME
                                    }).FirstOrDefault();
                                    if (oldCompany != null)
                                    {
                                        //根据公司字典ID查询公司字典表,查询公司名称
                                        //var oldCompanyHistory = dal.GetObjects<T_HR_COMPANYHISTORY>().FirstOrDefault(s => s.COMPANYID == oldCompany.COMPANYID);
                                        //异动前公司名称(中文)
                                        employeeEntity.OLDCOMPANYNAME = oldCompany.OLDCOMPANYNAMECH;
                                    }
                                    //备注
                                    employeeEntity.REMART = ent.REMARK;
                                    //创建时间
                                    employeeEntity.CREATEDATE = DateTime.Now;
                                    //所属员工ID
                                    employeeEntity.OWNERID = ent.OWNERID;
                                    //所属岗位ID
                                    employeeEntity.OWNERPOSTID = ent.OWNERPOSTID;
                                    //所属部门ID
                                    employeeEntity.OWNERDEPARTMENTID = ent.OWNERDEPARTMENTID;
                                    //所属公司ID
                                    employeeEntity.OWNERCOMPANYID = ent.OWNERCOMPANYID;
                                    dal.AddToContext(employeeEntity);
                                    dal.SaveContextChanges();
                                }
                                catch (Exception ex)
                                {
                                    SMT.Foundation.Log.Tracer.Debug("员工离职报表服务同步:" + ex.ToString());
                                }
                                #endregion
                                #region 禁用系统用户
                                //SMT.SaaS.BLLCommonServices.PermissionWS.PermissionServiceClient perclient = new SMT.SaaS.BLLCommonServices.PermissionWS.PermissionServiceClient();
                                T_SYS_USER user;
                                using (SysUserBLL bll = new SysUserBLL())
                                {
                                    user = bll.GetUserByEmployeeID(ent.EMPLOYEEID);
                                }
                                if (user != null)
                                {
                                    user.STATE = "0";
                                    //perclient.SysUserInfoUpdate(user);
                                    //by luojie 改为不需要离职申请也直接离职
                                    //if (ent.T_HR_LEFTOFFICE != null && ent.T_HR_LEFTOFFICE.T_HR_EMPLOYEEPOST != null)
                                    if (ent.EMPLOYEEPOSTID != null)
                                    {
                                        //判断要离职的岗位是否为主职
                                        //T_HR_EMPLOYEEPOST中ISAGENCY"0"为主职,"1"为兼职
                                        var LeftEmployeeInfo = (from c in dal.GetObjects <T_HR_EMPLOYEEPOST>()
                                                                where c.EMPLOYEEPOSTID == ent.EMPLOYEEPOSTID
                                                                select c).FirstOrDefault();
                                        bool IsMain = false;
                                        //if (ent.T_HR_LEFTOFFICE.T_HR_EMPLOYEEPOST.ISAGENCY == "0")
                                        if (LeftEmployeeInfo != null && LeftEmployeeInfo.ISAGENCY == "0")
                                        {
                                            IsMain = true;
                                        }

                                        //bool IsSuccess= perclient.SysUserInfoUpdateForEmployeeLeft(user, ent.T_HR_LEFTOFFICE.OWNERCOMPANYID,ent.T_HR_LEFTOFFICE.T_HR_EMPLOYEEPOST.EMPLOYEEPOSTID,IsMain);
                                        bool IsSuccess = false;// perclient.SysUserInfoUpdateForEmployeeLeft(user, ent.OWNERCOMPANYID, ent.EMPLOYEEPOSTID, IsMain);
                                        using (SysUserBLL UserBll = new SysUserBLL())
                                        {
                                            IsSuccess = UserBll.UpdateSysUserInfoForEmployeeLeftOffice(user, ent.OWNERCOMPANYID, ent.EMPLOYEEPOSTID, IsMain);
                                        }

                                        string StrResult = "";
                                        if (IsSuccess)
                                        {
                                            StrResult = "成功";
                                        }
                                        else
                                        {
                                            StrResult = "失败";
                                        }
                                        SMT.Foundation.Log.Tracer.Debug("员工离职更新权限系统用户状态为" + System.DateTime.Now.ToString() + ":" + StrResult);
                                    }
                                    else
                                    {
                                        SMT.Foundation.Log.Tracer.Debug("员工离职对象为空" + System.DateTime.Now.ToString());
                                    }
                                }
                                #endregion
                            }
                            else
                            {
                                #region 修改岗位状态
                                //根据员工ID查询员工岗位表
                                var employeeallposts = from epall in dal.GetObjects <T_HR_EMPLOYEEPOST>()
                                                       where epall.EDITSTATE == "1" && epall.EMPLOYEEPOSTID == ent.EMPLOYEEPOSTID
                                                       select epall;
                                if (employeeallposts.Count() > 0)
                                {
                                    foreach (var item in employeeallposts)
                                    {
                                        //if (item.ISAGENCY == "0")
                                        //{
                                        //    item.EDITSTATE = "0";
                                        //    dal.UpdateFromContext(item);
                                        //}
                                        //else
                                        //{
                                        //    dal.DeleteFromContext(item);
                                        //}

                                        //编辑状态:0未生效,1生效中
                                        item.EDITSTATE = "0";
                                        //更新员工岗位表
                                        dal.UpdateFromContext(item);
                                    }
                                    dal.SaveContextChanges();
                                }
                                #endregion
                                #region 添加异动记录
                                //根据岗位ID连表查询岗位表和部门表
                                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 == employeepost.FirstOrDefault().T_HR_POST.POSTID
                                              select new
                                {
                                    c.POSTID,
                                    b.DEPARTMENTID,
                                    b.T_HR_COMPANY.COMPANYID
                                };
                                //by luojie
                                EmployeePostBLL   epostBll = new EmployeePostBLL();
                                T_HR_EMPLOYEEPOST emppost  = (from ep in dal.GetObjects <T_HR_EMPLOYEEPOST>()
                                                              where ep.EMPLOYEEPOSTID == ent.EMPLOYEEPOSTID
                                                              select ep).FirstOrDefault();
                                emppost.CHECKSTATE = Convert.ToInt32(CheckStates.Approved).ToString();
                                emppost.EDITSTATE  = Convert.ToInt32(EditStates.UnActived).ToString();
                                epostBll.EmployeePostUpdate(emppost);
                                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 = employee.EMPLOYEEID;
                                postChange.EMPLOYEECODE             = employee.EMPLOYEECODE;
                                postChange.EMPLOYEENAME             = employee.EMPLOYEECNAME;
                                postChange.POSTCHANGEID             = Guid.NewGuid().ToString();
                                postChange.CHECKSTATE        = Convert.ToInt32(CheckStates.Approved).ToString();
                                postChange.ISAGENCY          = "0";
                                postChange.POSTCHANGCATEGORY = "3";

                                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 = ent.EMPLOYEEID;

                                postChange.POSTCHANGREASON = ent.LEFTOFFICEREASON;
                                postChange.CHANGEDATE      = ent.LEFTOFFICEDATE.ToString();
                                postChange.CREATEUSERID    = ent.CREATEUSERID;
                                string Msg = string.Empty;
                                epchangeBLL.EmployeePostChangeAdd(postChange, ref Msg);
                                #endregion
                            }
                        }
                        else
                        {
                            Tracer.Debug("员工离职确认,通过EMPLOYEEPOSTID未找到员工岗位记录:" + ent.EMPLOYEEPOSTID);
                        }
                    }
                    # endregion
                    Utility.CloneEntity <T_HR_LEFTOFFICECONFIRM>(entity, ent);
                    if (entity.T_HR_LEFTOFFICE != null)
                    {
                        ent.T_HR_LEFTOFFICEReference.EntityKey =
                            new System.Data.EntityKey(qualifiedEntitySetName + "T_HR_LEFTOFFICE", "DIMISSIONID", entity.T_HR_LEFTOFFICE.DIMISSIONID);
                    }
                    //dal.Update(ent);

                    Update(ent, ent.CREATEUSERID);
                }
            }
Esempio n. 2
0
 public string EmployeePostUpdate(T_HR_EMPLOYEEPOST entity)
 {
     using (EmployeePostBLL bll = new EmployeePostBLL())
     {
         return bll.EmployeePostUpdate(entity);
     }
 }
Esempio n. 3
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;
                T_SYS_USER sysuser    = new T_SYS_USER();//perclient.GetUserByEmployeeID(employeeId);
                using (SysUserBLL bll = new SysUserBLL())
                {
                    sysuser = bll.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>");
                            //查出用户的所有角色
                            List <T_SYS_USERROLE> roleUserList = new List <T_SYS_USERROLE>(); //perclient.GetSysUserRoleByUser(sysuser.SYSUSERID).ToList();
                            using (SysUserRoleBLL bll = new SysUserRoleBLL())
                            {
                                roleUserList = bll.GetSysUserRoleByUser(sysuser.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;
                                    List <T_SYS_USER> roleUserIncludeSource = new List <T_SYS_USER>();// perclient.GetSysUserByRoleToEmployeeLeave(roleId);

                                    using (SysUserRoleBLL bll = new SysUserRoleBLL())
                                    {
                                        roleUserIncludeSource = bll.GetSysUserByRole(roleId).ToList();
                                    }
                                    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;
                                    List <T_SYS_USER> flowManagers; //perclient.GetFlowManagers(new string[] { entity.T_HR_EMPLOYEE.OWNERCOMPANYID });
                                    using (SysPermissionBLL bll = new SysPermissionBLL())
                                    {
                                        flowManagers = bll.GetFlowManagers(new List <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;
            }
        }