189 lines
8.1 KiB
XML
189 lines
8.1 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="org.xyzh.crontab.mapper.CrontabTaskMapper">
|
||
|
|
|
||
|
|
<!-- 结果映射 -->
|
||
|
|
<resultMap id="BaseResultMap" type="org.xyzh.common.dto.crontab.TbCrontabTask">
|
||
|
|
<id column="id" property="ID" />
|
||
|
|
<result column="task_id" property="taskId" />
|
||
|
|
<result column="task_name" property="taskName" />
|
||
|
|
<result column="task_group" property="taskGroup" />
|
||
|
|
<result column="bean_name" property="beanName" />
|
||
|
|
<result column="method_name" property="methodName" />
|
||
|
|
<result column="method_params" property="methodParams" />
|
||
|
|
<result column="cron_expression" property="cronExpression" />
|
||
|
|
<result column="status" property="status" />
|
||
|
|
<result column="description" property="description" />
|
||
|
|
<result column="concurrent" property="concurrent" />
|
||
|
|
<result column="misfire_policy" property="misfirePolicy" />
|
||
|
|
<result column="creator" property="creator" />
|
||
|
|
<result column="updater" property="updater" />
|
||
|
|
<result column="create_time" property="createTime" />
|
||
|
|
<result column="update_time" property="updateTime" />
|
||
|
|
<result column="delete_time" property="deleteTime" />
|
||
|
|
<result column="deleted" property="deleted" />
|
||
|
|
</resultMap>
|
||
|
|
|
||
|
|
<!-- 字段列表 -->
|
||
|
|
<sql id="Base_Column_List">
|
||
|
|
id, task_id, task_name, task_group, bean_name, method_name, method_params,
|
||
|
|
cron_expression, status, description, concurrent, misfire_policy,
|
||
|
|
creator, updater, create_time, update_time, delete_time, deleted
|
||
|
|
</sql>
|
||
|
|
|
||
|
|
<!-- 查询条件 -->
|
||
|
|
<sql id="Base_Where_Clause">
|
||
|
|
<where>
|
||
|
|
<if test="filter != null">
|
||
|
|
<if test="filter.ID != null and filter.ID != ''">
|
||
|
|
AND id = #{filter.ID}
|
||
|
|
</if>
|
||
|
|
<if test="filter.taskId != null and filter.taskId != ''">
|
||
|
|
AND task_id = #{filter.taskId}
|
||
|
|
</if>
|
||
|
|
<if test="filter.taskName != null and filter.taskName != ''">
|
||
|
|
AND task_name LIKE CONCAT('%', #{filter.taskName}, '%')
|
||
|
|
</if>
|
||
|
|
<if test="filter.taskGroup != null and filter.taskGroup != ''">
|
||
|
|
AND task_group = #{filter.taskGroup}
|
||
|
|
</if>
|
||
|
|
<if test="filter.beanName != null and filter.beanName != ''">
|
||
|
|
AND bean_name = #{filter.beanName}
|
||
|
|
</if>
|
||
|
|
<if test="filter.methodName != null and filter.methodName != ''">
|
||
|
|
AND method_name = #{filter.methodName}
|
||
|
|
</if>
|
||
|
|
<if test="filter.status != null">
|
||
|
|
AND status = #{filter.status}
|
||
|
|
</if>
|
||
|
|
<if test="filter.deleted != null">
|
||
|
|
AND deleted = #{filter.deleted}
|
||
|
|
</if>
|
||
|
|
</if>
|
||
|
|
</where>
|
||
|
|
</sql>
|
||
|
|
|
||
|
|
<!-- 插入任务 -->
|
||
|
|
<insert id="insertTask">
|
||
|
|
INSERT INTO tb_crontab_task
|
||
|
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||
|
|
<if test="task.ID != null">id,</if>
|
||
|
|
<if test="task.taskId != null">task_id,</if>
|
||
|
|
<if test="task.taskName != null">task_name,</if>
|
||
|
|
<if test="task.taskGroup != null">task_group,</if>
|
||
|
|
<if test="task.beanName != null">bean_name,</if>
|
||
|
|
<if test="task.methodName != null">method_name,</if>
|
||
|
|
<if test="task.methodParams != null">method_params,</if>
|
||
|
|
<if test="task.cronExpression != null">cron_expression,</if>
|
||
|
|
<if test="task.status != null">status,</if>
|
||
|
|
<if test="task.description != null">description,</if>
|
||
|
|
<if test="task.concurrent != null">concurrent,</if>
|
||
|
|
<if test="task.misfirePolicy != null">misfire_policy,</if>
|
||
|
|
<if test="task.creator != null">creator,</if>
|
||
|
|
<if test="task.createTime != null">create_time,</if>
|
||
|
|
deleted
|
||
|
|
</trim>
|
||
|
|
VALUES
|
||
|
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||
|
|
<if test="task.ID != null">#{task.ID},</if>
|
||
|
|
<if test="task.taskId != null">#{task.taskId},</if>
|
||
|
|
<if test="task.taskName != null">#{task.taskName},</if>
|
||
|
|
<if test="task.taskGroup != null">#{task.taskGroup},</if>
|
||
|
|
<if test="task.beanName != null">#{task.beanName},</if>
|
||
|
|
<if test="task.methodName != null">#{task.methodName},</if>
|
||
|
|
<if test="task.methodParams != null">#{task.methodParams},</if>
|
||
|
|
<if test="task.cronExpression != null">#{task.cronExpression},</if>
|
||
|
|
<if test="task.status != null">#{task.status},</if>
|
||
|
|
<if test="task.description != null">#{task.description},</if>
|
||
|
|
<if test="task.concurrent != null">#{task.concurrent},</if>
|
||
|
|
<if test="task.misfirePolicy != null">#{task.misfirePolicy},</if>
|
||
|
|
<if test="task.creator != null">#{task.creator},</if>
|
||
|
|
<if test="task.createTime != null">#{task.createTime},</if>
|
||
|
|
0
|
||
|
|
</trim>
|
||
|
|
</insert>
|
||
|
|
|
||
|
|
<!-- 更新任务 -->
|
||
|
|
<update id="updateTask">
|
||
|
|
UPDATE tb_crontab_task
|
||
|
|
<set>
|
||
|
|
<if test="task.taskName != null">task_name = #{task.taskName},</if>
|
||
|
|
<if test="task.taskGroup != null">task_group = #{task.taskGroup},</if>
|
||
|
|
<if test="task.beanName != null">bean_name = #{task.beanName},</if>
|
||
|
|
<if test="task.methodName != null">method_name = #{task.methodName},</if>
|
||
|
|
<if test="task.methodParams != null">method_params = #{task.methodParams},</if>
|
||
|
|
<if test="task.cronExpression != null">cron_expression = #{task.cronExpression},</if>
|
||
|
|
<if test="task.status != null">status = #{task.status},</if>
|
||
|
|
<if test="task.description != null">description = #{task.description},</if>
|
||
|
|
<if test="task.concurrent != null">concurrent = #{task.concurrent},</if>
|
||
|
|
<if test="task.misfirePolicy != null">misfire_policy = #{task.misfirePolicy},</if>
|
||
|
|
<if test="task.updater != null">updater = #{task.updater},</if>
|
||
|
|
update_time = NOW()
|
||
|
|
</set>
|
||
|
|
WHERE id = #{task.ID} AND deleted = 0
|
||
|
|
</update>
|
||
|
|
|
||
|
|
<!-- 删除任务(逻辑删除) -->
|
||
|
|
<update id="deleteTask">
|
||
|
|
UPDATE tb_crontab_task
|
||
|
|
SET deleted = 1,
|
||
|
|
delete_time = NOW()
|
||
|
|
WHERE id = #{taskId} AND deleted = 0
|
||
|
|
</update>
|
||
|
|
|
||
|
|
<!-- 根据ID查询任务 -->
|
||
|
|
<select id="selectTaskById" resultMap="BaseResultMap">
|
||
|
|
SELECT
|
||
|
|
<include refid="Base_Column_List" />
|
||
|
|
FROM tb_crontab_task
|
||
|
|
WHERE id = #{taskId} AND deleted = 0
|
||
|
|
</select>
|
||
|
|
|
||
|
|
<!-- 根据过滤条件查询任务列表 -->
|
||
|
|
<select id="selectTaskList" resultMap="BaseResultMap">
|
||
|
|
SELECT
|
||
|
|
<include refid="Base_Column_List" />
|
||
|
|
FROM tb_crontab_task
|
||
|
|
<include refid="Base_Where_Clause" />
|
||
|
|
ORDER BY create_time DESC
|
||
|
|
</select>
|
||
|
|
|
||
|
|
<!-- 分页查询任务列表 -->
|
||
|
|
<select id="selectTaskPage" resultMap="BaseResultMap">
|
||
|
|
SELECT
|
||
|
|
<include refid="Base_Column_List" />
|
||
|
|
FROM tb_crontab_task
|
||
|
|
<include refid="Base_Where_Clause" />
|
||
|
|
ORDER BY create_time DESC
|
||
|
|
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
|
||
|
|
</select>
|
||
|
|
|
||
|
|
<!-- 查询所有运行中的任务 -->
|
||
|
|
<select id="selectRunningTasks" resultMap="BaseResultMap">
|
||
|
|
SELECT
|
||
|
|
<include refid="Base_Column_List" />
|
||
|
|
FROM tb_crontab_task
|
||
|
|
WHERE status = 1 AND deleted = 0
|
||
|
|
ORDER BY create_time DESC
|
||
|
|
</select>
|
||
|
|
|
||
|
|
<!-- 更新任务状态 -->
|
||
|
|
<update id="updateTaskStatus">
|
||
|
|
UPDATE tb_crontab_task
|
||
|
|
SET status = #{status},
|
||
|
|
update_time = NOW()
|
||
|
|
WHERE id = #{taskId} AND deleted = 0
|
||
|
|
</update>
|
||
|
|
|
||
|
|
<!-- 根据Bean名称和方法名称查询任务 -->
|
||
|
|
<select id="selectTaskByBeanAndMethod" resultMap="BaseResultMap">
|
||
|
|
SELECT
|
||
|
|
<include refid="Base_Column_List" />
|
||
|
|
FROM tb_crontab_task
|
||
|
|
WHERE bean_name = #{beanName}
|
||
|
|
AND method_name = #{methodName}
|
||
|
|
AND deleted = 0
|
||
|
|
LIMIT 1
|
||
|
|
</select>
|
||
|
|
</mapper>
|