2025-04-28 12:25:20 +08:00
|
|
|
|
const express = require('express');
|
|
|
|
|
const router = express.Router();
|
|
|
|
|
const {
|
|
|
|
|
getATAChapters,
|
|
|
|
|
getModelsByChapterId,
|
|
|
|
|
getModelVersionsByClassName,
|
|
|
|
|
saveModelVersion
|
|
|
|
|
} = require('../utils/db-utils');
|
|
|
|
|
|
|
|
|
|
// 获取所有ATA章节
|
|
|
|
|
router.get('/ata-chapters', (req, res) => {
|
|
|
|
|
try {
|
|
|
|
|
const chapters = getATAChapters();
|
|
|
|
|
res.json(chapters);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('处理ATA章节请求时出错:', error);
|
|
|
|
|
res.status(500).json({ error: '获取ATA章节数据失败', details: error.message });
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 获取指定章节ID的模型
|
|
|
|
|
router.get('/chapter-models/:chapterId', (req, res) => {
|
|
|
|
|
try {
|
|
|
|
|
const { chapterId } = req.params;
|
2025-04-30 13:47:35 +08:00
|
|
|
|
const { productName } = req.query;
|
2025-04-28 12:25:20 +08:00
|
|
|
|
|
|
|
|
|
if (!chapterId) {
|
|
|
|
|
return res.status(400).json({ error: '缺少章节ID参数' });
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-30 13:47:35 +08:00
|
|
|
|
const models = getModelsByChapterId(chapterId, productName);
|
2025-04-28 12:25:20 +08:00
|
|
|
|
res.json(models);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('处理章节模型请求时出错:', error);
|
|
|
|
|
res.status(500).json({ error: '获取章节模型数据失败', details: error.message });
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 获取指定ClassName的模型版本
|
|
|
|
|
router.get('/model-versions/:className', (req, res) => {
|
|
|
|
|
try {
|
|
|
|
|
const className = req.params.className;
|
2025-04-30 13:47:35 +08:00
|
|
|
|
const { productName } = req.query;
|
|
|
|
|
|
2025-04-28 12:25:20 +08:00
|
|
|
|
if (!className) {
|
|
|
|
|
return res.status(400).json({ error: '模型类名不能为空' });
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-30 13:47:35 +08:00
|
|
|
|
const versions = getModelVersionsByClassName(className, productName);
|
2025-04-28 12:25:20 +08:00
|
|
|
|
res.json(versions);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(`获取模型版本失败: ${error.message}`);
|
|
|
|
|
res.status(500).json({ error: '获取模型版本失败', details: error.message });
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 保存模型版本信息
|
|
|
|
|
router.post('/model-versions', (req, res) => {
|
|
|
|
|
try {
|
|
|
|
|
const versionData = req.body;
|
2025-04-30 13:47:35 +08:00
|
|
|
|
const { productName } = req.query;
|
2025-04-28 12:25:20 +08:00
|
|
|
|
|
|
|
|
|
if (!versionData || !versionData.ClassName) {
|
|
|
|
|
return res.status(400).json({ error: '缺少必要的模型版本数据' });
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-30 13:47:35 +08:00
|
|
|
|
// 如果请求中没有productName,则使用versionData中的ProductName
|
|
|
|
|
if (!productName && versionData.ProductName) {
|
|
|
|
|
versionData.ProductName = versionData.ProductName;
|
|
|
|
|
} else if (productName) {
|
|
|
|
|
versionData.ProductName = productName;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-28 12:25:20 +08:00
|
|
|
|
const result = saveModelVersion(versionData);
|
|
|
|
|
res.json(result);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error(`保存模型版本失败: ${error.message}`);
|
|
|
|
|
res.status(500).json({ error: '保存模型版本失败', details: error.message });
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
module.exports = router;
|