<?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.TpTicketMapper">
    <select id="ticketList" resultType="com.community.huiju.model.TpTicket">
    SELECT
    p.id,
    p.community_id,
    p.ta_user_id,
    p.ticket_title,
    p.ticket_content,
    p.STATUS,
    p.type,
    p.repair_type,
    p.tp_user_id,
    p.score,
    p.COMMENT,
    p.create_user,
    p.create_date,
    p.update_user,
    p.update_date,
    us.user_name
    FROM
    tp_ticket p
    LEFT JOIN ta_user AS us ON p.create_user=us.id
    LEFT JOIN tp_user AS u ON p.tp_user_id = u.id
<where>
    <if test="ticket.id != null and ticket.id !=''">
        and  p.id like concat('%',#{ticket.id,jdbcType=INTEGER},'%')
    </if>
    <if test="ticket.type != null and ticket.type !=''">
        and p.type like concat('%',#{ticket.type,jdbcType=VARCHAR},'%')
    </if>
    <if test="ticket.ticketTitle != null and ticket.ticketTitle !=''">
        and p.ticket_title like concat('%',#{ticket.ticketTitle,jdbcType=VARCHAR},'%')
    </if>
    <if test="userName != null and userName !=''">
        and us.user_name like concat('%',#{ userName,jdbcType=VARCHAR},'%')
    </if>
    <if test="ticket.status != null and ticket.status !=''">
        and  p.status=#{ticket.status,jdbcType=INTEGER}
    </if>
    <if test="updateUserNmae != null and updateUserNmae !=''">
        and u.user_name like concat('%',#{ updateUserNmae,jdbcType=VARCHAR},'%')
    </if>
    and p.community_id=#{communityId,jdbcType=INTEGER}
</where>
        order by  create_date desc
    </select>

    <select id="ticketDetails" resultType="com.community.huiju.vo.TpTicketVO">
        SELECT
        p.id,
        p.community_id,
        p.ta_user_id,
        p.ticket_title,
        p.ticket_content,
        p.STATUS,
        p.type,
        p.repair_type,
        p.tp_user_id,
        p.score,
        p.COMMENT,
        p.create_user,
        p.create_date,
        p.update_user,
        p.update_date
        FROM
        tp_ticket p
        WHERE p.id=#{id,jdbcType=INTEGER}
    </select>
</mapper>
