<?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.AdvertisingLinkRevertDaoImpl" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.advertising.entity.AdvertisingLinkRevert" >
    <id column="id" property="id" jdbcType="BIGINT" />
    <id column="brand_id" property="brandId" jdbcType="BIGINT" />
    <result column="link" property="link" jdbcType="VARCHAR" />
    <result column="revert_link" property="revertLink" jdbcType="VARCHAR" />
    <result column="short_link" property="shortLink" jdbcType="VARCHAR" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="create_user" property="createUser" jdbcType="BIGINT" />
  </resultMap>

  <sql id="Base_Column_List" >
    id, brand_id, link, revert_link, short_link, create_time, create_user
  </sql>


  <insert id="insert" parameterType="com.pcloud.book.advertising.entity.AdvertisingLinkRevert" useGeneratedKeys="true" keyProperty="id">
    insert into advertising_link_revert (id, brand_id, link, revert_link,
      short_link, create_time, create_user
      )
    values (#{id,jdbcType=BIGINT}, #{brandId,jdbcType=BIGINT}, #{link,jdbcType=VARCHAR}, #{revertLink},
      #{shortLink,jdbcType=VARCHAR}, NOW(), #{createUser,jdbcType=BIGINT}
      )
  </insert>

  <delete id="deleteById" parameterType="long">
    DELETE FROM advertising_link_revert
    WHERE id = #{id}
  </delete>

  <select id="listRevertRecord" parameterType="map" resultType="com.pcloud.book.advertising.dto.LinkRevertRecordDTO">
    SELECT
        id id,
        brand_id brandId,
        link link,
        short_link shortLink,
        create_time createTime
    FROM
        advertising_link_revert
    WHERE
        1 = 1
    <if test="null != brandId">
      AND brand_id = #{brandId}
    </if>
    ORDER BY
    create_time DESC,
    id DESC
  </select>

  <update id="update" parameterType="com.pcloud.book.advertising.entity.AdvertisingLinkRevert">
      update advertising_link_revert
      <set >
        <if test="link != null" >
          link = #{link,jdbcType=VARCHAR},
        </if>
        <if test="revertLink != null" >
          revert_link = #{revertLink,jdbcType=VARCHAR},
        </if>
        <if test="shortLink != null" >
          short_link = #{shortLink,jdbcType=VARCHAR},
        </if>
      </set>
    WHERE id = #{id}
  </update>

  <select id="getById" parameterType="long" resultMap="BaseResultMap">
    SELECT <include refid="Base_Column_List"/>
    FROM advertising_link_revert
    WHERE id = #{id}
  </select>

  <select id="getAll" resultMap="BaseResultMap">
    SELECT <include refid="Base_Column_List"/>
    FROM advertising_link_revert
  </select>

</mapper>