73 lines
2.0 KiB
JavaScript
73 lines
2.0 KiB
JavaScript
const { Pool } = require('pg');
|
|
const pool = new Pool({
|
|
host: '47.116.196.11',
|
|
port: 15432,
|
|
database: 'postgresql',
|
|
user: 'postgresql',
|
|
password: 'Jchl1528'
|
|
});
|
|
|
|
async function checkIdMatch() {
|
|
try {
|
|
// 1. 检查 op_schedule 中的 apply_id
|
|
console.log('=== 手术安排中的 apply_id ===');
|
|
const scheduleResult = await pool.query(`
|
|
SELECT DISTINCT apply_id
|
|
FROM hisdev.op_schedule
|
|
WHERE delete_flag = '0'
|
|
ORDER BY apply_id DESC
|
|
LIMIT 10
|
|
`);
|
|
console.log('apply_id 列表:', scheduleResult.rows.map(r => r.apply_id));
|
|
|
|
// 2. 检查 cli_surgery 中存在的 id
|
|
console.log('\n=== 手术申请中的 id ===');
|
|
const surgeryResult = await pool.query(`
|
|
SELECT id, surgery_no
|
|
FROM hisdev.cli_surgery
|
|
WHERE delete_flag = '0'
|
|
ORDER BY create_time DESC
|
|
LIMIT 10
|
|
`);
|
|
console.table(surgeryResult.rows);
|
|
|
|
// 3. 检查 ID 类型
|
|
console.log('\n=== 检查 ID 字段类型 ===');
|
|
const typeResult = await pool.query(`
|
|
SELECT
|
|
column_name,
|
|
data_type,
|
|
character_maximum_length
|
|
FROM information_schema.columns
|
|
WHERE table_schema = 'hisdev'
|
|
AND table_name IN ('op_schedule', 'cli_surgery')
|
|
AND column_name IN ('id', 'apply_id')
|
|
ORDER BY table_name, column_name
|
|
`);
|
|
console.table(typeResult.rows);
|
|
|
|
// 4. 尝试匹配
|
|
console.log('\n=== 尝试匹配 ===');
|
|
const matchResult = await pool.query(`
|
|
SELECT
|
|
os.schedule_id,
|
|
os.apply_id,
|
|
cs.id as surgery_id,
|
|
CASE WHEN cs.id IS NULL THEN '未找到' ELSE '已找到' END as match_status
|
|
FROM hisdev.op_schedule os
|
|
LEFT JOIN hisdev.cli_surgery cs ON os.apply_id = cs.id
|
|
WHERE os.delete_flag = '0'
|
|
ORDER BY os.create_time DESC
|
|
LIMIT 5
|
|
`);
|
|
console.table(matchResult.rows);
|
|
|
|
} catch (err) {
|
|
console.error('查询失败:', err.message);
|
|
} finally {
|
|
pool.end();
|
|
}
|
|
}
|
|
|
|
checkIdMatch();
|