<?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.boot.security.server.dao.SysLogsDao">

	<resultMap id="BaseResultMap" type="SysLogs">
		<id column="id" property="id" />
		<result column="module" property="module" />
		<result column="remark" property="remark" />
		<result column="flag" property="flag" />
		<result column="createTime" property="createTime" />
		<association property="user" javaType="SysUser">
			<result property="id" column="userId" />
			<result property="username" column="username" />
			<result property="nickname" column="nickname" />
		</association>
	</resultMap>

	<sql id="where">
		<where>
			<if test="params.flag != null and params.flag != ''">
				and t.flag = #{params.flag}
			</if>
			<if test="params.nickname != null and params.nickname != ''">
				and u.nickname like concat('%', #{params.nickname}, '%')
			</if>
			<if test="params.beginTime != null and params.beginTime != ''">
                and t.createTime &gt;= #{params.beginTime}
            </if>
            <if test="params.endTime != null and params.endTime != ''">
                and DATE(t.createTime) &lt;= #{params.endTime}
            </if>
		</where>
	</sql>

	<select id="count" resultType="int">
		select count(1) from sys_logs t left join sys_user
		u on
		u.id = t.userId
		<include refid="where" />
	</select>

	<select id="list" resultMap="BaseResultMap">
		select t.*, u.username, u.nickname from sys_logs t left join sys_user
		u on
		u.id = t.userId
		<include refid="where" />
		${params.orderBy}
		limit #{offset}, #{limit}
	</select>

</mapper>
