feat: improve asset inventory statistics and responsive UX (v1.1.16)

This commit is contained in:
shishengliang
2026-09-23 11:07:36 +08:00
parent 9b0980e349
commit b0cba26fbb
30 changed files with 626 additions and 498 deletions
+33
View File
@@ -37,6 +37,15 @@ interface WeeklyStats {
export const MAIN_SQL = `SELECT
CAST(vi.id AS CHAR) AS id,
CAST(am.id AS CHAR) AS abnormal_move_id,
am.move_type AS abnormal_move_type,
CAST(pdv.id AS CHAR) AS pending_delivery_id,
pdts.contract_code AS pending_contract_no,
pdts.customer_name AS pending_customer_name,
am.move_status AS abnormal_move_status,
CONCAT_WS(';', NULLIF(TRIM(am.remark), ''), NULLIF(TRIM(amr.remark), '')) AS abnormal_move_work,
DATE_FORMAT(am.move_plan_end_time, '%Y-%m-%d %H:%i') AS abnormal_move_target_time,
DATE_FORMAT(am.move_end_time, '%Y-%m-%d %H:%i') AS abnormal_move_actual_time,
vi.plate_number AS 车牌号,
vi.vin AS vin,
vm.brand AS 车辆品牌,
@@ -114,6 +123,30 @@ LEFT JOIN common_district vi_city
LEFT JOIN common_district vi_operation_city
ON vi_operation_city.CODE = vi.operation_city COLLATE utf8mb4_unicode_ci
AND vi_operation_city.STATUS = 'VALID'
-- Pending delivery uses the current active task, never a completed historical lease.
LEFT JOIN delivery_vehicle pdv ON pdv.id = (
SELECT dv.id
FROM delivery_vehicle dv
JOIN delivery_task_subject dts ON dts.id = dv.delivery_task_subject_id
AND dts.del_flag = '0' AND dts.status = 0
WHERE dv.vehicle_id = vi.id AND dv.del_flag = '0' AND dv.status = 0
AND dv.delivery_status IN (0, 1) AND vs.vehicle_status = '4'
ORDER BY dv.create_time DESC, dv.id DESC
LIMIT 1
)
LEFT JOIN delivery_task_subject pdts ON pdts.id = pdv.delivery_task_subject_id
-- Select one effective movement per vehicle; drafts and withdrawals are not operational work.
-- An ongoing movement takes precedence over completed history.
LEFT JOIN vehicle_abnormal_move_record amr ON amr.id = (
SELECT mr.id
FROM vehicle_abnormal_move_record mr
JOIN vehicle_abnormal_move m ON m.id = mr.move_id AND m.del_flag = '0'
WHERE mr.vehicle_id = vi.id AND mr.del_flag = '0' AND m.move_status IN (3, 5)
AND vs.vehicle_status = '14'
ORDER BY (m.move_status = 3) DESC, COALESCE(m.move_start_time, m.create_time) DESC, m.id DESC, mr.id DESC
LIMIT 1
)
LEFT JOIN vehicle_abnormal_move am ON am.id = amr.move_id
${LATEST_VEHICLE_LEASE_JOIN_SQL}
WHERE vi.del_flag = '0'
AND COALESCE(vs.operation_status, '') <> '5'`;