refactor(workflows): 统一替换 yingdao 目录引用为 workflows

1.  将所有文档、代码中对 `yingdao/` 目录的引用替换为 `workflows/`,统一影刀版代码的命名空间
2.  调整 workflows/share 模块内的路径引用与文档注释,确保一致性
3.  同步更新测试代码与配置文件中的旧目录引用
This commit is contained in:
2026-09-08 16:16:35 +08:00
parent be07de0e92
commit 9d067c0646
74 changed files with 5895 additions and 151 deletions
+279
View File
@@ -0,0 +1,279 @@
# -*- coding: utf-8 -*-
"""考勤月报封存检查 - 规则引擎与五项检查(webhost 场景插件)
与 desktop/plugins/seal_check/logic.py 保持同步(桌面版为单一真源)。
规则完全由运行人员每月在界面录入的天数值驱动:
- 固休:应休 = fixed_rest_days
- 大小休:应休 = size_rest_days(实际允许 size_rest_days ~ 8 天区间)
- 天数限额排休:应休 <= quota_rest_days(上限)
"""
import calendar
from dataclasses import dataclass
from datetime import date, datetime
from typing import Dict, List
from webhost.backend.plugins.seal_check import config
# ==================== 异常名单统一列 ====================
OUTPUT_COLUMNS = [
"37工号", "姓名", "月报检查月份", "异常类型", "所属单位",
"一级部门", "二级部门", "三级部门", "四级部门", "五级部门",
]
TYPE_1 = "当月在职天数有差缺排班"
TYPE_3 = "考勤封存非最新值,请重新封存"
TYPE_4 = "出勤天数大于当月应出勤天数"
TYPE_5 = "考勤月报未封存,请处理"
# ==================== 规则引擎 ====================
@dataclass
class RestRule:
rule_type: str # 大小休 / 固休 / 限额 / 未知
days: int = None # 应休天数(限额为 None)
max_days: int = None # 限额上限
desc: str = "" # 规则描述(异常类型)
def validate(self, rest_days: int) -> bool:
if self.rule_type == "固休":
return rest_days == self.days
if self.rule_type == "大小休":
return self.days <= rest_days <= 8
if self.rule_type == "限额":
return rest_days <= self.max_days
return True
def _normalize_rest_days(v) -> int:
try:
s = str(v).strip()
if s in ("", "nan", "None"):
return -1
if s.endswith(".0"):
s = s[:-2]
return int(float(s))
except (TypeError, ValueError):
return -1
class LeaveRuleEngine:
def __init__(self, size_rest_days=6, fixed_rest_days=5, quota_rest_days=8):
self.size_rest_days = int(size_rest_days)
self.fixed_rest_days = int(fixed_rest_days)
self.quota_rest_days = int(quota_rest_days)
def query(self, unit: str, org_label: str = "", sequence: str = "") -> RestRule:
if "技师" in sequence:
return RestRule("限额", max_days=self.quota_rest_days,
desc=f"当月排休不满足<={self.quota_rest_days}天规则")
if unit == "金色湖畔事业部":
return RestRule("固休", days=self.fixed_rest_days,
desc=f"当月排休不满足={self.fixed_rest_days}天规则")
if unit in config.GROUP_HEADQUARTER_UNITS:
return RestRule("大小休", days=self.size_rest_days,
desc=f"当月排休不满足>={self.size_rest_days}天<=8天规则")
if unit == "金色印象事业部":
if "事业部" in org_label:
return RestRule("大小休", days=self.size_rest_days,
desc=f"当月排休不满足>={self.size_rest_days}天<=8天规则")
return RestRule("固休", days=self.fixed_rest_days,
desc=f"当月排休不满足={self.fixed_rest_days}天规则")
return RestRule("未知")
def check(self, unit, org_label, sequence, rest_days):
rule = self.query(unit, org_label, sequence)
days = _normalize_rest_days(rest_days)
if rule.rule_type == "未知" or days < 0:
return False, rule, days
return (not rule.validate(days)), rule, days
# ==================== 检查工具 ====================
def _clean(v) -> str:
if v is None:
return ""
s = str(v).strip()
if s.lower() in ("nan", "none", "nat"):
return ""
if s.endswith(".0"):
s = s[:-2]
return s
def _to_int(v, default=0) -> int:
s = _clean(v)
if not s:
return default
try:
return int(float(s))
except (TypeError, ValueError):
return default
def _norm_path(p: str) -> str:
p = _clean(p).replace("\\", "/").strip("/")
if p.startswith("集团/"):
p = p[len("集团/"):]
elif p == "集团":
p = ""
return p.strip("/")
def _parse_date(s):
s = _clean(s)[:10]
if not s:
return None
try:
return datetime.strptime(s, "%Y-%m-%d").date()
except ValueError:
return None
def _row_from_seal(rec: dict, month_display: str, abnormal_type: str) -> dict:
return {
"37工号": _clean(rec.get("base_code")),
"姓名": _clean(rec.get("staff_name")),
"月报检查月份": month_display,
"异常类型": abnormal_type,
"所属单位": _clean(rec.get("BELONG_UNIT_ORG_NAME")),
"一级部门": _clean(rec.get("DEPT_ORG_ONE")),
"二级部门": _clean(rec.get("DEPT_ORG_TWO")),
"三级部门": _clean(rec.get("DEPT_ORG_THREE")),
"四级部门": _clean(rec.get("DEPT_ORG_FOUR")),
"五级部门": _clean(rec.get("DEPT_ORG_FIVE")),
}
def _resolve_org_label(rec: dict, org_name_map: Dict[str, str]) -> str:
"""解析员工组织类型标签:部门全路径匹配组织表组织全路径 → 组织名称。
匹配失败回退取路径最后一个节点名。"""
path = _norm_path(rec.get("ORG_FULL_PATH"))
if path and path in org_name_map:
return org_name_map[path]
if path:
return path.split("/")[-1]
return ""
# ==================== 检查1:在职天数是否均排班 ====================
def _calc_working_days(rec: dict, year: int, month: int) -> int:
"""按需求文档规则计算当月在职天数(基于入职/离职时间)。"""
month_days = calendar.monthrange(year, month)[1]
first = date(year, month, 1)
last = date(year, month, month_days)
join_d = _parse_date(rec.get("join_date"))
leave_d = _parse_date(rec.get("leaveOffice_date"))
def in_service(d):
if join_d and d < join_d:
return False
if leave_d and d > leave_d:
return False
return True
in_first, in_last = in_service(first), in_service(last)
if in_first and in_last:
# 1号和月末都在职 = 全月在职,在职天数即为当月自然天数
return month_days
if in_first and not in_last:
return (leave_d - first).days if leave_d else 0
if not in_first and in_last:
return (last - join_d).days if join_d else 0
# 首尾都不在职:仅当入职、离职日期都落在本月内时按差计算;否则返回 0
if join_d and leave_d and first <= join_d <= last and first <= leave_d <= last:
return (leave_d - join_d).days
return 0
def check1(seal_rows: List[dict], year: int, month: int) -> List[dict]:
month_display = f"{year:04d}-{month:02d}"
rows = []
for rec in seal_rows:
wd = _calc_working_days(rec, year, month)
yq = _to_int(rec.get("kq_stat_month_yq_work_day_in")) # 在职应勤工作日
rest = _to_int(rec.get("kq_stat_cal_ext9")) # 休息天
if wd - (yq + rest) != 0:
rows.append(_row_from_seal(rec, month_display, TYPE_1))
return rows
# ==================== 检查2:排休天数验证 ====================
def check2(seal_rows, org_name_map, seq_map, engine, year, month) -> List[dict]:
month_display = f"{year:04d}-{month:02d}"
rows = []
for rec in seal_rows:
unit = _clean(rec.get("BELONG_UNIT_ORG_NAME"))
org_label = _resolve_org_label(rec, org_name_map)
seq = seq_map.get(_clean(rec.get("base_code")), "")
abnormal, rule, _days = engine.check(unit, org_label, seq, rec.get("kq_stat_cal_ext9"))
if abnormal:
rows.append(_row_from_seal(rec, month_display, rule.desc))
return rows
# ==================== 检查3:封存值是否为最新值 ====================
def check3(diff_rows, seal_rows, diff_fields, year, month) -> List[dict]:
month_display = f"{year:04d}-{month:02d}"
if not diff_rows:
return []
seal_by_code = {_clean(r.get("base_code")): r for r in seal_rows}
rows = []
for dr in diff_rows:
code = _clean(dr.get("base_code")) or _clean(dr.get("工号"))
if any(_clean(dr.get(f)) for f in diff_fields) and code in seal_by_code:
rows.append(_row_from_seal(seal_by_code[code], month_display, TYPE_3))
return rows
# ==================== 检查4:出勤天数验证 ====================
def check4(seal_rows, shift_map, year, month) -> List[dict]:
month_display = f"{year:04d}-{month:02d}"
rows = []
for rec in seal_rows:
code = _clean(rec.get("base_code"))
expected = shift_map.get(code)
if expected is None:
continue
attend = _to_int(rec.get("kq_stat_cal_ext19"), default=-1) # 实际出勤天日
if attend >= 0 and attend > expected:
rows.append(_row_from_seal(rec, month_display, TYPE_4))
return rows
# ==================== 检查5:未封存名单 ====================
def check5(seal_rows, in_service_records, year, month) -> List[dict]:
month_display = f"{year:04d}-{month:02d}"
seal_codes = {_clean(r.get("base_code")) for r in seal_rows}
rows = []
for rec in in_service_records:
code = _clean(rec.get("工号"))
if code and code not in seal_codes:
rows.append({
"37工号": code, "姓名": _clean(rec.get("姓名")),
"月报检查月份": month_display, "异常类型": TYPE_5,
"所属单位": _clean(rec.get("所属单位")),
"一级部门": _clean(rec.get("一级部门")),
"二级部门": _clean(rec.get("二级部门")),
"三级部门": _clean(rec.get("三级部门")),
"四级部门": _clean(rec.get("四级部门")),
"五级部门": _clean(rec.get("五级部门")),
})
return rows
# ==================== 汇总编排 ====================
def run_all_checks(*, seal_rows, org_name_map, seq_map, in_service_records,
shift_map, engine, year, month, diff_rows=None, diff_fields=None,
notes=None) -> dict:
notes = list(notes or [])
results = {
1: check1(seal_rows, year, month),
2: check2(seal_rows, org_name_map, seq_map, engine, year, month),
3: check3(diff_rows or [], seal_rows, diff_fields or [], year, month),
4: check4(seal_rows, shift_map, year, month),
5: check5(seal_rows, in_service_records, year, month),
}
if diff_rows is None:
notes.append("检查3「封存值是否为最新值」:对比接口数据未提供,本次跳过该检查")
return {"rows": results, "notes": notes}