美文网首页
模板数据项、指令和指令策略间的关系

模板数据项、指令和指令策略间的关系

作者: 我是阿法 | 来源:发表于2018-11-12 14:25 被阅读0次

    1、什么是模板数据项?

    在一个设备的模板中,数据项就是物理设备采集指标在平台的一个定义。

    比如这个模板中定义了如下多个数据项:

    一个模板的数据项

    【序号】:数据项排序用,多用于组态和表单展示中

    【数据项】:这是提供给网关使用的,比如在MQTT协议中,上传的标签就是这个数据项字段

    【名称】:这是提供给平台显示使用的,因为大部分情况下【数据项】字段是不可读的,比如DO1,需要一个能够正常识别的名字

    【单位】:

    【是否数值】:

    【数据类型】:

    【取值范围】:

    除了这些显示的字段,在数据项中有两个非常重要的隐藏字段【id】和【uid】,先来一段代码:

    {
        "code": "0",
        "message": null,
        "data": [{
            "domainPath": "/0/314888726511165/",
            "id": 9,
            "label": "一号炉口",
            "createTime": "2018-08-29T07:44:03.975+0000",
            "modifyTime": "2018-11-09T12:57:19.586+0000",
            "orCondition": null,
            "conditionField": null,
            "values": {},
            "name": "DO1",
            "description": null,
            "icon": null,
            "canEdit": true,
            "noSave": false,
            "uid": 314888726511563,
            "modelId": 314888726511551,
            "modelIdList": null,
            "granularity": 5,
            "granularityUnit": "MINUTE",
            "expression": null,
            "unit": "NA",
            "unitId": null,
            "triggerTime": null,
            "saveInterval": 0,
            "keepPeriod": 0,
            "range": null,
            "normalRange": null,
            "baseKpiId": 0,
            "calKpiPeriod": null,
            "timeDeviation": 0,
            "industryId": null,
            "displayParam": null,
            "instance": 0,
            "compress": false,
            "compressTime": 0,
            "deadZoneRange": 0.0,
            "interval": false,
            "intervalTime": 0,
            "type": "kpi",
            "serial": 1,
            "tagModel": false,
            "exportDataModelId": 0,
            "autoCreation": false,
            "kpi": true,
            "number": true,
            "kpiType": false
        }, {
            "domainPath": "/0/314888726511165/",
            "id": 378837143666810,
            "label": "二号炉口",
            "createTime": "2018-08-29T07:43:57.947+0000",
            "modifyTime": "2018-11-09T12:57:19.586+0000",
            "orCondition": null,
            "conditionField": null,
            "values": {},
            "name": "DO2",
            "description": null,
            "icon": null,
            "canEdit": true,
            "noSave": false,
            "uid": 378837143666810,
            "modelId": 314888726511551,
            "modelIdList": null,
            "granularity": 5,
            "granularityUnit": "MINUTE",
            "expression": null,
            "unit": "NA",
            "unitId": null,
            "triggerTime": null,
            "saveInterval": 0,
            "keepPeriod": 0,
            "range": null,
            "normalRange": null,
            "baseKpiId": 0,
            "calKpiPeriod": null,
            "timeDeviation": 0,
            "industryId": null,
            "displayParam": null,
            "instance": 0,
            "compress": false,
            "compressTime": 0,
            "deadZoneRange": 0.0,
            "interval": false,
            "intervalTime": 0,
            "type": "kpi",
            "serial": 2,
            "tagModel": false,
            "exportDataModelId": 0,
            "autoCreation": false,
            "kpi": true,
            "number": true,
            "kpiType": false
        }],
        "stackTrace": null
    }
    

    有没有特别的发现?
    是的,数据项的属性【id】和【uid】有不同的展现方式:一号炉口的id=9和uid=314888726511563是不一样的,而二号炉口的id=378837143666810和uid=378837143666810却是一样的。这个是什么原因造成的呢?
    在解答这个问题之前,我们看一下模板里添加数据项的两种方式

    第一种:一个输入的数据项
    一个输入的数据项

    这种方式产生的数据项【id】和【uid】是一样的

    autoCreation: false
    baseKpiId: 0
    calKpiPeriod: null
    canEdit: true
    compress: false
    compressTime: 0
    conditionField: null
    createTime: "2018-11-12T02:49:06.160+0000"
    deadZoneRange: 0
    description: null
    displayParam: null
    domainPath: "/0/314888726511165/"
    exportDataModelId: 0
    expression: null
    granularity: 5
    granularityUnit: "MINUTE"
    icon: null
    id: 490232995857795
    industryId: null
    instance: 0
    interval: false
    intervalTime: 0
    keepPeriod: 0
    kpi: true
    kpiType: false
    label: "输入一个数据项"
    modelId: 314888726511536
    modelIdList: null
    modifyTime: "2018-11-12T02:49:06.160+0000"
    name: "输入一个数据项"
    noSave: false
    normalRange: null
    number: true
    orCondition: null
    range: null
    saveInterval: 0
    serial: 10
    tagModel: false
    timeDeviation: 0
    triggerTime: null
    type: "kpi"
    uid: 490232995857795
    unit: null
    unitId: null
    values: {}
    
    第二种:一个选择的数据项
    一个选择的数据项

    这种方式产生的数据项【id】和【uid】是不一样的,id来源于选择的这个数据项,比如选中了【风机状态】,这样的好处是我们能够保证每一个模板中数据项id是一样的

    utoCreation: false
    baseKpiId: 0
    calKpiPeriod: null
    canEdit: true
    compress: false
    compressTime: 0
    conditionField: null
    createTime: "2018-11-12T02:53:19.128+0000"
    deadZoneRange: 0
    description: null
    displayParam: null
    domainPath: "/0/314888726511165/"
    exportDataModelId: 0
    expression: null
    granularity: 5
    granularityUnit: "MINUTE"
    icon: null
    id: 42067
    industryId: null
    instance: 0
    interval: false
    intervalTime: 0
    keepPeriod: 0
    kpi: true
    kpiType: false
    label: "风机状态"
    modelId: 314888726511536
    modelIdList: null
    modifyTime: "2018-11-12T02:53:19.128+0000"
    name: "风机状态"
    noSave: false
    normalRange: null
    number: true
    orCondition: null
    range: null
    saveInterval: 0
    serial: 11
    tagModel: false
    timeDeviation: 0
    triggerTime: null
    type: "kpi"
    uid: 490232995857883
    unit: "NA"
    unitId: null
    values: {}
    

    那么这些来源于选择的数据项又是怎么来的,这是一个好问题,其实平台中数据项一部分来自内置,另一部分来自各个用户的创建。

    2、什么是模板的指令?

    数据项的数据如果采集自一个读写线圈或寄存器的话,那么客户应当可以对其进行控制(取决于授权)。
    比如我们在模板的指令中添加了如下几个指令,方便对炉口进行管理控制


    设备模板的指令
    一个指令的配置

    这里很清楚的表示了,我们是要对一号炉口进行控制,一号炉口这个数据项又是来源于我们之前的模板定义。
    所以,模板的指令是基于模板的数据项来创建的。
    来一段代码:

    {
        "code": "0",
        "message": null,
        "data": [{
            "domainPath": "/0/314888726511165/",
            "id": 378837143666848,
            "label": null,
            "createTime": "2018-08-29T07:49:10.973+0000",
            "modifyTime": "2018-11-09T13:01:16.383+0000",
            "orCondition": null,
            "conditionField": null,
            "values": {},
            "name": "一号炉灶控制",
            "description": "",
            "icon": null,
            "canEdit": true,
            "noSave": false,
            "commandCode": "1001",
            "commandName": null,
            "commandType": "nor",
            "kpiDefinitionIds": [314888726511563],
            "params": [{
                "domainPath": null,
                "id": 314888726511563,
                "label": "一号炉口",
                "createTime": null,
                "modifyTime": null,
                "orCondition": null,
                "conditionField": null,
                "values": {},
                "name": "DO1",
                "description": null,
                "icon": null,
                "canEdit": false,
                "noSave": false,
                "defaultValue": null,
                "uid": 0,
                "dataType": "String",
                "modelId": 0,
                "sourceType": null,
                "sourceValue": null,
                "sourceValueExtra": null,
                "matchType": null,
                "range": null,
                "attrType": null,
                "attrTypeSort": 0
            }],
            "modelId": 314888726511551,
            "kpiName": null
        }, {
            "domainPath": "/0/314888726511165/",
            "id": 378837143666849,
            "label": null,
            "createTime": "2018-08-29T07:49:23.015+0000",
            "modifyTime": "2018-11-09T13:01:21.161+0000",
            "orCondition": null,
            "conditionField": null,
            "values": {},
            "name": "二号炉灶控制",
            "description": "",
            "icon": null,
            "canEdit": true,
            "noSave": false,
            "commandCode": "1002",
            "commandName": null,
            "commandType": "nor",
            "kpiDefinitionIds": [378837143666810],
            "params": [{
                "domainPath": null,
                "id": 378837143666810,
                "label": "二号炉口",
                "createTime": null,
                "modifyTime": null,
                "orCondition": null,
                "conditionField": null,
                "values": {},
                "name": "DO2",
                "description": null,
                "icon": null,
                "canEdit": false,
                "noSave": false,
                "defaultValue": null,
                "uid": 0,
                "dataType": "String",
                "modelId": 0,
                "sourceType": null,
                "sourceValue": null,
                "sourceValueExtra": null,
                "matchType": null,
                "range": null,
                "attrType": null,
                "attrTypeSort": 0
            }],
            "modelId": 314888726511551,
            "kpiName": null
        }, {
            "domainPath": "/0/314888726511165/",
            "id": 378837143666861,
            "label": null,
            "createTime": "2018-08-29T07:57:03.943+0000",
            "modifyTime": "2018-11-09T13:01:49.406+0000",
            "orCondition": null,
            "conditionField": null,
            "values": {},
            "name": "所有炉灶控制",
            "description": "",
            "icon": null,
            "canEdit": true,
            "noSave": false,
            "commandCode": "1000",
            "commandName": null,
            "commandType": "nor",
            "kpiDefinitionIds": [314888726511563, 378837143666810],
            "params": [{
                "domainPath": null,
                "id": 378837143666810,
                "label": "二号炉口",
                "createTime": null,
                "modifyTime": null,
                "orCondition": null,
                "conditionField": null,
                "values": {},
                "name": "DO2",
                "description": null,
                "icon": null,
                "canEdit": false,
                "noSave": false,
                "defaultValue": null,
                "uid": 0,
                "dataType": "String",
                "modelId": 0,
                "sourceType": null,
                "sourceValue": null,
                "sourceValueExtra": null,
                "matchType": null,
                "range": null,
                "attrType": null,
                "attrTypeSort": 0
            }, {
                "domainPath": null,
                "id": 314888726511563,
                "label": "一号炉口",
                "createTime": null,
                "modifyTime": null,
                "orCondition": null,
                "conditionField": null,
                "values": {},
                "name": "DO1",
                "description": null,
                "icon": null,
                "canEdit": false,
                "noSave": false,
                "defaultValue": null,
                "uid": 0,
                "dataType": "String",
                "modelId": 0,
                "sourceType": null,
                "sourceValue": null,
                "sourceValueExtra": null,
                "matchType": null,
                "range": null,
                "attrType": null,
                "attrTypeSort": 0
            }],
            "modelId": 314888726511551,
            "kpiName": null
        }],
        "stackTrace": null
    }
    

    从代码中,很明白的看出了,指令的params参数的对象里,保存的是每一个数据项的信息,并且参数对象的【id】属性对应的是数据项中的【uid】,这一点很重要。因为数据项uid是能够唯一区分数据项的,所以指令的参数对象ID使用数据项的uid来作为唯一值。

    3、什么是指令策略?

    为了能够让平台进行自动化调整,比如什么时候开机、关机;又比如什么条件下做某些事情。那么需要一个能够设置指令策略的功能。平台免费提供了这样高级的功能:


    指令策略管理

    上图的策略我们先看一下数据的结构:

    {
        "code": "0",
        "message": null,
        "data": [{
            "domainPath": "/0/314888726511165/",
            "id": 378837143666892,
            "createTime": "2018-08-29T09:07:11.229+0000",
            "modifyTime": "2018-08-30T06:52:18.574+0000",
            "name": "炉灶自动开机",
            "description": "",
            "cron": "20 * * * * ? *",
            "frequency": "MINUTE",
            "directiveDomainPath": "/0/314888726511165/",
            "deviceModelId": 314888726511551,
            "deviceIds": [],
            "directiveId": 378837143666861,
            "kpiDefinitionIds": [378837143666810, 9],
            "thresholds": [{
                "targetKpiId": 378837143666810,
                "kpiId": 325243175548712,
                "compareType": "EQ",
                "thresholdValue": "0"
            }, {
                "targetKpiId": 9,
                "kpiId": 325243175548712,
                "compareType": "EQ",
                "thresholdValue": "0"
            }],
            "params": [{
                "kpiId": 378837143666810,
                "name": "DO2",
                "value": "1"
            }, {
                "kpiId": 9,
                "name": "DO1",
                "value": "1"
            }]
        }, {
            "domainPath": "/0/314888726511165/",
            "id": 378837143667579,
            "createTime": "2018-08-29T10:32:37.829+0000",
            "modifyTime": "2018-08-29T11:16:22.182+0000",
            "name": "炉灶自动关机",
            "description": "",
            "cron": "30 * * * * ? *",
            "frequency": "MINUTE",
            "directiveDomainPath": "/0/314888726511165/",
            "deviceModelId": 314888726511551,
            "deviceIds": [],
            "directiveId": 378837143666861,
            "kpiDefinitionIds": [378837143666810, 9],
            "thresholds": [{
                "targetKpiId": 378837143666810,
                "kpiId": 325243175548712,
                "compareType": "EQ",
                "thresholdValue": "1"
            }, {
                "targetKpiId": 9,
                "kpiId": 325243175548712,
                "compareType": "EQ",
                "thresholdValue": "1"
            }],
            "params": [{
                "kpiId": 378837143666810,
                "name": "DO2",
                "value": "0"
            }, {
                "kpiId": 9,
                "name": "DO1",
                "value": "0"
            }]
        }],
        "stackTrace": null
    }
    

    很明显,策略里params的对象参数kpiId是数据项的id,所以这里要注意一下:指令和指令策略里,关于id和uid并不一样。

    相关文章

      网友评论

          本文标题:模板数据项、指令和指令策略间的关系

          本文链接:https://www.haomeiwen.com/subject/njlaxqtx.html