rescue: 断电事故后工作区全量备份
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
@Module: hrbp.ehr.common
|
||||
@Description: HR 系统公共模块(登录、接口调用、会话管理、配置)
|
||||
"""
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
@Module: hrbp.ehr.common
|
||||
@Description: HR 系统公共模块(登录、接口调用、会话管理、配置)
|
||||
"""
|
||||
|
||||
@@ -1,130 +1,130 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
@Module: hrbp.ehr.common
|
||||
@FileName: config.py
|
||||
@Author: 小布丁
|
||||
@CreateTime: 2026-08-08 10:40
|
||||
@Description: HR 系统配置,集中管理接口地址、分页大小等常量(供各业务模块复用)
|
||||
@Version: 1.1.0
|
||||
"""
|
||||
|
||||
from app.service.hrbp.ehr.common.common_query import build_condition, encode_common_query
|
||||
|
||||
# ---------- 银行卡(工资卡)信息查询接口 ----------
|
||||
# 分页查询工资卡信息(aa.md 提供),返回 JSON
|
||||
WAGE_CARD_URL = "https://hr.37du.co/RedseaPlatform/getPageAjax/HrStaffWageCard.mc"
|
||||
|
||||
# 单页最大抓取条数
|
||||
PAGE_MAX_SIZE = 500
|
||||
|
||||
# ---------- 银行字典接口 ----------
|
||||
BANK_DICT_URL = "https://hr.37du.co/RedseaPlatform/PtCodeTypeValue.mc?method=getCodeValueByCodes"
|
||||
BANK_DICT_CODE_TYPE = "WAGE.BANKTYPE"
|
||||
BANK_DICT_EXPIRE_SEC = 7 * 24 * 60 * 60 # 缓存7天过期,自动重新拉取
|
||||
|
||||
# ---------- 员工花名册(自定义导出)页面 ----------
|
||||
# 花名册自定义导出页面
|
||||
ROSTER_URL = "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?clickFlag=true&treePermitType=permit&useSealTreeData=0&menuName=员工花名册"
|
||||
|
||||
# 待增减人员操作页面
|
||||
ADD_SUB_URL = "https://hr.37du.co/RedseaPlatform/PtPortal.mc?method=classic#ajax&1&nworktoday-40175-13664-23874-98879&nworktoday-40175-13664|/RedseaPlatform/hrRoster/7984ae1a-16ec-11ed-bea9-822ff8ed5b28/getCustomCommonList.mc?menuName=待增减人员"
|
||||
|
||||
# 预入职台账(排班异常识别)自定义导出页面(aa.md 提供)
|
||||
PRE_ENTRY_ROSTER_URL = "https://hr.37du.co/RedseaPlatform/PtPortal.mc?method=classic#ajax&1&nworktoday-40175-24311-01818-07406&nworktoday-40175-24311|/RedseaPlatform/hrRoster/10fe9cd6-b094-11ea-b588-14187743d052/getCustomCommonList.mc?_t=1787581570094&clickFlag=true&treePermitType=permit&useSealTreeData=0&menuName=预入职台账&_t=1787581570094"
|
||||
|
||||
# 调动台账(排班异常识别)自定义导出页面(aa.md 提供)
|
||||
TRANSFER_ROSTER_URL = "https://hr.37du.co/RedseaPlatform/PtPortal.mc?method=classic#ajax&1&nworktoday-40175-24311-01818-39687&nworktoday-40175-24311|/RedseaPlatform/hrRoster/1123d951-b094-11ea-b588-14187743d052/getCustomCommonList.mc?clickFlag=true&treePermitType=permit&useSealTreeData=0&menuName=%E8%B0%83%E5%8A%A8%E5%8F%B0%E8%B4%A6"
|
||||
|
||||
# 花名册自定义导出模板(下拉框中全部模板,后续各业务场景可按需选用)
|
||||
ROSTER_TEMPLATE_NAME = "员工基础信息" # 默认模板
|
||||
ROSTER_TEMPLATE_CADRE_SELECT = "干部选拔信息" # 干部选拔
|
||||
ROSTER_TEMPLATE_INDIVIDUAL_TAX = "个税申报基础信息" # 个税申报
|
||||
ROSTER_TEMPLATE_EMPLOYER_INSURANCE = "雇主险增减员导出模板" # 雇主险增减员
|
||||
ROSTER_TEMPLATE_SHIFT_ABNORMAL = "排班异常识别导出" # 排班异常识别(预入职台账)
|
||||
|
||||
# ---------- 考勤异常查询接口 ----------
|
||||
# 获取当前用户信息(用于校验 cookies 有效性,并取得查询考勤异常所需的 userId / rootId(treecode))
|
||||
GET_CUR_USER_INFO_URL = "https://hr.37du.co/RedseaPlatform/PtUsers.mc?method=getCurUserInfo"
|
||||
|
||||
# 分页查询考勤异常(aa.md 提供)
|
||||
ATTENDANCE_ABNORMAL_URL = "https://hr.37du.co/RedseaPlatform/kqController/getPageAjaxList.mc"
|
||||
|
||||
# 考勤异常确认/调整接口(abnormalIds=异常单据id,type=1 表示自动确认)
|
||||
ATTENDANCE_ADJUST_URL = "https://hr.37du.co/RedseaPlatform/abnormalAdjust/KqCountAbnormal.mc"
|
||||
|
||||
# 查询排班接口
|
||||
SHIFT_URL = "https://hr.37du.co/RedseaPlatform/redmagicapi/rf_p_kq_count_SelectBanci/getExecutePageResult.mc"
|
||||
|
||||
# 按部门查询排班集合接口(aa.md 提供):org_name=部门名,返回该部门全部排班
|
||||
# (data.list 记录含 work_date_name 排班名、org_name 部门名,逐条记录 = 一个排班)
|
||||
WORK_DATE_QUERY_URL = "https://hr.37du.co/RedseaPlatform/redmagicapi/rf_s_kq_work_date_query/redApiExec.mc"
|
||||
|
||||
# 查询请假记录接口
|
||||
LEAVE_URL = "https://hr.37du.co/RedseaPlatform/kqController/getPageAjaxList.mc"
|
||||
|
||||
# 查询加班记录接口
|
||||
OVERTIME_URL = "https://hr.37du.co/RedseaPlatform/kqController/getPageAjaxList.mc"
|
||||
|
||||
# 查询打卡记录接口
|
||||
KQ_DATA_URL = "https://hr.37du.co/RedseaPlatform/kqController/getPageAjaxList.mc"
|
||||
|
||||
# ---------- 考勤统计报表(逐日出勤,aa.md 提供) ----------
|
||||
# 分页查询"考勤统计报表",每人一行含 v_1~v_最后一天(当月逐日出勤状态),返回 JSON
|
||||
MONTH_ATT_REPORT_URL = "https://hr.37du.co/RedseaPlatform/pt/report/excel/detail/getPageAjax.mc"
|
||||
MONTH_ATT_REPORT_ID = "f880c52a619446e0b74e3820b898d53b"
|
||||
# 集团根组织 struId(aa.md 中 struId / belongUnitStruId / ds1.struId / ds2.stru_id 共用)
|
||||
COMPANY_STRU_ID = "596bae33-50e9-11ec-b526-822ff8ed5b28"
|
||||
|
||||
# ---------- 组织维护(组织设置)查询接口(aa.md 提供) ----------
|
||||
# 组织维护台账实时数据查询,返回 JSON(count/datas/pageCount)
|
||||
ORG_QUERY_URL = "https://hr.37du.co/RedseaPlatform/hrRoster/110118b4-b094-11ea-b588-14187743d052/queryRealTimeData.mc"
|
||||
ORG_TABLE_ID = "assemble-pt_organzation"
|
||||
ORG_ROSTER_ID = "110118b4-b094-11ea-b588-14187743d052"
|
||||
|
||||
# 组织维护查询固定入参(从浏览器抓包提取;登录用户变更时需同步更新 currentUserId / currentStaffId 等)
|
||||
# commonQuery 由前端加密算法自构造(等价于抓包原始串,即 in_use in ('1') 条件),
|
||||
# 需要追加/修改查询条件时直接改 ORG_QUERY_CONDITIONS 后重新加密即可
|
||||
ORG_QUERY_CONDITIONS = [
|
||||
build_condition("`pt_organzation.IN_USE`", "in", "1",
|
||||
query_text="1", left_bracket="(", right_bracket=")",
|
||||
input_type="select"),
|
||||
]
|
||||
|
||||
ORG_QUERY_BASE_PARAMS = {
|
||||
"menuName": "组织维护",
|
||||
"useSealTreeData": "0",
|
||||
"treePermitType": "permit",
|
||||
"cancelNodeClick": "1",
|
||||
"clickFlag": "true",
|
||||
"in_use": "1",
|
||||
"commonQuery": encode_common_query(ORG_QUERY_CONDITIONS),
|
||||
"newCondition": "",
|
||||
"urlConditions": "_t%3A1788589944798%23clickFlag%3Atrue%23cancelNodeClick%3A1%23treePermitType%3Apermit%23useSealTreeData%3A0%23menuName%3A%E7%BB%84%E7%BB%87%E7%BB%B4%E6%8A%A4%23_t%3A1788589944798%23",
|
||||
"exportConfig": "",
|
||||
"tableId": ORG_TABLE_ID,
|
||||
"rosterId": ORG_ROSTER_ID,
|
||||
"includeChildrenSetting": "",
|
||||
"struTreeCode": "cq37du",
|
||||
"djStruTreeCode": "",
|
||||
"djStruId": "",
|
||||
"djOrgName": "",
|
||||
"struId": COMPANY_STRU_ID,
|
||||
"belongUnitStruId": COMPANY_STRU_ID,
|
||||
"rootId": "cq37du",
|
||||
"isVirtual": "0",
|
||||
"currentUserRootId": "cq37du",
|
||||
"currentUserId": "178b0efa-8a65-11f1-a7d9-000c296f9469",
|
||||
"currentRoleIds": "POST_SYS_ADMIN,renshi",
|
||||
"currentStaffId": "1342173e-36cf-4160-8826-6b17d7d084a4",
|
||||
"baseHrefPath": "http://hr.37du.co:80RedseaPlatform",
|
||||
"qrCodeUrl": "jspresumepage-01.jsp",
|
||||
"orgName": "集团",
|
||||
"belongUnitOrgName": "集团",
|
||||
"throughParam": "",
|
||||
"sortType": "",
|
||||
"sortName": "",
|
||||
}
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
@Module: hrbp.ehr.common
|
||||
@FileName: config.py
|
||||
@Author: 小布丁
|
||||
@CreateTime: 2026-08-08 10:40
|
||||
@Description: HR 系统配置,集中管理接口地址、分页大小等常量(供各业务模块复用)
|
||||
@Version: 1.1.0
|
||||
"""
|
||||
|
||||
from app.service.hrbp.ehr.common.common_query import build_condition, encode_common_query
|
||||
|
||||
# ---------- 银行卡(工资卡)信息查询接口 ----------
|
||||
# 分页查询工资卡信息(aa.md 提供),返回 JSON
|
||||
WAGE_CARD_URL = "https://hr.37du.co/RedseaPlatform/getPageAjax/HrStaffWageCard.mc"
|
||||
|
||||
# 单页最大抓取条数
|
||||
PAGE_MAX_SIZE = 500
|
||||
|
||||
# ---------- 银行字典接口 ----------
|
||||
BANK_DICT_URL = "https://hr.37du.co/RedseaPlatform/PtCodeTypeValue.mc?method=getCodeValueByCodes"
|
||||
BANK_DICT_CODE_TYPE = "WAGE.BANKTYPE"
|
||||
BANK_DICT_EXPIRE_SEC = 7 * 24 * 60 * 60 # 缓存7天过期,自动重新拉取
|
||||
|
||||
# ---------- 员工花名册(自定义导出)页面 ----------
|
||||
# 花名册自定义导出页面
|
||||
ROSTER_URL = "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?clickFlag=true&treePermitType=permit&useSealTreeData=0&menuName=员工花名册"
|
||||
|
||||
# 待增减人员操作页面
|
||||
ADD_SUB_URL = "https://hr.37du.co/RedseaPlatform/PtPortal.mc?method=classic#ajax&1&nworktoday-40175-13664-23874-98879&nworktoday-40175-13664|/RedseaPlatform/hrRoster/7984ae1a-16ec-11ed-bea9-822ff8ed5b28/getCustomCommonList.mc?menuName=待增减人员"
|
||||
|
||||
# 预入职台账(排班异常识别)自定义导出页面(aa.md 提供)
|
||||
PRE_ENTRY_ROSTER_URL = "https://hr.37du.co/RedseaPlatform/PtPortal.mc?method=classic#ajax&1&nworktoday-40175-24311-01818-07406&nworktoday-40175-24311|/RedseaPlatform/hrRoster/10fe9cd6-b094-11ea-b588-14187743d052/getCustomCommonList.mc?_t=1787581570094&clickFlag=true&treePermitType=permit&useSealTreeData=0&menuName=预入职台账&_t=1787581570094"
|
||||
|
||||
# 调动台账(排班异常识别)自定义导出页面(aa.md 提供)
|
||||
TRANSFER_ROSTER_URL = "https://hr.37du.co/RedseaPlatform/PtPortal.mc?method=classic#ajax&1&nworktoday-40175-24311-01818-39687&nworktoday-40175-24311|/RedseaPlatform/hrRoster/1123d951-b094-11ea-b588-14187743d052/getCustomCommonList.mc?clickFlag=true&treePermitType=permit&useSealTreeData=0&menuName=%E8%B0%83%E5%8A%A8%E5%8F%B0%E8%B4%A6"
|
||||
|
||||
# 花名册自定义导出模板(下拉框中全部模板,后续各业务场景可按需选用)
|
||||
ROSTER_TEMPLATE_NAME = "员工基础信息" # 默认模板
|
||||
ROSTER_TEMPLATE_CADRE_SELECT = "干部选拔信息" # 干部选拔
|
||||
ROSTER_TEMPLATE_INDIVIDUAL_TAX = "个税申报基础信息" # 个税申报
|
||||
ROSTER_TEMPLATE_EMPLOYER_INSURANCE = "雇主险增减员导出模板" # 雇主险增减员
|
||||
ROSTER_TEMPLATE_SHIFT_ABNORMAL = "排班异常识别导出" # 排班异常识别(预入职台账)
|
||||
|
||||
# ---------- 考勤异常查询接口 ----------
|
||||
# 获取当前用户信息(用于校验 cookies 有效性,并取得查询考勤异常所需的 userId / rootId(treecode))
|
||||
GET_CUR_USER_INFO_URL = "https://hr.37du.co/RedseaPlatform/PtUsers.mc?method=getCurUserInfo"
|
||||
|
||||
# 分页查询考勤异常(aa.md 提供)
|
||||
ATTENDANCE_ABNORMAL_URL = "https://hr.37du.co/RedseaPlatform/kqController/getPageAjaxList.mc"
|
||||
|
||||
# 考勤异常确认/调整接口(abnormalIds=异常单据id,type=1 表示自动确认)
|
||||
ATTENDANCE_ADJUST_URL = "https://hr.37du.co/RedseaPlatform/abnormalAdjust/KqCountAbnormal.mc"
|
||||
|
||||
# 查询排班接口
|
||||
SHIFT_URL = "https://hr.37du.co/RedseaPlatform/redmagicapi/rf_p_kq_count_SelectBanci/getExecutePageResult.mc"
|
||||
|
||||
# 按部门查询排班集合接口(aa.md 提供):org_name=部门名,返回该部门全部排班
|
||||
# (data.list 记录含 work_date_name 排班名、org_name 部门名,逐条记录 = 一个排班)
|
||||
WORK_DATE_QUERY_URL = "https://hr.37du.co/RedseaPlatform/redmagicapi/rf_s_kq_work_date_query/redApiExec.mc"
|
||||
|
||||
# 查询请假记录接口
|
||||
LEAVE_URL = "https://hr.37du.co/RedseaPlatform/kqController/getPageAjaxList.mc"
|
||||
|
||||
# 查询加班记录接口
|
||||
OVERTIME_URL = "https://hr.37du.co/RedseaPlatform/kqController/getPageAjaxList.mc"
|
||||
|
||||
# 查询打卡记录接口
|
||||
KQ_DATA_URL = "https://hr.37du.co/RedseaPlatform/kqController/getPageAjaxList.mc"
|
||||
|
||||
# ---------- 考勤统计报表(逐日出勤,aa.md 提供) ----------
|
||||
# 分页查询"考勤统计报表",每人一行含 v_1~v_最后一天(当月逐日出勤状态),返回 JSON
|
||||
MONTH_ATT_REPORT_URL = "https://hr.37du.co/RedseaPlatform/pt/report/excel/detail/getPageAjax.mc"
|
||||
MONTH_ATT_REPORT_ID = "f880c52a619446e0b74e3820b898d53b"
|
||||
# 集团根组织 struId(aa.md 中 struId / belongUnitStruId / ds1.struId / ds2.stru_id 共用)
|
||||
COMPANY_STRU_ID = "596bae33-50e9-11ec-b526-822ff8ed5b28"
|
||||
|
||||
# ---------- 组织维护(组织设置)查询接口(aa.md 提供) ----------
|
||||
# 组织维护台账实时数据查询,返回 JSON(count/datas/pageCount)
|
||||
ORG_QUERY_URL = "https://hr.37du.co/RedseaPlatform/hrRoster/110118b4-b094-11ea-b588-14187743d052/queryRealTimeData.mc"
|
||||
ORG_TABLE_ID = "assemble-pt_organzation"
|
||||
ORG_ROSTER_ID = "110118b4-b094-11ea-b588-14187743d052"
|
||||
|
||||
# 组织维护查询固定入参(从浏览器抓包提取;登录用户变更时需同步更新 currentUserId / currentStaffId 等)
|
||||
# commonQuery 由前端加密算法自构造(等价于抓包原始串,即 in_use in ('1') 条件),
|
||||
# 需要追加/修改查询条件时直接改 ORG_QUERY_CONDITIONS 后重新加密即可
|
||||
ORG_QUERY_CONDITIONS = [
|
||||
build_condition("`pt_organzation.IN_USE`", "in", "1",
|
||||
query_text="1", left_bracket="(", right_bracket=")",
|
||||
input_type="select"),
|
||||
]
|
||||
|
||||
ORG_QUERY_BASE_PARAMS = {
|
||||
"menuName": "组织维护",
|
||||
"useSealTreeData": "0",
|
||||
"treePermitType": "permit",
|
||||
"cancelNodeClick": "1",
|
||||
"clickFlag": "true",
|
||||
"in_use": "1",
|
||||
"commonQuery": encode_common_query(ORG_QUERY_CONDITIONS),
|
||||
"newCondition": "",
|
||||
"urlConditions": "_t%3A1788589944798%23clickFlag%3Atrue%23cancelNodeClick%3A1%23treePermitType%3Apermit%23useSealTreeData%3A0%23menuName%3A%E7%BB%84%E7%BB%87%E7%BB%B4%E6%8A%A4%23_t%3A1788589944798%23",
|
||||
"exportConfig": "",
|
||||
"tableId": ORG_TABLE_ID,
|
||||
"rosterId": ORG_ROSTER_ID,
|
||||
"includeChildrenSetting": "",
|
||||
"struTreeCode": "cq37du",
|
||||
"djStruTreeCode": "",
|
||||
"djStruId": "",
|
||||
"djOrgName": "",
|
||||
"struId": COMPANY_STRU_ID,
|
||||
"belongUnitStruId": COMPANY_STRU_ID,
|
||||
"rootId": "cq37du",
|
||||
"isVirtual": "0",
|
||||
"currentUserRootId": "cq37du",
|
||||
"currentUserId": "178b0efa-8a65-11f1-a7d9-000c296f9469",
|
||||
"currentRoleIds": "POST_SYS_ADMIN,renshi",
|
||||
"currentStaffId": "1342173e-36cf-4160-8826-6b17d7d084a4",
|
||||
"baseHrefPath": "http://hr.37du.co:80RedseaPlatform",
|
||||
"qrCodeUrl": "jspresumepage-01.jsp",
|
||||
"orgName": "集团",
|
||||
"belongUnitOrgName": "集团",
|
||||
"throughParam": "",
|
||||
"sortType": "",
|
||||
"sortName": "",
|
||||
}
|
||||
|
||||
# ---------- 员工花名册(实时数据查询接口,纯 API 版) ----------
|
||||
# 花名册台账实时数据查询(与组织维护 queryRealTimeData 同模式),返回 JSON(count/datas/pageCount)
|
||||
ROSTER_QUERY_URL = "https://hr.37du.co/RedseaPlatform/hrRoster/1116da64-b094-11ea-b588-14187743d052/queryRealTimeData.mc"
|
||||
@@ -183,6 +183,6 @@ ROSTER_QUERY_BASE_PARAMS = {
|
||||
"hideCols": "",
|
||||
}
|
||||
|
||||
# 假期类型编码映射已上移到 HR 平台共享层 app/service/hrbp/common/config.py(VACATION_TYPE_MAP),
|
||||
# 由 ehr / oa 两系统统一引用,避免 oa 反向依赖 ehr。需要时从此处 import:
|
||||
# from app.service.hrbp.common.config import VACATION_TYPE_MAP
|
||||
# 假期类型编码映射已上移到 HR 平台共享层 app/service/hrbp/common/config.py(VACATION_TYPE_MAP),
|
||||
# 由 ehr / oa 两系统统一引用,避免 oa 反向依赖 ehr。需要时从此处 import:
|
||||
# from app.service.hrbp.common.config import VACATION_TYPE_MAP
|
||||
|
||||
@@ -1,88 +1,88 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
@Module: hrbp.ehr.common
|
||||
@FileName: hr_api/__init__.py
|
||||
@Description: HR 系统 API 包,按接口拆分到各子模块,此处统一导出(保持 from ...hr_api import X 兼容)
|
||||
@Version: 2.0.0
|
||||
"""
|
||||
|
||||
from app.service.hrbp.common.hr_session import HRSessionExpiredError, _is_expired, hr_request_json
|
||||
from app.service.hrbp.ehr.common.hr_api.wage_card import fetch_wage_card_page, fetch_all_wage_card
|
||||
from app.service.hrbp.ehr.common.hr_api.bank_dict import get_bank_dict, bank_type_to_name
|
||||
from app.service.hrbp.ehr.common.hr_api.attendance import (
|
||||
fetch_cur_user_info,
|
||||
fetch_attendance_abnormal_page,
|
||||
fetch_all_attendance_abnormal,
|
||||
adjust_abnormal,
|
||||
)
|
||||
from app.service.hrbp.ehr.common.hr_api.shift import fetch_shift_page, fetch_all_shift, fetch_work_date_page, fetch_all_work_date
|
||||
from app.service.hrbp.ehr.common.hr_api.leave import fetch_leave_page, fetch_all_leave
|
||||
from app.service.hrbp.ehr.common.hr_api.overtime import fetch_overtime_page, fetch_all_overtime
|
||||
from app.service.hrbp.ehr.common.hr_api.kq_data import fetch_kq_data_page, fetch_all_kq_data
|
||||
from app.service.hrbp.ehr.common.hr_api.attendance_stat import (
|
||||
fetch_attendance_stat_page,
|
||||
fetch_all_attendance_stat,
|
||||
)
|
||||
from app.service.hrbp.ehr.common.hr_api.org import fetch_org_page, fetch_all_orgs, to_org_rows
|
||||
from app.service.hrbp.ehr.common.hr_api.roster import (
|
||||
fetch_roster_page,
|
||||
fetch_all_rosters,
|
||||
to_roster_rows,
|
||||
build_leave_conditions,
|
||||
build_in_service_conditions,
|
||||
fetch_roster_code_dicts,
|
||||
)
|
||||
from app.service.hrbp.ehr.common.hr_api.code_dict import get_code_dicts, code_to_name
|
||||
from app.service.hrbp.ehr.common.hr_api.roster_export import export_common_list, export_roster_excel
|
||||
|
||||
__all__ = [
|
||||
# base
|
||||
"HRSessionExpiredError",
|
||||
"_is_expired",
|
||||
"hr_request_json",
|
||||
# wage_card
|
||||
"fetch_wage_card_page",
|
||||
"fetch_all_wage_card",
|
||||
# bank_dict
|
||||
"get_bank_dict",
|
||||
"bank_type_to_name",
|
||||
# attendance
|
||||
"fetch_cur_user_info",
|
||||
"fetch_attendance_abnormal_page",
|
||||
"fetch_all_attendance_abnormal",
|
||||
"adjust_abnormal",
|
||||
# shift
|
||||
"fetch_shift_page",
|
||||
"fetch_all_shift",
|
||||
"fetch_work_date_page",
|
||||
"fetch_all_work_date",
|
||||
# leave
|
||||
"fetch_leave_page",
|
||||
"fetch_all_leave",
|
||||
# overtime
|
||||
"fetch_overtime_page",
|
||||
"fetch_all_overtime",
|
||||
# kq_data
|
||||
"fetch_kq_data_page",
|
||||
"fetch_all_kq_data",
|
||||
# attendance_stat
|
||||
"fetch_attendance_stat_page",
|
||||
"fetch_all_attendance_stat",
|
||||
# org
|
||||
"fetch_org_page",
|
||||
"fetch_all_orgs",
|
||||
"to_org_rows",
|
||||
# roster
|
||||
"fetch_roster_page",
|
||||
"fetch_all_rosters",
|
||||
"to_roster_rows",
|
||||
"build_leave_conditions",
|
||||
"build_in_service_conditions",
|
||||
"fetch_roster_code_dicts",
|
||||
# code_dict
|
||||
"get_code_dicts",
|
||||
"code_to_name",
|
||||
# roster_export
|
||||
"export_common_list",
|
||||
"export_roster_excel",
|
||||
]
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
@Module: hrbp.ehr.common
|
||||
@FileName: hr_api/__init__.py
|
||||
@Description: HR 系统 API 包,按接口拆分到各子模块,此处统一导出(保持 from ...hr_api import X 兼容)
|
||||
@Version: 2.0.0
|
||||
"""
|
||||
|
||||
from app.service.hrbp.common.hr_session import HRSessionExpiredError, _is_expired, hr_request_json
|
||||
from app.service.hrbp.ehr.common.hr_api.wage_card import fetch_wage_card_page, fetch_all_wage_card
|
||||
from app.service.hrbp.ehr.common.hr_api.bank_dict import get_bank_dict, bank_type_to_name
|
||||
from app.service.hrbp.ehr.common.hr_api.attendance import (
|
||||
fetch_cur_user_info,
|
||||
fetch_attendance_abnormal_page,
|
||||
fetch_all_attendance_abnormal,
|
||||
adjust_abnormal,
|
||||
)
|
||||
from app.service.hrbp.ehr.common.hr_api.shift import fetch_shift_page, fetch_all_shift, fetch_work_date_page, fetch_all_work_date
|
||||
from app.service.hrbp.ehr.common.hr_api.leave import fetch_leave_page, fetch_all_leave
|
||||
from app.service.hrbp.ehr.common.hr_api.overtime import fetch_overtime_page, fetch_all_overtime
|
||||
from app.service.hrbp.ehr.common.hr_api.kq_data import fetch_kq_data_page, fetch_all_kq_data
|
||||
from app.service.hrbp.ehr.common.hr_api.attendance_stat import (
|
||||
fetch_attendance_stat_page,
|
||||
fetch_all_attendance_stat,
|
||||
)
|
||||
from app.service.hrbp.ehr.common.hr_api.org import fetch_org_page, fetch_all_orgs, to_org_rows
|
||||
from app.service.hrbp.ehr.common.hr_api.roster import (
|
||||
fetch_roster_page,
|
||||
fetch_all_rosters,
|
||||
to_roster_rows,
|
||||
build_leave_conditions,
|
||||
build_in_service_conditions,
|
||||
fetch_roster_code_dicts,
|
||||
)
|
||||
from app.service.hrbp.ehr.common.hr_api.code_dict import get_code_dicts, code_to_name
|
||||
from app.service.hrbp.ehr.common.hr_api.roster_export import export_common_list, export_roster_excel
|
||||
|
||||
__all__ = [
|
||||
# base
|
||||
"HRSessionExpiredError",
|
||||
"_is_expired",
|
||||
"hr_request_json",
|
||||
# wage_card
|
||||
"fetch_wage_card_page",
|
||||
"fetch_all_wage_card",
|
||||
# bank_dict
|
||||
"get_bank_dict",
|
||||
"bank_type_to_name",
|
||||
# attendance
|
||||
"fetch_cur_user_info",
|
||||
"fetch_attendance_abnormal_page",
|
||||
"fetch_all_attendance_abnormal",
|
||||
"adjust_abnormal",
|
||||
# shift
|
||||
"fetch_shift_page",
|
||||
"fetch_all_shift",
|
||||
"fetch_work_date_page",
|
||||
"fetch_all_work_date",
|
||||
# leave
|
||||
"fetch_leave_page",
|
||||
"fetch_all_leave",
|
||||
# overtime
|
||||
"fetch_overtime_page",
|
||||
"fetch_all_overtime",
|
||||
# kq_data
|
||||
"fetch_kq_data_page",
|
||||
"fetch_all_kq_data",
|
||||
# attendance_stat
|
||||
"fetch_attendance_stat_page",
|
||||
"fetch_all_attendance_stat",
|
||||
# org
|
||||
"fetch_org_page",
|
||||
"fetch_all_orgs",
|
||||
"to_org_rows",
|
||||
# roster
|
||||
"fetch_roster_page",
|
||||
"fetch_all_rosters",
|
||||
"to_roster_rows",
|
||||
"build_leave_conditions",
|
||||
"build_in_service_conditions",
|
||||
"fetch_roster_code_dicts",
|
||||
# code_dict
|
||||
"get_code_dicts",
|
||||
"code_to_name",
|
||||
# roster_export
|
||||
"export_common_list",
|
||||
"export_roster_excel",
|
||||
]
|
||||
|
||||
@@ -1,145 +1,145 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
@Module: hrbp.ehr.common.hr_api
|
||||
@FileName: attendance_stat.py
|
||||
@Description: 考勤统计报表(逐日出勤)查询接口:
|
||||
- fetch_attendance_stat_page:请求单页报表数据
|
||||
- fetch_all_attendance_stat:分页抓取某月全集团逐日出勤明细(每人一行,含 v_1~v_最后一天)
|
||||
- 登录态过期自动重登(复用 hr_session)
|
||||
@Version: 1.0.0
|
||||
"""
|
||||
|
||||
import time
|
||||
from typing import Any, Dict, List
|
||||
|
||||
from app.utils.logger import get_logger
|
||||
from app.service.hrbp.ehr.common.config import (
|
||||
MONTH_ATT_REPORT_URL,
|
||||
MONTH_ATT_REPORT_ID,
|
||||
COMPANY_STRU_ID,
|
||||
)
|
||||
from app.service.hrbp.common.hr_session import HRSessionExpiredError, hr_request_json
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
# 报表接口单页最大支持 1000 条(用户确认),全集团一次拉取即可减少翻页请求
|
||||
REPORT_PAGE_SIZE = 1000
|
||||
|
||||
|
||||
def fetch_attendance_stat_page(
|
||||
session,
|
||||
user_id: str,
|
||||
month: str,
|
||||
page_no: int = 1,
|
||||
page_size: int = REPORT_PAGE_SIZE,
|
||||
stru_id: str = COMPANY_STRU_ID,
|
||||
base_code: str = "",
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
请求单页"考勤统计报表"数据(aa.md 提供的接口入参)。
|
||||
|
||||
Args:
|
||||
session: 已登录的 requests.Session 对象
|
||||
user_id: 由 getCurUserInfo 返回的 userId(当前登录用户)
|
||||
month: 查询月份 "YYYYMM"
|
||||
page_no: 页码(从 1 开始)
|
||||
page_size: 每页条数(单页最大 1000)
|
||||
stru_id: 集团根组织 struId,默认 COMPANY_STRU_ID
|
||||
base_code: 员工工号;非空时仅查该员工(用于跨月追溯单人查询)
|
||||
|
||||
Returns:
|
||||
接口返回的 JSON 字典(datas 为明细数组,pageCount 为总页数)
|
||||
|
||||
Raises:
|
||||
RuntimeError: 请求失败或响应异常
|
||||
HRSessionExpiredError: 登录态过期(接口返回非 JSON)
|
||||
"""
|
||||
params = {
|
||||
"reportId": MONTH_ATT_REPORT_ID,
|
||||
"struId": stru_id,
|
||||
"start": (page_no - 1) * page_size,
|
||||
"sortType": "",
|
||||
"sortName": "",
|
||||
"pageNo": page_no,
|
||||
"pageSize": page_size,
|
||||
"ds1.userId": user_id,
|
||||
"ds1.struId": stru_id,
|
||||
"ds1.month": month,
|
||||
"ds2.stru_id": stru_id,
|
||||
"ds3.month": "#ds1.month#",
|
||||
"orgTypeCode": "1",
|
||||
"rootId": "cq37du",
|
||||
"showSetField": "1",
|
||||
"menuName": "考勤统计报表",
|
||||
"treePermitType": "permit",
|
||||
"struTreeCode": "cq37du",
|
||||
"belongUnitStruId": stru_id,
|
||||
"isVirtual": "0",
|
||||
"isHistory": "undefined",
|
||||
"useSealTreeData": "0",
|
||||
"orgAlias": "集团",
|
||||
"commonQuery": "[]",
|
||||
"ds1.base_code": base_code,
|
||||
}
|
||||
url = f"{MONTH_ATT_REPORT_URL}?reportsId={MONTH_ATT_REPORT_ID}"
|
||||
return hr_request_json(session, "POST", url, params, "考勤统计报表")
|
||||
|
||||
|
||||
def fetch_all_attendance_stat(
|
||||
session,
|
||||
user_id: str,
|
||||
month: str,
|
||||
stru_id: str = COMPANY_STRU_ID,
|
||||
base_code: str = "",
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
分页抓取某月考勤统计报表明细(每人一行,含 v_1~v_最后一天)。
|
||||
|
||||
Args:
|
||||
session: 已登录的 requests.Session 对象
|
||||
user_id: 由 getCurUserInfo 返回的 userId
|
||||
month: 查询月份 "YYYYMM"
|
||||
stru_id: 集团根组织 struId,默认 COMPANY_STRU_ID
|
||||
base_code: 员工工号;非空时仅查该员工(用于跨月追溯单人查询)
|
||||
|
||||
Returns:
|
||||
报表明细列表(接口 datas 字段内容)
|
||||
|
||||
Raises:
|
||||
HRSessionExpiredError: 登录态过期且重新登录后仍失败
|
||||
"""
|
||||
all_rows: List[Dict[str, Any]] = []
|
||||
page_no = 1
|
||||
while True:
|
||||
try:
|
||||
data = fetch_attendance_stat_page(session, user_id, month, page_no,
|
||||
REPORT_PAGE_SIZE, stru_id, base_code)
|
||||
except HRSessionExpiredError:
|
||||
logger.warning("考勤统计报表 HR 登录态过期,重新登录后续抓")
|
||||
from app.service.hrbp.common.hr_session import refresh_hr_session
|
||||
session = refresh_hr_session()
|
||||
# 重新登录后需重新获取当前用户 userId
|
||||
from app.service.hrbp.ehr.common.hr_api.attendance import fetch_cur_user_info
|
||||
user_id = fetch_cur_user_info(session).get("userId", "")
|
||||
data = fetch_attendance_stat_page(session, user_id, month, page_no,
|
||||
REPORT_PAGE_SIZE, stru_id, base_code)
|
||||
|
||||
if data.get("state") != "1":
|
||||
logger.error("考勤统计报表第%d页请求失败:%s", page_no, data.get("meg"))
|
||||
break
|
||||
|
||||
page_list = data.get("datas", []) or []
|
||||
if not page_list:
|
||||
logger.info("考勤统计报表无更多数据")
|
||||
break
|
||||
|
||||
all_rows.extend(page_list)
|
||||
|
||||
total_page = data.get("pageCount", 0)
|
||||
logger.info("考勤统计报表已抓取 %d/%d 页,累计 %d 条",
|
||||
page_no, total_page, len(all_rows))
|
||||
if page_no >= total_page:
|
||||
break
|
||||
page_no += 1
|
||||
time.sleep(0.2) # 轻微限速,避免触发风控
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
@Module: hrbp.ehr.common.hr_api
|
||||
@FileName: attendance_stat.py
|
||||
@Description: 考勤统计报表(逐日出勤)查询接口:
|
||||
- fetch_attendance_stat_page:请求单页报表数据
|
||||
- fetch_all_attendance_stat:分页抓取某月全集团逐日出勤明细(每人一行,含 v_1~v_最后一天)
|
||||
- 登录态过期自动重登(复用 hr_session)
|
||||
@Version: 1.0.0
|
||||
"""
|
||||
|
||||
import time
|
||||
from typing import Any, Dict, List
|
||||
|
||||
from app.utils.logger import get_logger
|
||||
from app.service.hrbp.ehr.common.config import (
|
||||
MONTH_ATT_REPORT_URL,
|
||||
MONTH_ATT_REPORT_ID,
|
||||
COMPANY_STRU_ID,
|
||||
)
|
||||
from app.service.hrbp.common.hr_session import HRSessionExpiredError, hr_request_json
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
# 报表接口单页最大支持 1000 条(用户确认),全集团一次拉取即可减少翻页请求
|
||||
REPORT_PAGE_SIZE = 1000
|
||||
|
||||
|
||||
def fetch_attendance_stat_page(
|
||||
session,
|
||||
user_id: str,
|
||||
month: str,
|
||||
page_no: int = 1,
|
||||
page_size: int = REPORT_PAGE_SIZE,
|
||||
stru_id: str = COMPANY_STRU_ID,
|
||||
base_code: str = "",
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
请求单页"考勤统计报表"数据(aa.md 提供的接口入参)。
|
||||
|
||||
Args:
|
||||
session: 已登录的 requests.Session 对象
|
||||
user_id: 由 getCurUserInfo 返回的 userId(当前登录用户)
|
||||
month: 查询月份 "YYYYMM"
|
||||
page_no: 页码(从 1 开始)
|
||||
page_size: 每页条数(单页最大 1000)
|
||||
stru_id: 集团根组织 struId,默认 COMPANY_STRU_ID
|
||||
base_code: 员工工号;非空时仅查该员工(用于跨月追溯单人查询)
|
||||
|
||||
Returns:
|
||||
接口返回的 JSON 字典(datas 为明细数组,pageCount 为总页数)
|
||||
|
||||
Raises:
|
||||
RuntimeError: 请求失败或响应异常
|
||||
HRSessionExpiredError: 登录态过期(接口返回非 JSON)
|
||||
"""
|
||||
params = {
|
||||
"reportId": MONTH_ATT_REPORT_ID,
|
||||
"struId": stru_id,
|
||||
"start": (page_no - 1) * page_size,
|
||||
"sortType": "",
|
||||
"sortName": "",
|
||||
"pageNo": page_no,
|
||||
"pageSize": page_size,
|
||||
"ds1.userId": user_id,
|
||||
"ds1.struId": stru_id,
|
||||
"ds1.month": month,
|
||||
"ds2.stru_id": stru_id,
|
||||
"ds3.month": "#ds1.month#",
|
||||
"orgTypeCode": "1",
|
||||
"rootId": "cq37du",
|
||||
"showSetField": "1",
|
||||
"menuName": "考勤统计报表",
|
||||
"treePermitType": "permit",
|
||||
"struTreeCode": "cq37du",
|
||||
"belongUnitStruId": stru_id,
|
||||
"isVirtual": "0",
|
||||
"isHistory": "undefined",
|
||||
"useSealTreeData": "0",
|
||||
"orgAlias": "集团",
|
||||
"commonQuery": "[]",
|
||||
"ds1.base_code": base_code,
|
||||
}
|
||||
url = f"{MONTH_ATT_REPORT_URL}?reportsId={MONTH_ATT_REPORT_ID}"
|
||||
return hr_request_json(session, "POST", url, params, "考勤统计报表")
|
||||
|
||||
|
||||
def fetch_all_attendance_stat(
|
||||
session,
|
||||
user_id: str,
|
||||
month: str,
|
||||
stru_id: str = COMPANY_STRU_ID,
|
||||
base_code: str = "",
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
分页抓取某月考勤统计报表明细(每人一行,含 v_1~v_最后一天)。
|
||||
|
||||
Args:
|
||||
session: 已登录的 requests.Session 对象
|
||||
user_id: 由 getCurUserInfo 返回的 userId
|
||||
month: 查询月份 "YYYYMM"
|
||||
stru_id: 集团根组织 struId,默认 COMPANY_STRU_ID
|
||||
base_code: 员工工号;非空时仅查该员工(用于跨月追溯单人查询)
|
||||
|
||||
Returns:
|
||||
报表明细列表(接口 datas 字段内容)
|
||||
|
||||
Raises:
|
||||
HRSessionExpiredError: 登录态过期且重新登录后仍失败
|
||||
"""
|
||||
all_rows: List[Dict[str, Any]] = []
|
||||
page_no = 1
|
||||
while True:
|
||||
try:
|
||||
data = fetch_attendance_stat_page(session, user_id, month, page_no,
|
||||
REPORT_PAGE_SIZE, stru_id, base_code)
|
||||
except HRSessionExpiredError:
|
||||
logger.warning("考勤统计报表 HR 登录态过期,重新登录后续抓")
|
||||
from app.service.hrbp.common.hr_session import refresh_hr_session
|
||||
session = refresh_hr_session()
|
||||
# 重新登录后需重新获取当前用户 userId
|
||||
from app.service.hrbp.ehr.common.hr_api.attendance import fetch_cur_user_info
|
||||
user_id = fetch_cur_user_info(session).get("userId", "")
|
||||
data = fetch_attendance_stat_page(session, user_id, month, page_no,
|
||||
REPORT_PAGE_SIZE, stru_id, base_code)
|
||||
|
||||
if data.get("state") != "1":
|
||||
logger.error("考勤统计报表第%d页请求失败:%s", page_no, data.get("meg"))
|
||||
break
|
||||
|
||||
page_list = data.get("datas", []) or []
|
||||
if not page_list:
|
||||
logger.info("考勤统计报表无更多数据")
|
||||
break
|
||||
|
||||
all_rows.extend(page_list)
|
||||
|
||||
total_page = data.get("pageCount", 0)
|
||||
logger.info("考勤统计报表已抓取 %d/%d 页,累计 %d 条",
|
||||
page_no, total_page, len(all_rows))
|
||||
if page_no >= total_page:
|
||||
break
|
||||
page_no += 1
|
||||
time.sleep(0.2) # 轻微限速,避免触发风控
|
||||
return all_rows
|
||||
Reference in New Issue
Block a user