Repository navigation
Expand file tree
/
Copy pathtest-full-feature.js
More file actions
316 lines (267 loc) · 10.5 KB
/
Copy pathtest-full-feature.js
File metadata and controls
316 lines (267 loc) · 10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/**
* 完整功能测试脚本
* 测试:项目管理、AI 任务拆解、团队成员、资源日历、报告生成
*/
const initSqlJs = require('sql.js');
const path = require('path');
const fs = require('fs');
const dbPath = path.join(process.env.APPDATA, 'project-delivery-tool', 'delivery.db');
async function runFullTest() {
console.log('='.repeat(60));
console.log(' 项目交付管理工具 - 完整功能测试');
console.log('='.repeat(60));
console.log();
const SQL = await initSqlJs();
const fileBuffer = fs.readFileSync(dbPath);
const db = new SQL.Database(fileBuffer);
// ========== 测试 1: 项目管理 ==========
console.log('【测试 1】项目管理模块');
console.log('-'.repeat(40));
// 查询现有项目
const projects = db.exec('SELECT id, name, client, start_date, end_date, status FROM projects ORDER BY id DESC');
console.log(`现有项目数量:${projects[0]?.values.length || 0}`);
if (projects[0]) {
projects[0].values.forEach(row => {
console.log(` [${row[0]}] ${row[1]} - ${row[2]} (${row[5]})`);
});
}
console.log('✅ 项目管理功能正常');
console.log();
// ========== 测试 2: AI 任务拆解 ==========
console.log('【测试 2】AI 任务拆解模块');
console.log('-'.repeat(40));
const { AIService } = require('./electron/ai-service');
const aiService = new AIService();
console.log(`AI Provider: ${aiService.provider}`);
console.log(`API Key: ${aiService.apiKey ? '已配置' : '未配置'}`);
const subtasks = await aiService.decomposeTask({
projectName: '测试项目',
taskDescription: '开发数据报表功能',
startDate: '2026-03-20',
endDate: '2026-03-30',
});
console.log(`AI 拆解返回:${subtasks.length} 个子任务`);
console.log('前 5 个子任务:');
subtasks.slice(0, 5).forEach((task, i) => {
console.log(` ${i+1}. ${task.name} (${task.duration}天)`);
});
console.log('✅ AI 任务拆解功能正常');
console.log();
// ========== 测试 3: 任务管理 ==========
console.log('【测试 3】任务管理模块');
console.log('-'.repeat(40));
// 查询 AI 测试项目的任务
const testProject = projects[0]?.values.find(p => p[1].includes('AI 测试'));
if (testProject) {
const tasks = db.exec(`SELECT id, name, duration, parent_id FROM tasks WHERE project_id = ${testProject[0]} ORDER BY id`);
console.log(`AI 测试项目任务数量:${tasks[0]?.values.length || 0}`);
// 显示层级结构
if (tasks[0]) {
const taskTree = buildTaskTree(tasks[0].values);
console.log('任务层级结构:');
printTaskTree(taskTree, 0);
}
}
console.log('✅ 任务管理功能正常');
console.log();
// ========== 测试 4: 团队成员管理 ==========
console.log('【测试 4】团队成员模块');
console.log('-'.repeat(40));
// 添加测试成员
const testMembers = [
{ name: '张三', role: '前端开发', skills: ['React', 'TypeScript', 'Ant Design'] },
{ name: '李四', role: '后端开发', skills: ['Node.js', 'Java', 'MySQL'] },
{ name: '王五', role: '产品经理', skills: ['需求分析', '原型设计'] },
];
for (const member of testMembers) {
const skillsJson = JSON.stringify(member.skills);
db.run(`
INSERT INTO members (name, role, skills, available_hours_per_day)
VALUES (?, ?, ?, 8)
`, [member.name, member.role, skillsJson]);
}
const members = db.exec('SELECT id, name, role, skills FROM members ORDER BY id DESC LIMIT 10');
console.log('团队成员列表:');
if (members[0]) {
members[0].values.forEach(row => {
const skills = JSON.parse(row[3] || '[]');
console.log(` [${row[0]}] ${row[1]} - ${row[2]} (技能:${skills.join(', ')})`);
});
}
console.log('✅ 团队成员管理功能正常');
console.log();
// ========== 测试 5: 资源日历 ==========
console.log('【测试 5】资源日历模块');
console.log('-'.repeat(40));
// 获取第一个成员
const firstMember = db.exec('SELECT id FROM members LIMIT 1');
if (firstMember[0]?.values.length > 0) {
const memberId = firstMember[0].values[0][0];
// 添加测试日历记录
const testDates = [
{ date: '2026-03-17', type: 'work', available: 8, assigned: 6 },
{ date: '2026-03-18', type: 'work', available: 8, assigned: 8 },
{ date: '2026-03-19', type: 'overtime', available: 10, assigned: 8 },
{ date: '2026-03-20', type: 'leave', available: 0, assigned: 0 },
];
for (const item of testDates) {
db.run(`
INSERT OR REPLACE INTO resource_calendar (member_id, date, available_hours, assigned_hours, type)
VALUES (?, ?, ?, ?, ?)
`, [memberId, item.date, item.available, item.assigned, item.type]);
}
const calendar = db.exec(`
SELECT date, type, available_hours, assigned_hours
FROM resource_calendar
WHERE member_id = ${memberId}
ORDER BY date
`);
console.log('资源日历记录:');
if (calendar[0]) {
calendar[0].values.forEach(row => {
const typeMap = { work: '工作', overtime: '加班', leave: '请假', training: '培训' };
console.log(` ${row[0]}: ${typeMap[row[1]]} - 可用${row[2]}h, 已分配${row[3]}h`);
});
}
}
console.log('✅ 资源日历功能正常');
console.log();
// ========== 测试 6: 报告生成 ==========
console.log('【测试 6】报告生成模块');
console.log('-'.repeat(40));
// 获取第一个项目
const firstProject = db.exec('SELECT id, name FROM projects LIMIT 1');
if (firstProject[0]?.values.length > 0) {
const projectId = firstProject[0].values[0][0];
const projectName = firstProject[0].values[0][1];
// 创建测试报告
const reportContent = `
# 项目日报 - ${projectName}
## 今日完成情况
- 完成需求分析文档
- 完成数据库设计
- 开始 API 开发
## 进行中任务
- 后端 API 开发 (进度:30%)
- 前端页面设计 (进度:50%)
## 风险与问题
- 无重大风险
## 明日计划
- 继续 API 开发
- 开始前端页面实现
`.trim();
db.run(`
INSERT INTO reports (project_id, type, date_range, content, metrics)
VALUES (?, 'daily', '2026-03-17', ?, ?)
`, [projectId, reportContent, JSON.stringify({ progress: 35, tasks: 5 })]);
const reports = db.exec(`SELECT id, type, date_range, created_at FROM reports WHERE project_id = ${projectId}`);
console.log('项目报告:');
if (reports[0]) {
reports[0].values.forEach(row => {
const typeMap = { daily: '日报', weekly: '周报' };
console.log(` [${row[0]}] ${typeMap[row[1]]} - ${row[2]} (创建:${row[3]})`);
});
}
// AI 报告生成测试
console.log('\nAI 报告生成测试:');
const tasks = db.exec(`SELECT name, progress, assignee FROM tasks WHERE project_id = ${projectId} LIMIT 5`);
const members = db.exec('SELECT name, role FROM members LIMIT 5');
const reportData = {
type: 'daily',
projectData: { name: projectName },
dateRange: '2026-03-17',
tasks: tasks[0]?.values.map(row => ({ name: row[0], progress: row[1], assignee: row[2] })) || [],
members: members[0]?.values.map(row => ({ name: row[0], role: row[1] })) || [],
};
const aiReport = await aiService.generateReport(reportData);
console.log(' AI 报告生成:', aiReport ? '成功' : '失败');
if (aiReport) {
console.log(' 报告预览 (前 100 字):', aiReport.substring(0, 100) + '...');
}
}
console.log('✅ 报告生成功能正常');
console.log();
// ========== 测试 7: 风险管理 ==========
console.log('【测试 7】风险管理模块');
console.log('-'.repeat(40));
const firstProj = db.exec('SELECT id, name FROM projects LIMIT 1');
if (firstProj[0]?.values.length > 0) {
const projectId = firstProj[0].values[0][0];
const projectName = firstProj[0].values[0][1];
// 添加测试风险
db.run(`
INSERT INTO risks (project_id, description, severity, probability, mitigation_plan, owner, status)
VALUES (?, ?, ?, ?, ?, ?, ?)
`, [projectId, '需求变更风险', 'high', 'medium', '加强沟通,定期确认需求', '张三', 'open']);
db.run(`
INSERT INTO risks (project_id, description, severity, probability, mitigation_plan, owner, status)
VALUES (?, ?, ?, ?, ?, ?, ?)
`, [projectId, '人员流动风险', 'medium', 'low', '做好知识文档管理', '李四', 'open']);
const risks = db.exec(`SELECT id, description, severity, probability, status FROM risks WHERE project_id = ${projectId}`);
console.log('项目风险:');
if (risks[0]) {
risks[0].values.forEach(row => {
console.log(` [${row[0]}] ${row[1]} (严重程度:${row[2]}, 概率:${row[3]}, 状态:${row[4]})`);
});
}
}
console.log('✅ 风险管理功能正常');
console.log();
// ========== 保存数据库 ==========
const data = db.export();
const buffer = Buffer.from(data);
fs.writeFileSync(dbPath, buffer);
db.close();
// ========== 测试总结 ==========
console.log('='.repeat(60));
console.log(' 测试总结');
console.log('='.repeat(60));
console.log();
console.log('✅ 所有模块测试通过!');
console.log();
console.log('测试覆盖:');
console.log(' 1. 项目管理 - CRUD 操作');
console.log(' 2. AI 任务拆解 - DeepSeek API 集成');
console.log(' 3. 任务管理 - WBS 层级结构');
console.log(' 4. 团队成员 - 技能管理');
console.log(' 5. 资源日历 - 工时分配');
console.log(' 6. 报告生成 - AI 自动生成');
console.log(' 7. 风险管理 - 风险跟踪');
console.log();
console.log('数据库位置:', dbPath);
console.log();
console.log('='.repeat(60));
}
// 构建树形结构
function buildTaskTree(tasks) {
const map = new Map();
const root = [];
tasks.forEach(task => {
map.set(task[0], { id: task[0], name: task[1], duration: task[2], parentId: task[3], children: [] });
});
map.forEach((node, id) => {
if (node.parentId) {
const parent = map.get(node.parentId);
if (parent) {
parent.children.push(node);
} else {
root.push(node);
}
} else {
root.push(node);
}
});
return root;
}
// 打印树形结构
function printTaskTree(tree, level) {
tree.forEach(node => {
const indent = ' '.repeat(level);
const prefix = level > 0 ? '└── ' : '';
console.log(`${indent}${prefix}[${node.id}] ${node.name} (${node.duration}天)`);
if (node.children.length > 0) {
printTaskTree(node.children, level + 1);
}
});
}
runFullTest().catch(console.error);