优化路口巡检报告周报生成逻辑
This commit is contained in:
parent
5d09b8ec99
commit
09f5c303f0
|
|
@ -2901,9 +2901,9 @@ def upload_cross_monitor_record_file(params):
|
|||
cos_client.put_object(Bucket=g_cos_bucket, Key=cos_key, Body=file_stream)
|
||||
download_url = f'{g_cos_root}/{cos_key}'
|
||||
record_info[item_class][item_key]['upload_file_path'].append(download_url)
|
||||
# record_info_json = json.loads(record_info)
|
||||
record_info_json = json.dumps(record_info, ensure_ascii=False)
|
||||
update_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
ret = db_task.save_cross_monitor_record_info_sql(nodeid, area_id, recordid, task_no, crossid, err_num, process_func, record_info, operator, operator_id, record_status, update_time, special_time_range, monitor_date, monitor_type)
|
||||
ret = db_task.save_cross_monitor_record_info_sql(nodeid, area_id, recordid, task_no, crossid, err_num, process_func, record_info_json, operator, operator_id, record_status, update_time, special_time_range, monitor_date, monitor_type)
|
||||
if ret:
|
||||
return json.dumps(make_common_res(0, 'ok'))
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -781,3 +781,10 @@ class TmnetDbHelper(TableDbHelperBase):
|
|||
res = self.do_select(sql)
|
||||
return res[0]['center'] if res else None
|
||||
|
||||
def gen_cross_type_dict(self):
|
||||
sql = """
|
||||
select mapping_code, web_tag from tags.cross_tag_meta where field_eng_name = 'cross_type'
|
||||
"""
|
||||
res = self.do_select(sql)
|
||||
cross_type_dict = {item['mapping_code']: item['web_tag'] for item in res}
|
||||
return cross_type_dict
|
||||
Binary file not shown.
|
|
@ -8,6 +8,8 @@
|
|||
3. 表格 -> data['part2']
|
||||
"""
|
||||
import io
|
||||
import logging
|
||||
import re
|
||||
from datetime import datetime
|
||||
|
||||
from docx import Document
|
||||
|
|
@ -218,6 +220,7 @@ def add_merged_table_rows(table, table_data, cell_style):
|
|||
except Exception as e:
|
||||
print(f"合并单元格失败: {e}")
|
||||
|
||||
|
||||
def process_merged_table(doc, data):
|
||||
table_data = data.get('part2', {}).get('data', [])
|
||||
table_cell_style = get_style_table_cell(doc)
|
||||
|
|
@ -254,9 +257,20 @@ def fill_report_template(data):
|
|||
|
||||
# 2. 替换正文和日期
|
||||
replace_basic_placeholders(doc, data)
|
||||
|
||||
tabel_style = get_style_table_cell(doc)
|
||||
# 3. 处理表格
|
||||
process_merged_table(doc, data)
|
||||
|
||||
for table in doc.tables:
|
||||
if len(table.rows) > 0 and len(table.rows[0].cells) == 5:
|
||||
for row_index, row in enumerate(table.rows):
|
||||
if row_index == 0:
|
||||
continue
|
||||
columns = [table.columns[0], table.columns[1], table.columns[2]]
|
||||
for column in columns:
|
||||
for cell in column.cells:
|
||||
set_cell_content(cell, cell.text.replace('\n', ''), tabel_style)
|
||||
|
||||
city_name = data.get('title', {}).get('city', '')
|
||||
week_num = data.get('title', {}).get('week_num', '')
|
||||
file_stream = io.BytesIO()
|
||||
|
|
@ -275,69 +289,7 @@ def fill_report_template(data):
|
|||
# ================= 3. 测试运行 =================
|
||||
if __name__ == "__main__":
|
||||
# 使用您提供的新数据结构
|
||||
report_data = {
|
||||
'title': {
|
||||
'city': 'XX',
|
||||
'week_num': 15,
|
||||
},
|
||||
'date': '2024年4月8日-2024年4月14日',
|
||||
'part1': {
|
||||
'total': 120,
|
||||
'normal_cross_num': 85,
|
||||
'focus_cross_num': 35,
|
||||
'error_cross_num': 8,
|
||||
'usually_err_info': '信号灯故障3起',
|
||||
'phase_err_num': '相位异常2起',
|
||||
'static_org_num': '标志标线问题2起',
|
||||
'static_device_num': '设备损坏1起',
|
||||
},
|
||||
'part2': {
|
||||
'data': [
|
||||
{
|
||||
'name': '信号系统',
|
||||
'item_data': [
|
||||
{
|
||||
'name': '信号灯',
|
||||
'num': 3,
|
||||
'item_data': [
|
||||
{'cross_name': '中山路-解放路', 'process_func': '已更换LED模块'},
|
||||
{'cross_name': '人民路-建设路', 'process_func': '已修复电源线路'},
|
||||
{'cross_name': '光明路-新华路', 'process_func': '已调整配时方案'}
|
||||
]
|
||||
},
|
||||
{
|
||||
'name': '相位控制',
|
||||
'num': 2,
|
||||
'item_data': [
|
||||
{'cross_name': '胜利路-和平路', 'process_func': '已重新配置相位'},
|
||||
{'cross_name': '东风路-红旗路', 'process_func': '已优化绿信比'}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'name': '静态设施',
|
||||
'item_data': [
|
||||
{
|
||||
'name': '交通标志',
|
||||
'num': 2,
|
||||
'item_data': [
|
||||
{'cross_name': '文化路-教育路', 'process_func': '已更换破损标志'},
|
||||
{'cross_name': '体育路-健康路', 'process_func': '已补充缺失标线'}
|
||||
]
|
||||
},
|
||||
{
|
||||
'name': '设备设施',
|
||||
'num': 1,
|
||||
'item_data': [
|
||||
{'cross_name': '科技路-创新路', 'process_func': '已维修检测设备'}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
report_data = {'title': {'city': '福州市', 'week_num': 19}, 'date': '2026年05月12日', 'part1': {'total': 3, 'normal_cross_num': 3, 'focus_cross_num': 0, 'error_cross_num': 2, 'usually_err_info': '异常最多的巡检项为机动车多次排队(2个)、路口周期过大(2个)。', 'phase_err_num': '需要优化路口方案的路口0个', 'static_org_num': '需要调整交通组织路口2个', 'static_device_num': '需要调整交通设施路口1个'}, 'part2': {'data': [{'name': '台账录入情况', 'item_data': [{'name': '录入渠化台账信息与现场不符', 'num': 0, 'item_data': []}, {'name': '录入配时方案与实际运行方案不符', 'num': 0, 'item_data': []}]}, {'name': '路口运行情况', 'item_data': [{'name': '机动车多次排队', 'num': 2, 'item_data': [{'cross_name': '康达路与清展街交叉口', 'process_func': ''}, {'cross_name': '清展街与福和路交叉口', 'process_func': '调整交通组织,其他处置措施'}]}, {'name': '停车次数较高', 'num': 0, 'item_data': []}]}, {'name': '配时方案情况', 'item_data': [{'name': '路口周期过大', 'num': 2, 'item_data': [{'cross_name': '康达路与清展街交叉口', 'process_func': ''}, {'cross_name': '清展街与福和路交叉口', 'process_func': '调整交通组织,其他处置措施'}]}, {'name': '行人过街时间不足', 'num': 0, 'item_data': []}]}, {'name': '设备设施情况', 'item_data': [{'name': '信号灯缺、损', 'num': 0, 'item_data': []}]}]}}
|
||||
|
||||
fill_report_template(
|
||||
report_data
|
||||
|
|
|
|||
|
|
@ -142,6 +142,26 @@ class CosFolderManager:
|
|||
self.create_folder(folder_path)
|
||||
return False
|
||||
|
||||
def file_exists(self, file_path):
|
||||
"""
|
||||
判断文件是否存在
|
||||
:param file_path: 文件路径,如 'data/test.txt' 或 '/data/test.txt'
|
||||
:return: True/False
|
||||
"""
|
||||
# 1. 去除开头的 /,保证路径格式统一
|
||||
key = file_path.lstrip('/')
|
||||
|
||||
if not key:
|
||||
return False # 空路径视为文件不存在
|
||||
|
||||
try:
|
||||
# 2. 调用 SDK 自带的 object_exists 方法进行判断
|
||||
return self.client.object_exists(Bucket=self.bucket, Key=key)
|
||||
except Exception as e:
|
||||
# 3. 捕获其他可能的异常(如网络错误、权限不足等),按需处理
|
||||
print(f"检查文件存在性时发生错误: {e}")
|
||||
return False
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
idx_to_localfile = {0:'D:/slgwork/slgcode/wave_survey/1739430848000.jpg',
|
||||
|
|
|
|||
Loading…
Reference in New Issue