<?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.AdvertisingCpaDaoImpl" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.advertising.entity.AdvertisingCpa" >
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="detail_name" property="detailName" jdbcType="VARCHAR" />
    <result column="detail_mode" property="detailMode" jdbcType="VARCHAR" />
    <result column="cover_pic" property="coverPic" jdbcType="VARCHAR" />
    <result column="welfare_pic" property="welfarePic" jdbcType="VARCHAR" />
    <result column="form_mobile_check" property="formMobileCheck" jdbcType="BIT" />
    <result column="form_remark" property="formRemark" jdbcType="VARCHAR" />
    <result column="form_button" property="formButton" jdbcType="VARCHAR" />
    <result column="form_link" property="formLink" jdbcType="VARCHAR" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
    <result column="detail_info" property="detailInfo" jdbcType="LONGVARCHAR" />
    <result column="preview_link" property="previewLink" jdbcType="VARCHAR" />
    <result column="cover_video" property="coverVideo" jdbcType="VARCHAR" />
    <result column="bg_color" property="bgColor" jdbcType="VARCHAR" />
    <result column="success_toast_type" property="successToastType" jdbcType="INTEGER" />
    <result column="success_toast_content" property="successToastContent" jdbcType="VARCHAR" />
    <result column="commit_button_type" property="commitButtonType" jdbcType="INTEGER" />
    <result column="commit_button_content" property="commitButtonContent" jdbcType="VARCHAR" />
    <result column="commit_button_image" property="commitButtonImage" jdbcType="VARCHAR" />
    <result column="bottom_button_type" property="bottomButtonType" jdbcType="INTEGER" />
    <result column="bottom_button_content" property="bottomButtonContent" jdbcType="VARCHAR" />
    <result column="bottom_button_image" property="bottomButtonImage" jdbcType="VARCHAR" />
    <result column="privacy_agreement" property="privacyAgreement" jdbcType="INTEGER" />
    <result column="success_email" property="successEmail" jdbcType="INTEGER" />
    <result column="success_send_code" property="successSendCode" jdbcType="VARCHAR" />
    <result column="jump_style" property="jumpStyle" jdbcType="INTEGER" />
    <result column="create_user" property="createUser" jdbcType="BIGINT" />
    <result column="update_user" property="updateUser" jdbcType="BIGINT" />
    <result column="head_picture" property="headPicture" jdbcType="VARCHAR" />
    <result column="cover_video_file_id" property="coverVideoFileId" jdbcType="VARCHAR" />
    <result column="file_convert_state" property="fileConvertState" jdbcType="INTEGER" />
    <result column="cover_video_file_name" property="coverVideoFileName" jdbcType="VARCHAR" />
    <result column="video_cover" property="videoCover" jdbcType="VARCHAR" />
    <result column="pay_setting" property="paySetting" jdbcType="INTEGER" />
  </resultMap>

  <resultMap id="AdvertisingCpaDTO" type="com.pcloud.book.advertising.dto.AdvertisingCpaDTO">
    <id column="id" property="id" jdbcType="BIGINT"/>
    <result column="detail_name" property="detailName" jdbcType="VARCHAR"/>
    <result column="detail_mode" property="detailMode" jdbcType="VARCHAR"/>
    <result column="cover_pic" property="coverPic" jdbcType="VARCHAR"/>
    <result column="welfare_pic" property="welfarePic" jdbcType="VARCHAR"/>
    <result column="form_mobile_check" property="formMobileCheck" jdbcType="BIT"/>
    <result column="form_remark" property="formRemark" jdbcType="VARCHAR"/>
    <result column="form_button" property="formButton" jdbcType="VARCHAR"/>
    <result column="form_link" property="formLink" jdbcType="VARCHAR"/>
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
    <result column="detail_info" property="detailInfo" jdbcType="LONGVARCHAR"/>
    <result column="preview_link" property="previewLink" jdbcType="VARCHAR" />
    <result column="cover_video" property="coverVideo" jdbcType="VARCHAR" />
    <result column="bg_color" property="bgColor" jdbcType="VARCHAR" />
    <result column="success_toast_type" property="successToastType" jdbcType="INTEGER" />
    <result column="success_toast_content" property="successToastContent" jdbcType="VARCHAR" />
    <result column="commit_button_type" property="commitButtonType" jdbcType="INTEGER" />
    <result column="commit_button_content" property="commitButtonContent" jdbcType="VARCHAR" />
    <result column="commit_button_image" property="commitButtonImage" jdbcType="VARCHAR" />
    <result column="bottom_button_type" property="bottomButtonType" jdbcType="INTEGER" />
    <result column="bottom_button_content" property="bottomButtonContent" jdbcType="VARCHAR" />
    <result column="bottom_button_image" property="bottomButtonImage" jdbcType="VARCHAR" />
    <result column="privacy_agreement" property="privacyAgreement" jdbcType="INTEGER" />
    <result column="success_email" property="successEmail" jdbcType="INTEGER" />
    <result column="success_send_code" property="successSendCode" jdbcType="VARCHAR" />
    <result column="jump_style" property="jumpStyle" jdbcType="INTEGER" />
    <result column="create_user" property="createUser" jdbcType="BIGINT" />
    <result column="update_user" property="updateUser" jdbcType="BIGINT" />
    <result column="head_picture" property="headPicture" jdbcType="VARCHAR" />
    <result column="cover_video_file_id" property="coverVideoFileId" jdbcType="VARCHAR" />
    <result column="file_convert_state" property="fileConvertState" jdbcType="INTEGER" />
    <result column="cover_video_file_name" property="coverVideoFileName" jdbcType="VARCHAR" />
    <result column="video_cover" property="videoCover" jdbcType="VARCHAR" />
    <result column="pay_setting" property="paySetting" jdbcType="INTEGER" />
  </resultMap>

  <sql id="Base_Column_List" >
    id, detail_name, detail_mode, cover_pic, welfare_pic, form_mobile_check, form_remark, 
    form_button, form_link, create_time, update_time, detail_info, preview_link
    ,cover_video,bg_color,success_toast_type,success_toast_content,commit_button_type,commit_button_content
    ,commit_button_image,bottom_button_type,bottom_button_content,bottom_button_image,privacy_agreement,success_email,success_send_code,jump_style,create_user,update_user
    ,head_picture,cover_video_file_id,file_convert_state,cover_video_file_name,video_cover,pay_setting
  </sql>

  <select id="getById" resultMap="BaseResultMap" parameterType="java.lang.Long" >
    select 
    <include refid="Base_Column_List" />
    from advertising_cpa
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteById" parameterType="java.lang.Long" >
    delete from advertising_cpa
    where id = #{id,jdbcType=BIGINT}
  </delete>

  <insert id="insert" parameterType="com.pcloud.book.advertising.entity.AdvertisingCpa" useGeneratedKeys="true" keyProperty="id">
    insert into advertising_cpa (detail_name, detail_mode,
      cover_pic, welfare_pic, form_mobile_check, 
      form_remark, form_button, form_link, 
      create_time, update_time, detail_info, preview_link
      ,cover_video,bg_color,success_toast_type,success_toast_content,commit_button_type,commit_button_content
      ,commit_button_image,bottom_button_type,bottom_button_content,bottom_button_image,privacy_agreement,success_email,success_send_code,jump_style
      ,create_user,update_user,head_picture,cover_video_file_id,file_convert_state,cover_video_file_name,video_cover,pay_setting
      )
    values (#{detailName,jdbcType=VARCHAR}, #{detailMode,jdbcType=VARCHAR},
      #{coverPic,jdbcType=VARCHAR}, #{welfarePic,jdbcType=VARCHAR}, #{formMobileCheck,jdbcType=BIT}, 
      #{formRemark,jdbcType=VARCHAR}, #{formButton,jdbcType=VARCHAR}, #{formLink,jdbcType=VARCHAR}, 
      NOW(), NOW(), #{detailInfo,jdbcType=LONGVARCHAR}, #{previewLink,jdbcType=VARCHAR}
      ,#{coverVideo},#{bgColor},#{successToastType},#{successToastContent},#{commitButtonType},#{commitButtonContent},#{commitButtonImage}
      ,#{bottomButtonType},#{bottomButtonContent},#{bottomButtonImage},#{privacyAgreement},#{successEmail},#{successSendCode},#{jumpStyle},#{createUser},#{updateUser},#{headPicture}
      ,#{coverVideoFileId},#{fileConvertState},#{coverVideoFileName},#{videoCover},#{paySetting}
      )
  </insert>

  <update id="update" parameterType="com.pcloud.book.advertising.entity.AdvertisingCpa" >
    update advertising_cpa
    <set >
      <if test="detailName != null" >
        detail_name = #{detailName,jdbcType=VARCHAR},
      </if>
      <if test="detailMode != null" >
        detail_mode = #{detailMode,jdbcType=VARCHAR},
      </if>
      <if test="coverPic != null" >
        cover_pic = #{coverPic,jdbcType=VARCHAR},
      </if>
      <if test="welfarePic != null" >
        welfare_pic = #{welfarePic,jdbcType=VARCHAR},
      </if>
      <if test="formMobileCheck != null" >
        form_mobile_check = #{formMobileCheck,jdbcType=BIT},
      </if>
      <if test="formRemark != null" >
        form_remark = #{formRemark,jdbcType=VARCHAR},
      </if>
      <if test="formButton != null" >
        form_button = #{formButton,jdbcType=VARCHAR},
      </if>
      <if test="formLink != null" >
        form_link = #{formLink,jdbcType=VARCHAR},
      </if>
        update_time = NOW(),
      <if test="detailInfo != null" >
        detail_info = #{detailInfo,jdbcType=LONGVARCHAR},
      </if>
      <if test="previewLink != null">
        preview_link = #{previewLink,jdbcType=VARCHAR},
      </if>
      <if test="coverVideo != null">
        cover_video = #{coverVideo,jdbcType=VARCHAR},
      </if>
      <if test="bgColor != null">
        bg_color = #{bgColor},
      </if>
      <if test="successToastType != null">
        success_toast_type = #{successToastType},
      </if>
      <if test="successToastContent != null">
        success_toast_content = #{successToastContent},
      </if>
      <if test="commitButtonType != null">
        commit_button_type = #{commitButtonType},
      </if>
      <if test="commitButtonContent != null">
        commit_button_content = #{commitButtonContent},
      </if>
      <if test="commitButtonImage != null">
        commit_button_image = #{commitButtonImage},
      </if>
      <if test="bottomButtonType != null">
       bottom_button_type = #{bottomButtonType},
      </if>
      <if test="bottomButtonContent != null">
        bottom_button_content = #{bottomButtonContent},
      </if>
      <if test="bottomButtonImage != null">
        bottom_button_image = #{bottomButtonImage},
      </if>
      <if test="privacyAgreement != null">
        privacy_agreement = #{privacyAgreement},
      </if>
      <if test="successEmail != null">
        success_email = #{successEmail},
      </if>
      <if test="successSendCode != null">
        success_send_code = #{successSendCode},
      </if>
      <if test="jumpStyle != null">
        jump_style = #{jumpStyle},
      </if>
      <if test="createUser != null">
        create_user = #{createUser},
      </if>
      <if test="updateUser != null">
        update_user = #{updateUser},
      </if>
      <if test="headPicture != null">
        head_picture = #{headPicture},
      </if>
      <if test="coverVideoFileId != null">
        cover_video_file_id = #{coverVideoFileId},
      </if>
      <if test="fileConvertState != null">
        file_convert_state = #{fileConvertState},
      </if>
      <if test="coverVideoFileName != null">
        cover_video_file_name = #{coverVideoFileName},
      </if>
      <if test="videoCover != null">
        video_cover = #{videoCover},
      </if>
      <if test="paySetting != null">
        pay_setting = #{paySetting},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>

  <select id="listPage" parameterType="map" resultMap="AdvertisingCpaDTO">
    select
    <include refid="Base_Column_List"/>
    from advertising_cpa
    WHERE
    1 = 1
    <if test="name != null ">
      AND detail_name LIKE CONCAT( '%', #{name}, '%')
    </if>
    <if test="detailMode != null">
      AND detail_mode = #{detailMode,jdbcType=VARCHAR}
    </if>
    ORDER BY
    update_time DESC
  </select>

  <select id="getNoPreviewLinkCPAList" resultType="long">
    SELECT
        id
    FROM
        advertising_cpa
    WHERE
        preview_link IS NULL
    AND detail_mode IS NOT NULL
  </select>

  <update id="updateVideo" parameterType="com.pcloud.book.advertising.entity.AdvertisingCpa" >
    update advertising_cpa
    set
        cover_video = #{coverVideo,jdbcType=VARCHAR},
        cover_video_file_id = #{coverVideoFileId},
        file_convert_state = #{fileConvertState},
        cover_video_file_name = #{coverVideoFileName},
        video_cover = #{videoCover},
        update_time=now()
    where id = #{id,jdbcType=BIGINT}
  </update>

</mapper>