<?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.cab.dao.ContentCommentMapper" >
  <resultMap id="BaseResultMap" type="com.cab.model.ContentComment" >
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="content" property="content" jdbcType="VARCHAR" />
    <result column="last_updated" property="lastUpdated" jdbcType="TIMESTAMP" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="follow_count" property="followCount" jdbcType="BIGINT" />
    <result column="content_id" property="contentId" jdbcType="BIGINT" />
    <association property="user" column="user_id" javaType="com.cab.model.User" resultMap="com.cab.dao.UserMapper.BaseJoinMap"/>
  </resultMap>
  <sql id="Base_Column_List" >
    CC.id, content, last_updated, create_time, user_id, content_id, follow_count
  </sql>
  
  <select id="selectByContentId" resultMap="BaseResultMap" >
    select 
    <include refid="Base_Column_List" />, U.avatar, U.name
    from cab_content_comment CC inner join cab_users U on CC.user_id = U.id
    where content_id = #{contentId,jdbcType=BIGINT} order by create_time desc limit #{start},#{limit}
  </select>
  <select id="getCount" resultType="java.lang.Long">
  select count(id) FROM cab_content_comment where content_id=#{contentId,jdbcType=BIGINT}
  </select>
  <insert id="insertSelective" parameterType="com.cab.model.ContentComment" useGeneratedKeys="true" keyProperty="id">
    insert into cab_content_comment
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="content != null" >
        content,
      </if>
      <if test="lastUpdated != null" >
        last_updated,
      </if>
      <if test="deleted != null" >
        deleted,
      </if>
      <if test="createTime != null" >
        create_time,
      </if>
      <if test="userId != null" >
        user_id,
      </if>
      <if test="contentId != null" >
        content_id,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=BIGINT},
      </if>
      <if test="content != null" >
        #{content,jdbcType=VARCHAR},
      </if>
      <if test="lastUpdated != null" >
        #{lastUpdated,jdbcType=TIMESTAMP},
      </if>
      <if test="deleted != null" >
        #{deleted,jdbcType=TIMESTAMP},
      </if>
      <if test="createTime != null" >
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="userId != null" >
        #{userId,jdbcType=BIGINT},
      </if>
      <if test="contentId != null" >
        #{contentId,jdbcType=BIGINT},
      </if>
    </trim>
  </insert>
  
  <update id="increaseFollowCount" parameterType="java.lang.Long">
      update cab_content_comment set follow_count = follow_count + 1 where id = #{id,jdbcType=BIGINT}
  </update>
</mapper>