| | |
| | | package com.ruoyi.integration.iotda.utils.api; |
| | | |
| | | import com.huaweicloud.sdk.core.auth.AbstractCredentials; |
| | | import com.huaweicloud.sdk.core.auth.ICredential; |
| | | import com.huaweicloud.sdk.core.exception.ConnectionException; |
| | | import com.huaweicloud.sdk.core.exception.RequestTimeoutException; |
| | | import com.huaweicloud.sdk.core.exception.ServiceResponseException; |
| | | import com.huaweicloud.sdk.iotda.v5.IoTDAClient; |
| | | import com.huaweicloud.sdk.iotda.v5.model.*; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.CodeGenerateUtils; |
| | | import com.ruoyi.common.core.utils.uuid.UUID; |
| | | import com.ruoyi.integration.api.vo.AddDeviceResp; |
| | | import com.ruoyi.integration.api.vo.DeleteDeviceResp; |
| | | import com.ruoyi.integration.iotda.builder.IotBuilder; |
| | | import com.ruoyi.integration.iotda.config.IotAccountConfig; |
| | | import com.ruoyi.integration.iotda.config.IotDAConfig; |
| | | import com.ruoyi.integration.iotda.constant.IotConstant; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.text.MessageFormat; |
| | | import java.util.ArrayList; |
| | |
| | | * iot接口调用工具类 |
| | | */ |
| | | @Slf4j |
| | | @RestController |
| | | @Component |
| | | public class IotInterfaceUtil { |
| | | |
| | | private static final String dataFormat = "json"; |
| | |
| | | * @param description 设备描述 |
| | | * @return AddDeviceResponse |
| | | */ |
| | | public AddDeviceResponse addDeviceRequest(String productId,String nodeId,String deviceName,String description) { |
| | | public R<AddDeviceResp> addDeviceRequest(String productId,String nodeId,String deviceName,String description) { |
| | | AddDeviceRequest request = new AddDeviceRequest(); |
| | | AddDevice body = new AddDevice(); |
| | | body.withDeviceId(nodeId); |
| | |
| | | try { |
| | | AddDeviceResponse response = iotBuilder.buildIot().addDevice(request); |
| | | log.info("创建设备:{}",response.toString()); |
| | | return response; |
| | | |
| | | AddDeviceResp addDeviceResp = new AddDeviceResp(); |
| | | BeanUtils.copyProperties(response, addDeviceResp); |
| | | return R.ok(addDeviceResp); |
| | | } catch (ConnectionException e) { |
| | | e.printStackTrace(); |
| | | } catch (RequestTimeoutException e) { |
| | |
| | | System.out.println(e.getErrorCode()); |
| | | System.out.println(e.getErrorMsg()); |
| | | } |
| | | return null; |
| | | return R.fail(); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param deviceId 设备ID 使用已有设备编号 |
| | | * @return DeleteDeviceResponse |
| | | */ |
| | | public DeleteDeviceResponse deleteDeviceRequest(String deviceId) { |
| | | public R<DeleteDeviceResp> deleteDeviceRequest(String deviceId) { |
| | | DeleteDeviceRequest request = new DeleteDeviceRequest(); |
| | | request.withDeviceId(deviceId); |
| | | try { |
| | | DeleteDeviceResponse response = iotBuilder.buildIot().deleteDevice(request); |
| | | log.info("删除设备:{}",response.toString()); |
| | | return response; |
| | | DeleteDeviceResp deleteDeviceResp = new DeleteDeviceResp(); |
| | | BeanUtils.copyProperties(response, deleteDeviceResp); |
| | | return R.ok(deleteDeviceResp); |
| | | } catch (ConnectionException e) { |
| | | e.printStackTrace(); |
| | | } catch (RequestTimeoutException e) { |
| | |
| | | System.out.println(e.getErrorCode()); |
| | | System.out.println(e.getErrorMsg()); |
| | | } |
| | | return null; |
| | | return R.fail(); |
| | | } |
| | | } |