<?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.community.huiju.dao.TpTicketRecordCommentMapper" >
  <resultMap id="BaseResultMap" type="com.community.huiju.model.TpTicketRecordComment" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="community_id" property="communityId" jdbcType="INTEGER" />
    <result column="ticket_id" property="ticketId" jdbcType="INTEGER" />
    <result column="ticket_record_id" property="ticketRecordId" jdbcType="INTEGER" />
    <result column="uuid" property="uuid" jdbcType="INTEGER" />
    <result column="user_type" property="userType" jdbcType="CHAR" />
    <result column="content" property="content" jdbcType="VARCHAR" />
    <result column="parent_id" property="parentId" jdbcType="INTEGER" />
    <result column="user_name" property="userName" jdbcType="VARCHAR" />
    <result column="create_date" property="createDate" jdbcType="TIMESTAMP" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, community_id, ticket_id, ticket_record_id, uuid, user_type, content, parent_id,
    user_name, create_date
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from tp_ticket_record_comment
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from tp_ticket_record_comment
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" useGeneratedKeys="true" keyProperty="id"  parameterType="com.community.huiju.model.TpTicketRecordComment" >
    insert into tp_ticket_record_comment (id, community_id, ticket_id,
      ticket_record_id, uuid, user_type, 
      content, parent_id, user_name, 
      create_date)
    values (#{id,jdbcType=INTEGER}, #{communityId,jdbcType=INTEGER}, #{ticketId,jdbcType=INTEGER},
      #{ticketRecordId,jdbcType=INTEGER}, #{uuid,jdbcType=INTEGER}, #{userType,jdbcType=CHAR}, 
      #{content,jdbcType=VARCHAR}, #{parentId,jdbcType=INTEGER}, #{userName,jdbcType=VARCHAR}, 
      #{createDate,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.community.huiju.model.TpTicketRecordComment" >
    insert into tp_ticket_record_comment
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="communityId != null" >
        community_id,
      </if>
      <if test="ticketId != null" >
        ticket_id,
      </if>
      <if test="ticketRecordId != null" >
        ticket_record_id,
      </if>
      <if test="uuid != null" >
        uuid,
      </if>
      <if test="userType != null" >
        user_type,
      </if>
      <if test="content != null" >
        content,
      </if>
      <if test="parentId != null" >
        parent_id,
      </if>
      <if test="userName != null" >
        user_name,
      </if>
      <if test="createDate != null" >
        create_date,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=INTEGER},
      </if>
      <if test="communityId != null" >
        #{communityId,jdbcType=INTEGER},
      </if>
      <if test="ticketId != null" >
        #{ticketId,jdbcType=INTEGER},
      </if>
      <if test="ticketRecordId != null" >
        #{ticketRecordId,jdbcType=INTEGER},
      </if>
      <if test="uuid != null" >
        #{uuid,jdbcType=INTEGER},
      </if>
      <if test="userType != null" >
        #{userType,jdbcType=CHAR},
      </if>
      <if test="content != null" >
        #{content,jdbcType=VARCHAR},
      </if>
      <if test="parentId != null" >
        #{parentId,jdbcType=INTEGER},
      </if>
      <if test="userName != null" >
        #{userName,jdbcType=VARCHAR},
      </if>
      <if test="createDate != null" >
        #{createDate,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.community.huiju.model.TpTicketRecordComment" >
    update tp_ticket_record_comment
    <set >
      <if test="communityId != null" >
        community_id = #{communityId,jdbcType=INTEGER},
      </if>
      <if test="ticketId != null" >
        ticket_id = #{ticketId,jdbcType=INTEGER},
      </if>
      <if test="ticketRecordId != null" >
        ticket_record_id = #{ticketRecordId,jdbcType=INTEGER},
      </if>
      <if test="uuid != null" >
        uuid = #{uuid,jdbcType=INTEGER},
      </if>
      <if test="userType != null" >
        user_type = #{userType,jdbcType=CHAR},
      </if>
      <if test="content != null" >
        content = #{content,jdbcType=VARCHAR},
      </if>
      <if test="parentId != null" >
        parent_id = #{parentId,jdbcType=INTEGER},
      </if>
      <if test="userName != null" >
        user_name = #{userName,jdbcType=VARCHAR},
      </if>
      <if test="createDate != null" >
        create_date = #{createDate,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.community.huiju.model.TpTicketRecordComment" >
    update tp_ticket_record_comment
    set community_id = #{communityId,jdbcType=INTEGER},
      ticket_id = #{ticketId,jdbcType=INTEGER},
      ticket_record_id = #{ticketRecordId,jdbcType=INTEGER},
      uuid = #{uuid,jdbcType=INTEGER},
      user_type = #{userType,jdbcType=CHAR},
      content = #{content,jdbcType=VARCHAR},
      parent_id = #{parentId,jdbcType=INTEGER},
      user_name = #{userName,jdbcType=VARCHAR},
      create_date = #{createDate,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=INTEGER}
  </update>

  <select id="selectByTicketId" parameterType="map" resultMap="BaseResultMap" >
    select ttrc.* from tp_ticket tp
                inner join tp_ticket_record ttr on tp.id = ttr.ticket_id
                inner join tp_ticket_record_comment ttrc on ttr.id = ttrc.ticket_record_id
    where tp.id=#{tickerId,jdbcType=INTEGER} order by ttrc.create_date DESC LIMIT #{size,jdbcType=INTEGER}
  </select>

  <select id="selectByTicketRecordId" parameterType="com.community.huiju.model.TpTicketRecord" resultMap="BaseResultMap" >
    SELECT
    <include refid="Base_Column_List" />
    FROM
        tp_ticket_record_comment
    WHERE
        community_id = #{communityId,jdbcType=INTEGER}
        AND ticket_id = #{ticketId,jdbcType=INTEGER}
        AND ticket_record_id = #{id,jdbcType=INTEGER}
  </select>
  <select id="getUuID" resultType="com.community.huiju.model.TpTicketRecordComment">
    SELECT
	*
    FROM
        tp_ticket_record_comment
    WHERE user_type=0
    and ticket_id= #{ticketId,jdbcType=INTEGER}
    and  community_id = #{communityId,jdbcType=INTEGER}
    ORDER BY
	create_date DESC
    LIMIT 1
  </select>
</mapper>