HealthController.java
9.12 KB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
package com.iot.scheduler.controller;
import com.iot.scheduler.service.DevicePullService;
import com.iot.scheduler.service.DeviceSearchService;
import com.iot.scheduler.service.EnergyPullService;
import com.iot.scheduler.service.EnergySearchService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Collections;
import java.util.Map;
@RestController
public class HealthController {
@Resource
private DevicePullService devicePullService;
@Resource
private DeviceSearchService deviceSearchService;
@Resource
private EnergySearchService energySearchService;
@Resource
private EnergyPullService energyPullService;
/**
* corpCode为空时的统一空数据响应
*/
private static Map<String, Object> emptyResult() {
return Collections.emptyMap();
}
@GetMapping("/health")
public String health(@RequestParam(required = false) String corpCode) throws Exception {
if (!isValidCorpCode(corpCode)) return "corpCode不能为空";
devicePullService.pullDeviceAndPushToIot(corpCode);
return "IoT Scheduler is running...";
}
@GetMapping("/device/list")
public Map<String, Object> deviceList(
@RequestParam(required = false) String corpCode,
@RequestParam(required = false) String deviceName,
@RequestParam(required = false) String lampState,
@RequestParam(defaultValue = "1") Integer pageNo,
@RequestParam(defaultValue = "10") Integer pageSize) {
if (!isValidCorpCode(corpCode)) return emptyResult();
return deviceSearchService.queryDeviceList(corpCode, deviceName, lampState, pageNo, pageSize);
}
@GetMapping("/device/stats")
public Map<String, Object> deviceStats(@RequestParam(required = false) String corpCode) {
if (!isValidCorpCode(corpCode)) return emptyResult();
return deviceSearchService.queryDeviceStats(corpCode);
}
@GetMapping("/device/lampData")
public Map<String, Object> lampData(
@RequestParam(required = false) String corpCode,
@RequestParam String dtuSn,
@RequestParam String date) {
if (!isValidCorpCode(corpCode)) return emptyResult();
return deviceSearchService.queryLampData(corpCode, dtuSn, date);
}
@GetMapping("/device/syncDevUtil")
public String syncDevUtil(@RequestParam(required = false) String corpCode) {
if (!isValidCorpCode(corpCode)) return "corpCode不能为空";
devicePullService.pullDevUtilAndSave(corpCode);
return "设备利用率数据同步完成";
}
@GetMapping("/device/syncOee")
public String syncOee(@RequestParam(required = false) String corpCode) {
if (!isValidCorpCode(corpCode)) return "corpCode不能为空";
devicePullService.pullOeeAndSave(corpCode);
return "OEE时序数据同步完成";
}
@GetMapping("/device/oeeStats")
public Map<String, Object> oeeStats(
@RequestParam(required = false) String corpCode,
@RequestParam String dtuSn,
@RequestParam(defaultValue = "day") String type,
@RequestParam(required = false) String startDate,
@RequestParam(required = false) String endDate) {
if (!isValidCorpCode(corpCode)) return emptyResult();
return deviceSearchService.queryOeeStats(corpCode, dtuSn, type, startDate, endDate);
}
/**
* OEE时序图分页查询(含稼动率)
*/
@GetMapping("/device/oeeTimeline")
public Map<String, Object> oeeTimeline(
@RequestParam(required = false) String corpCode,
@RequestParam String startDate,
@RequestParam String endDate,
@RequestParam(defaultValue = "1") Integer pageNo,
@RequestParam(defaultValue = "20") Integer pageSize) {
if (!isValidCorpCode(corpCode)) return emptyResult();
return deviceSearchService.queryOeeTimeline(corpCode, startDate, endDate, pageNo, pageSize);
}
/**
* 智能灯统计稼动率查询(仪表盘)
*/
@GetMapping("/device/lampStatistics")
public Map<String, Object> lampStatistics(
@RequestParam(required = false) String corpCode,
@RequestParam(required = false) String startDate,
@RequestParam(required = false) String endDate) {
if (!isValidCorpCode(corpCode)) return emptyResult();
return deviceSearchService.queryLampStatistics(corpCode, startDate, endDate);
}
/**
* 开机率查询(基于 dev_util 表)
*/
@GetMapping("/device/bootRate")
public Map<String, Object> bootRate(
@RequestParam(required = false) String corpCode,
@RequestParam String startDate,
@RequestParam String endDate) {
if (!isValidCorpCode(corpCode)) return emptyResult();
return deviceSearchService.queryBootRate(corpCode, startDate, endDate);
}
@GetMapping("/energy/history")
public void energyHistory(@RequestParam(required = false) String corpCode) {
if (isValidCorpCode(corpCode)) energyPullService.pullEnergyHistoryAndSave(corpCode);
}
/**
* 分页查询能耗设备信息
*/
@GetMapping("/energy/list")
public Map<String, Object> energyList(
@RequestParam(required = false) String corpCode,
@RequestParam(required = false) String deviceName,
@RequestParam(required = false) String runStatus,
@RequestParam(defaultValue = "1") Integer pageNo,
@RequestParam(defaultValue = "10") Integer pageSize) {
if (!isValidCorpCode(corpCode)) return emptyResult();
return energySearchService.queryEnergyList(corpCode, deviceName, runStatus, pageNo, pageSize);
}
@GetMapping("/energy/stats")
public Map<String, Object> energyStats(@RequestParam(required = false) String corpCode) {
if (!isValidCorpCode(corpCode)) return emptyResult();
return energySearchService.queryEnergyStats(corpCode);
}
/**
* 根据dtuSn查询指定日期的设备时用电量和OEE时序
*/
@GetMapping("/energy/detail")
public Map<String, Object> energyDetail(
@RequestParam(required = false) String corpCode,
@RequestParam String dtuSn,
@RequestParam String date) {
if (!isValidCorpCode(corpCode)) return emptyResult();
return energySearchService.queryEnergyDetailByDate(corpCode, dtuSn, date);
}
/**
* 根据dtuSn查询指定设备的运行时长明细
*/
@GetMapping("/energy/runtimeDetail")
public Map<String, Object> energyRuntimeDetail(
@RequestParam(required = false) String corpCode,
@RequestParam String dtuSn,
@RequestParam(defaultValue = "1") String type,
@RequestParam(required = false) String startDate,
@RequestParam(required = false) String endDate) {
if (!isValidCorpCode(corpCode)) return emptyResult();
return energySearchService.queryEnergyRuntimeDetail(corpCode, dtuSn, type, startDate, endDate);
}
/**
* 查询能耗时序状态 - 分页查询
*/
@GetMapping("/energy/timelineStatus")
public Map<String, Object> energyTimelineStatus(
@RequestParam(required = false) String corpCode,
@RequestParam String date,
@RequestParam(defaultValue = "1") Integer pageNo,
@RequestParam(defaultValue = "12") Integer pageSize) {
if (!isValidCorpCode(corpCode)) return emptyResult();
return energySearchService.queryEnergyTimelineStatus(corpCode, date, pageNo, pageSize);
}
/**
* eq_kwh综合统计查询
*/
@GetMapping("/energy/eqKwhStatistics")
public Map<String, Object> eqKwhStatistics(
@RequestParam(required = false) String corpCode,
@RequestParam String startDate,
@RequestParam String endDate) {
if (!isValidCorpCode(corpCode)) return emptyResult();
return energySearchService.queryEqKwhStatistics(corpCode, startDate, endDate);
}
/**
* 查询eq_kwh多设备能耗数据(按 时/日/月 聚合)
*/
@GetMapping("/energy/eqKwhByType")
public Map<String, Object> eqKwhByType(
@RequestParam(required = false) String corpCode,
@RequestParam(defaultValue = "1") String type,
@RequestParam(required = false) String startDate,
@RequestParam(required = false) String endDate) {
if (!isValidCorpCode(corpCode)) return emptyResult();
return energySearchService.queryEqKwhByType(corpCode, type, startDate, endDate);
}
/**
* 调试:查看eq_kwh表中的数据概况
*/
@GetMapping("/energy/debug/eqKwhInfo")
public Map<String, Object> debugEqKwhInfo(@RequestParam(required = false) String corpCode) {
if (!isValidCorpCode(corpCode)) return emptyResult();
return energySearchService.debugEqKwhInfo(corpCode);
}
private boolean isValidCorpCode(String corpCode) {
return corpCode != null && !corpCode.trim().isEmpty();
}
}