SCSAI PLM v50 Code Review Report and Optimization Completion Plan
Review Date: 2026-05-13
Review Scope: server/routes/aml.js, business-system.router.js, meta-model.router.js, frontend/app.js
Reviewer: SOLO
? Overall Assessment
| Dimension | Status | Description |
|---|---|---|
| Phase1-2 (TOC Reconstruction/Frontend Optimization) | ✅ Completed | 46 business systems, 442 object classes have been reconstructed |
| P0 BUG Fixes | ⚠️ Partially Completed | 1 of 3 P0 BUGs completed, 2 remain unfinished |
| P1 BUG Fixes | ⚠️ Partially Completed | 1 of 3 P1 BUGs completed, 2 remain unfinished |
| Phase3 (Template Auto-generation) | ❌ Not Implemented | Missing critical APIs and frontend UI |
| Phase4-6 | ❌ Not Implemented | Closed-loop mechanism, self-evolution, and business prompts are all unimplemented |
✅ Implemented Features
1. Phase1-2 Completed
- ✅ Business System Reconstruction API (/api/aml/business-systems/rebuild)
- ✅ 46 business systems + 442 object class associations
- ✅ Frontend business system layer table layout + search + filtering
- ✅ Object Class Detail Popup (Properties/Relationships/Methods/Lifecycle)
- ✅ Rule Template Editor (CRUD + Batch Operations)
2. Partial P0/P1 Fixes
- ✅ P0-BUG-1: Object Detail Business System Query Optimization
- Backend added /api/aml/business-system/by-item/:name API
- However, frontend still uses the old method (46 serial requests)
❌ Unimplemented Features (To Be Completed)
? P0 Priority (Must Fix)
#### P0-BUG-2: sciot_import.db Creates a New Connection on Every Request ❌
Location: server/routes/aml.js lines 335-341
Problematic code:
function getSciotDb() {
try {
return require('../sqlite-compat').createDatabase(path.join(__dirname, '..', 'data', 'sciot_import.db'));
} catch (e) {
return null;
}
}
影响: 每个API调用都创建新连接 + close(),性能极差
35 calls in the code, each creating a new connection
Fix:
// 改为单例模式
let _sciotDb = null;
function getSciotDb() {
if (!_sciotDb) {
_sciotDb = require('../sqlite-compat').createDatabase(
path.join(__dirname, '..', 'data', 'sciot_import.db')
);
}
return _sciotDb;
}
// 移除所有 sciotDb.close() 调用
#### P0-BUG-4: debug路由暴露SCSAI凭证 ❌
Location: server/routes/aml.js lines 2508-2553
Problematic code:
if (pathname === '/api/aml/debug-SCSAI' && req.method === 'POST') {
// ...
headers: {
'AUTHUSER': 'admin',
'AUTHPASSWORD': '607920b64fe136f9ab2389e371852af2', // 明文密码!
'DATABASE': 'SCPLM',
}
}
影响: 安全漏洞,SCSAI管理员密码硬编码在代码中
Fix: Delete these two debug routes (lines 2508-2553)
? P1 Priority (Recommended to fix)
#### P1-BUG-3: Duplicate definitions of Cache and DatabasePool classes ❌
Location:
- meta-model.router.js lines 38-164
- business-system.router.js lines 38-164
Problem: Both files contain identical copies of the Cache class (~50 lines) and DatabasePool class (~70 lines)
Fix: Extract to a shared utility file
server/utils/cache.js # Cache类
server/utils/db-pool.js # DatabasePool类
#### P1-BUG-6: is_core判断逻辑不合理 ❌
Location: business-system.router.js line 506
Problematic code:
const isCore = i < 10 ? 1 : 0; // 前10个算核心
问题: 对于只有5个对象的系统,全部是核心;对于144个对象的com系统,只有前10个是核心
Fix: Determine based on the is_core_business field from the sciot_item_types table
#### P1-BUG-1 Supplement: Frontend still uses the old query method ❌
Location: frontend/app.js lines 1468-1478
Problematic code:
for (const sys of systems) {
const detailRes = await fetch(`/api/aml/business-system/${sys.system_id}`); // 46次串行请求!
// ...
}
修复方案: 改用新API /api/aml/business-system/by-item/${itemTypeName}
? Phase3: Template Auto-generation (Not implemented at all)
#### 3.1 Missing Template Identification API ❌
Should implement: GET /api/aml/missing-templates
Function: Returns a list of object classes that have attributes/methods/relationships but lack templates
Implementation code:
function getMissingTemplates() {
const sciotDb = getSciotDb();
const missing = sciotDb.prepare(`
SELECT it.item_type_name, it.item_type_label,
(SELECT COUNT(*) FROM sciot_properties WHERE item_type_name = it.item_type_name) as prop_count,
(SELECT COUNT(*) FROM sciot_methods WHERE item_type_name = it.item_type_name) as method_count,
(SELECT COUNT(*) FROM sciot_relationships WHERE item_type_name = it.item_type_name) as rel_count
FROM sciot_item_types it
LEFT JOIN sciot_templates t ON it.item_type_name = t.item_type_name
WHERE t.item_type_name IS NULL
ORDER BY prop_count DESC
`).all();
return missing.filter(m => m.prop_count > 0 || m.method_count > 0);
}
#### 3.2 LLM批量生成模板API ❌
Should implement: POST /api/aml/batch-generate-templates
Function: Batch calls LLM to generate templates for missing object classes
Implementation points:
- Accepts item_types array and force parameter
- Retrieves attributes/methods/relationships for each
- Constructs Prompt to call LLM
- Parses results and saves to sciot_templates table
- Returns generation statistics (success/failure/skip)
#### 3.3 Frontend Template Generation UI ❌
Should implement: Add a "Batch Generate Templates" button to the Business System Layer Tab
Functions:
- 4-step wizard: Analyze missing → Select objects → Configure parameters → View results
- Display coverage statistics (298/442 = 67.4%)
- Support select all/clear all/batch generation
? Phase4-6 (Not implemented at all)
| Phase | Function | Status |
|---|---|---|
| Phase4 | Create result log table + Closed-loop mechanism | ❌ Not implemented |
| Phase5 | Self-evolution mechanism (Log analysis + Rule optimization) | ❌ Not implemented |
| Phase6 | Business system prompt generation | ❌ Not implemented |
? Detailed optimization and completion plan
Phase 1: Urgent fixes (P0 BUGs) - Estimated 2 hours
#### Task 1: Fix database connection issues
// server/routes/aml.js 第335行替换为:
let _sciotDb = null;
function getSciotDb() {
if (!_sciotDb) {
_sciotDb = require('../sqlite-compat').createDatabase(
path.join(__dirname, '..', 'data', 'sciot_import.db')
);
}
return _sciotDb;
}
- 删除所有
sciotDb.close()调用(约35处)
#### 任务2: 删除debug路由
// 删除 aml.js 第2508-2553行
// /api/aml/debug-save 和 /api/aml/debug-SCSAI
#### 任务3: 前端改用优化API
// frontend/app.js 第1468-1478行替换为:
const byItemRes = await fetch(`/api/aml/business-system/by-item/${t.item_type_name}`);
const byItemJson = await byItemRes.json();
if (byItemJson.success) {
plmArch.detailBusinessSystem = byItemJson.data;
}
第二阶段:P1Repair + Phase3实现 - 预计6小时
#### 任务4: 提取共享工具类
Create server/utils/cache.js and server/utils/db-pool.js
#### Task 5: Implement missing template identification API
Add GET /api/aml/missing-templates in aml.js
#### Task 6: Implement LLM batch generation API
Add POST /api/aml/batch-generate-templates in aml.js
#### Task 7: Frontend template generation UI
Add batch generation wizard to the business system layer tab in app.js
Phase 3: Phase4-6 Implementation - Estimated 10 hours
#### Task 8: Phase4 - Closed-loop mechanism
- Create sciot_creation_logs table
- Modify object creation process to log LLM generation and SCSAI return results
- Auto-refresh business system after TOC sync
#### Task 9: Phase5 - Self-evolution mechanism
- Create log analysis API
- Implement rule effectiveness scoring
- Schedule periodic task (weekly analysis)
#### Task 10: Phase6 - Business system prompts
- Implement POST /api/aml/business-systems/generate-prompts
- Batch generate prompts for 46 systems
- Frontend display business system prompts
? Priority sorting
| Priority | Task | Effort | Impact |
|---|---|---|---|
| ? P0 | Fix database connection issue | 30 minutes | Performance improvement |
| ? P0 | Remove debug routes | 10 minutes | Security |
| ? P0 | Frontend switch to optimized API | 20 minutes | User experience |
| ? P1 | Extract shared utility classes | 1 hour | Maintainability |
| ? P1 | Implement missing template identification API | 1 hour | Phase3 foundation |
| ? P1 | Implement LLM batch generation API | 2 hours | Phase3 core |
| ? P1 | Frontend template generation UI | 2 hours | Phase3 completeness |
| ? P2 | Phase4-6 implementation | 10 hours | Full closed loop |
? File change list
Files to modify
- server/routes/aml.js - Fix P0-BUG-2/4, add Phase3 API
- server/routes/business-system.router.js - Fix P1-BUG-6
- frontend/app.js - Fix P0-BUG-1 supplement, add Phase3 UI
- meta-model.router.js - Use shared utility classes
Files to create
- server/utils/cache.js - Shared Cache class
- server/utils/db-pool.js - Shared DatabasePool class
✅ Acceptance criteria
- [ ] All P0 BUGs fixed, performance test passed
- [ ] Missing template identification API returns correct data (144 missing)
- [ ] LLM batch generation can successfully generate and save templates
- [ ] Frontend template generation UI can complete the 4-step wizard process
- [ ] Template coverage increases from 67.4% to 90%+
Report generation complete, recommend implementing step by step according to priority
BossAgents