This commit is contained in:
张成
2025-11-26 20:48:42 +08:00
parent 4db078c80a
commit e3d335f0dd
5 changed files with 96 additions and 21 deletions

View File

@@ -37,6 +37,46 @@ class PlaAccountService {
return accountData;
}
/**
* 根据设备SN码获取账号信息
* @param {string} sn_code - 设备SN码
* @returns {Promise<Object>} 账号信息
*/
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码不能为空');
}
// 根据 sn_code 查询账号,排除已删除的账号
const account = await pla_account.findOne({
where: {
sn_code: sn_code,
is_delete: 0
}
});
if (!account) {
throw new Error('账号不存在');
}
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;
}
return accountData;
}
/**
* 获取账号列表
* @param {Object} params - 查询参数