ORM复杂使用
公共参数
__transaction__ 默认启用,0代表禁用 __error_continue__ 1代表出错继续运行 __enable_log__ 1代表启用日志,会记录当前系统的出错信息,只针对update,delete有效 __user_id__,__user_cn_name__ 用于保存日志时使用
流水号使用方式
表中字段若需要使用流水号,可在bs_sys_auto_seq表中配置,匹配对应的字段名称,table_neme表示配置使用流水号的表名,name表示字段名称,type表示流水号字段类型,若已在系统中配置相应的条码规则,可直接使用将条码规则名称配置在barcode中。
- orm更新
使用orm时,注意orm的更新,若对数据类型有修改,需要更新orm并重启服务再进行使用。
接口调用更新orm操作
{
"cmd": "update_table_orm",
"file": "web_data_base_query",
"table":"bs_camera",
"error_continue":"0",
"enable_log":"1",
"help": [
{
}
]
}
- 返回结果
{
"code": "1",
"error": "",
"help": "",
"orm": "\n--bs_camera\ncamera_code,,char[52],0,,\ncamera_id,PK,char[52],0,,\ncreate_time,,timestamp,0,,\ncreator,,char[52],0,,\nichannelid,,int,0,,\niprotocol,,int,0,,\nis_opening,,int,0,,\nis_zerochannel,,int,0,,\nistreamtype,,int,0,,\nlocation_id,,char[52],0,,\nmodified_by,,char[52],0,,\nmodified_time,,timestamp,0,,\nremark,,char[52],0,,\nstate,,int,0,,\nsz_ip,,char[16],0,,\nsz_password,,char[22],0,,\nsz_port,,char[8],0,,\nsz_username,,char[22],0,,\nwx_hls,,char[102],0,,\n"
}
- 新增操作
返回值rpc代表影响的数据行数
若需要使用流水号,需要在bs_sys_auto_seq表中进行配置,请参照流水号使用方式
help_code代表是流水号主键的替换,type=int,char,barcode这三种,barcode是根据配置生成的配置表的,配置表的项值
{
"cmd": "insert",
"file": "tn_web_base_setting",
"table": "bs_camera",
"error_continue": "0",
"enable_log": "1",
"busi_type": "base_setting",
"user_id": "1902",
"help": [
{
"camera_id": "",
"camera_code": "因4子3名称133333",
"sz_username": "因子名称133333"
}
],
"help_code": [
{
"name": "camera_id",
"type": "barcode",
"barcode": "box_code"
}
]
}
- 返回值
{
“code”:"1",
"error":"",
"help":"",
"rpc":"1"
}
- 修改操作
主键不会修改,返回值rpc代表影响的数据行数
{
"cmd": "update",
"file": "tn_web_base_setting",
"table":"bs_camera",
"error_continue":"0",
"enable_log":"1",
"keys":"camera_id",
"help": [
{
"camera_id": "v3",
"camera_code": "因子名2342称13333323",
"sz_username": "因子名称134234234"
},
{
"camera_id": "v4",
"camera_code": "因子名称1",
"sz_username": "因子名称133333"
}
]
}
- 返回值
{
"code":"1",
"error":"",
"help":"",
"rpc":"1"
}
- 删除操作
返回值rpc代表影响的数据行数
{
"cmd": "delete",
"file": "tn_web_base_setting",
"table":"bs_camera",
"help": [
{
"camera_id": "v3"
},
{
"camera_id": "v4"
}
]
}
- 返回值
{
"code":"1",
"error":"",
"help":"",
"rpc":"1"
}
- 流程操作
使用流程版本模式,支持同时提交多个表的修改,流水号生成help是在data help后面加上code
{
"cmd": "flow",
"file": "tn_web_base_setting",
"table":"bs_camera",
"flow":[
{
"table":"bs_camera",
"cmd":"update",
"data":"help",
"keys":"camera_id"
},
{
"table":"bs_call_map",
"cmd":"update",
"data":"help_2",
"keys":"call_map_id"
}
],
"help": [
{
"camera_id": "PB2103060020",
"camera_code": "111",
"sz_username": "111",
"sz_ip":""
},
{
"camera_id": "PB2103060021",
"camera_code": "222",
"sz_username": "222",
"sz_ip":""
}
],
"help_2": [
{
"call_map_id": "v3",
"user_id": "1000",
"user_cn_name": "XXX"
},
{
"call_map_id": "v4",
"user_id": "1041",
"user_cn_name": "XXX"
}
]
}
- 返回值
{
"code": "1",
"error": "",
"help": "",
"help_result": [
{
"table": "bs_camera",
"count": "2",
"error": "",
"content": ""
},
{
"table": "bs_call_map",
"count": "0",
"error": "",
"content": ""
}
]
}
- 复杂查询
1、查询的例子,如果为*代表返回全部,条件中如果为空字符,代表不使用此条件
{
"cmd": "select",
"file": "web_data_base_query",
"table": "bs_eqpt_all",
"order":"eqpt_name",
"fields":"*",
"help_where": [
{
"name": "location_id",
"op": "=",
"value":"90003",
"value2":"",
"empty_key":""
},
{
"name": "install_date",
"op": ">=",
"value":"",
"value2":"",
"empty_key":""
}
],
"help_join": [
{
"table":"bs_location",
"type":"left",
"keys": "location_id",
"fileds": "location_name,location_type_id"
},
{
"table":"bs_eqpt_class",
"type":"left",
"keys":"eqpt_class_id",
"fileds":"eqpt_class_code,eqpt_class_name"
}
]
}
- 返回结果
{
"code": "1",
"error": "",
"help": [
{
"eqpt_id": "1056275",
"eqpt_code": "017316104032",
"eqpt_name": "017316104032(X-Ray探伤机 SMX-31M-P)",
"location_id": "90003",
"company_shop_id": "",
"sub_company": "",
"wh_id": "",
"eqpt_class_id": "",
"eqpt_type_id": "",
"eqpt_short_name": "",
"eqpt_long_name": "X-Ray探伤机 SMX-31M-P",
"asset_id": "",
"made_by": "",
"power": "",
"manufacture_date": "",
"install_date": "",
"start_time": "",
"end_time": "",
"hardware_type": "",
"hardware_version": "",
"device_series_id": "",
"device_company_id": "",
"pic_path": "",
"check_stop_time": "",
"mt_work_time": "",
"is_disable": "0",
"org_value": "0",
"salvage_value": "0",
"depred_value": "",
"dur_year": "5",
"depr_type": "X-Ray探伤机 SMX-31M-P",
"use_type": "0",
"p_rate": "1",
"alarm_time": "",
"lng": "",
"lat": "",
"beat": "0",
"eqpt_spec": "",
"tested_time": "1900-01-01 00:00:00",
"asset_lvl": "",
"asset_name": "",
"asset_code": "",
"use_sub_company": "",
"physical_state": "0",
"is_show_board": "0",
"max_mould_num": "1",
"max_person_num": "0",
"remove_gather_id": "",
"is_real": "1",
"is_need_sub_wo_code": "0",
"remove_is_online": "0",
"remove_is_change_user": "0",
"process_id": "",
"dev_mn": "",
"model_id": "",
"cur_material_id": "",
"res1": "",
"res2": "",
"res3": "",
"res4": "",
"res5": "",
"res6": "",
"res7": "",
"res8": "",
"res9": "",
"res0": "",
"is_delete": "",
"create_time": "",
"create_by": "",
"create_by_name": "",
"modified_time": "1900-01-01 00:00:00",
"modified_by": "",
"modified_by_name": "",
"container_code": "",
"oee_type": "",
"location_name": "检测室",
"location_type_id": "4",
"eqpt_class_code": "",
"eqpt_class_name": ""
}
]
}
2、按组合条件查询模式,gop_id,记得组合的第一个字段必须写上op(or,and)
{
"file": "web_data_base_query",
"cmd": "select",
"table": "bs_customer",
"enable_count":"0",
"help_where": [
{
"name": "customer_code",
"op": "like",
"value": "01",
"value2": "",
"empty_key": "",
"gop_id": "customer_code,or"
},
{
"name": "customer_type",
"op": "=",
"value": "customer",
"value2": "",
"empty_key": "",
"gop_id": "customer_code"
}
],
"help_join": [
{
"table": "uums_user",
"type": "left",
"keys": "modified_by=user_id",
"fileds": "user_cn_name as create_by_name2"
},
{
"table": "uums_user",
"type": "left",
"keys": "modified_by=user_id",
"fileds": "user_cn_name as modified_by_name2"
}
],
"ent_id": "EN1046",
"user_id": "1463",
"to_json": "1"
}
- 返回结果
{
"code": "1",
"error": "",
"help": [
{
"customer_id": "1477",
"customer_type": "customer",
"customer_code": "01008",
"customer_simple_name": "",
"customer_name": "XXXXX有限公司",
"customer_kind": "",
"customer_tel": "1242343242",
"customer_fax": "234324324",
"customer_post": "",
"customer_email": "",
"customer_address": "",
"customer_web": "",
"customer_bank": "",
"customer_account": "",
"customer_remark": "",
"contact_name": "",
"contact_tel": "",
"contact_mobile": "",
"contact_qq": "",
"contact_email": "",
"contact_weixin": "",
"contact_birthday": "",
"enable": "1",
"sort_no": "",
"auth_code": "",
"passwd": "81dc9bdb52d04dc20036dbd8313ed055",
"customer_desc": "",
"is_delete": "0",
"create_time": "2019-04-20 15:36:30",
"create_by": "sync",
"create_by_name": "",
"modified_time": "2019-04-20 15:36:30",
"modified_by": "sysadmin",
"modified_by_name": "",
"create_by_name2": "",
"modified_by_name2": ""
}
]
}
3、查询业务参数
{
"cmd": "select_param",
"file": "web_data_base_query",
"table":"sys_parameter",
"type":"qc_eqpt_type"
}
- 返回结果
{
"code": "1",
"error": "",
"help": [
{
"id": "5032",
"code": "T1",
"name": "气动量仪",
"param_type_id": "qc_eqpt_type",
"pid": "0",
"child_param_type_id": "",
"param_type_ename": ""
},
{
"id": "5033",
"code": "T2",
"name": "卡尺",
"param_type_id": "qc_eqpt_type",
"pid": "0",
"child_param_type_id": "",
"param_type_ename": ""
}
]
}
4、查询系统参数
{
"cmd": "select_sys_setting",
"file": "web_data_base_query",
"set_name":"report_user_num7"
}
- 返回结果
{
"code": "1",
"error": "",
"help": [
{
"set_id": "25",
"set_name": "report_user_num7",
"set_value": "user_num7",
"default_value": "",
"description": "",
"create_time": "2015-09-24 15:31:26",
"last_modified_time": "2015-09-25 08:51:09",
"display_name": "自定义报工数7",
"sequence": "0",
"modified_by": "sysadmin",
"module_id": "0",
"is_show": "1"
}
]
}
5、一次性查询多个
{
"cmd": "select_union_param",
"file": "web_data_base_query",
"help":[
{
"table":"bs_eqpt_type",
"type":""
},
{
"table":"bs_file_type",
"type":""
},
{
"table":"sys_parameter",
"type":"db_busi_type"
}
]
}
- 返回结果
{
"code": "1",
"error": "",
"help": "",
"help_bs_eqpt_type": [
{
"id": "LX004",
"code": "vir_eqpt",
"name": "虚拟设备"
},
{
"id": "LX005",
"code": "station",
"name": "工位"
},
{
"id": "LX006",
"code": "eqpt",
"name": "设备"
},
{
"id": "LX007",
"code": "line",
"name": "产线"
},
{
"id": "LX008",
"code": "eqpt_group",
"name": "设备组"
}
],
"help_bs_file_type": [],
"help_sys_parameter": [
{
"id": "1345",
"code": "基础表",
"name": "基础表",
"param_type_id": "db_busi_type",
"pid": "",
"child_param_type_id": "",
"param_type_ename": ""
},
{
"id": "1346",
"code": "物料流转",
"name": "物料流转",
"param_type_id": "db_busi_type",
"pid": "",
"child_param_type_id": "",
"param_type_ename": ""
}
]
}