72 lines
2.6 KiB
XML
72 lines
2.6 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="com.mhd.basic.domain.scheduledTask.repository.mapper.ScheduledTaskMapper">
|
|
|
|
<!-- 通用结果映射 -->
|
|
<resultMap id="BaseResultMap" type="com.mhd.basic.domain.scheduledTask.entity.ScheduledTask">
|
|
<id column="id" property="id"/>
|
|
<result column="task_type" property="taskType"/>
|
|
<result column="execute_time" property="executeTime"/>
|
|
<result column="task_data" property="taskData"/>
|
|
<result column="task_status" property="taskStatus"/>
|
|
<result column="retry_count" property="retryCount"/>
|
|
<result column="create_time" property="createTime"/>
|
|
<result column="update_time" property="updateTime"/>
|
|
</resultMap>
|
|
|
|
<!-- 通用查询列 -->
|
|
<sql id="Base_Column_List">
|
|
id, task_type, execute_time, task_data, task_status, retry_count, create_time, update_time, bill_days, bill_time,bus_id
|
|
</sql>
|
|
|
|
<!-- 查询待执行任务 -->
|
|
<select id="findPendingTasks" resultMap="BaseResultMap">
|
|
SELECT
|
|
<include refid="Base_Column_List"/>
|
|
FROM scheduled_task
|
|
WHERE
|
|
TO_DATE(
|
|
TO_CHAR(SYSDATE, 'YYYY-MM-') || bill_days || ' ' || bill_time,
|
|
'YYYY-MM-DD HH24:MI:SS'
|
|
) BETWEEN #{startTime} AND #{endTime}
|
|
ORDER BY TO_DATE(
|
|
TO_CHAR(SYSDATE, 'YYYY-MM-') || bill_days || ' ' || bill_time,
|
|
'YYYY-MM-DD HH24:MI:SS'
|
|
) ASC
|
|
LIMIT #{limit}
|
|
</select>
|
|
|
|
<!-- 批量更新状态(可选:用于批量处理) -->
|
|
<update id="batchUpdateStatus" parameterType="map">
|
|
UPDATE scheduled_task
|
|
SET task_status = #{newStatus},
|
|
update_time = NOW()
|
|
WHERE id IN
|
|
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
|
#{id}
|
|
</foreach>
|
|
AND task_status = #{oldStatus}
|
|
</update>
|
|
|
|
<!-- 统计待处理任务数量 -->
|
|
<select id="countPendingTasks" resultType="int">
|
|
SELECT COUNT(*)
|
|
FROM scheduled_task
|
|
WHERE task_status = 'PENDING'
|
|
AND execute_time <= NOW()
|
|
</select>
|
|
|
|
<!-- 查询超时任务(处理中超过30分钟的任务) -->
|
|
<select id="findTimeoutTasks" resultMap="BaseResultMap">
|
|
SELECT
|
|
<include refid="Base_Column_List"/>
|
|
FROM scheduled_task
|
|
WHERE
|
|
task_status = 'PROCESSING'
|
|
AND update_time < DATE_SUB(NOW(), INTERVAL 30 MINUTE)
|
|
LIMIT 50
|
|
</select>
|
|
|
|
</mapper> |