Files
37duAutomation/plugins/XQ0001-0100/XQ0084 银行卡更新EHR系统/report/workbook.py
T
puddy de7eeee08f feat(plugin): XQ0084 0.1.1 插件界面 + 核对通过自动导入 HR 工资卡并回写台账
- 新增 ui-src(Vue3+Element Plus,v3 规范)与构建产物 ui/,plugin.json 开启 ui
- 接入 hr_sdk.wage_import:核对通过记录按身份证匹配导入工资卡,成功后回写「是否更新HR系统=是」
- 委托发放/缺开户银行记录跳过并注明原因,现金发放仍不导入;导入失败不中断出表与推送
- 工作簿新增 HR导入/说明列,推送正文补充导入统计;_pack 排除 ui-src 并校验 ui/index.html
2026-11-18 11:02:25 +08:00

82 lines
2.9 KiB
Python

# -*- coding: utf-8 -*-
"""XQ0084 输出层:核对结果工作簿。"""
from __future__ import annotations
import os
from openpyxl import Workbook
from openpyxl.styles import Alignment, Font, PatternFill
from openpyxl.utils import get_column_letter
from .. import config
COLUMNS = [
("emp_no", "工号", 11),
("holder", "持卡人姓名", 14),
("reason", "变更原因", 24),
("table_bank", "开户银行(表格)", 18),
("table_card", "银行卡号(表格)", 23),
("table_id", "身份证号(表格)", 23),
("ocr_id", "身份证号(识别)", 23),
("ocr_name", "姓名(识别)", 11),
("ocr_card", "银行卡号(识别)", 23),
("ocr_bank", "开户银行(识别)", 18),
("id_status", "身份证核对", 11),
("name_status", "姓名核对", 11),
("card_status", "卡号核对", 11),
("bank_status", "开户银行核对", 13),
("self_check", "表格自检", 26),
("triggers", "触发原因", 22),
("hr_status", "HR导入", 12),
("hr_note", "HR导入说明", 36),
("conclusion", "核对结论", 22),
("notes", "说明", 60),
("image_count", "影像数", 8),
("image_dir", "影像目录", 50),
]
_HEAD_FILL = PatternFill("solid", fgColor="1F4E78")
_HEAD_FONT = Font(color="FFFFFF", bold=True)
_MANUAL_FILL = PatternFill("solid", fgColor="FFF2CC")
_PASS_FILL = PatternFill("solid", fgColor="E2EFDA")
_CASH_FILL = PatternFill("solid", fgColor="DDEBF7")
def _write_sheet(ws, rows):
ws.append([title for _, title, _ in COLUMNS])
for col, (_, title, width) in enumerate(COLUMNS, start=1):
cell = ws.cell(row=1, column=col)
cell.fill = _HEAD_FILL
cell.font = _HEAD_FONT
cell.alignment = Alignment(horizontal="center", vertical="center")
ws.column_dimensions[get_column_letter(col)].width = width
ws.row_dimensions[1].height = 24
ws.freeze_panes = "A2"
for record in rows:
ws.append([record.get(key, "") for key, _, _ in COLUMNS])
r = ws.max_row
for col in range(1, len(COLUMNS) + 1):
ws.cell(row=r, column=col).alignment = Alignment(vertical="center", wrap_text=True)
conclusion = record.get("conclusion", "")
fill = (_MANUAL_FILL if conclusion == "需人工核实"
else _CASH_FILL if conclusion.startswith("现金发放") else _PASS_FILL)
ws.cell(row=r, column=[k for k, _, _ in COLUMNS].index("conclusion") + 1).fill = fill
ws.auto_filter.ref = f"A1:{get_column_letter(len(COLUMNS))}{max(ws.max_row, 1)}"
def write_workbook(rows, path):
"""写出「核对结果 / 异常名单」两个 sheet。"""
os.makedirs(os.path.dirname(path), exist_ok=True)
wb = Workbook()
ws = wb.active
ws.title = config.SHEET_FULL
_write_sheet(ws, rows)
abnormal = [r for r in rows if r.get("conclusion") == "需人工核实"]
ws2 = wb.create_sheet(config.SHEET_ABNORMAL)
_write_sheet(ws2, abnormal)
wb.save(path)
return path