Füge erweiterte SQL-Abfragen und Logging in ProduceWorker hinzu: Implementiere Update- und Insert-Logik für das Inventar und verbessere die Fehlerausgaben.
This commit is contained in:
@@ -231,7 +231,22 @@ ORDER BY total_capacity DESC;
|
||||
"#;
|
||||
|
||||
pub const QUERY_INSERT_INVENTORY: &str = r#"
|
||||
INSERT INTO falukant_data.inventory (stock_id, product_id, quantity, quality, produced_at) VALUES ($1, $2, $3, $4, NOW());
|
||||
INSERT INTO falukant_data.inventory (stock_id, product_id, quantity, quality, produced_at)
|
||||
VALUES ($1, $2, $3, $4, NOW())
|
||||
RETURNING id;
|
||||
"#;
|
||||
|
||||
pub const QUERY_UPDATE_INVENTORY_BY_STOCK_PRODUCT: &str = r#"
|
||||
UPDATE falukant_data.inventory
|
||||
SET quantity = quantity + $3,
|
||||
quality = LEAST(
|
||||
100,
|
||||
ROUND(
|
||||
((quantity * quality) + ($3 * $4))::numeric / NULLIF(quantity + $3, 0)
|
||||
)
|
||||
)
|
||||
WHERE stock_id = $1 AND product_id = $2
|
||||
RETURNING id;
|
||||
"#;
|
||||
|
||||
pub const QUERY_UPDATE_VEHICLE_AFTER_TRANSPORT: &str = r#"
|
||||
@@ -1361,7 +1376,7 @@ WHERE b.falukant_user_id = $1 AND s.stock_type_id = $2;
|
||||
"#;
|
||||
// Produce worker queries
|
||||
pub const QUERY_GET_FINISHED_PRODUCTIONS: &str = r#"
|
||||
SELECT
|
||||
SELECT
|
||||
p.id AS production_id,
|
||||
p.branch_id,
|
||||
p.product_id,
|
||||
@@ -1369,7 +1384,7 @@ pub const QUERY_GET_FINISHED_PRODUCTIONS: &str = r#"
|
||||
p.start_timestamp,
|
||||
pr.production_time,
|
||||
br.region_id,
|
||||
br.falukant_user_id,
|
||||
br.falukant_user_id AS user_id,
|
||||
ROUND(
|
||||
GREATEST(
|
||||
0,
|
||||
@@ -1390,7 +1405,7 @@ pub const QUERY_GET_FINISHED_PRODUCTIONS: &str = r#"
|
||||
ON p.branch_id = br.id
|
||||
JOIN falukant_data.character c
|
||||
ON c.user_id = br.falukant_user_id
|
||||
JOIN falukant_data.knowledge k
|
||||
LEFT JOIN falukant_data.knowledge k
|
||||
ON p.product_id = k.product_id
|
||||
AND k.character_id = c.id
|
||||
LEFT JOIN falukant_data.director d
|
||||
|
||||
Reference in New Issue
Block a user