RuoYi-Cloud/xjs-business/xjs-business-log/src/main/resources/mapper/log/ApiLogMapper.xml

87 lines
4.7 KiB
XML

<?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">
select id, api_name, url, method, is_success , create_time from api_log
<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">
select request, response from api_log
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>
<select id="selectApiLogListByOptimization" resultType="com.xjs.apilog.domain.ApiLog">
SELECT
id,api_name,url,method,is_success,create_time
FROM
api_log a
JOIN ( SELECT id bid FROM api_log
<where>
<if test="apiLog.apiName != null and apiLog.apiName != ''"> and api_name like concat('%', #{apiLog.apiName}, '%')</if>
<if test="apiLog.url != null and apiLog.url != ''"> and url like concat('%', #{apiLog.url}, '%')</if>
<if test="apiLog.method != null and apiLog.method != ''"> and method like concat('%', #{apiLog.method}, '%')</if>
<if test="apiLog.request != null and apiLog.request != ''"> and request like concat('%', #{apiLog.request}, '%')</if>
<if test="apiLog.response != null and apiLog.response != ''"> and response like concat('%', #{apiLog.response}, '%')</if>
<if test="apiLog.isSuccess != null "> and is_success = #{apiLog.isSuccess}</if>
<if test="apiLog.createTime != null and apiLog.endCreateTime != null"> and create_time between #{apiLog.createTime} and #{apiLog.endCreateTime}</if>
</where>
ORDER BY id desc LIMIT #{pageNum}, #{pageSize} ) b ON a.id = b.bid
</select>
<select id="countByCondition" resultType="java.lang.Long">
SELECT COUNT( * )
FROM api_log
<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>
</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>