Merge branch 'develop' of https://gitee.com/L-Shilin/go-fly-platform-services into feature_dzc
This commit is contained in:
+91
@@ -214,4 +214,95 @@ 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() {
|
||||
// 生成13位随机数字
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < 13; i++) {
|
||||
sb.append((int)(Math.random() * 10));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建指令消息
|
||||
*/
|
||||
private JsonObject buildCommandMessage(String orderNo, String deviceId, Map<String, Object> qrcodeResult) {
|
||||
// 使用默认的control参数,这里可以根据需要修改
|
||||
String control = "flighttask_prepare"; // 使用飞行任务准备指令
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
+10
-4
@@ -4,10 +4,7 @@ import com.central.common.constant.ServiceNameConstants;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.device.feign.fallback.OrderCenterServiceFallbackFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -31,6 +28,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 订单号
|
||||
|
||||
+5
@@ -39,6 +39,11 @@ public class OrderCenterServiceFallbackFactory implements FallbackFactory<OrderC
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getQrcodeByDeviceId(String deviceId, Integer qrcodeType) {
|
||||
return Map.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result createRefundForOfflineDevice(String orderNo, Map<String, Object> refundBody) {
|
||||
log.error("调用订单中心退款接口失败: orderNo={}, cause={}", orderNo, cause.getMessage());
|
||||
|
||||
+1
@@ -84,6 +84,7 @@ public class ControlMessageConstant {
|
||||
CONTROL_MESSAGE_MAP.put("flighttask_prepare", FLIGHTTASK_PREPARE);
|
||||
CONTROL_MESSAGE_MAP.put("return_home", RETURN_HOME);
|
||||
CONTROL_MESSAGE_MAP.put("flighttask_recovery", FLIGHTTASK_RECOVERY);
|
||||
CONTROL_MESSAGE_MAP.put("takeoff_to_point", TAKEOFF_TO_POINT);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user