<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.qy.worksheetsystem.model.mapper.ProjectMapper">

    <select id="getProjectListSingle" resultType="java.util.Map">
        select top 1 p.fid pid,p.fnumber pNumber,p.fname_l2 pName,
               org.FID orgId,org.FName_L2 orgName,org.FNumber orgNumber,
               CONVERT(varchar(10) , org.FEFFDT, 120 ) beginDate,
               CONVERT(varchar(10) , org.FLEFFDT, 120 ) endDate,
               isnull(org.FResponPositionID,post2.fid) responPositionID,org.FParentID,
               p2.fid managerId,p2.fname_l2 managerName,p2.fnumber managerNumber
        from t_bd_person p
                 left join T_HR_PERSONPOSITION pp on pp.fpersonid=p.fid
                 left join T_ORG_Admin org on org.fid=pp.FPersonDep
                 left join T_ORG_POSITION post on post.fid=pp.FPrimaryPositionID
                 left join T_ORG_POSITION post2 on post2.FAdminOrgUnitID = org.FParentID and post2.FIsRespPosition=1
                 left join T_HR_PERSONPOSITION pp2 on pp2.FPrimaryPositionID=isnull(org.FResponPositionID,post2.fid)
                 left join t_bd_person p2 on p2.fid=pp2.fpersonid
        where p.fnumber=#{number}
        <if test='id != null and id != ""'>
            and pp.FPersonDep=#{id}
        </if>
    </select>
    <select id="getProjectList" resultType="java.util.Map">
        select p.fid pid,p.fnumber pNumber,p.fname_l2 pName,
        org.FID orgId,(org2.fname_l2+'_'+org.FName_L2) orgName,org.FNumber orgNumber,
        CONVERT(varchar(10) , org.FEFFDT, 120 ) beginDate,
        CONVERT(varchar(10), org.FLEFFDT, 120 ) endDate,
        isnull(org.FResponPositionID,post2.fid) responPositionID,org.FParentID,
        p2.fid managerId,p2.fname_l2 managerName,p2.fnumber managerNumber,
        CONVERT(varchar(10) ,isnull(pp1.FEnterDate,''), 120 ) enterDate, post.fname_l2,wuser.userid wxUserId
        from t_bd_person p
        INNER join T_HR_EmpOrgRelation pp on pp.fpersonid=p.fid and pp.FLEFFDT='2199-12-31' and pp.FASSIGNTYPE=1
        INNER join T_HR_PERSONPOSITION pp1 on pp1.fpersonid=p.fid
        INNER join T_HR_EMPLABORRELATION ppp2 on ppp2.FPersonID=p.fid
        INNER join T_ORG_Admin org on org.fid=pp.FADMINORGID
        INNER join T_ORG_Admin org2 on org.FParentID=org2.fid
        INNER join T_ORG_POSITION post on post.fid=pp.FPOSITIONID
        left join T_ORG_POSITION post2 on post2.fid=post.FParentID
        left join T_HR_EmpOrgRelation parp on parp.FPositionID = post.FParentID and parp.FLEFFDT='2199-12-31' and parp.FASSIGNTYPE=1
        left join t_bd_person p2 on p2.fid=parp.fpersonid
        left join ct_wx_user wuser on wuser.number=p2.fnumber
        where p.fnumber=#{number}  and p2.fid is not null
        <if test='OrgNumber != null and OrgNumber != ""'>
            and pp1.FPersonDep in(select child.fid from T_ORG_Admin adcount
            left join T_ORG_Admin child on (charindex(adcount.flongnumber+'!',child.flongnumber) = 1 or adcount.flongnumber = child.flongnumber)
            where adcount.fnumber=#{OrgNumber})
        </if>

        <if test='id != null and id != ""'>
            and pp1.FPersonDep=#{id}
        </if>
        union
        select p.fid pid,p.fnumber pNumber,p.fname_l2 pName,
        org.FID orgId,(org2.fname_l2+'_'+org.FName_L2) orgName,org.FNumber orgNumber,
        CONVERT(varchar(10) , org.FEFFDT, 120 ) beginDate,
        CONVERT(varchar(10), org.FLEFFDT, 120 ) endDate,
        isnull(org.FResponPositionID,post2.fid) responPositionID,org.FParentID,
        p2.fid managerId,p2.fname_l2 managerName,p2.fnumber managerNumber,
        CONVERT(varchar(10) ,isnull(pp1.FEnterDate,''), 120 ) enterDate, post.fname_l2,wuser.userid wxUserId
        from t_bd_person p
        INNER join T_HR_EmpOrgRelation pp on pp.fpersonid=p.fid and pp.FLEFFDT='2199-12-31' and pp.FASSIGNTYPE=1
        INNER join T_HR_PERSONPOSITION pp1 on pp1.fpersonid=p.fid
        INNER join T_HR_EMPLABORRELATION ppp2 on ppp2.FPersonID=p.fid
        INNER join T_ORG_Admin org on org.fid=pp.FADMINORGID
        INNER join T_ORG_Admin org2 on org.FParentID=org2.fid
        INNER join T_ORG_POSITION post on post.fid=pp.FPOSITIONID
        left join T_ORG_POSITION post2 on post2.fid=post.FParentID
        left join T_HR_EmpOrgRelation parp on parp.FPositionID = post.FParentID and parp.FLEFFDT='2199-12-31' and parp.FASSIGNTYPE=0
        left join t_bd_person p2 on p2.fid=parp.fpersonid
        left join ct_wx_user wuser on wuser.number=p2.fnumber
        where p.fnumber=#{number}  and p2.fid is not null
        <if test='OrgNumber != null and OrgNumber != ""'>
            and pp1.FPersonDep in(select child.fid from T_ORG_Admin adcount
            left join T_ORG_Admin child on (charindex(adcount.flongnumber+'!',child.flongnumber) = 1 or adcount.flongnumber = child.flongnumber)
            where adcount.fnumber=#{OrgNumber})
        </if>

        <if test='id != null and id != ""'>
            and pp1.FPersonDep=#{id}
        </if>
        union
        select p.fid pid,p.fnumber pNumber,p.fname_l2 pName,
        org.FID orgId,(org2.fname_l2+'_'+org.FName_L2) orgName,org.FNumber orgNumber,
        CONVERT(varchar(10) , org.FEFFDT, 120 ) beginDate,
        CONVERT(varchar(10), org.FLEFFDT, 120 ) endDate,
        isnull(org.FResponPositionID,post2.fid) responPositionID,org.FParentID,
        p2.fid managerId,p2.fname_l2 managerName,p2.fnumber managerNumber,
        CONVERT(varchar(10) ,isnull(pp1.FEnterDate,''), 120 ) enterDate,
        post.fname_l2,wuser.userid wxUserId
        from t_bd_person p
        INNER join T_HR_EmpOrgRelation pp on pp.fpersonid=p.fid and pp.FLEFFDT='2199-12-31' and pp.FASSIGNTYPE=0
        INNER join T_HR_PERSONPOSITION pp1 on pp1.fpersonid=p.fid
        INNER join T_HR_EMPLABORRELATION ppp2 on ppp2.FPersonID=p.fid
        INNER join T_ORG_Admin org on org.fid=pp.FADMINORGID
        INNER join T_ORG_Admin org2 on org.FParentID=org2.fid
        INNER join T_ORG_POSITION post on post.fid=pp.FPOSITIONID
        left join T_ORG_POSITION post2 on post2.fid=post.FParentID
        left join T_HR_EmpOrgRelation parp on parp.FPositionID = post.FParentID and parp.FLEFFDT='2199-12-31' and parp.FASSIGNTYPE=0
        left join t_bd_person p2 on p2.fid=parp.fpersonid
        left join ct_wx_user wuser on wuser.number=p2.fnumber
        where p.fnumber=#{number}  and p2.fid is not null
        <if test='OrgNumber != null and OrgNumber != ""'>
            and pp1.FPersonDep in(select child.fid from T_ORG_Admin adcount
            left join T_ORG_Admin child on (charindex(adcount.flongnumber+'!',child.flongnumber) = 1 or adcount.flongnumber = child.flongnumber)
            where adcount.fnumber=#{OrgNumber})
        </if>

        <if test='id != null and id != ""'>
            and pp1.FPersonDep=#{id}
        </if>
        union
        select p.fid pid,p.fnumber pNumber,p.fname_l2 pName,
        org.FID orgId,(org2.fname_l2+'_'+org.FName_L2) orgName,org.FNumber orgNumber,
        CONVERT(varchar(10) , org.FEFFDT, 120 ) beginDate,
        CONVERT(varchar(10), org.FLEFFDT, 120 ) endDate,
        isnull(org.FResponPositionID,post2.fid) responPositionID,org.FParentID,
        p2.fid managerId,p2.fname_l2 managerName,p2.fnumber managerNumber,
        CONVERT(varchar(10) ,isnull(pp1.FEnterDate,''), 120 ) enterDate, post.fname_l2,
        wuser.userid wxUserId
        from t_bd_person p
        INNER join T_HR_EmpOrgRelation pp on pp.fpersonid=p.fid and pp.FLEFFDT='2199-12-31' and pp.FASSIGNTYPE=0
        INNER join T_HR_PERSONPOSITION pp1 on pp1.fpersonid=p.fid
        INNER join T_HR_EMPLABORRELATION ppp2 on ppp2.FPersonID=p.fid
        INNER join T_ORG_Admin org on org.fid=pp.FADMINORGID
        INNER join T_ORG_Admin org2 on org.FParentID=org2.fid
        INNER join T_ORG_POSITION post on post.fid=pp.FPOSITIONID
        left join T_ORG_POSITION post2 on post2.fid=post.FParentID
        left join T_HR_EmpOrgRelation parp on parp.FPositionID = post.FParentID and parp.FLEFFDT='2199-12-31' and parp.FASSIGNTYPE=1
        left join t_bd_person p2 on p2.fid=parp.fpersonid
        left join ct_wx_user wuser on wuser.number=p2.fnumber
        where p.fnumber=#{number}  and p2.fid is not null
        <if test='OrgNumber != null and OrgNumber != ""'>
            and pp1.FPersonDep in(select child.fid from T_ORG_Admin adcount
            left join T_ORG_Admin child on (charindex(adcount.flongnumber+'!',child.flongnumber) = 1 or adcount.flongnumber = child.flongnumber)
            where adcount.fnumber=#{OrgNumber})
        </if>

        <if test='id != null and id != ""'>
            and pp1.FPersonDep=#{id}
        </if>
    </select>
    <select id="getProjectListV2" resultType="java.util.Map">
        select p.fid pid,p.fnumber pNumber,p.fname_l2 pName,
        org.FID orgId,(org2.fname_l2+'_'+org.FName_L2) orgName,org.FNumber orgNumber,
        CONVERT(varchar(10) , org.FEFFDT, 120 ) beginDate,
        CONVERT(varchar(10), org.FLEFFDT, 120 ) endDate,
        isnull(org.FResponPositionID,post2.fid) responPositionID,org.FParentID,
        p2.fid managerId,p2.fname_l2 managerName,p2.fnumber managerNumber,
        CONVERT(varchar(10) ,isnull(pp1.FEnterDate,''), 120 ) enterDate, post.fname_l2,wuser.userid wxUserId
        from t_bd_person p
        INNER join T_HR_EmpOrgRelation pp on pp.fpersonid=p.fid and pp.FLEFFDT='2199-12-31' and pp.FASSIGNTYPE=0
        INNER join T_HR_PERSONPOSITION pp1 on pp1.fpersonid=p.fid
        INNER join T_HR_EMPLABORRELATION ppp2 on ppp2.FPersonID=p.fid
        INNER join T_ORG_Admin org on org.fid=pp.FADMINORGID
        INNER join T_ORG_Admin org2 on org.FParentID=org2.fid
        INNER join T_ORG_POSITION post on post.fid=pp.FPOSITIONID
        left join T_ORG_POSITION post2 on post2.fid=post.FParentID
        INNER join CT_WK_ManagerInfo mg on mg.CFPersonID=p.fid
        left join t_bd_person p2 on p2.fid=mg.CFManagerID
        left join ct_wx_user wuser on wuser.number=p2.fnumber
        where p.fnumber=#{number}  and p2.fid is not null
        <if test='OrgNumber != null and OrgNumber != ""'>
            and pp1.FPersonDep in(select child.fid from T_ORG_Admin adcount
            left join T_ORG_Admin child on (charindex(adcount.flongnumber+'!',child.flongnumber) = 1 or adcount.flongnumber = child.flongnumber)
            where adcount.fnumber=#{OrgNumber})
        </if>

        <if test='id != null and id != ""'>
            and pp1.FPersonDep=#{id}
        </if>
        union
        select p.fid pid,p.fnumber pNumber,p.fname_l2 pName,
        org.FID orgId,(org2.fname_l2+'_'+org.FName_L2) orgName,org.FNumber orgNumber,
        CONVERT(varchar(10) , org.FEFFDT, 120 ) beginDate,
        CONVERT(varchar(10), org.FLEFFDT, 120 ) endDate,
        isnull(org.FResponPositionID,post2.fid) responPositionID,org.FParentID,
        p2.fid managerId,p2.fname_l2 managerName,p2.fnumber managerNumber,
        CONVERT(varchar(10) ,isnull(pp1.FEnterDate,''), 120 ) enterDate, post.fname_l2,wuser.userid wxUserId
        from t_bd_person p
        INNER join T_HR_EmpOrgRelation pp on pp.fpersonid=p.fid and pp.FLEFFDT='2199-12-31' and pp.FASSIGNTYPE=1
        INNER join T_HR_PERSONPOSITION pp1 on pp1.fpersonid=p.fid
        INNER join T_HR_EMPLABORRELATION ppp2 on ppp2.FPersonID=p.fid
        INNER join T_ORG_Admin org on org.fid=pp.FADMINORGID
        INNER join T_ORG_Admin org2 on org.FParentID=org2.fid
        INNER join T_ORG_POSITION post on post.fid=pp.FPOSITIONID
        left join T_ORG_POSITION post2 on post2.fid=post.FParentID
        INNER join CT_WK_ManagerInfo mg on mg.CFPersonID=p.fid
        left join t_bd_person p2 on p2.fid=mg.CFManagerID
        left join ct_wx_user wuser on wuser.number=p2.fnumber
        where p.fnumber=#{number}  and p2.fid is not null
        <if test='OrgNumber != null and OrgNumber != ""'>
            and pp1.FPersonDep in(select child.fid from T_ORG_Admin adcount
            left join T_ORG_Admin child on (charindex(adcount.flongnumber+'!',child.flongnumber) = 1 or adcount.flongnumber = child.flongnumber)
            where adcount.fnumber=#{OrgNumber})
        </if>

        <if test='id != null and id != ""'>
            and pp1.FPersonDep=#{id}
        </if>
    </select>
    <select id="getProjectListToChildV2" resultType="java.util.Map">
        select p.fid pid,p.fnumber pNumber,p.fname_l2 pName,
        org.FID orgId,(org2.fname_l2+'_'+org.FName_L2) orgName,org.FNumber orgNumber,
        CONVERT(varchar(10) , org.FEFFDT, 120 ) beginDate,
        CONVERT(varchar(10), org.FLEFFDT, 120 ) endDate,
        isnull(org.FResponPositionID,post2.fid) responPositionID,org.FParentID,
        p2.fid managerId,p2.fname_l2 managerName,p2.fnumber managerNumber,
        CONVERT(varchar(10) ,isnull(pp1.FEnterDate,''), 120 ) enterDate, post.fname_l2,wuser.userid wxUserId
        from t_bd_person p
        INNER join T_HR_EmpOrgRelation pp on pp.fpersonid=p.fid and pp.FLEFFDT='2199-12-31' and pp.FASSIGNTYPE=1
        INNER join T_HR_PERSONPOSITION pp1 on pp1.fpersonid=p.fid
        INNER join T_HR_EMPLABORRELATION ppp2 on ppp2.FPersonID=p.fid
        INNER join T_ORG_Admin org on org.fid=pp.FADMINORGID
        INNER join T_ORG_Admin org2 on org.FParentID=org2.fid
        INNER join T_ORG_POSITION post on post.fid=pp.FPOSITIONID
        left join T_ORG_POSITION post2 on post2.fid=post.FParentID
        INNER join CT_WK_ManagerInfo mg on mg.CFPersonID=p.fid
        INNER join t_bd_person p2 on p2.fid=mg.CFManagerID
        left join ct_wx_user wuser on wuser.number=p2.fnumber
        where p2.fnumber=#{number}  and p2.fid is not null
        <if test='OrgNumber != null and OrgNumber != ""'>
            and pp1.FPersonDep in(select child.fid from T_ORG_Admin adcount
            left join T_ORG_Admin child on (charindex(adcount.flongnumber+'!',child.flongnumber) = 1 or adcount.flongnumber = child.flongnumber)
            where adcount.fnumber=#{OrgNumber})
        </if>

        <if test='id != null and id != ""'>
            and pp1.FPersonDep=#{id}
        </if>
        union
        select p.fid pid,p.fnumber pNumber,p.fname_l2 pName,
        org.FID orgId,(org2.fname_l2+'_'+org.FName_L2) orgName,org.FNumber orgNumber,
        CONVERT(varchar(10) , org.FEFFDT, 120 ) beginDate,
        CONVERT(varchar(10), org.FLEFFDT, 120 ) endDate,
        isnull(org.FResponPositionID,post2.fid) responPositionID,org.FParentID,
        p2.fid managerId,p2.fname_l2 managerName,p2.fnumber managerNumber,
        CONVERT(varchar(10) ,isnull(pp1.FEnterDate,''), 120 ) enterDate, post.fname_l2,wuser.userid wxUserId
        from t_bd_person p
        INNER join T_HR_EmpOrgRelation pp on pp.fpersonid=p.fid and pp.FLEFFDT='2199-12-31' and pp.FASSIGNTYPE=0
        INNER join T_HR_PERSONPOSITION pp1 on pp1.fpersonid=p.fid
        INNER join T_HR_EMPLABORRELATION ppp2 on ppp2.FPersonID=p.fid
        INNER join T_ORG_Admin org on org.fid=pp.FADMINORGID
        INNER join T_ORG_Admin org2 on org.FParentID=org2.fid
        INNER join T_ORG_POSITION post on post.fid=pp.FPOSITIONID
        left join T_ORG_POSITION post2 on post2.fid=post.FParentID
        INNER join CT_WK_ManagerInfo mg on mg.CFPersonID=p.fid
        INNER join t_bd_person p2 on p2.fid=mg.CFManagerID
        left join ct_wx_user wuser on wuser.number=p2.fnumber
        where p2.fnumber=#{number}  and p2.fid is not null
        <if test='OrgNumber != null and OrgNumber != ""'>
            and pp1.FPersonDep in(select child.fid from T_ORG_Admin adcount
            left join T_ORG_Admin child on (charindex(adcount.flongnumber+'!',child.flongnumber) = 1 or adcount.flongnumber = child.flongnumber)
            where adcount.fnumber=#{OrgNumber})
        </if>

        <if test='id != null and id != ""'>
            and pp1.FPersonDep=#{id}
        </if>

    </select>
    <select id="getProjectListToChildV2ByPid" resultType="java.lang.String">
        select p.fid pid
        from t_bd_person p
        INNER join T_HR_EmpOrgRelation pp on pp.fpersonid=p.fid and pp.FLEFFDT='2199-12-31' and pp.FASSIGNTYPE=1

        INNER join T_ORG_Admin org on org.fid=pp.FADMINORGID
        INNER join T_ORG_Admin org2 on org.FParentID=org2.fid
        INNER join T_ORG_POSITION post on post.fid=pp.FPOSITIONID
        left join T_ORG_POSITION post2 on post2.fid=post.FParentID
        INNER join CT_WK_ManagerInfo mg on mg.CFPersonID=p.fid
        INNER join t_bd_person p2 on p2.fid=mg.CFManagerID

        where p2.fnumber=#{number}  and p2.fid is not null
        <if test='OrgNumber != null and OrgNumber != ""'>
            and pp1.FPersonDep in(select child.fid from T_ORG_Admin adcount
            left join T_ORG_Admin child on (charindex(adcount.flongnumber+'!',child.flongnumber) = 1 or adcount.flongnumber = child.flongnumber)
            where adcount.fnumber=#{OrgNumber})
        </if>

        <if test='id != null and id != ""'>
            and pp.FADMINORGID=#{id}
        </if>
        union
        select p.fid pid
        from t_bd_person p
        INNER join T_HR_EmpOrgRelation pp on pp.fpersonid=p.fid and pp.FLEFFDT='2199-12-31' and pp.FASSIGNTYPE=0

        INNER join T_ORG_Admin org on org.fid=pp.FADMINORGID
        INNER join T_ORG_Admin org2 on org.FParentID=org2.fid
        INNER join T_ORG_POSITION post on post.fid=pp.FPOSITIONID
        left join T_ORG_POSITION post2 on post2.fid=post.FParentID
        INNER join CT_WK_ManagerInfo mg on mg.CFPersonID=p.fid
        INNER join t_bd_person p2 on p2.fid=mg.CFManagerID

        where p2.fnumber=#{number}  and p2.fid is not null
        <if test='OrgNumber != null and OrgNumber != ""'>
            and pp1.FPersonDep in(select child.fid from T_ORG_Admin adcount
            left join T_ORG_Admin child on (charindex(adcount.flongnumber+'!',child.flongnumber) = 1 or adcount.flongnumber = child.flongnumber)
            where adcount.fnumber=#{OrgNumber})
        </if>

        <if test='id != null and id != ""'>
            and pp.FADMINORGID=#{id}
        </if>

    </select>
    <select id="getProjectListToChild" resultType="java.util.Map">
        select p.fid pid,p.fnumber pNumber,p.fname_l2 pName,
        org.FID orgId,(org2.fname_l2+'_'+org.FName_L2) orgName,org.FNumber orgNumber,
        CONVERT(varchar(10) , org.FEFFDT, 120 ) beginDate,
        CONVERT(varchar(10), org.FLEFFDT, 120 ) endDate,
        isnull(org.FResponPositionID,post2.fid) responPositionID,org.FParentID,
        p2.fid managerId,p2.fname_l2 managerName,p2.fnumber managerNumber,
        CONVERT(varchar(10) ,isnull(pp1.FEnterDate,''), 120 ) enterDate, post.fname_l2,wuser.userid wxUserId
        from t_bd_person p
        INNER join T_HR_EmpOrgRelation pp on pp.fpersonid=p.fid and pp.FLEFFDT='2199-12-31' and pp.FASSIGNTYPE=1
        INNER join T_HR_PERSONPOSITION pp1 on pp1.fpersonid=p.fid
        INNER join T_HR_EMPLABORRELATION ppp2 on ppp2.FPersonID=p.fid
        INNER join T_ORG_Admin org on org.fid=pp.FADMINORGID
        INNER join T_ORG_Admin org2 on org.FParentID=org2.fid
        INNER join T_ORG_POSITION post on post.fid=pp.FPOSITIONID

        left join T_ORG_POSITION post2 on post2.fid=post.FParentID
        left join T_HR_EmpOrgRelation parp on parp.FPositionID = post.FParentID and parp.FLEFFDT='2199-12-31' and parp.FASSIGNTYPE=1
        left join t_bd_person p2 on p2.fid=parp.fpersonid
        left join ct_wx_user wuser on wuser.number=p2.fnumber
        where p2.fnumber=#{number}  and p2.fid is not null
        <if test='OrgNumber != null and OrgNumber != ""'>
            and pp1.FPersonDep in(select child.fid from T_ORG_Admin adcount
            left join T_ORG_Admin child on (charindex(adcount.flongnumber+'!',child.flongnumber) = 1 or adcount.flongnumber = child.flongnumber)
            where adcount.fnumber=#{OrgNumber})
        </if>

        <if test='id != null and id != ""'>
            and pp1.FPersonDep=#{id}
        </if>
        union
        select p.fid pid,p.fnumber pNumber,p.fname_l2 pName,
        org.FID orgId,(org2.fname_l2+'_'+org.FName_L2) orgName,org.FNumber orgNumber,
        CONVERT(varchar(10) , org.FEFFDT, 120 ) beginDate,
        CONVERT(varchar(10), org.FLEFFDT, 120 ) endDate,
        isnull(org.FResponPositionID,post2.fid) responPositionID,org.FParentID,
        p2.fid managerId,p2.fname_l2 managerName,p2.fnumber managerNumber,
        CONVERT(varchar(10) ,isnull(pp1.FEnterDate,''), 120 ) enterDate, post.fname_l2,wuser.userid wxUserId
        from t_bd_person p
        INNER join T_HR_EmpOrgRelation pp on pp.fpersonid=p.fid and pp.FLEFFDT='2199-12-31' and pp.FASSIGNTYPE=1
        INNER join T_HR_PERSONPOSITION pp1 on pp1.fpersonid=p.fid
        INNER join T_HR_EMPLABORRELATION ppp2 on ppp2.FPersonID=p.fid
        INNER join T_ORG_Admin org on org.fid=pp.FADMINORGID
        INNER join T_ORG_Admin org2 on org.FParentID=org2.fid
        INNER join T_ORG_POSITION post on post.fid=pp.FPOSITIONID
        left join T_ORG_POSITION post2 on post2.fid=post.FParentID
        left join T_HR_EmpOrgRelation parp on parp.FPositionID = post.FParentID and parp.FLEFFDT='2199-12-31' and parp.FASSIGNTYPE=0
        left join t_bd_person p2 on p2.fid=parp.fpersonid
        left join ct_wx_user wuser on wuser.number=p2.fnumber
        where p2.fnumber=#{number}  and p2.fid is not null
        <if test='OrgNumber != null and OrgNumber != ""'>
            and pp1.FPersonDep in(select child.fid from T_ORG_Admin adcount
            left join T_ORG_Admin child on (charindex(adcount.flongnumber+'!',child.flongnumber) = 1 or adcount.flongnumber = child.flongnumber)
            where adcount.fnumber=#{OrgNumber})
        </if>

        <if test='id != null and id != ""'>
            and pp1.FPersonDep=#{id}
        </if>
        union
        select p.fid pid,p.fnumber pNumber,p.fname_l2 pName,
        org.FID orgId,(org2.fname_l2+'_'+org.FName_L2) orgName,org.FNumber orgNumber,
        CONVERT(varchar(10) , org.FEFFDT, 120 ) beginDate,
        CONVERT(varchar(10), org.FLEFFDT, 120 ) endDate,
        isnull(org.FResponPositionID,post2.fid) responPositionID,org.FParentID,
        p2.fid managerId,p2.fname_l2 managerName,p2.fnumber managerNumber,
        CONVERT(varchar(10) ,isnull(pp1.FEnterDate,''), 120 ) enterDate,
        post.fname_l2,wuser.userid wxUserId
        from t_bd_person p
        INNER join T_HR_EmpOrgRelation pp on pp.fpersonid=p.fid and pp.FLEFFDT='2199-12-31' and pp.FASSIGNTYPE=0
        INNER join T_HR_PERSONPOSITION pp1 on pp1.fpersonid=p.fid
        INNER join T_HR_EMPLABORRELATION ppp2 on ppp2.FPersonID=p.fid
        INNER join T_ORG_Admin org on org.fid=pp.FADMINORGID
        INNER join T_ORG_Admin org2 on org.FParentID=org2.fid
        INNER join T_ORG_POSITION post on post.fid=pp.FPOSITIONID
        left join T_ORG_POSITION post2 on post2.fid=post.FParentID
        left join T_HR_EmpOrgRelation parp on parp.FPositionID = post.FParentID and parp.FLEFFDT='2199-12-31' and parp.FASSIGNTYPE=0
        left join t_bd_person p2 on p2.fid=parp.fpersonid
        left join ct_wx_user wuser on wuser.number=p2.fnumber
        where p2.fnumber=#{number}  and p2.fid is not null
        <if test='OrgNumber != null and OrgNumber != ""'>
            and pp1.FPersonDep in(select child.fid from T_ORG_Admin adcount
            left join T_ORG_Admin child on (charindex(adcount.flongnumber+'!',child.flongnumber) = 1 or adcount.flongnumber = child.flongnumber)
            where adcount.fnumber=#{OrgNumber})
        </if>

        <if test='id != null and id != ""'>
            and pp1.FPersonDep=#{id}
        </if>
        union
        select p.fid pid,p.fnumber pNumber,p.fname_l2 pName,
        org.FID orgId,(org2.fname_l2+'_'+org.FName_L2) orgName,org.FNumber orgNumber,
        CONVERT(varchar(10) , org.FEFFDT, 120 ) beginDate,
        CONVERT(varchar(10), org.FLEFFDT, 120 ) endDate,
        isnull(org.FResponPositionID,post2.fid) responPositionID,org.FParentID,
        p2.fid managerId,p2.fname_l2 managerName,p2.fnumber managerNumber,
        CONVERT(varchar(10) ,isnull(pp1.FEnterDate,''), 120 ) enterDate, post.fname_l2,
        wuser.userid wxUserId
        from t_bd_person p
        INNER join T_HR_EmpOrgRelation pp on pp.fpersonid=p.fid and pp.FLEFFDT='2199-12-31' and pp.FASSIGNTYPE=0
        INNER join T_HR_PERSONPOSITION pp1 on pp1.fpersonid=p.fid
        INNER join T_HR_EMPLABORRELATION ppp2 on ppp2.FPersonID=p.fid
        INNER join T_ORG_Admin org on org.fid=pp.FADMINORGID
        INNER join T_ORG_Admin org2 on org.FParentID=org2.fid
        INNER join T_ORG_POSITION post on post.fid=pp.FPOSITIONID
        left join T_ORG_POSITION post2 on post2.fid=post.FParentID
        left join T_HR_EmpOrgRelation parp on parp.FPositionID = post.FParentID and parp.FLEFFDT='2199-12-31' and parp.FASSIGNTYPE=1
        left join t_bd_person p2 on p2.fid=parp.fpersonid
        left join ct_wx_user wuser on wuser.number=p2.fnumber
        where p2.fnumber=#{number}  and p2.fid is not null
        <if test='OrgNumber != null and OrgNumber != ""'>
            and pp1.FPersonDep in(select child.fid from T_ORG_Admin adcount
            left join T_ORG_Admin child on (charindex(adcount.flongnumber+'!',child.flongnumber) = 1 or adcount.flongnumber = child.flongnumber)
            where adcount.fnumber=#{OrgNumber})
        </if>

        <if test='id != null and id != ""'>
            and pp1.FPersonDep=#{id}
        </if>
    </select>

    <select id="getProjectByPNumber" resultType="java.util.Map" parameterType="String">
        select child.* from T_ORG_Admin adcount
            left join T_ORG_Admin child on (charindex((adcount.flongnumber+'!'),child.flongnumber) = 1 or adcount.flongnumber = child.flongnumber)
        where  adcount.fid in(
            select pp.FADMINORGID from t_bd_person p
            inner join T_HR_EmpOrgRelation pp on  pp.fpersonid=p.fid and pp.FLEFFDT='2199-12-31'
            where p.fnumber=#{number}
            )
    </select>
    <select id="getProjectByPNumberV2" resultType="java.util.Map">
        select
        org.FID FID,(org2.fname_l2+'_'+org.FName_L2) orgName,org.FNumber orgNumber,
        org.FParentID,
        p.fid managerId,p.fname_l2 managerName,p.fnumber managerNumber,
        post.fid, post.fname_l2,wuser.userid wxUserId
        from t_bd_person p
        left join T_HR_EmpOrgRelation pp on pp.fpersonid=p.fid and pp.FLEFFDT='2199-12-31'  and pp.FASSIGNTYPE=1
        left join T_ORG_POSITION post on post.fid=pp.FPOSITIONID
        left join T_ORG_POSITION post2 on  post.fid=post2.FParentID
        left join T_HR_EmpOrgRelation parp on parp.FPositionID = post.FParentID and parp.FLEFFDT='2199-12-31' and parp.FASSIGNTYPE=1
        left join T_ORG_Admin org on org.fid=pp.FADMINORGID
        left join T_ORG_Admin org2 on org.FParentID=org2.fid
        left join t_bd_person p2 on p2.fid=parp.fpersonid
        left join ct_wx_user wuser on wuser.number=p2.fnumber
        where p.fnumber=#{number}  and p2.fid is not null
        <if test='OrgNumber != null and OrgNumber != ""'>
            and pp.FADMINORGID in(select child.fid from T_ORG_Admin adcount
            left join T_ORG_Admin child on (charindex(adcount.flongnumber+'!',child.flongnumber) = 1 or adcount.flongnumber = child.flongnumber)
            where adcount.fnumber=#{OrgNumber})
        </if>
        union
        select
        org.FID FID,(org2.fname_l2+'_'+org.FName_L2) orgName,org.FNumber orgNumber,
        org.FParentID,
        p.fid managerId,p.fname_l2 managerName,p.fnumber managerNumber,
        post.fid, post.fname_l2,wuser.userid wxUserId
        from t_bd_person p
        left join T_HR_EmpOrgRelation pp on pp.fpersonid=p.fid and pp.FLEFFDT='2199-12-31'  and pp.FASSIGNTYPE=0
        left join T_ORG_POSITION post on post.fid=pp.FPOSITIONID
        left join T_ORG_POSITION post2 on  post.fid=post2.FParentID
        left join T_HR_EmpOrgRelation parp on parp.FPositionID = post.FParentID and parp.FLEFFDT='2199-12-31' and parp.FASSIGNTYPE=0
        left join T_ORG_Admin org on org.fid=pp.FADMINORGID
        left join T_ORG_Admin org2 on org.FParentID=org2.fid
        left join t_bd_person p2 on p2.fid=parp.fpersonid
        left join ct_wx_user wuser on wuser.number=p2.fnumber
        where p.fnumber=#{number}  and p2.fid is not null
        <if test='OrgNumber != null and OrgNumber != ""'>
            and pp.FADMINORGID in(select child.fid from T_ORG_Admin adcount
            left join T_ORG_Admin child on (charindex(adcount.flongnumber+'!',child.flongnumber) = 1 or adcount.flongnumber = child.flongnumber)
            where adcount.fnumber=#{OrgNumber})
        </if>
        union
        select
        org.FID FID,(org2.fname_l2+'_'+org.FName_L2) orgName,org.FNumber orgNumber,
        org.FParentID,
        p.fid managerId,p.fname_l2 managerName,p.fnumber managerNumber,
        post.fid, post.fname_l2,wuser.userid wxUserId
        from t_bd_person p
        left join T_HR_EmpOrgRelation pp on pp.fpersonid=p.fid and pp.FLEFFDT='2199-12-31'  and pp.FASSIGNTYPE=1
        left join T_ORG_POSITION post on post.fid=pp.FPOSITIONID
        left join T_ORG_POSITION post2 on  post.fid=post2.FParentID
        left join T_HR_EmpOrgRelation parp on parp.FPositionID = post.FParentID and parp.FLEFFDT='2199-12-31' and parp.FASSIGNTYPE=0
        left join T_ORG_Admin org on org.fid=pp.FADMINORGID
        left join T_ORG_Admin org2 on org.FParentID=org2.fid
        left join t_bd_person p2 on p2.fid=parp.fpersonid
        left join ct_wx_user wuser on wuser.number=p2.fnumber
        where p.fnumber=#{number}  and p2.fid is not null
        <if test='OrgNumber != null and OrgNumber != ""'>
            and pp.FADMINORGID in(select child.fid from T_ORG_Admin adcount
            left join T_ORG_Admin child on (charindex(adcount.flongnumber+'!',child.flongnumber) = 1 or adcount.flongnumber = child.flongnumber)
            where adcount.fnumber=#{OrgNumber})
        </if>
        union
        select
        org.FID FID,(org2.fname_l2+'_'+org.FName_L2) orgName,org.FNumber orgNumber,
        org.FParentID,
        p.fid managerId,p.fname_l2 managerName,p.fnumber managerNumber,
        post.fid, post.fname_l2,wuser.userid wxUserId
        from t_bd_person p
        left join T_HR_EmpOrgRelation pp on pp.fpersonid=p.fid and pp.FLEFFDT='2199-12-31'  and pp.FASSIGNTYPE=0
        left join T_ORG_POSITION post on post.fid=pp.FPOSITIONID
        left join T_ORG_POSITION post2 on  post.fid=post2.FParentID
        left join T_HR_EmpOrgRelation parp on parp.FPositionID = post.FParentID and parp.FLEFFDT='2199-12-31' and parp.FASSIGNTYPE=1
        left join T_ORG_Admin org on org.fid=pp.FADMINORGID
        left join T_ORG_Admin org2 on org.FParentID=org2.fid
        left join t_bd_person p2 on p2.fid=parp.fpersonid
        left join ct_wx_user wuser on wuser.number=p2.fnumber
        where p.fnumber=#{number}  and p2.fid is not null
        <if test='OrgNumber != null and OrgNumber != ""'>
            and pp.FADMINORGID in(select child.fid from T_ORG_Admin adcount
            left join T_ORG_Admin child on (charindex(adcount.flongnumber+'!',child.flongnumber) = 1 or adcount.flongnumber = child.flongnumber)
            where adcount.fnumber=#{OrgNumber})
        </if>

    </select>
    <select id="getProjectByPNumberV3" resultType="java.util.Map">
        select
        org.FID FID,(org2.fname_l2+'_'+org.FName_L2) orgName,org.FNumber orgNumber,
        org.FParentID,
        p.fid managerId,p.fname_l2 managerName,p.fnumber managerNumber,
        post.fid, post.fname_l2,wuser.userid wxUserId
        from t_bd_person p
        left join T_HR_EmpOrgRelation pp on pp.fpersonid=p.fid and pp.FLEFFDT='2199-12-31'  and pp.FASSIGNTYPE=1
        left join T_ORG_POSITION post on post.fid=pp.FPOSITIONID
        left join T_ORG_Admin org on org.fid=pp.FADMINORGID
        left join T_ORG_Admin org2 on org.FParentID=org2.fid
        left join CT_WK_ManagerInfo mg on mg.CFPersonID=p.fid
        left join t_bd_person p2 on p2.fid=mg.CFManagerID
        left join ct_wx_user wuser on wuser.number=p2.fnumber
        where p.fnumber=#{number}  and p2.fid is not null
        <if test='OrgNumber != null and OrgNumber != ""'>
            and pp.FADMINORGID in(select child.fid from T_ORG_Admin adcount
            left join T_ORG_Admin child on (charindex(adcount.flongnumber+'!',child.flongnumber) = 1 or adcount.flongnumber = child.flongnumber)
            where adcount.fnumber=#{OrgNumber})
        </if>
        union
        select
        org.FID FID,(org2.fname_l2+'_'+org.FName_L2) orgName,org.FNumber orgNumber,
        org.FParentID,
        p.fid managerId,p.fname_l2 managerName,p.fnumber managerNumber,
        post.fid, post.fname_l2,wuser.userid wxUserId
        from t_bd_person p
        left join T_HR_EmpOrgRelation pp on pp.fpersonid=p.fid and pp.FLEFFDT='2199-12-31'  and pp.FASSIGNTYPE=0
        left join T_ORG_POSITION post on post.fid=pp.FPOSITIONID
        left join T_ORG_Admin org on org.fid=pp.FADMINORGID
        left join T_ORG_Admin org2 on org.FParentID=org2.fid
        left join CT_WK_ManagerInfo mg on mg.CFPersonID=p.fid
        left join t_bd_person p2 on p2.fid=mg.CFManagerID
        left join ct_wx_user wuser on wuser.number=p2.fnumber
        where p.fnumber=#{number}  and p2.fid is not null
        <if test='OrgNumber != null and OrgNumber != ""'>
            and pp.FADMINORGID in(select child.fid from T_ORG_Admin adcount
            left join T_ORG_Admin child on (charindex(adcount.flongnumber+'!',child.flongnumber) = 1 or adcount.flongnumber = child.flongnumber)
            where adcount.fnumber=#{OrgNumber})
        </if>

    </select>
</mapper>