diff --git a/app/tmnet_db_func.py b/app/tmnet_db_func.py index 305782f..6236719 100644 --- a/app/tmnet_db_func.py +++ b/app/tmnet_db_func.py @@ -192,48 +192,83 @@ class TmnetDbHelper(TableDbHelperBase): """ conn, cursor = self.connect() try: - sql = """select IFNULL(clui.name, c2.name) as name, - c.crossid, - IFNULL(clui.location, c.location) as location, - c.nodeid, - c.area_id, - IFNULL(r.roadid,IFNULL(rlui.roadid,udr.roadid)) as roadid, - IFNULL(rlui.from_crossid, IFNULL(r.from_crossid,udr.from_crossid)) as from_crossid, - IFNULL(rlui.to_crossid, IFNULL(r.to_crossid,udr.to_crossid)) as to_crossid, - IFNULL(rlui.name, IFNULL(r.name,udr.name)) as road_name, - IFNULL(rlui.src_direct, IFNULL(r.src_direct,udr.src_direct)) as src_direct - from `bound_crosses` as c - join `cross` c2 on c2.crossid = c.crossid and c2.nodeid = %s and c2.area_id = %s - left join `cross_ledger_update_info` as clui on clui.crossid = c.crossid and clui.nodeid = %s and clui.area_id = %s - left join `road` as r on r.nodeid = %s and r.to_crossid = c.crossid and r.recordstate = 0 and (r.is_sup_road is null or r.is_sup_road <> 1) - left join `road_ledger_update_info` as rlui on rlui.roadid = r.roadid and rlui.nodeid = %s 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) - left join `user_defined_roads` as udr on udr.nodeid = %s and udr.recordstate = 0 and udr.to_crossid = c2.crossid and (udr.is_sup_road is null or udr.is_sup_road <> 1) - where c.nodeid = %s - and c.area_id = %s - union all - select udc.name, - udc.crossid, - udc.location, - c.nodeid, - c.area_id, - IFNULL(r.roadid,IFNULL(rlui.roadid,udr.roadid)) as roadid, - IFNULL(rlui.from_crossid, IFNULL(r.from_crossid,udr.from_crossid)) as from_crossid, - IFNULL(rlui.to_crossid, IFNULL(r.to_crossid,udr.to_crossid)) as to_crossid, - IFNULL(rlui.name, IFNULL(r.name,udr.name)) as road_name, - IFNULL(rlui.src_direct, IFNULL(r.src_direct,udr.src_direct)) as src_direct - from `bound_crosses` as c - join `user_defined_cross` udc on udc.crossid = c.crossid and udc.nodeid = %s and udc.area_id = %s - left join `road` as r on r.nodeid = %s and r.to_crossid = udc.crossid and r.recordstate = 0 and (r.is_sup_road is null or r.is_sup_road <> 1) - left join `road_ledger_update_info` as rlui on rlui.roadid = r.roadid and rlui.nodeid = %s and rlui.recordstate = 0 and rlui.to_crossid = r.to_crossid and (rlui.is_sup_road is null or rlui.is_sup_road <> 1) - left join `user_defined_roads` as udr on udr.nodeid = %s and udr.recordstate = 0 and udr.to_crossid = c.crossid and (udr.is_sup_road is null or udr.is_sup_road <> 1) - where c.nodeid = %s - and c.area_id = %s""" + sql = """select IFNULL(clui.name, c2.name) as name, + c.crossid, + IFNULL(clui.location, c.location) as location, + c.nodeid, + c.area_id, + IFNULL(r.roadid,rlui.roadid) as roadid, + IFNULL(rlui.from_crossid, r.from_crossid) as from_crossid, + IFNULL(rlui.to_crossid, r.to_crossid) as to_crossid, + IFNULL(rlui.name, r.name) as road_name, + IFNULL(rlui.src_direct, r.src_direct) as src_direct + from `bound_crosses` as c + join `cross` c2 on c2.crossid = c.crossid and c2.nodeid = %s and c2.area_id = %s + left join `cross_ledger_update_info` as clui on clui.crossid = c.crossid and clui.nodeid = %s and clui.area_id = %s + left join `road` as r on r.nodeid = %s and r.to_crossid = c.crossid and r.recordstate = 0 and (r.is_sup_road is null or r.is_sup_road <> 1) + left join `road_ledger_update_info` as rlui on rlui.roadid = r.roadid and rlui.nodeid = %s 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 c.nodeid = %s + and c.area_id = %s + union all + select IFNULL(clui.name, c2.name) as name, + c.crossid, + IFNULL(clui.location, c.location) as location, + c.nodeid, + c.area_id, + udr.roadid, + udr.from_crossid, + udr.to_crossid, + udr.name, + udr.src_direct + from `bound_crosses` as c + join `cross` c2 on c2.crossid = c.crossid and c2.nodeid = %s and c2.area_id = %s + left join `cross_ledger_update_info` as clui on clui.crossid = c.crossid and clui.nodeid = %s and clui.area_id = %s + join `user_defined_roads` as udr on udr.nodeid = %s and udr.recordstate = 0 and udr.to_crossid = c2.crossid and (udr.is_sup_road is null or udr.is_sup_road <> 1) + where c.nodeid = %s + and c.area_id = %s + union all + select udc.name, + udc.crossid, + udc.location, + c.nodeid, + c.area_id, + IFNULL(r.roadid,rlui.roadid) as roadid, + IFNULL(rlui.from_crossid, r.from_crossid) as from_crossid, + IFNULL(rlui.to_crossid, r.to_crossid) as to_crossid, + IFNULL(rlui.name, r.name) as road_name, + IFNULL(rlui.src_direct, r.src_direct) as src_direct + from `bound_crosses` as c + join `user_defined_cross` udc on udc.crossid = c.crossid and udc.nodeid = %s and udc.area_id = %s + left join `road` as r on r.nodeid = %s and r.to_crossid = udc.crossid and r.recordstate = 0 and (r.is_sup_road is null or r.is_sup_road <> 1) + left join `road_ledger_update_info` as rlui on rlui.roadid = r.roadid and rlui.nodeid = %s and rlui.recordstate = 0 and rlui.to_crossid = r.to_crossid and (rlui.is_sup_road is null or rlui.is_sup_road <> 1) + where c.nodeid = %s + and c.area_id = %s + union all + select udc.name, + udc.crossid, + udc.location, + c.nodeid, + c.area_id, + udr.roadid, + udr.from_crossid, + udr.to_crossid, + udr.name as road_name, + udr.src_direct + from `bound_crosses` as c + join `user_defined_cross` udc on udc.crossid = c.crossid and udc.nodeid = %s and udc.area_id = %s + left join `user_defined_roads` as udr on udr.nodeid = %s and udr.recordstate = 0 and udr.to_crossid = c.crossid and (udr.is_sup_road is null or udr.is_sup_road <> 1) + where c.nodeid = %s + and c.area_id = %s""" print(cursor.mogrify(sql, ( - nodeid, area_id, nodeid, area_id, nodeid, nodeid, nodeid, int(nodeid), int(area_id), nodeid, area_id, + nodeid, area_id, nodeid, area_id, nodeid, nodeid, int(nodeid), int(area_id), + nodeid, area_id, nodeid, area_id, nodeid, int(nodeid), int(area_id), + nodeid, area_id, nodeid, nodeid, int(nodeid), int(area_id), nodeid, nodeid, nodeid, int(nodeid), int(area_id)))) cursor.execute(sql, ( - nodeid, area_id, nodeid, area_id, nodeid, nodeid, nodeid, int(nodeid), int(area_id), nodeid, area_id, - nodeid, nodeid, nodeid, int(nodeid), int(area_id))) + nodeid, area_id, nodeid, area_id, nodeid, nodeid, int(nodeid), int(area_id), + nodeid, area_id, nodeid, area_id, nodeid, int(nodeid), int(area_id), + nodeid, area_id, nodeid, nodeid, int(nodeid), int(area_id), + nodeid, nodeid, nodeid, int(nodeid), int(area_id))) result = cursor.fetchall() self.close(conn, cursor) return result, None