来源仓库: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 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
60 lines
2.2 KiB
JavaScript
60 lines
2.2 KiB
JavaScript
#!/usr/bin/env node
|
|
/** 只读:列出分公司及各表 branch_code 分布 */
|
|
import pg from 'pg';
|
|
import dotenv from 'dotenv';
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
dotenv.config({ path: path.join(__dirname, '..', '.env') });
|
|
|
|
const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL });
|
|
|
|
const BRANCH_TABLES = [
|
|
'customers', 'suppliers', 'orders', 'purchase_orders', 'supplier_preparations',
|
|
'delivery_tasks', 'inventory', 'customer_statements', 'supplier_statements',
|
|
'profiles', 'categories', 'warehouses', 'delivery_persons', 'inspections',
|
|
'picking_tasks', 'system_configs', 'after_sales', 'exception_tickets', 'invoices',
|
|
'customer_delivery_assignments', 'processing_tasks', 'cost_details',
|
|
];
|
|
|
|
async function main() {
|
|
const branches = (
|
|
await pool.query(`SELECT branch_code, branch_name, contact_name, contact_phone, status FROM branches ORDER BY branch_code`)
|
|
).rows;
|
|
console.log('=== BRANCHES ===');
|
|
console.log(JSON.stringify(branches, null, 2));
|
|
|
|
console.log('\n=== COUNTS BY branch_code ===');
|
|
for (const table of BRANCH_TABLES) {
|
|
const exists = await pool.query(`SELECT to_regclass('public.' || $1) IS NOT NULL AS ok`, [table]);
|
|
if (!exists.rows[0]?.ok) continue;
|
|
const cols = await pool.query(
|
|
`SELECT column_name FROM information_schema.columns WHERE table_schema='public' AND table_name=$1 AND column_name='branch_code'`,
|
|
[table]
|
|
);
|
|
if (!cols.rowCount) continue;
|
|
const rows = (
|
|
await pool.query(`SELECT branch_code, count(*)::int AS c FROM ${table} GROUP BY branch_code ORDER BY branch_code`)
|
|
).rows;
|
|
if (rows.length) console.log(table, JSON.stringify(rows));
|
|
}
|
|
|
|
const users = (
|
|
await pool.query(
|
|
`SELECT p.username, p.full_name, p.branch_code, array_agg(ur.role::text) roles
|
|
FROM profiles p LEFT JOIN user_roles ur ON ur.user_id = p.id
|
|
GROUP BY p.id, p.username, p.full_name, p.branch_code ORDER BY p.branch_code NULLS FIRST, p.username`
|
|
)
|
|
).rows;
|
|
console.log('\n=== USERS ===');
|
|
console.log(JSON.stringify(users, null, 2));
|
|
|
|
await pool.end();
|
|
}
|
|
|
|
main().catch((e) => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
});
|