SELECT
top.id,
top.runlog_or_operation AS runlogOrOperation,
tp.operation_type AS operationType,
tp.item_id AS itemId,
tp.station_id AS stationId,
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 tp.station_id = #{stationId}
and bw.username = #{username}
ORDER BY top.start_time DESC
SELECT
top.id,
top.runlog_or_operation AS runlogOrOperation,
tp.item_id AS itemId,
tp.operation_type AS operationType,
top.operation_id AS operationId,
bs.name AS stationName,
tp.station_id AS stationId,
-- 合并 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 top.start_time like concat('%',#{date},'%')
AND
YEAR(top.start_time) = #{year} AND MONTH(top.start_time) = #{month}
and bw.username = #{username}
and top.finish_status = #{status}
ORDER BY top.start_time DESC
SELECT
top.id,
tp.item_id AS itemId,
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 runLogOrOperation,
tp.tb_run_log_id AS runLogId,
tp.station_id AS stationId
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
tp.station_id = #{stationId}
and bw.username = #{username}
and top.finish_status = #{finishStatus}
ORDER BY
top.runlog_or_operation DESC, -- 1在前,0在后
top.start_time ASC
SELECT
top.id,
top.operation_id operationId,
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,
tp.tb_run_log_id AS runLogId,
tp.station_id AS stationId,
bs.lon lon,
bs.lat lat,
bs.address
-- 保留操作人员名称
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 top.finish_status = 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 tp.station_id = #{stationId}
and top.finish_status = #{finishStatus}
and tp.robot_id = #{robotId}
and tp.drone_id = #{droneId}
and top.id = #{id}
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
SELECT
top.id,
tp.operation_type AS operationType,
bs.name AS stationName,
COALESCE(br.name, dr.name) AS robotName,
tp.tb_run_log_id AS runLogId,
top.start_time AS startTime,
tp.station_id AS stationId,
top.operation_id AS operationId
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
tp.runlog_or_operation=1
AND tp.finish_status NOT 4
SELECT
top.id,
top.runlog_or_operation AS runlogOrOperation,
top.operation_id operationId,
tp.operation_type AS operationType,
bs.name AS stationName,
bs.address address,
bs.lon,
bs.lat,
COALESCE(br.name, ud.name, '未知设备') 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,
(
SELECT GROUP_CONCAT(DISTINCT bti.operation_item SEPARATOR ', ')
FROM tb_operation_item bti
WHERE FIND_IN_SET(bti.id, tp.item_id) > 0
) AS operationItems,
tp.item_id AS itemId,
tp.station_id AS stationId,
-- 新增lastTime字段:查找相同operation_id记录中的最大开始时间
(
SELECT MAX(t.start_time)
FROM tb_operation_job t
WHERE t.operation_id = top.operation_id
) AS lastTime
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 ud ON tp.drone_id = ud.id
LEFT JOIN tb_operation_item bti ON tp.item_id = bti.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.end_time <= #{endTime}
and tp.operation_type like concat('%',#{operationType},'%')
and tp.station_id = #{stationId}
and bw.username = #{username}
and top.id = #{id}
ORDER BY top.start_time DESC