103 lines
4.1 KiB
Python
103 lines
4.1 KiB
Python
from typing import Optional
|
|
import logging
|
|
|
|
from apps.api import govs
|
|
from apps.app_handler import AppHandler
|
|
from paste.web.decorators import route
|
|
from paste.core import aio_pool
|
|
from paste.core.logging import echo_log
|
|
from dock.govs import govs_create_reply
|
|
from models.govs_order_master import GovsOrderMaster
|
|
from models.govs_create_reply import GovsReplyFormal
|
|
|
|
|
|
@route(f'{govs.ApiPrefix}/reply-formal/create')
|
|
class CreateDelayHandler(AppHandler):
|
|
"""
|
|
答复办结接口。
|
|
|
|
对接省12345的答复办结接口,请求后本接口先将数据保存本地,然后响应客户端,然后开始后台启动推送。
|
|
"""
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
|
|
self.govs_order: Optional[GovsOrderMaster] = None
|
|
self.govs_reply: Optional[GovsReplyFormal] = None
|
|
|
|
def _params_for_db(self, **kwargs: dict) -> dict:
|
|
"""
|
|
提取数据库所需参数。
|
|
"""
|
|
return {
|
|
GovsReplyFormal.master_id.key: kwargs.get('gdId', ''),
|
|
GovsReplyFormal.flow_token.key: kwargs.get('flowToken', ''),
|
|
GovsReplyFormal.gd_id.key: kwargs.get('gdId', ''),
|
|
GovsReplyFormal.is_contact.key: kwargs.get('isContact', ''),
|
|
GovsReplyFormal.contact_name.key: kwargs.get('contactName', ''),
|
|
GovsReplyFormal.contact_time.key: kwargs.get('contactTime', ''),
|
|
GovsReplyFormal.contact_type.key: kwargs.get('contactType', ''),
|
|
GovsReplyFormal.advice.key: kwargs.get('advice', ''),
|
|
GovsReplyFormal.reason.key: kwargs.get('reason', ''),
|
|
GovsReplyFormal.remarks.key: kwargs.get('remarks', ''),
|
|
GovsReplyFormal.file_id_str.key: kwargs.get('fileIdStr', ''),
|
|
GovsReplyFormal.save_id.key: kwargs.get('saveId', ''),
|
|
GovsReplyFormal.process_instance_id.key: kwargs.get('processInstanceId', ''),
|
|
GovsReplyFormal.business_key.key: kwargs.get('businessKey', ''),
|
|
GovsReplyFormal.order_no.key: kwargs.get('orderNo', ''),
|
|
GovsReplyFormal.action_name.key: kwargs.get('actionName', ''),
|
|
GovsReplyFormal.case_accord_type_one_name.key: kwargs.get('caseAccordTypeOneName', ''),
|
|
GovsReplyFormal.case_accord_type_two_name.key: kwargs.get('caseAccordTypeTwoName', ''),
|
|
GovsReplyFormal.case_accord_type_three_name.key: kwargs.get('caseAccordTypeThreeName', ''),
|
|
}
|
|
|
|
async def create_delay(self, **kwargs) -> dict:
|
|
# 必填参数校验
|
|
required_keys = [
|
|
'gdId', 'flowToken', 'isContact', 'contactType', 'advice', 'reason'
|
|
]
|
|
missing = [
|
|
k for k in required_keys
|
|
if k not in kwargs or kwargs[k] is None
|
|
]
|
|
if missing:
|
|
raise ValueError(f"缺少必要参数: {missing}")
|
|
|
|
# 读取待办任务对象
|
|
govs_task_id = kwargs.get('gdId', '')
|
|
self.govs_order = await GovsOrderMaster.async_find_by_id(govs_task_id)
|
|
|
|
# 保存请求数据
|
|
params = self._params_for_db(**kwargs)
|
|
self.govs_reply = GovsReplyFormal().copy_from_dict(params)
|
|
self.govs_reply.status = 0
|
|
await self.govs_reply.async_save()
|
|
|
|
# 后台执行提交答复办结请求到省12345
|
|
await aio_pool.run_background_task(
|
|
govs_create_reply.create_reply(self.govs_reply, self.govs_order)
|
|
)
|
|
|
|
return {
|
|
'msg': '答复办结成功.'
|
|
}
|
|
|
|
# @auth_token
|
|
async def post(self):
|
|
"""
|
|
处理 POST 请求。
|
|
|
|
---
|
|
tags:
|
|
- D3I API
|
|
summary: 答复办结接口
|
|
"""
|
|
try:
|
|
echo_log(self.request.body.decode())
|
|
_, params = self.get_request_params()
|
|
_result = await self.create_delay(**params)
|
|
self.response_ok(code=0, data=_result)
|
|
except Exception as e:
|
|
self.response_error(e, status_code=200, api_status_code=500)
|
|
self.log(msg=e, level=logging.ERROR, is_log_exc=True)
|