<?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.ExtensionUploadFileMapper" >
  <resultMap id="BaseResultMap" type="cn.com.countrygarden.bi.main.dto.extension.ExtensionUpFileInfo" >
    <id column="id" property="id"  />
    <result column="extension_report_id" property="extensionReportId"  />
    <result column="file_name" property="fileName"  />
    <result column="file_url" property="fileUrl"  />
    <result column="file_type" property="fileType"  />
    <result column="file_tab" property="fileTab"  />
    <result column="file_real_name" property="fileRealName"  />
    <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, file_name, file_url, file_type, file_tab, file_real_name,
    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_upload_file
    where id = #{id}
  </select>
  <update id="deleteByPrimaryKey" parameterType="java.lang.Long" >
    update extension_upload_file
    set is_delete = 1
    where id = #{id}
  </update>
  <insert id="insert" parameterType="cn.com.countrygarden.bi.main.dto.extension.ExtensionUpFileInfo" >
    insert into extension_upload_file ( extension_report_id, file_name,
      file_url, file_type,
      file_tab, file_real_name, create_date,
      create_by, last_update_date, last_update_by
      )
    values ( #{extensionReportId}, #{fileName},
      #{fileUrl}, #{fileType},
      #{fileTab}, #{fileRealName}, NOW(),
      #{createBy}, NOW(), #{lastUpdateBy}
      )
  </insert>

  <insert id="insertBatchSelective" parameterType="cn.com.countrygarden.bi.main.dto.extension.ExtensionReportDTO" >
    insert into extension_upload_file(
      extension_report_id,
      file_name,
      file_url,
      file_type,
      file_tab,
      file_real_name,
      create_date,
      create_by,
      last_update_date,
      last_update_by
    )
    values
    <foreach collection="dto.fileInfos" item="item" index="index" separator=",">
      <trim prefix="(" suffix=")" suffixOverrides="," >
        #{dto.id},
          #{item.fileName},
          #{item.fileUrl},
          #{item.fileType},
          #{item.fileTab},
          #{item.fileRealName},
          NOW(),
          #{userCode},
          NOW(),
          #{userCode},
      </trim>
    </foreach>
  </insert>

  <update id="updateByPrimaryKeySelective" parameterType="cn.com.countrygarden.bi.main.dto.extension.ExtensionUpFileInfo" >
    update extension_upload_file
    <set >
      <if test="extensionReportId != null" >
        extension_report_id = #{extensionReportId},
      </if>
      <if test="fileName != null" >
        file_name = #{fileName},
      </if>
      <if test="fileUrl != null" >
        file_url = #{fileUrl},
      </if>
      <if test="fileType != null" >
        file_type = #{fileType},
      </if>
      <if test="fileTab != null" >
        file_tab = #{fileTab},
      </if>
      <if test="fileRealName != null" >
        file_real_name = #{fileRealName},
      </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.ExtensionUpFileInfo" >
    update extension_upload_file
    set extension_report_id = #{extensionReportId},
      file_name = #{fileName},
      file_url = #{fileUrl},
      file_type = #{fileType},
      file_tab = #{fileTab},
      file_real_name = #{fileRealName},
      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_upload_file
    <trim prefix="set" suffixOverrides=",">
      <trim prefix="file_name = case" suffix="end,">
        <foreach collection="dto.fileInfos" item="i" index="index">
          when id=#{i.id} then #{i.fileName}
        </foreach>
      </trim>
      <trim prefix=" file_url =case" suffix="end,">
        <foreach collection="dto.fileInfos" item="i" index="index">
          when id=#{i.id} then #{i.fileUrl}
        </foreach>
      </trim>
      <trim prefix=" last_update_date =case" suffix="end,">
        <foreach collection="dto.fileInfos" item="i" index="index">
          when id=#{i.id} then NOW()
        </foreach>
      </trim>
      <trim prefix=" last_update_by =case" suffix="end,">
        <foreach collection="dto.fileInfos" item="i" index="index">
          when id=#{i.id} then #{userCode}
        </foreach>
      </trim>
      <trim prefix=" file_real_name =case" suffix="end,">
        <foreach collection="dto.fileInfos" item="i" index="index">
          when id=#{i.id} then #{i.fileRealName}
        </foreach>
      </trim>
      <trim prefix=" is_delete =case" suffix="end,">
        <foreach collection="dto.fileInfos" item="i" index="index">
          when id=#{i.id} then #{i.isDelete}
        </foreach>
      </trim>
    </trim>

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