<?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.gxwebsoft.glt.mapper.GltUserTicketLogMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*, u.nickname, u.avatar, u.phone
        FROM glt_user_ticket_log a
        LEFT JOIN gxwebsoft_core.sys_user u ON a.user_id = u.user_id
        <where>
            <if test="param.id != null">
                AND a.id = #{param.id}
            </if>
            <if test="param.userTicketId != null">
                AND a.user_ticket_id = #{param.userTicketId}
            </if>
            <if test="param.changeType != null">
                AND a.change_type = #{param.changeType}
            </if>
            <if test="param.changeAvailable != null">
                AND a.change_available = #{param.changeAvailable}
            </if>
            <if test="param.changeFrozen != null">
                AND a.change_frozen = #{param.changeFrozen}
            </if>
            <if test="param.changeUsed != null">
                AND a.change_used = #{param.changeUsed}
            </if>
            <if test="param.availableAfter != null">
                AND a.available_after = #{param.availableAfter}
            </if>
            <if test="param.frozenAfter != null">
                AND a.frozen_after = #{param.frozenAfter}
            </if>
            <if test="param.usedAfter != null">
                AND a.used_after = #{param.usedAfter}
            </if>
            <if test="param.orderId != null">
                AND a.order_id = #{param.orderId}
            </if>
            <if test="param.orderNo != null">
                AND a.order_no LIKE CONCAT('%', #{param.orderNo}, '%')
            </if>
            <if test="param.userId != null">
                AND a.user_id = #{param.userId}
            </if>
            <if test="param.sortNumber != null">
                AND a.sort_number = #{param.sortNumber}
            </if>
            <if test="param.comments != null">
                AND a.comments LIKE CONCAT('%', #{param.comments}, '%')
            </if>
            <if test="param.status != null">
                AND a.status = #{param.status}
            </if>
            <if test="param.deleted != null">
                AND a.deleted = #{param.deleted}
            </if>
            <if test="param.deleted == null">
                AND a.deleted = 0
            </if>
            <if test="param.createTimeStart != null">
                AND a.create_time &gt;= #{param.createTimeStart}
            </if>
            <if test="param.createTimeEnd != null">
                AND a.create_time &lt;= #{param.createTimeEnd}
            </if>
            <if test="param.keywords != null">
                AND (a.comments LIKE CONCAT('%', #{param.keywords}, '%')
                  OR a.user_id = #{param.keywords}
                  OR a.user_ticket_id = #{param.keywords}
                  OR a.order_no = #{param.keywords}
                )
              </if>
        </where>
    </sql>

    <!-- 分页查询 -->
    <select id="selectPageRel" resultType="com.gxwebsoft.glt.entity.GltUserTicketLog">
        <include refid="selectSql"></include>
    </select>

    <!-- 查询全部 -->
    <select id="selectListRel" resultType="com.gxwebsoft.glt.entity.GltUserTicketLog">
        <include refid="selectSql"></include>
    </select>

</mapper>
