STEP1 :
https://bibfx.flyhsystem.com/datax/api/manage/reportDataPreview?dashBoardReportId=0fef1a97-fac6-4bb9-ac52-e352c88130fc&where={"conditions":[{"field":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"date_format(trace,'%Y-%m-%d %H:%m:%s')","isEXPR":true},"operator":">=","value":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"'2024-04-16 00:00:00'","isEXPR":true},"command":"AND"},{"field":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"date_format(trace,'%Y-%m-%d %H:%m:%s')","isEXPR":true},"operator":"<","value":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"'2024-04-17 00:00:00'","isEXPR":true},"command":"AND"}]}
STEP2 : 参数提取,给我全部整成斜杠了,我去
url = "https://bibfx.flyhsystem.com/datax/api/manage/reportDataPreview"
params = {
"dashBoardReportId": "0fef1a97-fac6-4bb9-ac52-e352c88130fc",
"where": "{\"conditions\":[{\"field\":{\"db\":\"bibfx_tms\",\"table\":\"bibfxuseronline_new\",\"name\":\"date_format(trace,'%Y-%m-%d %H:%m:%s')\",\"isEXPR\":true},\"operator\":\">=\",\"value\":{\"db\":\"bibfx_tms\",\"table\":\"bibfxuseronline_new\",\"name\":\"'2024-04-16 00:00:00'\",\"isEXPR\":true},\"command\":\"AND\"},{\"field\":{\"db\":\"bibfx_tms\",\"table\":\"bibfxuseronline_new\",\"name\":\"date_format(trace,'%Y-%m-%d %H:%m:%s')\",\"isEXPR\":true},\"operator\":\"<\",\"value\":{\"db\":\"bibfx_tms\",\"table\":\"bibfxuseronline_new\",\"name\":\"'2024-04-17 00:00:00'\",\"isEXPR\":true},\"command\":\"AND\"}]}"
}
type(params["where"])
str
params["where"] # 可以看到为JSON字符串
'{"conditions":[{"field":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"date_format(trace,\'%Y-%m-%d %H:%m:%s\')","isEXPR":true},"operator":">=","value":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"\'2024-04-16 00:00:00\'","isEXPR":true},"command":"AND"},{"field":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"date_format(trace,\'%Y-%m-%d %H:%m:%s\')","isEXPR":true},"operator":"<","value":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"\'2024-04-17 00:00:00\'","isEXPR":true},"command":"AND"}]}'
STEP3 : 构建时间变量参数
错误示范
begin_time = '2024-04-01 00:00:00'
end_time = '2024-04-02 00:00:00'
url = "https://bibfx.flyhsystem.com/datax/api/manage/reportDataPreview"
params = {
"dashBoardReportId": "0fef1a97-fac6-4bb9-ac52-e352c88130fc",
"where": "{\"conditions\":[{\"field\":{\"db\":\"bibfx_tms\",\"table\":\"bibfxuseronline_new\",\"name\":\"date_format(trace,'%Y-%m-%d %H:%m:%s')\",\"isEXPR\":true},\"operator\":\">=\",\"value\":{\"db\":\"bibfx_tms\",\"table\":\"bibfxuseronline_new\",\"name\":f\"'{begin_time}'\",\"isEXPR\":true},\"command\":\"AND\"},{\"field\":{\"db\":\"bibfx_tms\",\"table\":\"bibfxuseronline_new\",\"name\":\"date_format(trace,'%Y-%m-%d %H:%m:%s')\",\"isEXPR\":true},\"operator\":\"<\",\"value\":{\"db\":\"bibfx_tms\",\"table\":\"bibfxuseronline_new\",\"name\":f\"'{end_time}'\",\"isEXPR\":true},\"command\":\"AND\"}]}"
}
params["where"] # begin_time、end_time变量未生效
'{"conditions":[{"field":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"date_format(trace,\'%Y-%m-%d %H:%m:%s\')","isEXPR":true},"operator":">=","value":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":f"\'{begin_time}\'","isEXPR":true},"command":"AND"},{"field":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"date_format(trace,\'%Y-%m-%d %H:%m:%s\')","isEXPR":true},"operator":"<","value":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":f"\'{end_time}\'","isEXPR":true},"command":"AND"}]}'
STEP4 : 正确示范
# 将STEP2的基础上打印下来
# 关键一步:
params["where"]
'{"conditions":[{"field":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"date_format(trace,\'%Y-%m-%d %H:%m:%s\')","isEXPR":true},"operator":">=","value":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":f"\'{begin_time}\'","isEXPR":true},"command":"AND"},{"field":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"date_format(trace,\'%Y-%m-%d %H:%m:%s\')","isEXPR":true},"operator":"<","value":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":f"\'{end_time}\'","isEXPR":true},"command":"AND"}]}'
# 敲黑板,
# 1 .JSON字符串要打印下来
print(params["where"])
{"conditions":[{"field":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"date_format(trace,'%Y-%m-%d %H:%m:%s')","isEXPR":true},"operator":">=","value":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":f"'{begin_time}'","isEXPR":true},"command":"AND"},{"field":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"date_format(trace,'%Y-%m-%d %H:%m:%s')","isEXPR":true},"operator":"<","value":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":f"'{end_time}'","isEXPR":true},"command":"AND"}]}
# 2. 再复制出来构建日期参数 ()
begin_time = '2024-04-01 00:00:00'
end_time = '2024-04-02 00:00:00'
url = "https://bibfx.flyhsystem.com/datax/api/manage/reportDataPreview"
params = {
"dashBoardReportId": "0fef1a97-fac6-4bb9-ac52-e352c88130fc",
"where":{"conditions":[{"field":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"date_format(trace,'%Y-%m-%d %H:%m:%s')","isEXPR":True},"operator":">=","value":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":f"'{begin_time}'","isEXPR":True},"command":"AND"},{"field":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"date_format(trace,'%Y-%m-%d %H:%m:%s')","isEXPR":True},"operator":"<","value":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":f"'{end_time}'","isEXPR":True},"command":"AND"}]}
}
type(params["where"])
dict
params # 字典
{'dashBoardReportId': '0fef1a97-fac6-4bb9-ac52-e352c88130fc',
'where': {'conditions': [{'field': {'db': 'bibfx_tms',
'table': 'bibfxuseronline_new',
'name': "date_format(trace,'%Y-%m-%d %H:%m:%s')",
'isEXPR': True},
'operator': '>=',
'value': {'db': 'bibfx_tms',
'table': 'bibfxuseronline_new',
'name': "'2024-04-01 00:00:00'",
'isEXPR': True},
'command': 'AND'},
{'field': {'db': 'bibfx_tms',
'table': 'bibfxuseronline_new',
'name': "date_format(trace,'%Y-%m-%d %H:%m:%s')",
'isEXPR': True},
'operator': '<',
'value': {'db': 'bibfx_tms',
'table': 'bibfxuseronline_new',
'name': "'2024-04-02 00:00:00'",
'isEXPR': True},
'command': 'AND'}]}}
STEP4 : dict --> str
begin_time = '2024-04-01 00:00:00'
end_time = '2024-04-12 00:00:00'
url = "https://bibfx.flyhsystem.com/datax/api/manage/reportDataPreview"
params = {
"dashBoardReportId": "0fef1a97-fac6-4bb9-ac52-e352c88130fc",
"where":json.dumps({"conditions":[{"field":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"date_format(trace,'%Y-%m-%d %H:%m:%s')","isEXPR":True},"operator":">=","value":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":f"'{begin_time}'","isEXPR":True},"command":"AND"},{"field":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":"date_format(trace,'%Y-%m-%d %H:%m:%s')","isEXPR":True},"operator":"<","value":{"db":"bibfx_tms","table":"bibfxuseronline_new","name":f"'{end_time}'","isEXPR":True},"command":"AND"}]})
}
type(params["where"])
str
params
{'dashBoardReportId': '0fef1a97-fac6-4bb9-ac52-e352c88130fc',
'where': '{"conditions": [{"field": {"db": "bibfx_tms", "table": "bibfxuseronline_new", "name": "date_format(trace,\'%Y-%m-%d %H:%m:%s\')", "isEXPR": true}, "operator": ">=", "value": {"db": "bibfx_tms", "table": "bibfxuseronline_new", "name": "\'2024-04-01 00:00:00\'", "isEXPR": true}, "command": "AND"}, {"field": {"db": "bibfx_tms", "table": "bibfxuseronline_new", "name": "date_format(trace,\'%Y-%m-%d %H:%m:%s\')", "isEXPR": true}, "operator": "<", "value": {"db": "bibfx_tms", "table": "bibfxuseronline_new", "name": "\'2024-04-12 00:00:00\'", "isEXPR": true}, "command": "AND"}]}'}
#搞定
或者:
可视化效果:
url = "https://bibfx.flyhsystem.com/datax/api/manage/reportDataPreview"
begin_time = '2024-04-15 00:00:00'
end_time = '2024-04-18 00:00:00'
params = {
"dashBoardReportId": "0fef1a97-fac6-4bb9-ac52-e352c88130fc",
"where": json.dumps({
"conditions": [
{
"field": {
"db": "bibfx_tms",
"table": "bibfxuseronline_new",
"name": f"date_format(trace,'%Y-%m-%d %H:%m:%s')",
"isEXPR": True
},
"operator": ">=",
"value": {
"db": "bibfx_tms",
"table": "bibfxuseronline_new",
"name": f"'{begin_time}'",
"isEXPR": True
},
"command": "AND"
},
{
"field": {
"db": "bibfx_tms",
"table": "bibfxuseronline_new",
"name": f"date_format(trace,'%Y-%m-%d %H:%m:%s')",
"isEXPR": True
},
"operator": "<",
"value": {
"db": "bibfx_tms",
"table": "bibfxuseronline_new",
"name": f"'{end_time}'",
"isEXPR": True
},
"command": "AND"
}
]
})
}
# 成功
params["where"]