zhangwencui
6 天以前 19f0e68b3fe3cf5244a2b936bfef4e0712bdf025
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
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),
  };
}