<?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.com.countrygarden.bi.main.dao.extension.ExtensionProjectLeaderMapper" >
  <resultMap id="BaseResultMap" type="cn.com.countrygarden.bi.main.dto.extension.ExtensionProjectLeaderDTO" >
    <id column="id" property="id"  />
    <result column="extension_report_id" property="extensionReportId"  />
    <result column="leader_name" property="leaderName"  />
    <result column="leader_tel" property="leaderTel"  />
    <result column="create_date" property="createDate"  />
    <result column="create_by" property="createBy"  />
    <result column="last_update_date" property="lastUpdateDate"  />
    <result column="last_update_by" property="lastUpdateBy"  />
  </resultMap>
  <sql id="Base_Column_List" >
    id, extension_report_id, leader_name, leader_tel, create_date, create_by, last_update_date,
    last_update_by
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
    select 'false' as QUERYID,
    <include refid="Base_Column_List" />
    from extension_project_leader
    where id = #{id}
  </select>
  <update id="deleteByPrimaryKey" parameterType="java.lang.Long" >
    update extension_project_leader
    set is_delete = 1
    where id = #{id}
  </update>
  <insert id="insert" parameterType="cn.com.countrygarden.bi.main.dto.extension.ExtensionProjectLeaderDTO" >
    insert into extension_project_leader
      ( extension_report_id, leader_name,
           leader_tel, create_date, create_by,
           last_update_date, last_update_by)
    values (#{extensionReportId}, #{leaderName},
            #{leaderTel}, NOW(), #{createBy},
            NOW(), #{lastUpdateBy})
  </insert>

  <insert id="insertBatchSelective" parameterType="cn.com.countrygarden.bi.main.dto.extension.ExtensionReportDTO" >
    insert into extension_project_leader (
    extension_report_id,
    leader_name,
    leader_tel,
    create_date,
    create_by,
    last_update_date,
    last_update_by
    )
    values
    <foreach collection="dto.leaderDTO" item="item" index="index" separator=",">
      <trim prefix="(" suffix=")" suffixOverrides="," >
        #{dto.id},
        #{item.leaderName},
        #{item.leaderTel},
        NOW(),
        #{userCode},
        NOW(),
        #{userCode},
      </trim>
    </foreach>
  </insert>

  <update id="updateByPrimaryKeySelective" parameterType="cn.com.countrygarden.bi.main.dto.extension.ExtensionProjectLeaderDTO" >
    update extension_project_leader
    <set >
      <if test="extensionReportId != null" >
        extension_report_id = #{extensionReportId},
      </if>
      <if test="leaderName != null" >
        leader_name = #{leaderName},
      </if>
      <if test="leaderTel != null" >
        leader_tel = #{leaderTel},
      </if>
      <if test="createDate != null" >
        create_date = #{createDate},
      </if>
      <if test="createBy != null" >
        create_by = #{createBy},
      </if>
      <if test="lastUpdateDate != null" >
        last_update_date = #{lastUpdateDate},
      </if>
      <if test="lastUpdateBy != null" >
        last_update_by = #{lastUpdateBy},
      </if>
    </set>
    where id = #{id}
  </update>
  <update id="updateByPrimaryKey" parameterType="cn.com.countrygarden.bi.main.dto.extension.ExtensionProjectLeaderDTO" >
    update extension_project_leader
    set extension_report_id = #{extensionReportId},
        leader_name = #{leaderName},
        leader_tel = #{leaderTel},
        create_date = #{createDate},
        create_by = #{createBy},
        last_update_date = #{lastUpdateDate},
        last_update_by = #{lastUpdateBy}
    where id = #{id}
  </update>

  <update id="updateBatchSelective" parameterType="cn.com.countrygarden.bi.main.dto.extension.ExtensionReportDTO">
    update extension_project_leader
    <trim prefix="set" suffixOverrides=",">
      <trim prefix="leader_name = case" suffix="end,">
        <foreach collection="dto.leaderDTO" item="i" index="index">
          when id=#{i.id} then #{i.leaderName}
        </foreach>
      </trim>
      <trim prefix=" leader_tel =case" suffix="end,">
        <foreach collection="dto.leaderDTO" item="i" index="index">
          when id=#{i.id} then #{i.leaderTel}
        </foreach>
      </trim>
      <trim prefix=" last_update_date =case" suffix="end,">
        <foreach collection="dto.leaderDTO" item="i" index="index">
          when id=#{i.id} then #{i.lastUpdateDate}
        </foreach>
      </trim>
      <trim prefix=" last_update_by =case" suffix="end,">
        <foreach collection="dto.leaderDTO" item="i" index="index">
          when id=#{i.id} then #{userCode}
        </foreach>
      </trim>
      <trim prefix=" is_delete =case" suffix="end,">
        <foreach collection="dto.leaderDTO" item="i" index="index">
          when id=#{i.id} then #{i.isDelete}
        </foreach>
      </trim>
    </trim>
    where
    <foreach collection="dto.leaderDTO" separator="or" item="i" index="index" >
      id=#{i.id}
    </foreach>
  </update>
</mapper>