<?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.github.tangyi.user.mapper.LogMapper">
    <resultMap id="logResultMap" type="com.github.tangyi.common.core.model.Log">
        <id column="id" property="id"/>
        <result column="type" property="type"/>
        <result column="title" property="title"/>
        <result column="ip" property="ip"/>
        <result column="user_agent" property="userAgent"/>
        <result column="request_uri" property="requestUri"/>
        <result column="method" property="method"/>
        <result column="params" property="params"/>
        <result column="exception" property="exception"/>
        <result column="service_id" property="serviceId"/>
        <result column="time" property="time"/>
        <result column="creator" property="creator"/>
        <result column="create_date" property="createDate"/>
        <result column="modifier" property="modifier"/>
        <result column="modify_date" property="modifyDate"/>
        <result column="del_flag" property="delFlag"/>
        <result column="application_code" property="applicationCode"/>
        <result column="tenant_code" property="tenantCode"/>
    </resultMap>

    <sql id="logColumns">
        a.id,
        a.type,
        a.title,
        a.ip,
        a.user_agent,
        a.request_uri,
        a.method,
        a.params,
        a.exception,
        a.service_id,
        a.time,
        a.creator,
        a.create_date,
        a.modifier,
        a.modify_date,
        a.del_flag,
        a.application_code,
        a.tenant_code
    </sql>

    <select id="get" resultMap="logResultMap">
        SELECT
        <include refid="logColumns"/>
        FROM sys_log a
        WHERE a.id = #{id} and a.del_flag = 0
    </select>

    <select id="findList" resultMap="logResultMap">
        SELECT
        <include refid="logColumns"/>
        FROM sys_log a
        WHERE a.del_flag = 0 order by a.create_date desc
    </select>

    <insert id="insert">
        insert  into sys_log (
            id,
            type,
            title,
            ip,
            user_agent,
            request_uri,
            method,
            params,
            exception,
            service_id,
            time,
            creator,
            create_date,
            modifier,
            modify_date,
            del_flag,
            application_code,
            tenant_code
        ) values (
            #{id},
            #{type},
            #{title},
            #{ip},
            #{userAgent},
            #{requestUri},
            #{method},
            #{params},
            #{exception},
            #{serviceId},
            #{time},
            #{creator},
            #{createDate},
            #{modifier},
            #{modifyDate},
            #{delFlag},
            #{applicationCode},
            #{tenantCode}
        );
    </insert>

    <delete id="delete">
        DELETE FROM sys_log WHERE id = #{id}
    </delete>

    <delete id="deleteAll">
        DELETE FROM sys_log WHERE id in
        <foreach item="item" index="index" collection="array" open="("
                 separator="," close=")"> #{item}
        </foreach>
    </delete>
</mapper>
