<?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.lantone.security.mapper.OperationLogMapper">
    <insert id="addOperLog">
        insert into
        sys_operation_log(operation_id,operation_name,operation_date,operation_ip,operation_address,operation_method,operation_way,operation_url,operation_param,json_result,gmt_create,remark)
        values (#{operationId},#{operationName},#{operationDate},
        <choose>
            <when test="operationIp != null || operationIp = !''">
                INET_ATON(#{operationIp}),
            </when>
            <otherwise>#{operationIp}),</otherwise>
        </choose>
        #{operationAddress},#{operationMethod},#{operationWay},#{operationUrl},#{operationParam},#{jsonResult},#{gmtCreate},#{remark})
    </insert>

    <select id="getOperationLog" resultType="com.lantone.common.dto.OperationLogDTO">
        SELECT
        id,
        a.operation_id AS operationId,
        a.operation_name AS operationName,
        a.operation_date AS operationDate,
        a.operation_method AS operationMethod,
        a.operation_way AS operationWay,
        a.operation_url AS operationUrl,
        a.operation_param AS operationParam,
        INET_NTOA(a.operation_ip) AS operationIp,
        a.operation_address AS operationAddress,
        a.json_result AS jsonResult
        FROM
        sys_operation_log a
        where
        1 = 1
        <if test="operationName != null and operationName != ''">
            AND a.operation_name like CONCAT('%',#{operationName},'%')
        </if>
        <if test="startDate != null and endDate != null">
            <![CDATA[ AND a.operation_date >= #{startDate}]]>
            <![CDATA[ AND a.operation_date <= #{endDate}]]>
        </if>
        order by a.operation_date desc
    </select>
</mapper>