2025-10-22 14:08:03 +08:00
|
|
|
const express = require('express');
|
|
|
|
|
const { executePricingQuery, executeSecondaryProcessQuery, executePricingDetailsQuery, getTableStats } = require('../controllers/queryController');
|
|
|
|
|
const { testConnection } = require('../config/database');
|
|
|
|
|
|
|
|
|
|
const router = express.Router();
|
|
|
|
|
|
|
|
|
|
// 数据库连接测试
|
|
|
|
|
router.get('/test-db', async (req, res) => {
|
2025-10-23 09:52:24 +08:00
|
|
|
// try {
|
2025-10-22 14:08:03 +08:00
|
|
|
const isConnected = await testConnection();
|
|
|
|
|
res.json({
|
|
|
|
|
success: isConnected,
|
|
|
|
|
message: isConnected ? '数据库连接正常' : '数据库连接失败'
|
|
|
|
|
});
|
2025-10-23 09:52:24 +08:00
|
|
|
// } catch (error) {
|
|
|
|
|
// res.status(500).json({
|
|
|
|
|
// success: false,
|
|
|
|
|
// message: '数据库连接测试失败',
|
|
|
|
|
// error: error.message
|
|
|
|
|
// });
|
|
|
|
|
// }
|
2025-10-22 14:08:03 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 执行定价查询
|
|
|
|
|
router.post('/query/pricing', executePricingQuery);
|
|
|
|
|
|
|
|
|
|
// 执行二次工艺查询
|
|
|
|
|
router.post('/query/secondary-process', executeSecondaryProcessQuery);
|
|
|
|
|
|
|
|
|
|
// 执行定价详情查询
|
|
|
|
|
router.post('/query/pricing-details', executePricingDetailsQuery);
|
|
|
|
|
|
|
|
|
|
// 获取数据表统计
|
|
|
|
|
router.get('/stats/tables', getTableStats);
|
|
|
|
|
|
|
|
|
|
// API信息
|
|
|
|
|
router.get('/info', (req, res) => {
|
|
|
|
|
res.json({
|
|
|
|
|
success: true,
|
|
|
|
|
message: 'React Template Backend API',
|
|
|
|
|
version: '1.0.0',
|
|
|
|
|
endpoints: {
|
|
|
|
|
'POST /api/query/pricing': '执行定价查询',
|
|
|
|
|
'POST /api/query/secondary-process': '执行二次工艺查询',
|
|
|
|
|
'POST /api/query/pricing-details': '执行定价详情查询',
|
|
|
|
|
'GET /api/stats/tables': '获取数据表统计',
|
|
|
|
|
'GET /api/test-db': '测试数据库连接',
|
|
|
|
|
'GET /api/info': '获取API信息'
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
module.exports = router;
|