<?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.group.mapper.ResourcePageShareMapper">
  <resultMap id="BaseResultMap" type="com.pcloud.book.group.entity.ResourcePageShare">
    <id column="qrcode_id" jdbcType="BIGINT" property="qrcodeId" />
    <result column="share_title" jdbcType="VARCHAR" property="shareTitle" />
    <result column="share_img_url" jdbcType="VARCHAR" property="shareImgUrl" />
    <result column="share_content" jdbcType="VARCHAR" property="shareContent" />
    <result column="version" jdbcType="INTEGER" property="version" />
    <result column="update_user" jdbcType="BIGINT" property="updateUser" />
    <result column="create_user" jdbcType="BIGINT" property="createUser" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  </resultMap>
  <resultMap id="BaseResultDtoMap" type="com.pcloud.book.group.dto.ResourcePageShareDto">
    <id column="qrcode_id" jdbcType="BIGINT" property="qrcodeId" />
    <result column="share_title" jdbcType="VARCHAR" property="shareTitle" />
    <result column="share_img_url" jdbcType="VARCHAR" property="shareImgUrl" />
    <result column="share_content" jdbcType="VARCHAR" property="shareContent" />
  </resultMap>
  <sql id="Base_Column_List">
    qrcode_id, share_title, share_img_url, share_content, version, update_user, create_user, 
    update_time, create_time
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from resource_page_share
    where qrcode_id = #{qrcodeId,jdbcType=BIGINT}
  </select>
  <select id="selectDtoByPrimaryKey" resultMap="BaseResultDtoMap">
    select
    <include refid="Base_Column_List" />
    from resource_page_share
    where qrcode_id = #{qrcodeId,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from resource_page_share
    where qrcode_id = #{qrcodeId,jdbcType=BIGINT}
  </delete>
  <insert id="insert" parameterType="com.pcloud.book.group.entity.ResourcePageShare">
    insert into resource_page_share (qrcode_id, share_title, share_img_url, 
      share_content, version, update_user, 
      create_user, update_time, create_time
      )
    values (#{qrcodeId,jdbcType=BIGINT}, #{shareTitle,jdbcType=VARCHAR}, #{shareImgUrl,jdbcType=VARCHAR}, 
      #{shareContent,jdbcType=VARCHAR}, #{version,jdbcType=INTEGER}, #{updateUser,jdbcType=BIGINT}, 
      #{createUser,jdbcType=BIGINT}, #{updateTime,jdbcType=TIMESTAMP}, #{createTime,jdbcType=TIMESTAMP}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.pcloud.book.group.entity.ResourcePageShare">
    insert into resource_page_share
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="qrcodeId != null">
        qrcode_id,
      </if>
      <if test="shareTitle != null">
        share_title,
      </if>
      <if test="shareImgUrl != null">
        share_img_url,
      </if>
      <if test="shareContent != null">
        share_content,
      </if>
      <if test="version != null">
        version,
      </if>
      <if test="updateUser != null">
        update_user,
      </if>
      <if test="createUser != null">
        create_user,
      </if>
      <if test="updateTime != null">
        update_time,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="qrcodeId != null">
        #{qrcodeId,jdbcType=BIGINT},
      </if>
      <if test="shareTitle != null">
        #{shareTitle,jdbcType=VARCHAR},
      </if>
      <if test="shareImgUrl != null">
        #{shareImgUrl,jdbcType=VARCHAR},
      </if>
      <if test="shareContent != null">
        #{shareContent,jdbcType=VARCHAR},
      </if>
      <if test="version != null">
        #{version,jdbcType=INTEGER},
      </if>
      <if test="updateUser != null">
        #{updateUser,jdbcType=BIGINT},
      </if>
      <if test="createUser != null">
        #{createUser,jdbcType=BIGINT},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <insert id="save" parameterType="com.pcloud.book.group.entity.ResourcePageShare">
    insert into resource_page_share (qrcode_id, share_title, share_img_url,
                                     share_content, version, update_user,
                                     create_user, update_time, create_time
    )
    values (#{qrcodeId,jdbcType=BIGINT}, #{shareTitle,jdbcType=VARCHAR}, #{shareImgUrl,jdbcType=VARCHAR},
            #{shareContent,jdbcType=VARCHAR}, 1, #{updateUser,jdbcType=BIGINT},
            #{createUser,jdbcType=BIGINT}, now(), now()
           )
    ON DUPLICATE KEY UPDATE
        share_title = #{shareTitle,jdbcType=VARCHAR},
        share_img_url = #{shareImgUrl,jdbcType=VARCHAR},
        share_content = #{shareContent,jdbcType=VARCHAR},
      update_time=now(),
      version=version+1;
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.pcloud.book.group.entity.ResourcePageShare">
    update resource_page_share
    <set>
      <if test="shareTitle != null">
        share_title = #{shareTitle,jdbcType=VARCHAR},
      </if>
      <if test="shareImgUrl != null">
        share_img_url = #{shareImgUrl,jdbcType=VARCHAR},
      </if>
      <if test="shareContent != null">
        share_content = #{shareContent,jdbcType=VARCHAR},
      </if>
      <if test="version != null">
        version = #{version,jdbcType=INTEGER},
      </if>
      <if test="updateUser != null">
        update_user = #{updateUser,jdbcType=BIGINT},
      </if>
      <if test="createUser != null">
        create_user = #{createUser,jdbcType=BIGINT},
      </if>
      <if test="updateTime != null">
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where qrcode_id = #{qrcodeId,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.pcloud.book.group.entity.ResourcePageShare">
    update resource_page_share
    set share_title = #{shareTitle,jdbcType=VARCHAR},
      share_img_url = #{shareImgUrl,jdbcType=VARCHAR},
      share_content = #{shareContent,jdbcType=VARCHAR},
      version = #{version,jdbcType=INTEGER},
      update_user = #{updateUser,jdbcType=BIGINT},
      create_user = #{createUser,jdbcType=BIGINT},
      update_time = #{updateTime,jdbcType=TIMESTAMP},
      create_time = #{createTime,jdbcType=TIMESTAMP}
    where qrcode_id = #{qrcodeId,jdbcType=BIGINT}
  </update>
  <select id="selectByResourcePageId" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from resource_page_share
    where qrcode_id = #{sceneId}
    limit 1
  </select>

</mapper>