<?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.AdvertisingWechatMsgDaoImpl" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.advertising.entity.AdvertisingWechatMsg" >
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="ad_id" property="adId" jdbcType="BIGINT" />
    <result column="ad_position_mode" property="adPositionMode" jdbcType="VARCHAR" />
    <result column="ad_link" property="adLink" jdbcType="VARCHAR" />
    <result column="ad_title" property="adTitle" jdbcType="VARCHAR" />
    <result column="ad_slogan" property="adSlogan" jdbcType="VARCHAR" />
    <result column="ad_pic" property="adPic" jdbcType="VARCHAR" />
    <result column="seq" property="seq" jdbcType="INTEGER" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
  </resultMap>

  <sql id="Base_Column_List" >
    id, ad_id, ad_position_mode, ad_link, ad_title, ad_slogan, ad_pic, seq, create_time, update_time
  </sql>

  <insert id="insert" parameterType="com.pcloud.book.advertising.entity.AdvertisingWechatMsg" useGeneratedKeys="true" keyProperty="id">
    insert into advertising_wechat_msg (ad_id, ad_position_mode,
      ad_link, ad_title, ad_slogan, 
      ad_pic, seq, create_time, update_time
      )
    values (#{adId,jdbcType=BIGINT}, #{adPositionMode,jdbcType=VARCHAR},
      #{adLink,jdbcType=VARCHAR}, #{adTitle,jdbcType=VARCHAR}, #{adSlogan,jdbcType=VARCHAR}, 
      #{adPic,jdbcType=VARCHAR},#{seq},NOW(), NOW()
      )
  </insert>

  <delete id="deleteById" parameterType="java.lang.Long" >
    delete from advertising_wechat_msg
    where id = #{id,jdbcType=BIGINT}
  </delete>

  <update id="update" parameterType="com.pcloud.book.advertising.entity.AdvertisingWechatMsg" >
    update advertising_wechat_msg
    set
    ad_id = #{adId,jdbcType=BIGINT},
    ad_position_mode = #{adPositionMode,jdbcType=VARCHAR},
    ad_link = #{adLink,jdbcType=VARCHAR},
    ad_title = #{adTitle,jdbcType=VARCHAR},
    ad_slogan = #{adSlogan,jdbcType=VARCHAR},
    ad_pic = #{adPic,jdbcType=VARCHAR},
    update_time = NOW()
    where id = #{id,jdbcType=BIGINT}
  </update>

  <insert id="batchInsert" useGeneratedKeys="true" parameterType="java.util.List" keyProperty="id">
    insert into advertising_wechat_msg (ad_id, ad_position_mode,
    ad_link, ad_title, ad_slogan,
    ad_pic, seq, create_time, update_time
    )
    values
    <foreach collection="list" item="item" index="index" separator="," >
      (#{item.adId,jdbcType=BIGINT}, #{item.adPositionMode,jdbcType=VARCHAR},
      #{item.adLink,jdbcType=VARCHAR}, #{item.adTitle,jdbcType=VARCHAR}, #{item.adSlogan,jdbcType=VARCHAR},
      #{item.adPic,jdbcType=VARCHAR}, #{item.seq}, NOW(), NOW()
      )
    </foreach>
  </insert>

  <select id="getByAdId" resultMap="BaseResultMap" parameterType="long">
    SELECT <include refid="Base_Column_List"></include>
    FROM advertising_wechat_msg WHERE ad_id = #{adId,jdbcType=BIGINT}
    order by seq asc
  </select>

  <delete id="deleteByAdId" parameterType="java.lang.Long" >
    delete from advertising_wechat_msg
    where ad_id = #{adId,jdbcType=BIGINT}
  </delete>

</mapper>