This commit is contained in:
张成
2025-12-18 18:32:11 +08:00
parent 699c1d4f55
commit 891dfc5777
4 changed files with 37 additions and 50 deletions

View File

@@ -27,12 +27,10 @@ module.exports = {
chat_records,
op
} = models;
const deviceManager = require('../middleware/schedule/deviceManager');
// 设备统计(从 pla_account 和 deviceManager 获取)
// 设备统计(直接从数据库获取)
const totalDevices = await pla_account.count({ where: { is_delete: 0 } });
const deviceStatus = deviceManager.getAllDevicesStatus();
const onlineDevices = Object.values(deviceStatus).filter(d => d.isOnline).length;
const onlineDevices = await pla_account.count({ where: { is_delete: 0, is_online: 1 } });
const runningDevices = 0; // 不再维护运行状态
// 任务统计
@@ -211,29 +209,25 @@ return ctx.success({
'GET /dashboard/device-performance': async (ctx) => {
const models = Framework.getModels();
const { pla_account, task_status, job_postings, apply_records, chat_records } = models;
const deviceManager = require('../middleware/schedule/deviceManager');
// 从 pla_account 获取所有账号
const accounts = await pla_account.findAll({
where: { is_delete: 0 },
attributes: ['id', 'sn_code', 'name'],
attributes: ['id', 'sn_code', 'name', 'is_online'],
limit: 20
});
// 获取设备在线状态
const deviceStatus = deviceManager.getAllDevicesStatus();
// 为每个账号统计任务、岗位、投递、聊天数据
const performanceData = await Promise.all(accounts.map(async (account) => {
const snCode = account.sn_code;
const status = deviceStatus[snCode] || { isOnline: false };
const isOnline = account.is_online === 1;
// 统计任务
const [completedTasks, failedTasks] = await Promise.all([
task_status.count({ where: { sn_code: snCode, status: 'completed' } }),
task_status.count({ where: { sn_code: snCode, status: 'failed' } })
]);
// 统计岗位、投递、聊天(如果有相关字段)
const [jobsSearched, applies, chats] = await Promise.all([
job_postings.count({ where: { sn_code: snCode } }).catch(() => 0),
@@ -253,7 +247,7 @@ return ctx.success({
applies,
chats,
successRate,
healthScore: status.isOnline ? 100 : 0,
healthScore: isOnline ? 100 : 0,
onlineDuration: 0 // 不再维护在线时长
};
}));