<?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.jsh.erp.datasource.mappers.LogMapperEx">
    <resultMap extends="com.jsh.erp.datasource.mappers.LogMapper.BaseResultMap" id="ResultExMap" type="com.jsh.erp.datasource.vo.LogVo4List">
        <result column="userName" jdbcType="VARCHAR" property="userName" />
    </resultMap>

    <select id="selectByConditionLog" parameterType="com.jsh.erp.datasource.entities.LogExample" resultMap="ResultExMap">
        select l.*,u.username userName
        FROM jsh_log l
        left join jsh_user u on l.user_id = u.id and ifnull(u.status,'0') not in('1','2')
        where 1=1
        <if test="operation != null">
            <bind name="bindOperation" value="'%'+operation+'%'"/>
            and l.operation like #{bindOperation}
        </if>
        <if test="userId != null">
            and l.user_id=#{userId}
        </if>
        <if test="clientIp != null">
            <bind name="bindClientIp" value="'%'+clientIp+'%'"/>
            and l.client_ip like #{bindClientIp}
        </if>
        <if test="status != null">
            and l.status=#{status}
        </if>
        <if test="beginTime != null">
            and l.create_time &gt;= #{beginTime}
        </if>
        <if test="endTime != null">
            and l.create_time &lt;= #{endTime}
        </if>
        <if test="content != null">
            <bind name="bindContent" value="'%'+content+'%'"/>
            and l.content like #{bindContent}
        </if>
        order by l.create_time desc
        <if test="offset != null and rows != null">
            limit #{offset},#{rows}
        </if>
    </select>
    <select id="countsByLog" resultType="java.lang.Long">
        SELECT
        COUNT(1)
        FROM jsh_log l
        left join jsh_user u on l.user_id = u.id and ifnull(u.status,'0') not in('1','2')
        WHERE 1=1
        <if test="operation != null">
            <bind name="bindOperation" value="'%'+operation+'%'"/>
            and l.operation like #{bindOperation}
        </if>
        <if test="userId != null">
            and l.user_id=#{userId}
        </if>
        <if test="clientIp != null">
            <bind name="bindClientIp" value="'%'+clientIp+'%'"/>
            and l.client_ip like #{bindClientIp}
        </if>
        <if test="status != null">
            and l.status = #{status}
        </if>
        <if test="beginTime != null">
            and l.create_time &gt;= #{beginTime}
        </if>
        <if test="endTime != null">
            and l.create_time &lt;= #{endTime}
        </if>
        <if test="content != null">
            <bind name="bindContent" value="'%'+content+'%'"/>
            and l.content like #{bindContent}
        </if>
    </select>
</mapper>