Ejemplo n.º 1
0
        /// <summary>
        /// 获取指定部门下的指定岗位的任职人员
        /// </summary>
        /// <param name="deptId"></param>
        /// <param name="gparams"></param>
        /// <param name="execDescs"></param>
        /// <returns></returns>
        public PersonInfo GetDutyPerson(string deptId, GetDutyPersonParams gparams, ref List <string> execDescs)
        {
            if (execDescs == null)
            {
                execDescs = new List <string>();
            }
            DeptDutyPersonInfo dept = this.GetCacheItem(deptId);

            if (dept == null)
            {
                execDescs.Add("待查找的部门代码为空!");
                return(null);
            }
            else
            {
                return(dept.GetDutyPerson(gparams, ref execDescs));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 从缓存中查找对象,如果没有则从数据库查找并存到缓存中
        /// </summary>
        /// <param name="deptId_p"></param>
        /// <returns></returns>
        public DeptDutyPersonInfo GetCacheItem(string deptId_p)
        {
            string key = deptId_p;

            DeptDutyPersonInfo value = this.Get <DeptDutyPersonInfo>(key);

            if (value == null)
            {
                //检查部门Bcf中是否有岗位任职从表,有则说明存在部门岗位信息
                if (HasAduitOfDuty == false)
                {
                    return(null);
                }

                LibDataAccess dataAccess = new LibDataAccess();
                string        sql        = string.Format("Select B.DEPTID,B.DEPTNAME,B.SUPERDEPTID, " +
                                                         " E.DUTYID,E.DUTYNAME,E.DUTYLEVEL," +
                                                         " A.PERSONORDER,C.PERSONID,C.PERSONNAME" +
                                                         " From COMDEPT B " + //以部门为主查询表,无论其他是否有,部门都要查到
                                                         " left join COMDEPTDUTYPERSON  A on B.DEPTID=A.DEPTID " +
                                                         " left join COMPERSON C on C.PERSONID=A.PERSONID " +
                                                         " left join COMDUTY E on A.DUTYID=E.DUTYID " +//职务表
                                                         " Where B.DEPTID={0} ",
                                                         LibStringBuilder.GetQuotString(deptId_p));
                using (IDataReader reader = dataAccess.ExecuteDataReader(sql))
                {
                    while (reader.Read())
                    {
                        string deptId       = LibSysUtils.ToString(reader["DEPTID"]);
                        string deptName     = LibSysUtils.ToString(reader["DEPTNAME"]);
                        string parentDeptId = LibSysUtils.ToString(reader["SUPERDEPTID"]);

                        string dutyId    = LibSysUtils.ToString(reader["DUTYID"]);
                        string dutyName  = LibSysUtils.ToString(reader["DUTYNAME"]);
                        int    dutyLevel = LibSysUtils.ToInt32(reader["DUTYLEVEL"]);

                        string personId   = LibSysUtils.ToString(reader["PERSONID"]);
                        string personName = LibSysUtils.ToString(reader["PERSONNAME"]);
                        //对于一个部门中同一岗位下有多个人时,可按照序号从小到大表示职位在部门内的从高到低顺序,例如第一副经理、第二副经理
                        int personOrder = LibSysUtils.ToInt32(reader["PERSONORDER"]);

                        if (value == null)
                        {
                            value = new DeptDutyPersonInfo()
                            {
                                DeptId = deptId, DeptName = deptName, ParentDeptId = parentDeptId
                            }
                        }
                        ;
                        if (string.IsNullOrEmpty(dutyId))
                        {
                            continue;
                        }
                        DutyPeronInfo dutyPerson = value.DutyPersons.Find(item =>
                        {
                            if (item.DutyId.Equals(dutyId))
                            {
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }
                        });
                        if (dutyPerson == null)
                        {
                            dutyPerson = new DutyPeronInfo()
                            {
                                DutyId = dutyId, DutyName = dutyName, DutyLevel = dutyLevel, PersonOrder = personOrder
                            };
                            value.DutyPersons.Add(dutyPerson);
                        }
                        if (personOrder < dutyPerson.PersonOrder)
                        {
                            dutyPerson.PersonOrder = personOrder;
                        }
                        //先按照职级从小到大排序,对于职级相同的不同职位再按位序从大到小排序。方便查找时先找职级低,位序低的人
                        value.DutyPersons = (from item in value.DutyPersons
                                             orderby item.DutyLevel ascending, item.PersonOrder descending
                                             select item).ToList();
                        if (string.IsNullOrEmpty(personId))
                        {
                            continue;
                        }
                        PersonInfo personInfo = dutyPerson.PersonList.Find(person => {
                            if (person.PersonId.Equals(personId))
                            {
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }
                        });
                        if (personInfo == null)
                        {
                            personInfo = new PersonInfo()
                            {
                                PersonId           = personId,
                                PersonName         = personName,
                                PersonOrder        = personOrder,
                                AsBelongDeptId     = deptId,
                                AsBelongDeptName   = deptName,
                                AsBeOfficeDutyId   = dutyId,
                                AsBeOfficeDutyName = dutyName
                            };
                            dutyPerson.PersonList.Add(personInfo);
                            dutyPerson.PersonList = dutyPerson.PersonList.OrderByDescending(p => p.PersonOrder).ToList();//序号从大到小排列,表示先找位序低的人
                        }
                    }
                }

                if (value != null)
                {
                    //180分钟内不访问自动剔除
                    this.Set(key, value, new TimeSpan(0, 180, 0));
                }
            }
            return(value);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 根据岗位Id查找部门下岗位的任职人员
        /// </summary>
        /// <param name="gparams">查找时的参数</param>
        /// <param name="execDescs">执行中的特殊说明</param>
        /// <returns></returns>
        public PersonInfo GetDutyPerson(GetDutyPersonParams gparams, ref List <string> execDescs)
        {
            if (execDescs == null)
            {
                execDescs = new List <string>();
            }
            if (gparams == null)
            {
                execDescs.Add("查找参数集合为空。");
                return(null);
            }
            string dutyId                    = gparams.DutyId;
            int    dutyLevel                 = gparams.DutyLevel;
            bool   isDutyUp                  = gparams.IsDutyUp;
            bool   isDeptUp                  = gparams.IsDeptUp;
            bool   isNotSelf                 = gparams.IsNotSelf;
            bool   isMustHighLevel           = gparams.IsMustHighLevel;
            string submitPersonId            = gparams.SubmitPersonId;
            int    submitPersonMostHighLevel = gparams.SubmitPersonMostHighLevel;

            if (string.IsNullOrEmpty(dutyId))
            {
                execDescs.Add("待查找的岗位代码为空。");
                return(null);
            }
            PersonInfo    person     = null;
            int           index      = 0;
            DutyPeronInfo dutyPerson = null;

            int dutyLevelUpIndex = int.MinValue;//比需要的职位级别高的职位的索引

            //先查找有没有完全匹配的岗位任职人员
            while (index < this.DutyPersons.Count)
            {
                if (dutyLevelUpIndex == int.MinValue && this.DutyPersons[index].DutyLevel >= dutyLevel)
                {
                    dutyLevelUpIndex = index;
                }
                if (this.DutyPersons[index].DutyId.Equals(dutyId))
                {
                    if (isMustHighLevel == false)
                    {
                        dutyPerson = this.DutyPersons[index];
                        break;
                    }
                    else
                    {
                        //如果审核人职级必须要比提交人职级高,则需要继续判断职级
                        if (this.DutyPersons[index].DutyLevel > submitPersonMostHighLevel)
                        {
                            dutyPerson = this.DutyPersons[index];
                            break;
                        }
                        execDescs.Add(string.Format("设定的岗位:{0}级别没有比提交人的最高职级高。{1}", gparams.DutyName, gparams.ProcStepDesc));
                    }
                }
                index++;
            }
            person = GetPerson(dutyPerson, submitPersonId, isNotSelf, ref execDescs);
            if (person == null)
            {
                if (isDutyUp)
                {
                    execDescs.Add(string.Format("目标岗位:{2}。在部门:{0}中执行了岗位上溯。{1}", this.DeptName, gparams.ProcStepDesc, gparams.DutyName));
                    //先岗位上溯
                    if (dutyLevelUpIndex != int.MinValue) //dutyLevelUpIndex=int.MinValue表示当前部门完全没有岗位人员,或者没有比需要的岗位高的
                    {
                        index = dutyLevelUpIndex;         //从当前部门中比目标岗位级别高的岗位开始查找
                        while (index < this.DutyPersons.Count)
                        {
                            dutyPerson = this.DutyPersons[index];
                            person     = GetPerson(dutyPerson, submitPersonId, isNotSelf, ref execDescs);
                            if (person != null)
                            {
                                return(person);
                            }
                            index++;//继续查找本部门下更高岗位
                        }
                    }
                    //本部门的岗位上溯未找到审核人,则从上级部门查找
                    if (isDeptUp)
                    {
                        execDescs.Add(string.Format("目标岗位:{2}。在部门:{0}中执行了部门上溯。{1}", this.DeptName, gparams.ProcStepDesc, gparams.DutyName));
                        if (string.IsNullOrEmpty(this.ParentDeptId) == false)
                        {
                            DeptDutyPersonInfo parnetDeptInfo = LibDeptDutyPersonCache.Default.GetCacheItem(this.ParentDeptId);
                            if (parnetDeptInfo != null)
                            {
                                return(parnetDeptInfo.GetDutyPerson(gparams, ref execDescs));
                            }
                            else
                            {
                                execDescs.Add(string.Format("部门:{0}的上级部门(代码为:{1})的任职信息为空。{2}", this.DeptName, this.ParentDeptId, gparams.ProcStepDesc));
                                return(null);
                            }
                        }
                        else
                        {
                            execDescs.Add(string.Format("部门:{0}的上级部门为空。{1}", this.DeptName, gparams.ProcStepDesc));
                            return(null);
                        }
                    }
                    else
                    {
                        execDescs.Add(string.Format("此步骤:{0}设置为不允许部门上溯。部门:{1}。", gparams.ProcStepDesc, this.DeptName));
                        return(null);//不允许部门上溯或不存在上级部门,且本部门又未找到
                    }
                }
                else
                {
                    execDescs.Add(string.Format("此步骤:{0}设置为不允许岗位上溯。部门:{1}。", gparams.ProcStepDesc, this.DeptName));
                    return(null);//不允许岗位上溯,而且没找到
                }
            }
            else
            {
                return(person);
            }
        }