<?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.pcloud.book.advertising.dao.impl.AdvertisingDetailFileDaoImpl" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.advertising.entity.AdvertisingDetailFile" >
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="ad_id" property="adId" jdbcType="BIGINT" />
    <result column="file_id" property="fileId" jdbcType="VARCHAR" />
    <result column="file_convert_state" property="fileConvertState" jdbcType="INTEGER" />
    <result column="file_size" property="fileSize" jdbcType="BIGINT" />
    <result column="file_name" property="fileName" jdbcType="VARCHAR" />
    <result column="file_duration" property="fileDuration" jdbcType="BIGINT" />
    <result column="file_url" property="fileUrl" jdbcType="VARCHAR" />
    <result column="file_pilot_second" property="filePilotSecond" jdbcType="BIGINT" />
    <result column="file_pilot_url" property="filePilotUrl" jdbcType="VARCHAR" />
    <result column="file_pilot_finish_tip" property="filePilotFinishTip" jdbcType="VARCHAR" />
    <result column="title" property="title" jdbcType="VARCHAR" />
    <result column="cover_pic" property="coverPic" jdbcType="VARCHAR" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
    <result column="cpa_id" property="cpaId" jdbcType="BIGINT" />
  </resultMap>

  <sql id="Base_Column_List" >
    id, ad_id, file_id, file_convert_state, file_size, file_name, file_duration, file_url, 
    file_pilot_second, file_pilot_url, file_pilot_finish_tip, title, cover_pic, create_time, update_time, cpa_id
  </sql>

  <select id="getByCPAId" resultMap="BaseResultMap" parameterType="java.lang.Long" >
    select 
    <include refid="Base_Column_List" />
    from advertising_detail_file
    where cpa_id = #{cpaId,jdbcType=BIGINT}
  </select>

  <delete id="deleteByCPAId" parameterType="Long">
    delete from advertising_detail_file
    where cpa_id = #{cpaId,jdbcType=BIGINT}
  </delete>

  <insert id="batchInsert" useGeneratedKeys="true" parameterType="java.util.List" keyProperty="id">
    insert into advertising_detail_file (
    ad_id, file_id,
    file_convert_state, file_size, file_name,
    file_duration, file_url, file_pilot_second,
    file_pilot_url, file_pilot_finish_tip, title,
    cover_pic, create_time, cpa_id)
    values
    <foreach collection="list" item="item" index="index" separator="," >
      (
      #{item.adId,jdbcType=BIGINT}, #{item.fileId,jdbcType=VARCHAR},
      #{item.fileConvertState,jdbcType=INTEGER}, #{item.fileSize,jdbcType=BIGINT}, #{item.fileName,jdbcType=VARCHAR},
      #{item.fileDuration,jdbcType=BIGINT}, #{item.fileUrl,jdbcType=VARCHAR}, #{item.filePilotSecond,jdbcType=BIGINT},
      #{item.filePilotUrl,jdbcType=VARCHAR}, #{item.filePilotFinishTip,jdbcType=VARCHAR}, #{item.title,jdbcType=VARCHAR},
      #{item.coverPic,jdbcType=VARCHAR}, NOW(), #{item.cpaId}
      )
    </foreach>
  </insert>

  <update id="updateCPAId" parameterType="map">
    UPDATE advertising_detail_file
    SET cpa_id = #{cpaId,jdbcType=BIGINT}
    WHERE
        ad_id = #{adId}
  </update>

</mapper>