236 lines
6.1 KiB
Markdown
236 lines
6.1 KiB
Markdown
# 指令流程映射关系文档
|
||
|
||
## 📋 完整的指令执行流程
|
||
|
||
本文档说明从 Admin 前端到 boss-automation-nodejs 的完整指令映射关系。
|
||
|
||
## 🔄 执行流程图
|
||
|
||
```
|
||
Admin 前端 (pla_account_detail.vue)
|
||
↓ commandType
|
||
plaAccountServer.runCommand()
|
||
↓ HTTP POST
|
||
后端 API (pla_account.js)
|
||
↓ taskType
|
||
taskQueue.addTask()
|
||
↓
|
||
taskQueue.getTaskCommands()
|
||
↓ command_type
|
||
command.executeCommand()
|
||
↓
|
||
jobManager[command_type]()
|
||
↓ MQTT action
|
||
boss-automation-nodejs
|
||
↓
|
||
BossService[action]()
|
||
```
|
||
|
||
## 📊 完整映射表
|
||
|
||
| Admin commandType | taskType | command_type | MQTT action | Boss 方法 | 说明 |
|
||
|------------------|----------|--------------|-------------|-----------|------|
|
||
| `get_login_qr_code` | `get_login_qr_code` | `getLoginQrCode` | `get_login_qr_code` | `get_login_qr_code()` | 获取登录二维码 |
|
||
| `openBotDetection` | `openBotDetection` | `openBotDetection` | `openBotDetection` | `openBotDetection()` | 打开测试页 |
|
||
| `get_resume` | `get_resume` | `getOnlineResume` | `get_resume` | `get_resume()` | 获取用户简历 |
|
||
| `get_user_info` | `get_user_info` | `getUserInfo` | `get_user_info` | `get_user_info()` | 获取用户信息 |
|
||
| `search_jobs` | `search_jobs` | `searchJob` | `search_jobs` | `search_jobs()` | 搜索岗位 |
|
||
| `getJobList` | `getJobList` | `getJobList` | `getJobList` | `getJobList()` | 获取岗位列表 |
|
||
| `getChatList` | `getChatList` | `getChatList` | `getChatList` | `getChatList()` | 获取聊天列表 |
|
||
|
||
## 🔍 详细说明
|
||
|
||
### 1. Admin 前端 (commandType)
|
||
|
||
在 `pla_account_detail.vue` 中定义的操作类型:
|
||
|
||
```javascript
|
||
actionMenuList: [
|
||
{
|
||
value: 'get_login_qr_code',
|
||
label: '用户登录',
|
||
commandType: 'get_login_qr_code',
|
||
commandName: '获取登录二维码'
|
||
},
|
||
{
|
||
value: 'getJobList',
|
||
label: '岗位列表',
|
||
commandType: 'getJobList',
|
||
commandName: '获取岗位列表'
|
||
},
|
||
// ...
|
||
]
|
||
```
|
||
|
||
### 2. 后端 API (taskType)
|
||
|
||
在 `pla_account.js` 中,`commandType` 直接作为 `taskType` 传递:
|
||
|
||
```javascript
|
||
const task = await task_status.create({
|
||
sn_code: account.sn_code,
|
||
taskType: commandConfig.type, // 使用 commandType
|
||
taskName: commandName || commandConfig.name,
|
||
taskParams: JSON.stringify(finalParams)
|
||
});
|
||
```
|
||
|
||
### 3. 任务队列 (command_type)
|
||
|
||
在 `taskQueue.js` 的 `getTaskCommands()` 方法中,将 `taskType` 映射为 `command_type`:
|
||
|
||
```javascript
|
||
async getTaskCommands(task) {
|
||
const { taskType, taskParams } = task;
|
||
|
||
switch (taskType) {
|
||
case 'get_login_qr_code':
|
||
return [{
|
||
command_type: 'getLoginQrCode', // jobManager 方法名
|
||
command_name: '获取登录二维码',
|
||
command_params: JSON.stringify({ platform })
|
||
}];
|
||
|
||
case 'getJobList':
|
||
return [{
|
||
command_type: 'getJobList', // jobManager 方法名
|
||
command_name: '获取岗位列表',
|
||
command_params: JSON.stringify({ keyword, platform })
|
||
}];
|
||
|
||
// ...
|
||
}
|
||
}
|
||
```
|
||
|
||
### 4. 指令管理器 (jobManager 方法)
|
||
|
||
在 `command.js` 中调用 `jobManager` 的方法:
|
||
|
||
```javascript
|
||
async executeCommand(taskId, command, mqttClient) {
|
||
const commandType = command.command_type;
|
||
const commandParams = JSON.parse(command.command_params);
|
||
|
||
// 调用 jobManager 的方法
|
||
if (commandType && jobManager[commandType]) {
|
||
result = await jobManager[commandType](sn_code, mqttClient, commandParams);
|
||
}
|
||
}
|
||
```
|
||
|
||
### 5. MQTT 通信 (action)
|
||
|
||
在 `jobManager.js` 中,通过 MQTT 发送指令:
|
||
|
||
```javascript
|
||
async getJobList(sn_code, mqttClient, params = {}) {
|
||
const response = await mqttClient.publishAndWait(sn_code, {
|
||
platform: 'boss',
|
||
action: "getJobList", // MQTT action,对应 Boss 方法名
|
||
data: { keyword, pageCount }
|
||
});
|
||
return response.data;
|
||
}
|
||
```
|
||
|
||
### 6. Boss 模块执行
|
||
|
||
在 `boss-automation-nodejs` 中,根据 `action` 调用对应方法:
|
||
|
||
```javascript
|
||
// modules/index.js
|
||
async executeAction(platform, action, data) {
|
||
const modules = this.getModules();
|
||
|
||
// 调用 BossService[action]
|
||
let result = await modules[platform][action](data);
|
||
return result;
|
||
}
|
||
```
|
||
|
||
## ⚠️ 关键注意事项
|
||
|
||
### 1. 命名一致性
|
||
|
||
- **Admin commandType** → 用户界面显示的操作类型
|
||
- **taskType** → 任务类型,与 commandType 相同
|
||
- **command_type** → jobManager 中的方法名(驼峰命名)
|
||
- **MQTT action** → Boss 模块中的方法名(可能有别名)
|
||
|
||
### 2. 参数传递
|
||
|
||
参数在整个流程中的传递:
|
||
|
||
```javascript
|
||
// Admin 前端
|
||
commandParams: { keyword: '前端', platform: 'boss' }
|
||
↓
|
||
// taskParams
|
||
taskParams: { keyword: '前端', platform: 'boss' }
|
||
↓
|
||
// command_params
|
||
command_params: '{"keyword":"前端","platform":"boss"}'
|
||
↓
|
||
// jobManager 方法参数
|
||
params: { keyword: '前端', platform: 'boss' }
|
||
↓
|
||
// MQTT data
|
||
data: { keyword: '前端', pageCount: 3 }
|
||
↓
|
||
// Boss 方法参数
|
||
data: { keyword: '前端', pageCount: 3 }
|
||
```
|
||
|
||
### 3. 别名支持
|
||
|
||
Boss 模块中的别名方法:
|
||
|
||
```javascript
|
||
// BossService 类中
|
||
async openBotDetection(data) {
|
||
return this.open_bot_detection(data);
|
||
}
|
||
|
||
async get_resume(data) {
|
||
return this.getOnlineResume(data);
|
||
}
|
||
|
||
async search_jobs(data) {
|
||
return this.searchJob(data);
|
||
}
|
||
```
|
||
|
||
## 🐛 常见问题
|
||
|
||
### Q1: 提示"未知的指令类型"
|
||
|
||
**原因:** `command_type` 在 `jobManager` 中不存在
|
||
|
||
**解决:**
|
||
1. 检查 `taskQueue.js` 中的 `getTaskCommands()` 方法
|
||
2. 确保 `command_type` 与 `jobManager` 中的方法名一致
|
||
|
||
### Q2: MQTT 消息发送失败
|
||
|
||
**原因:** `action` 在 Boss 模块中不存在
|
||
|
||
**解决:**
|
||
1. 检查 `jobManager.js` 中的 MQTT action
|
||
2. 确保 Boss 模块中有对应的方法或别名
|
||
|
||
### Q3: 参数传递错误
|
||
|
||
**原因:** 参数格式不正确
|
||
|
||
**解决:**
|
||
1. 确保 `command_params` 是 JSON 字符串
|
||
2. 在 `jobManager` 中正确解析参数
|
||
3. 在 MQTT 消息中正确传递参数
|
||
|
||
---
|
||
|
||
**创建时间**: 2025-11-13
|
||
**作者**: Augment Agent
|
||
|