feat(hrbp-ehr): 新增HR薪资卡与花名册自动化模块
1. 新增hrbp.ehr业务模块目录结构与基础配置 2. 新增工资卡数据抓取、核对功能,支持在职/离职员工数据导出 3. 新增员工花名册自定义导出自动化流程 4. 添加pandas依赖到requirements.txt 5. 清理调试用的验证码图片文件
This commit is contained in:
@@ -1,123 +1,59 @@
|
||||
import requests
|
||||
import csv
|
||||
import os
|
||||
访问[hr.37du.co/RedseaPlatform/PtPortal.mc?method=classic#ajax#ajax&&1&&nworktoday-40175-24311-77128-52242&&nworktoday-40175-24311|/RedseaPlatform/hrRoster/1116da64-b094-11ea-b588-14187743d052/getCustomCommonList.mc?_t=1786190208277&&clickFlag=true&&treePermitType=permit&&useSealTreeData=0&&menuName=%E5%91%98%E5%B7%A5%E8%8A%B1%E5%90%8D%E5%86%8C](https://hr.37du.co/RedseaPlatform/PtPortal.mc?method=classic#ajax&1&nworktoday-40175-24311-77128-52242&nworktoday-40175-24311|/RedseaPlatform/hrRoster/1116da64-b094-11ea-b588-14187743d052/getCustomCommonList.mc?_t=1786190208277&clickFlag=true&treePermitType=permit&useSealTreeData=0&menuName=%E5%91%98%E5%B7%A5%E8%8A%B1%E5%90%8D%E5%86%8C&_t=1786190208277)
|
||||
|
||||
# 你的 Cookie 字符串(从浏览器复制完整)
|
||||
点击组织机构
|
||||
|
||||
COOKIE_STR = "你的完整Cookie"
|
||||
```
|
||||
<div class="hrm-bd-left-title" title="切换列表/树" data-i18n-attr="{'COMMON_TITLE':['title']}">
|
||||
<span class="iconfont icon-tree"></span>
|
||||
<span class="hrm-bd-left-title-name" data-i18n="COMMON_MENU">员工管理</span>
|
||||
<span class="hrm-bd-left-title-org tabActive" data-i18n="COMMON_TITLE">组织机构</span>
|
||||
</div>
|
||||
```
|
||||
|
||||
# 基础参数模板(和之前一样)
|
||||
点击集团
|
||||
|
||||
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": "",
|
||||
}
|
||||
```
|
||||
<a id="indexTree_1_a" class="level0 curSelectedNode" treenode_a="" onclick="" target="_blank" style="" title="集团"><span id="indexTree_1_ico" title="" treenode_ico="" class="button ico_open" style="background:url(/RedseaPlatform/skins/images/redsea-icon-bumenguanli.png) 0 0 no-repeat;"></span><span id="indexTree_1_span">集团</span></a>
|
||||
```
|
||||
|
||||
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()
|
||||
```
|
||||
<p>访问<a href="https://hr.37du.co/RedseaPlatform/hrRoster/1116da64-b094-11ea-b588-14187743d052/getCustomCommonList.mc">hr.37du.co/RedseaPlatform/hrRoster/1116da64-b094-11ea-b588-14187743d052/getCustomCommonList.mc</a><br />
|
||||
清空输入框</p>
|
||||
<div component-div="commonSearchVue_1116da64-b094-11ea-b588-14187743d052_hr_staff_base.person_status"><div data-v-717358fc="" class="form-select el-input-group el-input-group--prepend" style="--textSize: 13px;"><div data-v-717358fc="" class="el-input-group__prepend">在职状态</div><div data-v-717358fc="" class="el-select el-select--small" labelkey="label"><div class="el-select__tags" style="width: 100%; max-width: 113px;"><span><span class="el-tag el-tag--info el-tag--mini el-tag--light"><span class="el-select__tags-text">在职</span><i class="el-tag__close el-icon-close"></i></span></span><input type="text" autocomplete="off" class="el-select__input is-small" style="flex-grow: 1; width: 0.176991%; max-width: 103px;"></div><div class="el-input el-input--small el-input--suffix"><input tabindex="-1" type="text" readonly="readonly" autocomplete="off" placeholder="" class="el-input__inner" style="height: 32px;"><span class="el-input__suffix"><span class="el-input__suffix-inner"><i class="el-select__caret el-input__icon el-icon-arrow-up" style=""></i></span></span></div></div><input data-v-717358fc="" style="position: absolute; z-index: -999; width: 0px; height: 0px; border-width: medium; border-style: none; border-color: currentcolor; border-image: none; padding: 0px; opacity: 0;"></div></div>
|
||||
```
|
||||
|
||||
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
|
||||
```
|
||||
<button type="button" class="btn btn-success btn-sm dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i18n key="COMMON_BTN">更多操作</i18n>
|
||||
<span style="font-size: 14px;margin-left:5px;float: none;" class="icon icon-angle-down"></span>
|
||||
<span class="sr-only">Toggle Dropdown</span>
|
||||
</button>
|
||||
```
|
||||
|
||||
# ---------- 使用示例 ----------
|
||||
点击自定义导出
|
||||
|
||||
# 假设你有一个大的工号列表
|
||||
```
|
||||
<ul class="dropdown-menu" id="custom-btn-ul"><li trans-id="" btn-property-page-id="undefined" class=""><a>导出</a></li><li trans-id="" btn-property-page-id="undefined" class=""><a>自定义导出</a></li><li trans-id="109a1e49-b094-11ea-b588-14187743d052" btn-property-page-id="null" class=""><a>简历导出</a></li><li trans-id="109a0c98-b094-11ea-b588-14187743d052" btn-property-page-id="null" class=""><a>在职证明打印</a></li><li trans-id="109a81db-b094-11ea-b588-14187743d052" btn-property-page-id="null" class=""><a>离职证明打印</a></li><li trans-id="109bb704-b094-11ea-b588-14187743d052" btn-property-page-id="null" class=""><a>导入更新</a></li><li trans-id="1099c220-b094-11ea-b588-14187743d052" btn-property-page-id="null" class=""><a>批量上传头像</a></li><li trans-id="976c8025-11a7-443e-9853-93eb05fd5bf1" btn-property-page-id="null" class=""><a>批量下载头像</a></li><li trans-id="c7de15e0-c947-4e6c-88cf-311aa8fcb497" btn-property-page-id="c6255cdd51f0446783a9b0f2ad112b87" class=""><a>修改用工状态</a></li></ul>
|
||||
```
|
||||
|
||||
all_codes = [
|
||||
"37028192", "37030557", "37035022", "其他工号..."
|
||||
]
|
||||
点击选择模板
|
||||
|
||||
# 将大列表按15个一组拆分
|
||||
```
|
||||
<div data-v-717358fc="" class="form-select el-input-group el-input-group--prepend" data-v-252bd840="" style="--textSize: 13px;"><div data-v-717358fc="" class="el-input-group__prepend">模板</div><div data-v-717358fc="" class="el-select el-select--small" labelkey="label"><!----><div class="el-input el-input--small el-input--suffix"><!----><input type="text" readonly="readonly" autocomplete="off" placeholder="请选择模板" class="el-input__inner"><!----><span class="el-input__suffix"><span class="el-input__suffix-inner"><i class="el-select__caret el-input__icon el-icon-arrow-up"></i><!----><!----><!----><!----><!----></span><!----></span><!----><!----></div><div class="el-select-dropdown el-popper" style="display: none; min-width: 193.333px;"><div class="el-scrollbar" style=""><div class="el-select-dropdown__wrap el-scrollbar__wrap" style="margin-bottom: -15px; margin-right: -15px;"><ul class="el-scrollbar__view el-select-dropdown__list"><!----><div class="rs-option" label="干部选拔信息" value="548c2a43-7c45-459d-abb7-9b1622a188c5"><li class="el-select-dropdown__item" size="small"><div style="display: flex; justify-content: space-between; align-items: center;"><div>干部选拔信息</div> <div class="icon redsea-icon-error" style="display: none;"></div></div></li></div><div class="rs-option" label="员工基础信息" value="990effb5-f694-48ab-8820-6997edef50b5"><li class="el-select-dropdown__item" size="small"><div style="display: flex; justify-content: space-between; align-items: center;"><div>员工基础信息</div> <div class="icon redsea-icon-error" style="display: none;"></div></div></li></div><div class="rs-option" label="个税申报基础信息" value="e3e04246-9b9a-4de8-98b2-d0af999e252c"><li class="el-select-dropdown__item" size="small"><div style="display: flex; justify-content: space-between; align-items: center;"><div>个税申报基础信息</div> <div class="icon redsea-icon-error" style="display: none;"></div></div></li></div><div class="rs-option" label="雇主险增减员导出模板" value="fbe86100-a1b0-493d-ad6e-4a6ca0e6f7e1"><li class="el-select-dropdown__item" size="small"><div style="display: flex; justify-content: space-between; align-items: center;"><div>雇主险增减员导出模板</div> <div class="icon redsea-icon-error" style="display: none;"></div></div></li></div></ul></div><div class="el-scrollbar__bar is-horizontal"><div class="el-scrollbar__thumb" style="transform: translateX(0%);"></div></div><div class="el-scrollbar__bar is-vertical"><div class="el-scrollbar__thumb" style="transform: translateY(0%);"></div></div></div><!----></div></div><input data-v-717358fc="" style="position: absolute; z-index: -999; width: 0px; height: 0px; border-width: medium; border-style: none; border-color: currentcolor; border-image: none; padding: 0px; opacity: 0;"><!----><!----><!----></div>
|
||||
```
|
||||
|
||||
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 = [] # 用于存所有有数据的完整行,方便后续导出
|
||||
```
|
||||
<div class="el-select-dropdown__wrap el-scrollbar__wrap" style="margin-bottom: -15px; margin-right: -15px;"><ul class="el-scrollbar__view el-select-dropdown__list"><!----><div class="rs-option" label="干部选拔信息" value="548c2a43-7c45-459d-abb7-9b1622a188c5"><li class="el-select-dropdown__item" size="small"><div style="display: flex; justify-content: space-between; align-items: center;"><div>干部选拔信息</div> <div class="icon redsea-icon-error" style="display: none;"></div></div></li></div><div class="rs-option" label="员工基础信息" value="990effb5-f694-48ab-8820-6997edef50b5"><li class="el-select-dropdown__item hover" size="small"><div style="display: flex; justify-content: space-between; align-items: center;"><div>员工基础信息</div> <div class="icon redsea-icon-error" style="display: none;"></div></div></li></div><div class="rs-option" label="个税申报基础信息" value="e3e04246-9b9a-4de8-98b2-d0af999e252c"><li class="el-select-dropdown__item" size="small"><div style="display: flex; justify-content: space-between; align-items: center;"><div>个税申报基础信息</div> <div class="icon redsea-icon-error" style="display: none;"></div></div></li></div><div class="rs-option" label="雇主险增减员导出模板" value="fbe86100-a1b0-493d-ad6e-4a6ca0e6f7e1"><li class="el-select-dropdown__item" size="small"><div style="display: flex; justify-content: space-between; align-items: center;"><div>雇主险增减员导出模板</div> <div class="icon redsea-icon-error" style="display: none;"></div></div></li></div></ul></div>
|
||||
```
|
||||
|
||||
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)} 条")
|
||||
```
|
||||
<button type="button" class="el-button el-button--primary el-button--small"><!----><!----><span>确认导出</span></button>
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user