|
@@ -176,6 +176,53 @@ async def list_contracts(
|
|
|
"total_pages": total_pages
|
|
"total_pages": total_pages
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+@router.get("/contracts/detail/{sign_flow_id}", response_model=Union[dict, ErrorResponse])
|
|
|
|
|
+async def get_contract_detail(
|
|
|
|
|
+ sign_flow_id: str,
|
|
|
|
|
+ templates_server: ContractServer = Depends(get_contract_service)
|
|
|
|
|
+) -> Union[dict, ErrorResponse]:
|
|
|
|
|
+ """
|
|
|
|
|
+ 根据 sign_flow_id 获取合同详情
|
|
|
|
|
+ - status=0: 返回合同PDF链接(contract_url)和签署链接(sign_url)
|
|
|
|
|
+ - status=1: 拉取最新下载链接并更新数据库,返回 contract_download_url
|
|
|
|
|
+ """
|
|
|
|
|
+ row, item, items = await templates_server.get_contract_item_by_sign_flow_id(sign_flow_id)
|
|
|
|
|
+ if not item:
|
|
|
|
|
+ return ErrorResponse(success=False, message="未找到合同")
|
|
|
|
|
+
|
|
|
|
|
+ status = item.get("status")
|
|
|
|
|
+ if status == 0:
|
|
|
|
|
+ return {
|
|
|
|
|
+ "status": 0,
|
|
|
|
|
+ "contract_url": item.get("contract_url", ""),
|
|
|
|
|
+ "sign_url": item.get("sign_url", ""),
|
|
|
|
|
+ "sign_flow_id": sign_flow_id
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if status == 1:
|
|
|
|
|
+ try:
|
|
|
|
|
+ download_resp = file_download_url(sign_flow_id)
|
|
|
|
|
+ download_json = json.loads(download_resp)
|
|
|
|
|
+ contract_download_url = download_json["data"]["files"][0]["downloadUrl"]
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ logger.error(f"file_download_url failed sign_flow_id={sign_flow_id}: {e}")
|
|
|
|
|
+ return ErrorResponse(success=False, message="获取合同下载链接失败", raw=str(e))
|
|
|
|
|
+
|
|
|
|
|
+ if row and isinstance(items, list):
|
|
|
|
|
+ for it in items:
|
|
|
|
|
+ if it.get("sign_flow_id") == sign_flow_id:
|
|
|
|
|
+ it["contract_download_url"] = contract_download_url
|
|
|
|
|
+ break
|
|
|
|
|
+ await templates_server.update_contract_items(row["id"], items)
|
|
|
|
|
+
|
|
|
|
|
+ return {
|
|
|
|
|
+ "status": 1,
|
|
|
|
|
+ "contract_download_url": contract_download_url,
|
|
|
|
|
+ "sign_flow_id": sign_flow_id
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return ErrorResponse(success=False, message="未知合同状态", raw={"status": status})
|
|
|
|
|
+
|
|
|
@router.get("/get_all_templates", response_model=PaginatedResponse)
|
|
@router.get("/get_all_templates", response_model=PaginatedResponse)
|
|
|
async def get_all_templates(
|
|
async def get_all_templates(
|
|
|
page: int = Query(1, ge=1, description="页码,从1开始"),
|
|
page: int = Query(1, ge=1, description="页码,从1开始"),
|
|
@@ -264,12 +311,31 @@ async def esign_callback(
|
|
|
logger.error(f"esign_callback ignored payload: {payload}")
|
|
logger.error(f"esign_callback ignored payload: {payload}")
|
|
|
return ErrorResponse(success=False, message="未处理: signResult!=2 或手机号/签署流程缺失")
|
|
return ErrorResponse(success=False, message="未处理: signResult!=2 或手机号/签署流程缺失")
|
|
|
|
|
|
|
|
-@router.post("/esign/callback_auth", response_model=SuccessResponse)
|
|
|
|
|
-async def esign_callback_auth(
|
|
|
|
|
- payload: dict,
|
|
|
|
|
- templates_server: ContractServer = Depends(get_contract_service)
|
|
|
|
|
-) -> SuccessResponse:
|
|
|
|
|
- logger.info(f"esign_callback_auth payload: {payload}")
|
|
|
|
|
- return SuccessResponse(code="200", msg="success")
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+# @router.post("/esign/callback_auth", response_model=SuccessResponse)
|
|
|
|
|
+# async def esign_callback_auth(
|
|
|
|
|
+# payload: dict,
|
|
|
|
|
+# templates_server: ContractServer = Depends(get_contract_service)
|
|
|
|
|
+# ) -> SuccessResponse:
|
|
|
|
|
+# logger.info(f"esign_callback_auth payload: {payload}")
|
|
|
|
|
+# return SuccessResponse(code="200", msg="success")
|
|
|
|
|
|
|
|
|
|
|