<?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.gz.mapper.system.LogMapper">

    <select id="selectByTime" resultType="com.gz.rvo.system.LogRVO" parameterType="com.gz.vo.system.LogVO">
        SELECT
        l.*,
        u.admin_name
        FROM
        `tab_log` l
        LEFT JOIN `tab_admin` u ON l.exec_by = u.id
        <where>
            <if test="logType != null and logType != ''">
                and l.log_type = #{logType}
            </if>
            <if test="module != null and module != ''">
                and l.module = #{module}
            </if>
            <if test="business != null and business != ''">
                and l.business = #{business}
            </if>
            <if test="startTime != null and startTime != ''">
                and l.exec_time <![CDATA[>=]]> #{startTime}
            </if>
            <if test="endTime != null and endTime != ''">
                and l.exec_time <![CDATA[<=]]> #{endTime}
            </if>
        </where>
        ORDER BY l.exec_time DESC
    </select>

    <select id="selectLogModule" resultType="string">
        select module from tab_log group by module
    </select>

    <select id="selectLogBusiness" resultType="string" parameterType="string">
        select business from tab_log where module = #{module} group by business
    </select>

    <select id="clearAll" resultType="integer">
        TRUNCATE TABLE `tab_log`;
    </select>

    <select id="clearThirtyOut" resultType="integer">
        delete from tab_log where DATE_FORMAT(exec_time,'%Y-%m-%d') <![CDATA[<]]> DATE_SUB(curdate(),interval 30 day)
    </select>


    <select id="selectCountByTime" resultType="integer">
        select count(id) from tab_log l
        <where>
            <if test="logType != null and logType != ''">
                and l.log_type = #{logType}
            </if>
            <if test="startTime != null and startTime != ''">
                and l.exec_time <![CDATA[>=]]> #{startTime}
            </if>
            <if test="endTime != null and endTime != ''">
                and l.exec_time <![CDATA[<=]]> #{endTime}
            </if>
        </where>
    </select>
</mapper>
