上线查询路口大数据方案验证异常详情查询接口

This commit is contained in:
wangxu 2025-10-31 11:25:16 +08:00
parent c6f8189bd8
commit 3d5bba65d4
3 changed files with 89 additions and 1 deletions

View File

@ -52,5 +52,21 @@ def cross_problems_api():
def phase_cross_list_router(): def phase_cross_list_router():
return phase_cross_list(dict(request.args)) return phase_cross_list(dict(request.args))
@app.route('/api/cross_examine_records', methods=['POST'])
def cross_problems_detail_api():
return query_cross_examine_records_detail(request.json)
@app.route('/api/cross_examine_records', methods=['POST'])
def cross_problems_detail_api():
return query_cross_examine_records_detail(request.json)
@app.route('/api/cross_examine_records', methods=['POST'])
def cross_problems_detail_api():
return query_cross_examine_records_detail(request.json)
if __name__ == '__main__': if __name__ == '__main__':
pass pass

View File

@ -297,4 +297,76 @@ def query_cross_index_trend_controller(params):
return json.dumps(res, ensure_ascii=False) return json.dumps(res, ensure_ascii=False)
def query_cross_examine_records_detail(params):
crossid = check_param(params, 'crossid')
if not crossid:
return json.dumps(make_common_res(1, '缺少crossid 请刷新后重试'))
nodeid = check_param(params, 'nodeid')
if not nodeid:
return json.dumps(make_common_res(2, '缺少nodeid 请刷新后重试'))
area_id = check_param(params, 'area_id')
if not area_id:
return json.dumps(make_common_res(3, '缺少area_id 请刷新后重试'))
userid = check_param(params, 'userid')
if not userid:
return json.dumps(make_common_res(4, '缺少userid 请刷新后重试'))
area_list = db_user.query_user_areas(userid)
if not area_list or len(area_list) < 1:
return json.dumps(make_common_res(5, '用户信息异常'))
area_list = [int(row['area_id']) for row in area_list]
if int(area_id) not in area_list:
return json.dumps(make_common_res(6, '用户信息异常'))
date_list = check_param(params, 'date_list')
if not date_list:
return json.dumps(make_common_res(7, '缺少查询日期,请选择查询日期'))
time_range = check_param(params, 'time_range')
if not time_range:
return json.dumps(make_common_res(8, '缺少时段范围,请选择时段范围'))
max_date = max(date_list)
min_date = min(date_list)
tp_start = int(str(time_range.split('-')[0]).split(':')[0]) * 100 + int(str(time_range.split('-')[0]).split(':')[1])
cross_examine_records = db_cross.query_cross_examine_records(tp_start, max_date, crossid, min_date)
prev_day = (datetime.now() - timedelta(days=1)).strftime('%Y%m%d')
if not cross_examine_records:
return json.dumps(make_common_res(9, '当前路口在所选时段无异常情况'))
days_records = {}
dir_str_dict = {
'E': '', 'S': '', 'W': '西', 'N': '', 'NE': '东北', 'SE': '东南', 'SW': '西南', 'NW': '西北'
}
for row in cross_examine_records:
final_state = row['final_state']
level_color = row['level_color']
first_date = row['first_date']
if final_state == 6 or level_color == 4:
continue
date_list = generate_date_range(first_date, prev_day)
phase_types = row['phase_type']
phase_details = row['phase_detail']
phase_type_list = phase_types.split('^')
phase_detail_list = phase_details.split('^')
for i in range(len(date_list)):
date = date_list[i]
phase_type = phase_type_list[i]
phase_detail = phase_detail_list[i]
item_phase_type_list = phase_type.split(';')
item_phase_detail_list = phase_detail.split(';')
phase_type_dir_dict, dir_phase_detail_dict = {}, {}
for item in item_phase_detail_list:
src_dir_str = item.split(':')[0]
clean_key = re.sub(r'正|\(\d+\)', '', src_dir_str)
dir_phase_detail_dict[clean_key] = item
for item in item_phase_type_list:
if item == '':
continue
src_dir = item.split(':')[0]
item_type = item.split(':')[1]
item_detail = dir_phase_detail_dict[dir_str_dict[src_dir]]
if int(item_type) not in phase_type_dir_dict.keys():
phase_type_dir_dict[int(item_type)] = [item_detail]
else:
phase_type_dir_dict[int(item_type)].append(item_detail)
days_records[date] = phase_type_dir_dict
res = make_common_res(0, 'ok')
res['data'] = days_records
return json.dumps(res, ensure_ascii=False)

View File

@ -1376,7 +1376,7 @@ def gen_err_phase_problems(start_hm, max_date, crossid, min_date):
} }
] ]
for cross_examine_record in cross_examine_records: for cross_examine_record in cross_examine_records:
if cross_examine_record['level_color'] == 4: if cross_examine_record['level_color'] == 4 or cross_examine_record['final_state'] == 6:
continue continue
first_date = cross_examine_record['first_date'] first_date = cross_examine_record['first_date']
start_hm = convert_time(cross_examine_record['start_hm']) start_hm = convert_time(cross_examine_record['start_hm'])