This commit is contained in:
fenghp
2026-05-12 18:45:32 +08:00
parent c2fee4d2df
commit e78e4dd336
26 changed files with 1351 additions and 32 deletions
@@ -11,6 +11,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="onlineStatus" column="online_status"/>
<result property="taskStatus" column="task_status"/>
<result property="currentTaskId" column="current_task_id"/>
<result property="dispatchEnabled" column="dispatch_enabled"/>
<result property="workStatus" column="work_status"/>
<result property="idleTime" column="idle_time"/>
<result property="maintainReason" column="maintain_reason"/>
<result property="lastHeartbeatTime" column="last_heartbeat_time"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
@@ -21,7 +25,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<sql id="selectAfDeviceVo">
select id, user_name, device_code, online_status, task_status, current_task_id,
last_heartbeat_time, create_by, create_time, update_by, update_time, remark
dispatch_enabled, work_status, idle_time, maintain_reason, last_heartbeat_time,
create_by, create_time, update_by, update_time, remark
from af_device
</sql>
@@ -40,6 +45,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="taskStatus != null and taskStatus != ''">
and task_status = #{taskStatus}
</if>
<if test="dispatchEnabled != null and dispatchEnabled != ''">
and dispatch_enabled = #{dispatchEnabled}
</if>
<if test="workStatus != null and workStatus != ''">
and work_status = #{workStatus}
</if>
</where>
order by id desc
</select>
@@ -72,18 +83,34 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectAfDeviceVo"/>
where online_status = 'ONLINE'
and task_status = 'IDLE'
order by last_heartbeat_time desc, id asc
and dispatch_enabled = 'Y'
and work_status = 'READY'
and (maintain_reason is null or maintain_reason = '')
order by idle_time asc, last_heartbeat_time desc, id asc
limit 1
for update
</select>
<select id="selectDispatchableByIdForUpdate" resultMap="AfDeviceResult">
<include refid="selectAfDeviceVo"/>
where id = #{deviceId}
and online_status = 'ONLINE'
and task_status = 'IDLE'
and dispatch_enabled = 'Y'
and work_status = 'READY'
and (maintain_reason is null or maintain_reason = '')
for update
</select>
<insert id="insertAfDevice" parameterType="com.ruoyi.system.domain.af.AfDevice">
insert into af_device (
user_name, device_code, online_status, task_status, current_task_id,
last_heartbeat_time, create_by, create_time, update_by, update_time, remark
dispatch_enabled, work_status, idle_time, maintain_reason, last_heartbeat_time,
create_by, create_time, update_by, update_time, remark
) values (
#{userName}, #{deviceCode}, #{onlineStatus}, #{taskStatus}, #{currentTaskId},
#{lastHeartbeatTime}, #{createBy}, sysdate(), #{updateBy}, sysdate(), #{remark}
#{dispatchEnabled}, #{workStatus}, #{idleTime}, #{maintainReason}, #{lastHeartbeatTime},
#{createBy}, sysdate(), #{updateBy}, sysdate(), #{remark}
)
</insert>
@@ -93,7 +120,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="onlineStatus != null and onlineStatus != ''">online_status = #{onlineStatus},</if>
<if test="taskStatus != null and taskStatus != ''">task_status = #{taskStatus},</if>
<if test="currentTaskId != null">current_task_id = #{currentTaskId},</if>
<if test="currentTaskId == null">current_task_id = null,</if>
<if test="clearCurrentTaskId != null and clearCurrentTaskId">current_task_id = null,</if>
<if test="dispatchEnabled != null and dispatchEnabled != ''">dispatch_enabled = #{dispatchEnabled},</if>
<if test="workStatus != null and workStatus != ''">work_status = #{workStatus},</if>
<if test="idleTime != null">idle_time = #{idleTime},</if>
<if test="maintainReason != null">maintain_reason = #{maintainReason},</if>
<if test="lastHeartbeatTime != null">last_heartbeat_time = #{lastHeartbeatTime},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="remark != null">remark = #{remark},</if>
@@ -106,23 +137,74 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
update af_device
set task_status = 'HAS_TASK',
current_task_id = #{currentTaskId},
idle_time = null,
update_by = #{updateBy},
update_time = sysdate()
where id = #{id}
and online_status = 'ONLINE'
and task_status = 'IDLE'
and dispatch_enabled = 'Y'
and work_status = 'READY'
</update>
<update id="updateDeviceToIdle">
update af_device
set task_status = 'IDLE',
current_task_id = null,
idle_time = sysdate(),
update_by = #{updateBy},
update_time = sysdate()
where id = #{id}
and current_task_id = #{currentTaskId}
</update>
<update id="updateDeviceToIdleByExpect">
update af_device
set task_status = 'IDLE',
current_task_id = null,
idle_time = sysdate(),
update_by = #{updateBy},
update_time = sysdate()
where id = #{id}
and task_status = #{expectTaskStatus}
and current_task_id = #{currentTaskId}
</update>
<update id="enableDeviceDispatch">
update af_device
set dispatch_enabled = 'Y',
maintain_reason = null,
idle_time = case when task_status = 'IDLE' then ifnull(idle_time, sysdate()) else idle_time end,
update_by = #{updateBy},
update_time = sysdate()
where id = #{id}
</update>
<update id="disableDeviceDispatch">
update af_device
set dispatch_enabled = 'N',
maintain_reason = #{maintainReason},
update_by = #{updateBy},
update_time = sysdate()
where id = #{id}
</update>
<update id="updateWorkStatus">
update af_device
set work_status = #{workStatus},
update_by = #{updateBy},
update_time = sysdate()
where user_name = #{userName}
and device_code = #{deviceCode}
</update>
<select id="countActiveTaskByDeviceId" resultType="int">
select count(1)
from af_dispatch_task
where device_id = #{deviceId}
and status in ('CREATED', 'PUSHED', 'RECEIVED', 'PROCESSING')
</select>
<update id="refreshOfflineStatus">
update af_device
set online_status = 'OFFLINE',
@@ -167,4 +167,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
limit 1
</select>
<select id="countActiveTaskByOrderId" resultType="int">
select count(1)
from af_dispatch_task
where order_id = #{orderId}
and status in ('CREATED', 'PUSHED', 'RECEIVED', 'PROCESSING')
</select>
<select id="selectTimeoutTaskList" resultMap="AfDispatchTaskResult">
<include refid="selectAfDispatchTaskVo"/>
where status in ('PUSHED', 'RECEIVED', 'PROCESSING')
and timeout_at is not null
and timeout_at &lt;= now()
order by timeout_at asc, id asc
limit #{limit}
</select>
</mapper>
@@ -91,6 +91,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
user_name = #{userName},
device_code = #{deviceCode},
current_task_id = #{currentTaskId},
fail_reason = null,
update_by = #{updateBy},
update_time = sysdate()
where id = #{id}
@@ -129,4 +130,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where id = #{id}
</update>
<update id="updateOrderFailReason">
update af_order
set fail_reason = #{failReason},
update_by = #{updateBy},
update_time = sysdate()
where id = #{id}
</update>
</mapper>