SELECT
top.id,
tp.operation_type AS operationType,
bs.name AS stationName,
-- 合并 robot 和 drone 的 name 到 robotName(优先取 robot)
COALESCE(
br.name, -- 来自 bs_robot 的机器人名称
ud.name, -- 来自 uav_drone 的无人机名称
'未知设备' -- 默认值
) AS robotName,
top.start_time AS startTime,
top.end_time AS endTime,
top.finish_status AS finishStatus,
tp.robot_id AS robotId,
tp.drone_id AS droneId,
bw.worker_name AS workerName -- 保留操作人员名称
FROM
tb_operation_job top
LEFT JOIN tb_operation tp ON top.operation_id = tp.id
LEFT JOIN bs_station bs ON tp.station_id = bs.id
-- 关联 tb_message 表(保持您的原始关联条件)
LEFT JOIN tb_message tm ON
tp.station_id = tm.station_id
AND (tp.robot_id = tm.robot_id OR (tp.robot_id IS NULL AND tp.drone_id = tm.drone_id))
-- 关联 robot 表(通过 tb_message)
LEFT JOIN bs_robot br ON tm.robot_id = br.id
-- 关联 drone 表(通过 tb_message)
LEFT JOIN uav_drone ud ON tm.drone_id = ud.id
-- 关联 worker 表
LEFT JOIN tb_worker bw ON tm.operation_worker = bw.id
top.runlog_or_operation = 0
and br.name like concat('%',#{robotName},'%')
or ud.name like concat('%',#{robotName},'%')
and bs.name like concat('%',#{stationName},'%')
and bw.worker_name like concat('%',#{workerName},'%')
and top.status like concat('%',#{status},'%')
and top.start_time >= #{startTime}
and top.endTime <= #{endTime}
and tp.operation_type like concat('%',#{operationType},'%')
and top.station_id = #{stationId}
and bw.username = #{username}
ORDER BY top.start_time DESC
SELECT
top.id,
tp.operation_type AS operationType,
top.operation_id AS operationId,
bs.name AS stationName,
-- 合并 robot 和 drone 的 name 到 robotName(优先取 robot)
COALESCE(
br.name, -- 来自 bs_robot 的机器人名称
ud.name, -- 来自 uav_drone 的无人机名称
'未知设备' -- 默认值
) AS robotName,
top.start_time AS startTime,
top.end_time AS endTime,
top.finish_status AS finishStatus,
tp.robot_id AS robotId,
tp.drone_id AS droneId,
bw.worker_name AS workerName -- 保留操作人员名称
FROM
tb_operation_job top
LEFT JOIN tb_operation tp ON top.operation_id = tp.id
LEFT JOIN bs_station bs ON tp.station_id = bs.id
-- 关联 tb_message 表(保持您的原始关联条件)
LEFT JOIN tb_message tm ON
tp.station_id = tm.station_id
AND (tp.robot_id = tm.robot_id OR (tp.robot_id IS NULL AND tp.drone_id = tm.drone_id))
-- 关联 robot 表(通过 tb_message)
LEFT JOIN bs_robot br ON tm.robot_id = br.id
-- 关联 drone 表(通过 tb_message)
LEFT JOIN uav_drone ud ON tm.drone_id = ud.id
-- 关联 worker 表
LEFT JOIN tb_worker bw ON tm.operation_worker = bw.id
top.runlog_or_operation = 0
AND top.finish_status NOT IN (2, 4)
AND #{date} BETWEEN top.start_time AND top.end_time
AND
YEAR(top.start_time) = #{year} AND MONTH(top.start_time) = #{month}
and bw.username = #{username}
and top.finish_status = #{finishStatus}
ORDER BY top.start_time DESC
SELECT
top.id,
tp.operation_type AS operationType,
top.operation_id AS operationId,
bs.name AS stationName,
-- 合并 robot 和 drone 的 name 到 robotName(优先取 robot)
COALESCE(
br.name, -- 来自 bs_robot 的机器人名称
ud.name, -- 来自 uav_drone 的无人机名称
'未知设备' -- 默认值
) AS robotName,
top.start_time AS startTime,
top.end_time AS endTime,
top.finish_status AS finishStatus,
tp.robot_id AS robotId,
tp.drone_id AS droneId,
bw.worker_name AS workerName, -- 保留操作人员名称
top.runlog_or_operation AS runlog_or_operation
FROM
tb_operation_job top
LEFT JOIN tb_operation tp ON top.operation_id = tp.id
LEFT JOIN bs_station bs ON tp.station_id = bs.id
-- 关联 tb_message 表(保持您的原始关联条件)
LEFT JOIN tb_message tm ON
tp.station_id = tm.station_id
AND (tp.robot_id = tm.robot_id OR (tp.robot_id IS NULL AND tp.drone_id = tm.drone_id))
-- 关联 robot 表(通过 tb_message)
LEFT JOIN bs_robot br ON tm.robot_id = br.id
-- 关联 drone 表(通过 tb_message)
LEFT JOIN uav_drone ud ON tm.drone_id = ud.id
-- 关联 worker 表
LEFT JOIN tb_worker bw ON tm.operation_worker = bw.id
and top.station_id = #{stationId}
and bw.username = #{username}
and top.finish_status = #{finishStatus}
ORDER BY
top.runlog_or_operation DESC, -- 1在前,0在后
top.start_time DESC
SELECT
top.id,
tp.operation_type AS operationType,
bs.name AS stationName,
-- 合并 robot 和 drone 的 name 到 robotName(优先取 robot)
COALESCE(
br.name, -- 来自 bs_robot 的机器人名称
ud.name, -- 来自 uav_drone 的无人机名称
'未知设备' -- 默认值
) AS robotName,
top.start_time AS startTime,
top.end_time AS endTime,
top.finish_status AS finishStatus,
tp.robot_id AS robotId,
tp.drone_id AS droneId,
bw.worker_name AS workerName -- 保留操作人员名称
FROM
tb_operation_job top
LEFT JOIN tb_operation tp ON top.operation_id = tp.id
LEFT JOIN bs_station bs ON tp.station_id = bs.id
-- 关联 tb_message 表(保持您的原始关联条件)
LEFT JOIN tb_message tm ON
tp.station_id = tm.station_id
AND (tp.robot_id = tm.robot_id OR (tp.robot_id IS NULL AND tp.drone_id = tm.drone_id))
-- 关联 robot 表(通过 tb_message)
LEFT JOIN bs_robot br ON tm.robot_id = br.id
-- 关联 drone 表(通过 tb_message)
LEFT JOIN uav_drone ud ON tm.drone_id = ud.id
-- 关联 worker 表
LEFT JOIN tb_worker bw ON tm.operation_worker = bw.id
top.runlog_or_operation = 1
and br.name like concat('%',#{robotName},'%')
or ud.name like concat('%',#{robotName},'%')
and bs.name like concat('%',#{stationName},'%')
and bw.worker_name like concat('%',#{workerName},'%')
and top.status like concat('%',#{status},'%')
and top.start_time >= #{startTime}
and top.endTime <= #{endTime}
and tp.operation_type like concat('%',#{operationType},'%')
and top.station_id = #{stationId}
ORDER BY top.start_time DESC
UPDATE tb_operation_job
SET finish_status = CASE
WHEN CURRENT_TIMESTAMP > end_time THEN 2
ELSE 4
END
WHERE id = #{id};
SELECT *
FROM tb_operation_job
WHERE start_time > CURRENT_TIMESTAMP
ORDER BY start_time ASC
LIMIT 1;
UPDATE tb_operation_job
SET finish_status = 4
WHERE id = #{id};
select
COALESCE(br.name, dr.name) AS robotName,
bs.name AS stationName,
tp.operation_type AS operationType
from tb_operation_job top
LEFT JOIN tb_operation tp ON top.operation_id = tp.id
LEFT JOIN bs_station bs ON tp.station_id = bs.id
LEFT JOIN bs_robot br ON tp.robot_id = br.id
LEFT JOIN uav_drone dr ON tp.drone_id = dr.id
where
top.runlog_or_operation = 1
and top.finish_status = 1