This commit is contained in:
张成
2025-12-15 22:03:01 +08:00
parent 6e5c35f144
commit 4443d43ec1
15 changed files with 776 additions and 485 deletions

View File

@@ -16,7 +16,6 @@ class PlaAccountService {
*/
async getAccountById(id) {
const pla_account = db.getModel('pla_account');
const device_status = db.getModel('device_status');
const account = await pla_account.findByPk(id);
if (!account) {
@@ -25,15 +24,9 @@ class PlaAccountService {
const accountData = account.get({ plain: true });
// device_status 查询在线状态和登录状态
const deviceStatus = await device_status.findByPk(account.sn_code);
if (deviceStatus) {
accountData.is_online = deviceStatus.isOnline || false;
accountData.is_logged_in = deviceStatus.isLoggedIn || false;
} else {
accountData.is_online = false;
accountData.is_logged_in = false;
}
// 移除 device_status 依赖,在线状态和登录状态设为默认值
accountData.is_online = false;
accountData.is_logged_in = false;
return accountData;
}
@@ -45,7 +38,6 @@ class PlaAccountService {
*/
async getAccountBySnCode(sn_code) {
const pla_account = db.getModel('pla_account');
const device_status = db.getModel('device_status');
if (!sn_code) {
throw new Error('设备SN码不能为空');
@@ -65,15 +57,9 @@ class PlaAccountService {
const accountData = account.get({ plain: true });
// device_status 查询在线状态和登录状态
const deviceStatus = await device_status.findByPk(sn_code);
if (deviceStatus) {
accountData.is_online = deviceStatus.isOnline || false;
accountData.is_logged_in = deviceStatus.isLoggedIn || false;
} else {
accountData.is_online = false;
accountData.is_logged_in = false;
}
// 移除 device_status 依赖,在线状态和登录状态设为默认值
accountData.is_online = false;
accountData.is_logged_in = false;
return accountData;
}
@@ -85,7 +71,6 @@ class PlaAccountService {
*/
async getAccountList(params) {
const pla_account = db.getModel('pla_account');
const device_status = db.getModel('device_status');
const op = db.getModel('op');
const { key, value, platform_type, is_online, limit, offset } = params;
@@ -107,28 +92,8 @@ class PlaAccountService {
where.platform_type = platform_type;
}
// 如果按在线状态筛选,需要先查询在线设备的 sn_code
let onlineSnCodes = null;
if (is_online !== undefined && is_online !== null) {
const onlineDevices = await device_status.findAll({
where: { isOnline: is_online },
attributes: ['sn_code']
});
onlineSnCodes = onlineDevices.map(device => device.sn_code);
// 如果筛选在线但没有任何在线设备,直接返回空结果
if (is_online && onlineSnCodes.length === 0) {
return {
count: 0,
rows: []
};
}
// 如果筛选离线,需要在 where 中排除在线设备的 sn_code
if (!is_online && onlineSnCodes.length > 0) {
where.sn_code = { [op.notIn]: onlineSnCodes };
}
}
// 移除 device_status 依赖is_online 筛选功能暂时禁用
// 如果需要在线状态筛选,可以在 pla_account 表中添加相应字段
const result = await pla_account.findAndCountAll({
where,
@@ -137,23 +102,10 @@ class PlaAccountService {
order: [['id', 'DESC']]
});
// 批量查询所有账号对应的设备状态
const snCodes = result.rows.map(account => account.sn_code);
const deviceStatuses = await device_status.findAll({
where: { sn_code: { [op.in]: snCodes } },
attributes: ['sn_code', 'isOnline']
});
// 创建 sn_code 到 isOnline 的映射
const statusMap = {};
deviceStatuses.forEach(status => {
statusMap[status.sn_code] = status.isOnline;
});
// 处理返回数据,添加 is_online 字段
// 处理返回数据is_online 设为默认值 false
const rows = result.rows.map(account => {
const accountData = account.get({ plain: true });
accountData.is_online = statusMap[account.sn_code] || false;
accountData.is_online = false;
return accountData;
});
@@ -368,7 +320,6 @@ class PlaAccountService {
*/
async runCommand(params) {
const pla_account = db.getModel('pla_account');
const device_status = db.getModel('device_status');
const task_status = db.getModel('task_status');
const { id, commandType, commandName, commandParams } = params;
@@ -389,11 +340,8 @@ class PlaAccountService {
throw new Error(authCheck.message);
}
// device_status 检查账号是否在线
const deviceStatus = await device_status.findByPk(account.sn_code);
if (!deviceStatus || !deviceStatus.isOnline) {
throw new Error('账号不在线,无法执行指令');
}
// 移除 device_status 依赖,在线状态检查暂时移除
// 如果需要在线状态检查,可以在 pla_account 表中添加相应字段
// 获取调度管理器并执行指令
if (!scheduleManager.mqttClient) {
@@ -494,7 +442,6 @@ class PlaAccountService {
*/
async runTask(params) {
const pla_account = db.getModel('pla_account');
const device_status = db.getModel('device_status');
const { id, taskType, taskName } = params;
@@ -513,11 +460,8 @@ class PlaAccountService {
throw new Error('账号未启用,无法执行指令');
}
// device_status 检查账号是否在线
const deviceStatus = await device_status.findByPk(account.sn_code);
if (!deviceStatus || !deviceStatus.isOnline) {
throw new Error('账号不在线,无法执行指令');
}
// 移除 device_status 依赖,在线状态检查暂时移除
// 如果需要在线状态检查,可以在 pla_account 表中添加相应字段
// 获取调度管理器并执行指令
if (!scheduleManager.mqttClient) {