|
@@ -1,6 +1,6 @@
|
|
|
import datetime
|
|
import datetime
|
|
|
from fastapi import APIRouter, Depends, Query
|
|
from fastapi import APIRouter, Depends, Query
|
|
|
-from typing import Any, List, Union
|
|
|
|
|
|
|
+from typing import Any, List, Union, Optional
|
|
|
import json
|
|
import json
|
|
|
import os
|
|
import os
|
|
|
import logging
|
|
import logging
|
|
@@ -118,17 +118,45 @@ async def create_esign_templates(
|
|
|
@router.get("/contracts/{store_id}", response_model=Union[List[ContractStoreResponse], dict])
|
|
@router.get("/contracts/{store_id}", response_model=Union[List[ContractStoreResponse], dict])
|
|
|
async def list_contracts(
|
|
async def list_contracts(
|
|
|
store_id: int,
|
|
store_id: int,
|
|
|
|
|
+ status: Optional[int] = Query(None, description="筛选合同状态:0 未签署,1 已签署"),
|
|
|
templates_server: ContractServer = Depends(get_contract_service)
|
|
templates_server: ContractServer = Depends(get_contract_service)
|
|
|
) -> Any:
|
|
) -> Any:
|
|
|
- """根据 store_id 查询所有合同"""
|
|
|
|
|
|
|
+ """根据 store_id 查询所有合同,支持根据 status 筛选"""
|
|
|
# 1. 检查 store_info 中的审核状态
|
|
# 1. 检查 store_info 中的审核状态
|
|
|
reason = await templates_server.get_store_reason(store_id)
|
|
reason = await templates_server.get_store_reason(store_id)
|
|
|
if reason != "审核通过":
|
|
if reason != "审核通过":
|
|
|
- return {"msg": "先进行认证"}
|
|
|
|
|
|
|
+ return {"code": 555, "msg": "先进行认证"}
|
|
|
|
|
|
|
|
# 2. 返回合同列表
|
|
# 2. 返回合同列表
|
|
|
rows = await templates_server.list_by_store(store_id)
|
|
rows = await templates_server.list_by_store(store_id)
|
|
|
- return [ContractStoreResponse(**row) for row in rows]
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if status is None:
|
|
|
|
|
+ return [ContractStoreResponse(**row) for row in rows]
|
|
|
|
|
+
|
|
|
|
|
+ # 3. 根据 status 筛选 contract_url 中的项
|
|
|
|
|
+ filtered_rows = []
|
|
|
|
|
+ for row in rows:
|
|
|
|
|
+ contract_url_raw = row.get("contract_url")
|
|
|
|
|
+ if not contract_url_raw:
|
|
|
|
|
+ continue
|
|
|
|
|
+ try:
|
|
|
|
|
+ items = json.loads(contract_url_raw)
|
|
|
|
|
+ if not isinstance(items, list):
|
|
|
|
|
+ continue
|
|
|
|
|
+
|
|
|
|
|
+ # 过滤列表中的合同项
|
|
|
|
|
+ filtered_items = [item for item in items if item.get("status") == status]
|
|
|
|
|
+
|
|
|
|
|
+ if filtered_items:
|
|
|
|
|
+ # 只有当存在符合条件的合同时,才返回该记录,并只包含符合条件的合同项
|
|
|
|
|
+ row_copy = dict(row)
|
|
|
|
|
+ row_copy["contract_url"] = json.dumps(filtered_items, ensure_ascii=False)
|
|
|
|
|
+ filtered_rows.append(ContractStoreResponse(**row_copy))
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ logger.error(f"Error filtering contracts for store_id {store_id}: {e}")
|
|
|
|
|
+ continue
|
|
|
|
|
+
|
|
|
|
|
+ return filtered_rows
|
|
|
|
|
|
|
|
@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(
|
|
@@ -226,3 +254,4 @@ async def esign_callback_auth(
|
|
|
logger.info(f"esign_callback_auth payload: {payload}")
|
|
logger.info(f"esign_callback_auth payload: {payload}")
|
|
|
return SuccessResponse(code="200", msg="success")
|
|
return SuccessResponse(code="200", msg="success")
|
|
|
|
|
|
|
|
|
|
+
|