|
|
@@ -9,6 +9,7 @@ from models.chat import AIMessage
|
|
|
from models.user_data import UserData
|
|
|
from services.oss_service import oss_service
|
|
|
from utils.crypto import decrypt_url
|
|
|
+from utils.config import get_proxy_url
|
|
|
import time
|
|
|
import httpx
|
|
|
|
|
|
@@ -28,41 +29,48 @@ async def get_recommend_question(db: Session = Depends(get_db)):
|
|
|
|
|
|
@router.get("/get_policy_file")
|
|
|
async def get_policy_file(
|
|
|
- policy_type: Optional[int] = None,
|
|
|
+ policy_type: Optional[str] = None,
|
|
|
page: int = 1,
|
|
|
- page_size: int = 20,
|
|
|
+ pageSize: int = 20,
|
|
|
+ search: str = "",
|
|
|
db: Session = Depends(get_db)
|
|
|
):
|
|
|
"""获取策略文件列表"""
|
|
|
query = db.query(PolicyFile).filter(PolicyFile.is_deleted == 0)
|
|
|
|
|
|
- if policy_type is not None and policy_type != 0:
|
|
|
- query = query.filter(PolicyFile.policy_type == policy_type)
|
|
|
-
|
|
|
- total = query.count()
|
|
|
-
|
|
|
- offset = (page - 1) * page_size
|
|
|
+ # 只有当policy_type有效且不为0或空字符串时才添加类型过滤
|
|
|
+ if policy_type and policy_type != "" and policy_type != "0":
|
|
|
+ try:
|
|
|
+ policy_type_int = int(policy_type)
|
|
|
+ query = query.filter(PolicyFile.policy_type == policy_type_int)
|
|
|
+ except ValueError:
|
|
|
+ pass # 忽略无效的类型值
|
|
|
+
|
|
|
+ if search:
|
|
|
+ query = query.filter(PolicyFile.policy_name.like(f"%{search}%"))
|
|
|
+
|
|
|
+ offset = (page - 1) * pageSize
|
|
|
files = query.order_by(PolicyFile.updated_at.desc()).offset(
|
|
|
- offset).limit(page_size).all()
|
|
|
+ offset).limit(pageSize).all()
|
|
|
|
|
|
return {
|
|
|
"statusCode": 200,
|
|
|
"msg": "success",
|
|
|
- "data": {
|
|
|
- "total": total,
|
|
|
- "items": [
|
|
|
- {
|
|
|
- "id": f.id,
|
|
|
- "policy_name": f.policy_name,
|
|
|
- "policy_file_url": f.policy_file_url,
|
|
|
- "policy_type": f.policy_type,
|
|
|
- "file_type": f.file_type,
|
|
|
- "view_count": f.view_count,
|
|
|
- "created_at": f.created_at
|
|
|
- }
|
|
|
- for f in files
|
|
|
- ]
|
|
|
- }
|
|
|
+ "data": [
|
|
|
+ {
|
|
|
+ "id": f.id,
|
|
|
+ "policy_name": f.policy_name,
|
|
|
+ "policy_file_url": get_proxy_url(f.policy_file_url),
|
|
|
+ "policy_type": f.policy_type,
|
|
|
+ "file_type": f.file_type,
|
|
|
+ "file_tag": getattr(f, 'file_tag', ''),
|
|
|
+ "publish_time": getattr(f, 'publish_time', f.created_at),
|
|
|
+ "view_count": f.view_count,
|
|
|
+ "created_at": f.created_at,
|
|
|
+ "updated_at": f.updated_at
|
|
|
+ }
|
|
|
+ for f in files
|
|
|
+ ]
|
|
|
}
|
|
|
|
|
|
|