运算符相关示例
嵌套and、or和in
{ "params": { "sort": "desc", "orderBy": "name", "filter": { "joiner": "and", "conditions": [ { "conditionName": "name", "operator": "=", "conditionValues": [ "wyc" ] }, { "joiner": "or", "conditions": [ { "conditionName": "creator", "operator": "=", "conditionValues": [ "wyc" ] }, { "conditionName": "modifier", "operator": "in", "conditionValues": [ "wyc", "wxf" ] } ] } ] } } }
如上示例可得出如下SQL查询语句:
(name=wyc) and ( (creator=wyc) or (modifier in (wyc, wxf) ) ) order by name desc
其中,“joiner”用于控制相同层次的“conditions”间的关系。
单个条件
- 示例1:
{ "params": { "sort": "desc", "orderBy": "name", "filter": { "conditionName": "name", "operator": "=", "conditionValues": [ "wyc" ] } } }
- 示例2:
{ "params": { "sort": "desc", "orderBy": "name", "filter": { "joiner": "and", // and或者or "conditions": [ { "conditionName": "name", "operator": "=", "conditionValues": [ "wyc" ] } ] } } }
模型自身属性
支持使用ConditionName和orderBy字段。如果输入的入参不是该模型的属性,会提示错误。其错误示例如下所示:
{ "result": "FAIL", "data": [], "errors": [ { "code": "rdm.coresdk.unknown.exception", "message": "unknown exception", "detailMessage": "org.hibernate.QueryException: could not resolve property: string of: com.example.it.rdm.bean.module.DM0829002 [from com.example.it.rdm.bean.module.DM0829002 p left join fetch p.master where p.rdmDeleteFlag = 0 and UPPER(p.string) = UPPER('string') and p.latest = '1' order by p.id desc]" } ] }
其中,“could not resolve property: string”为具体错误的属性名称。
ISNULL和NOTNULL传参
{ "params": { "sort": "desc", "orderBy": "name", "filter": { "joiner": "and", // 或者or "conditions": [ { "conditionName": "name", "operator": "ISNULL", // 或者NOTNULL "conditionValues": [ // conditionValues可不写 "wyc" ] } ] } } }
参考对象
假设TestQuery的参考对象是SimpleEntity(别名为ref),SimpleEntity的别名为ref,有Long类型的ID字段和String类型的Name字段。用户希望对SimpleEntity过滤ID,其示例代码如下所示:
{ "params": { "filter": { "joiner": "and", "conditions": [ { "conditionName": "ref.id", "operator": "=", "conditionValues": [ "406889137980243968" ] } ] } } }
如需过滤其他属性,基于新增过滤条件即可。
扩展属性
扩展属性的固定前缀为“extAttrs”,格式有“extAttrs.扩展属性名”和“extAttrs.扩展属性名.value”两种。其中,“extAttrs.扩展属性名.value”适用于自定义精度的扩展属性。
{ "params": { "filter": { "joiner": "and", "conditions": [ { "conditionName": "extAttrs.extAttrName1", "operator": "=", "conditionValues": [ "406889137980243968" ] }, { "conditionName": "extAttrs.extAttrName2.value", "operator": "=", "conditionValues": [ "12.133" ] } ] } } }
分类属性
分类属性的固定前缀为“clsAttrs”,格式有“clsAttrs.分类名.分类内属性名”和“clsAttrs.分类名.分类内属性名.value”两种。其中,“clsAttrs.分类名.分类内属性名.value”适用于自定义精度的分类属性。
{ "params": { "filter": { "joiner": "and", "conditions": [ { "conditionName": "clsAttrs.clsAttrName.attrName1", "operator": "=", "conditionValues": [ "123" ] }, { "conditionName": "clsAttrs.clsAttrName.attrName2.value", "operator": "=", "conditionValues": [ "12.123" ] } ] } } }
扩展类型+扩展属性/分类属性
扩展类型+扩展属性/分类属性的固定前缀为“clsAttrs”,格式有“clsAttrs.分类名.分类内属性名”和“clsAttrs.分类名.分类内属性名.value”两种。其中,“clsAttrs.分类名.分类内属性名.value”适用于自定义精度的扩展类型+扩展属性/分类属性。如需查询此类属性,需额外增加一个过滤条件(rdmExtensionType),用于指明具体的扩展类型。
以“services/dynamic/api/Test0928001/find/20/1”的URI为例:
{ "params": { "sort": "DESC", "orderBy": "lastUpdateTime", "filter": { "joiner": "and", "conditions": [ { "conditionName": "clsAttrs.A0001.Testz", "operator": "like", "conditionValues": [ "WWW" ] }, { "conditionName": "rdmExtensionType", "operator": "=", "conditionValues": [ "Test0928001" ] } ] }, "isNeedTotal": false } }
多字段排序
多字段排序一般使用“sorts”字段表示,其结构如下:
{ "sorts": [ { "sort": "DESC", "orderBy": "description" }, { "sort": "ASC", "orderBy": "name" } ] }
使用“sorts”字段后,将按照其列表顺序进行排序。如上所示,对象会先按照“description”进行倒序排序,再按照“name”进行正序排序。
以“services/api/SZAPITEST202211280329/find/20/1”的URI为例,使用如下接口进行多字段排序。
- Find接口:
{ "params": { "sorts": [ { "sort": "DESC", "orderBy": "description" }, { "sort": "ASC", "orderBy": "name" } ], "filter": { "joiner": "and", "conditions": [ { "conditionName": "description", "operator": "=", "conditionValues": [ "a" ] }, { "conditionName": "rdmDeleteFlag", "operator": "=", "conditionValues": [ "0" ] } ] } } }
- Query接口:
{ "params": { "sorts": [ { "sort": "DESC", "orderBy": "description" }, { "sort": "ASC", "orderBy": "name" } ], "filter": { "joiner": "and", "conditions": [ { "conditionName": "description", "operator": "=", "conditionValues": [ "a" ] }, { "conditionName": "rdmDeleteFlag", "operator": "=", "conditionValues": [ "0" ] } ] } } }
- Select接口:
{ "params": { "selectedField": [ { "name": "name", "nameAs": "nameAsName" }, { "name": "description", "nameAs": "nameAsDescription" }, { "name": "creator" }, { "name": "id" } ], "sorts": [ { "sort": "DESC", "orderBy": "name" }, { "sort": "asc", "orderBy": "id" } ], "filter": { "joiner": "and", "conditions": [ { "conditionName": "description", "operator": "=", "conditionValues": [ "a" ] } ] } } }