日志导出忽略分页

This commit is contained in:
XinWei 2024-07-12 14:11:57 +08:00
parent 09e269947d
commit f691164000

View File

@ -1,30 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xxl.job.admin.dao.XxlJobLogDao"> <mapper namespace="com.xxl.job.admin.dao.XxlJobLogDao">
<resultMap id="XxlJobLog" type="com.xxl.job.admin.core.model.XxlJobLog" >
<result column="id" property="id" />
<result column="job_group" property="jobGroup" /> <resultMap id="XxlJobLog" type="com.xxl.job.admin.core.model.XxlJobLog">
<result column="job_id" property="jobId" /> <result column="id" property="id"/>
<result column="executor_address" property="executorAddress" /> <result column="job_group" property="jobGroup"/>
<result column="executor_handler" property="executorHandler" /> <result column="job_id" property="jobId"/>
<result column="executor_param" property="executorParam" />
<result column="executor_sharding_param" property="executorShardingParam" />
<result column="executor_fail_retry_count" property="executorFailRetryCount" />
<result column="trigger_time" property="triggerTime" />
<result column="trigger_code" property="triggerCode" />
<result column="trigger_msg" property="triggerMsg" />
<result column="handle_time" property="handleTime" />
<result column="handle_code" property="handleCode" />
<result column="handle_msg" property="handleMsg" />
<result column="alarm_status" property="alarmStatus" /> <result column="executor_address" property="executorAddress"/>
</resultMap> <result column="executor_handler" property="executorHandler"/>
<result column="executor_param" property="executorParam"/>
<result column="executor_sharding_param" property="executorShardingParam"/>
<result column="executor_fail_retry_count" property="executorFailRetryCount"/>
<result column="trigger_time" property="triggerTime"/>
<result column="trigger_code" property="triggerCode"/>
<result column="trigger_msg" property="triggerMsg"/>
<result column="handle_time" property="handleTime"/>
<result column="handle_code" property="handleCode"/>
<result column="handle_msg" property="handleMsg"/>
<result column="alarm_status" property="alarmStatus"/>
</resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
t.id, t.id,
@ -42,210 +42,214 @@
t.handle_code, t.handle_code,
t.handle_msg, t.handle_msg,
t.alarm_status t.alarm_status
</sql> </sql>
<select id="pageList" resultMap="XxlJobLog">
SELECT <include refid="Base_Column_List" />
FROM xxl_job_log AS t
<trim prefix="WHERE" prefixOverrides="AND | OR" >
<if test="jobId==0 and jobGroup gt 0">
AND t.job_group = #{jobGroup}
</if>
<if test="jobId gt 0">
AND t.job_id = #{jobId}
</if>
<if test="triggerTimeStart != null">
AND t.trigger_time <![CDATA[ >= ]]> #{triggerTimeStart}
</if>
<if test="triggerTimeEnd != null">
AND t.trigger_time <![CDATA[ <= ]]> #{triggerTimeEnd}
</if>
<if test="logStatus == 1" >
AND t.handle_code = 200
</if>
<if test="logStatus == 2" >
AND (
t.trigger_code NOT IN (0, 200) OR
t.handle_code NOT IN (0, 200)
)
</if>
<if test="logStatus == 3" >
AND t.trigger_code = 200
AND t.handle_code = 0
</if>
</trim>
ORDER BY t.trigger_time DESC
LIMIT #{offset}, #{pagesize}
</select>
<resultMap id="ApiXxlJobLog" type="com.xxl.job.admin.api.log.dto.JobLogRespDTO"> <select id="pageList" resultMap="XxlJobLog">
<id column="id" property="id"/> SELECT
<result column="job_id" property="jobId"/> <include refid="Base_Column_List"/>
<result column="executor_handler" property="handlerName"/> FROM xxl_job_log AS t
<result column="executor_param" property="handlerParam"/> <trim prefix="WHERE" prefixOverrides="AND | OR">
<result column="index" property="executeIndex"/> <if test="jobId==0 and jobGroup gt 0">
<result column="trigger_time" property="beginTime"/> AND t.job_group = #{jobGroup}
<result column="handle_time" property="endTime"/> </if>
<result column="duration" property="duration"/> <if test="jobId gt 0">
<result column="status" property="status"/> AND t.job_id = #{jobId}
</resultMap> </if>
<select id="apiPageList" resultMap="ApiXxlJobLog"> <if test="triggerTimeStart != null">
SELECT <include refid="Base_Column_List" />, ROW_NUMBER() OVER (ORDER BY t.trigger_time) AS 'index', (t.handle_time -t.trigger_time) AS 'duration', AND t.trigger_time <![CDATA[ >= ]]> #{triggerTimeStart}
IF(t.handle_code = 200, 1, 2) AS 'status' </if>
FROM xxl_job_log AS t <if test="triggerTimeEnd != null">
<trim prefix="WHERE" prefixOverrides="AND | OR" > AND t.trigger_time <![CDATA[ <= ]]> #{triggerTimeEnd}
<if test="jobId==0 and jobGroup gt 0"> </if>
AND t.job_group = #{jobGroup} <if test="logStatus == 1">
</if> AND t.handle_code = 200
<if test="jobId gt 0"> </if>
AND t.job_id = #{jobId} <if test="logStatus == 2">
</if> AND (
<if test="triggerTimeStart != null"> t.trigger_code NOT IN (0, 200) OR
AND t.trigger_time <![CDATA[ >= ]]> #{triggerTimeStart} t.handle_code NOT IN (0, 200)
</if> )
<if test="triggerTimeEnd != null"> </if>
AND t.trigger_time <![CDATA[ <= ]]> #{triggerTimeEnd} <if test="logStatus == 3">
</if> AND t.trigger_code = 200
<if test="logStatus == 1" > AND t.handle_code = 0
AND t.handle_code = 200 </if>
</if> </trim>
<if test="logStatus == 2" > ORDER BY t.trigger_time DESC
AND ( LIMIT #{offset}, #{pagesize}
t.trigger_code NOT IN (0, 200) OR </select>
t.handle_code NOT IN (0, 200)
)
</if>
<if test="logStatus == 3" >
AND t.trigger_code = 200
AND t.handle_code = 0
</if>
<if test="handlerName != null">
AND t.handlerName LIKE CONCAT('%', #{handlerName}, '%')
</if>
</trim>
ORDER BY t.trigger_time DESC
LIMIT #{offset}, #{pagesize}
</select>
<select id="pageListCount" resultType="int">
SELECT count(1)
FROM xxl_job_log AS t
<trim prefix="WHERE" prefixOverrides="AND | OR" >
<if test="jobId==0 and jobGroup gt 0">
AND t.job_group = #{jobGroup}
</if>
<if test="jobId gt 0">
AND t.job_id = #{jobId}
</if>
<if test="triggerTimeStart != null">
AND t.trigger_time <![CDATA[ >= ]]> #{triggerTimeStart}
</if>
<if test="triggerTimeEnd != null">
AND t.trigger_time <![CDATA[ <= ]]> #{triggerTimeEnd}
</if>
<if test="logStatus == 1" >
AND t.handle_code = 200
</if>
<if test="logStatus == 2" >
AND (
t.trigger_code NOT IN (0, 200) OR
t.handle_code NOT IN (0, 200)
)
</if>
<if test="logStatus == 3" >
AND t.trigger_code = 200
AND t.handle_code = 0
</if>
</trim>
</select>
<select id="apiPageListCount" resultType="int">
SELECT count(1)
FROM xxl_job_log AS t
<trim prefix="WHERE" prefixOverrides="AND | OR" >
<if test="jobId==0 and jobGroup gt 0">
AND t.job_group = #{jobGroup}
</if>
<if test="jobId gt 0">
AND t.job_id = #{jobId}
</if>
<if test="triggerTimeStart != null">
AND t.trigger_time <![CDATA[ >= ]]> #{triggerTimeStart}
</if>
<if test="triggerTimeEnd != null">
AND t.trigger_time <![CDATA[ <= ]]> #{triggerTimeEnd}
</if>
<if test="logStatus == 1" >
AND t.handle_code = 200
</if>
<if test="logStatus == 2" >
AND (
t.trigger_code NOT IN (0, 200) OR
t.handle_code NOT IN (0, 200)
)
</if>
<if test="logStatus == 3" >
AND t.trigger_code = 200
AND t.handle_code = 0
</if>
<if test="handlerName != null">
AND t.executor_handler LIKE CONCAT('%', #{handlerName}, '%')
</if>
</trim>
</select>
<select id="load" parameterType="java.lang.Long" resultMap="XxlJobLog">
SELECT <include refid="Base_Column_List" />
FROM xxl_job_log AS t
WHERE t.id = #{id}
</select>
<resultMap id="ApiXxlJobLog" type="com.xxl.job.admin.api.log.dto.JobLogRespDTO">
<insert id="save" parameterType="com.xxl.job.admin.core.model.XxlJobLog" useGeneratedKeys="true" keyProperty="id" > <id column="id" property="id"/>
INSERT INTO xxl_job_log ( <result column="job_id" property="jobId"/>
`job_group`, <result column="executor_handler" property="handlerName"/>
`job_id`, <result column="executor_param" property="handlerParam"/>
`trigger_time`, <result column="index" property="executeIndex"/>
`trigger_code`, <result column="trigger_time" property="beginTime"/>
`handle_code` <result column="handle_time" property="endTime"/>
) VALUES ( <result column="duration" property="duration"/>
#{jobGroup}, <result column="status" property="status"/>
#{jobId}, </resultMap>
#{triggerTime}, <select id="apiPageList" resultMap="ApiXxlJobLog">
#{triggerCode}, SELECT<include refid="Base_Column_List"/>, ROW_NUMBER() OVER (ORDER BY t.trigger_time) AS 'index',
#{handleCode} (t.handle_time -t.trigger_time) AS 'duration',
); IF(t.handle_code = 200, 1, 2) AS 'status'
<!--<selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id"> FROM xxl_job_log AS t
SELECT LAST_INSERT_ID() <trim prefix="WHERE" prefixOverrides="AND | OR">
</selectKey>--> <if test="jobId==0 and jobGroup gt 0">
</insert> AND t.job_group = #{jobGroup}
</if>
<if test="jobId gt 0">
AND t.job_id = #{jobId}
</if>
<if test="triggerTimeStart != null">
AND t.trigger_time <![CDATA[ >= ]]> #{triggerTimeStart}
</if>
<if test="triggerTimeEnd != null">
AND t.trigger_time <![CDATA[ <= ]]> #{triggerTimeEnd}
</if>
<if test="logStatus == 1">
AND t.handle_code = 200
</if>
<if test="logStatus == 2">
AND (
t.trigger_code NOT IN (0, 200) OR
t.handle_code NOT IN (0, 200)
)
</if>
<if test="logStatus == 3">
AND t.trigger_code = 200
AND t.handle_code = 0
</if>
<if test="handlerName != null">
AND t.handlerName LIKE CONCAT('%', #{handlerName}, '%')
</if>
</trim>
ORDER BY t.trigger_time DESC
<if test="pagesize > 0">
LIMIT #{offset}, #{pagesize}
</if>
</select>
<update id="updateTriggerInfo" > <select id="pageListCount" resultType="int">
UPDATE xxl_job_log SELECT count(1)
SET FROM xxl_job_log AS t
`trigger_time`= #{triggerTime}, <trim prefix="WHERE" prefixOverrides="AND | OR">
`trigger_code`= #{triggerCode}, <if test="jobId==0 and jobGroup gt 0">
`trigger_msg`= #{triggerMsg}, AND t.job_group = #{jobGroup}
`executor_address`= #{executorAddress}, </if>
`executor_handler`=#{executorHandler}, <if test="jobId gt 0">
`executor_param`= #{executorParam}, AND t.job_id = #{jobId}
`executor_sharding_param`= #{executorShardingParam}, </if>
`executor_fail_retry_count`= #{executorFailRetryCount} <if test="triggerTimeStart != null">
WHERE `id`= #{id} AND t.trigger_time <![CDATA[ >= ]]> #{triggerTimeStart}
</update> </if>
<if test="triggerTimeEnd != null">
AND t.trigger_time <![CDATA[ <= ]]> #{triggerTimeEnd}
</if>
<if test="logStatus == 1">
AND t.handle_code = 200
</if>
<if test="logStatus == 2">
AND (
t.trigger_code NOT IN (0, 200) OR
t.handle_code NOT IN (0, 200)
)
</if>
<if test="logStatus == 3">
AND t.trigger_code = 200
AND t.handle_code = 0
</if>
</trim>
</select>
<select id="apiPageListCount" resultType="int">
SELECT count(1)
FROM xxl_job_log AS t
<trim prefix="WHERE" prefixOverrides="AND | OR">
<if test="jobId==0 and jobGroup gt 0">
AND t.job_group = #{jobGroup}
</if>
<if test="jobId gt 0">
AND t.job_id = #{jobId}
</if>
<if test="triggerTimeStart != null">
AND t.trigger_time <![CDATA[ >= ]]> #{triggerTimeStart}
</if>
<if test="triggerTimeEnd != null">
AND t.trigger_time <![CDATA[ <= ]]> #{triggerTimeEnd}
</if>
<if test="logStatus == 1">
AND t.handle_code = 200
</if>
<if test="logStatus == 2">
AND (
t.trigger_code NOT IN (0, 200) OR
t.handle_code NOT IN (0, 200)
)
</if>
<if test="logStatus == 3">
AND t.trigger_code = 200
AND t.handle_code = 0
</if>
<if test="handlerName != null">
AND t.executor_handler LIKE CONCAT('%', #{handlerName}, '%')
</if>
</trim>
</select>
<update id="updateHandleInfo"> <select id="load" parameterType="java.lang.Long" resultMap="XxlJobLog">
UPDATE xxl_job_log SELECT
SET <include refid="Base_Column_List"/>
`handle_time`= #{handleTime}, FROM xxl_job_log AS t
`handle_code`= #{handleCode}, WHERE t.id = #{id}
`handle_msg`= #{handleMsg} </select>
WHERE `id`= #{id}
</update>
<insert id="save" parameterType="com.xxl.job.admin.core.model.XxlJobLog" useGeneratedKeys="true" keyProperty="id">
<delete id="delete" > INSERT INTO xxl_job_log (
delete from xxl_job_log `job_group`,
WHERE job_id = #{jobId} `job_id`,
</delete> `trigger_time`,
`trigger_code`,
`handle_code`
) VALUES (
#{jobGroup},
#{jobId},
#{triggerTime},
#{triggerCode},
#{handleCode}
);
<!--<selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id">
SELECT LAST_INSERT_ID()
</selectKey>-->
</insert>
<update id="updateTriggerInfo">
UPDATE xxl_job_log
SET `trigger_time`= #{triggerTime},
`trigger_code`= #{triggerCode},
`trigger_msg`= #{triggerMsg},
`executor_address`= #{executorAddress},
`executor_handler`=#{executorHandler},
`executor_param`= #{executorParam},
`executor_sharding_param`= #{executorShardingParam},
`executor_fail_retry_count`= #{executorFailRetryCount}
WHERE `id` = #{id}
</update>
<update id="updateHandleInfo">
UPDATE xxl_job_log
SET `handle_time`= #{handleTime},
`handle_code`= #{handleCode},
`handle_msg`= #{handleMsg}
WHERE `id` = #{id}
</update>
<delete id="delete">
delete
from xxl_job_log
WHERE job_id = #{jobId}
</delete>
<!--<select id="triggerCountByDay" resultType="java.util.Map" > <!--<select id="triggerCountByDay" resultType="java.util.Map" >
SELECT SELECT
@ -259,98 +263,97 @@
ORDER BY triggerDay ORDER BY triggerDay
</select>--> </select>-->
<select id="findLogReport" resultType="java.util.Map" > <select id="findLogReport" resultType="java.util.Map">
SELECT SELECT COUNT(handle_code) triggerDayCount,
COUNT(handle_code) triggerDayCount, SUM(CASE WHEN (trigger_code in (0, 200) and handle_code = 0) then 1 else 0 end) as triggerDayCountRunning,
SUM(CASE WHEN (trigger_code in (0, 200) and handle_code = 0) then 1 else 0 end) as triggerDayCountRunning, SUM(CASE WHEN handle_code = 200 then 1 else 0 end) as triggerDayCountSuc
SUM(CASE WHEN handle_code = 200 then 1 else 0 end) as triggerDayCountSuc FROM xxl_job_log
FROM xxl_job_log WHERE trigger_time BETWEEN #{from} and #{to}
WHERE trigger_time BETWEEN #{from} and #{to}
</select> </select>
<select id="findClearLogIds" resultType="long" > <select id="findClearLogIds" resultType="long">
SELECT id FROM xxl_job_log SELECT id FROM xxl_job_log
<trim prefix="WHERE" prefixOverrides="AND | OR" > <trim prefix="WHERE" prefixOverrides="AND | OR">
<if test="jobGroup gt 0"> <if test="jobGroup gt 0">
AND job_group = #{jobGroup} AND job_group = #{jobGroup}
</if> </if>
<if test="jobId gt 0"> <if test="jobId gt 0">
AND job_id = #{jobId} AND job_id = #{jobId}
</if> </if>
<if test="clearBeforeTime != null"> <if test="clearBeforeTime != null">
AND trigger_time <![CDATA[ <= ]]> #{clearBeforeTime} AND trigger_time <![CDATA[ <= ]]> #{clearBeforeTime}
</if> </if>
<if test="clearBeforeNum gt 0"> <if test="clearBeforeNum gt 0">
AND id NOT in( AND id NOT in(
SELECT id FROM( SELECT id FROM(
SELECT id FROM xxl_job_log AS t SELECT id FROM xxl_job_log AS t
<trim prefix="WHERE" prefixOverrides="AND | OR" > <trim prefix="WHERE" prefixOverrides="AND | OR">
<if test="jobGroup gt 0"> <if test="jobGroup gt 0">
AND t.job_group = #{jobGroup} AND t.job_group = #{jobGroup}
</if> </if>
<if test="jobId gt 0"> <if test="jobId gt 0">
AND t.job_id = #{jobId} AND t.job_id = #{jobId}
</if> </if>
</trim> </trim>
ORDER BY t.trigger_time desc ORDER BY t.trigger_time desc
LIMIT 0, #{clearBeforeNum} LIMIT 0, #{clearBeforeNum}
) t1 ) t1
) )
</if> </if>
</trim> </trim>
order by id asc order by id asc
LIMIT #{pagesize} LIMIT #{pagesize}
</select> </select>
<delete id="clearLog" > <delete id="clearLog">
delete from xxl_job_log delete from xxl_job_log
WHERE id in WHERE id in
<foreach collection="logIds" item="item" open="(" close=")" separator="," > <foreach collection="logIds" item="item" open="(" close=")" separator=",">
#{item} #{item}
</foreach> </foreach>
</delete> </delete>
<select id="findFailJobLogIds" resultType="long" > <select id="findFailJobLogIds" resultType="long">
SELECT id FROM `xxl_job_log` SELECT id
WHERE !( FROM `xxl_job_log`
(trigger_code in (0, 200) and handle_code = 0) WHERE !(
OR (trigger_code in (0
(handle_code = 200) , 200)
) and handle_code = 0)
AND `alarm_status` = 0 OR
ORDER BY id ASC (handle_code = 200)
LIMIT #{pagesize} )
</select> AND `alarm_status` = 0
ORDER BY id ASC
LIMIT #{pagesize}
</select>
<update id="updateAlarmStatus" > <update id="updateAlarmStatus">
UPDATE xxl_job_log UPDATE xxl_job_log
SET SET `alarm_status` = #{newAlarmStatus}
`alarm_status` = #{newAlarmStatus} WHERE `id` = #{logId}
WHERE `id`= #{logId} AND `alarm_status` = #{oldAlarmStatus} AND `alarm_status` = #{oldAlarmStatus}
</update> </update>
<select id="findLostJobIds" resultType="long" > <select id="findLostJobIds" resultType="long">
SELECT SELECT t.id
t.id FROM xxl_job_log t
FROM LEFT JOIN xxl_job_registry t2 ON t.executor_address = t2.registry_value
xxl_job_log t WHERE t.trigger_code = 200
LEFT JOIN xxl_job_registry t2 ON t.executor_address = t2.registry_value AND t.handle_code = 0
WHERE AND t.trigger_time <![CDATA[ <= ]]> #{losedTime}
t.trigger_code = 200 AND t2.id IS NULL;
AND t.handle_code = 0 </select>
AND t.trigger_time <![CDATA[ <= ]]> #{losedTime} <!--
AND t2.id IS NULL; SELECT t.id
</select> FROM xxl_job_log AS t
<!-- WHERE t.trigger_code = 200
SELECT t.id and t.handle_code = 0
FROM xxl_job_log AS t and t.trigger_time <![CDATA[ <= ]]> #{losedTime}
WHERE t.trigger_code = 200 and t.executor_address not in (
and t.handle_code = 0 SELECT t2.registry_value
and t.trigger_time <![CDATA[ <= ]]> #{losedTime} FROM xxl_job_registry AS t2
and t.executor_address not in ( )
SELECT t2.registry_value -->
FROM xxl_job_registry AS t2
)
-->
</mapper> </mapper>