来源仓库: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 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
97 lines
2.7 KiB
JavaScript
97 lines
2.7 KiB
JavaScript
const { Pool } = require('pg');
|
|
const fs = require('fs');
|
|
|
|
(async () => {
|
|
const env = fs.readFileSync('/opt/ai-fresh-delivery/server/.env', 'utf8');
|
|
const m = env.match(/^DATABASE_URL=(.+)$/m);
|
|
const pool = new Pool({
|
|
connectionString: m[1].trim().replace(/^["']|["']$/g, ''),
|
|
});
|
|
await pool.query(`SELECT set_config('search_path', 'tenant_br002, public', false)`);
|
|
|
|
const orderCode = 'ORD_MP_1785227388534RMSP';
|
|
|
|
const cols = await pool.query(
|
|
`SELECT column_name FROM information_schema.columns
|
|
WHERE table_schema = current_schema() AND table_name = 'purchase_orders'
|
|
ORDER BY 1`
|
|
);
|
|
console.log(
|
|
'PO_COLS',
|
|
cols.rows.map((r) => r.column_name)
|
|
);
|
|
|
|
const pos = await pool.query(
|
|
`SELECT * FROM purchase_orders WHERE order_code = $1 ORDER BY created_at`,
|
|
[orderCode]
|
|
);
|
|
console.log(
|
|
'POS',
|
|
pos.rows.map((r) => ({
|
|
purchase_code: r.purchase_code,
|
|
sku_code: r.sku_code,
|
|
purchase_status: r.purchase_status,
|
|
purchase_qty: r.purchase_qty,
|
|
purchase_price: r.purchase_price,
|
|
created_at: r.created_at,
|
|
remark: r.remark,
|
|
}))
|
|
);
|
|
|
|
const insps = await pool.query(
|
|
`SELECT id, sku_code, item_name, supplier_code, prepare_qty, purchase_price, source_type,
|
|
inspection_time, inbound_batch_no, compliance_status, created_at
|
|
FROM inspections WHERE order_code = $1 ORDER BY created_at`,
|
|
[orderCode]
|
|
);
|
|
console.log(
|
|
'INSPS',
|
|
insps.rows.map((r) => ({
|
|
item: r.item_name,
|
|
sku: r.sku_code,
|
|
supplier: r.supplier_code,
|
|
source: r.source_type,
|
|
qty: r.prepare_qty,
|
|
price: r.purchase_price,
|
|
insp_time: r.inspection_time,
|
|
batch: r.inbound_batch_no,
|
|
status: r.compliance_status,
|
|
created: r.created_at,
|
|
}))
|
|
);
|
|
|
|
// focus on the 4 pending names
|
|
const names = ['丝瓜', '青条椒', '小葱', '香菜'];
|
|
for (const name of names) {
|
|
const oi = await pool.query(
|
|
`SELECT id, sku_code, supplier_code, quantity, stock_cover_qty FROM order_items
|
|
WHERE order_code = $1 AND item_name = $2`,
|
|
[orderCode, name]
|
|
);
|
|
const po = await pool.query(
|
|
`SELECT purchase_code, sku_code, purchase_status, created_at, submitted_at, reviewed_at
|
|
FROM purchase_orders WHERE order_code = $1 AND sku_code = $2`,
|
|
[orderCode, oi.rows[0]?.sku_code]
|
|
);
|
|
const sp = await pool.query(
|
|
`SELECT id, prepare_status, prepare_time FROM supplier_preparations
|
|
WHERE order_code = $1 AND sku_code = $2`,
|
|
[orderCode, oi.rows[0]?.sku_code]
|
|
);
|
|
console.log(
|
|
'LINE',
|
|
name,
|
|
JSON.stringify({
|
|
item: oi.rows[0],
|
|
purchase: po.rows,
|
|
prep: sp.rows,
|
|
})
|
|
);
|
|
}
|
|
|
|
await pool.end();
|
|
})().catch((e) => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
});
|