const { Client } = require('pg'); const fs = require('fs'); const path = require('path'); const client = new Client({ host: '192.168.110.252', port: 15432, database: 'postgresql', user: 'postgresql', password: 'Jchl1528', }); async function main() { await client.connect(); await client.query('SET search_path TO healthlink_his'); // Get all dict types with their labels const res = await client.query( "SELECT dict_type, dict_label, dict_value FROM sys_dict_data WHERE status = '0' ORDER BY dict_type, dict_sort" ); // Group by dict_type const grouped = {}; for (const row of res.rows) { if (!grouped[row.dict_type]) grouped[row.dict_type] = []; grouped[row.dict_type].push({ label: row.dict_label, value: row.dict_value }); } // Output as JSON const output = {}; for (const [type, items] of Object.entries(grouped)) { output[type] = items; } fs.writeFileSync(path.join(__dirname, 'dict_data.json'), JSON.stringify(output, null, 2), 'utf8'); console.log('Total dict types:', Object.keys(grouped).length); console.log('Total dict entries:', res.rows.length); console.log('\nDict types:'); for (const [type, items] of Object.entries(grouped)) { console.log(` ${type}: ${items.length} items - ${items.map(i => i.label).join(', ')}`); } await client.end(); } main().catch(e => { console.error(e.message); process.exit(1); });