# -*- coding: utf-8 -*- """XQ0038 定性评价推送 插件 - 数据层:OA 接口请求。 只依赖 Python 标准库 / config(常量与钩子)。会话一律经 config.get_oa_session() 获取底座注入的 requests.Session(已带 OA cookies),不在本层读 cookie 文件。 """ import re import time from .. import config def org_search(s, key): """通讯录查询(orgType=8 人员):key 支持工号精确/姓名模糊,返回 (id, name)。""" resp = s.post(config.DATAXML_URL, data={"s_bean": "organizationDialogSearch", "key": key, "startWith": "", "orgType": "8", "times": "2"}, timeout=20) m = re.search(r']*>', resp.text) if not m: return None, None tag = m.group(0) i = re.search(r'''\bid="([^"]+)"''', tag) n = re.search(r'''\bname="([^"]+)"''', tag) return (i.group(1) if i else None, n.group(1) if n else None) def get_login_user(s): """门户页内嵌登录信息,返回 (姓名 userName, 登录名/工号 loginName)。""" resp = s.get(config.PORTAL_URL, timeout=30) name = re.search(r"var\s+userName\s*=\s*'([^']*)'", resp.text) no = re.search(r"var\s+loginName\s*=\s*'([^']*)'", resp.text) return (name.group(1) if name else '', no.group(1) if no else '') def get_export_columns(s, search_id): """查询方案字段字典,返回 [(fd, 中文名), ...]。""" resp = s.get(config.DATAXML_URL, params={"s_bean": "sysSearchResultExportDictService", "fdModelName": config.MODEL_NAME, "searchId": search_id, "type": "opt"}, timeout=20) return re.findall(r']+>', ' ', resp.text)) return None, '导出返回非 xls(%s):%s' % (ctype, text[:150]) with open(out_path, 'wb') as f: f.write(resp.content) return total, ''