来源仓库:jxc/ai-fresh-delivery 来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d 快照树: 09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件) 按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据 (生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、 deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
93 lines
3.4 KiB
JavaScript
93 lines
3.4 KiB
JavaScript
#!/usr/bin/env node
|
|
import pg from 'pg';
|
|
import { readFileSync } from 'fs';
|
|
|
|
const env = readFileSync('/opt/ai-fresh-delivery/server/.env', 'utf8');
|
|
const url = env.match(/^DATABASE_URL=(.+)$/m)[1].trim().replace(/^["']|["']$/g, '');
|
|
const code = process.argv[2];
|
|
if (!code) {
|
|
console.error('Usage: prod-order-diagnose.mjs <order_code>');
|
|
process.exit(1);
|
|
}
|
|
|
|
const pool = new pg.Pool({ connectionString: url });
|
|
|
|
try {
|
|
const order = await pool.query(
|
|
`SELECT order_code, order_status, branch_code, customer_code, delivery_date, created_at, updated_at, total_amount, remark
|
|
FROM orders WHERE order_code = $1`,
|
|
[code]
|
|
);
|
|
if (!order.rowCount) {
|
|
console.log('ORDER NOT FOUND:', code);
|
|
process.exit(0);
|
|
}
|
|
console.log('=== ORDER ===');
|
|
console.log(JSON.stringify(order.rows[0], null, 2));
|
|
|
|
const items = await pool.query(
|
|
`SELECT id, sku_code, item_name, quantity, supplier_code, item_status, price FROM order_items WHERE order_code = $1 ORDER BY sort_order`,
|
|
[code]
|
|
);
|
|
console.log('\n=== ORDER ITEMS ===', items.rowCount);
|
|
items.rows.forEach((r) => console.log(JSON.stringify(r)));
|
|
|
|
const preps = await pool.query(
|
|
`SELECT id, sku_code, item_name, prepare_status, is_stockout, transferred_to_purchase, supplier_code, prepare_qty
|
|
FROM supplier_preparations WHERE order_code = $1`,
|
|
[code]
|
|
);
|
|
console.log('\n=== PREPARATIONS ===', preps.rowCount);
|
|
preps.rows.forEach((r) => console.log(JSON.stringify(r)));
|
|
|
|
const purchases = await pool.query(
|
|
`SELECT purchase_code, sku_code, purchase_status, purchase_qty, actual_qty, actual_price, purchaser_code, remark
|
|
FROM purchase_orders WHERE order_code = $1`,
|
|
[code]
|
|
);
|
|
console.log('\n=== PURCHASE ORDERS ===', purchases.rowCount);
|
|
purchases.rows.forEach((r) => console.log(JSON.stringify(r)));
|
|
|
|
const inspections = await pool.query(
|
|
`SELECT id, sku_code, item_name, source_type, prepare_qty, actual_qty, quality_rating, inspection_time,
|
|
compliance_status, inbound_batch_no, created_at
|
|
FROM inspections WHERE order_code = $1 ORDER BY created_at`,
|
|
[code]
|
|
);
|
|
console.log('\n=== INSPECTIONS ===', inspections.rowCount);
|
|
inspections.rows.forEach((r) => console.log(JSON.stringify(r)));
|
|
|
|
const pendingWarehouse = await pool.query(
|
|
`SELECT id, sku_code, item_name, source_type, prepare_qty, created_at
|
|
FROM inspections
|
|
WHERE order_code = $1
|
|
AND inspection_time IS NULL
|
|
AND COALESCE(quality_rating, '') = ''
|
|
AND COALESCE(actual_qty, 0) = 0`,
|
|
[code]
|
|
);
|
|
console.log('\n=== PENDING WAREHOUSE TASKS ===', pendingWarehouse.rowCount);
|
|
pendingWarehouse.rows.forEach((r) => console.log(JSON.stringify(r)));
|
|
|
|
const pendingPreps = await pool.query(
|
|
`SELECT COUNT(*)::int AS cnt FROM supplier_preparations
|
|
WHERE order_code = $1
|
|
AND COALESCE(is_stockout, false) = false
|
|
AND COALESCE(transferred_to_purchase, false) = false
|
|
AND COALESCE(prepare_status, 10) < 30`,
|
|
[code]
|
|
);
|
|
const pendingPurchases = await pool.query(
|
|
`SELECT COUNT(*)::int AS cnt FROM purchase_orders
|
|
WHERE order_code = $1
|
|
AND COALESCE(purchase_status, 10) IN (10, 32)`,
|
|
[code]
|
|
);
|
|
console.log('\n=== FULFILLMENT BLOCKERS ===');
|
|
console.log('pending_preps:', pendingPreps.rows[0]?.cnt);
|
|
console.log('pending_purchases:', pendingPurchases.rows[0]?.cnt);
|
|
console.log('order_status:', order.rows[0].order_status, '(40=待验收)');
|
|
} finally {
|
|
await pool.end();
|
|
}
|