import java.sql.*;
|
|
/**
|
* Read-only probe: how the talent app derives the state of orders that left the payment flow
|
* (cancelled before payment, and refunded after payment). Mirrors the new CASE in
|
* UsageRecordPortalService plus the cancelSource/refundStatusText the order page computes.
|
*/
|
public class OrderStateProbe {
|
public static void main(String[] args) throws Exception {
|
String url = "jdbc:mysql://127.0.0.1:8134/talent_card?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&useSSL=false";
|
try (Connection connection = DriverManager.getConnection(url, "root", "123456")) {
|
query(connection, """
|
select o.order_no, o.order_status, o.verify_status, o.refund_status, o.pay_amount,
|
(select count(*) from order_refund r where r.order_id = o.id and r.deleted = 0) as refund_rows,
|
case
|
when o.order_status = 0 then 'pending_payment'
|
when o.order_status = 2 or o.refund_status <> 0 then 'cancelled'
|
when o.verify_status = 1 then 'completed'
|
else 'pending_verification'
|
end as list_status,
|
case when o.refund_status = 0 then '订单取消' else '退款处理' end as cancel_source,
|
case o.refund_status when 1 then '退款中' when 2 then '退款成功' when 3 then '退款失败' else '无需退款' end as refund_text
|
from benefit_order o
|
where o.deleted = 0 and (o.order_status = 2 or o.refund_status <> 0)
|
order by o.id desc limit 12
|
""", "== 已取消 / 已退款订单:列表状态与订单页文案 ==");
|
}
|
}
|
|
private static void query(Connection connection, String sql, String title) throws SQLException {
|
System.out.println();
|
System.out.println(title);
|
try (Statement statement = connection.createStatement(); ResultSet rows = statement.executeQuery(sql)) {
|
ResultSetMetaData meta = rows.getMetaData();
|
int columns = meta.getColumnCount();
|
StringBuilder header = new StringBuilder();
|
for (int index = 1; index <= columns; index++) header.append(meta.getColumnLabel(index)).append(" | ");
|
System.out.println(header);
|
while (rows.next()) {
|
StringBuilder line = new StringBuilder();
|
for (int index = 1; index <= columns; index++) {
|
Object value = rows.getObject(index);
|
line.append(value == null ? "NULL" : String.valueOf(value)).append(" | ");
|
}
|
System.out.println(line);
|
}
|
}
|
}
|
}
|