# 查询 ## 请求体 json ![web dev](./img/web-swager_009.jpg) ::: details 查看代码 ``` { "Cascade": [ { "Cascade": [ null ], "Distinct": true, "Filters": "string", "Group": { "AvgList": [ "string" ], "Count": true, "MaxList": [ "string" ], "MinList": [ "string" ], "NameList": [ "string" ], "SumList": [ "string" ] }, "Name": "string", "Orders": "name asc, createTime desc", "Projection": [ "string" ] } ], "Distinct": true, "Filters": "string", "Group": { "AvgList": [ "string" ], "Count": true, "MaxList": [ "string" ], "MinList": [ "string" ], "NameList": [ "string" ], "SumList": [ "string" ] }, "Orders": "name asc, createTime desc", "PageNumber": 1, "PageSize": 50, "Projection": [ "string" ] } ``` ::: ## 应答 json ::: details 查看代码 ```metadata json { "Content":[ { "EquipID":"Eq3702020002f9052971335b417b896c73bdcd832f2d", "EquipLocalId":"CCTV-15F-06-05", "BimId":"Pj37020200023d180a0a876a11eaad60abc9d54aea48F20:8240980", "BimLocation":"-106089.73,64853.35,92300.0" } ], "Message":"接口失败会返回原因", "PageNumber":1, "PageSize":50, "Result":"success", "Total":1 } ``` ::: ## 分页 PageNumber 请求页码 Int 值 默认 1 PageSize 请求条数 Int 值 默认 50 条 通用接口中 PageSize 请求条数最大为 1000,为了避免大量的数据请求占用过多的资源,减少带宽 ## 过滤条件 Filters 中编写过滤条件 例如: ```metadata json { "Filters": "ProjectId = 'Pj3702020002'; Category = 'FSSN' ", "PageNumber": 1, "PageSize": 50 } ``` 分号(;代表 and )还可以使用 and 来查询,例如: ```metadata json { "Filters": "ProjectId = 'Pj3702020002' and Category = 'FSSN' ", "PageNumber": 1, "PageSize": 50 } ``` 更多详细查询条件以及操作符使用参考 [ “过滤条件” 操作符介绍](./filters) ## 排序 Orders 排序,默认升序 asc 可以多字段排序,升序 asc 降序 desc,例如: ```metadata json { "Filters": "ProjectId = 'Pj3702020002' and Category = 'FSSN' ", "PageNumber": 1, "PageSize": 50, "Orders": "EquipName, CreateTime desc" } ``` 多字段排序从前往后依次按照 Orders 中的条件排序返回结果。 ## 指定应答属性 Projection 指定后返回的属性,有些时候并不想把某些对象所有信息点都查出来,只是用几个属性,提高数据交互质量可以指定需要的属性,例如: ```metadata json { "Filters": "ProjectId = 'Pj3702020002' and Category = 'FSSN' ", "PageNumber": 1, "PageSize": 50, "Projection": [ "EquipID","EquipName","EquipLocalId","EquipLocalName","Category" ] } ``` 如上面的请求体就会返回 Projection 中指定的属性 ## 去重 数据统计的时候会用到这个功能,比如统计某一个楼层下有多少种设备类型 ``` { "Distinct": true, "Filters": "ProjectId = 'Pj4101020002';FloorId = 'Fl410102000212f498f8128147a7bfdb853e80bd5596'", "PageNumber": 1, "PageSize": 50, "Projection": [ "Category" ] } ``` 返回结果 ```metadata json { "Content": [ { "Category": "AEOV" }, { "Category": "ATFC" } ], "Message": "", "PageNumber": 1, "PageSize": 2, "Result": "success", "Total": 20 } ``` 去重是不根据 Projection 指定返回的属性去重的,如果返回的字段中包含id,是无法去重的,因为id通常是唯一的,去重是根据指定返回的字段为一个从整体去重的。 ## 级联查询 级联查询:在查询某一个对象的时候想要知道和这个对象有关系的有哪些对象,可以通过级联查询来操作,例如查询设备,以及所在的业务空间: 请求体 ``` { "Cascade": [ { "Name": "zoneSpaceInBase" } ], "Filters": "ProjectId = 'Pj1101020002' and EquipID = 'Eq11010200020321acc7e6f311e88ca4e5a21975b346' ", "PageNumber": 1, "PageSize": 50 } ``` 返回结果 ```metadata json { "Content": [ { "BuildingId": "Bd110102000223fbec0accfb11e8a471b5d1be3b6dfe", "Category": "ATFU", "CreateTime": "2019-06-19 12:57:11", "EquipID": "Eq11010200020321acc7e6f311e88ca4e5a21975b346", "EquipLocalID": "ATFU-TOP-N", "EquipLocalName": "楼顶北新风机组", "EquipName": "新风机组-E5L73", "EquipQRCode": "9ca5b7b0daab49999d602ac4ccdcf105", "LastUpdate": "2020-08-18 15:20:57", "ProjectId": "Pj1101020002", "ZoneSpaceBaseIn": [ { "BuildingId": "Bd110102000223fbec0accfb11e8a471b5d1be3b6dfe", "FloorId": "Fl1101020002fbdcd07ed5cb11e88bee4dbb551fd992", "LastUpdate": "2020-07-17 17:17:19", "ObjectType": "GeneralZone", "ProjectId": "Pj1101020002", "RoomFuncType": "311", "RoomID": "Sp11010200024fdbd800e0aa11e88bee13864ca4ba47", "RoomLocalID": "7F-A801-1", "RoomLocalName": "A-801总裁室", "RoomName": "空间-ISRWU", "RoomQRCode": "2012bb68-2c9a-4bcc-a9a4-e0128634bf65" } ] } ], "Message": "", "PageNumber": 1, "PageSize": 50, "Result": "success", "Total": 1 } ``` ZoneSpaceBaseIn 中的数据就是当前设备所在的业务空间 级联的关系数据也支持 Filters 条件查询 Orders 排序 Projection 指定返回的字段,去重 Distinct ,级联出来的空间对象内部还可以继续级联 ``` { "Cascade": [ { "Cascade": [ "Name": "generalSystem" ], "Name": "zoneSpaceInBase" } ], "Filters": "ProjectId = 'Pj1101020002' and EquipID = 'Eq11010200020321acc7e6f311e88ca4e5a21975b346' ", "PageNumber": 1, "PageSize": 50 } ``` 上面的例子是查询设备 ,设备坐在的业务空间,业务空间和系统的关系,返回结构和上面的类似,在空间的数据中会出现系统的实例数据 ## 综合示例 查询某一楼层下的低压开关柜设备,使用创建时间加设备 ID 排序升序,指定返回字段为 EquipID EquipName Category EquipLocalID EquipLocalName 返回数量为100条 ,顺便查出来设备所在的默认业务空间,设备下的部件,设备关联的资产,设备和竖井的关系实例,竖井指定返回id和名称,示例如下: ```metadata json { "Cascade": [ { "Filters": "ObjectType = 'GeneralZone'", "Name": "zoneSpaceInBase" }, { "Name": "component" }, { "Name": "property" }, { "Name": "shaft", "Projection": [ "ShaftID", "ShaftName" ] } ], "Filters": "ProjectId = 'Pj4101020002';FloorId = 'Fl410102000212f498f8128147a7bfdb853e80bd5596'; Category = 'TDLS'", "Orders": "CreateTime asc,EquipID asc", "PageNumber": 1, "PageSize": 50, "Projection": [ "EquipID", "EquipName", "Category", "EquipLocalID", "EquipLocalName" ] } ``` 返回结果 ```metadata json { "Content":[ { "Category":"TDLS", "EquipID":"Eq11010200020321acc7e6f311e88ca4e5a21975b346", "EquipLocalID":"ATFU-TOP-N", "EquipLocalName":"楼顶北低压开关柜", "EquipName":"低压开关柜-E5L73", "ZoneSpaceBaseIn":[ { "BuildingId":"Bd110102000223fbec0accfb11e8a471b5d1be3b6dfe", "FloorId":"Fl1101020002fbdcd07ed5cb11e88bee4dbb551fd992", "ObjectType":"GeneralZone", "ProjectId":"Pj1101020002", "RoomFuncType":"311", "RoomID":"Sp11010200024fdbd800e0aa11e88bee13864ca4ba47", "RoomLocalID":"7F-A801-1", "RoomLocalName":"A-801室", "RoomName":"空间-ISRWU", } ], "component":[ { "Category":"TDLSDW", "EquipID":"Ec11010200020321acc7e6f311e88ca4e5a21975b303", "EquipLocalID":"ATFU-TOP-N-0", "EquipLocalName":"楼顶北低压开关柜抽屉" } ], "property":{ "Category":"LSA", "EquipID":"Pe11010200020321acc7e6f311e88ca4e5a21975b340", "EquipLocalID":"ATFU-TOP-N", "EquipLocalName":"楼顶北低压开关柜" }, "shaftList":[ { "ShaftID":"Sh11010200020321acc7e6f311e88ca4e5a21975b349", "ShaftName":"楼梯间" } ] } ], "Message":"", "PageNumber":1, "PageSize":50, "Result":"success", "Total":1 } ```