<?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.huiju.estateagents.property.dao.TpTicketRecordMapper">
<select id="selectTpTicketRecord" resultType="com.huiju.estateagents.property.model.TpTicketRecord">
    SELECT
    id, org_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>
    <update id="updateTicketRecord" parameterType="com.huiju.estateagents.property.model.TpTicketRecord" >
        update tp_ticket_record
        <set >
            <if test="orgId != null" >
                org_id = #{orgId,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>
    <select id="statusName" resultType="string">
        SELECT
       name
        FROM sys_dictionary
        WHERE code= #{status,jdbcType=INTEGER}
          and group_id = 1
    </select>

    <select id="getTicketRecordByTicketId" resultType="com.huiju.estateagents.property.model.TpTicketRecord">
    SELECT
        t.id,
        t.status,
        t.ticket_id AS ticketId,
        t.org_id AS orgId,
        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
        org_id = #{orgId,jdbcType=INTEGER}
        AND ticket_id = #{ticketId,jdbcType=INTEGER}
    order by t.status
  </select>
</mapper>
