Merge pull request '删除过时文件' (#29) from junmao_branch into develop
commit
71410741b7
@ -1,34 +0,0 @@
|
||||
package com.campus.water.web.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/admin/monitor")
|
||||
public class MonitorController {
|
||||
@Autowired
|
||||
private RealTimeService realTimeService;
|
||||
@Autowired
|
||||
private HistoryDataService historyDataService;
|
||||
|
||||
@GetMapping("/realTime/{deviceId}")
|
||||
public Object getRealTimeData(@PathVariable String deviceId) {
|
||||
return realTimeService.getRealTimeData(deviceId);
|
||||
}
|
||||
|
||||
@GetMapping("/realTime/all")
|
||||
public List<Object> getAllRealTimeData() {
|
||||
return realTimeService.getAllRealTimeData();
|
||||
}
|
||||
|
||||
@GetMapping("/history/{deviceId}")
|
||||
public List<Object> getHistoryData(
|
||||
@PathVariable String deviceId,
|
||||
@RequestParam String startTime,
|
||||
@RequestParam String endTime
|
||||
) {
|
||||
return historyDataService.getHistoryData(deviceId, startTime, endTime);
|
||||
}
|
||||
}
|
||||
@ -1,30 +0,0 @@
|
||||
package com.campus.water.web;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Service
|
||||
public class RealTimeService {
|
||||
|
||||
private ConcurrentHashMap<String, Object> realTimeData = new ConcurrentHashMap<>();
|
||||
private List<Object> alerts = new ArrayList<>();
|
||||
|
||||
public void updateRealTimeData(Object sensorData) {
|
||||
System.out.println("更新实时数据");
|
||||
}
|
||||
|
||||
public void addAlert(Object alertData) {
|
||||
alerts.add(alertData);
|
||||
System.out.println("添加告警");
|
||||
}
|
||||
|
||||
public Object getRealTimeData(String deviceId) {
|
||||
return realTimeData.get(deviceId);
|
||||
}
|
||||
|
||||
public List<Object> getAllRealTimeData() {
|
||||
return new ArrayList<>(realTimeData.values());
|
||||
}
|
||||
}
|
||||
@ -1,86 +0,0 @@
|
||||
package com.campus.water.mqtt.core;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import org.eclipse.paho.client.mqttv3.MqttClient;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class DataForwarder {
|
||||
@Autowired
|
||||
private MqttClient mqttClient;
|
||||
|
||||
public void forwardToWeb(Map<String, Object> sensorData) throws Exception {
|
||||
String deviceId = (String) sensorData.get("deviceId");
|
||||
String topic = "forward/web/device/" + deviceId;
|
||||
String payload = JSONObject.toJSONString(sensorData);
|
||||
publish(topic, payload, 0);
|
||||
System.out.println("转发到管理Web: " + deviceId);
|
||||
}
|
||||
|
||||
public void forwardToWeb(Map<String, Object> alertData, boolean isAlert) throws Exception {
|
||||
String deviceId = (String) alertData.get("deviceId");
|
||||
String topic = "forward/web/alert/" + deviceId;
|
||||
String payload = JSONObject.toJSONString(alertData);
|
||||
publish(topic, payload, 1);
|
||||
System.out.println("转发告警到管理Web: " + deviceId);
|
||||
}
|
||||
|
||||
public void forwardToStudentApp(Map<String, Object> sensorData) throws Exception {
|
||||
Integer deviceType = (Integer) sensorData.get("deviceType");
|
||||
if (deviceType != 1) return;
|
||||
|
||||
String deviceId = (String) sensorData.get("deviceId");
|
||||
String terminalId = getRelatedTerminalId(deviceId);
|
||||
String topic = "forward/student/terminal/" + terminalId;
|
||||
|
||||
Double tdsValue = (Double) sensorData.get("tdsValue");
|
||||
String payload = JSONObject.toJSONString(new JSONObject() {{
|
||||
put("terminalId", terminalId);
|
||||
put("tdsValue", tdsValue);
|
||||
put("waterQuality", getWaterQuality(tdsValue));
|
||||
put("timestamp", sensorData.get("timestamp"));
|
||||
}});
|
||||
publish(topic, payload, 0);
|
||||
System.out.println("转发到学生APP: " + terminalId);
|
||||
}
|
||||
|
||||
public void forwardToRepairApp(Map<String, Object> sensorData) throws Exception {
|
||||
String areaId = (String) sensorData.get("areaId");
|
||||
String deviceId = (String) sensorData.get("deviceId");
|
||||
String topic = "forward/repair/area/" + areaId + "/device/" + deviceId;
|
||||
String payload = JSONObject.toJSONString(sensorData);
|
||||
publish(topic, payload, 0);
|
||||
System.out.println("转发到维修APP: " + deviceId);
|
||||
}
|
||||
|
||||
public void forwardToRepairApp(Map<String, Object> alertData, boolean isAlert) throws Exception {
|
||||
String areaId = (String) alertData.get("areaId");
|
||||
String deviceId = (String) alertData.get("deviceId");
|
||||
String topic = "forward/repair/area/" + areaId + "/alert/" + deviceId;
|
||||
String payload = JSONObject.toJSONString(alertData);
|
||||
publish(topic, payload, 1);
|
||||
System.out.println("转发告警到维修APP: " + deviceId);
|
||||
}
|
||||
|
||||
private void publish(String topic, String payload, int qos) throws Exception {
|
||||
MqttMessage message = new MqttMessage(payload.getBytes());
|
||||
message.setQos(qos);
|
||||
mqttClient.publish(topic, message);
|
||||
}
|
||||
|
||||
private String getRelatedTerminalId(String deviceId) {
|
||||
return deviceId.equals("WM001") ? "TERM001" : "TERM002";
|
||||
}
|
||||
|
||||
private String getWaterQuality(Double tds) {
|
||||
if (tds == null) return "未知";
|
||||
if (tds < 50) return "纯净水(无矿物质)";
|
||||
else if (tds < 300) return "优质矿化水";
|
||||
else if (tds < 600) return "合格矿化水";
|
||||
else return "水质超标(不建议饮用)";
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue