From 7300af9073f60478fdc9318281a39541ced4399e Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 22 Apr 2024 15:49:57 -0400 Subject: [PATCH] Method to load workorders on bootstrap --- src/engine/db/handlers/dbWarehouseHandler.java | 13 ++++++++++--- src/engine/loot/WorkOrder.java | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/engine/db/handlers/dbWarehouseHandler.java b/src/engine/db/handlers/dbWarehouseHandler.java index 139303e8..49ec1e8b 100644 --- a/src/engine/db/handlers/dbWarehouseHandler.java +++ b/src/engine/db/handlers/dbWarehouseHandler.java @@ -186,20 +186,27 @@ public class dbWarehouseHandler extends dbHandlerBase { public void LOAD_WORKORDERS() { - ArrayList deleteList = new ArrayList<>(); + ArrayList submitList = new ArrayList<>(); try (Connection connection = DbManager.getConnection(); PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `dyn_workorders`;"); ResultSet rs = preparedStatement.executeQuery()) { while (rs.next()) { - int workOrderID = rs.getInt("workOrderID"); JSONObject jsonObject = new JSONObject(rs.getString("workorder")); WorkOrder workOrder = new WorkOrder(jsonObject); - deleteList.add(workOrder); + submitList.add(workOrder); } } catch (Exception e) { Logger.error(e); } + + // Delete the old records + + for (WorkOrder workOrder : submitList) + DbManager.WarehouseQueries.DELETE_WORKORDER(workOrder); + + // Pass the new workOrders to the ForgeManager + } } diff --git a/src/engine/loot/WorkOrder.java b/src/engine/loot/WorkOrder.java index bc2a0dfd..f1fc288f 100644 --- a/src/engine/loot/WorkOrder.java +++ b/src/engine/loot/WorkOrder.java @@ -49,6 +49,7 @@ public class WorkOrder implements Delayed { public WorkOrder(JSONObject jsonWorkOrder) { + this.workOrderID = jsonWorkOrder.getInt("workOrderID"); this.vendor = NPC.getNPC(jsonWorkOrder.getInt("vendor")); this.slots_used = jsonWorkOrder.getInt("slots_used"); this.total_to_produce = jsonWorkOrder.getInt("total_to_produce");