houzhongjian
2024-11-07 a874b928e16320839315b9abcdf2cece1229a424
提交 | 用户 | 时间
e7c126 1 <?xml version="1.0" encoding="UTF-8"?>
H 2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
3     "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
4 <mapper namespace="com.xxl.job.admin.dao.XxlJobLogDao">
5     
6     <resultMap id="XxlJobLog" type="com.xxl.job.admin.core.model.XxlJobLog" >
7         <result column="id" property="id" />
8
9         <result column="job_group" property="jobGroup" />
10         <result column="job_id" property="jobId" />
11
12         <result column="executor_address" property="executorAddress" />
13         <result column="executor_handler" property="executorHandler" />
14         <result column="executor_param" property="executorParam" />
15         <result column="executor_sharding_param" property="executorShardingParam" />
16         <result column="executor_fail_retry_count" property="executorFailRetryCount" />
17         
18         <result column="trigger_time" property="triggerTime" />
19         <result column="trigger_code" property="triggerCode" />
20         <result column="trigger_msg" property="triggerMsg" />
21         
22         <result column="handle_time" property="handleTime" />
23         <result column="handle_code" property="handleCode" />
24         <result column="handle_msg" property="handleMsg" />
25
26         <result column="alarm_status" property="alarmStatus" />
27     </resultMap>
28
29     <sql id="Base_Column_List">
30         t.id,
31         t.job_group,
32         t.job_id,
33         t.executor_address,
34         t.executor_handler,
35         t.executor_param,
36         t.executor_sharding_param,
37         t.executor_fail_retry_count,
38         t.trigger_time,
39         t.trigger_code,
40         t.trigger_msg,
41         t.handle_time,
42         t.handle_code,
43         t.handle_msg,
44         t.alarm_status
45     </sql>
46     
47     <select id="pageList" resultMap="XxlJobLog">
48         SELECT <include refid="Base_Column_List" />
49         FROM xxl_job_log AS t
50         <trim prefix="WHERE" prefixOverrides="AND | OR" >
51             <if test="jobId==0 and jobGroup gt 0">
52                 AND t.job_group = #{jobGroup}
53             </if>
54             <if test="jobId gt 0">
55                 AND t.job_id = #{jobId}
56             </if>
57             <if test="triggerTimeStart != null">
58                 AND t.trigger_time <![CDATA[ >= ]]> #{triggerTimeStart}
59             </if>
60             <if test="triggerTimeEnd != null">
61                 AND t.trigger_time <![CDATA[ <= ]]> #{triggerTimeEnd}
62             </if>
63             <if test="logStatus == 1" >
64                 AND t.handle_code = 200
65             </if>
66             <if test="logStatus == 2" >
67                 AND (
68                     t.trigger_code NOT IN (0, 200) OR
69                     t.handle_code NOT IN (0, 200)
70                 )
71             </if>
72             <if test="logStatus == 3" >
73                 AND t.trigger_code = 200
74                 AND t.handle_code = 0
75             </if>
76         </trim>
77         ORDER BY t.trigger_time DESC
78         LIMIT #{offset}, #{pagesize}
79     </select>
80     
81     <select id="pageListCount" resultType="int">
82         SELECT count(1)
83         FROM xxl_job_log AS t
84         <trim prefix="WHERE" prefixOverrides="AND | OR" >
85             <if test="jobId==0 and jobGroup gt 0">
86                 AND t.job_group = #{jobGroup}
87             </if>
88             <if test="jobId gt 0">
89                 AND t.job_id = #{jobId}
90             </if>
91             <if test="triggerTimeStart != null">
92                 AND t.trigger_time <![CDATA[ >= ]]> #{triggerTimeStart}
93             </if>
94             <if test="triggerTimeEnd != null">
95                 AND t.trigger_time <![CDATA[ <= ]]> #{triggerTimeEnd}
96             </if>
97             <if test="logStatus == 1" >
98                 AND t.handle_code = 200
99             </if>
100             <if test="logStatus == 2" >
101                 AND (
102                     t.trigger_code NOT IN (0, 200) OR
103                     t.handle_code NOT IN (0, 200)
104                 )
105             </if>
106             <if test="logStatus == 3" >
107                 AND t.trigger_code = 200
108                 AND t.handle_code = 0
109             </if>
110         </trim>
111     </select>
112     
113     <select id="load" parameterType="java.lang.Long" resultMap="XxlJobLog">
114         SELECT <include refid="Base_Column_List" />
115         FROM xxl_job_log AS t
116         WHERE t.id = #{id}
117     </select>
118
119     
120     <insert id="save" parameterType="com.xxl.job.admin.core.model.XxlJobLog" useGeneratedKeys="true" keyProperty="id" >
121         INSERT INTO xxl_job_log (
122             `job_group`,
123             `job_id`,
124             `trigger_time`,
125             `trigger_code`,
126             `handle_code`
127         ) VALUES (
128             #{jobGroup},
129             #{jobId},
130             #{triggerTime},
131             #{triggerCode},
132             #{handleCode}
133         );
134         <!--<selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id">
135             SELECT LAST_INSERT_ID() 
136         </selectKey>-->
137     </insert>
138
139     <update id="updateTriggerInfo" >
140         UPDATE xxl_job_log
141         SET
142             `trigger_time`= #{triggerTime},
143             `trigger_code`= #{triggerCode},
144             `trigger_msg`= #{triggerMsg},
145             `executor_address`= #{executorAddress},
146             `executor_handler`=#{executorHandler},
147             `executor_param`= #{executorParam},
148             `executor_sharding_param`= #{executorShardingParam},
149             `executor_fail_retry_count`= #{executorFailRetryCount}
150         WHERE `id`= #{id}
151     </update>
152
153     <update id="updateHandleInfo">
154         UPDATE xxl_job_log
155         SET 
156             `handle_time`= #{handleTime}, 
157             `handle_code`= #{handleCode},
158             `handle_msg`= #{handleMsg}
159         WHERE `id`= #{id}
160     </update>
161     
162     <delete id="delete" >
163         delete from xxl_job_log
164         WHERE job_id = #{jobId}
165     </delete>
166
167     <!--<select id="triggerCountByDay" resultType="java.util.Map" >
168         SELECT
169             DATE_FORMAT(trigger_time,'%Y-%m-%d') triggerDay,
170             COUNT(handle_code) triggerDayCount,
171             SUM(CASE WHEN (trigger_code in (0, 200) and handle_code = 0) then 1 else 0 end) as triggerDayCountRunning,
172             SUM(CASE WHEN handle_code = 200 then 1 else 0 end) as triggerDayCountSuc
173         FROM xxl_job_log
174         WHERE trigger_time BETWEEN #{from} and #{to}
175         GROUP BY triggerDay
176         ORDER BY triggerDay
177     </select>-->
178
179     <select id="findLogReport" resultType="java.util.Map" >
180         SELECT
181             COUNT(handle_code) triggerDayCount,
182             SUM(CASE WHEN (trigger_code in (0, 200) and handle_code = 0) then 1 else 0 end) as triggerDayCountRunning,
183             SUM(CASE WHEN handle_code = 200 then 1 else 0 end) as triggerDayCountSuc
184         FROM xxl_job_log
185         WHERE trigger_time BETWEEN #{from} and #{to}
186     </select>
187
188     <select id="findClearLogIds" resultType="long" >
189         SELECT id FROM xxl_job_log
190         <trim prefix="WHERE" prefixOverrides="AND | OR" >
191             <if test="jobGroup gt 0">
192                 AND job_group = #{jobGroup}
193             </if>
194             <if test="jobId gt 0">
195                 AND job_id = #{jobId}
196             </if>
197             <if test="clearBeforeTime != null">
198                 AND trigger_time <![CDATA[ <= ]]> #{clearBeforeTime}
199             </if>
200             <if test="clearBeforeNum gt 0">
201                 AND id NOT in(
202                 SELECT id FROM(
203                 SELECT id FROM xxl_job_log AS t
204                 <trim prefix="WHERE" prefixOverrides="AND | OR" >
205                     <if test="jobGroup gt 0">
206                         AND t.job_group = #{jobGroup}
207                     </if>
208                     <if test="jobId gt 0">
209                         AND t.job_id = #{jobId}
210                     </if>
211                 </trim>
212                 ORDER BY t.trigger_time desc
213                 LIMIT 0, #{clearBeforeNum}
214                 ) t1
215                 )
216             </if>
217         </trim>
218         order by id asc
219         LIMIT #{pagesize}
220     </select>
221
222     <delete id="clearLog" >
223         delete from xxl_job_log
224         WHERE id in
225         <foreach collection="logIds" item="item" open="(" close=")" separator="," >
226             #{item}
227         </foreach>
228     </delete>
229
230     <select id="findFailJobLogIds" resultType="long" >
231         SELECT id FROM `xxl_job_log`
232         WHERE !(
233             (trigger_code in (0, 200) and handle_code = 0)
234             OR
235             (handle_code = 200)
236         )
237         AND `alarm_status` = 0
238         ORDER BY id ASC
239         LIMIT #{pagesize}
240     </select>
241
242     <update id="updateAlarmStatus" >
243         UPDATE xxl_job_log
244         SET
245             `alarm_status` = #{newAlarmStatus}
246         WHERE `id`= #{logId} AND `alarm_status` = #{oldAlarmStatus}
247     </update>
248
249     <select id="findLostJobIds" resultType="long" >
250         SELECT
251             t.id
252         FROM
253             xxl_job_log t
254             LEFT JOIN xxl_job_registry t2 ON t.executor_address = t2.registry_value
255         WHERE
256             t.trigger_code = 200
257                 AND t.handle_code = 0
258                 AND t.trigger_time <![CDATA[ <= ]]> #{losedTime}
259                 AND t2.id IS NULL;
260     </select>
261     <!--
262     SELECT t.id
263     FROM xxl_job_log AS t
264     WHERE t.trigger_code = 200
265         and t.handle_code = 0
266         and t.trigger_time <![CDATA[ <= ]]> #{losedTime}
267         and t.executor_address not in (
268             SELECT t2.registry_value
269             FROM xxl_job_registry AS t2
270         )
271     -->
272
273 </mapper>