该接口支持新增产品物模型的属性。
请求接口
PATCH /api/device-product
请求参数
| 名称 | 位置 | 类型 | 必选 | 说明 |
|---|---|---|---|---|
| X-Access-Token | header | string | true | 平台token |
| body | body | object | true | - |
| » id | body | string | false | 产品唯一标识 |
| » name | body | string | true | 产品名称 |
| » photoUrl | body | string | false | 产品图标 |
| » classifiedId | body | string | true | 产品分类ID |
| » classifiedName | body | string | false | 产品分类名称 |
| » messageProtocol | body | string | false | 协议ID |
| » protocolName | body | string | false | 协议名称 |
| » metadata | body | string | true | 物模型(产品非自定义物模型,参数不能为空) |
| » transportProtocol | body | string | false | 网关组件类型,例如MQTT、TCP等 |
| » deviceType | body | object | true | 设备类型 |
| »» text | body | string | false | 内容 |
| »» value | body | string | true | 值 |
| » creatorId | body | string | false | 创建者ID |
| » createTime | body | integer | false | 创建时间 |
| » regulator | body | boolean | false | 是否为控制器 |
| » accessId | body | string | true | 设备接入网关ID |
| » accessProvider | body | string | false | 设备接入网关类型 |
| » accessName | body | string | false | 接入方式名称 |
| » superProductType | body | object | false | 超级设备类型 |
| »» text | body | string | false | 内容 |
| »» value | body | string | true | 值 |
| » virtualType | body | object | false | 虚拟设备类型:真实设备、虚拟设备 |
| »» text | body | string | false | 内容 |
| »» value | body | string | true | 值 |
| » productCreateType | body | object | false | 产品新增类型 |
| »» text | body | string | false | 内容 |
| »» value | body | string | true | 值 |
| » modifierId | body | string | false | 修改者ID |
| » modifyTime | body | integer | false | 修改时间 |
| » threeDimensionalUrl | body | string | false | 3D图片URL |
| » modelFrom | body | string | false | 型号 |
| » presetType | body | object | false | 类型 |
| »» text | body | string | false | 内容 |
| »» value | body | string | true | 值 |
| » fieldId | body | string | false | 行业id |
| » fieldName | body | string | false | 行业名 |
| » sceneId | body | string | false | 场景id |
| » sceneName | body | string | false | 场景名 |
响应参数
| 名称 | 类型 | 说明 |
|---|---|---|
| »message | string | 返回信息 |
| »result | string | 返回结果:true或false |
| »status | integer(int32) | 响应状态码 |
| »timestamp | integer(int64) | 时间戳(毫秒) |
响应状态码
| 状态码 | 状态码含义 | 说明 |
|---|---|---|
| 200 | OK | 成功 |
| 401 | Unauthorized | 登录状态已过期,token不能为空 |
| 500 | Internal Server Error | 服务器内部异常 |
返回示例
以200 Response为例:
json
{
"message":"success",
"status":200,
"timestamp":1695621095800
}{
"message":"success",
"status":200,
"timestamp":1695621095800
}使用示例
1. 查询产品详情接口,获取产品物模型
使用查询产品详情接口/api/device-product/{id},取result字段的所有内容为本接口的Body。
根据个人需求修改 metadata 中内容,实现新增或修改产品物模型。
json
{
……
"metadata": "{\"events\":[{\"expands\":{\"level\":\"ordinary\"},\"valueType\":{\"type\":\"object\",\"expands\":{},\"properties\":[{\"valueType\":{\"expands\":{},\"type\":\"int\"},\"id\":\"1\",\"name\":\"1\"}]},\"id\":\"11\",\"name\":\"11\",\"sortsIndex\":0}],\"properties\":[{\"valueType\":{\"type\":\"int\",\"expands\":{},\"unit\":\"count\"},\"expands\":{\"source\":\"device\",\"type\":[\"read\",\"write\",\"report\"],\"metrics\":[]},\"id\":\"a\",\"name\":\"abc\",\"sortsIndex\":0},{\"valueType\":{\"type\":\"string\",\"expands\":{}},\"expands\":{\"source\":\"device\",\"type\":[\"write\",\"read\",\"report\"],\"metrics\":[]},\"id\":\"b\",\"name\":\"b\",\"sortsIndex\":1}],\"functions\":[{\"inputs\":[{\"valueType\":{\"expands\":{},\"type\":\"int\"},\"id\":\"a\",\"name\":\"a\"}],\"output\":{\"type\":null,\"expands\":{}},\"id\":\"function\",\"name\":\"功能\",\"async\":false,\"sortsIndex\":0}],\"tags\":[{\"valueType\":{\"type\":\"int\",\"expands\":{}},\"expands\":{\"type\":[\"read\",\"write\",\"report\"],\"metrics\":[]},\"id\":\"biaoqian\",\"name\":\"标签\",\"sortsIndex\":0}]}",
……
}{
……
"metadata": "{\"events\":[{\"expands\":{\"level\":\"ordinary\"},\"valueType\":{\"type\":\"object\",\"expands\":{},\"properties\":[{\"valueType\":{\"expands\":{},\"type\":\"int\"},\"id\":\"1\",\"name\":\"1\"}]},\"id\":\"11\",\"name\":\"11\",\"sortsIndex\":0}],\"properties\":[{\"valueType\":{\"type\":\"int\",\"expands\":{},\"unit\":\"count\"},\"expands\":{\"source\":\"device\",\"type\":[\"read\",\"write\",\"report\"],\"metrics\":[]},\"id\":\"a\",\"name\":\"abc\",\"sortsIndex\":0},{\"valueType\":{\"type\":\"string\",\"expands\":{}},\"expands\":{\"source\":\"device\",\"type\":[\"write\",\"read\",\"report\"],\"metrics\":[]},\"id\":\"b\",\"name\":\"b\",\"sortsIndex\":1}],\"functions\":[{\"inputs\":[{\"valueType\":{\"expands\":{},\"type\":\"int\"},\"id\":\"a\",\"name\":\"a\"}],\"output\":{\"type\":null,\"expands\":{}},\"id\":\"function\",\"name\":\"功能\",\"async\":false,\"sortsIndex\":0}],\"tags\":[{\"valueType\":{\"type\":\"int\",\"expands\":{}},\"expands\":{\"type\":[\"read\",\"write\",\"report\"],\"metrics\":[]},\"id\":\"biaoqian\",\"name\":\"标签\",\"sortsIndex\":0}]}",
……
}metadata 去转义再格式化之后,格式如下:
properties:属性物模型events:事件物模型functions:功能物模型tags: 标签物模型
json
{
"properties": [
{
"valueType": {
"type": "int",
"expands": {},
"unit": "count"
},
"expands": {
"source": "device",
"type": [
"read",
"write",
"report"
],
"metrics": []
},
"id": "a",
"name": "abc",
"sortsIndex": 0
},
],
"events": [],
"functions": [],
"tags": []
}{
"properties": [
{
"valueType": {
"type": "int",
"expands": {},
"unit": "count"
},
"expands": {
"source": "device",
"type": [
"read",
"write",
"report"
],
"metrics": []
},
"id": "a",
"name": "abc",
"sortsIndex": 0
},
],
"events": [],
"functions": [],
"tags": []
}2. 新增或修改产品属性物模型
在原有物模型(metadata )的基础上,新增或修改properties字段。
id:标识name:名称sortsIndex:索引valueTypetype:数据类型expands:拓展字段unit:单位
expandssource:属性来源,可选值: "device"(设备)、"manual"(手动)、"rule" (规则)type:读写类型,"read"(读)、"write"(写)、"report"(上报)
metrics:[]description:说明,类型为string
其中,valueType 的各字段说明如下:
说明:valueType除了type、expands和unit三个字段外,还可以新增字段。
| type | expands | unit | 新增字段 |
|---|---|---|---|
| int | {} | percent、count、turnPerSeconds、nanometer、micron、millimeter、centimeter、meter、kilometer、squareMillimeter(平方毫米)、squareCentimeter(平方厘米)、squareMeter(平方米)、squareKilometer(平方千米)、hectare(公顷)、days、hour、minutes、seconds、milliseconds、microseconds、nanoseconds、cubicMillimeter、cubicCentimeter、cubicMeter、cubicKilometer、cubicMeterPerSec、cubicKilometerPerSec | \ |
| long | {} | 同上 | \ |
| float | {} | 同上 | scale:1(精度) |
| double | {} | 同上 | scale:2 (精度) |
| string | {"maxLength": 最大长度值(类型:int) } | \ | \ |
| boolean | {} | \ | "trueText": "是","trueValue": true,"falseText": "否","falseValue": false |
| date | {} | \ | \ |
| enum | {} | \ | "elements": [{"value": "a","text": "a"}] |
| array | {} | \ | "elementType": {"expands": |
| object | {} | \ | "properties":[{"valueType":{"expands":{},"type":"int"},"id":"a","name":"a"},{"valueType":{"expands":{},"type":"string"},"id":"b","name":"b"}] |
| file | {} | \ | "fileType": "url" 或 "fileType": "base64" 或 "fileType": "Binary(二进制)" |
| password | {"maxLength": 10} | \ | \ |
| geoPoint | {} | \ | \ |
以下内容为 metadata 未添加转义内容:
json
"properties": [
{
"valueType": {
"type": "int",
"expands": {},
"unit": "count"
},
"expands": {
"source": "device",
"type": [
"read",
"write",
"report"
],
"metrics": []
},
"id": "a",
"name": "abc",
"sortsIndex": 0
},
{
"valueType": {
"type": "string",
"expands": {}
},
"expands": {
"source": "device",
"type": [
"write",
"read",
"report"
],
"metrics": []
},
"id": "b",
"name": "b",
"sortsIndex": 1
}
]"properties": [
{
"valueType": {
"type": "int",
"expands": {},
"unit": "count"
},
"expands": {
"source": "device",
"type": [
"read",
"write",
"report"
],
"metrics": []
},
"id": "a",
"name": "abc",
"sortsIndex": 0
},
{
"valueType": {
"type": "string",
"expands": {}
},
"expands": {
"source": "device",
"type": [
"write",
"read",
"report"
],
"metrics": []
},
"id": "b",
"name": "b",
"sortsIndex": 1
}
]3. 获取查询产品详情接口返回值result,作为该接口的参数
json
{
"id": "waitdelete",
"name": "待删除",
"photoUrl": "/images/card/product.png",
"classifiedId": "-12-",
"classifiedName": "其他场景",
"messageProtocol": "d79e86511a67fc42fc0683a3917de033",
"protocolName": "内置协议",
"metadata": "{\"events\":[],\"properties\":[{\"valueType\":{\"type\":\"int\",\"expands\":{},\"unit\":\"count\"},\"expands\":{\"source\":\"device\",\"type\":[\"read\",\"write\",\"report\"],\"metrics\":[]},\"id\":\"a\",\"name\":\"a\",\"sortsIndex\":0},{\"valueType\":{\"type\":\"string\",\"expands\":{}},\"expands\":{\"source\":\"device\",\"type\":[\"write\",\"read\",\"report\"],\"metrics\":[]},\"id\":\"b\",\"name\":\"b\",\"sortsIndex\":1}]}",
"transportProtocol": "MQTT",
"deviceType": {
"text": "网关设备",
"value": "gateway"
},
"configuration": {
"secureId": "waitdelete",
"secureKey": "****************"
},
"state": 1,
"creatorId": "1199596756811550720",
"createTime": 1695376779513,
"regulator": false,
"accessId": "6b194cc8d70376c3dfc623b47aacb558",
"accessProvider": "child-device",
"accessName": "内置MQTT子设备接入网关",
"superProductType": {
"text": "普通产品",
"value": "commonProduct"
},
"virtualType": {
"text": "真实设备",
"value": "real"
},
"productCreateType": {
"text": "手动",
"value": "manual"
},
"modifierId": "1199596756811550720",
"modifyTime": 1695376779513,
"threeDimensionalUrl": "/images/card/product.png",
"deviceNum": 1,
"modelFrom": "自定义",
"presetType": {
"text": "非内置",
"value": "none"
}
}{
"id": "waitdelete",
"name": "待删除",
"photoUrl": "/images/card/product.png",
"classifiedId": "-12-",
"classifiedName": "其他场景",
"messageProtocol": "d79e86511a67fc42fc0683a3917de033",
"protocolName": "内置协议",
"metadata": "{\"events\":[],\"properties\":[{\"valueType\":{\"type\":\"int\",\"expands\":{},\"unit\":\"count\"},\"expands\":{\"source\":\"device\",\"type\":[\"read\",\"write\",\"report\"],\"metrics\":[]},\"id\":\"a\",\"name\":\"a\",\"sortsIndex\":0},{\"valueType\":{\"type\":\"string\",\"expands\":{}},\"expands\":{\"source\":\"device\",\"type\":[\"write\",\"read\",\"report\"],\"metrics\":[]},\"id\":\"b\",\"name\":\"b\",\"sortsIndex\":1}]}",
"transportProtocol": "MQTT",
"deviceType": {
"text": "网关设备",
"value": "gateway"
},
"configuration": {
"secureId": "waitdelete",
"secureKey": "****************"
},
"state": 1,
"creatorId": "1199596756811550720",
"createTime": 1695376779513,
"regulator": false,
"accessId": "6b194cc8d70376c3dfc623b47aacb558",
"accessProvider": "child-device",
"accessName": "内置MQTT子设备接入网关",
"superProductType": {
"text": "普通产品",
"value": "commonProduct"
},
"virtualType": {
"text": "真实设备",
"value": "real"
},
"productCreateType": {
"text": "手动",
"value": "manual"
},
"modifierId": "1199596756811550720",
"modifyTime": 1695376779513,
"threeDimensionalUrl": "/images/card/product.png",
"deviceNum": 1,
"modelFrom": "自定义",
"presetType": {
"text": "非内置",
"value": "none"
}
}