完善预警工单数据接入

parent b70ae87b
......@@ -743,7 +743,7 @@ export async function customerDeviceData() {
/**
* 数据集成-预警工单数据集成
* 从飞奕云平台拉取当天空调内机故障记录,按 indoorUnitAlarmId 去重后写入 device_fault 表
* 从飞奕云平台拉取最近 100 条空调内机故障记录,按 indoorUnitAlarmId 去重后写入 device_fault 表
*/
export async function alertWorkData() {
console.log('[预警工单集成] 开始...');
......@@ -755,22 +755,13 @@ export async function alertWorkData() {
}
try {
const todayDate = getTodayDateStr();
// 1. 分页拉取当天所有故障记录
const rows = await fetchAllPages(
(page, limit, extraParams) => getIndoorUnitAlarmErrorHis({
page,
limit,
occurrenceTime: extraParams.occurrenceTime,
}),
{ occurrenceTime: todayDate },
200,
);
// 1. 拉取最近 100 条故障记录(不再限制当天)
const result = await getIndoorUnitAlarmErrorHis({ page: 1, limit: 100 });
const rows: any[] = result?.rows || [];
console.log(`[预警工单集成] 获取 ${rows.length} 条故障记录`);
if (rows.length === 0) {
console.log('[预警工单集成] 当天无故障记录,跳过');
console.log('[预警工单集成] 无故障记录,跳过');
return;
}
......
......@@ -88,8 +88,16 @@ export async function handleDevicePush(deviceId: string, data: any, deviceTime?:
created_at: receivedTime,
});
// 根据设备上报的数据,联动控制空调设备
await controlAcByEnvironment(deviceId, data);
// 根据regionKey查询区域表,若包含文创,则禁用空调控制
const regionRow = await selectOneDataByParam(
TABLENAME.区域表, { id: device.data.region_key },
["name"]
);
// 调用空调控制(非文创区域才允许自动控温)
if (regionRow?.data && !regionRow.data.name?.includes("文创")) {
// 根据设备上报的数据,联动控制空调设备
await controlAcByEnvironment(deviceId, data);
}
return { success: true };
}
......
......@@ -57,7 +57,7 @@ export async function processDeviceData(message) {
const deviceRow = await selectOneDataByParam(
TABLENAME.设备表, { device_id: devEUI}
);
if (!deviceRow) {
if (!deviceRow && !deviceRow.data) {
console.warn(`设备不存在,跳过入库: ${devEUI}`);
return;
}
......@@ -89,8 +89,17 @@ export async function processDeviceData(message) {
console.log(`数据入库成功: 设备 ${devEUI}`);
// 调用空调控制
await controlAcByEnvironment(devEUI, data);
// 根据regionKey查询区域表,若包含文创,则禁用空调控制
if (deviceRow.data && deviceRow.data.region_key) {
const regionRow = await selectOneDataByParam(
TABLENAME.区域表, { id: deviceRow.data.region_key},
["name"]
);
// 调用空调控制(非文创区域才允许自动控温)
if (regionRow?.data && !regionRow.data.name?.includes("文创")) {
await controlAcByEnvironment(devEUI, data);
}
}
} catch (error) {
console.error('数据处理失败:', error);
......
/**
* 定时任务调度器
* - 每分钟执行一次数据同步任务
* - 每 10 分钟执行一次预警工单同步任务
* - 每 6 分钟执行一次预警工单同步任务
* - 内置锁机制,防止任务重叠执行
* - 任务锁死时(超时未释放),会主动强制释放锁,确保后续任务能正常执行
*/
......@@ -123,10 +123,10 @@ const alertTaskLock: TaskLock = {
};
/** 预警工单锁超时(毫秒) */
const ALERT_LOCK_TIMEOUT_MS = 9 * 60 * 1000; // 9 分钟
const ALERT_LOCK_TIMEOUT_MS = 5 * 60 * 1000; // 5 分钟
/** 预警工单执行间隔(毫秒) */
const ALERT_TASK_INTERVAL_MS = 10 * 60 * 1000; // 10 分钟
const ALERT_TASK_INTERVAL_MS = 6 * 60 * 1000; // 6 分钟
/**
* 尝试获取预警工单任务锁
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment