fix(优惠券中心):携程全链路调试完成,调试对接逻辑优化,新增设备一键起飞的指令接口,二维码新增类型字段来区分二维码中航线的的用途等逻辑

This commit is contained in:
2025-08-24 11:32:07 +08:00
parent 4b850d35ea
commit 6d9d9f2124
17 changed files with 386 additions and 39 deletions
@@ -214,4 +214,90 @@ public class ApiDeviceController {
public Result<Map> getWayline(@RequestParam String no){
return Result.succeed(orderCenterService.getWaylineByOrderNo(no));
}
/**
* 下发设备指令接口
* 通过设备ID和二维码类型获取航线信息,生成随机订单号,下发指令
*/
@Operation(summary = "下发设备指令")
@PostMapping("/command/{deviceId}")
public Result sendDeviceCommand(@PathVariable("deviceId") String deviceId, @RequestParam(defaultValue = "2") Integer qrcodeType) {
log.info("开始下发设备指令: deviceId={}, qrcodeType={}", deviceId, qrcodeType);
try {
// 1. 生成随机订单号
String orderNo = generateRandomOrderNo();
// 2. 根据设备ID和二维码类型获取二维码信息
Map<String, Object> qrcodeResult = orderCenterService.getQrcodeByDeviceId(deviceId, qrcodeType);
if (qrcodeResult == null || qrcodeResult.isEmpty()) {
return Result.failed("未找到对应的二维码配置");
}
// 3. 构建控制消息(使用默认的control参数)
JsonObject controlMessage = buildCommandMessage(orderNo, deviceId, qrcodeResult);
if (controlMessage == null) {
return Result.failed("暂未开放控制权限");
}
// 4. 发送设备控制请求
String url = baseUrl + "/device/instance/" + deviceId + "/property";
Map<String, String> result = requestUtils.getPostRequestResultMap(url, controlMessage.toString());
// 5. 处理响应结果
return handleDeviceResponse(result, orderNo);
} catch (Exception e) {
log.error("下发设备指令异常: deviceId={}, error={}", deviceId, e.getMessage(), e);
return Result.failed("系统异常");
}
}
/**
* 生成随机订单号
*/
private String generateRandomOrderNo() {
return "CMD_" + System.currentTimeMillis() + "_" + (int)(Math.random() * 1000);
}
/**
* 构建指令消息
*/
private JsonObject buildCommandMessage(String orderNo, String deviceId, Map<String, Object> qrcodeResult) {
// 使用默认的control参数,这里可以根据需要修改
String control = "camera_photo_take"; // 默认使用拍照指令
if (!ControlEnum.contains(ControlEnum.valueOf(control.toUpperCase()))) {
return null;
}
Gson gson = new Gson();
JsonObject jsonObject = gson.fromJson(controlMessageConstant.CONTROL_MESSAGE_MAP.get(control), JsonObject.class);
JsonObject data = jsonObject.getAsJsonObject("data");
// 设置订单信息
data.addProperty("order_no", orderNo);
// 设置航线信息
String waylineFilePath = MapUtil.getStrValue(qrcodeResult, "waylineFilePath");
String waylineId = MapUtil.getStrValue(qrcodeResult, "waylineId");
log.info("waylineFilePath:{}, waylineId:{}", waylineFilePath, waylineId);
data.addProperty("wayline_link_url", waylineFilePath);
LineFile lineFile = lineFileService.findLineFileByWaylineId(waylineId);
Assert.notNull(lineFile,"航线文件签名不正确");
data.addProperty("file_md5", lineFile.getSign());
// 新增takeOffOneKey字段
data.addProperty("takeOffOneKey", true);
// 设置设备视频流地址
try {
data.add("stream_urls", gson.fromJson(liveStreamService.generateStreamUrls(deviceId).toJSONString(), JsonElement.class));
} catch (Exception e) {
log.error("生成设备推流/拉流地址异常: deviceId={}, error={}", deviceId, e.getMessage(), e);
data.addProperty("stream_urls", "{}");
}
return jsonObject;
}
}
@@ -31,6 +31,15 @@ public interface OrderCenterService {
@GetMapping("/qrcode/wayline/{orderNo}")
Map<String,Object> getWaylineByOrderNo(@PathVariable("orderNo") String orderNo);
/**
* 根据设备ID和二维码类型获取二维码信息
* @param deviceId 设备ID
* @param qrcodeType 二维码类型(1:游客下单,2:定时巡查,3:其他)
* @return 二维码信息
*/
@GetMapping("/qrcode/device/{deviceId}")
Map<String,Object> getQrcodeByDeviceId(@PathVariable("deviceId") String deviceId, @RequestParam("qrcodeType") Integer qrcodeType);
/**
* 设备离线时自动创建退款订单
* @param orderNo 订单号