This commit is contained in:
admin
2026-02-01 21:01:19 +09:00
parent a2d7b54cd3
commit cf17eef442
3 changed files with 44 additions and 25 deletions

View File

@@ -7,8 +7,8 @@ class VoucherExportRequest(BaseModel):
"""账票エクスポート要求"""
start_year: int = Field(..., ge=2000, le=2099)
start_month: int = Field(..., ge=1, le=12)
end_year: int = Field(default=None, ge=2000, le=2099)
end_month: int = Field(default=None, ge=1, le=12)
end_year: Optional[int] = Field(default=None)
end_month: Optional[int] = Field(default=None)
employee_ids: List[int] = Field(..., min_items=1)
voucher_type: str = Field(default="all", pattern="^(all|salary|bonus)$")
format: str = Field(default="preview", pattern="^(preview|csv|pdf)$")

View File

@@ -78,6 +78,8 @@ def get_salary_data_for_period(
start_ym = start_year * 100 + start_month
end_ym = end_year * 100 + end_month
logger.info(f"給与検索: employee_id={employee_id}, start_ym={start_ym}, end_ym={end_ym}")
cur.execute("""
SELECT
e.employee_id, e.employee_code, e.name,
@@ -96,6 +98,7 @@ def get_salary_data_for_period(
""", (employee_id, start_ym, end_ym))
rows = cur.fetchall()
logger.info(f"給与データ件数: {len(rows)}")
data = []
for row in rows:
# Handle both dict and tuple formats
@@ -192,6 +195,8 @@ def get_bonus_data_for_period(
start_ym = start_year * 100 + start_month
end_ym = end_year * 100 + end_month
logger.info(f"賞与検索: employee_id={employee_id}, start_ym={start_ym}, end_ym={end_ym}")
cur.execute("""
SELECT
e.employee_id, e.employee_code, e.name,
@@ -209,6 +214,7 @@ def get_bonus_data_for_period(
""", (employee_id, start_ym, end_ym))
rows = cur.fetchall()
logger.info(f"賞与データ件数: {len(rows)}")
data = []
for row in rows:
# Handle both dict and tuple formats
@@ -342,11 +348,18 @@ def build_voucher_summary(
def export_vouchers(request: VoucherExportRequest) -> VoucherExportResponse:
"""账票エクスポート処理(メイン)"""
try:
# リクエストログ
end_label = f"{request.end_year:04d}-{request.end_month:02d}" if request.end_year else "None"
logger.info(f"エクスポート要求: start={request.start_year:04d}-{request.start_month:02d}, "
f"end={end_label}, "
f"type={request.voucher_type}, employees={request.employee_ids}")
# 日付範囲検証
start_year, start_month, end_year, end_month = validate_date_range(
request.start_year, request.start_month,
request.end_year, request.end_month
)
logger.info(f"検証後の日付範囲: {start_year:04d}-{start_month:02d} {end_year:04d}-{end_month:02d}")
# 給与・賞与データ取得
salary_data = {}
@@ -358,6 +371,7 @@ def export_vouchers(request: VoucherExportRequest) -> VoucherExportResponse:
emp_id, start_year, start_month, end_year, end_month
)
salary_data[emp_id] = data
logger.info(f"給与データ (emp_id={emp_id}): {len(data)}")
if request.voucher_type in ["all", "bonus"]:
for emp_id in request.employee_ids:
@@ -365,8 +379,13 @@ def export_vouchers(request: VoucherExportRequest) -> VoucherExportResponse:
emp_id, start_year, start_month, end_year, end_month
)
bonus_data[emp_id] = data
logger.info(f"賞与データ (emp_id={emp_id}): {len(data)}")
# データの存在判定
total_salary = sum(len(v) for v in salary_data.values())
total_bonus = sum(len(v) for v in bonus_data.values())
logger.info(f"合計: 給与={total_salary}件, 賞与={total_bonus}")
has_any_data = any(
salary_data.get(emp_id, []) or bonus_data.get(emp_id, [])
for emp_id in request.employee_ids
@@ -376,7 +395,7 @@ def export_vouchers(request: VoucherExportRequest) -> VoucherExportResponse:
return VoucherExportResponse(
status="no_data",
has_data=False,
message="選定件下、沒有找到任何數據。請檢查日期範圍和従業員選擇"
message="選定件下にデータが見つかりません。日付範囲と従業員選択を確認してください"
)
# 摘要構築
@@ -401,7 +420,7 @@ def export_vouchers(request: VoucherExportRequest) -> VoucherExportResponse:
# メッセージ構築
emp_with_data = len([s for s in summary if s.has_salary_data or s.has_bonus_data])
message = f"✓ 成功查詢: {emp_with_data}従業員有數據"
message = f"検索成功: {emp_with_data}人の従業員がデータを持ちます"
return VoucherExportResponse(
status="success",