定时任务xxl-job使用改造使用postgresql数据库

文章目录

参考

说明

mapper.xml语句修改

XxlJobLogMapper.xml

findFailJobLogIds(运算符替换)

原SQL

sql 复制代码
SELECT id FROM "xxl_job_log"
WHERE !(
	(trigger_code in (0, 200) and handle_code = 0)
	OR
	(handle_code = 200)
)
AND "alarm_status" = 0
ORDER BY id ASC
LIMIT #{pagesize}

修改

! 修改为 NOT

sql 复制代码
SELECT id FROM "xxl_job_log"
WHERE NOT (
	(trigger_code in (0, 200) and handle_code = 0)
	OR
	(handle_code = 200)
)
AND "alarm_status" = 0
ORDER BY id ASC
LIMIT #{pagesize}

pageList(分页)

原SQL

sql 复制代码
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}

修改

sql 复制代码
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 #{pagesize} offset #{offset}

findClearLogIds(分页)

原SQL

sql 复制代码
SELECT id FROM xxl_job_log
<trim prefix="WHERE" prefixOverrides="AND | OR" >
	<if test="jobGroup gt 0">
		AND job_group = #{jobGroup}
	</if>
	<if test="jobId gt 0">
		AND job_id = #{jobId}
	</if>
	<if test="clearBeforeTime != null">
		AND trigger_time <![CDATA[ <= ]]> #{clearBeforeTime}
	</if>
	<if test="clearBeforeNum gt 0">
		AND id NOT in(
		SELECT id FROM(
		SELECT id FROM xxl_job_log AS t
		<trim prefix="WHERE" prefixOverrides="AND | OR" >
			<if test="jobGroup gt 0">
				AND t.job_group = #{jobGroup}
			</if>
			<if test="jobId gt 0">
				AND t.job_id = #{jobId}
			</if>
		</trim>
		ORDER BY t.trigger_time desc
		LIMIT 0, #{clearBeforeNum}
		) t1
		)
	</if>
</trim>
order by id asc
LIMIT #{pagesize}

修改

sql 复制代码
SELECT id FROM xxl_job_log
<trim prefix="WHERE" prefixOverrides="AND | OR" >
	<if test="jobGroup gt 0">
		AND job_group = #{jobGroup}
	</if>
	<if test="jobId gt 0">
		AND job_id = #{jobId}
	</if>
	<if test="clearBeforeTime != null">
		AND trigger_time <![CDATA[ <= ]]> #{clearBeforeTime}
	</if>
	<if test="clearBeforeNum gt 0">
		AND id NOT in(
		SELECT id FROM(
		SELECT id FROM xxl_job_log AS t
		<trim prefix="WHERE" prefixOverrides="AND | OR" >
			<if test="jobGroup gt 0">
				AND t.job_group = #{jobGroup}
			</if>
			<if test="jobId gt 0">
				AND t.job_id = #{jobId}
			</if>
		</trim>
		ORDER BY t.trigger_time desc
		LIMIT #{clearBeforeNum}
		) t1
		)
	</if>
</trim>
order by id asc
LIMIT #{pagesize}

findLogReport(as大小写)

原SQL

sql 复制代码
SELECT
	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 handle_code = 200 then 1 else 0 end) as triggerDayCountSuc
FROM xxl_job_log
WHERE trigger_time BETWEEN #{from} and #{to}

修改

as 后面的别名是大小写格式,加双引号

sql 复制代码
SELECT
	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 handle_code = 200 then 1 else 0 end) as "triggerDayCountSuc"
FROM xxl_job_log
WHERE trigger_time BETWEEN #{from} and #{to}

XxlJobRegistryMapper.xml

findDead(时间)

原SQL

