来源仓库: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 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
73 lines
2.7 KiB
JavaScript
73 lines
2.7 KiB
JavaScript
#!/usr/bin/env node
|
|
const fs = require('fs');
|
|
const pg = require('pg');
|
|
const env = fs.readFileSync('/opt/ai-fresh-delivery/server/.env', 'utf8');
|
|
const url = env.match(/^DATABASE_URL=(.+)$/m)[1].trim().replace(/^["']|["']$/g, '');
|
|
const pool = new pg.Pool({ connectionString: url });
|
|
|
|
(async () => {
|
|
// product_catalog categories for BR002 with status
|
|
const pc = await pool.query(
|
|
`SELECT code, name, parent_code, level, status, sort_order
|
|
FROM product_catalog
|
|
WHERE item_type='category' AND branch_code='BR002'
|
|
ORDER BY sort_order NULLS LAST, name`
|
|
);
|
|
console.log('PC_CATS', JSON.stringify(pc.rows, null, 2));
|
|
|
|
// How many children?
|
|
const children = await pool.query(
|
|
`SELECT COUNT(*)::int AS child_cats
|
|
FROM product_catalog
|
|
WHERE item_type='category' AND branch_code='BR002' AND parent_code IS NOT NULL`
|
|
);
|
|
console.log('CHILD_CATS', children.rows[0]);
|
|
|
|
// BR001 categories?
|
|
const br001 = await pool.query(
|
|
`SELECT COUNT(*)::int AS n FROM product_catalog WHERE item_type='category' AND branch_code='BR001'`
|
|
);
|
|
console.log('BR001_CATS', br001.rows[0]);
|
|
|
|
// disabled / status 0
|
|
const disabled = await pool.query(
|
|
`SELECT code, name, status FROM product_catalog
|
|
WHERE item_type='category' AND branch_code='BR002' AND COALESCE(status,1) <> 1`
|
|
);
|
|
console.log('DISABLED', JSON.stringify(disabled.rows, null, 2));
|
|
|
|
// skus pointing to 蔬菜 old vs new
|
|
const veg = await pool.query(
|
|
`SELECT category_code, COUNT(*)::int AS n FROM skus WHERE branch_code='BR002'
|
|
AND (category_code ILIKE '%蔬菜%' OR category_code ILIKE '%VEG%' OR category_name ILIKE '%蔬菜%')
|
|
GROUP BY category_code`
|
|
).catch(() => ({ rows: [] }));
|
|
// skus may not have category_name
|
|
const veg2 = await pool.query(
|
|
`SELECT s.category_code, COUNT(*)::int AS n,
|
|
MAX(c.category_name) AS cat_name
|
|
FROM skus s
|
|
LEFT JOIN categories c ON c.category_code = s.category_code AND c.branch_code = s.branch_code
|
|
WHERE s.branch_code='BR002'
|
|
GROUP BY s.category_code
|
|
ORDER BY n DESC`
|
|
);
|
|
console.log('SKU_BY_CAT', JSON.stringify(veg2.rows, null, 2));
|
|
|
|
// recent category deletes in audit?
|
|
const audit = await pool.query(
|
|
`SELECT operation_type, target_table, target_id, created_at, operator_name
|
|
FROM operation_logs
|
|
WHERE (target_table ILIKE '%categor%' OR operation_type ILIKE '%categor%' OR operation_type ILIKE '%catalog%')
|
|
AND created_at > NOW() - INTERVAL '10 days'
|
|
ORDER BY created_at DESC
|
|
LIMIT 30`
|
|
).catch((e) => ({ rows: [{ error: e.message }] }));
|
|
console.log('AUDIT', JSON.stringify(audit.rows, null, 2));
|
|
|
|
await pool.end();
|
|
})().catch((e) => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
});
|