<?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.TpTicketMapper">
    <select id="ticketList" resultType="com.huiju.estateagents.property.model.TpTicket">
    SELECT
    p.id,
    p.org_id,
    p.person_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.name as user_name
    FROM
    tp_ticket p
    LEFT JOIN ta_person AS us ON p.create_user=us.person_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.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 us.name like concat('%',#{ updateUserNmae,jdbcType=VARCHAR},'%')
    </if>
    and p.org_id=#{orgId,jdbcType=INTEGER}
</where>
        order by  create_date desc
    </select>

    <select id="ticketDetails" resultType="com.huiju.estateagents.property.vo.TpTicketVO">
        SELECT
        p.id,
        p.org_id,
        p.person_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,
        p.price,
        p.bill_invoice_id,
        p.worker_id,
        p.worker_name
        FROM
        tp_ticket p
        WHERE p.id=#{id,jdbcType=INTEGER}
    </select>

    <select id="selectByCommuniytIdAndByTaUserIdAndByType" parameterType="java.util.Map" resultType="com.huiju.estateagents.property.model.TpTicket" >
        select
         *
        from tp_ticket
        <trim prefix="where" prefixOverrides="and">
            <if test="orgId != null" >
                and org_id = #{orgId,jdbcType=INTEGER}
            </if>
            <if test="personId!= null" >
                and person_id = #{personId}
            </if>
            <if test="type != null" >
                and type = #{type,jdbcType=CHAR}
            </if>
        </trim>
        order by create_date DESC
    </select>

    <select id="selectTpTicketName" resultType="com.huiju.estateagents.property.model.TpTicket">
    select
    *
    from tp_ticket
    where org_id = #{orgId,jdbcType=INTEGER}
     and ticket_title= #{ticketTitle,jdbcType=INTEGER}
     and type = #{type,jdbcType=VARCHAR}
  </select>

    <update id="updateTpUserId" parameterType="int" >
    update tp_ticket
    set
      tp_user_id =null
    where id = #{ticketId,jdbcType=INTEGER}
  </update>
</mapper>
