feat(xq0011): 支持检查项选择并增加岗位等核心字段到异常名单
This commit is contained in:
@@ -26,7 +26,7 @@ from datetime import date
|
||||
from typing import Dict, List, Optional, Tuple
|
||||
|
||||
from ..config import (
|
||||
logger, require_session, require_user_id,
|
||||
logger, require_session, require_user_id, get_shift_data,
|
||||
HR_BASE_URL, PAGE_MAX_SIZE, CACHE_DIR, DEFAULT_SAVE_DIR,
|
||||
)
|
||||
from ..data.seal_data_export import (
|
||||
@@ -68,7 +68,7 @@ SEAL_REST_FIELD = "kq_stat_cal_ext9" # 休息天(正休)
|
||||
|
||||
# 输出列(对应需求文档异常名单字段,附 应勤天/实际出勤天/正休/标准 便于排查)
|
||||
OUTPUT_COLUMNS = [
|
||||
"37工号", "姓名", "月报检查月份", "异常类型",
|
||||
"37工号", "姓名", "岗位", "入职时间", "离职时间", "月报检查月份", "异常类型",
|
||||
"应勤天", "实际出勤天", "正休", "正休标准", "异常明细",
|
||||
"所属单位", "一级部门", "二级部门", "三级部门", "四级部门", "五级部门",
|
||||
]
|
||||
@@ -384,20 +384,25 @@ def run_attendance_rest_check(month: str = None, save_dir: str = None) -> List[d
|
||||
raise RuntimeError("getCurUserInfo 未返回 userId,无法查询排班")
|
||||
team_plan = load_team_plan_cached(session, ym)
|
||||
|
||||
# 3. 拉取全集团排班 → 工号 → 当月出现最多的 team_name
|
||||
shift_rows = fetch_all_shift(session, user_id, begin_date, end_date)
|
||||
staff_team: Dict[str, str] = {}
|
||||
no_team_cnt = 0
|
||||
for row in shift_rows:
|
||||
code = _clean(row.get("base_code"))
|
||||
if not code:
|
||||
continue
|
||||
team = _staff_main_team(row)
|
||||
if not team:
|
||||
no_team_cnt += 1
|
||||
continue
|
||||
staff_team[code] = team
|
||||
logger.info("排班加载完成:%d 人带方案,%d 人无方案(跳过)", len(staff_team), no_team_cnt)
|
||||
# 3. 排班 → 工号 → 当月出现最多的 team_name
|
||||
# 优先用 run() 预处理阶段注入的结果(全部数据就绪后再检查);未注入时兜底自拉
|
||||
_, staff_team = get_shift_data()
|
||||
if staff_team:
|
||||
logger.info("排班复用预处理数据:%d 人带方案", len(staff_team))
|
||||
else:
|
||||
shift_rows = fetch_all_shift(session, user_id, begin_date, end_date)
|
||||
staff_team = {}
|
||||
no_team_cnt = 0
|
||||
for row in shift_rows:
|
||||
code = _clean(row.get("base_code"))
|
||||
if not code:
|
||||
continue
|
||||
team = _staff_main_team(row)
|
||||
if not team:
|
||||
no_team_cnt += 1
|
||||
continue
|
||||
staff_team[code] = team
|
||||
logger.info("排班加载完成:%d 人带方案,%d 人无方案(跳过)", len(staff_team), no_team_cnt)
|
||||
|
||||
# 4. 逐人校验:技师固定正休≤8天;其余 实际出勤天≤应勤天、正休≤当月天数-应勤天
|
||||
abnormal: List[dict] = []
|
||||
|
||||
@@ -55,7 +55,7 @@ TRANSFER_NOW_SEQ_COL = "现职位序列"
|
||||
|
||||
# 输出列(对应需求文档检查4输出字段,附 异常明细 便于排查)
|
||||
OUTPUT_COLUMNS = [
|
||||
"37工号", "姓名", "月报检查月份", "异常类型",
|
||||
"37工号", "姓名", "岗位", "入职时间", "离职时间", "月报检查月份", "异常类型",
|
||||
"异常明细",
|
||||
"所属单位", "一级部门", "二级部门", "三级部门", "四级部门", "五级部门",
|
||||
]
|
||||
|
||||
@@ -73,7 +73,7 @@ COMPARE_FIELDS: List[Tuple[str, str]] = [
|
||||
|
||||
# 输出列(对应需求文档检查3输出字段,附 异常明细 便于排查)
|
||||
OUTPUT_COLUMNS = [
|
||||
"37工号", "姓名", "月报检查月份", "异常类型",
|
||||
"37工号", "姓名", "岗位", "入职时间", "离职时间", "月报检查月份", "异常类型",
|
||||
"异常明细",
|
||||
"所属单位", "一级部门", "二级部门", "三级部门", "四级部门", "五级部门",
|
||||
]
|
||||
|
||||
@@ -47,7 +47,7 @@ ROSTER_SEQ_COL = "职位序列"
|
||||
|
||||
# 输出列(对应需求文档检查6输出字段,附 延时加班补贴小时 便于排查)
|
||||
OUTPUT_COLUMNS = [
|
||||
"37工号", "姓名", "月报检查月份", "异常类型",
|
||||
"37工号", "姓名", "岗位", "入职时间", "离职时间", "月报检查月份", "异常类型",
|
||||
"延时加班补贴小时",
|
||||
"所属单位", "一级部门", "二级部门", "三级部门", "四级部门", "五级部门",
|
||||
]
|
||||
|
||||
@@ -50,7 +50,7 @@ ROSTER_LEAVE_COL = "离职时间"
|
||||
|
||||
# 输出列(对应需求文档检查5输出字段)
|
||||
OUTPUT_COLUMNS = [
|
||||
"37工号", "姓名", "月报检查月份", "异常类型",
|
||||
"37工号", "姓名", "岗位", "入职时间", "离职时间", "月报检查月份", "异常类型",
|
||||
"所属单位", "一级部门", "二级部门", "三级部门", "四级部门", "五级部门",
|
||||
]
|
||||
|
||||
@@ -71,16 +71,18 @@ def _month_range(ym: str) -> Tuple[date, date]:
|
||||
return date(y, m, 1), date(y, m, total_days)
|
||||
|
||||
|
||||
def _seal_code_set(rows: List[dict]) -> Set[str]:
|
||||
"""取当月封存记录的全部工号集合。"""
|
||||
codes: Set[str] = set()
|
||||
def _seal_map(rows: List[dict]) -> Dict[str, dict]:
|
||||
"""取当月封存记录映射(工号 → 封存记录行,一员工一条)。"""
|
||||
mapping: Dict[str, dict] = {}
|
||||
for rec in rows:
|
||||
code = ""
|
||||
for f in SEAL_CODE_FIELDS:
|
||||
code = _clean(rec.get(f))
|
||||
if code:
|
||||
codes.add(code)
|
||||
break
|
||||
return codes
|
||||
if code:
|
||||
mapping.setdefault(code, rec)
|
||||
return mapping
|
||||
|
||||
|
||||
# ==================== 花名册在职判定 ====================
|
||||
@@ -107,11 +109,15 @@ def _in_month(join: Optional[date], leave: Optional[date], first: date, last: da
|
||||
|
||||
|
||||
# ==================== 主流程 ====================
|
||||
def _build_unsealed_rows(df, seal_codes: Set[str], ym: str, first: date, last: date,
|
||||
def _build_unsealed_rows(df, seal_map: Dict[str, dict], ym: str, first: date, last: date,
|
||||
roster_path: str = None) -> List[dict]:
|
||||
"""遍历花名册,找出检查月在职、所属单位在白名单内但无封存记录的员工,返回名单行列表。
|
||||
|
||||
与封存预处理口径一致:一级部门 = 职业技术培训学校 的员工不参与本检查,直接剔除。
|
||||
|
||||
在册判定口径(离职时间统一以封存记录为准):存在离职后又复职的员工,其最新花名册
|
||||
离职日期已被清空,若只看花名册会漏判其检查月曾离职;故对已封存(有封存记录)的
|
||||
员工优先用封存记录的入职/离职时间判定检查月在册,花名册仅兜底无封存记录者。
|
||||
"""
|
||||
abnormal: List[dict] = []
|
||||
seen: Set[str] = set()
|
||||
@@ -128,18 +134,23 @@ def _build_unsealed_rows(df, seal_codes: Set[str], ym: str, first: date, last: d
|
||||
if code in excluded:
|
||||
excluded_n += 1
|
||||
continue # 一级部门 = 职业技术培训学校,不参与本检查
|
||||
join = _parse_date(row.get(ROSTER_JOIN_COL))
|
||||
leave = _parse_date(row.get(ROSTER_LEAVE_COL))
|
||||
seal_rec = seal_map.get(code)
|
||||
if seal_rec is not None:
|
||||
join = _parse_date(seal_rec.get("join_date"))
|
||||
leave = _parse_date(seal_rec.get("leaveOffice_date"))
|
||||
else:
|
||||
join = _parse_date(row.get(ROSTER_JOIN_COL))
|
||||
leave = _parse_date(row.get(ROSTER_LEAVE_COL))
|
||||
if not _in_month(join, leave, first, last):
|
||||
continue # 检查月不在职(尚未入职或已离职早于月初)
|
||||
if code in seal_codes:
|
||||
continue # 检查月不在册(尚未入职或已离职早于月初)
|
||||
if code in seal_map:
|
||||
continue # 已有封存记录,正常
|
||||
abnormal.append(enrich_dept_fields({
|
||||
"37工号": code,
|
||||
"姓名": _clean(row.get(ROSTER_NAME_COL)),
|
||||
"月报检查月份": ym,
|
||||
"异常类型": ABNORMAL_TYPE,
|
||||
}, code, None, roster_path))
|
||||
}, code, seal_rec, roster_path))
|
||||
if excluded_n:
|
||||
logger.info("检查5 剔除「职业技术培训学校」%d 人", excluded_n)
|
||||
return abnormal
|
||||
@@ -177,10 +188,10 @@ def run_unsealed_check(month: str = None, save_dir: str = None,
|
||||
|
||||
# 2. 读取预处理封存表(已按所属单位白名单筛选并保存)
|
||||
seal_rows = load_seal_rows(ym, save_dir)
|
||||
seal_codes = _seal_code_set(seal_rows)
|
||||
logger.info("考勤封存记录共 %d 人:%s", len(seal_codes), ym)
|
||||
seal_map = _seal_map(seal_rows)
|
||||
logger.info("考勤封存记录共 %d 人:%s", len(seal_map), ym)
|
||||
|
||||
# 3. 找出在册未封存
|
||||
abnormal = _build_unsealed_rows(df, seal_codes, ym, first, last, roster_path)
|
||||
abnormal = _build_unsealed_rows(df, seal_map, ym, first, last, roster_path)
|
||||
logger.info("检查5命中异常 %d 人(在册未封存)", len(abnormal))
|
||||
return abnormal
|
||||
|
||||
@@ -8,15 +8,18 @@
|
||||
from datetime import date
|
||||
from typing import Dict, List, Optional, Tuple
|
||||
|
||||
from ..config import logger, DEFAULT_SAVE_DIR
|
||||
from ..config import logger, DEFAULT_SAVE_DIR, get_shift_data
|
||||
from ..data.seal_data_export import (
|
||||
enrich_dept_fields, load_seal_rows,
|
||||
enrich_dept_fields, load_roster_dept_map, load_seal_rows,
|
||||
_clean, _num, _text, _parse_date, _prev_month, _month_range,
|
||||
)
|
||||
|
||||
# 异常类型(对应需求文档检查1)
|
||||
ABNORMAL_TYPE = "当月在职天数有差缺排班"
|
||||
|
||||
# 二次入职员工(封存/花名册均拿不到离职时间)的在职天数无法精确校验,需人工核查
|
||||
NOTE_SECOND_HIRE = "员工二次入职,无法校验具体的在职天数,需人工核查"
|
||||
|
||||
# 封存记录字段(aa.md 列定义)
|
||||
SEAL_CODE_FIELDS = ("base_code", "seal_base_code")
|
||||
SEAL_NAME_FIELD = "staff_name"
|
||||
@@ -27,9 +30,10 @@ SEAL_REST_FIELD = "kq_stat_cal_ext9" # aa.md:休息天
|
||||
|
||||
# 输出列(对应需求文档检查1输出字段)
|
||||
OUTPUT_COLUMNS = [
|
||||
"37工号", "姓名", "月报检查月份", "异常类型",
|
||||
"37工号", "姓名", "岗位", "入职时间", "离职时间", "月报检查月份", "异常类型",
|
||||
"在职天数", "应勤工作日", "休息天", "差值",
|
||||
"所属单位", "一级部门", "二级部门", "三级部门", "四级部门", "五级部门",
|
||||
"备注",
|
||||
]
|
||||
|
||||
|
||||
@@ -56,12 +60,15 @@ def _build_seal_map(rows: List[dict]) -> Dict[str, dict]:
|
||||
return mapping
|
||||
|
||||
|
||||
def run_working_days_shift_check(month: str = None, save_dir: str = None) -> List[dict]:
|
||||
def run_working_days_shift_check(month: str = None, save_dir: str = None,
|
||||
roster_path: str = None) -> List[dict]:
|
||||
"""执行检查1「在职天数是否均排班验证」,返回异常名单行列表。
|
||||
|
||||
Args:
|
||||
month: 检查月份 "YYYY-MM",默认上月。
|
||||
save_dir: 输出目录(仅用于读取预处理封存表)。
|
||||
roster_path: 花名册路径(用于识别「二次入职」员工:离职后复职导致封存/花名册
|
||||
均拿不到离职时间,在职天数无法精确校验,异常行备注需人工核查)。
|
||||
|
||||
Returns:
|
||||
异常名单行列表(每行为 OUTPUT_COLUMNS 对应字段的 dict)。
|
||||
@@ -86,6 +93,10 @@ def run_working_days_shift_check(month: str = None, save_dir: str = None) -> Lis
|
||||
seal_map = _build_seal_map(seal_rows)
|
||||
logger.info("考勤封存加载完成,共 %d 人:%s", len(seal_map), ym)
|
||||
|
||||
# 排班预处理结果由 run() 预处理阶段统一注入 config(全部数据就绪后再执行检查);
|
||||
# 取「工号→最早排班日期」用于二次入职识别;未注入(预处理失败)时不识别
|
||||
shift_map, _ = get_shift_data()
|
||||
|
||||
abnormal: List[dict] = []
|
||||
for code, rec in seal_map.items():
|
||||
join = _parse_date(rec.get(SEAL_JOIN_FIELD))
|
||||
@@ -97,6 +108,17 @@ def run_working_days_shift_check(month: str = None, save_dir: str = None) -> Lis
|
||||
rest = _num(rec.get(SEAL_REST_FIELD))
|
||||
diff = wd - (work + rest)
|
||||
if diff != 0:
|
||||
# 二次入职识别(仅针对异常行):封存离职时间为空(在职或复职后被清)时,
|
||||
# 若花名册入职日期晚于该员工检查月最早排班日期(入职前已有排班)= 二次入职,
|
||||
# 其在职区间无法确定,在职天数无法精确校验,备注需人工核查(不误报差值)。
|
||||
# 当月入职新人最早排班日 ≈ 入职日期,不命中,其异常为真实排班问题照常展示。
|
||||
note = ""
|
||||
if leave is None:
|
||||
roster_info = load_roster_dept_map(roster_path).get(code) or {}
|
||||
roster_join = _parse_date(roster_info.get("入职时间"))
|
||||
earliest = shift_map.get(code)
|
||||
if earliest is not None and roster_join is not None and roster_join > earliest:
|
||||
note = NOTE_SECOND_HIRE
|
||||
abnormal.append(enrich_dept_fields({
|
||||
"37工号": code,
|
||||
"姓名": _text(rec.get(SEAL_NAME_FIELD)),
|
||||
@@ -106,6 +128,7 @@ def run_working_days_shift_check(month: str = None, save_dir: str = None) -> Lis
|
||||
"应勤工作日": int(work),
|
||||
"休息天": int(rest),
|
||||
"差值": diff,
|
||||
"备注": note,
|
||||
}, code, rec))
|
||||
logger.info("检查1命中异常 %d 人(在职天数≠应勤+休息)", len(abnormal))
|
||||
return abnormal
|
||||
|
||||
Reference in New Issue
Block a user