feat: 续签/离职/请假审批功能迭代与优化
- 续签电子签:新增电子签模板防呆校验,仅当模板配置时才提交;调整核验规则,仅签署完成(is_initiate_sign=2)算完成 - 改签离职电子签:新增后浪新天地按岗位细分签署单位逻辑,区分餐饮/非餐饮主体 - 转正不通过电子签:新增签署单位细分逻辑,与改签离职保持一致 - 通用审批:统一将审批请求的视图类型从VIEW改为WAIT,确保审批按钮正常加载;开启自动审批开关(APPROVE_ENABLED) - 转正流程:优化结果统计,区分成功/跳过/失败状态,跳过状态不判定为运行失败 - 请假审批:重构小时假校验逻辑,按请假时段匹配排班班段(含跨天夜班),新增排班班段字段记录
This commit is contained in:
@@ -106,7 +106,7 @@ PAGE_MAX_SIZE = 500 # 排班查询单页最大条数
|
||||
|
||||
# ==================== 真实审批提交 ====================
|
||||
# 影刀环境无 .env 文件,开关直接写死在代码中;如需临时关闭自动审批改为 False
|
||||
APPROVE_ENABLED = False
|
||||
APPROVE_ENABLED = True
|
||||
# 审批按钮:仅自动提交"同意"(校验通过);校验不通过未处理一律不自动提交,保留待人工处理
|
||||
_APPROVE_BUTTONS = {
|
||||
"通过": ("#chooseSubmit", "同意"),
|
||||
@@ -433,7 +433,9 @@ def parse_we_process_list(data):
|
||||
"""解析 WeProcess 待办行为单据字典。
|
||||
|
||||
taskId/businessKey/processId/formId 行内自带,无需再经浏览器 SSO 解析;
|
||||
detail_url 拼为 HR 流程详情页(goToWorkFlow, reqType=VIEW),供审批提交/推送链接用。
|
||||
detail_url 拼为 HR 流程详情页(goToWorkFlow, reqType=WAIT)供审批提交/推送链接用。
|
||||
注:必须用 reqType=WAIT(待办审批视图):reqType=VIEW 为只读查看,页面不加载表单数据、
|
||||
不显示审批按钮(#chooseSubmit 为 display:none),导致自动审批点击失败。
|
||||
注:数据行随服务端版本在 jsonList(total 型)与 datas(count 分页型)间切换,两种都兼容。
|
||||
"""
|
||||
docs = []
|
||||
@@ -449,7 +451,7 @@ def parse_we_process_list(data):
|
||||
detail_url = (
|
||||
f"{HR_BASE_URL}/RedseaPlatform/WorkformEngine.mc?method=goToWorkFlow"
|
||||
f"&formId={form_id}&businessKey={business_key}&processId={process_id}"
|
||||
f"&taskId={task_id}&reqType=VIEW&headType=&systemId="
|
||||
f"&taskId={task_id}&reqType=WAIT&headType=&systemId="
|
||||
)
|
||||
docs.append({
|
||||
"title": title,
|
||||
@@ -1405,7 +1407,8 @@ def run_flow(subject, validate_doc, generate_report):
|
||||
|
||||
|
||||
# ==================== 请假校验规则 ====================
|
||||
# 按小时请假的假期类型:不比对天数,只要请假当天是排班上班日即可
|
||||
# 按小时请假的假期类型:不比对天数,按请假时段判断是否落在排班班段内
|
||||
# (含前一天跨天夜班覆盖),另需已上传附件
|
||||
HOURLY_LEAVE_TYPES = {
|
||||
"小时特假",
|
||||
}
|
||||
@@ -1461,6 +1464,120 @@ def _get_work_days_count(start_date, end_date, staff_code):
|
||||
return len(work_days)
|
||||
|
||||
|
||||
def _parse_leave_time(value):
|
||||
"""解析小时假请假时间 "YYYY-MM-DD HH:MM[:SS]" -> (date, 当日分钟数);解析失败返回 None。"""
|
||||
if not value:
|
||||
return None
|
||||
m = re.search(r"(\d{4})-(\d{1,2})-(\d{1,2})[ T](\d{1,2}):(\d{2})", str(value))
|
||||
if not m:
|
||||
return None
|
||||
try:
|
||||
day = datetime(int(m.group(1)), int(m.group(2)), int(m.group(3))).date()
|
||||
except ValueError:
|
||||
return None
|
||||
return day, int(m.group(4)) * 60 + int(m.group(5))
|
||||
|
||||
|
||||
def _shift_min_range(bc_time):
|
||||
"""解析班段时间 "09:00 ~ 18:00" -> (开始分钟, 结束分钟);跨天夜班 end<start(如 "21:00 ~ 09:00");解析失败返回 None。"""
|
||||
if not bc_time:
|
||||
return None
|
||||
m = re.search(r"(\d{1,2}):(\d{2})\s*~\s*(\d{1,2}):(\d{2})", str(bc_time))
|
||||
if not m:
|
||||
return None
|
||||
return int(m.group(1)) * 60 + int(m.group(2)), int(m.group(3)) * 60 + int(m.group(4))
|
||||
|
||||
|
||||
def _fmt_min(m):
|
||||
"""分钟数(0-1439) -> "HH:MM"。"""
|
||||
return f"{m // 60:02d}:{m % 60:02d}"
|
||||
|
||||
|
||||
def _hourly_leave_within_shift(shift_rows, leave_date, leave_end_date, start_min, end_min):
|
||||
"""判断小时假请假时段是否完整落在某天排班班段内(含前一天跨天夜班)。
|
||||
|
||||
请假时段与班段均转成相对请假开始日 0 点的绝对分钟区间(跨天自动 +1440)做包含判断。
|
||||
例如请假当天日历为休息日,但时段落在前一天夜班(如 "21:00 ~ 09:00")跨天覆盖范围内,
|
||||
同样判定通过。返回 (是否通过, 命中班段日期, 命中bc_time)。
|
||||
"""
|
||||
end_abs = end_min + (leave_end_date - leave_date).days * 1440
|
||||
if end_abs < start_min:
|
||||
end_abs += 1440 # 请假自身跨天兜底(仅当结束时刻早于开始时刻)
|
||||
for delta in (0, -1):
|
||||
day = (leave_date + timedelta(days=delta)).strftime("%Y-%m-%d")
|
||||
info = _get_day_shift(shift_rows, day)
|
||||
r = _shift_min_range(info["bc_time"])
|
||||
if r is None:
|
||||
continue
|
||||
s, e = r
|
||||
base = delta * 1440 # 该日 0 点相对请假日 0 点的绝对偏移
|
||||
if s == 0 and e == 0:
|
||||
iv = (base, base + 1440) # 全天班(罕见)
|
||||
elif e < s:
|
||||
iv = (base + s, base + e + 1440) # 跨天夜班:当日 start ~ 次日 end
|
||||
else:
|
||||
iv = (base + s, base + e) # 当日班段
|
||||
if iv[0] <= start_min and end_abs <= iv[1]:
|
||||
return True, day, info["bc_time"]
|
||||
return False, None, None
|
||||
|
||||
|
||||
def _validate_hourly_leave(result, session, leave_info, staff_code, attachment, vacation_type):
|
||||
"""小时特假等按小时请假校验:请假时段须完整落在排班班段内(含前一天跨天夜班)+ 已上传附件。
|
||||
|
||||
请假时段与班段均转成相对请假开始日 0 点的绝对分钟区间做包含判断:
|
||||
例如请假当天日历为休息日,但时段落在前一天夜班(如 "21:00 ~ 09:00")跨天覆盖范围内,
|
||||
同样判定通过;时段不在任何班段内则校验不通过未处理。
|
||||
"""
|
||||
leave_hours = leave_info.get("请假小时")
|
||||
leave_start = _parse_leave_time(leave_info.get("开始时间"))
|
||||
leave_end = _parse_leave_time(leave_info.get("结束时间"))
|
||||
|
||||
if leave_start is None:
|
||||
result["decision"] = "校验不通过未处理"
|
||||
result["note"] = "无法解析请假开始时间"
|
||||
return result
|
||||
if leave_end is None:
|
||||
leave_end = leave_start
|
||||
|
||||
try:
|
||||
hr_session, user_id = _get_hr_context()
|
||||
query_start = (leave_start[0] - timedelta(days=1)).strftime("%Y-%m-%d")
|
||||
query_end = leave_end[0].strftime("%Y-%m-%d")
|
||||
shift_rows = fetch_all_shift(hr_session, user_id, staff_code, query_start, query_end)
|
||||
except Exception as e:
|
||||
logger.warning("小时假获取排班数据失败: %s", str(e))
|
||||
result["decision"] = "校验不通过未处理"
|
||||
result["note"] = f"获取排班数据失败: {e}"
|
||||
return result
|
||||
|
||||
ok, hit_day, hit_bc = _hourly_leave_within_shift(
|
||||
shift_rows, leave_start[0], leave_end[0], leave_start[1], leave_end[1])
|
||||
|
||||
if not ok:
|
||||
result["decision"] = "校验不通过未处理"
|
||||
result["note"] = (
|
||||
f"请假时段 {_fmt_min(leave_start[1])}~{_fmt_min(leave_end[1])} "
|
||||
f"未落在请假当天({query_end})或前一天({query_start})的排班班段内"
|
||||
)
|
||||
return result
|
||||
|
||||
if not attachment:
|
||||
result["decision"] = "校验不通过未处理"
|
||||
result["note"] = "未上传附件"
|
||||
return result
|
||||
|
||||
result["decision"] = "通过"
|
||||
result["附件路径"] = download_attachment(session, attachment)
|
||||
result["leave_info"]["排班班段"] = f"{hit_day} {hit_bc}"
|
||||
result["note"] = (
|
||||
f"审批通过(假期类型: {vacation_type},请假小时: {leave_hours},"
|
||||
f"请假时段 {_fmt_min(leave_start[1])}~{_fmt_min(leave_end[1])} 落在排班班段 "
|
||||
f"{hit_day} {hit_bc} 内,附件已上传)"
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
def _verify_attachment(session, vacation_type, reason, file_id):
|
||||
"""
|
||||
根据假期类型校验附件内容,返回 (decision, note, attachment_path)。
|
||||
@@ -1548,11 +1665,9 @@ def validate_doc(doc, session):
|
||||
leave_days = leave_info.get("请假天数")
|
||||
attachment = leave_info.get("附件")
|
||||
# 小时特假为按小时请假:start_time/end_time 为当日实际起止时间(可能 end_date 为空),
|
||||
# 用它们取当天日期判断排班;其他假期不受影响,仍用 begin_date/end_date
|
||||
# 需按请假时段(开始~结束时间)校验是否落在排班班段内(含前一天跨天夜班);
|
||||
# 其他假期不受影响,仍用 begin_date/end_date 校验排班上班天数
|
||||
is_hourly = vacation_type in HOURLY_LEAVE_TYPES
|
||||
if is_hourly:
|
||||
begin_date = leave_info.get("开始时间")
|
||||
end_date = leave_info.get("结束时间")
|
||||
|
||||
result = {
|
||||
"title": doc.get("title", ""),
|
||||
@@ -1579,6 +1694,10 @@ def validate_doc(doc, session):
|
||||
result["note"] = "请假人工号缺失"
|
||||
return result
|
||||
|
||||
# 小时假(如小时特假)不走天数比对,提前按请假时段校验排班班段
|
||||
if is_hourly:
|
||||
return _validate_hourly_leave(result, session, leave_info, staff_code, attachment, vacation_type)
|
||||
|
||||
start_date, end_date = _get_date_range(begin_date, end_date)
|
||||
if not start_date or not end_date:
|
||||
result["decision"] = "校验不通过未处理"
|
||||
@@ -1605,24 +1724,7 @@ def validate_doc(doc, session):
|
||||
# 0.5天->1个工作日,1.0天->1个工作日,1.5天->2个工作日
|
||||
days_mismatch = actual_work_days != math.ceil(round(fill_days, 2))
|
||||
|
||||
if vacation_type in HOURLY_LEAVE_TYPES:
|
||||
# 按小时请假(如小时特假):当天为上班日 + 已上传附件才通过
|
||||
leave_hours = leave_info.get("请假小时")
|
||||
if actual_work_days < 1:
|
||||
result["decision"] = "校验不通过未处理"
|
||||
result["note"] = f"请假当天非排班上班日(实际上班天数: {actual_work_days})"
|
||||
elif not attachment:
|
||||
result["decision"] = "校验不通过未处理"
|
||||
result["note"] = "未上传附件"
|
||||
else:
|
||||
result["decision"] = "通过"
|
||||
result["附件路径"] = download_attachment(session, attachment)
|
||||
result["note"] = (
|
||||
f"审批通过(假期类型: {vacation_type},请假小时: {leave_hours},"
|
||||
f"当天为上班日,附件已上传)"
|
||||
)
|
||||
|
||||
elif vacation_type in LEAVE_TYPE_GROUP_1:
|
||||
if vacation_type in LEAVE_TYPE_GROUP_1:
|
||||
if days_mismatch:
|
||||
result["decision"] = "校验不通过未处理"
|
||||
result["note"] = f"排班上班天数({actual_work_days}天)与填报天数({fill_days}天)不一致"
|
||||
@@ -1680,6 +1782,7 @@ def _format_detail(info):
|
||||
("结束段", "结束段"),
|
||||
("请假天数", "请假天数"),
|
||||
("请假小时", "请假小时"),
|
||||
("排班班段", "排班班段"),
|
||||
("实际上班天数", "实际上班天数"),
|
||||
("填报天数", "填报天数"),
|
||||
("附件", "附件"),
|
||||
|
||||
Reference in New Issue
Block a user