fix: 修复连接器ID显示名称和特来电数据显示问题
Coze-Commit-Type: user Coze-User-ID: 3722323274763196 Coze-Conversation-ID: 9894087
This commit is contained in:
BIN
assets/image_20260713131717942.png
Normal file
BIN
assets/image_20260713131717942.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 90 KiB |
@@ -19,7 +19,7 @@ ID_TO_NAME_MAPPING = {
|
|||||||
'user_id': ('t_user', 'id', 'user_name'),
|
'user_id': ('t_user', 'id', 'user_name'),
|
||||||
'company_id': ('t_company', 'id', 'company_name'),
|
'company_id': ('t_company', 'id', 'company_name'),
|
||||||
'station_id': ('t_station', 'id', 'station_name'),
|
'station_id': ('t_station', 'id', 'station_name'),
|
||||||
'equipment_id': ('t_equipment', 'id', 'equipment_name'),
|
'equipment_id': ('t_connector', 'id', 'connector_name'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -45,6 +45,13 @@ TELECOM_FIELD_MAPPING = {
|
|||||||
'vehicle_self_no': 'company_name', # 车量自编号 → 企业名称
|
'vehicle_self_no': 'company_name', # 车量自编号 → 企业名称
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 特来电数据中名称字段到ID字段的映射(用于匹配selected_fields中的ID字段)
|
||||||
|
TELECOM_NAME_TO_ID_FIELDS = {
|
||||||
|
'company_name': 'company_id',
|
||||||
|
'station_name': 'station_id',
|
||||||
|
'equipment_name': 'equipment_id',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def query_telecom_orders(vehicle_self_nos, start_time_str, end_time_str):
|
def query_telecom_orders(vehicle_self_nos, start_time_str, end_time_str):
|
||||||
"""
|
"""
|
||||||
@@ -106,6 +113,14 @@ def query_telecom_orders(vehicle_self_nos, start_time_str, end_time_str):
|
|||||||
for telecom_field, report_field in TELECOM_FIELD_MAPPING.items():
|
for telecom_field, report_field in TELECOM_FIELD_MAPPING.items():
|
||||||
if telecom_field in row:
|
if telecom_field in row:
|
||||||
converted[report_field] = row[telecom_field]
|
converted[report_field] = row[telecom_field]
|
||||||
|
|
||||||
|
# 将名称字段复制到对应的ID字段,以便ID转名称逻辑能正确处理
|
||||||
|
# 例如:company_name → company_id(值相同),这样 build_id_to_name_map 会查询 t_company 表
|
||||||
|
# 但由于值是名称而不是ID,查询会失败,所以我们需要特殊处理
|
||||||
|
for name_field, id_field in TELECOM_NAME_TO_ID_FIELDS.items():
|
||||||
|
if name_field in converted:
|
||||||
|
converted[id_field] = converted[name_field]
|
||||||
|
|
||||||
# 添加数据来源标记
|
# 添加数据来源标记
|
||||||
converted['data_source'] = '特来电'
|
converted['data_source'] = '特来电'
|
||||||
converted_orders.append(converted)
|
converted_orders.append(converted)
|
||||||
@@ -134,11 +149,24 @@ def build_id_to_name_map(orders, selected_fields):
|
|||||||
|
|
||||||
# 收集所有需要查询的ID值
|
# 收集所有需要查询的ID值
|
||||||
id_values = set()
|
id_values = set()
|
||||||
|
telecom_name_values = {} # 特来电数据中的名称值(直接使用)
|
||||||
|
|
||||||
for order in orders:
|
for order in orders:
|
||||||
val = order.get(field)
|
val = order.get(field)
|
||||||
if val is not None and val != '' and val != 0:
|
if val is not None and val != '' and val != 0:
|
||||||
|
# 检查是否是特来电订单
|
||||||
|
if order.get('data_source') == '特来电' and field in TELECOM_NAME_TO_ID_FIELDS.values():
|
||||||
|
# 特来电数据中的ID字段实际是名称,直接使用
|
||||||
|
telecom_name_values[str(val)] = str(val)
|
||||||
|
else:
|
||||||
id_values.add(str(val))
|
id_values.add(str(val))
|
||||||
|
|
||||||
|
# 合并特来电的名称映射
|
||||||
|
if telecom_name_values:
|
||||||
|
id_name_maps[field] = telecom_name_values
|
||||||
|
print(f"[ID转换] {field}: 特来电数据直接使用名称 {len(telecom_name_values)} 个")
|
||||||
|
|
||||||
|
# 查询驿来特数据的ID映射
|
||||||
if not id_values:
|
if not id_values:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -148,10 +176,13 @@ def build_id_to_name_map(orders, selected_fields):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
results = execute_query(sql, tuple(id_values))
|
results = execute_query(sql, tuple(id_values))
|
||||||
id_name_maps[field] = {str(row['id_val']): row['name_val'] for row in results}
|
if field not in id_name_maps:
|
||||||
|
id_name_maps[field] = {}
|
||||||
|
id_name_maps[field].update({str(row['id_val']): row['name_val'] for row in results})
|
||||||
print(f"[ID转换] {field}: 查询到 {len(results)} 个名称映射")
|
print(f"[ID转换] {field}: 查询到 {len(results)} 个名称映射")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[ID转换] {field} 查询失败: {e}")
|
print(f"[ID转换] {field} 查询失败: {e}")
|
||||||
|
if field not in id_name_maps:
|
||||||
id_name_maps[field] = {}
|
id_name_maps[field] = {}
|
||||||
|
|
||||||
return id_name_maps
|
return id_name_maps
|
||||||
|
|||||||
Reference in New Issue
Block a user