<?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.ejweb.modules.sys.dao.LogDao">
    
    <select id="findList" resultType="Log">
        SELECT 
            a.*,
            u.id AS "createBy.id",
            u.name AS "createBy.name",
            c.name AS "createBy.company.name",
            o.name AS "createBy.office.name"
        FROM ct_bbtc_sys_log a
        LEFT JOIN ct_bbtc_sys_user u ON u.id = a.create_by
        LEFT JOIN ct_bbtc_sys_office c ON c.id = u.company_id
        LEFT JOIN ct_bbtc_sys_office o ON o.id = u.office_id
        WHERE a.create_date BETWEEN #{beginDate} AND #{endDate}
        <if test="title != null and title != ''">
            AND a.title LIKE 
                    <if test="dbName == 'oracle'">'%'||#{title}||'%'</if>
                    <if test="dbName == 'mssql'">'%'+#{title}+'%'</if>
                    <if test="dbName == 'mysql'">CONCAT('%', #{title}, '%')</if>
        </if>
        <if test="createBy != null and createBy.id != null and createBy.id != ''">
            AND a.create_by = #{createBy.id}
        </if>
        <if test="requestUri != null and requestUri != ''">
            AND a.request_uri LIKE 
                    <if test="dbName == 'oracle'">'%'||#{requestUri}||'%'</if>
                    <if test="dbName == 'mssql'">'%'+#{requestUri}+'%'</if>
                    <if test="dbName == 'mysql'">CONCAT('%', #{requestUri}, '%')</if>
        </if>
        <if test="exception != null and exception != ''">
            AND a.type = #{TYPE_EXCEPTION}
        </if>
        ORDER BY a.create_date DESC
    </select>
    
    <insert id="insert">
        INSERT INTO ct_bbtc_sys_log(
            id, 
            type, 
            title,
            create_by, 
            create_date, 
            remote_addr, 
            user_agent, 
            request_uri, 
            method, 
            params, 
            exception
        ) VALUES (
            #{id}, 
            #{type}, 
            #{title}, 
            #{createBy.id}, 
            #{createDate}, 
            #{remoteAddr}, 
            #{userAgent}, 
            #{requestUri}, 
            #{method}, 
            #{params}, 
            #{exception}
        )
    </insert>
    
</mapper>