<?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" />
  </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" />
  </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
  </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
      )
    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}
      )
  </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>
    </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>

</mapper>