序号 | 分类 | 关键字 | 函数/变量 | 功能说明 | 适用范围 | 用法示例 | 备注 |
---|
1 | 全局变量
| this.className this.oprName |
| 获取当前类名(当前脚本所在表单对应的类名) 获取当前操作名 |
|
代码块 |
---|
language | js |
---|
title | this.className |
---|
linenumbers | true |
---|
| this.logger.info("this.className - " + this.className);
this.logger.info("this.oprName - " + this.oprName); |
| |
2 | this.user | - token:当前用户token
- oid:当前用户userId(同oid)
- userId:当前用户英文名userName
- userName:当前用户显示名displayName
- displayName:显示名
- userGroups:用户组
| 获取当前登录用户信息,包括token、oid、userId、userName、displayName、userGroups等关键字 |
|
代码块 |
---|
language | js |
---|
title | this.user |
---|
linenumbers | true |
---|
| this.logger.info("this.user - " + JSON.stringify(this.user));
this.logger.info("this.user.token - " + this.user.token);
this.logger.info("this.user.oid - " + this.user.oid);
this.logger.info("this.user.userId - " + this.user.userId);
this.logger.info("this.user.userName - " + this.user.userName);
this.logger.info("this.user.displayName - " + this.user.displayName);
this.logger.info("this.user.userGroups - " + this.user.userGroups);
if (this.user.userGroups.length > 0) {
this.logger.info("this.user.userGroups[0] - " + this.user.userGroups[0]);
this.logger.info("this.user.userGroups[0].displayName - " + this.user.userGroups[0].displayName);
} |
| |
3 | this.env | - serverIp:当前服务器ip
- serverPort:当前服务器端口
- serverURL:当前服务器URL
- appConfig:application.properties文件中external.appConfig部分
- locale:当前语言环境
| DWF服务端的当前环境信息,包括appConfig、locale、serverIp、serverPort、serverURL等关键字 |
|
代码块 |
---|
language | js |
---|
title | this.env |
---|
linenumbers | true |
---|
| this.logger.info("this.env - " + JSON.stringify(this.env));
this.logger.info("this.env.serverIp - " + this.env.serverIp);
this.logger.info("this.env.serverPort - " + this.env.serverPort);
this.logger.info("this.env.serverURL - " + this.env.serverURL);
this.logger.info("this.env.appConfig - " + JSON.stringify(this.env.appConfig));
this.logger.info("this.env.appConfig.demoKey - " + JSON.stringify(this.env.appConfig.demoKey));
// 暂不支持以下方法
// this.logger.info("this.env.appConfig.demoKey.with.dots - " + JSON.stringify(this.env.appConfig.demoKey.with.dots));
this.logger.info("this.env.locale - " + JSON.stringify(this.env.locale));
this.logger.info("this.env.locale.name - " + this.env.locale.name); |
| |
4 | this.obj |
| 表单绑定的类对象 |
| 实体类: - this.obj.属性名,如this.obj.oid
代码块 |
---|
language | js |
---|
title | this.obj |
---|
linenumbers | true |
---|
| this.logger.info("this.obj - " + JSON.stringify(this.obj));
this.logger.info("this.obj.oid - " + this.obj.oid);
this.logger.info("this.obj.ceshiAttr - " + this.obj.ceshiAttr); |
关联类: - this.obj.relation_关联类属性名,如this.obj.relation_oid
- this.obj.left_左类属性名,如this.obj.left_oid
- this.obj.right_右类属性名,如this.obj.right_oid
代码块 |
---|
language | js |
---|
title | this.obj |
---|
linenumbers | true |
---|
| this.logger.info("this.obj - " + JSON.stringify(this.obj));
this.logger.info("this.obj.relation_oid - " + this.obj.relation_oid);
this.logger.info("this.obj.left_oid - " + this.obj.left_oid);
this.logger.info("this.obj.right_oid - " + this.obj.right_oid); |
| 实体类
关联类
|
5 | this.objs |
| 前端多对象控件选中的对象传递到后端(多选的多个对象,默认多对象控件有效) |
| 实体类:(x代表第x个元素) - this.objs[x].属性名,如this.objs[0].oid
代码块 |
---|
language | js |
---|
title | this.objs |
---|
linenumbers | true |
---|
| this.logger.info("this.objs - " + JSON.stringify(this.objs));
if (this.objs.length > 0) {
this.logger.info("this.objs[0].oid - " + this.objs[0].oid);
this.logger.info("this.objs[0].ceshiAttr - " + this.objs[0].ceshiAttr);
} |
关联类:(x代表第x个元素) - this.objs[x].relation_关联类属性名,如this.objs[0].relation_oid
- this.objs[x].left_左类属性名,如this.objs[0].left_oid
- this.objs[x].right_右类属性名,如this.objs[0].right_oid
代码块 |
---|
language | js |
---|
title | this.objs |
---|
linenumbers | true |
---|
| this.logger.info("this.objs - " + JSON.stringify(this.objs));
if (this.objs.length > 0) {
this.logger.info("this.objs[0].relation_oid - " + this.objs[0].relation_oid);
this.logger.info("this.objs[0].left_oid - " + this.objs[0].left_oid);
this.logger.info("this.objs[0].right_oid - " + this.objs[0].right_oid);
} |
| 实体类
关联类
|
6 | this.selectedObj |
| 前端多对象控件选中的对象传递到后端(选中的多个对象中的第一条,默认多对象控件有效) |
| 实体类: this.selectedObj.属性名,如this.selectedObj.oid 代码块 |
---|
language | js |
---|
title | this.selectedObj |
---|
linenumbers | true |
---|
| this.logger.info("this.selectedObj - " + JSON.stringify(this.selectedObj));
if (this.selectedObj != null) {
this.logger.info("this.selectedObj.oid - " + this.selectedObj.oid);
this.logger.info("this.selectedObj.ceshiAttr - " + this.selectedObj.ceshiAttr);
} |
关联类: this.selectedObj.relation_关联类属性名,如this.selectedObj.relation_oid this.selectedObj.left_左类属性名,如this.selectedObj.left_oid this.selectedObj.right_右类属性名,如this.selectedObj.right_oid 代码块 |
---|
language | js |
---|
title | this.selectedObj |
---|
linenumbers | true |
---|
| this.logger.info("this.selectedObj - " + JSON.stringify(this.selectedObj));
if (this.selectedObj != null) {
this.logger.info("this.selectedObj.relation_oid - " + this.selectedObj.relation_oid);
this.logger.info("this.selectedObj.left_oid - " + this.selectedObj.left_oid);
this.logger.info("this.selectedObj.right_oid - " + this.selectedObj.right_oid);
} |
| 实体类
关联类
|
7 | this.selectedObjs |
| 前端多对象控件选中的对象传递到后端(多选的多个对象,默认多对象控件有效) |
| 实体类:(x代表第x个元素) this.selectedObjs[x].属性名,如this.selectedObjs[0].oid 代码块 |
---|
language | js |
---|
title | this.selectedObjs |
---|
linenumbers | true |
---|
| this.logger.info("this.selectedObjs - " + JSON.stringify(this.selectedObjs));
if (this.selectedObjs != null && this.selectedObjs.length > 0) {
this.logger.info("this.selectedObjs[0].oid - " + this.selectedObjs[0].oid);
this.logger.info("this.selectedObjs[0].ceshiAttr - " + this.selectedObjs[0].ceshiAttr);
} |
关联类:(x代表第x个元素) this.selectedObjs[x].relation_关联类属性名,如this.selectedObjs[0].relation_oid this.selectedObjs[x].left_左类属性名,如this.selectedObjs[0].left_oid this.selectedObjs[x].right_右类属性名,如this.selectedObjs[0].right_oid 代码块 |
---|
language | js |
---|
title | this.selectedObjs |
---|
linenumbers | true |
---|
| this.logger.info("this.selectedObjs - " + JSON.stringify(this.selectedObjs));
if (this.selectedObjs != null && this.selectedObjs.length > 0) {
this.logger.info("this.selectedObjs[0].relation_oid - " + this.selectedObjs[0].relation_oid);
this.logger.info("this.selectedObjs[0].left_oid - " + this.selectedObjs[0].left_oid);
this.logger.info("this.selectedObjs[0].right_oid - " + this.selectedObjs[0].right_oid);
} |
| 实体类
关联类
|
8 | this.oldObj |
| 获取当前更新类的更新前的数据对象 可以是实体类和关联类 | 该关键字只能使用在类事件上 | 与this.obj相同 |
|
9 | this.oldObjs |
| 获取当前更新类的更新前的多条数据对象 可以是实体类和关联类 | 该关键字只能使用在类事件上 | 与this.objs相同 |
|
10 | this.customData |
| 前端脚本调用后端脚本传入的自定义参数 参数需要是Json对象 | 在前端脚本中通过this.callServer(param,"scriptName");这个param对应的是后端脚本的customData |
代码块 |
---|
language | js |
---|
title | this.customData |
---|
linenumbers | true |
---|
| // 前端脚本
this.callServer({"a": 1, "b": 2}).then(res => { console.log(res); });
// 后端脚本
this.logger.info("this.customData - " + JSON.stringify(this.customData)); |
| |
11 | this.generateUUID() |
| 返回一个全局唯一的UUID(32位长度) |
|
代码块 |
---|
language | js |
---|
title | this.generateUUID() |
---|
linenumbers | true |
---|
| this.logger.info("this.generateUUID() - " + this.generateUUID()); |
| |
12 | 数据交互
| this.omf
| getByOid(Integer oid, String className) getByOid(String oid, String className) getByOid(String oid, String className, boolean flatten) | 根据对象oid和类名查询对象详情 传入: - oid:对象全局唯一标识
- className:类英文名
- flatten:是否返回拉平格式,只对关联类生效,默认为false
返回:ProxyObject |
|
代码块 |
---|
language | js |
---|
title | this.omf.getByOid |
---|
linenumbers | true |
---|
| var entityObj = this.omf.getByOid("63ED49BD68B7B841B985C9658364D993", this.className);
this.logger.info(JSON.stringify(entityObj));
this.logger.info("entityObj.oid - " + entityObj.oid);
var flattenRelationObj = this.omf.getByOid("FD00543903AED649BBC257F1190FD7A4", "AllTestRel", true);
this.logger.info(JSON.stringify(flattenRelationObj));
this.logger.info("flattenRelationObj.relation_oid - " + flattenRelationObj.relation_oid);
this.logger.info("flattenRelationObj.left_tstring - " + flattenRelationObj.left_tstring); |
| |
13 | handleQueryData(String condition, String className) handleQueryData(String condition, String className, boolean withEnv) | 根据自定义查询条件查询对象列表 传入: - condition:快速/原生查询语句
- className:类英文名
- withEnv:是否判断权限,默认为false
返回: List<ProxyObject> | condition: - 支持快速查询条件,也支持原生查询条件
- 原生查询条件需要补充前缀“nativequery:”
- 关联类查询是joined查询,需要写入拉平格式的查询语句,查询结果也是拉平格式
|
代码块 |
---|
language | js |
---|
title | this.omf.handleQueryData |
---|
linenumbers | true |
---|
| // 快速查询
this.logger.info("---------- 快速查询 - 实体类 ----------");
let entitySql = `and obj.tstring is not null limit 2`;
var entityObjs = this.omf.handleQueryData(entitySql, this.className);
this.logger.info(JSON.stringify(entityObjs));
this.logger.info("entityObjs.length - " + entityObjs.length);
this.logger.info("entityObjs[0].oid" + entityObjs[0].oid);
this.logger.info("---------- 快速查询 - 关联类 ----------");
let relationSql = `and obj.relation_relstring is not null limit 2`;
var relationObjs = this.omf.handleQueryData(relationSql, "AllTestRel");
this.logger.info(JSON.stringify(relationObjs));
this.logger.info("relationObjs.length - " + relationObjs.length);
this.logger.info("relationObjs[0].relation_oid" + relationObjs[0].relation_oid);
this.logger.info("relationObjs[0].left_id" + relationObjs[0].left_id);
// 原生查询
this.logger.info("---------- 原生查询 - 实体类 ----------");
let entityNativeSql = `nativequery:select plt_currentprocess as "currentProcess",plt_createtime as "createTime",plt_creator as "creator",plt_lastmodifytime as "lastModifyTime",plt_lastmodifier as "lastModifier",plt_id as "id",plt_owner as "owner",plt_oid as "oid",plt_tcustombind as "tcustombind",plt_dynamicparams as "dynamicParams",plt_tstring as "tstring",plt_tuuid as "tuuid",plt_ttimestamp as "ttimestamp",plt_tboolean as "tboolean",plt_tinteger as "tinteger",plt_tdouble as "tdouble",plt_ttimeseries as "ttimeseries",plt_tlong as "tlong",plt_ttime as "ttime",plt_tlocalfile as "tlocalfile",plt_tclob as "tclob",plt_ttext as "ttext",cast(plt_tjson as varchar) as "tjson",plt_www as "www",plt_testlength as "testLength",plt_ceshiattr as "ceshiAttr",plt_signstring as "signString",plt_hhh as "hhh" from plt_test_alltest where 1=1 limit 2`;
var entityNativeObjs = this.omf.handleQueryData(entityNativeSql, this.className);
this.logger.info("entityNativeObjs.length - " + entityNativeObjs.length);
this.logger.info("entityNativeObjs[0].oid" + entityNativeObjs[0].oid);
this.logger.info("---------- 原生查询 - 关联类 ----------");
let relationNativeSql = `nativequery:select leftclass.plt_currentprocess as "left_currentProcess",leftclass.plt_createtime as "left_createTime",leftclass.plt_creator as "left_creator",leftclass.plt_lastmodifytime as "left_lastModifyTime",leftclass.plt_lastmodifier as "left_lastModifier",leftclass.plt_id as "left_id",leftclass.plt_owner as "left_owner",leftclass.plt_oid as "left_oid",leftclass.plt_tcustombind as "left_tcustombind",leftclass.plt_dynamicparams as "left_dynamicParams",leftclass.plt_tstring as "left_tstring",leftclass.plt_tuuid as "left_tuuid",leftclass.plt_ttimestamp as "left_ttimestamp",leftclass.plt_tboolean as "left_tboolean",leftclass.plt_tinteger as "left_tinteger",leftclass.plt_tdouble as "left_tdouble",leftclass.plt_ttimeseries as "left_ttimeseries",leftclass.plt_tlong as "left_tlong",leftclass.plt_ttime as "left_ttime",leftclass.plt_tlocalfile as "left_tlocalfile",leftclass.plt_tclob as "left_tclob",leftclass.plt_ttext as "left_ttext",cast(leftclass.plt_tjson as varchar) as "left_tjson",leftclass.plt_www as "left_www",leftclass.plt_testlength as "left_testLength",leftclass.plt_ceshiattr as "left_ceshiAttr",leftclass.plt_signstring as "left_signString",leftclass.plt_hhh as "left_hhh",relationclass.plt_createtime as "relation_createTime",relationclass.plt_creator as "relation_creator",relationclass.plt_version as "relation_version",relationclass.plt_rightclass as "relation_rightClass",relationclass.plt_leftoid as "relation_leftOid",relationclass.plt_rightoid as "relation_rightOid",relationclass.plt_lastmodifytime as "relation_lastModifyTime",relationclass.plt_oid as "relation_oid",relationclass.plt_lastmodifier as "relation_lastModifier",relationclass.plt_rightrev as "relation_rightRev",relationclass.plt_leftclass as "relation_leftClass",relationclass.plt_order as "relation_order",relationclass.plt_relint as "relation_relint",relationclass.plt_relstring as "relation_relstring",cast(relationclass.plt_reljson as varchar) as "relation_reljson",relationclass.plt_rellocalfile as "relation_relLocalfile",rightclass.plt_currentprocess as "right_currentProcess",rightclass.plt_createtime as "right_createTime",rightclass.plt_creator as "right_creator",rightclass.plt_lastmodifytime as "right_lastModifyTime",rightclass.plt_lastmodifier as "right_lastModifier",rightclass.plt_id as "right_id",rightclass.plt_owner as "right_owner",rightclass.plt_oid as "right_oid",rightclass.plt_tcustombind as "right_tcustombind",rightclass.plt_dynamicparams as "right_dynamicParams",rightclass.plt_tstring as "right_tstring",rightclass.plt_tuuid as "right_tuuid",rightclass.plt_ttimestamp as "right_ttimestamp",rightclass.plt_tboolean as "right_tboolean",rightclass.plt_tinteger as "right_tinteger",rightclass.plt_tdouble as "right_tdouble",rightclass.plt_ttimeseries as "right_ttimeseries",rightclass.plt_tlong as "right_tlong",rightclass.plt_ttime as "right_ttime",rightclass.plt_tlocalfile as "right_tlocalfile",rightclass.plt_tclob as "right_tclob",rightclass.plt_ttext as "right_ttext",cast(rightclass.plt_tjson as varchar) as "right_tjson",rightclass.plt_www as "right_www",rightclass.plt_testlength as "right_testLength",rightclass.plt_ceshiattr as "right_ceshiAttr",rightclass.plt_signstring as "right_signString",rightclass.plt_hhh as "right_hhh" from plt_cus_r_alltestrel relationclass left join plt_test_alltest leftclass on leftclass.plt_oid = relationclass.plt_leftoid left join plt_test_alltest rightclass on relationclass.plt_rightoid = rightclass.plt_oid where 1=1 limit 2`;
var relationNativeObjs = this.omf.handleQueryData(relationNativeSql, "AllTestRel");
this.logger.info("relationNativeObjs.length - " + relationNativeObjs.length);
this.logger.info("relationNativeObjs[0].relation_oid" + relationNativeObjs[0].relation_oid);
this.logger.info("relationNativeObjs[0].left_id" + relationNativeObjs[0].left_id); |
| |
14 | duplicateValueCheck(Map<String, Object> obj, String className, List<String> attrNames) | 判断对象中指定属性取值是否重复 传入: - obj:对象
- className:类英文名
- attrNames:需要判重的属性名列表
返回:List<String> 存在重复的属性名列表 |
|
代码块 |
---|
language | js |
---|
title | this.omf.duplicateValueCheck |
---|
linenumbers | true |
---|
| var dvc = this.omf.duplicateValueCheck({"id": "789", "tstring": "test", "currentProcess": "123"}, this.className, ["id", "tstring"]);
this.logger.info("duplicateValueCheck - " + dvc); |
以上代码中配置对id、tstring判重,返回结果为“存在重复的属性名列表“,没有重复则返回空列表 数据中,id和currentProcess重复,tstring不重复,因此返回结果为[id] | |
15 | create(Map<String, Object> obj, String className) create(Map<String, Object> obj, String className, boolean runScript) create(Map<String, Object> obj, String className, List<String> attrNames) create(Map<String, Object> obj, String className, boolean runScript, List<String> attrNames) | 创建对象 传入: - obj:对象
- className:类英文名
- runScript:是否运行前后处理脚本,默认为false
- attrNames:需要判重的属性名列表,默认为空
返回:ProxyObject 创建后的对象 |
|
代码块 |
---|
language | js |
---|
title | this.omf.create |
---|
linenumbers | true |
---|
| try {
var createdObj1 = this.omf.create({"tstring": "createByScript1", "id": 789}, this.className);
this.logger.info("createdObj1 - " + JSON.stringify(createdObj1));
} catch (err) {
this.ex.setFieldError("1创建失败", err.getMessage());
}
try {
var createdObj2 = this.omf.create({"tstring": "createByScript2", "id": 789}, this.className, ["id"]);
this.logger.info("createdObj2 - " + JSON.stringify(createdObj2));
} catch (err) {
this.ex.setFieldError("2创建失败", err.getMessage());
} |
| 对象1创建成功
对象2因为id重复判重而创建失败
|
16 | createObjs(List<Map<String, Object>> objs, String className) createObjs(List<Map<String, Object>> objs, String className, boolean runScript) createObjs(List<Map<String, Object>> objs, String className, List<String> attrNames) createObjs(List<Map<String, Object>> objs, String className, boolean runScript, List<String> attrNames) | 批量创建对象 传入: - objs:对象列表
- className:类英文名
- runScript:是否运行前后处理脚本,默认为false
- attrNames:需要判重的属性名列表,默认为空
返回:ProxyArray 创建后的对象列表 |
|
代码块 |
---|
language | js |
---|
title | this.omf.createObjs |
---|
linenumbers | true |
---|
| try {
var createdObjs = this.omf.createObjs([{"tstring": "createByScript1", "id": 001}, {"tstring": "createByScript2", "id": 002}], this.className);
this.logger.info("createdObjs - " + JSON.stringify(createdObjs));
this.logger.info("createdObjs[0].oid - " + createdObjs[0].oid);
this.logger.info("createdObjs[1].oid - " + createdObjs[1].oid);
} catch (err) {
this.ex.setFieldError("创建失败", err.getMessage());
} |
代码块 |
---|
language | js |
---|
title | this.omf.createObjs |
---|
linenumbers | true |
---|
| // omf.createObjs 脚本2
var myDate = new Date();
var objs = [];
var obj1 = {"tstring": "testObj1 " + myDate.toLocaleTimeString()};
var obj2 = {"tstring": "testObj2 " + myDate.toLocaleTimeString()};
objs.push(obj1);
objs.push(obj2);
this.logger.info("obj1.tstring - " + objs[0].tstring);
this.logger.info("obj2.tstring - " + objs[1].tstring);
var myCreates = this.omf.createObjs(objs, this.className);
this.logger.info("myCreates1.oid - " + myCreates[0].oid);
this.logger.info("myCreates2.oid - " + myCreates[1].oid);
this.res = myCreates; |
| 脚本1
脚本2
|
17 | edit(Map<String, Object> obj, String className) edit(Map<String, Object> obj, String className, boolean runScript) edit(Map<String, Object> obj, String className, List<String> attrNames) edit(Map<String, Object> obj, String className, boolean runScript, List<String> attrNames) | 编辑对象 传入: - obj:对象
- className:类英文名
- runScript:是否运行前后处理脚本,默认为false
- attrNames:需要判重的属性名列表,默认为空
返回:ProxyObject 修改后的对象 |
|
代码块 |
---|
language | js |
---|
title | this.omf.edit |
---|
linenumbers | true |
---|
| try {
var queryObjs = this.omf.handleQueryData(" and obj.tstring is not null limit 1", this.className);
if (queryObjs.length > 0) {
var newObj = queryObjs[0];
newObj.tstring = "editedByScript";
newObj.id = 999;
var editedObj = this.omf.edit(newObj, this.className);
this.logger.info("editedObj - " + JSON.stringify(editedObj));
this.logger.info("editedObj.tstring - " + editedObj.tstring);
} else this.logger.error("查询失败");
} catch (err) {
this.ex.setFieldError("更新失败", err.getMessage());
} |
| |
18 | editObjs(List<Map<String, Object>> objs, String className) editObjs(List<Map<String, Object>> objs, String className, boolean runScript) editObjs(List<Map<String, Object>> objs, String className, List<String> attrNames) editObjs(List<Map<String, Object>> objs, String className, boolean runScript, List<String> attrNames) | 批量编辑对象 传入: - objs:对象列表
- className:类英文名
- runScript:是否运行前后处理脚本,默认为false
- attrNames:需要判重的属性名列表,默认为空
返回:ProxyArray 修改后的对象列表 |
|
代码块 |
---|
language | js |
---|
title | this.omf.editObjs |
---|
linenumbers | true |
---|
| try {
var editedObjs = this.omf.editObjs([
{"oid": "AEF5B0B0CA6BE1448592CA3534F83A71", "tstring": "editedByScript1", "id": 111},
{"oid": "F94FD27B94685242900FA1FE54436A6F", "tstring": "editedByScript2", "id": 222}
], this.className);
this.logger.info("editedObjs - " + JSON.stringify(editedObjs));
this.logger.info("editedObjs[0].tstring - " + editedObjs[0].tstring);
this.logger.info("editedObjs[1].tstring - " + editedObjs[1].tstring);
} catch (err) {
this.ex.setFieldError("更新失败", err.getMessage());
} |
代码块 |
---|
language | js |
---|
title | this.omf.editObjs |
---|
linenumbers | true |
---|
| // omf.editObjs 脚本2(上接omf.createObjs脚本2)
myDate = new Date();
myCreates[0].tstring = "testObj1 edit " + myDate.toLocaleTimeString();
myCreates[1].tstring = "testObj2 edit " + myDate.toLocaleTimeString();
var myEdits = this.omf.editObjs(myCreates, this.className);
this.logger.info("myEdits1.tstring - " + myEdits[0].tstring);
this.logger.info("myEdits2.tstring - " + myEdits[1].tstring);
this.res = myEdits; |
| 脚本1
脚本2
|
19 | delete(Map<String, Object> obj, String className) delete(Map<String, Object> obj, String className, boolean runScript) | 删除对象 - obj:对象,必须包含oid字段
- className:类英文名
- runScript:是否运行前后处理脚本,默认为false
返回:Boolean 是否删除成功 |
|
代码块 |
---|
language | js |
---|
title | this.omf.delete |
---|
linenumbers | true |
---|
| let oid = "testoid";
var queryObj = this.omf.getByOid(oid, this.className);
let deleteRes1 = this.omf.delete(queryObj, this.className);
this.logger.info("deleteRes1 - " + deleteRes1);
let deleteRes2 = this.omf.delete({"oid": oid}, this.className);
this.logger.info("deleteRes2 - " + deleteRes2); |
| |
20 | deleteObjs(List<Map<String, Object>> objs, String className) deleteObjs(List<Map<String, Object>> objs, String className, boolean runScript) | 批量删除对象 - objs:对象列表,没个对象必须包含oid字段
- className:类英文名
- runScript:是否运行前后处理脚本,默认为false
返回:Boolean 所有对象是否删除成功 |
|
代码块 |
---|
language | js |
---|
title | this.omf.deleteObjs |
---|
linenumbers | true |
---|
| let deleteRes3 = this.omf.deleteObjs([{oid: "AEF5B0B0CA6BE1448592CA3534F83A71"}, {oid: "F94FD27B94685242900FA1FE54436A6F"}], this.className);
this.logger.info("deleteRes3 - " + deleteRes3); |
| |
21 | deleteByCondition(String condition, String className) deleteByCondition(String condition, String className, boolean runScript) | 按条件删除对象 - condition:查询语句
- className:类英文名
- runScript:是否运行前后处理脚本,默认为false
返回:Boolean 是否删除成功
|
|
代码块 |
---|
language | js |
---|
title | this.omf.deleteByCondition |
---|
linenumbers | true |
---|
| if (this.selectedObjs != null && this.selectedObjs.length > 0) {
var condition = `and obj.oid = '${this.selectedObjs[0].oid}'`;
this.logger.info("condition - " + condition);
let deleteRes4 = this.omf.deleteByCondition(condition, this.className);
this.logger.info("deleteRes4 - " + deleteRes4);
} else this.ex.setFieldError("删除失败", "请选择对象"); |
| |
22 | relCreate(Map<String, Object> flattenObj, String className) relCreate(Map<String, Object> flattenObj, String className, boolean runScript) relCreate(Map<String, Object> flattenObj, String className, List<String> flattenAttrNames) relCreate(Map<String, Object> flattenObj, String className, boolean runScript, List<String> flattenAttrNames) | 创建关联类对象,并创建/更新左右类对象 传入: - flattenObj:拉平格式对象,如
{ relation_oid: xxx, relation_xxx: xxx, left_oid: yyy, left_yyy: yyy, right_oid: zzz, right_zzz: zzz } - className:关联类英文名
- runScript:是否运行前后处理脚本,默认为false(目前只针对关联对象,其左右类的脚本始终会被执行)
- flattenAttrNames:需要判重的拉平格式属性名列表,默认为空
返回:ProxyObject 创建后的对象 |
|
代码块 |
---|
language | js |
---|
title | this.omf.relCreate |
---|
linenumbers | true |
---|
| // 新增关联对象及其左右类对象
let relObj1 = {
"left_tstring": "leftTstringTest1",
"right_id": "rightIdTest1",
"relation_relstring": "relStringTest1"
};
let relCreatedObj1 = this.omf.relCreate(relObj1, this.className);
this.logger.info("relCreatedObj1 - " + JSON.stringify(relCreatedObj1));
// 新增关联对象和左类对象,更新右类对象
let relObj2 = {
"left_tstring": "leftTstringTest2",
"right_id": "rightIdTest2",
"relation_relstring": "relStringTest2",
"relation_rightOid": "63ED49BD68B7B841B985C9658364D993"
};
let relCreatedObj2 = this.omf.relCreate(relObj2, this.className);
this.logger.info("relCreatedObj2 - " + JSON.stringify(relCreatedObj2)); |
| |
23 | relCreateObjs(List<Map<String, Object>> flattenObjs, String className) relCreateObjs(List<Map<String, Object>> flattenObjs, String className, boolean runScript) relCreateObjs(List<Map<String, Object>> flattenObjs, String className, List<String> attrNames) relCreateObjs(List<Map<String, Object>> flattenObjs, String className, boolean runScript, List<String> flattenAttrNames) | 批量创建关联类对象,含左类对象和右类对象 传入: - flattenObjs:拉平格式对象列表
- className:关联类英文名
- runScript:是否运行前后处理脚本,默认为false
- flattenAttrNames:需要判重的拉平格式属性名列表,默认为空
返回:ProxyArray 创建后的对象列表 |
|
代码块 |
---|
language | js |
---|
title | this.omf.relCreateObjs |
---|
linenumbers | true |
---|
| let relObj1 = {
"left_tstring": "leftTstringTest1",
"right_id": "rightIdTest1",
"relation_relstring": "relStringTest1"
};
let relObj2 = {
"left_tstring": "leftTstringTest2",
"right_id": "rightIdTest2",
"relation_relstring": "relStringTest2",
"relation_rightOid": "63ED49BD68B7B841B985C9658364D993"
};
let relCreatedObjs = this.omf.relCreateObjs([relObj1, relObj2], this.className);
this.logger.info("relCreatedObjs - " + JSON.stringify(relCreatedObjs));
this.logger.info("relCreatedObjs[0].relation_relstring - " + relCreatedObjs[0].relation_relstring);
this.logger.info("relCreatedObjs[0].left_oid - " + relCreatedObjs[0].left_oid);
this.logger.info("relCreatedObjs[0].right_oid - " + relCreatedObjs[0].right_oid);
this.logger.info("relCreatedObjs[1].relation_relstring - " + relCreatedObjs[1].relation_relstring);
this.logger.info("relCreatedObjs[1].left_oid - " + relCreatedObjs[1].left_oid); |
代码块 |
---|
language | js |
---|
title | this.omf.relCreateObjs |
---|
linenumbers | true |
---|
| var myDate = new Date();
var objs = []; // 优先级 left_oid > relation_leftOid
var obj1 = {
"relation_relString": "relString1 " + myDate.toLocaleTimeString(),
"relation_leftOid": "54D98B2C9A770B479A4EA7742F210A69",
"relation_rightOid": "C0AE6822C308744BABFF3621F85F86FA"
};
var obj2 = {
"relation_relString": "relString2 " + myDate.toLocaleTimeString(),
"relation_leftOid": "750D4855B440034D87B00748FAF432DF",
"relation_rightOid": "6F7777BE9DA6A94892C235C625963002",
"left_tstring": "testRelObj1 testObj1 edit " + myDate.toLocaleTimeString(),
"right_tstring": "testRelObj1 testObj2 edit " + myDate.toLocaleTimeString()
};
var obj3 = {
"relation_relString": "relString3 " + myDate.toLocaleTimeString(),
"left_tstring": "left addRelationsWithEntityObjFromScript",
"right_tstring": "right addRelationsWithEntityObjFromScript"
};
objs.push(obj1); objs.push(obj2); objs.push(obj3);
var myCreates = this.omf.relCreateObjs(objs, this.className);
this.logger.info("myCreates1.relation_oid - " + myCreates[0].relation_oid);
this.logger.info("myCreates2.relation_oid - " + myCreates[1].relation_oid);
this.logger.info("myCreates3.relation_oid - " + myCreates[2].relation_oid);
this.res = myCreates; |
| |
24 | relEdit(Map<String, Object> flattenObj, String className) relEdit(Map<String, Object> flattenObj, String className, boolean runScript) relEdit(Map<String, Object> flattenObj, String className, List<String> flattenAttrNames) relEdit(Map<String, Object> flattenObj, String className, boolean runScript, List<String> flattenAttrNames) | 编辑关联类对象,并更新左右类对象 传入: - flattenObj:拉平格式对象,如
{ relation_oid: xxx, relation_xxx: xxx, left_oid: yyy, left_yyy: yyy, right_oid: zzz, right_zzz: zzz } - className:关联类英文名
- runScript:是否运行前后处理脚本,默认为false
- flattenAttrNames:需要判重的拉平格式属性名列表,默认为空
返回:ProxyObject 编辑后的对象 |
|
代码块 |
---|
language | js |
---|
title | this.omf.relEdit |
---|
linenumbers | true |
---|
| if (this.selectedObj != null) { // 更新关联类对象及其左右类对象
this.selectedObj.relation_relstring = "testEditScript1";
this.selectedObj.left_tstring = "testEditScript1_left";
this.selectedObj.right_tstring = "testEditScript1_right";
let relEditedObj = this.omf.relEdit(this.selectedObj, this.className);
this.logger.info("relEditedObj - " + JSON.stringify(relEditedObj));
} |
| |
25 | relEditObjs(List<Map<String, Object>> flattenObjs, String className) relEditObjs(List<Map<String, Object>> flattenObjs, String className, boolean runScript) relEditObjs(List<Map<String, Object>> flattenObjs, String className, List<String> flattenAttrNames) relEditObjs(List<Map<String, Object>> flattenObjs, String className, boolean runScript, List<String> flattenAttrNames) | 批量编辑关联类对象,并更新左右类对象 传入: - flattenObjs:拉平格式对象列表
- className:关联类英文名
- runScript:是否运行前后处理脚本,默认为false
- flattenAttrNames:需要判重的拉平格式属性名列表,默认为空
返回:ProxyArray 编辑后的对象列表 |
|
代码块 |
---|
language | js |
---|
title | this.omf.relEditObjs |
---|
linenumbers | true |
---|
| if (this.selectedObjs != null && this.selectedObjs.length > 1) { // 更新关联类对象及其左右类对象
this.selectedObjs[0].relation_relstring = "testEditScript001";
this.selectedObjs[0].left_tstring = "testEditScript001_left";
this.selectedObjs[0].right_tstring = "testEditScript001_right";
this.selectedObjs[1].relation_relstring = "testEditScript002";
this.selectedObjs[1].left_tstring = "testEditScript002_left";
this.selectedObjs[1].right_tstring = "testEditScript002_right";
let relEditedObjs = this.omf.relEditObjs([this.selectedObjs[0], this.selectedObjs[1]], this.className);
this.logger.info("relEditedObjs - " + JSON.stringify(relEditedObjs));
this.logger.info("relEditedObjs[0].left_tstring - " + relEditedObjs[0].left_tstring);
this.logger.info("relEditedObjs[0].right_tstring - " + relEditedObjs[0].right_tstring);
this.logger.info("relEditedObjs[1].left_tstring - " + relEditedObjs[1].left_tstring);
this.logger.info("relEditedObjs[1].right_tstring - " + relEditedObjs[1].right_tstring);
} |
| |
26 | relDelete(Map<String, Object> flattenObj, String className) relDelete(Map<String, Object> flattenObj, String className, boolean runScript) | 删除关联类对象,不删除左右类对象 传入: - flattenObj:拉平格式对象,如
{ relation_oid: xxx, relation_xxx: xxx, left_oid: yyy, left_yyy: yyy, right_oid: zzz, right_zzz: zzz } - className:关联类英文名
- runScript:是否运行前后处理脚本,默认为false
返回:boolean 是否删除成功 |
|
代码块 |
---|
language | js |
---|
title | this.omf.relDelete |
---|
linenumbers | true |
---|
| if (this.selectedObjs != null && this.selectedObjs.length > 1) {
var flattenRelObj = this.omf.getByOid(this.selectedObjs[0].relation_oid, this.className, true);
var deleteRes1 = this.omf.relDelete(flattenRelObj, this.className);
this.logger.info("deleteRes1 - " + deleteRes1);
var deleteRes2 = this.omf.relDelete(this.selectedObjs[1], this.className);
this.logger.info("deleteRes2 - " + deleteRes2);
} |
| |
27 | relDeleteObjs(List<Map<String, Object>> flattenObjs, String className) relDeleteObjs(List<Map<String, Object>> flattenObjs, String className, boolean runScript) | 批量删除关联类对象,不删除左右类对象 传入: - flattenObjs:拉平格式对象列表
- className:关联类英文名
- runScript:是否运行前后处理脚本,默认为false
返回:boolean 是否全部删除成功 |
|
代码块 |
---|
language | js |
---|
title | this.omf.relDeleteObjs |
---|
linenumbers | true |
---|
| if (this.selectedObjs != null) {
var deleteRes3 = this.omf.relDeleteObjs(this.selectedObjs, this.className);
this.logger.info("deleteRes3 - " + deleteRes3);
} |
| |
28 | cudBatchObjs(List<Map<String, Object>> events) | 批量增删改类对象,与cud-batch接口一致 传入: (cud事件格式参考cud-batch接口,包含action、className、objs和oids参数,其中objs和oids类型需要为ArrayList) 返回:ProxyArray 对象列表 |
|
代码块 |
---|
language | js |
---|
title | this.omf.cudBatchObjs |
---|
linenumbers | true |
---|
| var ArrayList = Java.type(`java.util.ArrayList`);
var cudBatchList = [];
var objs = new ArrayList();
objs.add({"tstring": "cudBatchTest1"});
objs.add({"tstring": "cudBatchTest2"});
var cudObj1 = {
"action": "create",
"className": this.className,
"objs": objs
}
cudBatchList.push(cudObj1);
var myCudResult = this.omf.cudBatchObjs(cudBatchList);
this.logger.info("myCudResult - " + myCudResult);
// 目前暂不清楚如何从ProxyArray获取内容,只好将ProxyArray结果转为String
let rawData = "" + myCudResult;
// 使用正则表达式替换键值对格式,并将等号替换为冒号,但值中的等号保持不变
var jsonData = rawData.replace(/(\w+)=(\{[^{}]+\}|[^,}\]]+)/g, function(match, key, value) {
// 检查值是否为null或是一个对象形式
if (value === "null" || (value.charAt(0) === '{' && value.charAt(value.length - 1) === '}')) return `"${key}":${value}`;
else return `"${key}":"${value}"`;
}).replace(/":(?!null|"|{|})/g, '":');
var parsedData = JSON.parse(jsonData); // 解析JSON
this.logger.info("parsedData - " + JSON.stringify(parsedData));
this.logger.info("parsedData[0].tstring - " + parsedData[0].tstring);
|
| |
29 | getString(Integer oid, String className, String attrName) getString(String oid, String className, String attrName) getString(String stashOid) | 根据主键oid和localfile类型的属性英文名attrName返回对应文件的base64字符串 传入: - oid:对象主键
- className:类英文名
- attrName:localfile类型的属性英文名
- stashOid:暂存文件oid,以stash开头
返回:String 文件的base64字符串 |
|
代码块 |
---|
language | js |
---|
title | this.omf.getString |
---|
linenumbers | true |
---|
| // getString(String oid, String className, String attrName)
var fileStr = this.omf.getString(this.obj.oid, this.className, "tlocalfile");
this.logger.info("fileStr - " + fileStr);
// getString(String stashOid)
if (this.obj.tlocalfile != null && this.obj.tlocalfile.startsWith("stash")) {
var stashFileStr = this.omf.getString(this.obj.tlocalfile);
this.logger.info("stashFileStr - " + stashFileStr);
} |
| 表单edit状态且第一个对象的tlocalfile属性有文件时
表单create状态,在tlocalfile属性上传一个文件后(点击新增前)
|
30 | getByteArray(Integer oid, String className, String attrName) getByteArray(String oid, String className, String attrName) getByteArray(String stashOid) | 根据主键oid和localfile类型的属性英文名attrName返回对应文件的Byte[]字节流 传入: - oid:对象主键
- className:类英文名
- attrName:localfile类型的属性英文名
- stashOid:暂存文件oid,以stash开头
返回:ProxyArray 文件的Byte[]字节流 |
|
代码块 |
---|
language | js |
---|
title | this.omf.getByteArray |
---|
linenumbers | true |
---|
| if (this.obj.tlocalfile != null) {
if (this.obj.tlocalfile.startsWith("stash")) { // getByteArray(String stashOid)
var stashFileBytes = this.omf.getByteArray(this.obj.tlocalfile);
this.logger.info("stashFileBytes.length - " + stashFileBytes.length);
this.logger.info("stashFileBytes - " + stashFileBytes);
} else { // getByteArray(String oid, String className, String attrName)
var bytes = this.omf.getByteArray(this.obj.oid, this.className, "tlocalfile");
this.logger.info("bytes.length - " + bytes.length);
this.logger.info("bytes - " + bytes);
}
} |
|
表单edit状态且第一个对象的tlocalfile属性有文件时
表单create状态,在tlocalfile属性上传一个文件后(点击新增前)
|
31 | getFilePath(Integer oid, String className, String attrName) getFilePath(String oid, String className, String attrName) getFilePath(String stashOid) | 根据主键oid和localfile类型的属性英文名attrName获取对应文件的路径 传入: - oid:对象主键
- className:类英文名
- attrName:localfile类型的属性英文名
- stashOid:暂存文件oid,以stash开头
返回:String 文件路径 |
|
代码块 |
---|
language | js |
---|
title | this.omf.getByteArray |
---|
linenumbers | true |
---|
| if (this.obj.tlocalfile != null) {
if (this.obj.tlocalfile.startsWith("stash")) { // getFilePath(String stashOid)
var stashFilePath = this.omf.getFilePath(this.obj.tlocalfile);
this.logger.info("stashFilePath - " + stashFilePath);
} else { // getFilePath(String oid, String className, String attrName)
var filePath = this.omf.getFilePath(this.obj.oid, this.className, "tlocalfile");
this.logger.info("filePath - " + filePath);
}
} |
| 表单edit状态且第一个对象的tlocalfile属性有文件时
表单create状态,在tlocalfile属性上传一个文件后(点击新增前)
|
32 | setLocalFile(Integer oid, String className, String filePath) setLocalFile(String oid, String className, String filePath) | 将指定路径filePath的文件存储到主键oid对象的localfile类型的属性英文名attrName中 传入: - oid:对象主键
- className:类英文名
- filePath:文件在服务器上的绝对路径
返回:boolean 文件是否上传成功 |
|
代码块 |
---|
language | js |
---|
title | this.omf.setLocalFile |
---|
linenumbers | true |
---|
| let filePath = "/home/dwf/test.sh";
this.logger.info(`将文件${filePath}改为对象${this.obj.oid}的tlocalfile对应的文件`);
var setLFSuccess = this.omf.setLocalFile(this.obj.oid, this.className, "tlocalfile", filePath);
this.logger.info("setLFSuccess - " + setLFSuccess); |
| 表单edit状态且第一个对象的tlocalfile属性有文件时
成功后可查看和下载该对象的文件,已变为test.sh
|
33 | transferToStashFile(String filePath) | 将指定路径filePath的文件转存为暂存文件(原文件会被删除,暂存文件超过30min会过期自动删除) 传入: 返回:String 暂存文件oid,以stash开头 |
|
代码块 |
---|
language | js |
---|
title | this.omf.transferToStashFile |
---|
linenumbers | true |
---|
| let filePath = "/home/dwf/test.sh";
this.logger.info(`将文件${filePath}转存为暂存文件,并返回暂存文件oid`);
var stashOid = this.omf.transferToStashFile(filePath);
this.logger.info("stashOid - " + stashOid); |
注意,暂存文件超过30min会过期,自动删除 | |
34 | uploadFileToResource(String oid, String className, String attrName) | 根据主键oid和localfile类型的属性英文名attrName将对应文件(必须为zip文件)上传为资源文件 传入: - oid:对象主键
- className:类英文名
- attrName:localfile类型的属性英文名
返回:ProxyObject 资源文件信息 |
|
代码块 |
---|
language | js |
---|
title | this.omf.uploadFileToResource |
---|
linenumbers | true |
---|
| var resource = this.omf.uploadFileToResource(this.obj.oid, this.className, "tlocalfile");
this.logger.info("resource - " + JSON.stringify(resource));
this.logger.info("resource.filePath - " + resource.filePath); |
注意,只有zip文件允许被上传为资源文件 | |
35 | testApi(String apiConfigOid) testApi(String apiConfigOid, Map<String, Object> customConfigMap) | 传入: - apiConfigOid:
- customConfigMap:
返回:Object |
|
代码块 |
---|
language | js |
---|
title | this.omf.testApi |
---|
linenumbers | true |
---|
| var result = this.omf.testApi("2AC55B9B53A1554CBF1B3D3859073B10");
this.logger.info("result - " + result);
this.logger.info("result.totalCount - " + result.totalCount);
this.logger.info("result.data[0].tstring - " + result.data[0].tstring);
let customConfigMap = {
"requestHeader": `{"Authorization":"$user.token"}`,
"requestParam": `{"pageIndex": 1, "pageSize": 3, "totalCount": true}`,
"requestBody": `{"condition": "and obj.tstring is not null and obj.tstring <> 'cudBatchTest2'"}`,
"dataAnalysis": "res"
};
result = this.omf.testApi("2AC55B9B53A1554CBF1B3D3859073B10", customConfigMap);
this.logger.info("result - " + result);
this.logger.info("result.data.totalCount - " + result.data.totalCount);
this.logger.info("result.data.data[0].tstring - " + result.data.data[0].tstring); |
| API配置:
|
36 | handleQueryByAPI(String apiName) handleQueryByAPI(String apiName, Map<String, Object> customConfigMap) | 传入: 返回:Object |
|
代码块 |
---|
language | js |
---|
title | this.omf.handleQueryByAPI |
---|
linenumbers | true |
---|
| var result1 = this.omf.handleQueryByAPI("测试");
this.logger.info("result1.data[0].tstring - " + result1.data[0].tstring);
// 解析为空时,将结果转为json
var JSONObject = Java.type("com.alibaba.fastjson.JSONObject");
let customConfigMap = {
"requestHeader": `{"Authorization":"$user.token"}`,
"requestParam": `{"pageIndex": 1, "pageSize": 3, "totalCount": true}`,
"requestBody": `{"condition": "and obj.tstring is not null and obj.tstring <> 'cudBatchTest2'"}`,
"dataAnalysis": null
};
var result2 = this.omf.handleQueryByAPI("测试", customConfigMap);
var json = JSONObject.parseObject(result2.toString());
this.logger.info("json - " + json);
this.logger.info("json.data.data[0] - " + json.getJSONObject("data").getJSONArray("data").get(0)); |
| |
37 | handleQueryBySQL(Map<String, Object> queryObjReqMap) handleQueryBySQL(String dataSourceName, Map<String, Object> queryObjReqMap) | 传入: - dataSourceName:
- queryObjReqMap:
返回:ProxyObject |
|
代码块 |
---|
language | js |
---|
title | this.omf.handleQueryBySQL |
---|
linenumbers | true |
---|
| var result3 = this.omf.handleQueryBySQL({"condition": "select * from plt_mdl_metaclass limit 2"});
this.logger.info("result3.head - " + result3.head);
this.logger.info("result3.data[0] - " + result3.data[0]);
var result4 = this.omf.handleQueryBySQL("pgtest", {"condition": "select * from plt_mdl_metaclass limit 2 offset 2"});
this.logger.info("result4.head - " + result4.head);
let headStr = "" + result4.head;
var headArray = headStr.slice(1, -1).split(", "); // 去除字符串中的方括号并用逗号分割成数组
var idx = headArray.indexOf("plt_classname");
this.logger.info("result4.data[0][indexOfClassName] - " + result4.data[0][idx]); |
| 数据连接配置:
|
38 | executeSQL(Map<String, Object> queryObjReqMap) executeSQL(String dataSourceName, Map<String, Object> queryObjReqMap) | 传入: - dataSourceName:
- queryObjReqMap:
返回:void |
|
代码块 |
---|
language | js |
---|
title | this.omf.executeSQL |
---|
linenumbers | true |
---|
| // 第一段测试代码:pg增、改、删对象
this.omf.executeSQL({"condition": "insert into plt_cus_alltest(plt_oid, plt_str) values ('oidtest', 'teststr')"});
this.omf.executeSQL({"condition": "update plt_cus_alltest set plt_str = 'test1' where plt_oid = 'oidtest'"});
this.omf.executeSQL({"condition": "delete from plt_cus_alltest where plt_oid = 'oidtest'"});
// var obj1 = this.omf.handleQueryBySQL({"dataSourceName": "pgtest", "condition": "select * from plt_mdl_metaclass"});
// this.logger.info("obj1 - " + obj1);
var obj2 = this.omf.handleQueryBySQL({"condition": "select * from plt_cus_alltest"});
this.logger.info("obj2 - " + obj2);
// 第二段测试代码:iotdb新增对象
this.omf.executeSQL({"dataSourceName": "iotdb1065", "condition": "insert into root.cac.fcc.2911401.hc1(timestamp, t1, t2) values(now(), 22.22, 33.33)"});
var iotdbObj1 = this.omf.handleQueryBySQL({"dataSourceName": "iotdb1065", "condition": "select * from root.cac.fcc.2911401.hc1 where t2 = 33.33"});
this.logger.info("iotdbObj1 - " + iotdbObj1);
// 第三段测试代码:iotdb新增对象,condition加密
this.omf.executeSQL({"dataSourceName": "iotdb1065", "condition": this.omf.dwfEncode("insert into root.cac.fcc.2911401.hc1(timestamp, t1, t2) values(now(), 44.44, 55.55)")});
var iotdbObj2 = this.omf.handleQueryBySQL({"dataSourceName": "iotdb1065", "condition": this.omf.dwfEncode("select * from root.cac.fcc.2911401.hc1 where t2 = 55.55")});
this.logger.info("iotdbObj2 - " + iotdbObj2); |
|
|
39 | dwfDecode(String content) | 传入: 返回:String 解密后的查询条件 |
|
代码块 |
---|
language | js |
---|
title | this.omf.dwfDecode |
---|
linenumbers | true |
---|
| this.logger.info(this.omf.dwfDecode("YW5kJTIwb2JqLm9pZCUyMCUzRCUyMCUyNzElMjc="));
this.logger.info(this.omf.dwfDecode("YW5kIG9iai5vaWQgPSAnMSc=")); |
|
|
40 | dwfEncode(String content) | 传入: 返回:String 加密后的查询条件 |
|
代码块 |
---|
language | js |
---|
title | this.omf.dwfEncode |
---|
linenumbers | true |
---|
| this.logger.info(this.omf.dwfEncode("and obj.oid = '1'")); |
|
|
41 | this.em | createNativeQuery(String sqlString) | 直接执行SQL语句,支持数据更新、数据查询 支持的执行方法包括以下三种 1)更新数据对象executeUpdate()【支持:insert 、 update、delete】 2)查询数据对象,返回单个对象getSingleResult() 3)查询数据对象,返回多个对象getResultList() | 1)执行SQL语言executeUpdate() 2)查询返回单个对象getSingleResult () 3)查询返回多个对象getResultList() | 执行sql语句
function id() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}
this .em.createNativeQuery( "insert into public.plt_org_user(plt_oid, plt_creator, plt_lastmodifier, plt_name, plt_displayname) values ('" + id() + "', '9C92E891E9AE534DB685737DE467A9D0', '9C92E891E9AE534DB685737DE467A9D0', 'testServerScript', '测试服务端脚本')" ).executeUpdate();
//2执行存储函数
this .em.createNativeQuery( "select cast(test_procedure() as text)" ).getResultList();
|
|
42 | this.restTemplate
| getForEntity(String url, Class<T> responseType, Object... uriVariables) | get方法请求第三方服务接口 @param url:第一参数表示要调用的服务的地址 @param responseType :第二个参数表示返回的消息体的数据类型 @param Object.../Map<String, ?> :第三个参数表示上传的参数 ,支持map和object @return <T> ResponseEntity<T> :包括 响应码、 contentType、 contentLength、 响应消息体等
|
|
this .logger.info( "Get请求,获取Json响应" );
var get_response = this .restTemplate.getForEntity( "http://192.168.31.53:6060/test/get-admin-token"
, java.util.Map.class);
var get_response_body = get_response.getBody();
this .logger.info( "body: " + get_response_body);
this .logger.info( "body.message: " + get_response_body.get("message"));
this .logger.info( "Get请求,获取String响应" );
get_response = this .restTemplate.getForEntity( "http://www.baidu.com"
, java.lang.String.class);
get_response_body = get_response.getBody();
this .logger.info( "body: " + get_response_body);
|
|
43 | postForEntity(String url, @Nullable Object request, Class<T> responseType, Object... uriVariables) | post方法请求第三方服务接口 @param url:第一参数表示要调用的服务的地址 @param responseType:第二个参数表示返回的消息体的数据类型 @param Object... /Map<String, ?> uriVariables:第三个参数表示上传的参数 @retrun 返回值是一个ResponseEntity<T>, 包括响应码、contentType、contentLength、响应消息体等 |
|
var Map = Java.type( 'java.util.Map' );
this .logger.info( "Post请求,传递request body,获取json响应" );
var request_body = { "name" : "hahahaname" };
var post_response = this .restTemplate.postForEntity( "http://127.0.0.1:6060/dwf/v1/testPost" , request_body, Map.class);
var post_response_body = post_response.getBody();
this .logger.info( "body: " + post_response_body);
this .logger.info( "Post请求,传递request body和http header,获取json响应" );
var HttpHeaders = Java.type( "org.springframework.http.HttpHeaders" );
var HttpEntity = Java.type( 'org.springframework.http.HttpEntity' );
headers = new HttpHeaders();
headers.set( "Authorization" , "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImV4cCI6MTU2ODAzNTcxOX0.5dfoAvd1SFQ7V_CnmzKMNbB7qR_k9Y1BK5zJXUuzc_BkhMFu9oEAVT3EUky1qhBlpihyPd7hV6136I1dnMX-GA" );
request_body = {
"appName" : "test_json_engine" ,
"extConfig" : "string" ,
};
request = new HttpEntity(request_body,headers);
var Map = Java.type( 'java.util.Map' );
post_response = this .restTemplate.postForEntity( "http://127.0.0.1:6060/dwf/v1/apps-create" , request, Map.class);
post_response_body = post_response.getBody();
this .logger.info( "body: " + post_response_body);
/*3 请求体[]
var HttpHeaders = Java.type('org.springframework.http.HttpHeaders'); var HttpMethod = Java.type('org.springframework.http.HttpMethod'); var HttpEntity = Java.type('org.springframework.http.HttpEntity'); var ArrayList = Java.type('java.util.ArrayList'); var JSONArray = Java.type('com.alibaba.fastjson.JSONArray'); var JSONObject = Java.type('com.alibaba.fastjson.JSONObject'); // 请求头 headers = new HttpHeaders(); headers.add("Authorization", this.env.token); // 请求体 var request_body = new ArrayList(); request_body.add({"tstring": "restTemplate测试用"}); request = new HttpEntity(request_body, headers); this.logger.info("request body - " + request_body); // 发送请求 var url = "http://" + this.env.serverIp + ":9090/dwf/v1/omf/entities/" + this.className + "/objects-create"; this.logger.info("url - " + url); // var post_response = this.restTemplate.exchange(url, HttpMethod.POST, request, JSONObject.class); var post_response = this.restTemplate.postForEntity(url, request, JSONObject.class); var body = post_response.getBody(); this.logger.info("body - " + body); |
|
44 | exchange(String url, HttpMethod method, @Nullable HttpEntity<?> requestEntity, Class<T> responseType, Object... uriVariables) | exchange方法请求第三方服务接口 1)url: 请求地址; 2)method: 请求类型(如:POST,PUT,DELETE,GET); 3)requestEntity: 请求实体,封装请求头,请求内容 4)responseType: 响应类型,根据服务接口的返回类型决定 5)params: url中参数变量值 |
| (示例一)使用后端脚本的restTemplate.exchange请求第三方接口示例(POST方法),此方法可以带Header 代码块 |
---|
| //开始请求token
var HttpHeaders = Java.type("org.springframework.http.HttpHeaders");
var HttpEntity = Java.type('org.springframework.http.HttpEntity');
var HttpMethod = Java.type('org.springframework.http.HttpMethod');
var HashMap = Java.type('java.util.HashMap');
headers = new HttpHeaders();
headers.add("Content-Type", "application/json");
headers.add("Accept", "*/*");
request_body =
{
"appName":clientId,
"userName":username,
"password":password
};
request = new HttpEntity(request_body,headers);
//以下注释掉,等有了登录接口后在开通
this.logger.info("post_response:");
var get_response = this.restTemplate.exchange(tokenUrl,HttpMethod.POST, request,java.lang.String.class);
var get_response_body = get_response.getBody();
this.res=get_response_body; //将请求结果返回给前端 |
(示例二)使用后端脚本的restTemplate.getForEntity方法请求第三方接口(Get方法) 无需header 代码块 |
---|
| var get_response = this.restTemplate.getForEntity("接口访问地址,带参数的",Java.type('java.util.Map').class);
// 如果返回结果是json,response建议反序列化为Map,从而可以用.直接访问属性
var get_response_body = get_response.getBody();
this.logger.info("body: "+ get_response_body);
this.res = get_response_body; |
(示例三)使用后端脚本的restTemplate.exchange的方法调用Get接口带header 代码块 |
---|
| var HttpHeaders = Java.type("org.springframework.http.HttpHeaders");
var HttpEntity = Java.type('org.springframework.http.HttpEntity');
var HttpMethod = Java.type('org.springframework.http.HttpMethod');
headers = new HttpHeaders();
headers.set("user", username);
headers.set("timestamp", timestamp+"");
headers.set("sign", sign);
request_body ={};
this.logger.info("request");
request = new HttpEntity(headers);
var get_response = restTemplate.exchange(tokenUrl,HttpMethod.GET, request, Java.type('java.util.Map').class);
this.res = get_response.getBody() //请求结果返回给前端 |
|
|
45 | this.websocket
| socketId instanceId | 当前连接对应的socketId | 仅在消息订阅控件事件中支持 | var msg1 = this.websocket.getMsg(); if (msg1) this.logger.info("getMsg1 = " + msg1+" sockId:"+this.websocket.socketId+" msg"+this.customData); else this.logger.info("getMsg1 = null"); |
|
46 | sendMsg(Object msg) | 发送单个连接信息 @param msg:消息对象 | 仅在消息订阅控件事件中支持 | this.websocket.sendMsg({"percent": 100, "desc": over}); |
|
47 | getLastMsg() | 根据socketid返回socket最后一次消息 @param socketId 指定的socketId @return Object : | 仅在消息订阅控件事件中支持 | var msg2 = this.websocket.getLastMsg(); if (msg2) this.logger.info("getLastMsg = " + msg2+" sockId:"+this.websocket.socketId+" customData:"+this.customData); else this.logger.info("msg2 = null"); |
|
48 | getMsg() | 获取最后一个消息 @return Object : | 仅在消息订阅控件事件中支持 | var msg1 = this.websocket.getMsg(); if (msg1) this.logger.info("getMsg1 = " + msg1+" sockId:"+this.websocket.socketId+" msg"+this.customData); else this.logger.info("getMsg1 = null"); |
|
49 | checkSocketIdExists() | 检查socketId是否活动 @return Object : | 仅在消息订阅控件事件中支持 | this.logger.info("2 checkSockIdExists - " + this.websocket.checkSocketIdExists()); |
|
50 | this.ex | setFieldError(String field, String message) | 在前端弹出错误提示信息 @param field:自定义,例如“报错信息是“; @param message:自定义,可以try catch异常后,将异常抛出,err.getMessage() | 会在前端执行后端脚本的界面上提示错误信息 |
代码块 |
---|
language | js |
---|
title | this.ex |
---|
linenumbers | true |
---|
| try {
let queryObj = this.omf.handleQueryData("errorQuerySql", this.className);
this.logger.info("queryObj - " + queryObj);
} catch (err) {
this.ex.setFieldError("报错内容", err.getMessage());
} |
| 日志:无 接口返回
前端提示信息
|
51 | 日志打印
| this.logger
| info(String msg) | 打印info类型信息 |
|
代码块 |
---|
language | js |
---|
title | this.logger |
---|
linenumbers | true |
---|
| this.logger.warn("this is a warn message");
this.logger.info("this is a info message");
this.logger.error("this is a error message"); |
| |
52 | error(String msg) | 打印error类型信息 |
|
53 | warn(String msg) | 打印warn类型信息 |
|
54 | 执行第三方程序 | this.sh | exeCmd(String[] args) | 执行命令并等待命令执行结果,无超时限制 传入: 返回:String 执行命令后产生的内容 |
|
代码块 |
---|
language | js |
---|
title | this.sh |
---|
linenumbers | true |
---|
| this.logger.info("--------------- exeCmd ---------------");
let cmdArray = ["python3", "/home/dwf/test.py", "exeCmd"];
this.logger.info(this.sh.exeCmd(cmdArray));
this.logger.info("--------------- execute ---------------");
this.logger.info(this.sh.execute("python3 /home/dwf/test.py execute"));
this.logger.info("--------------- execute with timeOut ---------------");
this.logger.info(this.sh.execute("python3 /home/dwf/test.py executeWithTimeout", 5));
this.logger.info("--------------- executeAsync ---------------");
this.logger.info(this.sh.executeAsync("python3 /home/dwf/test.py executeAsync")); |
| 脚本功能为连续10s打印日志
|
55 | execute(String commandStr) execute(String commandStr, Integer timeoutSecond) | 执行命令并等待命令执行结果 传入: - commandStr:执行的命令
- timeoutSecond:超时中断时间,单位为秒,默认180,设置为0则禁止超时中断
返回:String 执行命令后产生的内容 |
|
56 | executeAsync(String commandStr) | 异步执行,不等待返回结果 传入: 返回:null |
|
57 | 组织用户管理 | this.org | user.create(Map<String, Object> user) | 新增用户 |
|
代码块 |
---|
language | js |
---|
title | this.org.user.create |
---|
linenumbers | true |
---|
| // 新增用户
this.logger.info("------------- 新增用户 -------------");
var ArrayList = Java.type('java.util.ArrayList');
var groupNames = new ArrayList();
groupNames.add("AllTestGroup"); // 传入用户组英文名
var u = {"name":"userTest0823", "displayName":"测试脚本", "password":"123Abc", "email":"123Abc@123.com", "groupNames":groupNames, "comment":"测试脚本"};
let createResult = this.org.user.create(u);
this.logger.info("create user: " + JSON.stringify(createResult)); |
| |
58 | user.edit(Map<String, Object> user) | 修改用户 |
|
代码块 |
---|
language | js |
---|
title | this.org.user.edit |
---|
linenumbers | true |
---|
| // 编辑用户
this.logger.info("------------- 编辑用户 -------------");
let testU = this.org.user.getByName("userTest0823");
this.logger.info("testU: " + JSON.stringify(testU));
testU.displayName = "edit";
let editResult = this.org.user.edit(testU); // 与接口一致,只返回true和false
this.logger.info("edit user: " + editResult);
var editedUser = this.org.user.getByName(testU.name);
this.logger.info("editedUser: " + JSON.stringify(editedUser)); |
|
59 | user.delete(String name) user.delete(Map<String, Object> user) | 根据用户名删除用户 |
|
代码块 |
---|
language | js |
---|
title | this.org.user.delete |
---|
linenumbers | true |
---|
| // 删除用户
this.logger.info("------------- 删除用户 -------------");
deleteResult = this.org.user.delete("userTest0823"); // 与接口一致,只返回true和false
this.logger.info("delete user: " + deleteResult); |
|
60 | user.getByName(String name) | 根据用户名获取用户信息(password不返回) |
|
代码块 |
---|
language | js |
---|
title | this.org.user.getByName |
---|
linenumbers | true |
---|
| // 查询用户信息
this.logger.info("------------- 查询用户信息 -------------");
let testUser = this.org.user.getByName("userTest0823");
this.logger.info("testUser: " + JSON.stringify(testUser)); |
|
61 | user.getToken(String userName, String password) | 根据账号密码获取token |
|
代码块 |
---|
language | js |
---|
title | this.org.user.getToken |
---|
linenumbers | true |
---|
| // 根据用户名和密码获取token
this.logger.info("------------- 根据用户名和密码获取token -------------");
var token = this.org.user.getToken("userTest0823", "123Abc");
this.logger.info("getToken: " + token); |
|
62 | user.login(String userName, String password) |
|
|
代码块 |
---|
language | js |
---|
title | this.org.user.login |
---|
linenumbers | true |
---|
| // 根据用户名和密码登录并获取token
var token = this.org.user.login("uTest", "uTest123123");
this.logger.info("login: " + token); |
|
63 | group.create(Map<String, Object> group) | 新增用户组 |
|
代码块 |
---|
language | js |
---|
title | this.org.group.create |
---|
linenumbers | true |
---|
| // 新增用户组
var g = {"name":"groupTest0912", "displayName":"测试脚本", "comment":"测试脚本"};
let createdGroup = this.org.group.create(g);
this.logger.info("create - " + JSON.stringify(createdGroup)); |
| |
64 | group.edit(Map<String, Object> group) | 修改用户组 |
|
代码块 |
---|
language | js |
---|
title | this.org.group.edit |
---|
linenumbers | true |
---|
| // 编辑用户组
var testG = this.org.group.getByName("groupTest0912");
this.logger.info("getByName - " + JSON.stringify(testG));
testG.displayName = "edit";
let editResultG = this.org.group.edit(testG); // 与接口一致,只返回true和false
this.logger.info("edit - " + editResultG);
var editedGroup = this.org.group.getByName(testG.name);
this.logger.info("getByName - " + JSON.stringify(editedGroup)); |
| |
65 | group.delete(String name) group.delete(Map<String, Object> group) | 根据用户组名删除用户组 |
|
代码块 |
---|
language | js |
---|
title | this.org.group.delete |
---|
linenumbers | true |
---|
| // 删除用户组
deleteResult = this.org.group.delete("groupTest0912"); // 与接口一致,只返回true和false
this.logger.info("delete - " + deleteResult); |
| |
66 | group.getByName(String name) | 根据用户组名获取用户组信息 |
|
代码块 |
---|
language | js |
---|
title | this.org.group.getByName |
---|
linenumbers | true |
---|
| // 查询用户组信息
var testG = this.org.group.getByName("groupTest0912");
this.logger.info("getByName - " + JSON.stringify(testG)); |
| |
67 | group.bindChildGroup(String parentGroupOid, String childGroupOid) group.bindChildGroup(String parentGroupOid, List<String> childGroupOid) | 根据oid绑定父子用户组 |
|
代码块 |
---|
language | js |
---|
title | this.org.group.bindChildGroup |
---|
linenumbers | true |
---|
| // 创建用户组
let parentGroup = this.org.group.create({"name":"groupTest0912", "displayName":"groupTest0912", "comment":"parent"});
this.logger.info("parentGroup: " + JSON.stringify(parentGroup));
this.logger.info("parentGroup.oid: " + parentGroup.oid);
let childGroup = this.org.group.create({"name":"childGroupTest0912", "displayName":"childGroupTest0912", "comment":"child"});
this.logger.info("childGroup: " + JSON.stringify(childGroup));
this.logger.info("childGroup.oid: " + childGroup.oid);
// 通过oid绑定父子组
var result = this.org.group.bindChildGroup(parentGroup.oid, childGroup.oid);
this.logger.info("bindChildGroup: " + JSON.stringify(result)); |
| |
68 | 工具 | this.util | dwfDecode(String content) | 传入: 返回:String 解密后的查询条件 |
|
代码块 |
---|
language | js |
---|
title | this.util.dwfDecode |
---|
linenumbers | true |
---|
| this.logger.info(this.util.dwfDecode("YW5kJTIwb2JqLm9pZCUyMCUzRCUyMCUyNzElMjc="));
this.logger.info(this.util.dwfDecode("YW5kIG9iai5vaWQgPSAnMSc=")); |
|
|
69 | dwfEncode(String content) | 传入: 返回:String 加密后的查询条件 |
|
代码块 |
---|
language | js |
---|
title | this.util.dwfEncode |
---|
linenumbers | true |
---|
| this.logger.info(this.util.dwfEncode("and obj.oid = '1'")); |
|
|
70 | transferLanguage(String content) transferLanguage(String content, Map<String, String> keyWordMap) | 传入: - content:需被翻译的内容
- keyWordMap:翻译内容和变量的关键词键值对
返回:String 翻译后的内容 |
|
代码块 |
---|
language | js |
---|
title | this.util.transferLanguage |
---|
linenumbers | true |
---|
| // 翻译成功
this.logger.info("【类名不允许为空】翻译后 - " + this.util.transferLanguage("类名不允许为空"));
// 翻译成功,且keyword替换正确
this.logger.info("【{keyword}连接失败】翻译后 - " + this.util.transferLanguage("{keyword}连接失败", {"keyword": this.className}));
// 翻译成功,但keyword替换错误
this.logger.info("【类{className}查询失败:】翻译后 - " + this.util.transferLanguage("类{className}查询失败:", {"keyword": this.className}));
// 获取前端语言环境
this.logger.info("this.env.locale - " + JSON.stringify(this.env.locale));
this.logger.info("this.env.locale.name - " + this.env.locale.name); |
| |
71 | 消息订阅 | this.subscription | instanceId |
|
|
|
|
72 | 系统消息、站内信 | this.sysNotification | sendMail(Map<String, String> mailMap, List<String> receiverList) |
|
|
代码块 |
---|
language | js |
---|
title | this.sysNotification |
---|
linenumbers | true |
---|
| // 收件人(用户、用户组英文名)
let receiverList = ["zs", "ls", "testGroup"];
// 发邮件
let mailMap = {
"type": "测试",
"title": "邮件标题",
"content": "邮件内容"
};
let mailResp = this.sysNotification.sendMail(mailMap, receiverList);
// 或者 this.sysNotification.sendMailOrNotice(mailMap, receiverList, true)
this.logger.info("" + mailResp);
// 发通告
let noticeMap = {
"type": "测试",
"title": "通告标题",
"content": "通告内容"
};
let noticeResp = this.sysNotification.sendNotice(noticeMap, receiverList);
// 或者 this.sysNotification.sendMailOrNotice(noticeMap, receiverList, false)
this.logger.info("" + noticeResp); |
|
|
73 | sendNotice(Map<String, String> noticeMap, List<String> receiverList) |
|
|
|
74 | sendMailOrNotice(Map<String, String> notificationMap, List<String> receiverList, boolean isMail) |
|
|
|
75 |
| this.objectMapper | ? |
|
|
|
|
76 | 代码装配 | this.partExt | ? |
|
|
|
|
77 | Java扩展 | Java.type('...') | |
|
|
代码块 |
---|
title | Unirest |
---|
linenumbers | true |
---|
| const Unirest = Java.type('kong.unirest.Unirest');
try {
// get接口
let pageSize = 5;
const getResponse = Unirest.get(`http://localhost:6060/dwf/v1/org/user-to-groups?isPaged=true&pageSize=${pageSize}&withPageInfo=true`)
.header("Authorization", this.env.token)
.asString();
this.logger.info("Unirest user-to-groups - " + JSON.stringify(JSON.parse(getResponse.getBody()).data));
// post接口
let body = [
{ "tstring": "1 created by unirest" }
];
body.push({ "tstring": "2 created by unirest" })
const postResponse = Unirest.post(`http://localhost:9090/dwf/v1/omf/entities/${this.className}/objects-create`)
.header("Content-Type", "application/json")
.header("Authorization", this.env.token)
.body(JSON.stringify(body))
.asString();
let data = JSON.stringify(JSON.parse(postResponse.getBody()).data);
this.logger.info("Unirest objects-create - " + data);
this.res = data;
} catch (ex) {
this.logger.info(ex.toString());
this.ex = ex.toString();
} |
| |
78 | 兼容性测试 |
|
|
|
|
代码块 |
---|
| // this.logger.info("Graal.versionJS - " + Graal.versionJS); // undefined (Graal.versionGraalVM, Graal.isGraalRuntime)
// 兼容 ECMA 11 测试
var m = new Map();
// 兼容 Nashorn 测试
var Date = Java.type('java.util.Date');
var date = new Date();
var myYear = date.year;
date.year = myYear + 1;
this.logger.info("date - " + date);
this.logger.info("myYear - " + myYear); // undefined
var myYear2 = date.getYear();
date.setYear(myYear2 + 1);
this.logger.info("date - " + date);
this.logger.info("myYear2 - " + myYear2);
this.logger.info(`"123".length - ` + "123".length);
// 图标
print("print ✅");
console.log("console.log ✅");
this.logger.info("this.logger.info ✅");
// BigDecimal
var bd = new java.math.BigDecimal('10');
this.logger.info("bd - " + bd);
var BigDecimal = Java.type('java.math.BigDecimal');
var bd2 = new BigDecimal('10');
this.logger.info("bd2 - " + bd2);
// JSON.stringify
let objA = {"a": "a", "b": "b"};
this.logger.info("objA - " + JSON.stringify(objA));
this.logger.info("objA - " + objA.a);
objA.a = "1";
objA.b = objA.a;
this.logger.info("objA - " + JSON.stringify(objA)); |
|
|