Enhance production management by adding region_id to ProductionPlan and updating SQL queries: Introduced region_id to the ProductionPlan struct and modified the insert production query to include weather_type_id based on region. Updated finished productions query to account for weather effects on quality ratings, ensuring accurate production assessments. Improved comments for clarity on the impact of weather on production quality.
This commit is contained in:
@@ -24,6 +24,7 @@ struct ProductionPlan {
|
||||
certificate: i32,
|
||||
branch_id: i32,
|
||||
product_id: i32,
|
||||
region_id: i32,
|
||||
stock_size: i32,
|
||||
used_in_stock: i32,
|
||||
running_productions: i32,
|
||||
@@ -93,6 +94,7 @@ const QUERY_GET_BEST_PRODUCTION: &str = r#"
|
||||
fdu.certificate,
|
||||
ftp.id product_id,
|
||||
ftp.label_tr,
|
||||
fdb.region_id,
|
||||
(
|
||||
SELECT SUM(quantity)
|
||||
FROM falukant_data.stock fds
|
||||
@@ -146,8 +148,12 @@ const QUERY_GET_BEST_PRODUCTION: &str = r#"
|
||||
"#;
|
||||
|
||||
const QUERY_INSERT_PRODUCTION: &str = r#"
|
||||
INSERT INTO falukant_data.production (branch_id, product_id, quantity)
|
||||
VALUES ($1, $2, $3);
|
||||
INSERT INTO falukant_data.production (branch_id, product_id, quantity, weather_type_id)
|
||||
VALUES ($1, $2, $3, (
|
||||
SELECT weather_type_id
|
||||
FROM falukant_data.weather
|
||||
WHERE region_id = $4
|
||||
));
|
||||
"#;
|
||||
|
||||
// Query zum Abfragen der aktuellen Lager- und Produktionswerte für einen Branch
|
||||
@@ -540,6 +546,10 @@ impl DirectorWorker {
|
||||
.get("running_productions_quantity")
|
||||
.and_then(|v| v.parse::<i32>().ok())
|
||||
.unwrap_or(0);
|
||||
let region_id: i32 = row
|
||||
.get("region_id")
|
||||
.and_then(|v| v.parse::<i32>().ok())
|
||||
.unwrap_or(0);
|
||||
|
||||
Some(ProductionPlan {
|
||||
falukant_user_id,
|
||||
@@ -547,6 +557,7 @@ impl DirectorWorker {
|
||||
certificate,
|
||||
branch_id,
|
||||
product_id,
|
||||
region_id,
|
||||
stock_size,
|
||||
used_in_stock,
|
||||
running_productions,
|
||||
@@ -634,9 +645,10 @@ impl DirectorWorker {
|
||||
conn.prepare("insert_production", QUERY_INSERT_PRODUCTION)?;
|
||||
|
||||
// Eine einzelne Produktion mit max. 100 Stück anlegen
|
||||
// Das aktuelle Wetter der Region wird automatisch aus der weather-Tabelle geholt
|
||||
conn.execute(
|
||||
"insert_production",
|
||||
&[&plan.branch_id, &plan.product_id, &to_produce],
|
||||
&[&plan.branch_id, &plan.product_id, &to_produce, &plan.region_id],
|
||||
)?;
|
||||
|
||||
eprintln!(
|
||||
|
||||
@@ -30,7 +30,7 @@ struct StockInfo {
|
||||
|
||||
// SQL-Queries analog zur C++-Implementierung
|
||||
// Wichtig: Pro `production.id` darf hier **genau eine Zeile** zurückkommen.
|
||||
// Durch die Joins auf Director/Knowledge kann es sonst zu Mehrfachzeilen mit
|
||||
// Durch die Joins auf Director/Knowledge/Wetter kann es sonst zu Mehrfachzeilen mit
|
||||
// unterschiedlicher berechneter Qualität kommen. Deshalb wird die Qualität
|
||||
// über MAX() aggregiert und nach `production_id` gruppiert.
|
||||
const QUERY_GET_FINISHED_PRODUCTIONS: &str = r#"
|
||||
@@ -41,13 +41,24 @@ const QUERY_GET_FINISHED_PRODUCTIONS: &str = r#"
|
||||
p.quantity,
|
||||
p.start_timestamp,
|
||||
pr.production_time,
|
||||
-- Aggregierte Qualitätsbewertung pro Produktion
|
||||
-- Aggregierte Qualitätsbewertung pro Produktion inkl. Wettereinfluss
|
||||
MAX(
|
||||
GREATEST(
|
||||
0,
|
||||
LEAST(
|
||||
100,
|
||||
ROUND(
|
||||
(
|
||||
CASE
|
||||
WHEN k2.id IS NOT NULL
|
||||
THEN (k.knowledge * 2 + k2.knowledge) / 3
|
||||
ELSE k.knowledge
|
||||
END
|
||||
)::numeric
|
||||
+ COALESCE(pwe.quality_effect, 0) * 2.5
|
||||
)
|
||||
)
|
||||
)::int
|
||||
) AS quality,
|
||||
br.region_id,
|
||||
br.falukant_user_id AS user_id
|
||||
@@ -63,6 +74,10 @@ const QUERY_GET_FINISHED_PRODUCTIONS: &str = r#"
|
||||
AND k.character_id = c.id
|
||||
JOIN falukant_data.stock s
|
||||
ON s.branch_id = br.id
|
||||
-- Optionaler Wettereinfluss: pro (Produkt, Wetter) genau ein Datensatz
|
||||
LEFT JOIN falukant_type.product_weather_effect pwe
|
||||
ON pwe.product_id = p.product_id
|
||||
AND pwe.weather_type_id = p.weather_type_id
|
||||
LEFT JOIN falukant_data.director d
|
||||
ON d.employer_user_id = c.user_id
|
||||
LEFT JOIN falukant_data.knowledge k2
|
||||
|
||||
Reference in New Issue
Block a user