<?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.xjs.apilog.mapper.ApiLogMapper">

    <resultMap type="com.xjs.apilog.domain.ApiLog" id="ApiLogResult">
        <result property="id"    column="id"    />
        <result property="apiName"    column="api_name"    />
        <result property="url"    column="url"    />
        <result property="method"    column="method"    />
        <result property="request"    column="request"    />
        <result property="response"    column="response"    />
        <result property="isSuccess"    column="is_success"    />
    </resultMap>

    <sql id="selectApiLogVo">
        select id, api_name, url, method, request, response, is_success , create_time from api_log
    </sql>

    <select id="selectApiLogList" parameterType="com.xjs.apilog.domain.ApiLog" resultMap="ApiLogResult">
        <include refid="selectApiLogVo"/>
        <where>
            <if test="apiName != null  and apiName != ''"> and api_name like concat('%', #{apiName}, '%')</if>
            <if test="url != null  and url != ''"> and url like concat('%', #{url}, '%')</if>
            <if test="method != null  and method != ''"> and method like concat('%', #{method}, '%')</if>
            <if test="request != null  and request != ''"> and request like concat('%', #{request}, '%')</if>
            <if test="response != null  and response != ''"> and response like concat('%', #{response}, '%')</if>
            <if test="isSuccess != null "> and is_success = #{isSuccess}</if>
            <if test="createTime != null and endCreateTime != null"> and create_time between #{createTime} and #{endCreateTime}</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectApiLogById" parameterType="Long" resultMap="ApiLogResult">
        <include refid="selectApiLogVo"/>
        where id = #{id}
    </select>
    <select id="statisticsByDate" resultType="com.xjs.apilog.vo.ApiLogVo">
        select api_name ,count(api_name) count FROM
            (select api_name from api_log where
            create_time BETWEEN #{startDate} and #{endDate}) t
        GROUP BY api_name
    </select>

    <delete id="deleteApiLogById" parameterType="Long">
        delete from api_log where id = #{id}
    </delete>

    <delete id="deleteApiLogByIds" parameterType="Long">
        delete from api_log where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
