设备数据

支持设备IT、OT、指标等多个维度的实时数据、历史数据查询。可多个设备同时查询。

基本信息

路径

/industry/asset/data/get

版本

1.0.0

请求参数

入参名称

数据类型

结构类型

是否必须

入参描述

子级参数类型

assetCodeList

JSON

数组

设备编码

字符串

startTime

字符串

开始时间 yyyyMMddHHmmss

endTime

字符串

结束时间 yyyyMMddHHmmss

time

整型

相对时间,优先级低于绝对时间

timeUnit

字符串

相对时间单位

  • 天:d

  • 小时:h

  • 分:m

pageNo

整型

页码,查询历史数据时可用,从属性维度进行分页,默认为1

pageSize

整型

页大小,查询历史数据时可用,从属性维度进行分页,默认为10

以下为技术属性查询入参,如无需查询技术属性,可忽略这部分入参

iotAttributeQueryMode

整型

技术属性值查询模式,0=不查询,1=查询最新值,2=查询历史值,默认为0

iotAttributeCodeList

JSON

数组

技术属性编码列表,默认查询所有

字符串

iotAttributeQueryType

字符串

查询类型,可选:

  • 最新值:last

  • 最旧值:first

  • 最小值:min

  • 最大值:max

  • 平均值:mean

  • 不同值:distinct

  • 总数:count

以下为业务属性查询入参,如无需查询业务属性,可忽略这部分入参

bizAttributeQueryMode

整型

业务属性值查询模式,0=不查询,1=查询最新值,2=查询历史值,默认为0

bizAttributeNameList

JSON

数组

业务属性名称列表,默认查询所有

-attributeGroupName

字符串

业务属性组名称

-attributeName

字符串

业务属性名称

以下为指标查询入参,如无需查询指标,可忽略这部分入参

indicatorQueryMode

整型

指标值查询模式,0=不查询,1=查询最新值,2=查询历史值,默认为0

indicatorCodeList

JSON

数组

指标编码列表,默认查询所有

字符串

请求示例

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import com.aliyun.iotapigateway.Client;
import com.aliyun.iotapigateway.models.CommonParams;
import com.aliyun.iotapigateway.models.Config;
import com.aliyun.iotapigateway.models.IoTApiRequest;
import com.aliyun.tea.TeaResponse;
import com.aliyun.teautil.Common;
import com.aliyun.teautil.models.RuntimeOptions;

/**
 * @author dongxun.cwj
 * @since 2021/12/16
 */
public class AssetDataTest {

    //AppKey由工业数据应用平台颁发, 第三方应用需要携带写入请求头
    private static final String APP_KEY = "***";
    //AppSecret 由工业数据应用平台颁发时与AppKey映射,用于数据签名
    private static final String APP_SECRET = "***";
    //服务域名/ip
    private static final String HOST = "192.168.0.1:30101";
    //服务路径
    private static final String PATH = "/industry/asset/data/get";
    //服务版本,目前默认1.0.0
    private static final String VERSION = "1.0.0";
    private static final String HTTP_COL = "HTTP";
    private static final String HTTP_METHOD = "POST";

    public static void main(String[] args) throws Exception{
        Config config = new Config();
        config.appKey = APP_KEY;
        config.appSecret = APP_SECRET;
        config.domain = HOST;

        Client client = new Client(config);
        Map<String, Object> params = new HashMap<>();

      	// 设备编码
        List<String> assetCodeList = new ArrayList<>();
        assetCodeList.add("water_meter_4");
        assetCodeList.add("water_meter_3");
        assetCodeList.add("water_meter_2");
        params.put("assetCodeList", JSON.parse(JSONArray.toJSONString(assetCodeList)));
      	
        //params.put("time", 1);
        //params.put("timeUnit", "h");
        params.put("startTime", "20230201111111");
        params.put("endTime", "20230417120000");
        
      	params.put("pageNo", 1);
        params.put("pageSize", 10);

      	// 技术属性参数,无需查询时可忽略
        params.put("iotAttributeQueryMode", 1);
        //List<String> codes = new ArrayList<>();
        //codes.add("mWF1");
        //codes.add("mWF2");
        //params.put("iotAttributeCodeList", JSON.parse(JSONArray.toJSONString(codes)));

        //params.put("iotAttributeQueryType", "mean");

        // 业务属性参数,无需查询时可忽略
        params.put("bizAttributeQueryMode", 1);
        //Map<String, String> bizParam = new HashMap<>();
        //bizParam.put("attributeGroupName", "工艺参数");
        //bizParam.put("attributeName", "process_param");
        //List list = new ArrayList();
        //list.add(bizParam);
        //params.put("bizAttributeNameList", JSON.parse(JSONArray.toJSONString(list)));

      	// 指标参数,无需查询时可忽略
        params.put("indicatorQueryMode", 1);
        //List<String> codes = new ArrayList<>();
        //codes.add("tmp_code2");
        //codes.add("tmp_code1");
        //params.put("indicatorCodeList", JSON.parse(JSONArray.toJSONString(codes)));

        CommonParams req = new CommonParams();
        req.apiVer = VERSION;

        IoTApiRequest body = new IoTApiRequest();
        body.params = params;
        body.request = req;

        RuntimeOptions runtime = new RuntimeOptions();

        TeaResponse teaResponse = client.doRequest(PATH, HTTP_COL, HTTP_METHOD, null, body, runtime);
        //请求返回, 解析出对象 Common支持多种转换读取根据实际转换处理
        System.out.printf(Common.readAsString(teaResponse.body));
    }
}

