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:
Torsten Schulz (local)
2025-12-02 09:57:31 +01:00
parent 32dd79bc6e
commit c943e57f80
2 changed files with 37 additions and 10 deletions

View File

@@ -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!(