请假推送公司、职务等相关信息

This commit is contained in:
runny committed 2026-05-19 16:34:16 +08:00
1 parent fed57cc3cf
commit 51b466d4ab
4 files changed
+116 -24

No files matched your search

+8 -2
View File
@@ -118,6 +118,9 @@ class HRLeaveSQLServerService:
raise RuntimeError("pyodbc 未安装,无法连接 HR SQL Server") from exc
driver = os.getenv("HR_SQLSERVER_DRIVER", "").strip() or cls._pick_driver(pyodbc)
available_drivers = pyodbc.drivers()
if driver not in available_drivers:
driver = cls._pick_driver(pyodbc)
server = os.getenv("HR_SQLSERVER_HOST", "192.168.100.191").strip()
port = os.getenv("HR_SQLSERVER_PORT", "1433").strip()
database = os.getenv("HR_SQLSERVER_DATABASE", "NH_N8_HEXIN").strip()
@@ -133,9 +136,12 @@ class HRLeaveSQLServerService:
f"DATABASE={database};"
f"UID={username};"
f"PWD={password};"
f"Encrypt={encrypt};"
f"TrustServerCertificate={trust_cert};"
)
if driver != "SQL Server":
conn_str += (
f"Encrypt={encrypt};"
f"TrustServerCertificate={trust_cert};"
)
return pyodbc.connect(conn_str, timeout=timeout)
@staticmethod
+59 -18
View File
@@ -101,20 +101,35 @@ class OALeaveWorkflowService:
'Content-Type': 'text/xml; charset=utf-8',
'SOAPAction': action,
}
try:
response = requests.post(
cls._get_service_url(),
data=payload,
headers=headers,
timeout=cls._request_timeout(),
)
response.raise_for_status()
except requests.RequestException as exc:
raise OALeaveWorkflowError(f'OA WorkflowService 请求失败:{exc}') from exc
try:
return ET.fromstring(response.text)
except ET.ParseError as exc:
raise OALeaveWorkflowError('OA WorkflowService 返回了无法解析的 XML。') from exc
max_retries = 3
last_exc = None
for attempt in range(1, max_retries + 1):
try:
response = requests.post(
cls._get_service_url(),
data=payload,
headers=headers,
timeout=cls._request_timeout(),
)
response.raise_for_status()
return ET.fromstring(response.text)
except requests.RequestException as exc:
last_exc = exc
status_code = getattr(getattr(exc, 'response', None), 'status_code', None)
retryable = status_code in (502, 503, 504) if status_code else True
if retryable and attempt < max_retries:
import time
wait = attempt * 2
current_app.logger.warning(
'[oa-leave] SOAP request failed (attempt %d/%d, status=%s), retrying in %ds: %s',
attempt, max_retries, status_code, wait, exc,
)
time.sleep(wait)
continue
raise OALeaveWorkflowError(f'OA WorkflowService 请求失败:{exc}') from exc
except ET.ParseError as exc:
raise OALeaveWorkflowError('OA WorkflowService 返回了无法解析的 XML。') from exc
raise OALeaveWorkflowError(f'OA WorkflowService 请求失败(重试{max_retries}次后仍出错):{last_exc}') from last_exc
@classmethod
def resolve_oa_user(cls, employee_id: str | None, real_name: str | None = None) -> dict[str, str]:
@@ -228,13 +243,18 @@ class OALeaveWorkflowService:
if show_node is None:
show_node = ET.SubElement(field, f'{{{WORKFLOW_NS}}}fieldShowValue')
show_node.text = str(show_value)
# 强制将字段设为可编辑和可见,防止OA流程节点中被配置为只读导致无法写入
filed_html_node = field.find('wf:filedHtmlShow', NS)
if filed_html_node is not None:
filed_html_node.text = str(show_value)
for tag in ['edit', 'view']:
node = field.find(f'wf:{tag}', NS)
if node is None:
if node is not None:
node.text = 'true'
else:
node = ET.SubElement(field, f'{{{WORKFLOW_NS}}}{tag}')
node.text = 'true'
node.text = 'true'
@classmethod
def _set_text(cls, parent: ET.Element, xpath: str, value: str) -> None:
@@ -352,6 +372,16 @@ class OALeaveWorkflowService:
cls._set_field(request_info, 'sqrzw', value=applicant_jobtitle, show_value=applicant_jobtitle_name or applicant_jobtitle or '暂无')
cls._set_field(request_info, 'sqrbm', value=applicant_department, show_value=applicant_department_name or applicant_department or '暂无')
cls._set_field(request_info, 'sqrgs', value=applicant_subcompany, show_value=applicant_subcompany_name or applicant_subcompany or '暂无')
current_app.logger.info(
'[oa-leave] field values: tdrzw=%s/%s tdrbm=%s/%s tdrgs=%s/%s sqrzw=%s/%s sqrbm=%s/%s sqrgs=%s/%s',
filler_jobtitle, filler_jobtitle_name or filler_jobtitle or '暂无',
filler_department, filler_department_name or filler_department or '暂无',
filler_subcompany, filler_subcompany_name or filler_subcompany or '暂无',
applicant_jobtitle, applicant_jobtitle_name or applicant_jobtitle or '暂无',
applicant_department, applicant_department_name or applicant_department or '暂无',
applicant_subcompany, applicant_subcompany_name or applicant_subcompany or '暂无',
)
cls._set_field(request_info, 'dlrgh', value=agent['employee_id'])
cls._set_field(request_info, 'dlrxm', value=agent['user_id'], show_value=agent['name'])
@@ -397,9 +427,20 @@ class OALeaveWorkflowService:
@classmethod
def submit_leave_request(cls, form_data: dict[str, Any], current_user: Any) -> dict[str, Any]:
request_info, filler, applicant, agent = cls.build_request_info(form_data, current_user)
log_fields = ['tdrzw', 'tdrbm', 'tdrgs', 'sqrzw', 'sqrbm', 'sqrgs', 'qjsc', 'tdrgh', 'sqrgh']
for fn in log_fields:
f = cls._find_field(request_info, fn)
if f is not None:
fv = f.findtext('wf:fieldValue', default='', namespaces=NS)
fsv = f.findtext('wf:fieldShowValue', default='', namespaces=NS)
fe = f.findtext('wf:edit', default='(removed)', namespaces=NS)
current_app.logger.info('[oa-leave] PUSH field %s: value=%s showValue=%s edit=%s', fn, fv, fsv, fe)
action = 'urn:weaver.workflow.webservices.WorkflowService.doCreateWorkflowRequest'
root = cls._post_soap(action, cls._build_create_body(request_info, filler['user_id']))
request_id = cls._parse_create_response(root)
current_app.logger.info('[oa-leave] OA response request_id=%s', request_id)
return {
'ok': True,
'request_id': request_id,
+10 -4
View File
@@ -21,6 +21,9 @@ class OASQLServerService:
@classmethod
def _connect(cls):
driver = os.getenv("OA_SQLSERVER_DRIVER", "").strip() or cls._pick_driver()
available_drivers = pyodbc.drivers()
if driver not in available_drivers:
driver = cls._pick_driver()
server = os.getenv("OA_SQLSERVER_HOST", "192.168.100.225").strip()
port = os.getenv("OA_SQLSERVER_PORT", "1433").strip()
database = os.getenv("OA_SQLSERVER_DATABASE", "ecology").strip()
@@ -36,9 +39,12 @@ class OASQLServerService:
f"DATABASE={database};"
f"UID={username};"
f"PWD={password};"
f"Encrypt={encrypt};"
f"TrustServerCertificate={trust_cert};"
)
if driver != "SQL Server":
conn_str += (
f"Encrypt={encrypt};"
f"TrustServerCertificate={trust_cert};"
)
return pyodbc.connect(conn_str, timeout=timeout)
@classmethod
@@ -62,8 +68,8 @@ class OASQLServerService:
# Fetch page
# Compatible with older SQL Server versions (2008/2012)
query_sql = """
SELECT v.id, v.workcode, v.lastname, v.jobtitle, v.departmentid, v.subcompanyid1,
d.departmentname, s.subcompanyname, j.jobtitlename
SELECT id, workcode, lastname, jobtitle, departmentid, subcompanyid1,
departmentname, subcompanyname, jobtitlename
FROM (
SELECT v.id, v.workcode, v.lastname, v.jobtitle, v.departmentid, v.subcompanyid1,
d.departmentname, s.subcompanyname, j.jobtitlename,
+39
View File
@@ -0,0 +1,39 @@
"""Check qjsc field details in OA template"""
import sys, os
sys.path.insert(0, os.path.dirname(__file__))
from app import create_app
app = create_app('development')
with app.app_context():
from app.services.oa_leave_workflow import OALeaveWorkflowService, NS
import xml.etree.ElementTree as ET
filler = OALeaveWorkflowService._resolve_runtime_oa_user('26030025', '梁春艳', role_label='filler')
template = OALeaveWorkflowService._get_template_request_info(
OALeaveWorkflowService.WORKFLOW_ID, filler['user_id']
)
for field in template.findall('.//wf:WorkflowRequestTableField', NS):
fname = field.findtext('wf:fieldName', default='', namespaces=NS)
if fname == 'qjsc':
print('=== qjsc (duration) field ===')
for child in field:
tag = child.tag.split('}')[1] if '}' in child.tag else child.tag
print(f' {tag}: {child.text!r}')
break
else:
print('qjsc field NOT FOUND in template')
# Also check after setting
from copy import deepcopy
modified = deepcopy(template)
OALeaveWorkflowService._set_field(modified, 'qjsc', value='9', show_value='9')
for field in modified.findall('.//wf:WorkflowRequestTableField', NS):
fname = field.findtext('wf:fieldName', default='', namespaces=NS)
if fname == 'qjsc':
print('\n=== qjsc AFTER _set_field ===')
for child in field:
tag = child.tag.split('}')[1] if '}' in child.tag else child.tag
print(f' {tag}: {child.text!r}')
break