Add SQL query for product price history: Introduced a new query to insert regional product prices into the history table, calculating prices based on sell cost and worth percentage. Updated ValueRecalculationWorker to log current prices for affected regions, enhancing price tracking functionality.
This commit is contained in:
@@ -14,6 +14,7 @@ use crate::worker::sql::{
|
||||
QUERY_DELETE_REGION_SELL_PRICE,
|
||||
QUERY_GET_SELL_REGIONS,
|
||||
QUERY_HOURLY_PRICE_RECALCULATION,
|
||||
QUERY_INSERT_PRODUCT_PRICE_HISTORY,
|
||||
QUERY_SET_MARRIAGES_BY_PARTY,
|
||||
QUERY_GET_STUDYINGS_TO_EXECUTE,
|
||||
QUERY_GET_OWN_CHARACTER_ID,
|
||||
@@ -139,11 +140,17 @@ impl ValueRecalculationWorker {
|
||||
conn.prepare("update_region_sell_price", QUERY_UPDATE_REGION_SELL_PRICE)?;
|
||||
conn.execute("update_region_sell_price", &[])?;
|
||||
|
||||
// Preis-Historie für betroffene Regionen erfassen
|
||||
conn.prepare("insert_price_history", QUERY_INSERT_PRODUCT_PRICE_HISTORY)?;
|
||||
|
||||
conn.prepare("get_sell_regions", QUERY_GET_SELL_REGIONS)?;
|
||||
let regions = conn.execute("get_sell_regions", &[])?;
|
||||
|
||||
for row in regions {
|
||||
if let Some(region_id) = row.get("region_id").and_then(|v| v.parse::<i32>().ok()) {
|
||||
// Aktuelle Preise dieser Region in die Historie schreiben
|
||||
let _ = conn.execute("insert_price_history", &[®ion_id]);
|
||||
|
||||
let message =
|
||||
format!(r#"{{"event":"price_update","region_id":{}}}"#, region_id);
|
||||
broker.publish(message);
|
||||
@@ -167,6 +174,9 @@ impl ValueRecalculationWorker {
|
||||
conn.prepare("hourly_price_recalculation", QUERY_HOURLY_PRICE_RECALCULATION)?;
|
||||
let _updated_rows = conn.execute("hourly_price_recalculation", &[])?;
|
||||
|
||||
// Prepared Statement für Preis-Historie
|
||||
conn.prepare("insert_price_history", QUERY_INSERT_PRODUCT_PRICE_HISTORY)?;
|
||||
|
||||
// Sammle alle betroffenen Regionen für Event-Benachrichtigungen
|
||||
let mut affected_regions = HashSet::new();
|
||||
|
||||
@@ -191,6 +201,9 @@ impl ValueRecalculationWorker {
|
||||
|
||||
// Benachrichtige alle betroffenen Regionen über Preisänderungen
|
||||
for region_id in affected_regions {
|
||||
// aktuellen Preisstand in die Historie schreiben
|
||||
let _ = conn.execute("insert_price_history", &[®ion_id]);
|
||||
|
||||
let message =
|
||||
format!(r#"{{"event":"price_update","region_id":{}}}"#, region_id);
|
||||
broker.publish(message);
|
||||
|
||||
Reference in New Issue
Block a user