agent请假推申请单到OA
This commit is contained in:
1 parent
aeb6b66513
commit
367c20eb09
15 files changed
+1833
-143
No files matched your search
@@ -3,6 +3,7 @@ from app import db
|
||||
from app.models import User, Agent, QuickQuestion, UserFavoriteAgent, UserDefaultAgent, UserHomepageConfig, Announcement, LoginAudit, WecomCallbackAudit, GeneralFeedback, ChatLog
|
||||
from app.services.wecom_notify import mark_wecom_message_opened, send_wecom_event_message
|
||||
from app.services.wecom_crypto import sha1_hex, decrypt_wecom_aes, extract_encrypt_field
|
||||
from app.services.oa_leave_workflow import OALeaveWorkflowService, OALeaveWorkflowError
|
||||
from app.auth_jwt import get_current_user as _auth_current_user
|
||||
from app.auth_jwt import issue_local_access_token
|
||||
from sqlalchemy.exc import DatabaseError, IntegrityError, OperationalError
|
||||
@@ -521,6 +522,15 @@ def _clean_str(value):
|
||||
return str(value).strip() or None
|
||||
|
||||
|
||||
def _parse_leave_int_flag(value, field_label: str):
|
||||
if value in (0, 1):
|
||||
return int(value)
|
||||
text = _clean_str(value)
|
||||
if text in ('0', '1'):
|
||||
return int(text)
|
||||
raise OALeaveWorkflowError(f'{field_label} 取值无效,应为 0 或 1。')
|
||||
|
||||
|
||||
def _normalize_mobile(mobile: str):
|
||||
mobile = _clean_str(mobile)
|
||||
if not mobile:
|
||||
@@ -1557,6 +1567,64 @@ def wecom_task_complete():
|
||||
return jsonify(result), 200 if result.get('ok') else 202
|
||||
|
||||
|
||||
@user_bp.route('/leave-workflow/submit', methods=['POST'])
|
||||
def submit_leave_workflow():
|
||||
user = _get_current_user()
|
||||
if not user:
|
||||
return jsonify({'error': 'Unauthorized'}), 401
|
||||
|
||||
data = request.get_json() or {}
|
||||
form_data = {
|
||||
'applicantName': _clean_str(data.get('applicantName')) or _clean_str(getattr(user, 'real_name', None)) or _clean_str(getattr(user, 'username', None)),
|
||||
'employeeId': _clean_str(data.get('employeeId')) or _clean_str(getattr(user, 'employee_id', None)) or _clean_str(getattr(user, 'username', None)),
|
||||
'applyTime': _clean_str(data.get('applyTime')),
|
||||
'fillerName': _clean_str(data.get('fillerName')) or _clean_str(getattr(user, 'real_name', None)) or _clean_str(getattr(user, 'username', None)),
|
||||
'agentUid': _clean_str(data.get('agentUid')),
|
||||
'agentEmployeeId': _clean_str(data.get('agentEmployeeId')),
|
||||
'agentName': _clean_str(data.get('agentName')),
|
||||
'leaveType': _clean_str(data.get('leaveType')),
|
||||
'startTime': _clean_str(data.get('startTime')),
|
||||
'endTime': _clean_str(data.get('endTime')),
|
||||
'durationHours': data.get('durationHours'),
|
||||
'isOutOfOffice': _parse_leave_int_flag(data.get('isOutOfOffice'), '是否外出'),
|
||||
'isWorkInjury': _parse_leave_int_flag(data.get('isWorkInjury'), '是否为工伤'),
|
||||
'remark': _clean_str(data.get('remark')) or '',
|
||||
}
|
||||
|
||||
required_fields = {
|
||||
'applicantName': '申请人',
|
||||
'employeeId': '工号',
|
||||
'fillerName': '填单人',
|
||||
'agentUid': '代理人UID',
|
||||
'agentEmployeeId': '代理人工号',
|
||||
'agentName': '代理人姓名',
|
||||
'leaveType': '假别',
|
||||
'startTime': '开始时间',
|
||||
'endTime': '结束时间',
|
||||
}
|
||||
for key, label in required_fields.items():
|
||||
if not form_data.get(key):
|
||||
return jsonify({'error': f'{label}不能为空。'}), 400
|
||||
|
||||
try:
|
||||
result = OALeaveWorkflowService.submit_leave_request(form_data, user)
|
||||
except OALeaveWorkflowError as exc:
|
||||
current_app.logger.warning('[oa-leave] submit failed user_id=%s employee_id=%s err=%s', getattr(user, 'id', None), form_data.get('employeeId'), exc)
|
||||
return jsonify({'error': str(exc)}), 400
|
||||
except Exception as exc:
|
||||
current_app.logger.exception('[oa-leave] unexpected submit failure user_id=%s', getattr(user, 'id', None))
|
||||
return jsonify({'error': f'OA 请假提交失败:{exc}'}), 500
|
||||
|
||||
current_app.logger.info(
|
||||
'[oa-leave] submit success user_id=%s employee_id=%s request_id=%s workflow_id=%s',
|
||||
getattr(user, 'id', None),
|
||||
form_data.get('employeeId'),
|
||||
result.get('request_id'),
|
||||
result.get('workflow_id'),
|
||||
)
|
||||
return jsonify(result)
|
||||
|
||||
|
||||
@user_bp.route('/wecom/callback', methods=['GET', 'POST'])
|
||||
def wecom_callback():
|
||||
"""
|
||||
|
||||
Reference in new issue
Block a user