<?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="cn.wisenergy.oaMapper.ProjectAndBoMapper">
    <resultMap id="Project_Map" type="cn.wisenergy.oaModel.OaProject">
        <id column="project_no" property="no"/>
        <result property="name" column="project_name"/>
        <result property="managerNo" column="pm_no"/>
        <result property="bo" column="bo_no"/>
        <result property="bName" column="bo_name"/>
        <result property="managerName" column="manager_name"/>
        <result property="deptNo" column="project_depart_no"/>
        <result property="deptName" column="project_depart_name"/>
        <result property="cost" column="cost"/>
        <result property="startDate" column="start_date"/>
        <result property="endDate" column="end_date"/>
    </resultMap>

    <resultMap id="Bo_Map" type="cn.wisenergy.oaModel.OaProject">
        <id column="project_no" property="no"/>
        <result property="name" column="project_name"/>
        <result property="managerNo" column="pm_no"/>
        <result property="managerName" column="manager_name"/>
        <result property="deptNo" column="project_depart_no"/>
        <result property="deptName" column="project_depart_name"/>
        <result property="cost" column="cost"/>
        <result property="startDate" column="start_date"/>
        <result property="endDate" column="end_date"/>
    </resultMap>

    <sql id="values_project">
        project_no, project_name ,pm_no ,bo_no ,bo_name ,manager_name,
        project_depart_no ,project_depart_name ,cost,start_date ,end_date
    </sql>

    <sql id="values_bo">
        bo, bo_name,pm_no,manager_name,project_depart_no,project_depart_name

    </sql>

    <select id="getListOaProjectByDept" resultMap="Project_Map">
    select p.project_no, p.project_name, p.pm_no, p.project_depart_no, p.cost, p.start_date, p.end_date, b.bo_no, b.bo_name
    from v_project_base p left join v_bo_base b on p.bo_no = b.bo_no
    where p.project_depart_no = #{oaDeptNo}
          AND (p.project_no like CONCAT("%" ,#{projectNameOrNo},"%") OR p.project_name like CONCAT("%" ,#{projectNameOrNo},"%"))
          <if test="oaProjectIds.size != 0">
              AND p.project_no not in
              <foreach collection="oaProjectIds" item="oaProject" open="(" close=")"  separator=",">
                  #{oaProject}
              </foreach>
          </if>

    </select>

    <select id="getListOaBoByDept" resultMap="Bo_Map">
        select b.bo_no AS project_no, b.bo_name AS project_name, b.pm_no, b.pm_name, b.project_depart_no, b.project_depart_name
        from v_project_base p right join v_bo_base b on p.bo_no = b.bo_no
        where (b.project_depart_no = #{oaDeptNo} OR p.project_depart_no = #{oaDeptNo})
                AND (b.bo_no like CONCAT("%" ,#{projectNameOrNo},"%") OR b.bo_name like CONCAT("%" ,#{projectNameOrNo},"%"))
               <if test="oaProjectIds.size != 0">
                AND b.bo_no not in
                <foreach collection="oaProjectIds" item="oaProject" open="(" close=")" separator=",">
                    #{oaProject}
                </foreach>
                </if>
    </select>


    <select id="getProjectByNameAndNo" resultMap="Project_Map">
    select  <include refid="values_project"/>
    from v_project_base
    where  project_no = #{projectNo} AND project_name = #{projectName}
            <!--<if test="boNo != null ">-->
                <!--AND bo_no = #{boNo} -->
            <!--</if>-->

    </select>
    <select id="getBoByNameAndNo" resultMap="Bo_Map">
        select  bo_no AS project_no, bo_name AS project_name,pm_no,manager_name,project_depart_no,project_depart_name
        from  v_bo_base
        where bo_no = #{projectNo} AND bo_name = #{projectName}
    </select>


</mapper>