来源仓库: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 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
108 lines
3.3 KiB
JavaScript
108 lines
3.3 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] || 'ORD_MP_1783329222231XQ2O';
|
|
const pool = new pg.Pool({ connectionString: url });
|
|
|
|
try {
|
|
const items = await pool.query(
|
|
`SELECT oi.id, oi.item_name, oi.sku_code, oi.quantity, oi.supplier_code, oi.category_code, oi.item_status
|
|
FROM order_items oi WHERE oi.order_code = $1 ORDER BY oi.sort_order NULLS LAST, oi.id`,
|
|
[code]
|
|
);
|
|
console.log('订单行数:', items.rowCount);
|
|
|
|
const inspected = await pool.query(
|
|
`SELECT id, item_name, sku_code, inspection_time, compliance_status, inbound_batch_no
|
|
FROM inspections WHERE order_code = $1 ORDER BY id`,
|
|
[code]
|
|
);
|
|
const doneInsp = inspected.rows.filter((r) => r.inspection_time);
|
|
console.log('验收记录:', inspected.rowCount, '已验:', doneInsp.length);
|
|
|
|
const preps = await pool.query(
|
|
`SELECT id, item_name, sku_code, supplier_code, prepare_status, prepare_qty
|
|
FROM supplier_preparations WHERE order_code = $1 ORDER BY id`,
|
|
[code]
|
|
);
|
|
console.log('供应商备货:', preps.rowCount);
|
|
|
|
const pos = await pool.query(
|
|
`SELECT purchase_code, sku_code, supplier_code, purchaser_code, purchase_status, purchase_qty, source_id, remark
|
|
FROM purchase_orders WHERE order_code = $1 ORDER BY created_at`,
|
|
[code]
|
|
);
|
|
console.log('采购单:', pos.rowCount);
|
|
|
|
const pending = [];
|
|
for (const oi of items.rows) {
|
|
const insp = inspected.rows.find(
|
|
(i) =>
|
|
i.inspection_time &&
|
|
((i.sku_code && oi.sku_code && i.sku_code === oi.sku_code) ||
|
|
i.item_name?.trim() === oi.item_name?.trim())
|
|
);
|
|
if (insp) continue;
|
|
|
|
const prep = preps.rows.find(
|
|
(p) =>
|
|
(p.sku_code && oi.sku_code && p.sku_code === oi.sku_code) ||
|
|
p.item_name?.trim() === oi.item_name?.trim()
|
|
);
|
|
const po = pos.rows.find(
|
|
(p) =>
|
|
p.source_id === String(oi.id) ||
|
|
(p.sku_code && oi.sku_code && p.sku_code === oi.sku_code) ||
|
|
p.sku_name?.trim() === oi.item_name?.trim()
|
|
);
|
|
|
|
pending.push({
|
|
name: oi.item_name,
|
|
sku: oi.sku_code,
|
|
qty: oi.quantity,
|
|
oi_supplier: oi.supplier_code,
|
|
category: oi.category_code,
|
|
item_status: oi.item_status,
|
|
prep: prep
|
|
? {
|
|
supplier: prep.supplier_code,
|
|
prepare_status: prep.prepare_status,
|
|
}
|
|
: null,
|
|
purchase: po
|
|
? {
|
|
code: po.purchase_code,
|
|
supplier: po.supplier_code,
|
|
purchaser: po.purchaser_code,
|
|
status: po.purchase_status,
|
|
remark: po.remark,
|
|
}
|
|
: null,
|
|
});
|
|
}
|
|
|
|
console.log('\n=== 未验收商品', pending.length, '===');
|
|
pending.forEach((p) => console.log(JSON.stringify(p)));
|
|
|
|
const stuckPrep = preps.rows.filter((p) => {
|
|
const ps = p.prepare_status;
|
|
return ps != null && Number(ps) < 30;
|
|
});
|
|
console.log('\n备货未完成(<30):', stuckPrep.length);
|
|
stuckPrep.slice(0, 20).forEach((p) =>
|
|
console.log(
|
|
JSON.stringify({
|
|
name: p.item_name,
|
|
sku: p.sku_code,
|
|
supplier: p.supplier_code,
|
|
prepare_status: p.prepare_status,
|
|
})
|
|
)
|
|
);
|
|
} finally {
|
|
await pool.end();
|
|
}
|