54 lines
2.0 KiB
JavaScript
54 lines
2.0 KiB
JavaScript
|
|
// 测试统计服务
|
||
|
|
const apiService = require('./miniprogram/services/apiService');
|
||
|
|
const statisticsService = require('./miniprogram/services/statisticsService');
|
||
|
|
|
||
|
|
async function testStatisticsService() {
|
||
|
|
console.log('开始测试统计服务...');
|
||
|
|
|
||
|
|
try {
|
||
|
|
// 测试获取统计数据
|
||
|
|
console.log('1. 测试获取统计数据...');
|
||
|
|
const stats = await statisticsService.getSystemStats();
|
||
|
|
console.log('统计数据获取成功:');
|
||
|
|
console.log('- 员工总数:', stats.employeeCount);
|
||
|
|
console.log('- 订单总数:', stats.orderCount);
|
||
|
|
console.log('- 仓库总数:', stats.warehouseCount);
|
||
|
|
console.log('- 待处理订单:', stats.pendingOrders);
|
||
|
|
console.log('- 进行中订单:', stats.activeOrders);
|
||
|
|
|
||
|
|
// 测试缓存功能
|
||
|
|
console.log('\n2. 测试缓存功能...');
|
||
|
|
const cacheStatus1 = statisticsService.getCacheStatus();
|
||
|
|
console.log('缓存状态:', cacheStatus1);
|
||
|
|
|
||
|
|
// 再次获取数据(应该使用缓存)
|
||
|
|
const stats2 = await statisticsService.getSystemStats();
|
||
|
|
console.log('第二次获取数据(应使用缓存)');
|
||
|
|
|
||
|
|
// 测试客户端更新功能
|
||
|
|
console.log('\n3. 测试客户端更新功能...');
|
||
|
|
statisticsService.updateStats('employee', 30);
|
||
|
|
statisticsService.updateStats('order', 200);
|
||
|
|
statisticsService.updateStats('warehouse', 10);
|
||
|
|
|
||
|
|
const updatedStats = await statisticsService.getSystemStats();
|
||
|
|
console.log('更新后的统计数据:');
|
||
|
|
console.log('- 员工总数:', updatedStats.employeeCount);
|
||
|
|
console.log('- 订单总数:', updatedStats.orderCount);
|
||
|
|
console.log('- 仓库总数:', updatedStats.warehouseCount);
|
||
|
|
|
||
|
|
// 测试刷新功能
|
||
|
|
console.log('\n4. 测试刷新功能...');
|
||
|
|
statisticsService.refreshStats();
|
||
|
|
const cacheStatus2 = statisticsService.getCacheStatus();
|
||
|
|
console.log('刷新后缓存状态:', cacheStatus2);
|
||
|
|
|
||
|
|
console.log('\n✅ 统计服务测试完成!');
|
||
|
|
|
||
|
|
} catch (error) {
|
||
|
|
console.error('❌ 测试失败:', error);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 运行测试
|
||
|
|
testStatisticsService();
|