1
This commit is contained in:
@@ -87,16 +87,6 @@ module.exports = {
|
|||||||
// 统一邮箱地址为小写
|
// 统一邮箱地址为小写
|
||||||
const email_normalized = email.toLowerCase().trim();
|
const email_normalized = email.toLowerCase().trim();
|
||||||
|
|
||||||
// 验证邮箱格式
|
|
||||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
||||||
if (!emailRegex.test(email_normalized)) {
|
|
||||||
return ctx.fail('邮箱格式不正确');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证密码长度
|
|
||||||
if (password.length < 6 || password.length > 50) {
|
|
||||||
return ctx.fail('密码长度不正确');
|
|
||||||
}
|
|
||||||
|
|
||||||
const { pla_account } = await Framework.getModels();
|
const { pla_account } = await Framework.getModels();
|
||||||
|
|
||||||
|
|||||||
@@ -300,6 +300,40 @@ class MqttDispatcher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理来自 boss-automation-nodejs 的 Boss 聊天消息
|
||||||
|
* @param {object|string} message - Boss 消息对象或 JSON 字符串
|
||||||
|
*/
|
||||||
|
async handleBossMessage(message) {
|
||||||
|
try {
|
||||||
|
let data = message;
|
||||||
|
if (typeof message === 'string') {
|
||||||
|
try {
|
||||||
|
data = JSON.parse(message);
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('[MQTT Boss 消息] JSON 解析失败,按原始字符串处理');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const sn_code = data && data.sn_code ? data.sn_code : null;
|
||||||
|
const payload = data && data.payload ? data.payload : null;
|
||||||
|
|
||||||
|
if (!sn_code || !payload) {
|
||||||
|
console.warn('[MQTT Boss 消息] sn_code 或 payload 缺失,忽略:', data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`[MQTT Boss 消息] 收到设备 ${sn_code} 的新消息,payload 长度:`, typeof payload === 'string' ? payload.length : 'object');
|
||||||
|
|
||||||
|
// TODO: 这里可以根据业务需要:
|
||||||
|
// - 写入 chat_message / chat_reply_intent_log 等表
|
||||||
|
// - 触发 AI 自动回复流程
|
||||||
|
// 当前先只是打印日志,预留扩展点。
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[MQTT Boss 消息] 处理 Boss 消息失败:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理响应消息
|
* 处理响应消息
|
||||||
* @param {object|string} message - 响应消息对象或JSON字符串
|
* @param {object|string} message - 响应消息对象或JSON字符串
|
||||||
|
|||||||
@@ -130,6 +130,17 @@ class ScheduleManager {
|
|||||||
console.error('[调度管理器] 处理响应消息失败:', error);
|
console.error('[调度管理器] 处理响应消息失败:', error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 订阅 Boss 聊天消息主题,将 boss-automation-nodejs 转发过来的新消息交给 mqttDispatcher 处理
|
||||||
|
this.mqttClient.subscribe("boss/message", async (topic, message) => {
|
||||||
|
try {
|
||||||
|
if (this.mqttDispatcher && typeof this.mqttDispatcher.handleBossMessage === 'function') {
|
||||||
|
await this.mqttDispatcher.handleBossMessage(message);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[调度管理器] 处理 Boss 消息失败:', error);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user