项目说明
项目本身开发中采用定时框架:xxl-job是一个分布式任务调度平台,它是依托于MySQL数据库执行。但后续客户要求必须满足信创环境,因此调整MySQL数据库为达梦数据库。由此就有了xxl-job适配达梦数据库的一系列操作。
Xxl-job表结构导入
方法一:达梦迁移工具
1.打开达梦迁移工具新建工程
2.新建迁移,如下图:
3.选择迁移方式
4.输入MySQL的信息
5. 输入dm的信息
6.选择迁移选项默认即可。
7.指定模式
8.指定对象:全选然后下一步
8.审阅迁移任务之后,点击完成
9.完成迁移向导
10.验证是否迁移达梦数据库成功
从上图可知,表结构已经导入成功。
解决刚刚那个xxl_job_group数据问题,重新导入一条示例数据。查看xxl_job_group:如下图:表中无数据。
插入一条示例数据,手动添加即可(根据xxl_job表的示例)。
方法二:手动导入
- 创建表空间(XXLJOB)
- 创建用户并设置密码(XXLJOB)
- 给XXLJOB用户授权
- 创建xxl-job的表结构
- 添加示例数据,注意提交(commit)
注意:此方法也可以使用达梦管理工具,只不过在创建xxl-job表结构时候切换创建的用户XXLJOB进行创建。
参考如下表中sql所示:
--创建表空间
CREATE TABLESPACE "XXLJOB" DATAFILE 'XXLJOB.DBF' SIZE 300 autoextend on maxsize 67108863 CACHE = NORMAL;
--创建用户
CREATE USER "XXLJOB" IDENTIFIED BY "XXLJOB!123" LIMIT PASSWORD_LOCK_TIME 1, PASSWORD_GRACE_TIME 10 DEFAULT TABLESPACE "XXLJOB";
--给用户授权
GRANT "RESOURCE","PUBLIC","DBA","VTI" TO "XXLJOB";
# 创建xxl-job的表结构
CREATE TABLE "XXLJOB"."XXL_JOB_GROUP"
(
"ID" INT IDENTITY(2, 1) NOT NULL,
"APP_NAME" VARCHAR(64) NOT NULL,
"TITLE" VARCHAR(12) NOT NULL,
"ADDRESS_TYPE" INT DEFAULT 0 NOT NULL,
"ADDRESS_LIST" TEXT,
"UPDATE_TIME" TIMESTAMP(0),
NOT CLUSTER PRIMARY KEY("ID")) STORAGE(ON "XXLJOB", CLUSTERBTR) ;
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_GROUP"."ADDRESS_LIST" IS '执行器地址列表,多地址逗号分隔';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_GROUP"."ADDRESS_TYPE" IS '执行器地址类型:0=自动注册、1=手动录入';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_GROUP"."APP_NAME" IS '执行器AppName';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_GROUP"."TITLE" IS '执行器名称';
CREATE TABLE "XXLJOB"."XXL_JOB_INFO"
(
"ID" INT IDENTITY(2, 1) NOT NULL,
"JOB_GROUP" INT NOT NULL,
"JOB_DESC" VARCHAR(255) NOT NULL,
"ADD_TIME" TIMESTAMP(0),
"UPDATE_TIME" TIMESTAMP(0),
"AUTHOR" VARCHAR(64),
"ALARM_EMAIL" VARCHAR(255),
"SCHEDULE_TYPE" VARCHAR(50) DEFAULT 'NONE' NOT NULL,
"SCHEDULE_CONF" VARCHAR(128),
"MISFIRE_STRATEGY" VARCHAR(50) DEFAULT 'DO_NOTHING' NOT NULL,
"EXECUTOR_ROUTE_STRATEGY" VARCHAR(50),
"EXECUTOR_HANDLER" VARCHAR(255),
"EXECUTOR_PARAM" VARCHAR(512),
"EXECUTOR_BLOCK_STRATEGY" VARCHAR(50),
"EXECUTOR_TIMEOUT" INT DEFAULT 0 NOT NULL,
"EXECUTOR_FAIL_RETRY_COUNT" INT DEFAULT 0 NOT NULL,
"GLUE_TYPE" VARCHAR(50) NOT NULL,
"GLUE_SOURCE" CLOB,
"GLUE_REMARK" VARCHAR(128),
"GLUE_UPDATETIME" TIMESTAMP(0),
"CHILD_JOBID" VARCHAR(255),
"TRIGGER_STATUS" INT DEFAULT 0 NOT NULL,
"TRIGGER_LAST_TIME" BIGINT DEFAULT 0 NOT NULL,
"TRIGGER_NEXT_TIME" BIGINT DEFAULT 0 NOT NULL,
NOT CLUSTER PRIMARY KEY("ID")) STORAGE(ON "XXLJOB", CLUSTERBTR) ;
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_INFO"."ALARM_EMAIL" IS '报警邮件';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_INFO"."AUTHOR" IS '作者';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_INFO"."CHILD_JOBID" IS '子任务ID,多个逗号分隔';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_INFO"."EXECUTOR_BLOCK_STRATEGY" IS '阻塞处理策略';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_INFO"."EXECUTOR_FAIL_RETRY_COUNT" IS '失败重试次数';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_INFO"."EXECUTOR_HANDLER" IS '执行器任务handler';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_INFO"."EXECUTOR_PARAM" IS '执行器任务参数';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_INFO"."EXECUTOR_ROUTE_STRATEGY" IS '执行器路由策略';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_INFO"."EXECUTOR_TIMEOUT" IS '任务执行超时时间,单位秒';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_INFO"."GLUE_REMARK" IS 'GLUE备注';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_INFO"."GLUE_SOURCE" IS 'GLUE源代码';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_INFO"."GLUE_TYPE" IS 'GLUE类型';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_INFO"."GLUE_UPDATETIME" IS 'GLUE更新时间';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_INFO"."JOB_GROUP" IS '执行器主键ID';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_INFO"."MISFIRE_STRATEGY" IS '调度过期策略';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_INFO"."SCHEDULE_CONF" IS '调度配置,值含义取决于调度类型';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_INFO"."SCHEDULE_TYPE" IS '调度类型';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_INFO"."TRIGGER_LAST_TIME" IS '上次调度时间';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_INFO"."TRIGGER_NEXT_TIME" IS '下次调度时间';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_INFO"."TRIGGER_STATUS" IS '调度状态:0-停止,1-运行';
CREATE TABLE "XXLJOB"."XXL_JOB_LOCK"
(
"LOCK_NAME" VARCHAR(50) NOT NULL,
NOT CLUSTER PRIMARY KEY("LOCK_NAME")) STORAGE(ON "XXLJOB", CLUSTERBTR) ;
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_LOCK"."LOCK_NAME" IS '锁名称';
CREATE TABLE "XXLJOB"."XXL_JOB_LOG"
(
"ID" BIGINT IDENTITY(1, 1) NOT NULL,
"JOB_GROUP" INT NOT NULL,
"JOB_ID" INT NOT NULL,
"EXECUTOR_ADDRESS" VARCHAR(255),
"EXECUTOR_HANDLER" VARCHAR(255),
"EXECUTOR_PARAM" VARCHAR(512),
"EXECUTOR_SHARDING_PARAM" VARCHAR(20),
"EXECUTOR_FAIL_RETRY_COUNT" INT DEFAULT 0 NOT NULL,
"TRIGGER_TIME" TIMESTAMP(0),
"TRIGGER_CODE" INT NOT NULL,
"TRIGGER_MSG" TEXT,
"HANDLE_TIME" TIMESTAMP(0),
"HANDLE_CODE" INT NOT NULL,
"HANDLE_MSG" TEXT,
"ALARM_STATUS" TINYINT DEFAULT 0 NOT NULL,
NOT CLUSTER PRIMARY KEY("ID")) STORAGE(ON "XXLJOB", CLUSTERBTR) ;
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_LOG"."ALARM_STATUS" IS '告警状态:0-默认、1-无需告警、2-告警成功、3-告警失败';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_LOG"."EXECUTOR_ADDRESS" IS '执行器地址,本次执行的地址';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_LOG"."EXECUTOR_FAIL_RETRY_COUNT" IS '失败重试次数';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_LOG"."EXECUTOR_HANDLER" IS '执行器任务handler';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_LOG"."EXECUTOR_PARAM" IS '执行器任务参数';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_LOG"."EXECUTOR_SHARDING_PARAM" IS '执行器任务分片参数,格式如 1/2';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_LOG"."HANDLE_CODE" IS '执行-状态';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_LOG"."HANDLE_MSG" IS '执行-日志';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_LOG"."HANDLE_TIME" IS '执行-时间';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_LOG"."JOB_GROUP" IS '执行器主键ID';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_LOG"."JOB_ID" IS '任务,主键ID';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_LOG"."TRIGGER_CODE" IS '调度-结果';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_LOG"."TRIGGER_MSG" IS '调度-日志';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_LOG"."TRIGGER_TIME" IS '调度-时间';
CREATE INDEX "I_TRIGGER_TIME" ON "XXLJOB"."XXL_JOB_LOG"("TRIGGER_TIME" ASC) STORAGE(ON "XXLJOB", CLUSTERBTR) ;
CREATE INDEX "I_HANDLE_CODE" ON "XXLJOB"."XXL_JOB_LOG"("HANDLE_CODE" ASC) STORAGE(ON "XXLJOB", CLUSTERBTR) ;
CREATE TABLE "XXLJOB"."XXL_JOB_LOGGLUE"
(
"ID" INT IDENTITY(1, 1) NOT NULL,
"JOB_ID" INT NOT NULL,
"GLUE_TYPE" VARCHAR(50),
"GLUE_SOURCE" CLOB,
"GLUE_REMARK" VARCHAR(128) NOT NULL,
"ADD_TIME" TIMESTAMP(0),
"UPDATE_TIME" TIMESTAMP(0),
NOT CLUSTER PRIMARY KEY("ID")) STORAGE(ON "XXLJOB", CLUSTERBTR) ;
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_LOGGLUE"."GLUE_REMARK" IS 'GLUE备注';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_LOGGLUE"."GLUE_SOURCE" IS 'GLUE源代码';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_LOGGLUE"."GLUE_TYPE" IS 'GLUE类型';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_LOGGLUE"."JOB_ID" IS '任务,主键ID';
CREATE TABLE "XXLJOB"."XXL_JOB_LOG_REPORT"
(
"ID" INT IDENTITY(1, 1) NOT NULL,
"TRIGGER_DAY" TIMESTAMP(0),
"RUNNING_COUNT" INT DEFAULT 0 NOT NULL,
"SUC_COUNT" INT DEFAULT 0 NOT NULL,
"FAIL_COUNT" INT DEFAULT 0 NOT NULL,
"UPDATE_TIME" TIMESTAMP(0),
NOT CLUSTER PRIMARY KEY("ID"),
CONSTRAINT "I_TRIGGER_DAY" UNIQUE("TRIGGER_DAY")) STORAGE(ON "XXLJOB", CLUSTERBTR) ;
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_LOG_REPORT"."FAIL_COUNT" IS '执行失败-日志数量';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_LOG_REPORT"."RUNNING_COUNT" IS '运行中-日志数量';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_LOG_REPORT"."SUC_COUNT" IS '执行成功-日志数量';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_LOG_REPORT"."TRIGGER_DAY" IS '调度-时间';
CREATE TABLE "XXLJOB"."XXL_JOB_REGISTRY"
(
"ID" INT IDENTITY(1, 1) NOT NULL,
"REGISTRY_GROUP" VARCHAR(50) NOT NULL,
"REGISTRY_KEY" VARCHAR(255) NOT NULL,
"REGISTRY_VALUE" VARCHAR(255) NOT NULL,
"UPDATE_TIME" TIMESTAMP(0),
NOT CLUSTER PRIMARY KEY("ID")) STORAGE(ON "XXLJOB", CLUSTERBTR) ;
CREATE INDEX "I_G_K_V" ON "XXLJOB"."XXL_JOB_REGISTRY"("REGISTRY_GROUP" ASC,"REGISTRY_KEY" ASC,"REGISTRY_VALUE" ASC) STORAGE(ON "XXLJOB", CLUSTERBTR) ;
CREATE TABLE "XXLJOB"."XXL_JOB_USER"
(
"ID" INT IDENTITY(2, 1) NOT NULL,
"USERNAME" VARCHAR(50) NOT NULL,
"PASSWORD" VARCHAR(50) NOT NULL,
"ROLE" TINYINT NOT NULL,
"PERMISSION" VARCHAR(255),
NOT CLUSTER PRIMARY KEY("ID"),
CONSTRAINT "I_USERNAME" UNIQUE("USERNAME")) STORAGE(ON "XXLJOB", CLUSTERBTR) ;
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_USER"."PASSWORD" IS '密码';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_USER"."PERMISSION" IS '权限:执行器ID列表,多个逗号分割';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_USER"."ROLE" IS '角色:0-普通用户、1-管理员';
COMMENT ON COLUMN "XXLJOB"."XXL_JOB_USER"."USERNAME" IS '账号';
#添加示例数据
INSERT INTO "xxl_job_group"( "app_name", "title", "address_type", "address_list", "update_time") VALUES ( 'xxl-job-executor-sample', '示例执行器', 0, NULL, '2018-11-03 22:21:31' );
INSERT INTO "xxl_job_info"("job_group", "job_desc", "add_time", "update_time", "author", "alarm_email", "schedule_type", "schedule_conf", "misfire_strategy", "executor_route_strategy", "executor_handler", "executor_param", "executor_block_strategy", "executor_timeout", "executor_fail_retry_count", "glue_type", "glue_source", "glue_remark", "glue_updatetime", "child_jobid") VALUES ( 1, '测试任务1', '2018-11-03 22:21:31', '2018-11-03 22:21:31', 'XXL', '', 'CRON', '0 0 0 * * ? *', 'DO_NOTHING', 'FIRST', 'demoJobHandler', '', 'SERIAL_EXECUTION', 0, 0, 'BEAN', '', 'GLUE代码初始化', '2018-11-03 22:21:31', '');
INSERT INTO "xxl_job_user"("username", "password", "role", "permission") VALUES ('admin', 'e10adc3949ba59abbe56e057f20f883e', 1, NULL);
INSERT INTO "xxl_job_lock" ( "lock_name") VALUES ( 'schedule_lock');
Xxl-job-admin源码变更
1.更改pom.xml文件
将MySQL的依赖注释掉添加dm依赖,一个是xxl-job的pom,另一个是xxl-job-admin的pom两处地方。
#xxl-job
<dm-connector-java.version>8.1.1.49</dm-connector-java.version>
# xx-job-admin
<dependency>
<groupId>com.dameng</groupId>
<artifactId>Dm8JdbcDriver18</artifactId>
<version>${dm-connector-java.version}</version>
</dependency>
2.修改xxl-job-admin的application.properties
### dm8
spring.datasource.url=jdbc:dm://xxx.xx.xx/XXL_JOB?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8
spring.datasource.username=账号
spring.datasource.password=密码
spring.datasource.driver-class-name=dm.jdbc.driver.DmDriver
3.修改JobScheduleHelper类代码
修改路径:com/xxl/job/admin/core/thread/JobScheduleHelper.java
第73行。
修改为如下:
preparedStatement = conn.prepareStatement( "select * from \"XXLJOB\".\"XXL_JOB_LOCK\" where lock_name = 'schedule_lock' for update" );
4.替换所有的mybatis-mapper中的内容
注意:替换时可以直接根据自己在达梦中创建的表和库名称直接在下面maaper.xml中替换即可。作者在此用的达梦库是XXL_JOB。
(1)XxlJobGroupMapper.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.xxl.job.admin.dao.XxlJobGroupDao">
<resultMap id="XxlJobGroup" type="com.xxl.job.admin.core.model.XxlJobGroup" >
<result column="id" property="id" />
<result column="app_name" property="appname" />
<result column="title" property="title" />
<result column="address_type" property="addressType" />
<result column="address_list" property="addressList" />
<result column="update_time" property="updateTime" />
</resultMap>
<sql id="Base_Column_List">
t.id,
t.app_name,
t.title,
t.address_type,
t.address_list,
t.update_time
</sql>
<select id="findAll" resultMap="XxlJobGroup">
SELECT <include refid="Base_Column_List" />
FROM "XXL_JOB"."XXL_JOB_GROUP" AS t
ORDER BY t.app_name, t.title, t.id ASC
</select>
<select id="findByAddressType" parameterType="java.lang.Integer" resultMap="XxlJobGroup">
SELECT <include refid="Base_Column_List" />
FROM "XXL_JOB"."XXL_JOB_GROUP" AS t
WHERE t.address_type = #{addressType}
ORDER BY t.app_name, t.title, t.id ASC
</select>
<insert id="save" parameterType="com.xxl.job.admin.core.model.XxlJobGroup" useGeneratedKeys="true" keyProperty="id" >
INSERT INTO "XXL_JOB"."XXL_JOB_GROUP" ( app_name, title, address_type, address_list, update_time)
values ( #{appname}, #{title}, #{addressType}, #{addressList}, #{updateTime} );
</insert>
<update id="update" parameterType="com.xxl.job.admin.core.model.XxlJobGroup" >
UPDATE "XXL_JOB"."XXL_JOB_GROUP"
SET app_name = #{appname},
title = #{title},
address_type = #{addressType},
address_list = #{addressList},
update_time = #{updateTime}
WHERE id = #{id}
</update>
<delete id="remove" parameterType="java.lang.Integer" >
DELETE FROM "XXL_JOB"."XXL_JOB_GROUP"
WHERE id = #{id}
</delete>
<select id="load" parameterType="java.lang.Integer" resultMap="XxlJobGroup">
SELECT <include refid="Base_Column_List" />
FROM "XXL_JOB"."XXL_JOB_GROUP" AS t
WHERE t.id = #{id}
</select>
<select id="pageList" parameterType="java.util.HashMap" resultMap="XxlJobGroup">
SELECT <include refid="Base_Column_List" />
FROM "XXL_JOB"."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}
</select>
<select id="pageListCount" parameterType="java.util.HashMap" resultType="int">
SELECT count(1)
FROM "XXL_JOB"."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>
</select>
</mapper>
(2)XxlJobInfoMapper.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.xxl.job.admin.dao.XxlJobInfoDao">
<resultMap id="XxlJobInfo" type="com.xxl.job.admin.core.model.XxlJobInfo" >
<result column="id" property="id" />
<result column="job_group" property="jobGroup" />
<result column="job_desc" property="jobDesc" />
<result column="add_time" property="addTime" />
<result column="update_time" property="updateTime" />
<result column="author" property="author" />
<result column="alarm_email" property="alarmEmail" />
<result column="schedule_type" property="scheduleType" />
<result column="schedule_conf" property="scheduleConf" />
<result column="misfire_strategy" property="misfireStrategy" />
<result column="executor_route_strategy" property="executorRouteStrategy" />
<result column="executor_handler" property="executorHandler" />
<result column="executor_param" property="executorParam" />
<result column="executor_block_strategy" property="executorBlockStrategy" />
<result column="executor_timeout" property="executorTimeout" />
<result column="executor_fail_retry_count" property="executorFailRetryCount" />
<result column="glue_type" property="glueType" />
<result column="glue_source" property="glueSource" />
<result column="glue_remark" property="glueRemark" />
<result column="glue_updatetime" property="glueUpdatetime" />
<result column="child_jobid" property="childJobId" />
<result column="trigger_status" property="triggerStatus" />
<result column="trigger_last_time" property="triggerLastTime" />
<result column="trigger_next_time" property="triggerNextTime" />
</resultMap>
<sql id="Base_Column_List">
t.id,
t.job_group,
t.job_desc,
t.add_time,
t.update_time,
t.author,
t.alarm_email,
t.schedule_type,
t.schedule_conf,
t.misfire_strategy,
t.executor_route_strategy,
t.executor_handler,
t.executor_param,
t.executor_block_strategy,
t.executor_timeout,
t.executor_fail_retry_count,
t.glue_type,
t.glue_source,
t.glue_remark,
t.glue_updatetime,
t.child_jobid,
t.trigger_status,
t.trigger_last_time,
t.trigger_next_time
</sql>
<select id="pageList" parameterType="java.util.HashMap" resultMap="XxlJobInfo">
SELECT <include refid="Base_Column_List" />
FROM "XXL_JOB"."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}
</select>
<select id="pageListCount" parameterType="java.util.HashMap" resultType="int">
SELECT count(1)
FROM "XXL_JOB"."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>
</select>
<insert id="save" parameterType="com.xxl.job.admin.core.model.XxlJobInfo" useGeneratedKeys="true" keyProperty="id" >
INSERT INTO "XXL_JOB"."XXL_JOB_INFO" (
job_group,
job_desc,
add_time,
update_time,
author,
alarm_email,
schedule_type,
schedule_conf,
misfire_strategy,
executor_route_strategy,
executor_handler,
executor_param,
executor_block_strategy,
executor_timeout,
executor_fail_retry_count,
glue_type,
glue_source,
glue_remark,
glue_updatetime,
child_jobid,
trigger_status,
trigger_last_time,
trigger_next_time
) VALUES (
#{jobGroup},
#{jobDesc},
#{addTime},
#{updateTime},
#{author},
#{alarmEmail},
#{scheduleType},
#{scheduleConf},
#{misfireStrategy},
#{executorRouteStrategy},
#{executorHandler},
#{executorParam},
#{executorBlockStrategy},
#{executorTimeout},
#{executorFailRetryCount},
#{glueType},
#{glueSource},
#{glueRemark},
#{glueUpdatetime},
#{childJobId},
#{triggerStatus},
#{triggerLastTime},
#{triggerNextTime}
);
<!--<selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id">
SELECT LAST_INSERT_ID()
/*SELECT @@IDENTITY AS id*/
</selectKey>-->
</insert>
<select id="loadById" parameterType="java.util.HashMap" resultMap="XxlJobInfo">
SELECT <include refid="Base_Column_List" />
FROM "XXL_JOB"."XXL_JOB_INFO" AS t
WHERE t.id = #{id}
</select>
<update id="update" parameterType="com.xxl.job.admin.core.model.XxlJobInfo" >
UPDATE "XXL_JOB"."XXL_JOB_INFO"
SET
job_group = #{jobGroup},
job_desc = #{jobDesc},
update_time = #{updateTime},
author = #{author},
alarm_email = #{alarmEmail},
schedule_type = #{scheduleType},
schedule_conf = #{scheduleConf},
misfire_strategy = #{misfireStrategy},
executor_route_strategy = #{executorRouteStrategy},
executor_handler = #{executorHandler},
executor_param = #{executorParam},
executor_block_strategy = #{executorBlockStrategy},
executor_timeout = ${executorTimeout},
executor_fail_retry_count = ${executorFailRetryCount},
glue_type = #{glueType},
glue_source = #{glueSource},
glue_remark = #{glueRemark},
glue_updatetime = #{glueUpdatetime},
child_jobid = #{childJobId},
trigger_status = #{triggerStatus},
trigger_last_time = #{triggerLastTime},
trigger_next_time = #{triggerNextTime}
WHERE id = #{id}
</update>
<delete id="delete" parameterType="java.util.HashMap">
DELETE
FROM "XXL_JOB"."XXL_JOB_INFO"
WHERE id = #{id}
</delete>
<select id="getJobsByGroup" parameterType="java.util.HashMap" resultMap="XxlJobInfo">
SELECT <include refid="Base_Column_List" />
FROM "XXL_JOB"."XXL_JOB_INFO" AS t
WHERE t.job_group = #{jobGroup}
</select>
<select id="findAllCount" resultType="int">
SELECT count(1)
FROM "XXL_JOB"."XXL_JOB_INFO"
</select>
<select id="scheduleJobQuery" parameterType="java.util.HashMap" resultMap="XxlJobInfo">
SELECT <include refid="Base_Column_List" />
FROM "XXL_JOB"."XXL_JOB_INFO" AS t
WHERE t.trigger_status = 1
and t.trigger_next_time <![CDATA[ <= ]]> #{maxNextTime}
ORDER BY id ASC
LIMIT #{pagesize}
</select>
<update id="scheduleUpdate" parameterType="com.xxl.job.admin.core.model.XxlJobInfo" >
UPDATE "XXL_JOB"."XXL_JOB_INFO"
SET
trigger_last_time = #{triggerLastTime},
trigger_next_time = #{triggerNextTime},
trigger_status = #{triggerStatus}
WHERE id = #{id}
</update>
</mapper>
(3)XxlJobLogGlueMapper.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.xxl.job.admin.dao.XxlJobLogGlueDao">
<resultMap id="XxlJobLogGlue" type="com.xxl.job.admin.core.model.XxlJobLogGlue" >
<result column="id" property="id" />
<result column="job_id" property="jobId" />
<result column="glue_type" property="glueType" />
<result column="glue_source" property="glueSource" />
<result column="glue_remark" property="glueRemark" />
<result column="add_time" property="addTime" />
<result column="update_time" property="updateTime" />
</resultMap>
<sql id="Base_Column_List">
t.id,
t.job_id,
t.glue_type,
t.glue_source,
t.glue_remark,
t.add_time,
t.update_time
</sql>
<insert id="save" parameterType="com.xxl.job.admin.core.model.XxlJobLogGlue" useGeneratedKeys="true" keyProperty="id" >
INSERT INTO "XXL_JOB"."XXL_JOB_LOGGLUE" (
job_id,
glue_type,
glue_source,
glue_remark,
add_time,
update_time
) VALUES (
#{jobId},
#{glueType},
#{glueSource},
#{glueRemark},
#{addTime},
#{updateTime}
);
<!--<selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id">
SELECT LAST_INSERT_ID()
</selectKey>-->
</insert>
<select id="findByJobId" parameterType="java.lang.Integer" resultMap="XxlJobLogGlue">
SELECT <include refid="Base_Column_List" />
FROM "XXL_JOB"."XXL_JOB_LOGGLUE" AS t
WHERE t.job_id = #{jobId}
ORDER BY id DESC
</select>
<delete id="removeOld" >
DELETE FROM "XXL_JOB"."XXL_JOB_LOGGLUE"
WHERE id NOT in(
SELECT id FROM(
SELECT id FROM "XXL_JOB"."XXL_JOB_LOGGLUE"
WHERE job_id = #{jobId}
ORDER BY update_time desc
LIMIT 0, #{limit}
) t1
) AND job_id = #{jobId}
</delete>
<delete id="deleteByJobId" parameterType="java.lang.Integer" >
DELETE FROM "XXL_JOB"."XXL_JOB_LOGGLUE"
WHERE job_id = #{jobId}
</delete>
</mapper>
(4)XxlJobLogMapper.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.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" />
<result column="job_id" property="jobId" />
<result column="executor_address" property="executorAddress" />
<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">
t.id,
t.job_group,
t.job_id,
t.executor_address,
t.executor_handler,
t.executor_param,
t.executor_sharding_param,
t.executor_fail_retry_count,
t.trigger_time,
t.trigger_code,
t.trigger_msg,
t.handle_time,
t.handle_code,
t.handle_msg,
t.alarm_status
</sql>
<select id="pageList" resultMap="XxlJobLog">
SELECT <include refid="Base_Column_List" />
FROM "XXL_JOB"."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>
<select id="pageListCount" resultType="int">
SELECT count(1)
FROM "XXL_JOB"."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="load" parameterType="java.lang.Long" resultMap="XxlJobLog">
SELECT <include refid="Base_Column_List" />
FROM "XXL_JOB"."XXL_JOB_LOG" AS t
WHERE t.id = #{id}
</select>
<insert id="save" parameterType="com.xxl.job.admin.core.model.XxlJobLog" useGeneratedKeys="true" keyProperty="id" >
INSERT INTO "XXL_JOB"."XXL_JOB_LOG" (
job_group,
job_id,
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"."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"."XXL_JOB_LOG"
SET
handle_time= #{handleTime},
handle_code= #{handleCode},
handle_msg= #{handleMsg}
WHERE `id`= #{id}
</update>
<delete id="delete" >
delete from "XXL_JOB"."XXL_JOB_LOG"
WHERE job_id = #{jobId}
</delete>
<!--<select id="triggerCountByDay" resultType="java.util.Map" >
SELECT
DATE_FORMAT(trigger_time,'%Y-%m-%d') triggerDay,
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}
GROUP BY triggerDay
ORDER BY triggerDay
</select>-->
<select id="findLogReport" resultType="java.util.Map" >
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"."XXL_JOB_LOG"
WHERE trigger_time BETWEEN #{from} and #{to}
</select>
<select id="findClearLogIds" resultType="long" >
SELECT id FROM "XXL_JOB"."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"."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}
</select>
<delete id="clearLog" >
delete from "XXL_JOB"."XXL_JOB_LOG"
WHERE id in
<foreach collection="logIds" item="item" open="(" close=")" separator="," >
#{item}
</foreach>
</delete>
<select id="findFailJobLogIds" resultType="long" >
SELECT id FROM "XXL_JOB"."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}
</select>
<update id="updateAlarmStatus" >
UPDATE "XXL_JOB"."XXL_JOB_LOG"
SET
alarm_status = #{newAlarmStatus}
WHERE id= #{logId} AND alarm_status = #{oldAlarmStatus}
</update>
<select id="findLostJobIds" resultType="long" >
SELECT t.id
FROM "XXL_JOB"."XXL_JOB_LOG" AS t
WHERE t.trigger_code = 200
and t.handle_code = 0
and t.trigger_time <![CDATA[ <= ]]> #{losedTime}
and t.executor_address not in (
SELECT t2.registry_value
FROM "XXL_JOB"."XXL_JOB_REGISTRY" AS t2
)
</select>
</mapper>
(5)XxlJobLogReportMapper.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.xxl.job.admin.dao.XxlJobLogReportDao">
<resultMap id="XxlJobLogReport" type="com.xxl.job.admin.core.model.XxlJobLogReport" >
<result column="id" property="id" />
<result column="trigger_day" property="triggerDay" />
<result column="running_count" property="runningCount" />
<result column="suc_count" property="sucCount" />
<result column="fail_count" property="failCount" />
</resultMap>
<sql id="Base_Column_List">
t.id,
t.trigger_day,
t.running_count,
t.suc_count,
t.fail_count
</sql>
<insert id="save" parameterType="com.xxl.job.admin.core.model.XxlJobLogReport" useGeneratedKeys="true" keyProperty="id" >
INSERT INTO "XXL_JOB"."XXL_JOB_LOG_REPORT" (
trigger_day,
running_count,
suc_count,
fail_count
) VALUES (
#{triggerDay},
#{runningCount},
#{sucCount},
#{failCount}
);
<!--<selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id">
SELECT LAST_INSERT_ID()
</selectKey>-->
</insert>
<update id="update" >
UPDATE "XXL_JOB"."XXL_JOB_LOG_REPORT"
SET running_count = #{runningCount},
suc_count = #{sucCount},
fail_count = #{failCount}
WHERE trigger_day = #{triggerDay}
</update>
<select id="queryLogReport" resultMap="XxlJobLogReport">
SELECT <include refid="Base_Column_List" />
FROM "XXL_JOB"."XXL_JOB_LOG_REPORT" AS t
WHERE t.trigger_day between #{triggerDayFrom} and #{triggerDayTo}
ORDER BY t.trigger_day ASC
</select>
<select id="queryLogReportTotal" resultMap="XxlJobLogReport">
SELECT
SUM(running_count) running_count,
SUM(suc_count) suc_count,
SUM(fail_count) fail_count
FROM "XXL_JOB"."XXL_JOB_LOG_REPORT" AS t
</select>
</mapper>
(6) XxlJobRegistryMapper.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.xxl.job.admin.dao.XxlJobRegistryDao">
<resultMap id="XxlJobRegistry" type="com.xxl.job.admin.core.model.XxlJobRegistry" >
<result column="id" property="id" />
<result column="registry_group" property="registryGroup" />
<result column="registry_key" property="registryKey" />
<result column="registry_value" property="registryValue" />
<result column="update_time" property="updateTime" />
</resultMap>
<sql id="Base_Column_List">
t.id,
t.registry_group,
t.registry_key,
t.registry_value,
t.update_time
</sql>
<select id="findDead" parameterType="java.util.HashMap" resultType="java.lang.Integer" >
SELECT t.id
FROM "XXL_JOB"."XXL_JOB_REGISTRY" AS t
WHERE t.update_time <![CDATA[ < ]]> DATEADD(SECOND, -#{timeout}, #{nowTime})
</select>
<delete id="removeDead" parameterType="java.lang.Integer" >
DELETE FROM "XXL_JOB"."XXL_JOB_REGISTRY"
WHERE id in
<foreach collection="ids" item="item" open="(" close=")" separator="," >
#{item}
</foreach>
</delete>
<select id="findAll" parameterType="java.util.HashMap" resultMap="XxlJobRegistry">
SELECT <include refid="Base_Column_List" />
FROM "XXL_JOB"."XXL_JOB_REGISTRY" AS t
WHERE t.update_time <![CDATA[ > ]]> DATEADD(SECOND,-#{timeout},#{nowTime})
</select>
<update id="registryUpdate" >
UPDATE "XXL_JOB"."XXL_JOB_REGISTRY"
SET update_time = #{updateTime}
WHERE registry_group = #{registryGroup}
AND registry_key = #{registryKey}
AND registry_value = #{registryValue}
</update>
<insert id="registrySave" >
INSERT INTO "XXL_JOB"."XXL_JOB_REGISTRY"( registry_group , registry_key , registry_value, update_time)
VALUES( #{registryGroup} , #{registryKey} , #{registryValue}, #{updateTime})
</insert>
<delete id="registryDelete" >
DELETE FROM "XXL_JOB"."XXL_JOB_REGISTRY"
WHERE registry_group = #{registryGroup}
AND registry_key = #{registryKey}
AND registry_value = #{registryValue}
</delete>
</mapper>
(7)XxlJobUserMapper.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.xxl.job.admin.dao.XxlJobUserDao">
<resultMap id="XxlJobUser" type="com.xxl.job.admin.core.model.XxlJobUser" >
<result column="id" property="id" />
<result column="username" property="username" />
<result column="password" property="password" />
<result column="role" property="role" />
<result column="permission" property="permission" />
</resultMap>
<sql id="Base_Column_List">
t.id,
t.username,
t.password,
t.role,
t.permission
</sql>
<select id="pageList" parameterType="java.util.HashMap" resultMap="XxlJobUser">
SELECT <include refid="Base_Column_List" />
FROM "XXL_JOB"."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}
</select>
<select id="pageListCount" parameterType="java.util.HashMap" resultType="int">
SELECT count(1)
FROM "XXL_JOB"."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>
</select>
<select id="loadByUserName" parameterType="java.util.HashMap" resultMap="XxlJobUser">
SELECT <include refid="Base_Column_List" />
FROM "XXL_JOB"."XXL_JOB_USER" AS t
WHERE t.username = #{username}
</select>
<insert id="save" parameterType="com.xxl.job.admin.core.model.XxlJobUser" useGeneratedKeys="true" keyProperty="id" >
INSERT INTO "XXL_JOB"."XXL_JOB_USER" (
username,
password,
role,
permission
) VALUES (
#{username},
#{password},
#{role},
#{permission}
);
</insert>
<update id="update" parameterType="com.xxl.job.admin.core.model.XxlJobUser" >
UPDATE "XXL_JOB"."XXL_JOB_USER"
SET
<if test="password != null and password != ''">
password = #{password},
</if>
role = #{role},
permission = #{permission}
WHERE id = #{id}
</update>
<delete id="delete" parameterType="java.util.HashMap">
DELETE
FROM "XXL_JOB"."XXL_JOB_USER"
WHERE id = #{id}
</delete>
</mapper>
xxl-job-admin启动及验证
本地测试启动xxl-job-admin
启动成功,访问地址:ip+端口
新增一个执行器,在达梦数据库中查看是否成功。