diff --git a/app/cross_eva_views.py b/app/cross_eva_views.py index 2be84e7..18c7ea4 100644 --- a/app/cross_eva_views.py +++ b/app/cross_eva_views.py @@ -9,6 +9,7 @@ from flask_cors import CORS from flask_caching import Cache from app.cross_evaluate_worker import * +from app.phasetable_worker import phase_cross_list app = Flask(__name__) cache = Cache(app, config={'CACHE_TYPE': 'simple'}) @@ -47,5 +48,9 @@ def cross_problems_api(): return query_cross_problems(request.json) +@app.route('/api/crosslist', methods=['GET']) +def phase_cross_list_router(): + return phase_cross_list(dict(request.args)) + if __name__ == '__main__': pass \ No newline at end of file diff --git a/app/phasetable_worker.py b/app/phasetable_worker.py new file mode 100644 index 0000000..8f91994 --- /dev/null +++ b/app/phasetable_worker.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# @Author: Owl +# @Date: 2025/10/10 14:33 +# @Description: +import json + +from app.common_worker import * +from app.eva_common import * + + +# 查询可用路口列表 +from proto.phase_grpc import QueryCrossRunningPhase + + +def phase_cross_list(params): + nodeid = check_param(params, 'nodeid') + if not nodeid: + return json.dumps(make_common_res(1, '缺少nodeid, 请刷新后重试')) + area_id = check_param(params, 'area_id') + if not area_id: + return json.dumps(make_common_res(2, '缺少area_id, 请刷新后重试')) + userid = check_param(params, 'userid') + if not userid: + return json.dumps(make_common_res(3, '缺少userid, 请刷新后重试')) + area_list = db_user.query_user_areas(userid) + if not area_list or len(area_list) < 1: + return json.dumps(make_common_res(4, '用户信息异常')) + 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(5, '用户信息异常')) + + + cross_road_list, error = db_tmnet.query_cross_list_road(str(nodeid), str(area_id)) + + if error: + return json.dumps(make_common_res(2, f"{error}"), ensure_ascii=False) + + cross_map = {} + for item_cross_road_list in cross_road_list: + if item_cross_road_list['crossid'] not in cross_map: + cross_map[item_cross_road_list['crossid']] = { + "crossid": item_cross_road_list['crossid'], + "name": item_cross_road_list['name'], + "src_dir": [], + } + if item_cross_road_list['src_direct'] not in cross_map[item_cross_road_list['crossid']]['src_dir']: + cross_map[item_cross_road_list['crossid']]['src_dir'].append(item_cross_road_list['src_direct']) + res = make_common_res(0, 'ok') + res["data"] = list(cross_map.values()) + return json.dumps(res, ensure_ascii=False) diff --git a/app/tmnet_db_func.py b/app/tmnet_db_func.py index 1d1e69f..21db494 100644 --- a/app/tmnet_db_func.py +++ b/app/tmnet_db_func.py @@ -173,4 +173,42 @@ class TmnetDbHelper(TableDbHelperBase): from (select name,crossid, location,nodeid, area_id from `cross` where nodeid = %s and area_id = %s and at_edge=0 and isdeleted=0 and crossid = %s) as t1 left join (select name,crossid, location,nodeid, area_id from `cross_ledger_update_info` where nodeid = %s and area_id = %s and at_edge=0 and isdeleted=0 and crossid = %s) as t2 on t1.crossid=t2.crossid """ % (nodeid, area_id, crossid, nodeid, area_id, crossid) - return self.do_select(sql) \ No newline at end of file + return self.do_select(sql) + + def query_cross_list_road(self, nodeid:str, area_id:str): + conn, cursor = self.connect() + try: + sql = """select if(clui.name is not null, clui.name, c.name) as name, + c.crossid, + if(clui.location is not null, clui.location, c.location) as location, + c.nodeid, + c.area_id, + t2.to_crossid, + t2.name road_name, + t2.src_direct + from `cross` as c + left join `cross_ledger_update_info` as clui on clui.crossid = c.crossid and clui.nodeid = c.nodeid and clui.area_id = c.area_id + left join ( + select r.roadid, + if(rlui.from_crossid is not null, rlui.from_crossid, r.from_crossid) as from_crossid, + if(rlui.to_crossid is not null, rlui.to_crossid, r.to_crossid) as to_crossid, + if(rlui.name is not null, rlui.name, r.name) as name, + if(rlui.src_direct is not null, rlui.src_direct, r.src_direct) as src_direct + from road as r + left join road_ledger_update_info as rlui on rlui.nodeid = r.nodeid and rlui.recordstate = r.recordstate and rlui.to_crossid = r.to_crossid and (rlui.is_sup_road is null or rlui.is_sup_road <> 1) + where r.nodeid = %s + and r.recordstate = 0 + and (r.is_sup_road is null or r.is_sup_road <> 1) + ) as t2 on t2.to_crossid = c.crossid + where c.nodeid = %s + and c.area_id = %s + and c.at_edge = 0 + and c.isdeleted = 0""" + print(cursor.mogrify(sql, (nodeid, nodeid, area_id))) + cursor.execute(sql, (nodeid, nodeid, area_id)) + result = cursor.fetchall() + self.close(conn, cursor) + return result, None + except Exception as error: + self.close(conn, cursor) + return None, error \ No newline at end of file