cross_doctor/app/db_cross_delay.py

161 lines
7.9 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# @Author: Owl
# @Date: 2025/10/10 16:17
# @Description:
from app.db_func_base import *
class CrossDbHelper(TableDbHelperBase):
def __init__(self, pool):
self.db_pool = pool
self.DB_Name = 'ledger'
def query_cross_usable_date_sql(self, crossid, nodeid):
sql = f"""
select distinct day from traffic_{nodeid}.cross_delay where crossid = '{crossid}'
"""
return self.do_select(sql)
def query_cross_delay_info(self, crossid, nodeid, date_list, tp_start):
date_list = ','.join(["'" + str(item) + "'" for item in date_list])
sql = f"""
select * from traffic_{nodeid}.cross_delay where crossid = '{crossid}' and day in ({date_list}) and tp_start = '{tp_start}' order by day
"""
return self.do_select(sql)
def query_cross_delay_whole_day_hours(self, crossid, nodeid, query_date):
sql = f"""
select * from traffic_{nodeid}.cross_delay where crossid = '{crossid}' and day = '{query_date}' and tp_start like 'h%' order by CAST(REGEXP_SUBSTR(tp_start, '[0-9]+') AS UNSIGNED)
"""
return self.do_select(sql)
def query_cross_examine_records(self, start_hm, first_date, crossid, end_date):
sql = """
select * from cross_doctor_matedata.cross_phase_problems_record where crossid = '%s' and start_hm = '%s' and first_date <= %s and (end_date >= '%s' or end_date is null)
""" % (crossid, start_hm, first_date, end_date)
2025-11-03 18:45:50 +08:00
return self.do_select(sql)
2025-11-14 14:46:15 +08:00
def query_cross_examine_record_detail(self, start_hm, first_date, crossid):
sql = """
2025-11-14 14:59:16 +08:00
select * from cross_doctor_matedata.cross_phase_problems_record where crossid = '%s' and start_hm = '%s' and first_date = %s
2025-11-14 14:46:15 +08:00
""" % (crossid, start_hm, first_date)
return self.do_select(sql)
def query_crosses_examine_records(self, crossid_list, first_date, min_date):
crossids = ','.join(["'" + str(item) + "'" for item in crossid_list])
sql = """
select * from cross_doctor_matedata.cross_phase_problems_record where crossid in (%s) and first_date <= '%s' and (end_date >= '%s' or end_date is null)
""" % (crossids, min_date, first_date)
return self.do_select(sql)
2025-11-11 11:14:22 +08:00
def query_cross_examine_records_nostarthm(self, first_date, crossid, end_date):
sql = """
select * from cross_doctor_matedata.cross_phase_problems_record where crossid = '%s' and first_date <= %s and (end_date >= '%s' or end_date is null)
""" % (crossid, first_date, end_date)
return self.do_select(sql)
2025-11-11 11:42:02 +08:00
def update_cross_examine_record_state_sql(self, crossid, first_date, end_date, start_hm, state):
2025-11-03 18:45:50 +08:00
sql = """
2025-11-12 14:54:47 +08:00
update cross_doctor_matedata.cross_phase_problems_record set final_state = '%s', end_date = '%s' where crossid = '%s' and first_date = '%s' and start_hm = %s
2025-11-11 11:42:02 +08:00
""" % (state, end_date, crossid, first_date, start_hm)
2025-11-04 15:34:41 +08:00
return self.do_execute(sql)
2025-11-15 15:03:22 +08:00
def query_monitor_task_dates(self, nodeid, area_id):
day_sql = f"select distinct day from traffic_{nodeid}.cross_inspect where citycode = {nodeid} and area_id = {area_id} and type = 'day'"
week_sql = f"select distinct day from traffic_{nodeid}.cross_inspect where citycode = {nodeid} and area_id = {area_id} and type = 'week'"
day_date_list = self.do_select(day_sql)
week_date_list = self.do_select(week_sql)
day_list = [item['day'] for item in day_date_list]
week_list = [item['day'] for item in week_date_list]
return day_list, week_list
def query_monitor_data_sql(self, nodeid, area_id, date_type, query_date):
2025-11-15 15:03:22 +08:00
if date_type in ['week', 'workday', 'weekend']:
date_type = 'week'
sql = f"""
select * from traffic_{nodeid}.cross_inspect where citycode = {nodeid} and area_id = {area_id} and type = '{date_type}' and day = '{query_date}'
"""
return self.do_select(sql)
def query_monitor_data_trend_sql(self, nodeid, area_id, date_type):
limit_num = 30
if date_type in ['week', 'workday', 'weekend']:
date_type = 'week'
limit_num = 10
sql = f"""
select * from traffic_{nodeid}.cross_inspect where area_id = {area_id} and type = '{date_type}' order by day desc limit {limit_num}
"""
return self.do_select(sql)
def query_cross_tp_problem_record(self, yesterday, date_type, area_id):
sql = f"""
select * from cross_doctor_matedata.cross_tp_problem_record where area_id = {area_id} and date_type = '{date_type}' and date(update_time) = '{yesterday}' and time_range is not null and time_range != ''
"""
return self.do_select(sql)
def query_tide_cross_records(self, yesterday, area_id):
sql = f"""
select * from cross_doctor_matedata.cross_tp_problem_record where area_id = {area_id} and date(update_time) = '{yesterday}'
"""
return self.do_select(sql)
def insert_cross_tp_problem_record(self, insert_list):
conn, cursor = self.connect()
sql = f"""
insert into cross_doctor_matedata.cross_tp_problem_record (area_id, crossid, weekday, time_range, date_type, high_park_problem, too_many_stop_times, imbalance_inroad, turn_imbalance, tide_cross, inroad_turnlane_mismatch) values (%s, '%s', '%s', '%s', '%s', %d, %d, %d, %d, %d, %d)""" % (insert_list)
conn.begin()
try:
ret = cursor.executemany(sql)
if ret == len(insert_list):
conn.commit()
return 1, "success"
else:
conn.rollback()
return 0, "fail"
except Exception as e:
conn.rollback()
logging.error(e)
return 0, "error"
def query_inroad_lanes(self, nodeid_list):
nodeids = ','.join(["'" + str(item) + "'" for item in nodeid_list])
sql = """
select t1.roadid,
if(t1.lane_turn_info != t1.lane_turn_info, t2.lane_turn_info, t1.lane_turn_info) as lane_turn_info
from (select roadid,lane_turn_info from tmnet.road where nodeid in (%s) and is_sup_road <> 1) t1
left join (select roadid, lane_turn_info from tmnet.road_ledegr_update_info where nodeid in (%s) and is_sup_road <> 1) t2
on t1.roadid = t2.roadid
""" % (nodeids, nodeids)
return self.do_select(sql)
def query_cross_problem_record(self, area_id, update_date, query_type):
sql = """
select * from cross_doctor_matedata.cross_tp_problem_record where area_id = %s and date(update_time) = '%s' and date_type = '%s'
""" % (area_id, update_date, query_type)
return self.do_select(sql)
def query_shield_records(self, area_id):
sql = """
select * from cross_doctor_matedata.cross_problem_shield where area_id = %s
""" % (area_id)
return self.do_select(sql)
def add_shield_records(self, crossid ,area_id, weekday, time_range, problem_key, date_type):
sql = """
insert into cross_doctor_matedata.cross_problem_shield (crossid, area_id, weekdays, time_range, problem_key, date_type) values ('%s', %s, '%s', '%s', '%s', '%s')
""" % (crossid, area_id, weekday, time_range, problem_key, date_type)
return self.do_execute(sql)
def delete_shield_records(self, crossid, area_id, weekday, time_range, problem_key, date_type):
sql = """
delete from cross_doctor_matedata.cross_problem_shield where crossid = '%s' and area_id = %s and weekdays = '%s' and time_range = '%s' and problem_key = '%s' and date_type = '%s'
""" % (crossid, area_id, weekday, time_range, problem_key, date_type)
return self.do_execute(sql)
def query_csr_data(self, nodeid, key, crossid):
sql = f"""
select * from traffic_{nodeid}.csr_data where key = '{key}' and crossid = '{crossid}'
"""
2025-11-15 15:03:22 +08:00
return self.do_select(sql)