Add sleep management for productions in ProduceWorker: Implement logic to set productions to sleep when storage capacity is insufficient. Introduce methods for processing and retrieving sleep productions, enhancing inventory management and production flow control.
This commit is contained in:
@@ -1655,6 +1655,7 @@ pub const QUERY_GET_FINISHED_PRODUCTIONS: &str = r#"
|
||||
AND pwe.weather_type_id = w.weather_type_id
|
||||
-- Wetter-Effekte derzeit aus der Qualitätsberechnung entfernt
|
||||
WHERE p.start_timestamp + INTERVAL '1 minute' * pr.production_time <= NOW()
|
||||
AND COALESCE(p.sleep, FALSE) = FALSE
|
||||
ORDER BY p.start_timestamp;
|
||||
"#;
|
||||
|
||||
@@ -1663,6 +1664,64 @@ pub const QUERY_DELETE_PRODUCTION: &str = r#"
|
||||
WHERE id = $1;
|
||||
"#;
|
||||
|
||||
pub const QUERY_SET_PRODUCTION_SLEEP: &str = r#"
|
||||
UPDATE falukant_data.production
|
||||
SET sleep = TRUE
|
||||
WHERE id = $1;
|
||||
"#;
|
||||
|
||||
pub const QUERY_GET_SLEEP_PRODUCTIONS: &str = r#"
|
||||
SELECT
|
||||
p.id AS production_id,
|
||||
p.branch_id,
|
||||
p.product_id,
|
||||
p.quantity,
|
||||
p.start_timestamp,
|
||||
pr.production_time,
|
||||
br.region_id,
|
||||
br.falukant_user_id AS user_id,
|
||||
ROUND(
|
||||
GREATEST(
|
||||
0,
|
||||
LEAST(
|
||||
100,
|
||||
(
|
||||
(COALESCE(k.knowledge, 0) * 0.75
|
||||
+ COALESCE(k2.knowledge, 0) * 0.25)
|
||||
* COALESCE(pwe.quality_effect, 100) / 100.0
|
||||
)
|
||||
)
|
||||
)
|
||||
)::int AS quality
|
||||
FROM falukant_data.production p
|
||||
JOIN falukant_type.product pr
|
||||
ON p.product_id = pr.id
|
||||
JOIN falukant_data.branch br
|
||||
ON p.branch_id = br.id
|
||||
LEFT JOIN LATERAL (
|
||||
SELECT c.id, c.user_id
|
||||
FROM falukant_data.character c
|
||||
WHERE c.user_id = br.falukant_user_id
|
||||
ORDER BY c.updated_at DESC NULLS LAST, c.id DESC
|
||||
LIMIT 1
|
||||
) c ON TRUE
|
||||
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
|
||||
ON d.employer_user_id = c.user_id
|
||||
LEFT JOIN falukant_data.knowledge k2
|
||||
ON k2.character_id = d.director_character_id
|
||||
AND k2.product_id = p.product_id
|
||||
LEFT JOIN falukant_data.weather w
|
||||
ON w.region_id = br.region_id
|
||||
LEFT JOIN falukant_type.product_weather_effect pwe
|
||||
ON pwe.product_id = p.product_id
|
||||
AND pwe.weather_type_id = w.weather_type_id
|
||||
WHERE p.sleep = TRUE
|
||||
ORDER BY p.start_timestamp;
|
||||
"#;
|
||||
|
||||
pub const QUERY_INSERT_UPDATE_PRODUCTION_LOG: &str = r#"
|
||||
INSERT INTO falukant_log.production (
|
||||
region_id,
|
||||
|
||||
Reference in New Issue
Block a user