无关风月
2024-12-11 4d7a208f388e42e7dd83dab0e38eadfa0847de1c
ruoyi-service/ruoyi-integration/src/main/java/com/ruoyi/integration/iotda/utils/produce/IotMessageProduce.java
@@ -1,5 +1,6 @@
package com.ruoyi.integration.iotda.utils.produce;
import com.alibaba.fastjson2.JSONObject;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
@@ -13,27 +14,39 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * iotda消息发送
 */
@Slf4j
@Component
@RestController
public class IotMessageProduce {
    @Autowired
    private IotBuilder iotBuilder;
    @Autowired
    private IotDAConfig config;
    /**
     * 设备消息下发
     * @param deviceId 设备id
     * @param name 消息名称
     * @param message 消息内容
     * @return
     */
    public String sendMessage(String deviceId,String name,String message){
    @PostMapping("/sendMessage")
    public String sendMessage(String code, String name, JSONObject message){
        CreateMessageRequest request = new CreateMessageRequest();
        request.withDeviceId(deviceId);
        System.err.println(code);
        System.err.println(JSONObject.toJSONString(config));
        if(config.getTest() && code.equals(config.getTestDriverCode())){
            request.withDeviceId(config.getTestDeviceId());
        }else{
            request.withDeviceId(config.getDeviceId());
        }
        DeviceMessageRequest body = new DeviceMessageRequest();
        body.withMessageId(UUID.randomUUID().toString());
        body.withName(name);