Commit 7b817d2a authored by 王蔡翾's avatar 王蔡翾
Browse files

初始化

parent 42848b59
......@@ -3,63 +3,88 @@
<mapper namespace="com.example.operation_platform.mapper.OperationDoMapper">
<select id="queryDoList" resultType="com.example.operation_platform.model.vo.OperationDoVO">
select
top.id as id,
top.operation_cycle as operationCycle,
top.start_time as startTime,
br.name as robotName,
bs.name as stationName,
bw.worker_name as workerName,
top.operation_type as operationType,
top.status
from tb_operation top
left join bs_robot br on top.robot_id = br.id
left join bs_station bs on top.station_id = bs.id
left join tb_worker bw on top.worker_id = bw.id
SELECT
top.id AS id,
top.operation_cycle AS operationCycle,
top.start_time AS startTime,
COALESCE(br.name, dr.name) AS robotName,
bs.name AS stationName,
bw.worker_name AS workerName,
top.operation_type AS operationType,
top.status AS status,
top.robot_id AS robotId,
top.station_id AS stationId,
top.item_id AS itemId,
top.finish_time AS finishTime,
top.drone_id AS droneId,
latest_rd.operation_date AS lastTime,
(
SELECT GROUP_CONCAT(DISTINCT bti.operation_item SEPARATOR ', ')
FROM tb_operation_item bti
WHERE FIND_IN_SET(bti.id, top.item_id) > 0
) AS operationItems
FROM tb_operation top
LEFT JOIN bs_robot br ON top.robot_id = br.id
LEFT JOIN bs_station bs ON top.station_id = bs.id
LEFT JOIN tb_message tb ON top.station_id = tb.station_id
AND (top.robot_id = tb.robot_id OR (top.robot_id IS NULL AND top.drone_id = tb.drone_id))
LEFT JOIN tb_worker bw ON tb.operation_worker = bw.id
LEFT JOIN uav_drone dr ON top.drone_id = dr.id
LEFT JOIN (
SELECT rd1.*
FROM tb_operation_record rd1
INNER JOIN (
SELECT operation_id, MAX(operation_date) AS max_date
FROM tb_operation_record
GROUP BY operation_id
) rd2 ON rd1.operation_id = rd2.operation_id AND rd1.operation_date = rd2.max_date
) latest_rd ON top.id = latest_rd.operation_id
<where>
top.runlog_or_operation = 0
<if test="robotName != null and robotName != ''">
br.name like concat('%',#{robotName},'%')
and br.name LIKE CONCAT('%', #{robotName}, '%')
or dr.name LIKE CONCAT('%', #{robotName}, '%')
</if>
<if test="stationName != null and stationName != ''">
and bs.name like concat('%',#{stationName},'%')
AND bs.name LIKE CONCAT('%', #{stationName}, '%')
</if>
<if test="workerName != null and workerName != ''">
and bw.worker_name like concat('%',#{workerName},'%')
AND bw.worker_name LIKE CONCAT('%', #{workerName}, '%')
</if>
<if test="status != null and status != ''">
and top.status like concat('%',#{status},'%')
AND top.status = #{status}
</if>
<if test="startTime != null">
and top.start_time &gt;= #{startTime}
AND top.start_time &gt;= #{startTime}
</if>
<if test="endTime != null">
and top.end_time &lt;= #{endTime}
AND top.start_time &lt;= #{endTime} <!-- 注意字段名是finish_time还是end_time -->
</if>
</where>
ORDER BY top.start_time DESC
</select>
<update id="stopDo" parameterType="com.example.operation_platform.model.vo.OperationDoVO">
UPDATE tb_operation
SET status = #{status}
WHERE id = #{id}
</update>
<select id="querymoreDoList" resultType="com.example.operation_platform.model.vo.OperationDoVO">
SELECT
info.*
FROM
tb_operation info
JOIN (
-- 拆分后的ID子查询
SELECT
SUBSTRING_INDEX(SUBSTRING_INDEX(item_id, ',', numbers.n), ',', -1) AS split_id
FROM
tb_operation_item
CROSS JOIN
(SELECT 1 AS n UNION SELECT 2 UNION SELECT 3 UNION SELECT 4) numbers
WHERE
CHAR_LENGTH(item_id) - CHAR_LENGTH(REPLACE(item_id, ',', '')) >= numbers.n - 1
) split_data ON info.item_id = split_data.split_id;
</select>
<select id="querymessage" resultType="com.example.operation_platform.model.vo.MessageNeedDataVo">
select
top.start_time AS startTime,
COALESCE(br.name, dr.name) AS robotName,
bs.name AS stationName,
top.operation_type AS operationType
from tb_operation top
LEFT JOIN bs_robot br ON top.robot_id = br.id
LEFT JOIN bs_station bs ON top.station_id = bs.id
LEFT JOIN tb_operation_job tb ON top.id = tb.operation_id
LEFT JOIN uav_drone dr ON top.drone_id = dr.id
where
top.id = #{id}
and top.runlog_or_operation = 0
and tb.start_time > CURRENT_TIMESTAMP
</select>
</mapper>
......@@ -3,22 +3,41 @@
<mapper namespace="com.example.operation_platform.mapper.OperationJobMapper">
<select id="queryJobList" resultType="com.example.operation_platform.model.vo.OperationJobVO">
select
SELECT
top.id,
tp.operation_type as operationType,
bs.name as stationName,
bw.worker_name as workerName,
br.name as robotName,
top.start_time as startTime,
top.finish_status
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 tb_worker bw on tp.worker_id = bw.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
<where>
top.runlog_or_operation = 0
<if test="robotName != null and robotName != ''">
br.name like concat('%',#{robotName},'%')
and br.name like concat('%',#{robotName},'%')
or ud.name like concat('%',#{robotName},'%')
</if>
<if test="stationName != null and stationName != ''">
and bs.name like concat('%',#{stationName},'%')
......@@ -33,9 +52,13 @@
and top.start_time &gt;= #{startTime}
</if>
<if test="endTime != null">
and top.end_time &lt;= #{endTime}
and top.endTime &lt;= #{endTime}
</if>
<if test="operationType != null and operationType != ''">
and tp.operation_type like concat('%',#{operationType},'%')
</if>
</where>
ORDER BY top.start_time DESC
</select>
......
......@@ -9,6 +9,7 @@
tw.worker_name workerName,
tw.phone_number phoneNumber,
typ.worker_type type,
tw.type typeId,
tw.company company
from
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment