<?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.PersonMapper">

    <select id="getPersonByUserId" resultType="java.util.Map" parameterType="String">
        select p.fid "id",p.fnumber "personNumber",p.fname_l2 "personName",
        TO_CHAR(NVL(pp2.FEnterDate, ''), 'YYYY-MM-DD') "enterDate",
        btype.fname_l2 "btypeName",btype.fid "btypeId",
        pp.fid "userID",pp2.FControlUnitID "controlUnitID",pp2.FHrOrgUnitID "hrOrgUnitID",
        pop.FPersonDep "adminOrgId",pop.FPRIMARYPOSITIONID "positionId",
        adminOrg.fname_l2 "adminOrgName",pos.fName_l2 "positionName",
        pos.fnumber "positionNumber"
        from t_bd_person p
        left join t_pm_user pp on pp.fpersonid=p.fid
        left join T_HR_EMPLABORRELATION pp2 on pp2.FPersonID=p.fid
        left join T_HR_BDEmployeeType btype on btype.fid=pp2.FLaborRelationStateID
        left join T_HR_PersonPosition pop on pop.fpersonid=p.fid
        left join T_org_admin adminOrg on adminOrg.fid= pop.FPersonDep
        left join T_org_position pos on pos.fid= pop.FPRIMARYPOSITIONID
        where pp.fid=#{userid}
    </select>

    <select id="getPersonByOpenId" resultType="java.util.Map" parameterType="String">
        select p.fid "id",p.fnumber "personNumber",p.fname_l2 "personName",
        TO_CHAR(NVL(pp2.FEnterDate, ''), 'YYYY-MM-DD') "enterDate",
        btype.fname_l2 "btypeName",btype.fid "btypeId",
        pp.fid "userID",pp2.FControlUnitID "controlUnitID",pp2.FHrOrgUnitID "hrOrgUnitID",
        pop.FPersonDep "adminOrgId",pop.FPRIMARYPOSITIONID "positionId",
        adminOrg.fname_l2 "adminOrgName",pos.fName_l2 "positionName",
        pos.fnumber "positionNumber"
        from t_bd_person p
        left join t_pm_user pp on pp.fpersonid=p.fid
        left join T_HR_EMPLABORRELATION pp2 on pp2.FPersonID=p.fid
        left join T_HR_BDEmployeeType btype on btype.fid=pp2.FLaborRelationStateID
        left join T_HR_PersonPosition pop on pop.fpersonid=p.fid
        left join T_org_admin adminOrg on adminOrg.fid= pop.FPersonDep
        left join T_org_position pos on pos.fid= pop.FPRIMARYPOSITIONID
        where pp.fopenid=#{openid}
    </select>

    <select id="getPersonByJobNo" resultType="java.util.Map" parameterType="String">
        select p.fid "id",p.fnumber "personNumber",p.fname_l2 "personName",
        TO_CHAR(NVL(pp2.FEnterDate, ''), 'YYYY-MM-DD') "enterDate",
        btype.fname_l2 "btypeName",btype.fid "btypeId",
        pp.fid "userID",pp2.FControlUnitID "controlUnitID",pp2.FHrOrgUnitID "hrOrgUnitID",
        pop.FPersonDep "adminOrgId",pop.FPRIMARYPOSITIONID "positionId",
        adminOrg.fname_l2 "adminOrgName",pos.fName_l2 "positionName",
        pos.fnumber "positionNumber"
        from t_bd_person p
        left join t_pm_user pp on pp.fpersonid=p.fid
        left join T_HR_EMPLABORRELATION pp2 on pp2.FPersonID=p.fid
        left join T_HR_BDEmployeeType btype on btype.fid=pp2.FLaborRelationStateID
        left join T_HR_PersonPosition pop on pop.fpersonid=p.fid
        left join T_org_admin adminOrg on adminOrg.fid= pop.FPersonDep
        left join T_org_position pos on pos.fid= pop.FPRIMARYPOSITIONID
        where p.fnumber=#{jobNo}
    </select>
    <select id="getPersonByPersonId" resultType="java.util.Map" parameterType="String">
        select p.fid "id",p.fnumber "personNumber",p.fname_l2 "personName",
        TO_CHAR(NVL(pp2.FEnterDate, ''), 'YYYY-MM-DD') "enterDate",
        btype.fname_l2 "btypeName",btype.fid "btypeId",
        pp.fid "userID",pp2.FControlUnitID "controlUnitID",pp2.FHrOrgUnitID "hrOrgUnitID",
        pop.FPersonDep "adminOrgId",pop.FPRIMARYPOSITIONID "positionId",
        adminOrg.fname_l2 "adminOrgName",pos.fName_l2 "positionName",
        pos.fnumber "positionNumber"
        from t_bd_person p
        left join t_pm_user pp on pp.fpersonid=p.fid
        left join T_HR_EMPLABORRELATION pp2 on pp2.FPersonID=p.fid
        left join T_HR_BDEmployeeType btype on btype.fid=pp2.FLaborRelationStateID
        left join T_HR_PersonPosition pop on pop.fpersonid=p.fid
        left join T_org_admin adminOrg on adminOrg.fid= pop.FPersonDep
        left join T_org_position pos on pos.fid= pop.FPRIMARYPOSITIONID
        where p.fid=#{id}
    </select>
</mapper>