Enhance DirectorWorker functionality: Added branch_id to the Director struct and updated SQL queries to include branch_id as a parameter. Improved logging messages to include branch_id for better traceability during production, transport, and sales checks. This change enhances the clarity and functionality of the DirectorWorker's operations.
This commit is contained in:
@@ -11,6 +11,7 @@ use super::base::{BaseWorker, Worker, WorkerState};
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct Director {
|
struct Director {
|
||||||
id: i32,
|
id: i32,
|
||||||
|
branch_id: i32,
|
||||||
may_produce: bool,
|
may_produce: bool,
|
||||||
may_sell: bool,
|
may_sell: bool,
|
||||||
may_start_transport: bool,
|
may_start_transport: bool,
|
||||||
@@ -135,6 +136,7 @@ const QUERY_GET_BEST_PRODUCTION: &str = r#"
|
|||||||
ON ftp.id = fdtpw.product_id
|
ON ftp.id = fdtpw.product_id
|
||||||
AND ftp.category <= fdu.certificate
|
AND ftp.category <= fdu.certificate
|
||||||
WHERE fdd.id = $1
|
WHERE fdd.id = $1
|
||||||
|
AND fdb.id = $2
|
||||||
ORDER BY worth DESC
|
ORDER BY worth DESC
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
"#;
|
"#;
|
||||||
@@ -165,7 +167,8 @@ const QUERY_GET_INVENTORY: &str = r#"
|
|||||||
ON d.employer_user_id = fu.id
|
ON d.employer_user_id = fu.id
|
||||||
JOIN falukant_type.product p
|
JOIN falukant_type.product p
|
||||||
ON p.id = i.product_id
|
ON p.id = i.product_id
|
||||||
WHERE d.id = $1;
|
WHERE d.id = $1
|
||||||
|
AND b.id = $2;
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
const QUERY_REMOVE_INVENTORY: &str = r#"
|
const QUERY_REMOVE_INVENTORY: &str = r#"
|
||||||
@@ -323,22 +326,22 @@ impl DirectorWorker {
|
|||||||
for director in directors {
|
for director in directors {
|
||||||
if director.may_produce {
|
if director.may_produce {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"[DirectorWorker] Starte Produktionsprüfung für Director {}",
|
"[DirectorWorker] Starte Produktionsprüfung für Director {} (branch_id={})",
|
||||||
director.id
|
director.id, director.branch_id
|
||||||
);
|
);
|
||||||
self.start_productions(&director)?;
|
self.start_productions(&director)?;
|
||||||
}
|
}
|
||||||
if director.may_start_transport {
|
if director.may_start_transport {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"[DirectorWorker] Starte Transportprüfung für Director {}",
|
"[DirectorWorker] Starte Transportprüfung für Director {} (branch_id={})",
|
||||||
director.id
|
director.id, director.branch_id
|
||||||
);
|
);
|
||||||
self.start_transports_stub(&director);
|
self.start_transports_stub(&director);
|
||||||
}
|
}
|
||||||
if director.may_sell {
|
if director.may_sell {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"[DirectorWorker] Starte Verkaufsprüfung für Director {}",
|
"[DirectorWorker] Starte Verkaufsprüfung für Director {} (branch_id={})",
|
||||||
director.id
|
director.id, director.branch_id
|
||||||
);
|
);
|
||||||
self.start_sellings(&director)?;
|
self.start_sellings(&director)?;
|
||||||
}
|
}
|
||||||
@@ -350,6 +353,7 @@ impl DirectorWorker {
|
|||||||
fn map_row_to_director(row: Row) -> Option<Director> {
|
fn map_row_to_director(row: Row) -> Option<Director> {
|
||||||
Some(Director {
|
Some(Director {
|
||||||
id: row.get("id")?.parse().ok()?,
|
id: row.get("id")?.parse().ok()?,
|
||||||
|
branch_id: row.get("branch_id")?.parse().ok()?,
|
||||||
may_produce: row.get("may_produce").map(|v| v == "t" || v == "true").unwrap_or(false),
|
may_produce: row.get("may_produce").map(|v| v == "t" || v == "true").unwrap_or(false),
|
||||||
may_sell: row.get("may_sell").map(|v| v == "t" || v == "true").unwrap_or(false),
|
may_sell: row.get("may_sell").map(|v| v == "t" || v == "true").unwrap_or(false),
|
||||||
may_start_transport: row
|
may_start_transport: row
|
||||||
@@ -370,7 +374,7 @@ impl DirectorWorker {
|
|||||||
.map_err(|e| DbError::new(format!("DB-Verbindung fehlgeschlagen: {e}")))?;
|
.map_err(|e| DbError::new(format!("DB-Verbindung fehlgeschlagen: {e}")))?;
|
||||||
|
|
||||||
conn.prepare("get_to_produce", QUERY_GET_BEST_PRODUCTION)?;
|
conn.prepare("get_to_produce", QUERY_GET_BEST_PRODUCTION)?;
|
||||||
let rows = conn.execute("get_to_produce", &[&director.id])?;
|
let rows = conn.execute("get_to_produce", &[&director.id, &director.branch_id])?;
|
||||||
if rows.is_empty() {
|
if rows.is_empty() {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"[DirectorWorker] Keine Produktionskandidaten für Director {} gefunden.",
|
"[DirectorWorker] Keine Produktionskandidaten für Director {} gefunden.",
|
||||||
@@ -567,7 +571,7 @@ impl DirectorWorker {
|
|||||||
.map_err(|e| DbError::new(format!("DB-Verbindung fehlgeschlagen: {e}")))?;
|
.map_err(|e| DbError::new(format!("DB-Verbindung fehlgeschlagen: {e}")))?;
|
||||||
|
|
||||||
conn.prepare("get_to_sell", QUERY_GET_INVENTORY)?;
|
conn.prepare("get_to_sell", QUERY_GET_INVENTORY)?;
|
||||||
let rows = conn.execute("get_to_sell", &[&director.id])?;
|
let rows = conn.execute("get_to_sell", &[&director.id, &director.branch_id])?;
|
||||||
|
|
||||||
let mut items: Vec<InventoryItem> =
|
let mut items: Vec<InventoryItem> =
|
||||||
rows.into_iter().filter_map(Self::map_row_to_inventory_item).collect();
|
rows.into_iter().filter_map(Self::map_row_to_inventory_item).collect();
|
||||||
|
|||||||
Reference in New Issue
Block a user