fix: 电话报警通知逻辑修改。

This commit is contained in:
tianyongbao
2026-03-07 22:13:40 +08:00
parent b5963e0948
commit ec148bd203
14 changed files with 557 additions and 1294 deletions

View File

@@ -38,6 +38,7 @@ import com.intc.iot.service.IotDeviceService;
import com.intc.iot.service.MqttService;
import com.intc.iot.service.VmsMnsConsumerService;
import com.intc.iot.service.VmsNoticeService;
import com.intc.iot.handler.DeviceDataHandler;
import com.intc.iot.service.WarnCallNoticeService;
import com.intc.iot.utils.AliyunAmqpSignUtil;
import com.intc.iot.utils.ControllerHelper;
@@ -95,6 +96,9 @@ public class IotController extends BaseController {
@Autowired(required = false)
private WarnCallNoticeService warnCallNoticeService;
@Autowired(required = false)
private DeviceDataHandler deviceDataHandler;
@Autowired(required = false)
private javax.jms.Connection amqpConnection;
@@ -588,6 +592,66 @@ public class IotController extends BaseController {
}
}
// ======================== 模拟报警触发接口 ========================
/**
* 模拟设备数据上报,触发报警和打电话流程。
* 接口会伪造一条 MQTT 属性上报消息,携带你指定的传感器值,
* 走完整的「数据解析 → 阈值判断 → 告警记录 → VMS语音呼叫」链路。
*
* @param deviceName 设备序列号(需在数据库中存在,且已配置手机号和告警阈值)
* @param dissolvedOxygen 溶解氧值mg/L不传则使用默认值 1.0(低于通常阈值,触发告警)
* @param temperature 水温值°C不传则不设置
* @param battery 电量(%),不传则不设置
*/
@Operation(summary = "模拟告警触发(测试打电话)",
description = "构造超阈值传感器数据走完整告警→VMS语音呼叫链路")
@PostMapping("/alarm/simulate")
public R<Map<String, Object>> simulateAlarm(
@Parameter(description = "设备序列号serialNum") @RequestParam String deviceName,
@Parameter(description = "溶解氧值默认1.0触发低溶解氧告警") @RequestParam(required = false) Double dissolvedOxygen,
@Parameter(description = "水温值,可选") @RequestParam(required = false) Double temperature,
@Parameter(description = "电池电量%,可选") @RequestParam(required = false) Double battery) {
try {
if (deviceDataHandler == null) {
return R.fail("DeviceDataHandler 未启用IDeviceSensorDataService 未加载)");
}
// 默认溶解氧给一个极低值,保证能触发告警
double doValue = dissolvedOxygen != null ? dissolvedOxygen : 1.0;
// 构造飞燕平台属性上报的标准 payload
// Topic 格式: /sys/{productKey}/{deviceName}/thing/event/property/post
// 这里 productKey 随便填一个非控制器的值,让它走普通传感器处理分支
String mockProductKey = "simulate";
String mockTopic = "/sys/" + mockProductKey + "/" + deviceName + "/thing/event/property/post";
// 构造 params JSON字段数 > 3 以通过过滤条件
cn.hutool.json.JSONObject params = new cn.hutool.json.JSONObject();
params.set("dissolvedOxygen", doValue);
params.set("temperature", temperature != null ? temperature : 25.0);
params.set("battery", battery != null ? battery : 80.0);
params.set("saturability", 50.0); // 补足字段数 > 3
cn.hutool.json.JSONObject payload = new cn.hutool.json.JSONObject();
payload.set("params", params);
log.info("[模拟告警] deviceName={}, topic={}, payload={}", deviceName, mockTopic, payload);
// 调用真实的属性处理方法,走完整链路
deviceDataHandler.handlePropertyPost(mockTopic, payload.toString());
Map<String, Object> result = new java.util.HashMap<>();
result.put("mockTopic", mockTopic);
result.put("mockPayload", payload.toString());
result.put("message", "模拟消息已发送,请查看日志确认告警和呼叫是否触发");
return R.ok(result);
} catch (Exception e) {
log.error("模拟告警触发失败: {}", e.getMessage(), e);
return R.fail("模拟告警触发失败: " + e.getMessage());
}
}
// ======================== VMS 语音通知相关接口 ========================
@Operation(summary = "发送语音通知(测试接口)")