2026-04-17 17:12:41 +08:00
|
|
|
package com.maibu.controller;
|
2026-04-17 10:42:16 +08:00
|
|
|
|
2026-04-17 17:12:41 +08:00
|
|
|
import com.maibu.common.CommandConstant;
|
|
|
|
|
import com.maibu.core.controller.BaseController;
|
|
|
|
|
import com.maibu.core.domain.AjaxResult;
|
2026-04-30 15:25:58 +08:00
|
|
|
import com.maibu.core.business.device.NettyDevice;
|
2026-04-17 17:12:41 +08:00
|
|
|
import com.maibu.dto.ObstacleData;
|
|
|
|
|
import com.maibu.manager.DeviceSessionManager;
|
|
|
|
|
import com.maibu.utils.CommandUtils;
|
2026-04-17 10:42:16 +08:00
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
import io.netty.buffer.Unpooled;
|
|
|
|
|
import io.netty.util.CharsetUtil;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/iot/api")
|
|
|
|
|
public class DeviceExternalApiController extends BaseController {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private DeviceSessionManager deviceSessionManager;
|
|
|
|
|
|
|
|
|
|
@PostMapping("/obstacleData")
|
|
|
|
|
public AjaxResult obstacleData(@RequestBody ObstacleData obstacleData) {
|
|
|
|
|
Map<String, Object> data = obstacleData.getData();
|
|
|
|
|
String deviceId = (String) data.get("deviceId");
|
|
|
|
|
if (StringUtils.isEmpty(deviceId)) {
|
|
|
|
|
return AjaxResult.error("deviceId为空!");
|
|
|
|
|
}
|
|
|
|
|
// Map<String, Object> obstacle = (Map<String, Object>) data.get("obstacle");
|
|
|
|
|
// Boolean isSecure = (Boolean) data.get("isSecure");
|
|
|
|
|
|
|
|
|
|
List<NettyDevice> devices = deviceSessionManager.getSlaveControl(deviceId);
|
|
|
|
|
if (!CollectionUtils.isEmpty(devices)) {
|
|
|
|
|
devices.forEach(x -> {
|
|
|
|
|
ByteBuf buf = Unpooled.buffer();
|
|
|
|
|
CommandUtils.buildCommand(buf, obstacleData, CommandConstant.interaction);
|
|
|
|
|
String content = buf.toString(CharsetUtil.UTF_8);
|
|
|
|
|
logger.info("推送设备:{}障碍物消息:{}到:{}", deviceId, content, x.getConnectorId());
|
|
|
|
|
if (x.getChannel() != null && x.getChannel().isActive()) {
|
|
|
|
|
x.getChannel().writeAndFlush(buf);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return AjaxResult.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|