Files
SenMeshNet/electron/bridges/inspection/reportScheduleStore.cjs
zhaolei 2f9f8da48e
Some checks failed
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
Initial commit: NetMesh smart ops platform with 3D topology, inspection reports, RCA and AI ops assistant
2026-10-15 13:53:04 +08:00

79 lines
2.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use strict";
/**
* 巡检报告调度配置存储
*
* 存储内容(report-schedule.json):
* {
* enabled: true,
* defaultIntervalHours: 1, // 全局默认巡检周期(小时)
* dailyReportTime: "23:00", // 日运行报告定时触发时间 HH:MM
* enabledDeviceIds: null | string[], // null/undefined = 全部;[] = 一个都不选;["id1","id2"] = 指定
* perDeviceInterval: { host_a: 2 }, // 单设备周期覆盖(小时)
* aiSummaryEnabled: true // AI 汇总分析开关
* }
*/
const { STORAGE_KEY_REPORT_SCHEDULE } = require("./storageKeys.cjs");
const DEFAULTS = {
enabled: false,
defaultIntervalHours: 1,
dailyReportTime: "23:00",
enabledDeviceIds: null, // null = 全部设备(向后兼容旧的 empty array 也按全部处理)
perDeviceInterval: {},
aiSummaryEnabled: true,
};
function _safeParse(raw, def) {
try { return JSON.parse(raw); }
catch { return def; }
}
function _normalize(cfg) {
// 旧数据兼容:undefined enabledDeviceIds → null(全部)
// 新约定:null = 全部;[] = 一个都不选;[id1,id2] = 指定 —— 不主动改动
if (cfg.enabledDeviceIds === undefined) {
cfg.enabledDeviceIds = null;
}
return cfg;
}
function getSchedule(readFn) {
const raw = readFn(STORAGE_KEY_REPORT_SCHEDULE);
if (!raw) return _normalize({ ...DEFAULTS });
const parsed = _safeParse(raw, {});
return _normalize({ ...DEFAULTS, ...parsed });
}
function saveSchedule(writeFn, config) {
const merged = _normalize({ ...DEFAULTS, ...config });
writeFn(STORAGE_KEY_REPORT_SCHEDULE, JSON.stringify(merged, null, 2));
return merged;
}
function getIntervalHours(readFn, deviceId) {
const cfg = getSchedule(readFn);
if (cfg.perDeviceInterval && cfg.perDeviceInterval[deviceId]) {
return Number(cfg.perDeviceInterval[deviceId]) || cfg.defaultIntervalHours;
}
return cfg.defaultIntervalHours;
}
function isDeviceEnabled(readFn, deviceId) {
const cfg = getSchedule(readFn);
if (!cfg.enabled) return false;
// null/undefined = 全部;空数组 = 都不选;非空数组 = 白名单
if (!cfg.enabledDeviceIds) return true;
if (cfg.enabledDeviceIds.length === 0) return false;
return cfg.enabledDeviceIds.includes(deviceId);
}
module.exports = {
DEFAULTS,
getSchedule,
saveSchedule,
getIntervalHours,
isDeviceEnabled,
};