feat(XQ0008): 新增 HR 接口数据源及花名册 fallback 逻辑,修复 OA 推送附件上传 Content-Type 问题
- 新增 HR 花名册接口拉取逻辑,优先从 HR 接口获取花名册,失败回退源表/本地文件 - 新增推送人映射支持所属单位回退值,新增「水庄大鹅事业部」映射 - 修复 OA 推送附件上传时清除默认 Content-Type,避免 multipart 请求被服务端拒绝 - 优化二级部门解析逻辑,为空时用所属单位替代,避免中断流程 - 新增 store_point_api.py 和 attendance_points_push.py 积分推送模块,新增 store_login_api.py 门店登录模块 - 新增 notice_gen.py 中 HR 接口加密逻辑及多数据源 fallback 处理
This commit is contained in:
@@ -48,7 +48,7 @@ class ChongqingSocialChangePlugin(ScenePlugin):
|
||||
|
||||
id = "xq0008"
|
||||
name = "重庆社保增减员办理"
|
||||
version = "1.0.3"
|
||||
version = "1.0.5"
|
||||
description = ("重庆社保增减员全流程(XQ0008 名单制作 + XQ0014 系统办理/核查回盘 + "
|
||||
"XQ0015/XQ0016 告知书制作下发):目录预检、增/减员名单制作、增/减员系统办理、"
|
||||
"增/减员核查回盘、告知书制作与 OA 推送八阶段可选串行。逐参保单位读取台账账号"
|
||||
@@ -142,6 +142,12 @@ class ChongqingSocialChangePlugin(ScenePlugin):
|
||||
|
||||
def _run_notice(self, ctx):
|
||||
"""告知书制作:生成三类告知书 + 构造 OA 推送数据;按开关自动推送。"""
|
||||
# 花名册优先走 HR 接口取数(需已登录 HR);未登录/失效时回退源表「附-在职花名册」/本地文件
|
||||
try:
|
||||
config.set_hr_session(ctx.get_session("hr"))
|
||||
except Exception as e:
|
||||
config.set_hr_session(None)
|
||||
ctx.log(f"HR 登录态不可用,花名册将回退源表/本地文件:{e}", "WARN")
|
||||
result = notice_gen.make_notices()
|
||||
summary_parts = [f"生成 {result['total']} 份告知书(docx+pdf)",
|
||||
f"构造 {result['messages_count']} 条 OA 推送数据"]
|
||||
|
||||
@@ -242,13 +242,15 @@ LEGACY_PLACEHOLDERS = {
|
||||
"{{当前月+1}}": "{{下月}}",
|
||||
"{{费用*2}}": "{{一次性扣款}}",
|
||||
}
|
||||
# 二级部门(经营中心)推送人映射(优先于花名册人事查找)
|
||||
# 推送人映射:键可为「二级部门(经营中心)」或「二级部门为空时的所属单位回退值」(如 水庄大鹅事业部)。
|
||||
# 优先于花名册人事查找(覆盖映射不依赖员工是否在花名册)。
|
||||
DEPT2_PUSH_OVERRIDE = {
|
||||
"金色印象海口经营中心": ["37000700"],
|
||||
"金色印象昆明经营中心": ["37002511"],
|
||||
"金色印象南宁经营中心": ["37009626"],
|
||||
"金色印象深圳经营中心": ["37018211"],
|
||||
"金色印象郑州经营中心": ["37006992"],
|
||||
"水庄大鹅事业部": ["37036104"], # 所属单位回退值(非二级部门),直接推送 37036104 唐佳膑
|
||||
}
|
||||
DEPT2_HR_OVERRIDE = {"石桥铺会馆": ["37001302"]}
|
||||
CC_RECEIVER_NAME = "周卫"
|
||||
@@ -483,6 +485,19 @@ def get_oa_session():
|
||||
return _oa_session
|
||||
|
||||
|
||||
# ==================== 花名册数据源钩子(run() 注入) ====================
|
||||
_hr_session = None # 底座注入的 HR requests.Session(花名册接口取数用,未登录为 None)
|
||||
|
||||
|
||||
def set_hr_session(session):
|
||||
global _hr_session
|
||||
_hr_session = session
|
||||
|
||||
|
||||
def get_hr_session():
|
||||
return _hr_session
|
||||
|
||||
|
||||
# ==================== 通用辅助 ====================
|
||||
def _to_text(value):
|
||||
"""转可写文本:证件号/电话等长数字统一为字符串,避免丢精度/科学计数。"""
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
OA 工作沟通推送数据:build_work_communication_data 构造后落盘到
|
||||
{输出}/YYYYMM/oa_messages.json;真实 OA 推送由 __init__ 阶段(启用推送开关时)调 oa_push 完成。
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
@@ -24,7 +25,7 @@ import random
|
||||
import functools
|
||||
import subprocess
|
||||
from copy import deepcopy
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from .. import config
|
||||
|
||||
@@ -434,6 +435,246 @@ def _read_roster_map(roster_path: str) -> dict:
|
||||
wb.close()
|
||||
|
||||
|
||||
# ==================== 花名册数据源:HR 接口 → 源表「附-在职花名册」→ 本地文件 ====================
|
||||
# HR 花名册直查接口(与共享模块 roster_export_api.py 同款参数,插件自包含复刻)
|
||||
_HR_API_ROSTER_ID = "1116da64-b094-11ea-b588-14187743d052"
|
||||
_HR_API_LIST_URL = (f"https://hr.37du.co/RedseaPlatform/hrRoster/"
|
||||
f"{_HR_API_ROSTER_ID}/getCustomCommonList.mc")
|
||||
_HR_API_BASE_PARAMS = {
|
||||
"menuName": "员工花名册", "useSealTreeData": "0", "treePermitType": "permit",
|
||||
"cancelNodeClick": "1", "clickFlag": "true", "in_use": "1", "commonQuery": "",
|
||||
"newCondition": "", "urlConditions": "", "exportConfig": "",
|
||||
"tableId": "assemble-hr_staff_base", "rosterId": _HR_API_ROSTER_ID,
|
||||
"includeChildrenSetting": "", "struTreeCode": "cq37du", "djStruTreeCode": "",
|
||||
"djStruId": "", "djOrgName": "", "struId": "596bae33-50e9-11ec-b526-822ff8ed5b28",
|
||||
"belongUnitStruId": "596bae33-50e9-11ec-b526-822ff8ed5b28", "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": "",
|
||||
"start": "0", "sortType": "", "sortName": "", "pageNo": "1", "pageSize": "15",
|
||||
"dataIds": "", "hideCols": "",
|
||||
}
|
||||
_HR_API_CHARS = "y!89(*z02BCcdD_bEeGHIJKLmnNOPQopRMSTqrUklVstWXYZafgh3ij1uvwx456A7"
|
||||
_HR_API_PAD = '7'
|
||||
_HR_API_SALT = "yyryrtweasdasd"
|
||||
|
||||
|
||||
def _hr_base64_encode(data):
|
||||
"""HR commonQuery 自定义字符表 Base64(与前端/共享模块一致)。"""
|
||||
out = []
|
||||
for i in range(0, len(data), 3):
|
||||
chunk = data[i:i + 3]
|
||||
b1 = chunk[0] if len(chunk) > 0 else 0
|
||||
b2 = chunk[1] if len(chunk) > 1 else 0
|
||||
b3 = chunk[2] if len(chunk) > 2 else 0
|
||||
enc1 = (b1 >> 2) & 0x3F
|
||||
enc2 = ((b1 << 4) | (b2 >> 4)) & 0x3F
|
||||
enc3 = ((b2 << 2) | (b3 >> 6)) & 0x3F
|
||||
enc4 = b3 & 0x3F
|
||||
if len(chunk) == 1:
|
||||
enc3 = enc4 = 64
|
||||
elif len(chunk) == 2:
|
||||
enc4 = 64
|
||||
out.append(_HR_API_CHARS[enc1])
|
||||
out.append(_HR_API_CHARS[enc2])
|
||||
out.append(_HR_API_CHARS[enc3])
|
||||
out.append(_HR_API_CHARS[enc4])
|
||||
return "".join(out)
|
||||
|
||||
|
||||
def _hr_encode_common_query(query_list):
|
||||
"""把查询条件加密为 commonQuery(encodeURIComponent + 自定义 Base64 + 盐值 + 首尾重排)。"""
|
||||
import urllib.parse
|
||||
json_str = json.dumps(query_list, ensure_ascii=False, separators=(",", ":"))
|
||||
uri_encoded = urllib.parse.quote(json_str, safe="-_.~!*'()")
|
||||
en_str = _hr_base64_encode(uri_encoded.encode("utf-8")) + _HR_API_SALT
|
||||
return en_str[:2] + en_str[-3:] + en_str[2:-3]
|
||||
|
||||
|
||||
def _hr_in_service_conditions():
|
||||
"""在职人员查询条件:主职 in (1) + 在职状态 in (1)。"""
|
||||
def cond(field, qtype, value, input_type, left="", right="", logic="AND"):
|
||||
return {"queryField": field, "leftBracket": left, "queryType": qtype,
|
||||
"queryValue": value, "queryText": value, "rightBracket": right,
|
||||
"logic": logic, "inputType": input_type}
|
||||
return [
|
||||
cond("`pt_staff_stru.POST_STRU_ID`", "in", "1", "select", left="(", right=")"),
|
||||
cond("`hr_staff_base.person_status`", "in", "1", "multipleSelect", left="(", right=")"),
|
||||
]
|
||||
|
||||
|
||||
def _hr_date_params():
|
||||
"""HR 接口动态日期参数(当月/上月/当年首月)。"""
|
||||
now = datetime.now()
|
||||
last_month = datetime(now.year, now.month, 1) - timedelta(days=1)
|
||||
return {
|
||||
"currentDate": now.strftime("%Y-%m-%d"),
|
||||
"currentMonth": now.strftime("%Y%m"),
|
||||
"currentMonthBar": now.strftime("%Y-%m"),
|
||||
"lastMonth": last_month.strftime("%Y%m"),
|
||||
"lastMonFirstDay": last_month.strftime("%Y-%m-01"),
|
||||
"lastMonLastDay": last_month.strftime("%Y-%m-%d"),
|
||||
"curYearFirstMon": f"{now.year}01",
|
||||
"curYearFirstMonBar": f"{now.year}-01",
|
||||
}
|
||||
|
||||
|
||||
def _hr_pick(row: dict, candidates: tuple):
|
||||
"""按候选 key(先精确后包含)从 API 行取字段值。"""
|
||||
low = {str(k).lower(): v for k, v in row.items() if isinstance(k, str)}
|
||||
for cand in candidates:
|
||||
if cand in low:
|
||||
return low[cand]
|
||||
for k, v in low.items():
|
||||
for cand in candidates:
|
||||
if cand in k:
|
||||
return v
|
||||
return None
|
||||
|
||||
|
||||
def _roster_rows_to_map(rows: list) -> dict:
|
||||
"""API 返回行转 roster_map({工号: {姓名, 二级部门, 四级部门, 岗位, 所属单位}})。"""
|
||||
result = {}
|
||||
for row in rows:
|
||||
if not isinstance(row, dict):
|
||||
continue
|
||||
code = _norm_code(_hr_pick(row, ("base_code", "工号", "staff_code", "code")))
|
||||
if not code:
|
||||
continue
|
||||
result[code] = {
|
||||
"姓名": str(_hr_pick(row, ("staff_name", "姓名", "name")) or ""),
|
||||
"二级部门": str(_hr_pick(row, ("dept_org_two", "二级部门", "dept2", "DEPT_ORG_TWO")) or ""),
|
||||
"四级部门": str(_hr_pick(row, ("dept_org_four", "四级部门", "dept4", "DEPT_ORG_FOUR")) or ""),
|
||||
"岗位": str(_hr_pick(row, ("post_org_name", "岗位", "post", "POST_ORG_NAME")) or ""),
|
||||
"所属单位": str(_hr_pick(row, ("belong_unit_org_name", "所属单位", "BELONG_UNIT_ORG_NAME")) or ""),
|
||||
}
|
||||
return result
|
||||
|
||||
|
||||
def _fetch_roster_map_via_api(session) -> dict:
|
||||
"""直连 HR 花名册接口拉取在职人员 roster_map;任一环节失败返回 {}(由调用方回退)。"""
|
||||
if session is None:
|
||||
return {}
|
||||
params = {k: str(v) for k, v in _HR_API_BASE_PARAMS.items()}
|
||||
params["commonQuery"] = _hr_encode_common_query(_hr_in_service_conditions())
|
||||
params.update(_hr_date_params())
|
||||
headers = {"X-Requested-With": "XMLHttpRequest"}
|
||||
rows, page_no = [], 1
|
||||
for _ in range(50): # 分页上限
|
||||
params.update({"pageNo": str(page_no), "pageSize": "10000",
|
||||
"start": str((page_no - 1) * 10000),
|
||||
"_t": str(int(time.time() * 1000))})
|
||||
try:
|
||||
resp = session.post(_HR_API_LIST_URL, data=params, headers=headers, timeout=30)
|
||||
except Exception as e:
|
||||
logger.warning("花名册 HR 接口请求失败,回退其他数据源:%s", e)
|
||||
return {}
|
||||
text = (resp.text or "").strip() if resp is not None else ""
|
||||
if not text.startswith(("{", "[")):
|
||||
logger.warning("花名册 HR 接口返回异常/登录态失效,回退其他数据源")
|
||||
return {}
|
||||
try:
|
||||
data = resp.json()
|
||||
except Exception:
|
||||
return {}
|
||||
if str(data.get("state") or "") in ("Nosession", "Login"):
|
||||
logger.warning("花名册 HR 接口会话过期,请在工作台重新登录 HR")
|
||||
return {}
|
||||
jl = data.get("jsonList") or []
|
||||
if not jl:
|
||||
break
|
||||
rows.extend(jl)
|
||||
total = data.get("total")
|
||||
try:
|
||||
total_n = int(total) if total not in (None, "") else len(rows)
|
||||
except (TypeError, ValueError):
|
||||
total_n = len(rows)
|
||||
if len(rows) >= total_n:
|
||||
break
|
||||
page_no += 1
|
||||
if not rows:
|
||||
return {}
|
||||
return _roster_rows_to_map(rows)
|
||||
|
||||
|
||||
def _read_roster_from_source_sheet(excel_path: str) -> dict:
|
||||
"""读取源表内嵌「附-在职花名册」sheet 构建 roster_map(与业务同文件同月份,数据可靠)。"""
|
||||
import openpyxl
|
||||
if not excel_path or not os.path.exists(excel_path):
|
||||
return {}
|
||||
try:
|
||||
wb = openpyxl.load_workbook(excel_path, read_only=True, data_only=True)
|
||||
except Exception as e:
|
||||
logger.warning("源表读取失败,无法用「附-在职花名册」构建花名册:%s", e)
|
||||
return {}
|
||||
try:
|
||||
ws = next((s for s in wb.worksheets if "在职花名册" in s.title), None)
|
||||
if ws is None:
|
||||
return {}
|
||||
rows = list(ws.iter_rows(min_row=1, max_row=1, max_col=60))
|
||||
cols = {}
|
||||
for i, h in enumerate(rows[0]):
|
||||
v = h.value
|
||||
name = str(v).strip() if v is not None else ""
|
||||
if name and name not in cols:
|
||||
cols[name] = i
|
||||
if "工号" not in cols or "姓名" not in cols:
|
||||
logger.warning("「附-在职花名册」缺少工号/姓名列,无法构建花名册")
|
||||
return {}
|
||||
result = {}
|
||||
code_col = cols["工号"]
|
||||
for row in ws.iter_rows(min_row=2, max_col=60):
|
||||
vals = [c.value for c in row]
|
||||
if all(v is None for v in vals):
|
||||
continue
|
||||
code = _norm_code(vals[code_col] if code_col < len(vals) else None)
|
||||
if not code or code == "0":
|
||||
continue
|
||||
|
||||
def cell(key):
|
||||
i = cols.get(key)
|
||||
return vals[i] if i is not None and i < len(vals) else None
|
||||
|
||||
result[code] = {
|
||||
"姓名": str(cell("姓名") or ""),
|
||||
"二级部门": str(cell("二级部门") or ""),
|
||||
"四级部门": str(cell("四级部门") or ""),
|
||||
"岗位": str(cell("岗位") or ""),
|
||||
"所属单位": str(cell("所属单位") or ""),
|
||||
}
|
||||
return result
|
||||
finally:
|
||||
wb.close()
|
||||
|
||||
|
||||
def _load_roster_map(excel_path: str = None, roster_path: str = None) -> dict:
|
||||
"""加载花名册 roster_map:HR 接口 → 源表「附-在职花名册」→ 本地 员工花名册.xlsx。
|
||||
全部失败返回 {}(接收人解析受限但不中断流程)。"""
|
||||
excel_path = excel_path or ""
|
||||
roster_path = roster_path or _roster_path()
|
||||
hr_session = config.get_hr_session()
|
||||
if hr_session is not None:
|
||||
m = _fetch_roster_map_via_api(hr_session)
|
||||
if m:
|
||||
logger.info("花名册经 HR 接口获取:共 %d 人", len(m))
|
||||
return m
|
||||
if excel_path:
|
||||
m = _read_roster_from_source_sheet(excel_path)
|
||||
if m:
|
||||
logger.info("花名册经源表「附-在职花名册」获取:共 %d 人", len(m))
|
||||
return m
|
||||
try:
|
||||
m = _read_roster_map(roster_path)
|
||||
logger.info("花名册经本地文件读取:共 %d 人", len(m))
|
||||
return m
|
||||
except Exception as e:
|
||||
logger.warning("本地花名册读取失败,接收人解析受限:%s", e)
|
||||
return {}
|
||||
|
||||
|
||||
def _fill_dept4(rec: dict, roster_map: dict) -> str:
|
||||
"""四级部门:源数据缺失时查花名册(按37工号),仍缺失 fallback 二级部门。"""
|
||||
dept4 = str(rec.get("四级部门") or "").strip()
|
||||
@@ -481,7 +722,7 @@ def _read_transfer_records(excel_path: str, roster_map: dict = None) -> list:
|
||||
for src, std in config.TRANSFER_COL_MAP.items():
|
||||
if src in col_idx:
|
||||
rec[std] = _cell(vals, src)
|
||||
for key in ("姓名", "二级部门", "四级部门", "37工号", "备注"):
|
||||
for key in ("姓名", "二级部门", "四级部门", "37工号", "备注", "所属单位"):
|
||||
if key in col_idx:
|
||||
rec[key] = _cell(vals, key)
|
||||
full_key = "全称" if "全称" in col_idx else "参保单位全称"
|
||||
@@ -550,15 +791,16 @@ def _find_store_manager_in_map(roster_map: dict, code: str):
|
||||
|
||||
|
||||
def _find_hr_personnel_in_map(roster_map: dict, code: str, dept2: str = None) -> list:
|
||||
"""查人事/推送人:二级部门命中 DEPT2_PUSH_OVERRIDE 直接返回;其次石桥铺会馆固定;再兜底岗位含人事。"""
|
||||
info = roster_map.get(code)
|
||||
if not info:
|
||||
return []
|
||||
dept2 = dept2 or info["二级部门"]
|
||||
"""查人事/推送人:二级部门(含所属单位回退值)命中 DEPT2_PUSH_OVERRIDE 直接返回;
|
||||
其次石桥铺会馆固定;再兜底岗位含人事。覆盖映射不依赖员工是否在花名册。"""
|
||||
info = roster_map.get(code) or {}
|
||||
dept2 = dept2 or info.get("二级部门") or ""
|
||||
if dept2 in config.DEPT2_PUSH_OVERRIDE:
|
||||
return list(config.DEPT2_PUSH_OVERRIDE[dept2])
|
||||
if dept2 in config.DEPT2_HR_OVERRIDE:
|
||||
return list(config.DEPT2_HR_OVERRIDE[dept2])
|
||||
if not info:
|
||||
return []
|
||||
if "经营中心" not in dept2:
|
||||
return []
|
||||
return [c for c, it in roster_map.items()
|
||||
@@ -626,11 +868,7 @@ def build_work_communication_data(branch: str, output_dir: str = None, ym: tuple
|
||||
|
||||
logger.info("构造 OA 工作沟通数据:分支=%s(%d-%02d)", branch, y, m)
|
||||
excel_path = _find_current_month_excel(_base_dir())
|
||||
try:
|
||||
roster_map = _read_roster_map(roster_path)
|
||||
except Exception as e:
|
||||
logger.warning("花名册读取失败,二级部门解析/接收人查找将受限:%s", e)
|
||||
roster_map = {}
|
||||
roster_map = _load_roster_map(excel_path, roster_path)
|
||||
logger.info("花名册共 %d 人:%s", len(roster_map), roster_path)
|
||||
|
||||
matched_by_rule = {}
|
||||
@@ -674,8 +912,11 @@ def build_work_communication_data(branch: str, output_dir: str = None, ym: tuple
|
||||
continue
|
||||
d2 = _resolve_dept2(r, all_records, roster_map)
|
||||
if not d2:
|
||||
logger.error("员工「%s」无法解析二级部门(参保单位=%s),不推送该员工",
|
||||
r.get("姓名"), _ins_org_of(r))
|
||||
# 二级部门为空时不跳过:用「所属单位」列替代作为推送分组依据
|
||||
d2 = str(r.get("所属单位") or "").strip()
|
||||
if not d2:
|
||||
logger.error("员工「%s」无法解析二级部门且无所属单位,不推送该员工",
|
||||
r.get("姓名"))
|
||||
continue
|
||||
dept2_by_code[c] = d2
|
||||
codes.append(c)
|
||||
@@ -730,11 +971,7 @@ def generate_notices(branch: str, output_dir: str = None, ym: tuple = None,
|
||||
excel_path = _find_current_month_excel(_base_dir())
|
||||
logger.info("读取名单:%s(目标年月 %d-%02d)", excel_path, y, m)
|
||||
|
||||
try:
|
||||
roster_map = _read_roster_map(roster_path or _roster_path())
|
||||
except Exception as e:
|
||||
logger.warning("花名册读取失败,二级部门解析将受限:%s", e)
|
||||
roster_map = {}
|
||||
roster_map = _load_roster_map(excel_path, roster_path or _roster_path())
|
||||
if branch == "转移参保":
|
||||
transfer_records = _read_transfer_records(excel_path, roster_map)
|
||||
logger.info("社保转移命中 %d 人:%s", len(transfer_records), excel_path)
|
||||
@@ -766,8 +1003,11 @@ def generate_notices(branch: str, output_dir: str = None, ym: tuple = None,
|
||||
for rec in matched:
|
||||
dept2 = _resolve_dept2(rec, all_records, roster_map)
|
||||
if not dept2:
|
||||
logger.error("员工「%s」无法解析二级部门(参保单位=%s),跳过生成",
|
||||
rec.get("姓名"), _ins_org_of(rec))
|
||||
# 二级部门为空时不跳过生成:用「所属单位」列替代作为分组/命名依据
|
||||
dept2 = str(rec.get("所属单位") or "").strip()
|
||||
if not dept2:
|
||||
logger.error("员工「%s」无法解析二级部门且无所属单位,跳过生成",
|
||||
rec.get("姓名"))
|
||||
continue
|
||||
rec["二级部门"] = dept2
|
||||
key = (dept2, _trans_org_of(rec))
|
||||
|
||||
@@ -147,13 +147,22 @@ def upload_attachment(session, file_path):
|
||||
|
||||
# 2) 上传二进制
|
||||
uploader_url = f"{config.ATT_UPLOADER_URL}?gettype=upload&format=json&userkey={userkey}"
|
||||
with open(file_path, "rb") as f:
|
||||
files = {"file": (file_name, f, file_type)}
|
||||
data2 = {"id": "WU_FILE_0", "name": file_name, "type": file_type,
|
||||
"lastModifiedDate": last_modified, "size": file_size}
|
||||
resp2 = _check_response(session.post(uploader_url, data=data2, files=files,
|
||||
timeout=60, headers=_DEFAULT_HEADERS),
|
||||
"附件上传-二进制")
|
||||
# 底座注入的共享会话默认带 Content-Type: application/x-www-form-urlencoded,
|
||||
# 会导致 requests 在 files 上传时不再自动生成 multipart/form-data 边界头,
|
||||
# 服务端(Apache Commons FileUpload)以 InvalidContentTypeException 拒绝。
|
||||
# 上传前临时清除该默认头,让 requests 生成正确的 multipart 请求,随后恢复。
|
||||
saved_ct = session.headers.pop("Content-Type", None)
|
||||
try:
|
||||
with open(file_path, "rb") as f:
|
||||
files = {"file": (file_name, f, file_type)}
|
||||
data2 = {"id": "WU_FILE_0", "name": file_name, "type": file_type,
|
||||
"lastModifiedDate": last_modified, "size": file_size}
|
||||
resp2 = _check_response(session.post(uploader_url, data=data2, files=files,
|
||||
timeout=60, headers=_DEFAULT_HEADERS),
|
||||
"附件上传-二进制")
|
||||
finally:
|
||||
if saved_ct is not None:
|
||||
session.headers["Content-Type"] = saved_ct
|
||||
try:
|
||||
filekey = resp2.json().get("filekey")
|
||||
except Exception:
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"schema_version": 1,
|
||||
"id": "xq0008",
|
||||
"name": "重庆社保增减员办理",
|
||||
"version": "1.0.4",
|
||||
"version": "1.0.5",
|
||||
"description": "重庆社保增减员全流程(XQ0008 名单制作 + XQ0014 系统办理/核查回盘 + XQ0015/XQ0016 告知书制作下发):目录预检、增/减员名单制作、增/减员系统办理、增/减员核查回盘、告知书制作与 OA 推送八阶段可选串行。逐参保单位读取台账账号登录重庆人社政务平台(法人用户+图形验证码识别)完成导入申报、审核结论核查与回盘表核对,回写源名单办理状态/办理停保及备注;生成三类告知书并构造 OA 工作沟通推送,全程 JSON 缓存防崩溃、结束统一落盘。",
|
||||
"category": "社保",
|
||||
"icon": "",
|
||||
|
||||
Reference in New Issue
Block a user