Merge branch 'dev' into hugo
This commit is contained in:
commit
7544361c05
15 files changed
+570
-135
No files matched your search
+20
-26
@@ -20,7 +20,7 @@ import re
|
||||
import requests
|
||||
import uuid
|
||||
from app.services.wecom_notify import send_wecom_event_message
|
||||
from app.services.wecom_directory_sync import sync_wecom_userids_from_directory
|
||||
from app.services.oa_wecom_sync import sync_wecom_userids_from_oa
|
||||
from app.services.dify import DifyService
|
||||
from app.auth_jwt import get_current_user as _get_auth_user
|
||||
from app.errors import AppError, ValidationError, UnauthorizedError, ForbiddenError, NotFoundError, ConflictError, ServiceUnavailableError, raise_for_status
|
||||
@@ -1258,46 +1258,40 @@ def wecom_binding_stats():
|
||||
@require_admin
|
||||
def sync_wecom_userids_admin():
|
||||
"""
|
||||
从企微通讯录按工号同步 users.wecom_userid。
|
||||
Request JSON: { "apply": false, "department_id": 1 }
|
||||
从 OA userInfo_view 按工号同步 users.wecom_userid(workcode→employee_id,id→wecom_userid)。
|
||||
Request JSON: { "apply": false }
|
||||
"""
|
||||
data = request.get_json() or {}
|
||||
apply = bool(data.get('apply'))
|
||||
department_id = data.get('department_id')
|
||||
if department_id is not None and department_id != '':
|
||||
try:
|
||||
department_id = int(department_id)
|
||||
except (TypeError, ValueError):
|
||||
raise ValidationError('department_id must be an integer')
|
||||
else:
|
||||
department_id = None
|
||||
try:
|
||||
summary = sync_wecom_userids_from_directory(apply=apply, department_id=department_id)
|
||||
summary = sync_wecom_userids_from_oa(apply=apply)
|
||||
current_app.logger.info(
|
||||
'[wecom_sync] admin apply=%s updated=%s would_update=%s conflicts=%s',
|
||||
'[wecom_sync] oa apply=%s updated=%s would_update=%s conflicts=%s local_matched=%s',
|
||||
apply,
|
||||
summary.get('updated'),
|
||||
summary.get('would_update'),
|
||||
len(summary.get('conflicts') or []),
|
||||
summary.get('local_matched'),
|
||||
)
|
||||
return jsonify(summary)
|
||||
except RuntimeError as exc:
|
||||
message = str(exc)
|
||||
if 'not configured' in message.lower():
|
||||
raise AppError(
|
||||
code='SYSTEM.HTTP_ERROR',
|
||||
message=message,
|
||||
http_status=503,
|
||||
details={'error_code': 'WECOM_NOT_CONFIGURED'},
|
||||
)
|
||||
if 'conflicts detected' in message.lower():
|
||||
raise ConflictError(message, details={'error_code': 'WECOM_SYNC_CONFLICTS'})
|
||||
if 'department/list failed' in message.lower() or 'user/list failed' in message.lower():
|
||||
if '未找到可用的 SQL Server ODBC 驱动' in message or 'pyodbc' in message.lower():
|
||||
raise AppError(
|
||||
code='SYSTEM.HTTP_ERROR',
|
||||
message='WeCom directory API failed. Check app contact read permissions.',
|
||||
http_status=502,
|
||||
details={'error_code': 'WECOM_DIRECTORY_API_FAILED', 'technical': message[:300]},
|
||||
code='SYSTEM.SERVICE_UNAVAILABLE',
|
||||
message='OA SQL Server driver is not available on this server',
|
||||
http_status=503,
|
||||
details={'error_code': 'OA_SQLSERVER_DRIVER_MISSING', 'technical': message[:300]},
|
||||
)
|
||||
raise AppError(code='SYSTEM.INTERNAL_ERROR', message=message, http_status=500)
|
||||
raise AppError(
|
||||
code='SYSTEM.HTTP_ERROR',
|
||||
message='OA SQL Server sync failed. Check OA_SQLSERVER_* env and network access.',
|
||||
http_status=502,
|
||||
details={'error_code': 'OA_SQLSERVER_SYNC_FAILED', 'technical': message[:300]},
|
||||
)
|
||||
except Exception as exc:
|
||||
current_app.logger.exception('[wecom_sync] oa unexpected failure: %s', exc)
|
||||
raise AppError(code='SYSTEM.INTERNAL_ERROR', message=str(exc), http_status=500)
|
||||
|
||||
Reference in new issue
Block a user