Files
api-debug/server/init_admin_endpoints.js

70 lines
2.3 KiB
JavaScript

require('dotenv').config();
const pool = require('./db');
async function initAdminEndpoints() {
try {
console.log('开始为 admin 账号初始化接口...\n');
// 模块名称到分类的映射
const moduleToCategory = {
'组织接口API': '组织接口',
'职位职务接口API': '职位职务接口',
'人事接口API': '人事接口',
'假勤接口API': '假勤接口',
'薪酬接口API': '薪酬接口',
'绩效接口API': '绩效接口'
};
// 查询所有模板接口
const [templates] = await pool.query(
'SELECT * FROM endpoint_templates ORDER BY module, id'
);
console.log(`共找到 ${templates.length} 条模板接口\n`);
let successCount = 0;
let errorCount = 0;
for (const template of templates) {
try {
const category = moduleToCategory[template.module] || template.module;
await pool.query(
`INSERT INTO endpoints
(user_id, name, category, module, api_code, user_name, url, method, body, description)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
[
'admin',
template.name,
'标品PP', // 接口类型固定为标品PP
category, // 使用映射后的分类
template.api_code,
template.user_name,
template.url,
template.method,
template.body,
template.description
]
);
successCount++;
console.log(`✓ [${category}] ${template.name}`);
} catch (err) {
errorCount++;
console.error(`✗ 导入失败: ${template.name}`, err.message);
}
}
console.log('\n========== 初始化完成 ==========');
console.log(`成功: ${successCount}`);
console.log(`失败: ${errorCount}`);
process.exit(0);
} catch (error) {
console.error('初始化失败:', error);
process.exit(1);
}
}
initAdminEndpoints();