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)]
|
||||
struct Director {
|
||||
id: i32,
|
||||
branch_id: i32,
|
||||
may_produce: bool,
|
||||
may_sell: bool,
|
||||
may_start_transport: bool,
|
||||
@@ -135,6 +136,7 @@ const QUERY_GET_BEST_PRODUCTION: &str = r#"
|
||||
ON ftp.id = fdtpw.product_id
|
||||
AND ftp.category <= fdu.certificate
|
||||
WHERE fdd.id = $1
|
||||
AND fdb.id = $2
|
||||
ORDER BY worth DESC
|
||||
LIMIT 1;
|
||||
"#;
|
||||
@@ -165,7 +167,8 @@ const QUERY_GET_INVENTORY: &str = r#"
|
||||
ON d.employer_user_id = fu.id
|
||||
JOIN falukant_type.product p
|
||||
ON p.id = i.product_id
|
||||
WHERE d.id = $1;
|
||||
WHERE d.id = $1
|
||||
AND b.id = $2;
|
||||
"#;
|
||||
|
||||
const QUERY_REMOVE_INVENTORY: &str = r#"
|
||||
@@ -323,22 +326,22 @@ impl DirectorWorker {
|
||||
for director in directors {
|
||||
if director.may_produce {
|
||||
eprintln!(
|
||||
"[DirectorWorker] Starte Produktionsprüfung für Director {}",
|
||||
director.id
|
||||
"[DirectorWorker] Starte Produktionsprüfung für Director {} (branch_id={})",
|
||||
director.id, director.branch_id
|
||||
);
|
||||
self.start_productions(&director)?;
|
||||
}
|
||||
if director.may_start_transport {
|
||||
eprintln!(
|
||||
"[DirectorWorker] Starte Transportprüfung für Director {}",
|
||||
director.id
|
||||
"[DirectorWorker] Starte Transportprüfung für Director {} (branch_id={})",
|
||||
director.id, director.branch_id
|
||||
);
|
||||
self.start_transports_stub(&director);
|
||||
}
|
||||
if director.may_sell {
|
||||
eprintln!(
|
||||
"[DirectorWorker] Starte Verkaufsprüfung für Director {}",
|
||||
director.id
|
||||
"[DirectorWorker] Starte Verkaufsprüfung für Director {} (branch_id={})",
|
||||
director.id, director.branch_id
|
||||
);
|
||||
self.start_sellings(&director)?;
|
||||
}
|
||||
@@ -350,6 +353,7 @@ impl DirectorWorker {
|
||||
fn map_row_to_director(row: Row) -> Option<Director> {
|
||||
Some(Director {
|
||||
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_sell: row.get("may_sell").map(|v| v == "t" || v == "true").unwrap_or(false),
|
||||
may_start_transport: row
|
||||
@@ -370,7 +374,7 @@ impl DirectorWorker {
|
||||
.map_err(|e| DbError::new(format!("DB-Verbindung fehlgeschlagen: {e}")))?;
|
||||
|
||||
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() {
|
||||
eprintln!(
|
||||
"[DirectorWorker] Keine Produktionskandidaten für Director {} gefunden.",
|
||||
@@ -567,7 +571,7 @@ impl DirectorWorker {
|
||||
.map_err(|e| DbError::new(format!("DB-Verbindung fehlgeschlagen: {e}")))?;
|
||||
|
||||
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> =
|
||||
rows.into_iter().filter_map(Self::map_row_to_inventory_item).collect();
|
||||
|
||||
Reference in New Issue
Block a user