响应参数

参数名称

数据类型

结构类型

参数描述

code

整型

code

data

JSON

数组

data

-assetCode

字符串

设备编码

-iotAttributeDataList

JSON

数组

技术属性值

-attributeCode

字符串

属性编码

-value

字符串

属性值

-time

长整型

创建时间

-quality

长整型

质量码

-bizAttributeDataList

JSON

数组

业务属性值

-attributeGroupName

字符串

属性组名称

-attributeName

字符串

属性名称

-value

字符串

属性值

-time

长整型

创建时间

-indicatorDataList

JSON

数组

指标值

-indicatorCode

字符串

指标编码

-value

字符串

指标值

-time

长整型

创建时间(转换类型指标)

-windowStart

长整型

窗口开始时间(窗口类型)

-windowEnd

长整型

窗口结束时间(窗口类型)

message

字符串

message

localizedMsg

字符串

localizedMsg

响应示例

{
    "code":200,
    "data":[
        {
            "assetCode":"water_meter_4",
            "indicatorDataList":[
                {
                    "indicatorCode":"tmp_code1",
                    "time":1681783145000,
                    "value":"2.0"
                },
                {
                    "windowStart":1681783080000,
                    "indicatorCode":"tmp_code2",
                    "windowEnd":1681783140000,
                    "value":"0.03876255"
                }
            ],
            "bizAttributeDataList":[
                {
                    "attributeName":"process_param",
                    "time":1681782996000,
                    "attributeGroupName":"工艺参数",
                    "value":"ttt"
                }
            ],
            "iotAttributeDataList":[
                {
                    "attributeCode":"mWF2",
                    "time":1681703999000,
                    "value":"18055657",
                    "quality":0
                },
                {
                    "attributeCode":"mWF1",
                    "time":1681703999000,
                    "value":"18055657",
                    "quality":0
                },
                {
                    "attributeCode":"WM_VIR002",
                    "time":1681703995000,
                    "value":"0",
                    "quality":0
                },
                {
                    "attributeCode":"WM_VIR001",
                    "time":1681703999000,
                    "value":"0",
                    "quality":0
                },
                {
                    "attributeCode":"flow",
                    "time":1681703999000,
                    "value":"13507.1815081092",
                    "quality":0
                },
                {
                    "attributeCode":"mPa",
                    "time":1681703999000,
                    "value":"0.9682478521012786",
                    "quality":0
                }
            ]
        },
        {
            "assetCode":"water_meter_3",
            "indicatorDataList":[
                {
                    "indicatorCode":"tmp_code1",
                    "time":1681783145000,
                    "value":"2.0"
                },
                {
                    "windowStart":1681783080000,
                    "indicatorCode":"tmp_code2",
                    "windowEnd":1681783140000,
                    "value":"0.04308947"
                }
            ],
            "bizAttributeDataList":[
                {
                    "attributeName":"process_param",
                    "time":1670385037000,
                    "attributeGroupName":"工艺参数",
                    "value":"DDDD"
                }
            ],
            "iotAttributeDataList":[
                {
                    "attributeCode":"mWF1",
                    "time":1681703999000,
                    "value":"18055657",
                    "quality":0
                },
                {
                    "attributeCode":"WM_VIR002",
                    "time":1681703995000,
                    "value":"0",
                    "quality":0
                },
                {
                    "attributeCode":"WM_VIR001",
                    "time":1681703999000,
                    "value":"0",
                    "quality":0
                },
                {
                    "attributeCode":"mWF2",
                    "time":1681703999000,
                    "value":"18055657",
                    "quality":0
                },
                {
                    "attributeCode":"flow",
                    "time":1681703999000,
                    "value":"13510.21657149709",
                    "quality":0
                },
                {
                    "attributeCode":"mPa",
                    "time":1681703999000,
                    "value":"1.008550599811725",
                    "quality":0
                }
            ]
        },
        {
            "assetCode":"water_meter_2",
            "indicatorDataList":[
                {
                    "indicatorCode":"tmp_code1",
                    "time":1681783145000,
                    "value":"2.0"
                },
                {
                    "windowStart":1681783080000,
                    "indicatorCode":"tmp_code2",
                    "windowEnd":1681783140000,
                    "value":"0.03626381"
                }
            ],
            "bizAttributeDataList":[
                {
                    "attributeName":"process_param",
                    "time":1670385027000,
                    "attributeGroupName":"工艺参数",
                    "value":"CCCC"
                }
            ],
            "iotAttributeDataList":[
                {
                    "attributeCode":"WM_VIR001",
                    "time":1681703999000,
                    "value":"0",
                    "quality":0
                },
                {
                    "attributeCode":"flow",
                    "time":1681703999000,
                    "value":"13509.47032017426",
                    "quality":0
                },
                {
                    "attributeCode":"mWF2",
                    "time":1681703999000,
                    "value":"18055657",
                    "quality":0
                },
                {
                    "attributeCode":"mWF1",
                    "time":1681703999000,
                    "value":"18055657",
                    "quality":0
                },
                {
                    "attributeCode":"WM_VIR002",
                    "time":1681703995000,
                    "value":"0",
                    "quality":0
                },
                {
                    "attributeCode":"mPa",
                    "time":1681703999000,
                    "value":"0.9783824079998346",
                    "quality":0
                }
            ]
        }
    ],
    "id":"a7457867-b709-41a0-bf58-873b6d579f4716817831705751"
}