Files
IoT-OpenApi/src/main/java/com/iot/gateway/openapi/OpenCommandController.java
T

41 lines
1.7 KiB
Java

package com.iot.gateway.openapi;
import com.iot.gateway.common.Result;
import com.iot.gateway.oauth.GatewaySecurityContext;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@Tag(name = "OpenAPI - 设备反写控制指令 (REST API)")
@RestController
@RequestMapping("/open/v1/commands")
public class OpenCommandController {
@Operation(summary = "下发设备控制与工艺参数反写指令 (MQTT桥接)")
@PostMapping
@PreAuthorize("hasAuthority('SCOPE_device.control') or hasAuthority('SCOPE_all')")
public Result<Map<String, Object>> sendCommand(@RequestBody Map<String, Object> req) {
Long tenantId = GatewaySecurityContext.getTenantIdOrDefault(1L);
String deviceId = String.valueOf(req.get("deviceId"));
String command = String.valueOf(req.get("command"));
log.info("三方系统下发设备反写指令: tenantId={}, deviceId={}, command={}", tenantId, deviceId, command);
return Result.success(Map.of(
"success", true,
"commandId", "CMD-" + System.currentTimeMillis(),
"deviceId", deviceId,
"command", command,
"status", "DELIVERED",
"message", "指令已成功路由至对应租户的边缘网关执行"
));
}
}