<?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.common.system.mapper.UserBalanceLogMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*,
               b.nickname,b.avatar,b.phone
        FROM sys_user_balance_log a
        LEFT JOIN sys_user b ON a.user_id = b.user_id
        <where>
            <if test="param.logId != null">
                AND a.log_id = #{param.logId}
            </if>
            <if test="param.userId != null">
                AND a.user_id = #{param.userId}
            </if>
            <if test="param.scene != null">
              AND a.scene = #{param.scene}
            </if>
            <if test="param.sceneMultiple != null">
              AND a.scene IN
              <foreach collection="param.sceneMultiple.split(',')" item="item" separator="," open="(" close=")">
                #{item}
              </foreach>
            </if>
            <if test="param.money != null">
                AND a.money = #{param.money}
            </if>
            <if test="param.balance != null">
                AND a.balance = #{param.balance}
            </if>
            <if test="param.describe != null">
                AND a.describe LIKE CONCAT('%', #{param.describe}, '%')
            </if>
            <if test="param.remark != null">
                AND a.remark LIKE CONCAT('%', #{param.remark}, '%')
            </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.merchantCode != null">
                AND a.merchant_code LIKE CONCAT('%', #{param.merchantCode}, '%')
            </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.user_id = #{param.keywords}
              OR b.nickname LIKE CONCAT('%', #{param.keywords}, '%')
              OR b.alias LIKE CONCAT('%', #{param.keywords}, '%')
              OR b.phone = #{param.keywords}
              )
            </if>
        </where>
    </sql>

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

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

</mapper>
