feat: add endpoints and logic for retrieving warehouse space usage and status distribution, including SQL queries, models, and service integration
This commit is contained in:
@@ -95,3 +95,26 @@ WHERE st.transaction_type = 'export'
|
||||
GROUP BY c.id, c.name, c.unit, ct.name
|
||||
ORDER BY total_exported DESC
|
||||
LIMIT sqlc.arg('limit_count')::int;
|
||||
|
||||
-- name: GetStatusDistribution :many
|
||||
SELECT status, COUNT(*) AS count, COALESCE(SUM(quantity), 0)::bigint AS total_quantity
|
||||
FROM component_items ci
|
||||
JOIN containers con ON ci.container_id = con.id
|
||||
JOIN shelves s ON con.shelf_id = s.id
|
||||
JOIN cabinets cab ON s.cabinet_id = cab.id
|
||||
JOIN rooms r ON cab.room_id = r.id
|
||||
WHERE (sqlc.narg('warehouse_id')::bigint IS NULL OR r.warehouse_id = sqlc.narg('warehouse_id')::bigint)
|
||||
GROUP BY ci.status;
|
||||
|
||||
-- name: GetSpaceUsage :many
|
||||
SELECT w.name AS warehouse, r.name AS room,
|
||||
COUNT(DISTINCT c.id)::bigint AS total_containers,
|
||||
COUNT(DISTINCT ci.container_id)::bigint AS used_containers
|
||||
FROM warehouses w
|
||||
JOIN rooms r ON r.warehouse_id = w.id
|
||||
JOIN cabinets cb ON cb.room_id = r.id
|
||||
JOIN shelves s ON s.cabinet_id = cb.id
|
||||
JOIN containers c ON c.shelf_id = s.id
|
||||
LEFT JOIN component_items ci ON ci.container_id = c.id
|
||||
WHERE (sqlc.narg('warehouse_id')::bigint IS NULL OR w.id = sqlc.narg('warehouse_id')::bigint)
|
||||
GROUP BY w.name, r.name;
|
||||
|
||||
Reference in New Issue
Block a user