增加机场属性设置
This commit is contained in:
parent
02384897ab
commit
f633b2179f
|
|
@ -40,6 +40,7 @@ public interface BusinessConstant {
|
|||
String STATE = "state";
|
||||
String EVENTS = "events";
|
||||
String SERVICES_REPLY = "services_reply";
|
||||
String SET_REPLY = "set_reply";
|
||||
String STORAGE_CONFIG_GET = "storage_config_get";
|
||||
String _REPLY = "_reply";
|
||||
//********************************* dj payload key *********************************//
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
package com.multictrl.modules.business.controller;
|
||||
|
||||
import com.multictrl.common.annotation.ApiOrder;
|
||||
import com.multictrl.common.annotation.LogOperation;
|
||||
import com.multictrl.common.utils.Result;
|
||||
import com.multictrl.modules.business.service.DockSetService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 机场属性设置
|
||||
*
|
||||
* @author Sdy
|
||||
* @since 1.0.0 2026/6/17
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("business/dock/set")
|
||||
@Tag(name = "机场属性设置")
|
||||
@ApiOrder(25)
|
||||
@RequiredArgsConstructor
|
||||
public class DockSetController {
|
||||
private final DockSetService dockSetService;
|
||||
|
||||
@Operation(summary = "空中回传(目前仅大疆机场三支持)")
|
||||
@PostMapping("/airTransfer/{dockSn}")
|
||||
@LogOperation("空中回传")
|
||||
@RequiresPermissions("bus:dockSet:airTransfer")
|
||||
public Result<Object> supplementLightClose(@PathVariable String dockSn,
|
||||
@Parameter(description = "空中回传开关 false:关闭,true:开启")
|
||||
@RequestParam Boolean enable) {
|
||||
return new Result<>().ok(dockSetService.setDockProperty(dockSn, "air_transfer_enable", enable));
|
||||
}
|
||||
|
||||
@Operation(summary = "机场静音模式")
|
||||
@PostMapping("/silentMode/{dockSn}")
|
||||
@LogOperation("机场静音模式")
|
||||
@RequiresPermissions("bus:dockSet:silentMode")
|
||||
public Result<Object> supplementLightClose(@PathVariable String dockSn,
|
||||
@Parameter(description = "机场静音模式 0:非静音模式,1:静音模式")
|
||||
@RequestParam Integer value) {
|
||||
return new Result<>().ok(dockSetService.setDockProperty(dockSn, "silent_mode", value));
|
||||
}
|
||||
|
||||
@Operation(summary = "用户体验改善计划")
|
||||
@PostMapping("/userExperienceImprovement/{dockSn}")
|
||||
@LogOperation("用户体验改善计划")
|
||||
@RequiresPermissions("bus:dockSet:userExperienceImprovement")
|
||||
public Result<Object> userExperienceImprovement(@PathVariable String dockSn,
|
||||
@Parameter(description = "用户体验改善计划 0:初始状态,1:拒绝加入用户体验改善计划,2:同意加入用户体验改善计划")
|
||||
@RequestParam Integer value) {
|
||||
return new Result<>().ok(dockSetService.setDockProperty(dockSn, "user_experience_improvement", value));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package com.multictrl.modules.business.handler;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.multictrl.common.constant.BusinessConstant;
|
||||
import com.multictrl.common.utils.CacheUtils;
|
||||
import com.multictrl.common.utils.JsonUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 属性设置上报
|
||||
*
|
||||
* @author Sdy
|
||||
* @since 1.0.0 2026/6/17
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class SetReplyHandle implements MessageHandler {
|
||||
|
||||
@Override
|
||||
public void handleMessage(String topic, String payload, String gateway) {
|
||||
log.debug("set property reply --> topic: {}, payload: {}", topic, payload);
|
||||
JSONObject message = JsonUtils.parseObject(payload, JSONObject.class);
|
||||
if (message != null) {
|
||||
String bid = message.getStr("bid");
|
||||
String tid = message.getStr("tid");
|
||||
if (StrUtil.isNotBlank(bid) && StrUtil.isNotBlank(tid)) {
|
||||
JSONObject data = message.getJSONObject(BusinessConstant.DATA);
|
||||
if (data == null) {
|
||||
data = new JSONObject();
|
||||
data.set("result", 0);
|
||||
}
|
||||
CacheUtils.set(bid + "_" + tid, data);
|
||||
}
|
||||
} else {
|
||||
log.debug("set property reply --> payload解析失败,解析后为null");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -31,6 +31,7 @@ public class TopicDistributor {
|
|||
private final StateHandler stateHandler;
|
||||
private final ServicesReplyHandler servicesReplyHandler;
|
||||
private final EventsHandler eventsHandler;
|
||||
private final SetReplyHandle setReplyHandle;
|
||||
private final ZhiMouCallbackHandler zhiMouCallbackHandler;
|
||||
private final Q20OsdTopicHandler q20OsdTopicHandler;
|
||||
private final Q20EventsHandler q20EventsHandler;
|
||||
|
|
@ -51,6 +52,7 @@ public class TopicDistributor {
|
|||
handlerMap.put(BusinessConstant.STATE, stateHandler);
|
||||
handlerMap.put(BusinessConstant.EVENTS, eventsHandler);
|
||||
handlerMap.put(BusinessConstant.SERVICES_REPLY, servicesReplyHandler);
|
||||
handlerMap.put(BusinessConstant.SET_REPLY, setReplyHandle);
|
||||
handlerMap.put(BusinessConstant.ZHIMOU_AI_CALLBACK, zhiMouCallbackHandler);
|
||||
|
||||
q20HandlerMap.put(BusinessConstant.OSD, q20OsdTopicHandler);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
package com.multictrl.modules.business.service;
|
||||
|
||||
/**
|
||||
* 机场属性设置
|
||||
*
|
||||
* @author Sdy
|
||||
* @since 1.0.0 2026/6/17
|
||||
*/
|
||||
public interface DockSetService {
|
||||
|
||||
//设置机场属性
|
||||
String setDockProperty(String dockSn, String property, Object value);
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
package com.multictrl.modules.business.service.impl;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.multictrl.common.exception.RenException;
|
||||
import com.multictrl.common.utils.CacheUtils;
|
||||
import com.multictrl.common.utils.DJIErrorCodeUtils;
|
||||
import com.multictrl.common.utils.Utils;
|
||||
import com.multictrl.modules.business.dto.error.DJICloudErrorCode;
|
||||
import com.multictrl.modules.business.service.DockSetService;
|
||||
import com.multictrl.modules.business.service.MqttPushService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 机场属性设置
|
||||
*
|
||||
* @author Sdy
|
||||
* @since 1.0.0 2026/6/17
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DockSetServiceImpl implements DockSetService {
|
||||
private final MqttPushService mqttPushService;
|
||||
|
||||
@Override
|
||||
public String setDockProperty(String dockSn, String property, Object value) {
|
||||
JSONObject message = new JSONObject();
|
||||
JSONObject data = new JSONObject();
|
||||
JSONObject state = new JSONObject();
|
||||
state.set("state", value);
|
||||
data.set(property, state);
|
||||
message.set("data", data);
|
||||
String bid = IdUtil.randomUUID();
|
||||
String tid = IdUtil.randomUUID();
|
||||
message.set("bid", bid);
|
||||
message.set("tid", tid);
|
||||
message.set("timestamp", System.currentTimeMillis());
|
||||
mqttPushService.pushMessageByClient1("thing/product/" + dockSn + "/property/set", message.toString());
|
||||
String key = bid + "_" + tid;
|
||||
int tryCount = 100;
|
||||
while (tryCount-- > 0) {
|
||||
Object object = CacheUtils.get(key);
|
||||
if (object != null) {
|
||||
CacheUtils.delete(key);
|
||||
JSONObject dataJson = (JSONObject) object;
|
||||
JSONObject propertyObject = dataJson.getJSONObject(property);
|
||||
JSONObject stateObject = propertyObject.getJSONObject("state");
|
||||
Integer result = stateObject.getInt("result");
|
||||
if (result == 0) {
|
||||
return "执行成功";
|
||||
} else if (result == 1) {
|
||||
throw new RenException("执行失败");
|
||||
} else if (result == 2) {
|
||||
throw new RenException("执行超时");
|
||||
} else {
|
||||
String msg = "执行失败";
|
||||
DJICloudErrorCode errorMsg = DJIErrorCodeUtils.getErrorMsg(String.valueOf(result));
|
||||
if (errorMsg != null) {
|
||||
msg = errorMsg.toString();
|
||||
}
|
||||
throw new RenException(msg);
|
||||
}
|
||||
}
|
||||
Utils.sleep(100);
|
||||
}
|
||||
throw new RenException("执行超时");
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue