import request from "@/utils/request"; /** 能耗数据列表查询 */ export function listStatisticEle(query) { return request({ url: "/statisticEle/list", method: "get", params: query, }); } /** 能耗汇总统计 */ export function summaryStatisticEle(query) { return request({ url: "/statisticEle/summary", method: "get", params: query, }); } /** 能耗综合分析 */ export function analyticsStatisticEle(query) { return request({ url: "/statisticEle/analytics", method: "get", params: query, }); } /** 昨日用电量汇总 */ export function getYesterdaySummary() { return request({ url: "/statisticEle/yesterday", method: "get", }); } /** 获取昨天日期 YYYYMMDD */ export function getYesterdayDayTime() { const d = new Date(); d.setDate(d.getDate() - 1); return formatDayTime(d); } /** 获取昨天日期 YYYY-MM-DD */ export function getYesterdayDayPicker() { const d = new Date(); d.setDate(d.getDate() - 1); return formatDayPicker(d); } /** 同步状态 */ export function getSyncStatus() { return request({ url: "/statisticEle/syncStatus", method: "get", }); } /** 格式化时间为小时维度 YYYYMMDDHH */ export function formatHourTime(date) { const y = date.getFullYear(); const m = String(date.getMonth() + 1).padStart(2, "0"); const d = String(date.getDate()).padStart(2, "0"); const h = String(date.getHours()).padStart(2, "0"); return `${y}${m}${d}${h}`; } /** 格式化时间为天维度 YYYYMMDD */ export function formatDayTime(date) { const y = date.getFullYear(); const m = String(date.getMonth() + 1).padStart(2, "0"); const d = String(date.getDate()).padStart(2, "0"); return `${y}${m}${d}`; } /** 天维度转日期选择器格式 YYYY-MM-DD */ export function formatDayPicker(date) { const y = date.getFullYear(); const m = String(date.getMonth() + 1).padStart(2, "0"); const d = String(date.getDate()).padStart(2, "0"); return `${y}-${m}-${d}`; } /** 格式化时间为月维度 YYYYMM */ export function formatMonthTime(date) { const y = date.getFullYear(); const m = String(date.getMonth() + 1).padStart(2, "0"); return `${y}${m}`; } /** 格式化时间为年维度 YYYY */ export function formatYearTime(date) { return String(date.getFullYear()); } /** 解析时间标识为可读格式 */ export function parseTimeKey(timeKey, dimension) { if (!timeKey) return "-"; if (dimension === "hour" && timeKey.length >= 10) { return `${timeKey.slice(0, 4)}-${timeKey.slice(4, 6)}-${timeKey.slice(6, 8)} ${timeKey.slice(8, 10)}:00`; } if ((dimension === "manual" || dimension === "minute") && timeKey.length >= 12) { return `${timeKey.slice(0, 4)}-${timeKey.slice(4, 6)}-${timeKey.slice(6, 8)} ${timeKey.slice(8, 10)}:${timeKey.slice(10, 12)}`; } if (dimension === "week" && timeKey.includes("W")) { const [y, w] = timeKey.split("W"); return `${y}年 第${Number(w)}周`; } if (dimension === "day" && timeKey.length >= 8) { return `${timeKey.slice(0, 4)}-${timeKey.slice(4, 6)}-${timeKey.slice(6, 8)}`; } if (dimension === "month" && timeKey.length >= 6) { return `${timeKey.slice(0, 4)}-${timeKey.slice(4, 6)}`; } if (dimension === "quarter" && timeKey.includes("Q")) { const [y, q] = timeKey.split("Q"); return `${y}年 第${q}季度`; } if (dimension === "year" && timeKey.length >= 4) { return `${timeKey.slice(0, 4)}年`; } return timeKey; } /** 格式化时间为分钟维度 YYYYMMDDHHmm */ export function formatMinuteTime(date) { const y = date.getFullYear(); const m = String(date.getMonth() + 1).padStart(2, "0"); const d = String(date.getDate()).padStart(2, "0"); const h = String(date.getHours()).padStart(2, "0"); const min = String(date.getMinutes()).padStart(2, "0"); return `${y}${m}${d}${h}${min}`; } /** 时间范围转查询 key(支持分钟精度) */ export function formatRangeStart(date) { return formatMinuteTime(date); } export function formatRangeEnd(date) { return formatMinuteTime(date); } /** 获取最近 N 小时的时间范围 */ export function getRecentHourRange(hours = 24) { const end = new Date(); const start = new Date(end.getTime() - hours * 3600000); return { startTime: formatMinuteTime(start), endTime: formatMinuteTime(end), }; }