<?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">
    <insert id="addProjectPerson" parameterType="java.util.Map">
        insert into CT_PRO_MemberManagement(fid, CFEmployeeID, CFPROJECTMANAGEMENID,
                                            CFProjectRoleID, FCreatorID, FLastUpdateUserID,
                                            FCreateTime, FLastUpdateTime, FControlUnitID,
                                            CFState, CFProjectCode, CFProjectName,
                                            FHROrgUnitID, fnumber)
        values (#{id},
                #{personID},
                #{projectID},
                #{projectRoleID},
                #{currentUser},
                #{currentUser},
                sysdate,
                sysdate,
                #{controUnit},
                #{state},
                #{projectName},
                #{projectNumber},
                #{hrOrgUnit},
                #{number})
    </insert>

    <select id="getProjectManagementByState" resultType="java.util.Map">

        select
        projectManagement.fid as "id",
        projectManagement.CFProjectName as "projectName",
        projectManagement.CFExpectedStartTime as "expectedStartTime",
        projectManagement.CFExpectedEndTime as "expectedEndTime",
        person.fid as "personId",
        person.Fname_l2 as "personName",
        person.Fnumber as "personNumber",
        CFTotalPersonDays as "totalPersonDays",
        CFCostAmount as "costAmount",
        CFNotes as "notes",
        FWorkerDaysReported as "workerDaysReported",
        FProDayConsumption as "proDayConsumption",
        projectManagement.fnumber as "number",
        projectManagement.FBillState as "billState",
        CFProjectLevel as "projectLevel" ,
        CFProjectState as "projectState",
        CFBeingChanged as "beingChanged" ,
        CFChangedManDays as "changedManDays"
        from CT_PRO_ProjectManagement projectManagement
        left join T_BD_Person person on person.fid = projectManagement.CFProjectManagerID
        left join T_org_admin adminOrg on adminOrg.fid = projectManagement.FAdminOrgUnitId
        where CFExpectedEndTime
        <if test="state==1">
            &gt;=
        </if>
        <if test="state==0">
            &lt;=
        </if>
        to_date(#{dateTime},'YYYY-MM-DD')
    </select>
    <select id="getMemberManagementInfoByPerobjectId" resultType="java.util.Map">
        select projectRole.fid                     as "projectRoleId",
               projectRole.fname_l2                as "projectRoleName",
               person.fid                          as "personId",
               person.Fname_l2                     as "personName",
               projectManagement.CFProjectName     as "projectName",
               projectManagement.CFExpectedEndTime as "expectedEndTime",
               projectType.fname_l2                as "projectTypeName",
               projectType.fid                     as "projectTypeId",
               projectType.fnumber                 as "projectTypeNumber"
        from CT_PRO_MemberManagement memberManagement
                 left join CT_PRO_ProjectRole projectRole on projectRole.fid = memberManagement.CFProjectRoleID
                 left join T_BD_person person on person.fid = memberManagement.CFEmployeeID
                 left join CT_PRO_ProjectManagement projectManagement
                           on projectManagement.fid = memberManagement.CFPROJECTMANAGEMENID
                 left join CT_PRO_ProjectType projectType on projectType.fid = projectRole.CFTypeID
        where projectManagement.fid = #{perobjectId} order by  projectType.fnumber
    </select>
    <select id="getProjectListByState" resultType="java.util.Map">
        select fid as "id" ,fnumber as "number" ,CFProjectName as "name" from CT_PRO_ProjectManagement
        where CFProjectManagerID = (select fid from T_bd_person where fnumber = #{personNumber})
        <!--        where CFExpectedEndTime-->
        <!--        <if test="state==1">-->
        <!--            &gt;=-->
        <!--        </if>-->
        <!--        <if test="state==0">-->
        <!--            &lt;=-->
        <!--        </if>-->
        <!--        to_date(#{dateTime},'YYYY-MM-DD')-->
    </select>

</mapper>
