<?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.TpTicketRecordMapper" >
  <resultMap id="BaseResultMap" type="com.community.huiju.model.TpTicketRecord" >
    <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="content" property="content" jdbcType="VARCHAR" />
    <result column="status" property="status" jdbcType="CHAR" />
    <result column="create_user" property="createUser" jdbcType="INTEGER" />
    <result column="create_date" property="createDate" jdbcType="TIMESTAMP" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, community_id, ticket_id, content, status, create_user, create_date
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from tp_ticket_record
    where ticket_id = #{ticketId,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from tp_ticket_record
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.community.huiju.model.TpTicketRecord" >
    insert into tp_ticket_record (id, community_id, ticket_id, content,
      status, create_user, create_date
      )
    values (#{id,jdbcType=INTEGER}, #{communityId,jdbcType=INTEGER}, #{ticketId,jdbcType=INTEGER}, 
      #{content,jdbcType=VARCHAR}, #{status,jdbcType=CHAR}, #{createUser,jdbcType=INTEGER}, #{createDate,jdbcType=TIMESTAMP}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.community.huiju.model.TpTicketRecord" >
    insert into tp_ticket_record
    <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="content != null">
        content,
      </if>
      <if test="status != null" >
        status,
      </if>
      <if test="createUser != null" >
        create_user,
      </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="content != null">
        #{content,jdbcType=VARCHAR},
      </if>
      <if test="status != null" >
        #{status,jdbcType=CHAR},
      </if>
      <if test="createUser != null" >
        #{createUser,jdbcType=INTEGER},
      </if>
      <if test="createDate != null" >
        #{createDate,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.community.huiju.model.TpTicketRecord" >
    update tp_ticket_record
    <set >
      <if test="communityId != null" >
        community_id = #{communityId,jdbcType=INTEGER},
      </if>
      <if test="ticketId != null" >
        ticket_id = #{ticketId,jdbcType=INTEGER},
      </if>
      <if test="content != null">
        content = #{content,jdbcType=VARCHAR},
      </if>
      <if test="status != null" >
        status = #{status,jdbcType=CHAR},
      </if>
      <if test="createUser != null" >
        create_user = #{createUser,jdbcType=INTEGER},
      </if>
      <if test="createDate != null" >
        create_date = #{createDate,jdbcType=TIMESTAMP},
      </if>
    </set>
    where ticket_id = #{ticketId,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.community.huiju.model.TpTicketRecord" >
    update tp_ticket_record
    set community_id = #{communityId,jdbcType=INTEGER},
      ticket_id = #{ticketId,jdbcType=INTEGER},
      content = #{content,jdbcType=VARCHAR},
      status = #{status,jdbcType=CHAR},
      create_user = #{createUser,jdbcType=INTEGER},
      create_date = #{createDate,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=INTEGER}
  </update>


  <select id="getTicketRecordByTicketId" resultType="com.community.huiju.model.TpTicketRecord">
    SELECT
        t.id,
        t.status,
        t.ticket_id AS ticketId,
        t.community_id AS communityId,
        t.content AS content,
        t.create_date AS createDate,
        d.NAME AS ticketStatusName
    FROM
        tp_ticket_record t
        LEFT JOIN sys_dictionary d ON t.STATUS = d.CODE
        AND d.group_id = ( SELECT id FROM sys_dictionary WHERE CODE = "ticket_status" )
    WHERE
        community_id = #{communityId,jdbcType=INTEGER}
        AND ticket_id = #{ticketId,jdbcType=INTEGER}
    order by t.status
  </select>
  <select id="selectTpTicketRecord" resultType="com.community.huiju.model.TpTicketRecord">
    SELECT
    id, community_id, ticket_id, content, status, create_user, create_date
    FROM tp_ticket_record
    WHERE ticket_id = #{ticketId,jdbcType=INTEGER}
          and status = #{status,jdbcType=INTEGER}
</select>
</mapper>