feat: 新增部门排班查询接口与排班异常校验优化
1. 新增按部门查询排班集合的接口能力,替换原模糊匹配排班名的校验逻辑 2. 新增门店技师序列的排除规则,优化异常判定范围 3. 修复导入统计分页截断问题,完善全量数据抓取逻辑 4. 更新钉钉推送模板与测试账号配置 5. 补全离职电子签流程相关文档
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
@@ -252,6 +253,78 @@ def _extract_json_response(req):
|
||||
return None
|
||||
|
||||
|
||||
def _merge_datas(result, resp):
|
||||
"""从一次接口响应(resp)中提取并累计统计:需导入总条数、成功数、异常明细。"""
|
||||
for item in resp.get("datas") or []:
|
||||
item = item or {}
|
||||
msg = str(item.get("imp_fixed_msg", "") or "").strip()
|
||||
if not msg:
|
||||
continue
|
||||
# 接口返回的每一行即本次调度的一条需导入记录,全部计入需导入总条数
|
||||
result["total_count"] += 1
|
||||
# HR 对导入成功的行同样返回「导入成功;」等固定文案,成功行只统计数量,
|
||||
# 不纳入异常(否则会被误报为异常,如「异常:导入成功;」)
|
||||
if "导入成功" in msg:
|
||||
result["success_count"] += 1
|
||||
continue
|
||||
result["exceptions"].append({
|
||||
"staff_code": str(item.get("imp_assi_staff_code_ext_table_field_base_id", "") or ""),
|
||||
"staff_name": str(item.get("imp_assi_staff_name_ext_table_field_base_id", "") or ""),
|
||||
"insurance_name": str(item.get("ext_insurance_name", "") or ""),
|
||||
"message": msg,
|
||||
})
|
||||
|
||||
|
||||
def _build_hr_session():
|
||||
"""用 HR 登录态(common.login 缓存的 hr_cookies.json)构建可访问 HR 接口的
|
||||
requests.Session(仅注入 37du.co 域 cookies),与 common.login 校验同一套方式。"""
|
||||
cookies = load_cookies()
|
||||
if not cookies:
|
||||
raise FileNotFoundError("缺少 HR 登录态 hr_cookies.json(请先完成 HR 登录)")
|
||||
import requests
|
||||
session = requests.Session()
|
||||
session.headers.update({
|
||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/120.0.0.0 Safari/537.36",
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
})
|
||||
for c in cookies:
|
||||
if c.get("domain") and "37du.co" in str(c.get("domain", "")):
|
||||
session.cookies.set(c.get("name"), c.get("value"),
|
||||
domain=c.get("domain"), path=c.get("path", "/"))
|
||||
return session
|
||||
|
||||
|
||||
def _fetch_remaining_pages(result, first_url, page_count, page_size=15):
|
||||
"""getTmpDataPage 每页固定返回 15 条,弹窗只加载第一页时监听只能统计到 15 条,
|
||||
实际导入量常超 15,导致成功数/异常明细被截断、漏统计。
|
||||
此函数用 HR 登录态按 pageNo 主动拉取剩余页并合并全部结果,保证统计覆盖全量。"""
|
||||
if page_count <= 1:
|
||||
return
|
||||
try:
|
||||
session = _build_hr_session()
|
||||
except Exception as e:
|
||||
logger.warning("分页拉取失败(无法构建 HR 会话):%s,仅统计弹窗第一页", e)
|
||||
return
|
||||
for page_no in range(2, page_count + 1):
|
||||
start = (page_no - 1) * page_size
|
||||
url = re.sub(r"pageNo=\d+", f"pageNo={page_no}", first_url)
|
||||
url = re.sub(r"start=\d+", f"start={start}", url)
|
||||
url = re.sub(r"pageSize=\d+", f"pageSize={page_size}", url)
|
||||
try:
|
||||
resp = session.get(url, timeout=15)
|
||||
data = resp.json()
|
||||
except Exception as e:
|
||||
logger.warning("分页第 %s/%s 页拉取失败:%s", page_no, page_count, e)
|
||||
continue
|
||||
if str(data.get("state", "")).strip() != TMP_DATA_STATE_OK:
|
||||
logger.warning("分页第 %s/%s 页返回 state=%s,跳过",
|
||||
page_no, page_count, data.get("state"))
|
||||
continue
|
||||
logger.info("分页第 %s/%s 页返回 %s 条",
|
||||
page_no, page_count, len(data.get("datas") or []))
|
||||
_merge_datas(result, data)
|
||||
|
||||
|
||||
def _capture_import_exceptions(page, timeout=TMP_DATA_WAIT):
|
||||
"""监听「第二个下一步:真正导入内容」结果接口(getTmpDataPage.mc),捕获返回的全部异常。
|
||||
|
||||
@@ -260,8 +333,9 @@ def _capture_import_exceptions(page, timeout=TMP_DATA_WAIT):
|
||||
- state="1" 表示接口正常;meg 为全局提示;
|
||||
- datas[].imp_fixed_msg 为逐行导入结果说明:异常行如「存在已参保的人员,不允许重复增员!」,
|
||||
成功行返回「导入成功;」(成功行不纳入异常上报)。
|
||||
本函数合并该接口全部(含分页/多次)响应中的异常(不逐行单独处理),供流程统一上报;
|
||||
成功行(「导入成功」)只统计成功行数,不纳入异常。
|
||||
接口分页返回(每页固定 pageSize=15,响应带 pageCount 总页数),弹窗默认只加载第一页,
|
||||
故捕获首响应后主动按 pageNo 翻页拉取剩余页合并,保证总条数/成功数/异常明细覆盖全量,
|
||||
不再出现「每次固定 15 条」的截断问题。
|
||||
|
||||
Returns:
|
||||
dict: {
|
||||
@@ -270,13 +344,16 @@ def _capture_import_exceptions(page, timeout=TMP_DATA_WAIT):
|
||||
"meg": str, # 全局提示
|
||||
"listen_ok": bool, # 接口监听是否成功启动(False=未监听,结果不可信)
|
||||
"success_count": int, # 接口返回的导入成功行数
|
||||
"total_count": int, # 接口返回的需导入总行数(成功+异常,即本次需导入条数)
|
||||
"exceptions": [ # 全部异常明细
|
||||
{"staff_code":..., "staff_name":..., "insurance_name":..., "message":...}, ...
|
||||
],
|
||||
}
|
||||
"""
|
||||
result = {"captured": False, "state": "", "meg": "", "exceptions": [],
|
||||
"listen_ok": True, "success_count": 0}
|
||||
"listen_ok": True, "success_count": 0, "total_count": 0}
|
||||
first_url = None
|
||||
page_count = 1
|
||||
deadline = time.time() + timeout
|
||||
last_hit = time.time()
|
||||
while time.time() < deadline:
|
||||
@@ -306,22 +383,18 @@ def _capture_import_exceptions(page, timeout=TMP_DATA_WAIT):
|
||||
meg = str(resp.get("meg", "") or "").strip()
|
||||
if meg:
|
||||
result["meg"] = meg
|
||||
for item in resp.get("datas") or []:
|
||||
item = item or {}
|
||||
msg = str(item.get("imp_fixed_msg", "") or "").strip()
|
||||
if not msg:
|
||||
continue
|
||||
# HR 对导入成功的行同样返回「导入成功;」等固定文案,成功行只统计数量,
|
||||
# 不纳入异常(否则会被误报为异常,如「异常:导入成功;」)
|
||||
if "导入成功" in msg:
|
||||
result["success_count"] += 1
|
||||
continue
|
||||
result["exceptions"].append({
|
||||
"staff_code": str(item.get("imp_assi_staff_code_ext_table_field_base_id", "") or ""),
|
||||
"staff_name": str(item.get("imp_assi_staff_name_ext_table_field_base_id", "") or ""),
|
||||
"insurance_name": str(item.get("ext_insurance_name", "") or ""),
|
||||
"message": msg,
|
||||
})
|
||||
# 记录第一页 URL 与总页数,用于主动翻页拉全(弹窗默认只加载第一页 15 条)
|
||||
if first_url is None:
|
||||
first_url = req.url
|
||||
try:
|
||||
page_count = max(1, int(resp.get("pageCount") or 1))
|
||||
except Exception:
|
||||
page_count = 1
|
||||
_merge_datas(result, resp)
|
||||
# 若接口存在多页(实际导入量超过一页 15 条),主动翻页拉取剩余页后结束
|
||||
if first_url and page_count > 1:
|
||||
_fetch_remaining_pages(result, first_url, page_count)
|
||||
break
|
||||
return result
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user