增加发布正式版的命令
This commit is contained in:
32
lib/db.py
32
lib/db.py
@@ -1,24 +1,28 @@
|
||||
"""
|
||||
数据库连接配置
|
||||
"""
|
||||
import os
|
||||
import pymysql
|
||||
from contextlib import contextmanager
|
||||
from lib.logger import log_info, log_error, log_warning
|
||||
|
||||
# 数据库配置
|
||||
DB_CONFIG = {
|
||||
'host': 'haoslm2.xicp.net',
|
||||
'port': 10216,
|
||||
'user': 'root',
|
||||
'password': 'DsideaL147258369',
|
||||
'database': 'yltcharge',
|
||||
'charset': 'utf8mb4',
|
||||
'cursorclass': pymysql.cursors.DictCursor,
|
||||
'autocommit': True,
|
||||
'connect_timeout': 30, # 连接超时30秒
|
||||
'read_timeout': 60, # 读取超时60秒
|
||||
'write_timeout': 60 # 写入超时60秒
|
||||
}
|
||||
def get_db_config():
|
||||
"""从环境变量或默认值获取数据库配置"""
|
||||
return {
|
||||
'host': os.environ.get('DB_HOST', 'haoslm2.xicp.net'),
|
||||
'port': int(os.environ.get('DB_PORT', 10216)),
|
||||
'user': os.environ.get('DB_USER', 'root'),
|
||||
'password': os.environ.get('DB_PASSWORD', 'DsideaL147258369'),
|
||||
'database': os.environ.get('DB_NAME', 'yltcharge'),
|
||||
'charset': 'utf8mb4',
|
||||
'cursorclass': pymysql.cursors.DictCursor,
|
||||
'autocommit': True,
|
||||
'connect_timeout': 30,
|
||||
'read_timeout': 60,
|
||||
'write_timeout': 60
|
||||
}
|
||||
|
||||
DB_CONFIG = get_db_config()
|
||||
|
||||
|
||||
@contextmanager
|
||||
|
||||
@@ -869,31 +869,46 @@ def generate_excel(orders, selected_fields, sum_fields, sum_results,
|
||||
charge_degree_col = col_idx
|
||||
break
|
||||
|
||||
# 第一列显示标题
|
||||
# 总列数
|
||||
total_cols = len(selected_fields) + 2
|
||||
if has_custom_service_fee:
|
||||
total_cols += 1
|
||||
|
||||
# 标题文字
|
||||
title_text = f'当月累计充电量(共{total_days}天,截止{report_date})'
|
||||
if missing_dates and len(missing_dates) > 0:
|
||||
# 最多显示5个缺失日期,超过的用"...共N天"表示
|
||||
if len(missing_dates) <= 5:
|
||||
missing_str = '、'.join([d[5:] for d in missing_dates]) # 只显示月-日
|
||||
missing_str = '、'.join([d[5:] for d in missing_dates])
|
||||
else:
|
||||
missing_str = '、'.join([d[5:] for d in missing_dates[:5]]) + f'...共{len(missing_dates)}天'
|
||||
title_text += f'\n(缺:{missing_str})'
|
||||
|
||||
ws.cell(row=monthly_row, column=1).value = title_text
|
||||
ws.cell(row=monthly_row, column=1).font = monthly_font
|
||||
ws.cell(row=monthly_row, column=1).fill = monthly_fill
|
||||
ws.cell(row=monthly_row, column=1).alignment = Alignment(horizontal='center', vertical='center', wrap_text=True)
|
||||
ws.cell(row=monthly_row, column=1).border = thin_border
|
||||
# 标题跨列:从第1列到 charge_degree_col 的前一列
|
||||
# 如果没有找到充电电量列,就跨到倒数第二列
|
||||
title_end_col = charge_degree_col - 1 if charge_degree_col else total_cols - 1
|
||||
if title_end_col < 1:
|
||||
title_end_col = 1
|
||||
|
||||
# 其他列也填充背景色
|
||||
total_cols = len(selected_fields) + 2
|
||||
if has_custom_service_fee:
|
||||
total_cols += 1
|
||||
# 合并标题单元格
|
||||
if title_end_col > 1:
|
||||
ws.merge_cells(start_row=monthly_row, start_column=1,
|
||||
end_row=monthly_row, end_column=title_end_col)
|
||||
|
||||
# 设置标题单元格
|
||||
title_cell = ws.cell(row=monthly_row, column=1)
|
||||
title_cell.value = title_text
|
||||
title_cell.font = monthly_font
|
||||
title_cell.fill = monthly_fill
|
||||
title_cell.alignment = Alignment(horizontal='center', vertical='center', wrap_text=True)
|
||||
title_cell.border = thin_border
|
||||
|
||||
# 其他列填充背景色和边框
|
||||
for col_idx in range(2, total_cols):
|
||||
cell = ws.cell(row=monthly_row, column=col_idx)
|
||||
cell.fill = monthly_fill
|
||||
cell.border = thin_border
|
||||
|
||||
# 数值放在 charge_degree 列
|
||||
if charge_degree_col:
|
||||
cell = ws.cell(row=monthly_row, column=charge_degree_col)
|
||||
cell.value = total_degree
|
||||
@@ -901,11 +916,11 @@ def generate_excel(orders, selected_fields, sum_fields, sum_results,
|
||||
cell.alignment = Alignment(horizontal='right', vertical='center')
|
||||
cell.number_format = '0.000'
|
||||
|
||||
# 如果有缺失日期,行高加大一点
|
||||
# 行高
|
||||
if missing_dates and len(missing_dates) > 0:
|
||||
ws.row_dimensions[monthly_row].height = 40
|
||||
ws.row_dimensions[monthly_row].height = 45
|
||||
else:
|
||||
ws.row_dimensions[monthly_row].height = 25
|
||||
ws.row_dimensions[monthly_row].height = 28
|
||||
except Exception as e:
|
||||
log_error(f"[日报生成] 写入月度总计时出错: {e}", 'report')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user