Skip to content

新增产品属性物模型 (PATCH)

更新时间:

该接口支持新增产品物模型的属性。

请求接口

PATCH /api/device-product

TIP

访问权限:需要登录超级设备管理平台获取token,并校验token

请求参数

名称位置类型必选说明
X-Access-Tokenheaderstringtrue平台token
bodybodyobjecttrue-
» idbodystringfalse产品唯一标识
» namebodystringtrue产品名称
» photoUrlbodystringfalse产品图标
» classifiedIdbodystringtrue产品分类ID
» classifiedNamebodystringfalse产品分类名称
» messageProtocolbodystringfalse协议ID
» protocolNamebodystringfalse协议名称
» metadatabodystringtrue物模型(产品非自定义物模型,参数不能为空)
» transportProtocolbodystringfalse网关组件类型,例如MQTT、TCP等
» deviceTypebodyobjecttrue设备类型
»» textbodystringfalse内容
»» valuebodystringtrue
» creatorIdbodystringfalse创建者ID
» createTimebodyintegerfalse创建时间
» regulatorbodybooleanfalse是否为控制器
» accessIdbodystringtrue设备接入网关ID
» accessProviderbodystringfalse设备接入网关类型
» accessNamebodystringfalse接入方式名称
» superProductTypebodyobjectfalse超级设备类型
»» textbodystringfalse内容
»» valuebodystringtrue
» virtualTypebodyobjectfalse虚拟设备类型:真实设备、虚拟设备
»» textbodystringfalse内容
»» valuebodystringtrue
» productCreateTypebodyobjectfalse产品新增类型
»» textbodystringfalse内容
»» valuebodystringtrue
» modifierIdbodystringfalse修改者ID
» modifyTimebodyintegerfalse修改时间
» threeDimensionalUrlbodystringfalse3D图片URL
» modelFrombodystringfalse型号
» presetTypebodyobjectfalse类型
»» textbodystringfalse内容
»» valuebodystringtrue
» fieldIdbodystringfalse行业id
» fieldNamebodystringfalse行业名
» sceneIdbodystringfalse场景id
» sceneNamebodystringfalse场景名

响应参数

名称类型说明
»messagestring返回信息
»resultstring返回结果:true或false
»statusinteger(int32)响应状态码
»timestampinteger(int64)时间戳(毫秒)

响应状态码

状态码状态码含义说明
200OK成功
401Unauthorized登录状态已过期,token不能为空
500Internal 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:索引
  • valueType
    • type:数据类型
    • expands:拓展字段
    • unit:单位
  • expands
    • source:属性来源,可选值: "device"(设备)、"manual"(手动)、"rule" (规则)
    • type:读写类型,"read"(读)、"write"(写)、"report"(上报)
  • metrics:[]
  • description:说明,类型为string

其中,valueType 的各字段说明如下:

说明:valueType除了type、expands和unit三个字段外,还可以新增字段。

typeexpandsunit新增字段
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"
	}
}