- 新增社保参保/停保状态核对核心逻辑,支持调用HR接口校验工号参保记录 - 新增滑块验证码改进版登录工具,支持缓存会话免重复登录 - 新增HR通用API封装模块 - 新增员工异动名单清洗、导出、核对全流程功能 - 新增依赖库xlrd、openpyxl、opencv等 - 删除旧的钉钉消息推送文档、测试用Excel、aa.md脚本文件 - 优化员工异动导出流程,自动完成去重和参保核对
124 lines
3.7 KiB
Markdown
124 lines
3.7 KiB
Markdown
import requests
|
||
import csv
|
||
import os
|
||
|
||
# 你的 Cookie 字符串(从浏览器复制完整)
|
||
|
||
COOKIE_STR = "你的完整Cookie"
|
||
|
||
# 基础参数模板(和之前一样)
|
||
|
||
BASE_PARAMS = {
|
||
"start": "0",
|
||
"pageNo": "1",
|
||
"pageSize": "15",
|
||
"USER_ID": "07b83185-6243-42bc-b79f-b81b4cffb471",
|
||
"STRU_ID": "596bae33-50e9-11ec-b526-822ff8ed5b28",
|
||
"STRU_TREE_CODE": "cq37du",
|
||
"queryTempPersonType": "queryForList",
|
||
"belongUnitStruId": "f1a6c12a-cef4-11ee-b449-000c296f9469",
|
||
"fastMode": "0",
|
||
"rootId": "cq37du",
|
||
"_noTrans_": "noTrans",
|
||
"defineColumnType": "5",
|
||
"PERSON_STATUS": "",
|
||
"SI_STATE": "98",
|
||
"staff_names": "",
|
||
"base_codes": "", # 这个会被动态替换
|
||
"includeSubUnit": "1",
|
||
"postStruId": "1",
|
||
"regist_property": "",
|
||
"identity": "",
|
||
"idcards": "",
|
||
"if_sb": "",
|
||
"payOrgId": "",
|
||
"payUnitId": "",
|
||
"siName": "",
|
||
"belongUnitId": "",
|
||
"belongUnitName": "",
|
||
"DEPT_NAME": "",
|
||
"inputDeptName": "",
|
||
"selectType": "1",
|
||
"operator": "",
|
||
"joinDate_begin": "", "joinDate_end": "",
|
||
"leaveDate_begin": "", "leaveDate_end": "",
|
||
"siBeginDate_begin": "", "siBeginDate_end": "",
|
||
"siEndDate_begin": "", "siEndDate_end": "",
|
||
}
|
||
|
||
HEADERS = {
|
||
"Cookie": COOKIE_STR,
|
||
"User-Agent": "Mozilla/5.0",
|
||
"Content-Type": "application/x-www-form-urlencoded",
|
||
}
|
||
|
||
def query_batch(codes_batch):
|
||
"""查询一批工号(≤15个),返回响应 JSON"""
|
||
params = BASE_PARAMS.copy()
|
||
params["base_codes"] = ",".join(codes_batch)
|
||
resp = requests.post(
|
||
"https://hr.37du.co/RedseaPlatform/getPageAjax/si_main_SelectByTreeCode/CoreRequest.mc",
|
||
data=params,
|
||
headers=HEADERS,
|
||
timeout=15
|
||
)
|
||
resp.raise_for_status() # 如果不是200会抛出异常
|
||
return resp.json()
|
||
|
||
def extract_found_codes(response_json):
|
||
"""从返回的JSON里提取所有出现的工号(base_Code)"""
|
||
datas = response_json.get("datas", [])
|
||
return [item["base_Code"] for item in datas if "base_Code" in item]
|
||
|
||
def check_batch(codes_batch):
|
||
"""比较查询结果与输入工号,返回找到的、未找到的列表"""
|
||
try:
|
||
data = query_batch(codes_batch)
|
||
found = extract_found_codes(data)
|
||
missing = [c for c in codes_batch if c not in found]
|
||
return found, missing, data
|
||
except Exception as e:
|
||
print(f"请求失败:{e}")
|
||
return [], codes_batch, None
|
||
|
||
# ---------- 使用示例 ----------
|
||
|
||
# 假设你有一个大的工号列表
|
||
|
||
all_codes = [
|
||
"37028192", "37030557", "37035022", "其他工号..."
|
||
]
|
||
|
||
# 将大列表按15个一组拆分
|
||
|
||
batch_size = 15
|
||
batches = [all_codes[i:i+batch_size] for i in range(0, len(all_codes), batch_size)]
|
||
|
||
all_found = []
|
||
all_missing = []
|
||
output_rows = [] # 用于存所有有数据的完整行,方便后续导出
|
||
|
||
for batch in batches:
|
||
found, missing, resp_json = check_batch(batch)
|
||
all_found.extend(found)
|
||
all_missing.extend(missing)
|
||
|
||
# 如果找到数据,可以把这一批的完整行记录下来
|
||
if resp_json and resp_json.get("datas"):
|
||
output_rows.extend(resp_json["datas"])
|
||
print(f"查询 {batch} → 找到 {found},未找到 {missing}")
|
||
|
||
print("\n=== 总结 ===")
|
||
print(f"总计找到 {len(all_found)} 个工号:{all_found}")
|
||
print(f"未找到 {len(all_missing)} 个工号:{all_missing}")
|
||
|
||
# 把有数据的记录保存为CSV(字段已全量输出)
|
||
|
||
if output_rows:
|
||
keys = output_rows[0].keys()
|
||
with open("found_si_data.csv", "w", newline="", encoding="utf-8-sig") as f:
|
||
writer = csv.DictWriter(f, fieldnames=keys)
|
||
writer.writeheader()
|
||
writer.writerows(output_rows)
|
||
print(f"有数据的记录已保存到 found_si_data.csv,共 {len(output_rows)} 条")
|