-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVerifyDetailedOrders.java
More file actions
61 lines (50 loc) · 2.77 KB
/
Copy pathVerifyDetailedOrders.java
File metadata and controls
61 lines (50 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import java.sql.*;
import java.math.BigDecimal;
public class VerifyDetailedOrders {
public static void main(String[] args) throws Exception {
String url = "jdbc:mariadb://beyond21.iptime.org:7001/chaing";
String user = "root";
String pass = "root";
Class.forName("org.mariadb.jdbc.Driver");
try (Connection conn = DriverManager.getConnection(url, user, pass)) {
String dateStr = "2026-03-13";
System.out.println("=== Verifying Detailed Order Aggregation for " + dateStr + " ===");
// 1. Find all order IDs for the date
String orderSql = "SELECT franchise_order_id, order_code, order_status FROM franchise_order " +
"WHERE franchise_id = 1 AND CAST(created_at AS DATE) = ?";
BigDecimal totalOrderAmount = BigDecimal.ZERO;
int orderCount = 0;
int totalItemCount = 0;
try (PreparedStatement stmt = conn.prepareStatement(orderSql)) {
stmt.setString(1, dateStr);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
long orderId = rs.getLong("franchise_order_id");
String code = rs.getString("order_code");
String status = rs.getString("order_status");
orderCount++;
System.out.println("\n[Order: " + code + "] Status: " + status);
// 2. Fetch items for this specific order
String itemSql = "SELECT product_id, unit_price, quantity, total_price FROM franchise_order_item " +
"WHERE franchise_order_id = ? AND deleted_at IS NULL";
try (PreparedStatement itemStmt = conn.prepareStatement(itemSql)) {
itemStmt.setLong(1, orderId);
ResultSet itemRs = itemStmt.executeQuery();
while (itemRs.next()) {
BigDecimal itemTotal = itemRs.getBigDecimal("total_price");
long productId = itemRs.getLong("product_id");
int qty = itemRs.getInt("quantity");
System.out.printf(" - Product ID: %d (Qty: %d) | Total: %s%n", productId, qty, itemTotal);
totalOrderAmount = totalOrderAmount.add(itemTotal);
totalItemCount++;
}
}
}
}
System.out.println("\n--- Aggregation Summary ---");
System.out.println("Total Orders: " + orderCount);
System.out.println("Total Items Collected: " + totalItemCount);
System.out.println("Calculated Daily Order Amount: " + totalOrderAmount);
}
}
}