Refactor DirectorWorker SQL queries: Remove unused QUERY_GET_DIRECTOR_USER and update vehicle count retrieval to use consistent column names. This improves code clarity and maintains consistency in data handling.
This commit is contained in:
@@ -24,7 +24,6 @@ use crate::worker::sql::{
|
|||||||
QUERY_GET_SALARY_TO_PAY,
|
QUERY_GET_SALARY_TO_PAY,
|
||||||
QUERY_SET_SALARY_PAYED,
|
QUERY_SET_SALARY_PAYED,
|
||||||
QUERY_UPDATE_SATISFACTION,
|
QUERY_UPDATE_SATISFACTION,
|
||||||
QUERY_GET_DIRECTOR_USER,
|
|
||||||
QUERY_COUNT_VEHICLES_IN_BRANCH_REGION,
|
QUERY_COUNT_VEHICLES_IN_BRANCH_REGION,
|
||||||
QUERY_COUNT_VEHICLES_IN_REGION,
|
QUERY_COUNT_VEHICLES_IN_REGION,
|
||||||
QUERY_CHECK_ROUTE,
|
QUERY_CHECK_ROUTE,
|
||||||
@@ -589,14 +588,8 @@ impl DirectorWorker {
|
|||||||
// Für alle Items dieses Directors sollten die user_id-Felder identisch
|
// Für alle Items dieses Directors sollten die user_id-Felder identisch
|
||||||
// sein (Arbeitgeber des Directors).
|
// sein (Arbeitgeber des Directors).
|
||||||
let falukant_user_id = if items.is_empty() {
|
let falukant_user_id = if items.is_empty() {
|
||||||
// Wenn keine Items vorhanden sind, müssen wir die user_id anders ermitteln
|
// User-ID ist bereits über QUERY_GET_DIRECTORS geladen.
|
||||||
conn.prepare("get_director_user", QUERY_GET_DIRECTOR_USER)?;
|
director.falukant_user_id
|
||||||
let user_rows = conn.execute("get_director_user", &[&director.id])?;
|
|
||||||
user_rows
|
|
||||||
.into_iter()
|
|
||||||
.next()
|
|
||||||
.and_then(|row| row.get("employer_user_id").and_then(|v| v.parse::<i32>().ok()))
|
|
||||||
.ok_or_else(|| DbError::new("Konnte employer_user_id nicht ermitteln"))?
|
|
||||||
} else {
|
} else {
|
||||||
items[0].user_id
|
items[0].user_id
|
||||||
};
|
};
|
||||||
@@ -612,7 +605,7 @@ impl DirectorWorker {
|
|||||||
let vehicles_in_branch = vehicle_count_rows
|
let vehicles_in_branch = vehicle_count_rows
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.next()
|
.next()
|
||||||
.and_then(|row| row.get("count").and_then(|v| v.parse::<i32>().ok()))
|
.and_then(|row| row.get("cnt").and_then(|v| v.parse::<i32>().ok()))
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
|
|
||||||
// Falls es nichts zu transportieren gibt, prüfe auf leere Transporte
|
// Falls es nichts zu transportieren gibt, prüfe auf leere Transporte
|
||||||
@@ -665,7 +658,7 @@ impl DirectorWorker {
|
|||||||
let vehicles_in_branch_after = vehicle_count_rows_after
|
let vehicles_in_branch_after = vehicle_count_rows_after
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.next()
|
.next()
|
||||||
.and_then(|row| row.get("count").and_then(|v| v.parse::<i32>().ok()))
|
.and_then(|row| row.get("cnt").and_then(|v| v.parse::<i32>().ok()))
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
|
|
||||||
if vehicles_in_branch_after == 0 {
|
if vehicles_in_branch_after == 0 {
|
||||||
@@ -715,7 +708,7 @@ impl DirectorWorker {
|
|||||||
let vehicles_in_branch_final = vehicle_count_rows_final
|
let vehicles_in_branch_final = vehicle_count_rows_final
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.next()
|
.next()
|
||||||
.and_then(|row| row.get("count").and_then(|v| v.parse::<i32>().ok()))
|
.and_then(|row| row.get("cnt").and_then(|v| v.parse::<i32>().ok()))
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
|
|
||||||
if vehicles_in_branch_final == 0 {
|
if vehicles_in_branch_final == 0 {
|
||||||
@@ -1168,7 +1161,7 @@ impl DirectorWorker {
|
|||||||
let vehicle_count = vehicle_count_rows
|
let vehicle_count = vehicle_count_rows
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.next()
|
.next()
|
||||||
.and_then(|row| row.get("count").and_then(|v| v.parse::<i32>().ok()))
|
.and_then(|row| row.get("cnt").and_then(|v| v.parse::<i32>().ok()))
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
|
|
||||||
eprintln!(
|
eprintln!(
|
||||||
@@ -1186,7 +1179,7 @@ impl DirectorWorker {
|
|||||||
let route_exists = route_rows
|
let route_exists = route_rows
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.next()
|
.next()
|
||||||
.and_then(|row| row.get("count").and_then(|v| v.parse::<i32>().ok()))
|
.and_then(|row| row.get("1").and_then(|v| v.parse::<i32>().ok()))
|
||||||
.unwrap_or(0) > 0;
|
.unwrap_or(0) > 0;
|
||||||
|
|
||||||
eprintln!(
|
eprintln!(
|
||||||
|
|||||||
@@ -455,10 +455,6 @@ WITH new_sats AS (
|
|||||||
UPDATE falukant_data.director dir SET satisfaction = ns.new_satisfaction FROM new_sats ns WHERE dir.id = ns.id AND dir.satisfaction IS DISTINCT FROM ns.new_satisfaction RETURNING dir.employer_user_id;
|
UPDATE falukant_data.director dir SET satisfaction = ns.new_satisfaction FROM new_sats ns WHERE dir.id = ns.id AND dir.satisfaction IS DISTINCT FROM ns.new_satisfaction RETURNING dir.employer_user_id;
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
pub const QUERY_GET_DIRECTOR_USER: &str = r#"
|
|
||||||
SELECT fu.id AS falukant_user_id FROM falukant_data.director d JOIN falukant_data.falukant_user fu ON fu.id = d.employer_user_id WHERE d.id = $1 LIMIT 1;
|
|
||||||
"#;
|
|
||||||
|
|
||||||
pub const QUERY_COUNT_VEHICLES_IN_BRANCH_REGION: &str = r#"
|
pub const QUERY_COUNT_VEHICLES_IN_BRANCH_REGION: &str = r#"
|
||||||
SELECT COUNT(v.id) AS cnt FROM falukant_data.vehicle v WHERE v.falukant_user_id = $1 AND v.region_id = $2;
|
SELECT COUNT(v.id) AS cnt FROM falukant_data.vehicle v WHERE v.falukant_user_id = $1 AND v.region_id = $2;
|
||||||
"#;
|
"#;
|
||||||
|
|||||||
Reference in New Issue
Block a user