refactor(oa): 将审批决策中的「驳回」统一替换为「校验不通过未处理」
1. 统一所有模块的决策状态命名,替换原「驳回」为「校验不通过未处理」 2. 调整配置注释、文档说明、报告输出文案与推送文本 3. 新增请假附件OCR详情识别函数,支持多附件校验与命中关键词记录 4. 优化多附件下载逻辑,支持逗号分隔fileId与避免文件覆盖 5. 调整请假校验逻辑,适配小时假日期区间获取与多附件处理 6. 更新测试用例与审批提交逻辑,适配新的决策状态
This commit is contained in:
@@ -40,10 +40,9 @@ logger = get_logger(__name__)
|
||||
|
||||
|
||||
# ==================== 真实审批提交(默认关闭) ====================
|
||||
# 审批按钮:通过->同意(#chooseSubmit),驳回->退回申请人(#backApplySubmit)
|
||||
# 仅自动提交"同意"(校验通过):驳回/校验不通过未处理一律不自动提交,保留待人工处理
|
||||
_APPROVE_BUTTONS = {
|
||||
"通过": ("#chooseSubmit", "同意"),
|
||||
"驳回": ("#backApplySubmit", "退回申请人"),
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +86,7 @@ def submit_approval(browser, decision: str) -> Dict[str, str]:
|
||||
|
||||
Args:
|
||||
browser: 停留在详情页的 ChromiumPage
|
||||
decision: 校验决策(通过/驳回;其余决策不提交)
|
||||
decision: 校验决策(通过/校验不通过未处理;其余决策不提交)
|
||||
|
||||
Returns:
|
||||
{"action": "同意"/"退回申请人"/"-", "ok": "true"/"false", "message": ...}
|
||||
@@ -103,21 +102,31 @@ def submit_approval(browser, decision: str) -> Dict[str, str]:
|
||||
return {"action": label, "ok": "false", "message": msg}
|
||||
logger.info("点击审批按钮: %s(%s)", selector, label)
|
||||
btn.click()
|
||||
# 点击同意/退回后,弹出的弹窗结构不固定,需兼容两类"确定"按钮:
|
||||
# 1) #custom-confirm-modal-ok(普通确认框);
|
||||
# 2) tag:button@@class:btn-primary@@onclick:confirmSelect(选择人员弹窗,如加班
|
||||
# "选择中心负责人",人员由系统自动选中,确定按钮 onclick=confirmSelect()
|
||||
# 为弹窗独有,用多属性与匹配(@@)+包含匹配(:)精确咬住,避免误点页面其它
|
||||
# modal-footer 里的同类确定按钮)
|
||||
# 确认框由点击审批按钮后动态生成(modal 渐入动画),轮询等待其出现。
|
||||
# 确认按钮为唯一 id,主文档直接用 ele() 高频等待其动态出现,避免 _find_button 的 iframe 遍历开销
|
||||
# 普通流程确认框 #custom-confirm-modal-ok 为主;选人弹窗 .wf-select-people 为特殊单据才触发
|
||||
def _visible(el):
|
||||
try:
|
||||
return el.states.is_displayed
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
confirm = None
|
||||
for _ in range(10):
|
||||
confirm = _find_button(browser, "#custom-confirm-modal-ok", timeout=1)
|
||||
if confirm is None:
|
||||
confirm = _find_button(browser, "tag:button@@class:btn-primary@@onclick:confirmSelect", timeout=1)
|
||||
if confirm:
|
||||
for _ in range(20):
|
||||
c1 = browser.ele("#custom-confirm-modal-ok", timeout=0.2)
|
||||
if c1 is not None and _visible(c1):
|
||||
confirm = c1
|
||||
break
|
||||
time.sleep(0.5)
|
||||
# 选人弹窗(容器常驻但默认隐藏,仅弹出时才可见)兜底
|
||||
people = browser.ele(".wf-select-people", timeout=0.2)
|
||||
if people is not None and _visible(people):
|
||||
try:
|
||||
c2 = people.ele("css:.modal-footer button.btn.btn-primary", timeout=0.2)
|
||||
except Exception:
|
||||
c2 = None
|
||||
if c2 is not None and _visible(c2):
|
||||
confirm = c2
|
||||
break
|
||||
time.sleep(0.2)
|
||||
if confirm is None:
|
||||
msg = "未找到确认框确定按钮(#custom-confirm-modal-ok 或 .modal-footer .btn.btn-primary),审批未提交"
|
||||
logger.error(msg)
|
||||
@@ -240,7 +249,7 @@ def run_flow(
|
||||
orig_decision = result.get("decision")
|
||||
submit = submit_approval(browser, orig_decision)
|
||||
result["审批动作"] = submit["action"]
|
||||
# 提交失败兜底:单据在 OA 中状态未变,不能仍标为通过/驳回,
|
||||
# 提交失败兜底:单据在 OA 中状态未变,不能仍标为通过/校验不通过未处理,
|
||||
# 归为「异常」并附机器结论,交由人工跟进
|
||||
if submit["ok"] == "false":
|
||||
result["decision"] = "异常"
|
||||
|
||||
@@ -60,7 +60,7 @@ FLEX_TRIGGER_TIME = "23:00"
|
||||
FLEX_LATE_LUNCH_TRIGGER_TIME = "13:00"
|
||||
# 次日弹性上班扣减时扣除的中午休息时长(小时)
|
||||
LUNCH_BREAK_HOURS = 1
|
||||
# 延时加班有效时长门槛:不足该小时数直接驳回
|
||||
# 延时加班有效时长门槛:不足该小时数直接校验不通过未处理
|
||||
OT_MIN_HOURS = 1
|
||||
# 跨天打卡判定:次日首条打卡时间早于该时刻(6点),视为归属加班当天的跨天有效打卡
|
||||
CROSS_DAY_BEFORE_HOUR = 6
|
||||
|
||||
@@ -68,7 +68,7 @@ def build_push_summary(results: list, subject: str = "") -> str:
|
||||
"""
|
||||
根据校验结果生成钉钉推送的文字消息(多行)。
|
||||
|
||||
通过/驳回/人工复核/超期四组均以文字说明推送(不再只发表格):
|
||||
通过/校验不通过未处理/人工复核/超期四组均以文字说明推送(不再只发表格):
|
||||
- 全部通过:用简洁格式
|
||||
【{subject}审批】本次审批 N 条{subject}申请,
|
||||
分别是:
|
||||
@@ -99,7 +99,7 @@ def build_push_summary(results: list, subject: str = "") -> str:
|
||||
return ""
|
||||
|
||||
passed = [r for r in results if r.get("decision") == "通过"]
|
||||
rejected = [r for r in results if r.get("decision") == "驳回"]
|
||||
rejected = [r for r in results if r.get("decision") == "校验不通过未处理"]
|
||||
review = [r for r in results if r.get("decision") == "人工复核"]
|
||||
overdue = [r for r in results if r.get("decision") == "超期"]
|
||||
abnormal = [r for r in results if r.get("decision") == "异常"]
|
||||
|
||||
@@ -132,20 +132,43 @@ def download_attachment(
|
||||
save_dir: str = ATTACHMENT_SAVE_DIR,
|
||||
) -> Optional[str]:
|
||||
"""
|
||||
根据附件 fileId 从 OA 下载请假单据附件。
|
||||
根据附件 fileId 从 OA 下载请假单据附件,支持多附件(逗号分隔多个 fileId)。
|
||||
|
||||
Args:
|
||||
session: 已登录的 SessionPage 对象(已带登录 Cookie)
|
||||
file_id: 附件 fileId(表单 result.file 字段值,即下载链接里的 fileId)
|
||||
file_id: 附件 fileId 或逗号分隔的多个 fileId(表单 result.file 字段值)
|
||||
save_dir: 保存目录(默认 downloads)
|
||||
|
||||
Returns:
|
||||
保存的完整文件路径;失败返回 None
|
||||
成功保存的文件路径;多附件或下载失败时返回逗号拼接的相对路径列表
|
||||
(保持与历史单附件行为一致:单个成功仍返回单个路径字符串)。
|
||||
"""
|
||||
if not file_id:
|
||||
logger.warning("附件 fileId 为空,跳过下载")
|
||||
return None
|
||||
|
||||
# 兼容多附件:file 字段可能为逗号分隔的多个 fileId,逐个下载
|
||||
ids = [x.strip() for x in str(file_id).split(",") if x.strip()]
|
||||
saved = []
|
||||
for fid in ids:
|
||||
path = _download_one(session, fid, save_dir)
|
||||
if path:
|
||||
saved.append(path)
|
||||
if not saved:
|
||||
return None
|
||||
return ",".join(saved)
|
||||
|
||||
|
||||
def _download_one(
|
||||
session: SessionPage,
|
||||
file_id: str,
|
||||
save_dir: str,
|
||||
) -> Optional[str]:
|
||||
"""
|
||||
下载单个附件 fileId,返回本地保存路径;失败返回 None。
|
||||
"""
|
||||
if not file_id:
|
||||
return None
|
||||
os.makedirs(save_dir, exist_ok=True)
|
||||
url = f"{FILE_DOWNLOAD_URL}?fileId={file_id}"
|
||||
logger.info("下载附件: fileId=%s", file_id)
|
||||
@@ -186,6 +209,12 @@ def download_attachment(
|
||||
# 清理非法字符,防止路径注入
|
||||
filename = "".join(c for c in filename if c not in '\\/:*?"<>|')
|
||||
path = os.path.join(save_dir, filename)
|
||||
# 多附件可能出现同名文件导致覆盖:追加 fileId 短后缀区分
|
||||
counter = 1
|
||||
base, ext = os.path.splitext(filename)
|
||||
while os.path.exists(path):
|
||||
path = os.path.join(save_dir, f"{base}_{file_id[:8]}_{counter}{ext}")
|
||||
counter += 1
|
||||
with open(path, "wb") as f:
|
||||
f.write(resp.content)
|
||||
logger.info("附件已下载: %s", path)
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
@Author: 小布丁
|
||||
@CreateTime: 2026-08-05 17:11
|
||||
@Description: 请假流程报告模块。
|
||||
校验结果分三组:通过 / 驳回 / 人工复核。
|
||||
校验结果分三组:通过 / 校验不通过未处理 / 人工复核。
|
||||
输出两份清单:
|
||||
《请假审批校验不通过未处理人员明细清单》:员工姓名、假期类型、校验不通过原因、详情页链接
|
||||
《附件人工复核待办清单》:员工姓名、假期类型、详情页链接(供人工打开查看附件)
|
||||
@@ -52,16 +52,16 @@ def _format_detail(info: Dict[str, Any]) -> str:
|
||||
|
||||
def generate_report(results: List[Dict[str, Any]]) -> str:
|
||||
"""
|
||||
生成请假审批报告:汇总行 + 每条明细 + 驳回清单 + 人工复核清单(+处理失败)。
|
||||
生成请假审批报告:汇总行 + 每条明细 + 校验不通过未处理清单 + 人工复核清单(+处理失败)。
|
||||
|
||||
Args:
|
||||
results: validate_doc 返回的校验结果列表,decision ∈ {通过/驳回/人工复核/失败}
|
||||
results: validate_doc 返回的校验结果列表,decision ∈ {通过/校验不通过未处理/人工复核/失败}
|
||||
|
||||
Returns:
|
||||
报告文本
|
||||
"""
|
||||
passed = [r for r in results if r.get("decision") == "通过"]
|
||||
rejected = [r for r in results if r.get("decision") == "驳回"]
|
||||
rejected = [r for r in results if r.get("decision") == "校验不通过未处理"]
|
||||
review = [r for r in results if r.get("decision") == "人工复核"]
|
||||
abnormal = [r for r in results if r.get("decision") == "异常"]
|
||||
failed = [r for r in results if r.get("decision") == "失败"]
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
@FileName: validator.py
|
||||
@Author: 小布丁
|
||||
@CreateTime: 2026-08-05 17:11
|
||||
@Description: 请假流程校验模块(审批决策三态:通过 / 驳回 / 人工复核)
|
||||
@Description: 请假流程校验模块(审批决策三态:通过 / 校验不通过未处理 / 人工复核)
|
||||
1. 根据假期类型分支处理:
|
||||
- 小时特假:请假当天是排班上班日即通过,否则驳回
|
||||
- 事假/调休假/半天休/普通事假等:排班上班天数与填报天数一致 -> 通过,否则驳回
|
||||
- 小时特假:请假当天是排班上班日即通过,否则校验不通过未处理
|
||||
- 事假/调休假/半天休/普通事假等:排班上班天数与填报天数一致 -> 通过,否则校验不通过未处理
|
||||
- 病假/特别福利假/特殊事假/产假:天数一致 + 已上传附件 -> 人工复核(附件内容需人工核验);
|
||||
天数不一致或缺附件 -> 驳回
|
||||
天数不一致或缺附件 -> 校验不通过未处理
|
||||
2. 排班数据获取:调用排班接口(rf_p_kq_count_SelectBanci,按工号+日期范围,含未来日期排班),
|
||||
统计请假区间内非"休息"天数
|
||||
@Version: 4.2.0
|
||||
@@ -25,7 +25,11 @@ from app.service.hrbp.oa.common.oa_api import download_attachment
|
||||
from app.service.hrbp.common.hr_session import build_hr_session, HRSessionExpiredError
|
||||
from app.service.hrbp.ehr.common.hr_api.attendance import fetch_cur_user_info
|
||||
from app.service.hrbp.ehr.common.hr_api.shift import fetch_all_shift
|
||||
from app.utils.ocr import check_leave_attachment, marriage_within_one_year
|
||||
from app.utils.ocr import (
|
||||
check_leave_attachment,
|
||||
check_leave_attachment_detail,
|
||||
marriage_within_one_year,
|
||||
)
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
@@ -138,30 +142,57 @@ def _verify_attachment(session: Any, vacation_type: str, reason: str, file_id: s
|
||||
if not path:
|
||||
return "人工复核", "附件下载失败,需人工核验", None
|
||||
|
||||
# 多附件支持:download_attachment 对逗号分隔的多个 fileId 返回逗号拼接的路径串,
|
||||
# 拆分后逐个做内容校验,任一命中即通过
|
||||
paths = [p for p in path.split(",") if p]
|
||||
if not paths:
|
||||
return "人工复核", "附件下载失败,需人工核验", None
|
||||
|
||||
def _first_hit(checker):
|
||||
return next((p for p in paths if checker(p)), None)
|
||||
|
||||
def _kw_hint(p, leave_type):
|
||||
"""返回该附件 OCR 命中的关键词列表(逗号拼接),用于备注便于人工判断。"""
|
||||
_, hits, _ = check_leave_attachment_detail(p, leave_type)
|
||||
return "、".join(hits) if hits else ""
|
||||
|
||||
if vacation_type == "病假":
|
||||
if check_leave_attachment(path, "sick"):
|
||||
return "通过", "附件OCR检测通过(病假)", path
|
||||
return "人工复核", "附件OCR未命中病假关键词,需人工核验", path
|
||||
hit = _first_hit(lambda p: check_leave_attachment(p, "sick"))
|
||||
if hit:
|
||||
kw_desc = f"(命中关键词: {_kw_hint(hit, 'sick')})" if _kw_hint(hit, "sick") else ""
|
||||
return "通过", f"附件OCR检测通过(病假,共{len(paths)}份){kw_desc if kw_desc else ''}", path
|
||||
return "人工复核", f"共{len(paths)}份附件OCR均未命中病假关键词,需人工核验", path
|
||||
|
||||
if vacation_type == "特别福利假":
|
||||
reason = reason or ""
|
||||
if "婚" in reason:
|
||||
if not check_leave_attachment(path, "marriage"):
|
||||
return "人工复核", "附件OCR未命中结婚证关键词,需人工核验", path
|
||||
ok, reg_date = marriage_within_one_year(path)
|
||||
hit = None
|
||||
reg_kw = ""
|
||||
for p in paths:
|
||||
ok, _, hits = check_leave_attachment_detail(p, "marriage")
|
||||
if ok:
|
||||
hit = p
|
||||
reg_kw = "、".join(hits)
|
||||
break
|
||||
if hit is None:
|
||||
return "人工复核", f"共{len(paths)}份附件OCR均未命中结婚证关键词,需人工核验", path
|
||||
ok, reg_date = marriage_within_one_year(hit)
|
||||
kw_desc = f"(命中关键词: {reg_kw})" if reg_kw else ""
|
||||
if ok:
|
||||
return "通过", f"结婚证OCR检测通过(登记日期{reg_date}在1年内)", path
|
||||
return "人工复核", f"结婚登记日期{reg_date if reg_date else '未识别'}不在1年内,需人工核验", path
|
||||
return "通过", f"结婚证OCR检测通过,登记日期{reg_date}在1年内{kw_desc}", path
|
||||
return "人工复核", f"结婚登记日期{reg_date if reg_date else '未识别'}不在1年内{kw_desc},需人工核验", path
|
||||
if "产" in reason or "孕" in reason:
|
||||
if check_leave_attachment(path, "maternity"):
|
||||
return "通过", "产检附件OCR检测通过", path
|
||||
return "人工复核", "附件OCR未命中产检关键词,需人工核验", path
|
||||
hit = _first_hit(lambda p: check_leave_attachment(p, "maternity"))
|
||||
if hit:
|
||||
kw_desc = f"(命中关键词: {_kw_hint(hit, 'maternity')})" if _kw_hint(hit, "maternity") else ""
|
||||
return "通过", f"产检附件OCR检测通过(共{len(paths)}份){kw_desc if kw_desc else ''}", path
|
||||
return "人工复核", f"共{len(paths)}份附件OCR均未命中产检关键词,需人工核验", path
|
||||
if "丧" in reason:
|
||||
return "通过", "丧假附件已上传", path
|
||||
return "通过", f"丧假附件已上传({len(paths)}份)", path
|
||||
return "人工复核", f"特别福利假具体类型无法识别(理由: {reason}),需人工核验", path
|
||||
|
||||
# 特殊事假 / 产假:有附件即通过
|
||||
return "通过", "附件已上传", path
|
||||
return "通过", f"附件已上传({len(paths)}份)", path
|
||||
|
||||
|
||||
def validate_doc(doc: Dict[str, Any], session: Any) -> Dict[str, Any]:
|
||||
@@ -172,9 +203,9 @@ def validate_doc(doc: Dict[str, Any], session: Any) -> Dict[str, Any]:
|
||||
1. 解析表单数据,提取假期类型、请假天数、附件等信息
|
||||
2. 调用排班接口,计算请假区间内实际上班天数
|
||||
3. 根据假期类型分支处理:
|
||||
- 小时特假:请假当天为排班上班日 -> 通过,否则驳回
|
||||
- Group 1(事假/调休假等):排班上班天数与填报天数一致 -> 通过,否则驳回
|
||||
- Group 2(病假/产假等):天数一致且已上传附件 -> 人工复核;否则驳回
|
||||
- 小时特假:请假当天为排班上班日 -> 通过,否则校验不通过未处理
|
||||
- Group 1(事假/调休假等):排班上班天数与填报天数一致 -> 通过,否则校验不通过未处理
|
||||
- Group 2(病假/产假等):天数一致且已上传附件 -> 人工复核;否则校验不通过未处理
|
||||
|
||||
Args:
|
||||
doc: 单据信息,含基本信息(title/creator/time/detail_url)
|
||||
@@ -191,11 +222,16 @@ def validate_doc(doc: Dict[str, Any], session: Any) -> Dict[str, Any]:
|
||||
staff_id = leave_info.get("请假人员ID")
|
||||
staff_code = leave_info.get("工号")
|
||||
vacation_type = leave_info.get("假期类型")
|
||||
# 日期区间以 begin_date/end_date(开始日期/结束日期)为准,缺失时回退起止时间
|
||||
begin_date = leave_info.get("开始日期") or leave_info.get("开始时间")
|
||||
end_date = leave_info.get("结束日期") or leave_info.get("结束时间")
|
||||
# 日期区间:其他假期一律用 begin_date/end_date(start_time/end_time 可能跨天,
|
||||
# 不可用于取日期);仅小时特假为按小时请假,用 start_time/end_time 取当日排班
|
||||
begin_date = leave_info.get("开始日期")
|
||||
end_date = leave_info.get("结束日期")
|
||||
leave_days = leave_info.get("请假天数")
|
||||
attachment = leave_info.get("附件")
|
||||
is_hourly = vacation_type in HOURLY_LEAVE_TYPES
|
||||
if is_hourly:
|
||||
begin_date = leave_info.get("开始时间")
|
||||
end_date = leave_info.get("结束时间")
|
||||
|
||||
result: Dict[str, Any] = {
|
||||
"title": doc.get("title", ""),
|
||||
@@ -209,24 +245,24 @@ def validate_doc(doc: Dict[str, Any], session: Any) -> Dict[str, Any]:
|
||||
|
||||
# 缺失必要信息
|
||||
if not vacation_type:
|
||||
result["decision"] = "驳回"
|
||||
result["decision"] = "校验不通过未处理"
|
||||
result["note"] = "无法识别假期类型"
|
||||
return result
|
||||
|
||||
if not staff_id:
|
||||
result["decision"] = "驳回"
|
||||
result["decision"] = "校验不通过未处理"
|
||||
result["note"] = "请假人员ID缺失"
|
||||
return result
|
||||
|
||||
if not staff_code:
|
||||
result["decision"] = "驳回"
|
||||
result["decision"] = "校验不通过未处理"
|
||||
result["note"] = "请假人工号缺失"
|
||||
return result
|
||||
|
||||
# 获取日期范围
|
||||
start_date, end_date = _get_date_range(begin_date, end_date)
|
||||
if not start_date or not end_date:
|
||||
result["decision"] = "驳回"
|
||||
result["decision"] = "校验不通过未处理"
|
||||
result["note"] = "请假起止日期缺失"
|
||||
return result
|
||||
|
||||
@@ -235,7 +271,7 @@ def validate_doc(doc: Dict[str, Any], session: Any) -> Dict[str, Any]:
|
||||
actual_work_days = _get_work_days_count(staff_code, start_date, end_date)
|
||||
except Exception as e:
|
||||
logger.warning("计算上班天数失败: %s", str(e))
|
||||
result["decision"] = "驳回"
|
||||
result["decision"] = "校验不通过未处理"
|
||||
result["note"] = f"获取排班数据失败: {e}"
|
||||
return result
|
||||
|
||||
@@ -258,10 +294,10 @@ def validate_doc(doc: Dict[str, Any], session: Any) -> Dict[str, Any]:
|
||||
# 按小时请假(如小时特假):当天为上班日 + 已上传附件才通过
|
||||
leave_hours = leave_info.get("请假小时")
|
||||
if actual_work_days < 1:
|
||||
result["decision"] = "驳回"
|
||||
result["decision"] = "校验不通过未处理"
|
||||
result["note"] = f"请假当天非排班上班日(实际上班天数: {actual_work_days})"
|
||||
elif not attachment:
|
||||
result["decision"] = "驳回"
|
||||
result["decision"] = "校验不通过未处理"
|
||||
result["note"] = "未上传附件"
|
||||
else:
|
||||
result["decision"] = "通过"
|
||||
@@ -274,7 +310,7 @@ def validate_doc(doc: Dict[str, Any], session: Any) -> Dict[str, Any]:
|
||||
elif vacation_type in LEAVE_TYPE_GROUP_1:
|
||||
# Group 1:仅校验天数一致
|
||||
if days_mismatch:
|
||||
result["decision"] = "驳回"
|
||||
result["decision"] = "校验不通过未处理"
|
||||
result["note"] = (
|
||||
f"排班上班天数({actual_work_days}天)与填报天数({fill_days}天)不一致"
|
||||
)
|
||||
@@ -287,7 +323,7 @@ def validate_doc(doc: Dict[str, Any], session: Any) -> Dict[str, Any]:
|
||||
|
||||
elif vacation_type in LEAVE_TYPE_GROUP_2:
|
||||
# Group 2:需附件的假期(病假/特别福利假/特殊事假/产假)
|
||||
# - 天数不一致或缺附件 -> 驳回
|
||||
# - 天数不一致或缺附件 -> 校验不通过未处理
|
||||
# - 附件通过内容校验(OCR/仅附件)-> 通过;OCR 无法确认 -> 人工复核
|
||||
reasons = []
|
||||
if days_mismatch:
|
||||
@@ -298,7 +334,7 @@ def validate_doc(doc: Dict[str, Any], session: Any) -> Dict[str, Any]:
|
||||
reasons.append("未上传附件")
|
||||
|
||||
if reasons:
|
||||
result["decision"] = "驳回"
|
||||
result["decision"] = "校验不通过未处理"
|
||||
result["note"] = ";".join(reasons)
|
||||
else:
|
||||
result["decision"], result["note"], result["附件路径"] = _verify_attachment(
|
||||
@@ -306,7 +342,7 @@ def validate_doc(doc: Dict[str, Any], session: Any) -> Dict[str, Any]:
|
||||
)
|
||||
else:
|
||||
# 未识别的假期类型
|
||||
result["decision"] = "驳回"
|
||||
result["decision"] = "校验不通过未处理"
|
||||
result["note"] = f"无法识别的假期类型: {vacation_type}"
|
||||
|
||||
return result
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
@Author: 小布丁
|
||||
@CreateTime: 2026-08-05 21:35
|
||||
@Description: 加班流程报告模块。
|
||||
校验结果分四组:通过 / 驳回 / 人工复核 / 超期。
|
||||
校验结果分四组:通过 / 校验不通过未处理 / 人工复核 / 超期。
|
||||
输出三份清单:
|
||||
《加班审批校验不通过未处理人员明细清单》:员工姓名、加班类型、校验不通过原因、详情页链接
|
||||
《附件人工复核待办清单》:员工姓名、加班类型、详情页链接(供人工打开查看附件)
|
||||
@@ -68,16 +68,16 @@ def _format_detail(info: Dict[str, Any]) -> str:
|
||||
|
||||
def generate_report(results: List[Dict[str, Any]]) -> str:
|
||||
"""
|
||||
生成加班审批报告:汇总行 + 每条明细 + 驳回清单 + 人工复核清单(+处理失败)。
|
||||
生成加班审批报告:汇总行 + 每条明细 + 校验不通过未处理清单 + 人工复核清单(+处理失败)。
|
||||
|
||||
Args:
|
||||
results: validate_doc 返回的校验结果列表,decision ∈ {通过/驳回/人工复核/失败}
|
||||
results: validate_doc 返回的校验结果列表,decision ∈ {通过/校验不通过未处理/人工复核/失败}
|
||||
|
||||
Returns:
|
||||
报告文本
|
||||
"""
|
||||
passed = [r for r in results if r.get("decision") == "通过"]
|
||||
rejected = [r for r in results if r.get("decision") == "驳回"]
|
||||
rejected = [r for r in results if r.get("decision") == "校验不通过未处理"]
|
||||
review = [r for r in results if r.get("decision") == "人工复核"]
|
||||
overdue = [r for r in results if r.get("decision") == "超期"]
|
||||
abnormal = [r for r in results if r.get("decision") == "异常"]
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
@FileName: validator.py
|
||||
@Author: 小布丁
|
||||
@CreateTime: 2026-08-05 21:35
|
||||
@Description: 加班流程校验模块(按 aa.md 审批规则:延时加班/休息日加班/法定假日加班,判定通过/驳回/超期)
|
||||
@Description: 加班流程校验模块(按 aa.md 审批规则:延时加班/休息日加班/法定假日加班,判定通过/校验不通过未处理/超期)
|
||||
@Version: 3.2.0
|
||||
"""
|
||||
|
||||
@@ -313,20 +313,20 @@ def _validate_delayed(
|
||||
"""
|
||||
延时加班审批(按 aa.md 规则一):
|
||||
|
||||
(一)驳回门槛:
|
||||
(一)校验不通过未处理门槛:
|
||||
1. 日期匹配:加班开始时间所属日期 = 申请加班日期;
|
||||
2. 时长达标:1小时起算,超1小时按0.5h累加,不足1h驳回;
|
||||
2. 时长达标:1小时起算,超1小时按0.5h累加,不足1h校验不通过未处理;
|
||||
3. 区间合规:开始时间 >= 规定下班时间(以排班结束时间为准,未获取到回退默认 18:00);
|
||||
结束时间晚于实际下班打卡时,按实际打卡区间(申请开始->实际下班打卡)取整后的
|
||||
实际在岗时长 >= 申请时长即通过,不足则驳回。
|
||||
实际在岗时长 >= 申请时长即通过,不足则校验不通过未处理。
|
||||
|
||||
(二)弹性到岗兑换(仅影响结算,校验驳回则驳回):
|
||||
(二)弹性到岗兑换(仅影响结算,校验校验不通过未处理则校验不通过未处理):
|
||||
D 基于实际下班打卡时间计算,>= 23:00 时 D = 1 + floor((打卡-23:00)/0.5)*0.5。
|
||||
次日休息/请假覆盖上班时间/无打卡 -> 不触发兑换。
|
||||
正常工作日按次日打卡 P 校验(次日上班时间 T 优先取排班开始时间,未获取到回退
|
||||
09:00):P<=T 不扣;T<P<=T+D 扣 ceil(晚到时长)(晚到时长 = P-T,次日打卡超过
|
||||
13:00 时再扣 1 小时午餐;1 小时起算向上取整,不足 1 小时不扣);P>T+D 扣 D。
|
||||
兑换校验:加班时长+晚到 <= 实际在岗时长(加班开始->实际下班打卡按取整),不满足则驳回。
|
||||
兑换校验:加班时长+晚到 <= 实际在岗时长(加班开始->实际下班打卡按取整),不满足则校验不通过未处理。
|
||||
"""
|
||||
ot_date = info.get("加班日期")
|
||||
start = _parse_dt(info.get("加班开始时间"))
|
||||
@@ -336,7 +336,7 @@ def _validate_delayed(
|
||||
# 申请结束时间晚于实际下班打卡、但实际在岗时长(按系统取整)仍满足申请时长时,用于附加到通过备注
|
||||
end_checkout_note = ""
|
||||
|
||||
# 1. 日期校验:加班开始日期与申请加班日期不一致时直接驳回,
|
||||
# 1. 日期校验:加班开始日期与申请加班日期不一致时直接校验不通过未处理,
|
||||
# 无需再校验后续的时长、区间合规等内容
|
||||
if start is None:
|
||||
reasons.append("加班开始时间缺失")
|
||||
@@ -345,7 +345,7 @@ def _validate_delayed(
|
||||
info["弹性扣减(小时)"] = 0
|
||||
info["有效加班时长(小时)"] = 0
|
||||
info["弹性额度D(小时)"] = 0
|
||||
return "驳回", f"加班开始日期({start:%Y-%m-%d})与申请加班日期({ot_date})不一致"
|
||||
return "校验不通过未处理", f"加班开始日期({start:%Y-%m-%d})与申请加班日期({ot_date})不一致"
|
||||
|
||||
# 2. 时长校验
|
||||
hours = None
|
||||
@@ -411,7 +411,7 @@ def _validate_delayed(
|
||||
info["弹性扣减(小时)"] = 0
|
||||
info["有效加班时长(小时)"] = hours
|
||||
info["弹性额度D(小时)"] = 0
|
||||
return "驳回", ";".join(reasons)
|
||||
return "校验不通过未处理", ";".join(reasons)
|
||||
|
||||
# 4. 弹性到岗兑换(仅影响结算时长)
|
||||
deduction = 0.0
|
||||
@@ -462,8 +462,8 @@ def _validate_delayed(
|
||||
info["弹性扣减(小时)"] = 0
|
||||
info["有效加班时长(小时)"] = hours
|
||||
info["弹性额度D(小时)"] = d_hours
|
||||
return "驳回", (
|
||||
f"弹性兑换校验驳回:申请加班{hours:g}h + 晚到{late_hours}h "
|
||||
return "校验不通过未处理", (
|
||||
f"弹性兑换校验校验不通过未处理:申请加班{hours:g}h + 晚到{late_hours}h "
|
||||
f"> 实际在岗时长{actual_work:g}h"
|
||||
)
|
||||
deduction = float(late_hours)
|
||||
@@ -474,8 +474,8 @@ def _validate_delayed(
|
||||
info["弹性扣减(小时)"] = 0
|
||||
info["有效加班时长(小时)"] = hours
|
||||
info["弹性额度D(小时)"] = d_hours
|
||||
return "驳回", (
|
||||
f"弹性兑换校验驳回:申请加班{hours:g}h + 兑换额度{d_hours:g}h "
|
||||
return "校验不通过未处理", (
|
||||
f"弹性兑换校验校验不通过未处理:申请加班{hours:g}h + 兑换额度{d_hours:g}h "
|
||||
f"> 实际在岗时长{actual_work:g}h"
|
||||
)
|
||||
deduction = float(d_hours)
|
||||
@@ -508,7 +508,7 @@ def _validate_day_ot(
|
||||
require_holiday: bool,
|
||||
) -> tuple:
|
||||
"""
|
||||
休息日/法定假日加班审批(任一条件不满足即驳回):
|
||||
休息日/法定假日加班审批(任一条件不满足即校验不通过未处理):
|
||||
- 排班显示为休息;
|
||||
- 法定假日(仅春节):申请日期必须为春节法定节假日;
|
||||
- 加班时长 > 0;
|
||||
@@ -529,7 +529,7 @@ def _validate_day_ot(
|
||||
reasons.append(f"{ot_date}不在春节法定节假日列表中")
|
||||
|
||||
# 加班时长 > 0:休息日加班按天计,表单 ot_hour 常为 0(aa.md 中 ot_hours=0.0、ot_days=1.00),
|
||||
# 此时用申报起止时间推算实际加班时长,避免误驳回
|
||||
# 此时用申报起止时间推算实际加班时长,避免误校验不通过未处理
|
||||
ot_hour = info.get("加班时长(小时)") or info.get("系统判断加班时长(小时)")
|
||||
try:
|
||||
ot_hour = float(ot_hour)
|
||||
@@ -579,7 +579,7 @@ def _validate_day_ot(
|
||||
info["打卡时间间隔(小时)"] = interval
|
||||
info["申报天数(天)"] = apply_days
|
||||
if reasons:
|
||||
return "驳回", ";".join(reasons)
|
||||
return "校验不通过未处理", ";".join(reasons)
|
||||
return "通过", f"审批通过(申报{apply_days:g}天,打卡间隔{interval:.2f}小时)"
|
||||
|
||||
|
||||
@@ -626,7 +626,7 @@ def check_review_period(ot_date: Optional[str], today: Optional[datetime] = None
|
||||
# ---------- 主入口 ----------
|
||||
def validate_doc(doc: Dict[str, Any], session: Any) -> Dict[str, Any]:
|
||||
"""
|
||||
校验单张加班单据,返回审批决策(通过 / 驳回)。
|
||||
校验单张加班单据,返回审批决策(通过 / 校验不通过未处理)。
|
||||
|
||||
按加班类型分派规则:
|
||||
ot_type=1 延时加班;
|
||||
@@ -679,7 +679,7 @@ def validate_doc(doc: Dict[str, Any], session: Any) -> Dict[str, Any]:
|
||||
overtime_info, punch_info, session, staff_id, require_holiday=require_holiday
|
||||
)
|
||||
else:
|
||||
decision, note = "驳回", f"无法识别加班类型: {ot_type_code}"
|
||||
decision, note = "校验不通过未处理", f"无法识别加班类型: {ot_type_code}"
|
||||
|
||||
return {
|
||||
"title": doc.get("title", ""),
|
||||
|
||||
Reference in New Issue
Block a user