<?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.SysLogDao">

    <sql id="includeLog">
        id,
        username,
        COALESCE(action, '') action,
        COALESCE(classname, '') classname,
        COALESCE(method, '') method,
        COALESCE(params, '') params,
        COALESCE(time, '') time,
        COALESCE(ip, '') ip,
        create_time
    </sql>

    <resultMap id="resultMapLogList" type="java.util.LinkedHashMap">
        <id property="id" column="id" jdbcType="BIGINT" />
        <result property="username" column="username" />
        <result property="action" column="action" />
        <result property="classname" column="classname" />
        <result property="method" column="method" />
        <result property="params" column="params" />
        <result property="time" column="time" javaType="java.lang.Long" />
        <result property="ip" column="ip" />
        <result property="create_time" column="create_time" />
    </resultMap>

    <select id="selectLogList" resultMap="resultMapLogList">
        SELECT <include refid="includeLog" />
        FROM sys_log
        <where>
            <if test="username != null and username != ''">
                AND username LIKE CONCAT('%', #{username}, '%')
            </if>
            <if test="action != null and action != ''">
                AND action LIKE CONCAT('%', #{action}, '%')
            </if>
            <if test="ip != null and ip != ''">
                AND ip = #{ip}
            </if>
            <if test="create_time_begin != null and create_time_begin != '' and create_time_end != null and create_time_end != ''">
                AND create_time BETWEEN #{create_time_begin} AND #{create_time_end}
            </if>
        </where>
        ORDER BY create_time DESC
    </select>

</mapper>