fix: 修复分时段电量字段导致的SQL查询错误
Coze-Commit-Type: user Coze-User-ID: 3722323274763196 Coze-Conversation-ID: 9894087
This commit is contained in:
BIN
assets/image_20260710150426596.png
Normal file
BIN
assets/image_20260710150426596.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 32 KiB |
@@ -205,8 +205,16 @@ def generate_daily_report(config_id, start_time=None, end_time=None):
|
|||||||
print(f" 时间范围: {start_time_str} 至 {end_time_str}")
|
print(f" 时间范围: {start_time_str} 至 {end_time_str}")
|
||||||
print(f" 选择字段: {len(selected_fields)} 个")
|
print(f" 选择字段: {len(selected_fields)} 个")
|
||||||
|
|
||||||
# 构建查询SQL
|
# 构建查询SQL - 过滤掉虚拟字段(时段电量等)
|
||||||
fields_str = ', '.join(selected_fields)
|
# 虚拟字段不是数据库表中的实际字段,需要动态计算
|
||||||
|
TIME_PERIOD_FIELDS = {'sharp_electricity', 'peak_electricity', 'flat_electricity', 'valley_electricity'}
|
||||||
|
db_fields = [f for f in selected_fields if f not in TIME_PERIOD_FIELDS]
|
||||||
|
|
||||||
|
# 确保至少有 order_no 字段用于关联分时数据
|
||||||
|
if 'order_no' not in db_fields:
|
||||||
|
db_fields.append('order_no')
|
||||||
|
|
||||||
|
fields_str = ', '.join(db_fields)
|
||||||
|
|
||||||
# 检查是否为多选值(逗号分隔)
|
# 检查是否为多选值(逗号分隔)
|
||||||
split_values = [v.strip() for v in config['split_value'].split(',') if v.strip()]
|
split_values = [v.strip() for v in config['split_value'].split(',') if v.strip()]
|
||||||
|
|||||||
Reference in New Issue
Block a user