<?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.AbnormalLogMapper">
    <insert id="addOperErrorLog">
        insert into
        sys_abnormal_log(operation_id,operation_name,operation_ip,operation_agent,operation_error_info,operation_method,operation_way,operation_url,operation_param,gmt_create)
        values (#{operationId},#{operationName},
        <choose>
            <when test="operationIp != null || operationIp = !''">
                INET_ATON(#{operationIp}),
            </when>
            <otherwise>#{operationIp}),</otherwise>
        </choose>
        #{operationAgent},#{operationErrorInfo},#{operationMethod},#{operationWay},#{operationUrl},#{operationParam},#{gmtCreate})
    </insert>

    <select id="getAbnormalLog" resultType="com.lantone.common.dto.AbnormalLogDTO">
        SELECT
        id,
        a.operation_id AS operationId,
        a.operation_name AS operationName,
        a.gmt_create AS gmtCreate,
        a.operation_method AS operationMethod,
        a.operation_way AS operationWay,
        a.operation_url AS operationUrl,
        a.operation_param AS operationParam,
        a.operation_agent AS operationAgent,
        a.operation_error_info AS operationErrorInfo,
        INET_NTOA(a.operation_ip) AS operationIp
        FROM
        sys_abnormal_log a
        where
        1 = 1
        <if test="operationWay != null and operationWay != ''">
            AND a.operation_way like CONCAT('%',#{operationWay},'%')
        </if>
        <if test="operationIp != null and operationIp != ''">
            AND INET_NTOA(a.operation_ip) like CONCAT('%',#{operationIp},'%')
        </if>
        order by a.gmt_create desc
    </select>

    <select id="getAbnormalLogWayAndIp" resultType="java.lang.String">
        SELECT
        <if test="mark == 0">
            a.operation_way AS operationWay
        </if>
        <if test="mark == 1">
            INET_NTOA(a.operation_ip) AS operationIp
        </if>
        FROM
        sys_abnormal_log a
        where
        1 = 1
        <if test="operationWay != null and operationWay != ''">
            AND a.operation_way like CONCAT('%',#{operationWay},'%')
        </if>
        <if test="operationIp != null and operationIp != ''">
            AND INET_NTOA(a.operation_ip) like CONCAT('%',#{operationIp},'%')
        </if>
    </select>
</mapper>