sql 复制代码
SELECT t.id
FROM xxl_job_registry AS t
WHERE t.update_time <![CDATA[ < ]]> DATE_ADD(#{nowTime},INTERVAL -#{timeout} SECOND)

修改

DATE_ADD 在postgresql中没有

sql 复制代码
SELECT t.id
FROM xxl_job_registry AS t
WHERE t.update_time <![CDATA[ < ]]> (now() - INTERVAL '${timeout} S')

findAll(时间)

原SQL

sql 复制代码
SELECT <include refid="Base_Column_List" />
FROM xxl_job_registry AS t
WHERE t.update_time <![CDATA[ > ]]> DATE_ADD(#{nowTime},INTERVAL -#{timeout} SECOND)

修改

DATE_ADD 在postgresql中没有

sql 复制代码
SELECT <include refid="Base_Column_List" />
FROM xxl_job_registry AS t
WHERE t.update_time <![CDATA[ > ]]> (now() - INTERVAL '${timeout} S')

XxlJobGroupMapper.xml

pageList(分页)

原SQL

sql 复制代码
SELECT <include refid="Base_Column_List" />
FROM xxl_job_group AS t
<trim prefix="WHERE" prefixOverrides="AND | OR" >
	<if test="appname != null and appname != ''">
		AND t.app_name like CONCAT(CONCAT('%', #{appname}), '%')
	</if>
	<if test="title != null and title != ''">
		AND t.title like CONCAT(CONCAT('%', #{title}), '%')
	</if>
</trim>
ORDER BY t.app_name, t.title, t.id ASC
LIMIT #{offset}, #{pagesize}

修改

sql 复制代码
SELECT <include refid="Base_Column_List" />
FROM xxl_job_group AS t
<trim prefix="WHERE" prefixOverrides="AND | OR" >
	<if test="appname != null and appname != ''">
		AND t.app_name like CONCAT(CONCAT('%', #{appname}), '%')
	</if>
	<if test="title != null and title != ''">
		AND t.title like CONCAT(CONCAT('%', #{title}), '%')
	</if>
</trim>
ORDER BY t.app_name, t.title, t.id ASC
LIMIT #{pagesize} offset #{offset}

XxlJobInfoMapper.xml

pageList(分页)

原SQL

sql 复制代码
SELECT <include refid="Base_Column_List" />
FROM xxl_job_info AS t
<trim prefix="WHERE" prefixOverrides="AND | OR" >
	<if test="jobGroup gt 0">
		AND t.job_group = #{jobGroup}
	</if>
	<if test="triggerStatus gte 0">
		AND t.trigger_status = #{triggerStatus}
	</if>
	<if test="jobDesc != null and jobDesc != ''">
		AND t.job_desc like CONCAT(CONCAT('%', #{jobDesc}), '%')
	</if>
	<if test="executorHandler != null and executorHandler != ''">
		AND t.executor_handler like CONCAT(CONCAT('%', #{executorHandler}), '%')
	</if>
	<if test="author != null and author != ''">
		AND t.author like CONCAT(CONCAT('%', #{author}), '%')
	</if>
</trim>
ORDER BY id DESC
LIMIT #{offset}, #{pagesize}

修改

sql 复制代码
SELECT <include refid="Base_Column_List" />
FROM xxl_job_info AS t
<trim prefix="WHERE" prefixOverrides="AND | OR" >
	<if test="jobGroup gt 0">
		AND t.job_group = #{jobGroup}
	</if>
	<if test="triggerStatus gte 0">
		AND t.trigger_status = #{triggerStatus}
	</if>
	<if test="jobDesc != null and jobDesc != ''">
		AND t.job_desc like CONCAT(CONCAT('%', #{jobDesc}), '%')
	</if>
	<if test="executorHandler != null and executorHandler != ''">
		AND t.executor_handler like CONCAT(CONCAT('%', #{executorHandler}), '%')
	</if>
	<if test="author != null and author != ''">
		AND t.author like CONCAT(CONCAT('%', #{author}), '%')
	</if>
</trim>
ORDER BY id DESC
LIMIT #{pagesize} offset #{offset}

scheduleJobQuery(分页)

原SQL

sql 复制代码
SELECT <include refid="Base_Column_List" />
FROM xxl_job_info AS t
WHERE t.trigger_status = 1
	and t.trigger_next_time <![CDATA[ <= ]]> #{maxNextTime}
ORDER BY id ASC
LIMIT #{pagesize}

修改

sql 复制代码
SELECT <include refid="Base_Column_List" />
FROM xxl_job_info AS t
WHERE t.trigger_status = 1
	and t.trigger_next_time <![CDATA[ <= ]]> #{maxNextTime}
ORDER BY id ASC
LIMIT #{pagesize} offset 0

XxlJobLogGlueMapper.xml

removeOld(分页)

原SQL

sql 复制代码
DELETE FROM xxl_job_logglue
WHERE id NOT in(
	SELECT id FROM(
		SELECT id FROM xxl_job_logglue
		WHERE "job_id" = #{jobId}
		ORDER BY update_time desc
		LIMIT 0, #{limit}
	) t1
) AND "job_id" = #{jobId}

修改

sql 复制代码
DELETE FROM xxl_job_logglue
WHERE id NOT in(
	SELECT id FROM(
		SELECT id FROM xxl_job_logglue
		WHERE "job_id" = #{jobId}
		ORDER BY update_time desc
		LIMIT #{limit}
	) t1
) AND "job_id" = #{jobId}

XxlJobUserMapper.xml

pageList(分页)

原SQL

sql 复制代码
SELECT <include refid="Base_Column_List" />
FROM xxl_job_user AS t
<trim prefix="WHERE" prefixOverrides="AND | OR" >
	<if test="username != null and username != ''">
		AND t.username like CONCAT(CONCAT('%', #{username}), '%')
	</if>
	<if test="role gt -1">
		AND t.role = #{role}
	</if>
</trim>
ORDER BY username ASC
LIMIT #{offset}, #{pagesize}

修改

sql 复制代码
SELECT <include refid="Base_Column_List" />
FROM xxl_job_user AS t
<trim prefix="WHERE" prefixOverrides="AND | OR" >
	<if test="username != null and username != ''">
		AND t.username like CONCAT(CONCAT('%', #{username}), '%')
	</if>
	<if test="role gt -1">
		AND t.role = #{role}
	</if>
</trim>
ORDER BY username ASC
LIMIT #{pagesize} offset #{offset}
相关推荐
虹科网络安全15 小时前
艾体宝干货|数据复制详解:类型、原理与适用场景
java·开发语言·数据库
2301_7717172116 小时前
解决mysql报错:1406, Data too long for column
android·数据库·mysql
HackTorjan16 小时前
深度神经网络的反向传播与梯度优化原理
人工智能·spring boot·神经网络·机器学习·dnn
小江的记录本16 小时前
【Kafka核心】架构模型:Producer、Broker、Consumer、Consumer Group、Topic、Partition、Replica
java·数据库·分布式·后端·搜索引擎·架构·kafka
dvjr cloi16 小时前
MySQL Workbench菜单汉化为中文
android·数据库·mysql
运维全栈笔记16 小时前
Linux安装配置Tomcat保姆级教程:从部署到性能调优
linux·服务器·中间件·tomcat·apache·web
dFObBIMmai17 小时前
MySQL主从同步中大事务导致的延迟_如何拆分大事务优化同步
jvm·数据库·python
szccyw017 小时前
mysql如何限制特定存储过程执行权限_MySQL存储过程安全访问
jvm·数据库·python
czlczl2002092517 小时前
利用“延迟关联”优化 MySQL 巨量数据的深分页查询
数据库·mysql
ACP广源盛1392462567318 小时前
IX8024与科学大模型的碰撞@ACP#筑牢科研 AI 算力高速枢纽分享
运维·服务器·网络·数据库·人工智能·嵌入式硬件·电脑