<?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.backendsys.modules.system.dao.SysUserIntegralLogDao">

    <sql id="includeIntegralLog">
        uil.id,
        uil.user_id,
        COALESCE(ufsec.nickname, '') user_nickname,
        COALESCE(uil.content, '') content,
        uil.integral,
        uil.operation,
        COALESCE(uil.operation_user_id, '') operation_user_id,
        COALESCE(uf.nickname, '') operation_user_nickname,
        uil.origin,
        COALESCE(uil.operation_ip, '') operation_ip,
        uil.create_time
    </sql>

    <resultMap id="resultMapIntegralLogList" type="java.util.LinkedHashMap">
        <id property="id" column="id" jdbcType="BIGINT" />
        <result property="user_id" column="user_id" javaType="java.lang.Long" />
        <result property="user_nickname" column="user_nickname" />
        <result property="content" column="content" />
        <result property="integral" column="integral" javaType="java.lang.Integer" />
        <result property="operation" column="operation" javaType="java.lang.Integer" />
        <result property="operation_user_id" column="operation_user_id" javaType="java.lang.Long" />
        <result property="operation_user_nickname" column="operation_user_nickname" />
        <result property="origin" column="origin" javaType="java.lang.Integer" />
        <result property="operation_ip" column="operation_ip" />
        <result property="create_time" column="create_time" />
    </resultMap>

    <select id="selectIntegralLogList" resultMap="resultMapIntegralLogList">
        SELECT <include refid="includeIntegralLog" />
        FROM sys_user_integral_log uil
        LEFT JOIN sys_user_info uf ON uil.operation_user_id = uf.user_id
        LEFT JOIN sys_user_info ufsec ON uil.user_id = ufsec.user_id
        <where>
            <if test="user_id != null and user_id != ''">
                AND uil.user_id = #{user_id}
            </if>
            <if test="user_nickname != null and user_nickname != ''">
                AND ufsec.nickname LIKE CONCAT('%', #{user_nickname}, '%')
            </if>
            <if test="content != null and content != ''">
                AND uil.content LIKE CONCAT('%', #{content}, '%')
            </if>
            <if test="operation != null and operation != ''">
                AND uil.operation = #{operation}
            </if>
            <if test="operation_user_id != null and operation_user_id != ''">
                AND uil.operation_user_id = #{operation_user_id}
            </if>
            <if test="operation_user_nickname != null and operation_user_nickname != ''">
                AND uf.nickname LIKE CONCAT('%', #{operation_user_nickname}, '%')
            </if>
            <if test="operation_ip != null and operation_ip != ''">
                AND uil.operation_ip = #{operation_ip}
            </if>
            <if test="create_time_begin != null and create_time_begin != '' and create_time_end != null and create_time_end != ''">
                AND uil.create_time BETWEEN #{create_time_begin} AND #{create_time_end}
            </if>
        </where>
        ORDER BY create_time DESC
    </select>

</mapper>


