Merge branch 'main' of https://git.light120.com/zc/autoAiWorkSys
This commit is contained in:
@@ -26,11 +26,11 @@ const baseConfig = {
|
|||||||
// 开发环境配置
|
// 开发环境配置
|
||||||
const developmentConfig = {
|
const developmentConfig = {
|
||||||
...baseConfig,
|
...baseConfig,
|
||||||
apiUrl: 'http://localhost:9097/admin_api/',
|
// apiUrl: 'http://localhost:9097/admin_api/',
|
||||||
uploadUrl: 'http://localhost:9097/admin_api/upload',
|
// uploadUrl: 'http://localhost:9097/admin_api/upload',
|
||||||
|
|
||||||
// apiUrl: 'http://work.light120.com/admin_api/',
|
apiUrl: 'http://work.light120.com/admin_api/',
|
||||||
// uploadUrl: 'http://work.light120.com/admin_api/upload',
|
uploadUrl: 'http://work.light120.com/admin_api/upload',
|
||||||
// 开发环境显示更多调试信息
|
// 开发环境显示更多调试信息
|
||||||
debug: true
|
debug: true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Admin Framework Demo</title>
|
<title>Admin Framework</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
|
|||||||
@@ -25,6 +25,15 @@ class PlaAccountServer {
|
|||||||
return window.framework.http.post('/account/detail', { id })
|
return window.framework.http.post('/account/detail', { id })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过设备SN码获取账号信息
|
||||||
|
* @param {String} sn_code - 设备SN码
|
||||||
|
* @returns {Promise}
|
||||||
|
*/
|
||||||
|
getBySnCode(sn_code) {
|
||||||
|
return window.framework.http.post('/account/getBySnCode', { sn_code })
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增账号
|
* 新增账号
|
||||||
* @param {Object} row - 账号数据
|
* @param {Object} row - 账号数据
|
||||||
|
|||||||
@@ -19,8 +19,8 @@
|
|||||||
<FormItem label="平台">
|
<FormItem label="平台">
|
||||||
<Select v-model="gridOption.param.seachOption.platform_type" style="width: 120px" clearable
|
<Select v-model="gridOption.param.seachOption.platform_type" style="width: 120px" clearable
|
||||||
@on-change="query(1)">
|
@on-change="query(1)">
|
||||||
<Option value="1">Boss直聘</Option>
|
<Option value="boss">Boss直聘</Option>
|
||||||
<Option value="2">猎聘</Option>
|
<Option value="liepin">猎聘</Option>
|
||||||
</Select>
|
</Select>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
<FormItem label="在线状态">
|
<FormItem label="在线状态">
|
||||||
@@ -276,8 +276,8 @@ export default {
|
|||||||
{ title: '设备SN码', key: 'sn_code', type: 'text', required: true },
|
{ title: '设备SN码', key: 'sn_code', type: 'text', required: true },
|
||||||
{
|
{
|
||||||
title: '平台', key: 'platform_type', com: 'Select', required: true, source: [
|
title: '平台', key: 'platform_type', com: 'Select', required: true, source: [
|
||||||
{ key: '1', value: 'Boss直聘' },
|
{ key: 'boss', value: 'Boss直聘' },
|
||||||
{ key: '2', value: '猎聘' }
|
{ key: 'liepin', value: '猎聘' }
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{ title: '登录名', key: 'login_name', com: 'Input', required: true },
|
{ title: '登录名', key: 'login_name', com: 'Input', required: true },
|
||||||
@@ -293,8 +293,8 @@ export default {
|
|||||||
minWidth: 100,
|
minWidth: 100,
|
||||||
render: (h, params) => {
|
render: (h, params) => {
|
||||||
const platformMap = {
|
const platformMap = {
|
||||||
'1': { text: 'Boss直聘', color: 'blue' },
|
'boss': { text: 'Boss直聘', color: 'blue' },
|
||||||
'2': { text: '猎聘', color: 'green' }
|
'liepin': { text: '猎聘', color: 'green' }
|
||||||
}
|
}
|
||||||
const platform = platformMap[params.row.platform_type] || { text: params.row.platform_type, color: 'default' }
|
const platform = platformMap[params.row.platform_type] || { text: params.row.platform_type, color: 'default' }
|
||||||
return h('Tag', { props: { color: platform.color } }, platform.text)
|
return h('Tag', { props: { color: platform.color } }, platform.text)
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<!-- 账户信息卡片 -->
|
<!-- 账户信息卡片 -->
|
||||||
<Card v-if="accountInfo.id" style="margin-bottom: 16px;" class="account-info-card">
|
<Card v-if="accountInfo && (accountInfo.id || accountInfo.sn_code)" style="margin-bottom: 16px;" class="account-info-card">
|
||||||
<div slot="title" style="display: flex; align-items: center; justify-content: space-between;">
|
<div slot="title" style="display: flex; align-items: center; justify-content: space-between;">
|
||||||
<span>账户信息</span>
|
<span>账户信息</span>
|
||||||
<Button type="primary" size="small" @click="viewAccountDetail">查看详情</Button>
|
<Button type="primary" size="small" @click="viewAccountDetail">查看详情</Button>
|
||||||
@@ -718,26 +718,21 @@ export default {
|
|||||||
try {
|
try {
|
||||||
console.log('加载账户信息,设备SN:', this.selectedDeviceSn)
|
console.log('加载账户信息,设备SN:', this.selectedDeviceSn)
|
||||||
|
|
||||||
// 根据 sn_code 查询账户信息
|
// 通过 sn_code 直接获取账户信息
|
||||||
const res = await PlaAccountServer.page({
|
const res = await PlaAccountServer.getBySnCode(this.selectedDeviceSn)
|
||||||
seachOption: {
|
|
||||||
key: 'sn_code',
|
|
||||||
value: this.selectedDeviceSn
|
|
||||||
},
|
|
||||||
pageOption: {
|
|
||||||
page: 1,
|
|
||||||
pageSize: 1
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
console.log('账户信息接口返回:', res)
|
console.log('账户信息接口返回:', res)
|
||||||
|
|
||||||
// 支持多种数据格式
|
if (res.code === 0 && res.data) {
|
||||||
const accountList = res.data?.rows || res.data?.list || res.data?.data || []
|
const accountData = res.data
|
||||||
|
console.log('找到账户信息原始数据:', accountData)
|
||||||
|
|
||||||
if (accountList.length > 0) {
|
// 确保 id 字段存在,支持多种字段名
|
||||||
const accountData = accountList[0]
|
if (!accountData.id) {
|
||||||
console.log('找到账户信息:', accountData)
|
accountData.id = accountData.account_id || accountData.accountId || accountData.ID || null
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('账户ID:', accountData.id)
|
||||||
|
|
||||||
// 如果接口没有返回设备状态,则单独查询
|
// 如果接口没有返回设备状态,则单独查询
|
||||||
if (accountData.is_online === undefined || accountData.is_logged_in === undefined) {
|
if (accountData.is_online === undefined || accountData.is_logged_in === undefined) {
|
||||||
@@ -758,16 +753,18 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 确保布尔值字段正确初始化
|
// 确保布尔值字段正确初始化,转换为数字类型(0 或 1)
|
||||||
accountData.is_enabled = accountData.is_enabled !== undefined ? accountData.is_enabled : 1
|
accountData.is_enabled = accountData.is_enabled !== undefined ? Number(accountData.is_enabled) : 1
|
||||||
accountData.auto_deliver = accountData.auto_deliver !== undefined ? accountData.auto_deliver : 0
|
accountData.auto_deliver = accountData.auto_deliver !== undefined ? Number(accountData.auto_deliver) : 0
|
||||||
accountData.auto_chat = accountData.auto_chat !== undefined ? accountData.auto_chat : 0
|
accountData.auto_chat = accountData.auto_chat !== undefined ? Number(accountData.auto_chat) : 0
|
||||||
accountData.auto_active = accountData.auto_active !== undefined ? accountData.auto_active : 0
|
accountData.auto_active = accountData.auto_active !== undefined ? Number(accountData.auto_active) : 0
|
||||||
|
|
||||||
this.accountInfo = accountData
|
this.accountInfo = accountData
|
||||||
console.log('设置账户信息:', this.accountInfo)
|
console.log('设置账户信息:', this.accountInfo)
|
||||||
|
console.log('accountInfo.id 值:', this.accountInfo.id)
|
||||||
|
console.log('v-if 判断结果:', !!this.accountInfo.id)
|
||||||
} else {
|
} else {
|
||||||
console.warn('未找到账户信息,设备SN:', this.selectedDeviceSn)
|
console.warn('未找到账户信息,设备SN:', this.selectedDeviceSn, '响应:', res)
|
||||||
this.accountInfo = {}
|
this.accountInfo = {}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -778,7 +775,7 @@ export default {
|
|||||||
|
|
||||||
// 处理开关变化
|
// 处理开关变化
|
||||||
async handleSwitchChange(field, value) {
|
async handleSwitchChange(field, value) {
|
||||||
if (!this.accountInfo.id) {
|
if (!this.accountInfo || !this.accountInfo.id) {
|
||||||
this.$Message.warning('账户信息不存在')
|
this.$Message.warning('账户信息不存在')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -801,8 +798,8 @@ export default {
|
|||||||
this.switchLoading[field] = true
|
this.switchLoading[field] = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 确保 value 是数字类型(0 或 1)
|
// i-switch 的 on-change 事件已经返回了正确的值(1 或 0),直接使用
|
||||||
const numericValue = value ? 1 : 0
|
const numericValue = Number(value)
|
||||||
|
|
||||||
// 构建更新数据,确保是纯对象,只包含基本类型
|
// 构建更新数据,确保是纯对象,只包含基本类型
|
||||||
const updateData = {
|
const updateData = {
|
||||||
@@ -822,19 +819,8 @@ export default {
|
|||||||
const errorMsg = error.response?.data?.message || error.message || '请稍后重试'
|
const errorMsg = error.response?.data?.message || error.message || '请稍后重试'
|
||||||
this.$Message.error('更新失败:' + errorMsg)
|
this.$Message.error('更新失败:' + errorMsg)
|
||||||
|
|
||||||
// 恢复原值
|
// 恢复原值(从数据库重新加载)
|
||||||
this.$nextTick(() => {
|
await this.loadAccountInfo()
|
||||||
const oldValue = this.accountInfo[field]
|
|
||||||
if (field === 'is_enabled') {
|
|
||||||
this.accountInfo.is_enabled = oldValue === 1 ? 0 : 1
|
|
||||||
} else if (field === 'auto_deliver') {
|
|
||||||
this.accountInfo.auto_deliver = oldValue === 1 ? 0 : 1
|
|
||||||
} else if (field === 'auto_chat') {
|
|
||||||
this.accountInfo.auto_chat = oldValue === 1 ? 0 : 1
|
|
||||||
} else if (field === 'auto_active') {
|
|
||||||
this.accountInfo.auto_active = oldValue === 1 ? 0 : 1
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} finally {
|
} finally {
|
||||||
this.switchLoading[field] = false
|
this.switchLoading[field] = false
|
||||||
}
|
}
|
||||||
@@ -853,8 +839,8 @@ export default {
|
|||||||
// 获取平台颜色
|
// 获取平台颜色
|
||||||
getPlatformColor(platformType) {
|
getPlatformColor(platformType) {
|
||||||
const colorMap = {
|
const colorMap = {
|
||||||
'1': 'blue',
|
'boss': 'blue',
|
||||||
'2': 'green'
|
'liepin': 'green'
|
||||||
}
|
}
|
||||||
return colorMap[platformType] || 'default'
|
return colorMap[platformType] || 'default'
|
||||||
},
|
},
|
||||||
@@ -862,8 +848,8 @@ export default {
|
|||||||
// 获取平台文本
|
// 获取平台文本
|
||||||
getPlatformText(platformType) {
|
getPlatformText(platformType) {
|
||||||
const textMap = {
|
const textMap = {
|
||||||
'1': 'Boss直聘',
|
'boss': 'Boss直聘',
|
||||||
'2': '猎聘'
|
'liepin': '猎聘'
|
||||||
}
|
}
|
||||||
return textMap[platformType] || platformType || '-'
|
return textMap[platformType] || platformType || '-'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,35 @@ module.exports = {
|
|||||||
const accountData = await plaAccountService.getAccountById(id);
|
const accountData = await plaAccountService.getAccountById(id);
|
||||||
return ctx.success(accountData);
|
return ctx.success(accountData);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @swagger
|
||||||
|
* /admin_api/account/getBySnCode:
|
||||||
|
* post:
|
||||||
|
* summary: 通过设备SN码获取账号信息
|
||||||
|
* description: 根据设备SN码直接获取对应的账号信息
|
||||||
|
* tags: [后台-账号管理]
|
||||||
|
* requestBody:
|
||||||
|
* required: true
|
||||||
|
* content:
|
||||||
|
* application/json:
|
||||||
|
* schema:
|
||||||
|
* type: object
|
||||||
|
* required:
|
||||||
|
* - sn_code
|
||||||
|
* properties:
|
||||||
|
* sn_code:
|
||||||
|
* type: string
|
||||||
|
* description: 设备SN码
|
||||||
|
* responses:
|
||||||
|
* 200:
|
||||||
|
* description: 获取成功
|
||||||
|
*/
|
||||||
|
'POST /account/getBySnCode': async (ctx) => {
|
||||||
|
const { sn_code } = ctx.getBody();
|
||||||
|
const accountData = await plaAccountService.getAccountBySnCode(sn_code);
|
||||||
|
return ctx.success(accountData);
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* @swagger
|
* @swagger
|
||||||
* /admin_api/account/list:
|
* /admin_api/account/list:
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const db = require('../dbProxy.js');
|
const db = require('../dbProxy.js');
|
||||||
|
const logProxy = require('../logProxy.js');
|
||||||
const deviceManager = require('../schedule/deviceManager.js');
|
const deviceManager = require('../schedule/deviceManager.js');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -192,7 +193,7 @@ class MqttDispatcher {
|
|||||||
heartbeatData = JSON.parse(message);
|
heartbeatData = JSON.parse(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { sn_code, timestamp, status, memory, platform_status, platform_login_status } = heartbeatData;
|
const { sn_code, timestamp, status, memory, platform_status, platform_login_status,clientId } = heartbeatData;
|
||||||
|
|
||||||
if (!sn_code) {
|
if (!sn_code) {
|
||||||
console.warn('[MQTT心跳] 心跳消息中未找到设备SN码');
|
console.warn('[MQTT心跳] 心跳消息中未找到设备SN码');
|
||||||
@@ -232,6 +233,7 @@ class MqttDispatcher {
|
|||||||
loggedInUsername = platform_login_status.username || '';
|
loggedInUsername = platform_login_status.username || '';
|
||||||
loggedInUserId = platform_login_status.user_id || null;
|
loggedInUserId = platform_login_status.user_id || null;
|
||||||
|
|
||||||
|
|
||||||
if (platform_login_status.timestamp) {
|
if (platform_login_status.timestamp) {
|
||||||
loginTime = new Date(platform_login_status.timestamp);
|
loginTime = new Date(platform_login_status.timestamp);
|
||||||
}
|
}
|
||||||
@@ -266,19 +268,11 @@ class MqttDispatcher {
|
|||||||
if (device) {
|
if (device) {
|
||||||
await device_status.update(updateData, { where: { sn_code } });
|
await device_status.update(updateData, { where: { sn_code } });
|
||||||
console.log(`[MQTT心跳] 设备 ${sn_code} 状态已更新 - 在线: true, 登录: ${updateData.isLoggedIn}`);
|
console.log(`[MQTT心跳] 设备 ${sn_code} 状态已更新 - 在线: true, 登录: ${updateData.isLoggedIn}`);
|
||||||
} else {
|
}
|
||||||
// 创建新设备记录
|
else
|
||||||
await device_status.create({
|
{
|
||||||
sn_code,
|
logProxy.error('[MQTT心跳] 设备 ${sn_code} 不存在', { sn_code });
|
||||||
deviceName: `设备_${sn_code}`,
|
return;
|
||||||
deviceType: 'node_mqtt_client',
|
|
||||||
...updateData,
|
|
||||||
isRunning: false,
|
|
||||||
taskStatus: 'idle',
|
|
||||||
healthStatus: 'unknown',
|
|
||||||
healthScore: 0
|
|
||||||
});
|
|
||||||
console.log(`[MQTT心跳] 设备 ${sn_code} 记录已创建 - 在线: true, 登录: ${updateData.isLoggedIn}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 记录心跳到设备管理器
|
// 记录心跳到设备管理器
|
||||||
|
|||||||
@@ -37,6 +37,46 @@ class PlaAccountService {
|
|||||||
return accountData;
|
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 - 查询参数
|
* @param {Object} params - 查询参数
|
||||||
|
|||||||
Reference in New Issue
Block a user