<?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.ExtensionJointMapper" >
  <resultMap id="BaseResultMap" type="cn.com.countrygarden.bi.main.dto.extension.ExtensionJointInfoDTO" >
    <id column="id" property="id"  />
    <result column="extension_report_id" property="extensionReportId"  />
    <result column="joint_name" property="jointName"  />
    <result column="joint_tel" property="jointTel"  />
    <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, joint_name, joint_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_joint
    where id = #{id}
  </select>
  <update id="deleteByPrimaryKey" parameterType="java.lang.Long" >
    update extension_joint
    set is_delete = 1
    where id = #{id}
  </update>
  <insert id="insert" parameterType="cn.com.countrygarden.bi.main.dto.extension.ExtensionJointInfoDTO" >
    insert into extension_joint ( extension_report_id, joint_name,
      joint_tel, create_date, create_by, 
      last_update_date, last_update_by)
    values (#{extensionReportId}, #{jointName},
      #{jointTel}, NOW(), #{createBy},
       NOW(), #{lastUpdateBy})
  </insert>


  <insert id="insertBatchSelective" parameterType="cn.com.countrygarden.bi.main.dto.extension.ExtensionReportDTO" >
      insert into extension_joint (
          extension_report_id,
          joint_name,
          joint_tel,
          create_date,
          create_by,
          last_update_date,
          last_update_by
      )
      values
      <foreach collection="dto.jointDTO" item="item" index="index" separator=",">
        <trim prefix="(" suffix=")" suffixOverrides="," >
            #{dto.id},
            #{item.jointName},
            #{item.jointTel},
            #{item.createDate},
            #{userCode},
            #{item.lastUpdateDate},
            #{userCode},
        </trim>
      </foreach>
  </insert>

  <update id="updateByPrimaryKeySelective" parameterType="cn.com.countrygarden.bi.main.dto.extension.ExtensionJointInfoDTO" >
    update extension_joint
    <set >
      <if test="extensionReportId != null" >
        extension_report_id = #{extensionReportId},
      </if>
      <if test="jointName != null" >
        joint_name = #{jointName},
      </if>
      <if test="jointTel != null" >
        joint_tel = #{jointTel},
      </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.ExtensionJointInfoDTO" >
    update extension_joint
    set extension_report_id = #{extensionReportId},
      joint_name = #{jointName},
      joint_tel = #{jointTel},
      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_joint
      <trim prefix="set" suffixOverrides=",">
          <trim prefix="joint_name = case" suffix="end,">
              <foreach collection="dto.jointDTO" item="i" index="index">
                      when id=#{i.id} then #{i.jointName}
              </foreach>
          </trim>
          <trim prefix=" joint_tel =case" suffix="end,">
              <foreach collection="dto.jointDTO" item="i" index="index">
                      when id=#{i.id} then #{i.jointTel}
              </foreach>
          </trim>
          <trim prefix=" last_update_date =case" suffix="end,">
              <foreach collection="dto.jointDTO" item="i" index="index">
                  when id=#{i.id} then #{i.lastUpdateDate}
              </foreach>
          </trim>
          <trim prefix=" last_update_by =case" suffix="end,">
              <foreach collection="dto.jointDTO" item="i" index="index">
                  when id=#{i.id} then #{userCode}
              </foreach>
          </trim>
          <trim prefix=" is_delete =case" suffix="end,">
              <foreach collection="dto.jointDTO" item="i" index="index">
                  when id=#{i.id} then #{i.isDelete}
              </foreach>
          </trim>
      </trim>

      where
      <foreach collection="dto.jointDTO" separator="or" item="i" index="index" >
          id=#{i.id}
      </foreach>
  </update>
</mapper>