增加get_local_job_count函数

This commit is contained in:
jingrow 2025-11-05 05:29:14 +08:00
parent 43fc266277
commit 0371b7a8a4
4 changed files with 46 additions and 44 deletions

View File

@ -200,14 +200,14 @@ export const getCount = async (pagetype: string): Promise<{ success: boolean; co
export const getLocalJobCount = async (): Promise<{ success: boolean; count?: number; message?: string }> => {
try {
const response = await axios.get(
`/api/action/jingrow.core.pagetype.local_job.local_job.get_local_job_count`,
`/jingrow/local-job-count`,
{
headers: get_session_api_headers(),
withCredentials: true
}
)
const count = response.data?.message || 0
const count = response.data?.count || 0
return {
success: true,
count: count,
@ -217,7 +217,7 @@ export const getLocalJobCount = async (): Promise<{ success: boolean; count?: nu
return {
success: false,
count: 0,
message: error.response?.data?.message || error.message || '获取Local Job总数失败'
message: error.response?.data?.detail || error.response?.data?.message || error.message || '获取Local Job总数失败'
}
}
}

View File

@ -34,11 +34,6 @@ export interface LocalJobDetailResponse {
data: LocalJob
}
export interface LocalJobStatsResponse {
success: boolean
stats: Record<string, any>
}
export interface BatchDeleteResponse {
success: boolean
message: string
@ -103,10 +98,3 @@ export async function batchDeleteLocalJobs(jobIds: string[]): Promise<BatchDelet
return response.data
}
/**
* Local Job统计信息
*/
export async function getLocalJobStats(): Promise<LocalJobStatsResponse> {
const response = await axios.get(`${API_BASE_URL}/local-jobs/stats`)
return response.data
}

View File

@ -6,6 +6,7 @@ import requests
from jingrow.utils.auth import get_jingrow_api_headers
from jingrow.config import Config
from jingrow.utils.jingrow_api import get_local_job_count
logger = logging.getLogger(__name__)
router = APIRouter()
@ -273,36 +274,18 @@ async def batch_delete_local_jobs(request: Request, request_data: Dict[str, Any]
logger.error(f"Failed to batch delete local jobs: {str(e)}")
raise HTTPException(status_code=500, detail=str(e))
@router.get("/jingrow/local-jobs/stats")
async def get_local_job_stats(request: Request):
@router.get("/jingrow/local-job-count")
async def get_local_job_count_route(request: Request):
"""
获取Local Job统计信息
获取Local Job总数
"""
try:
# 统一使用系统级认证
headers = get_jingrow_api_headers()
if not headers:
logger.error("JINGROW_API_KEY 或 JINGROW_API_SECRET 未配置")
raise HTTPException(status_code=500, detail="系统认证配置错误")
headers.update({
"X-Requested-With": "XMLHttpRequest",
})
result = call_jingrow_api(
'POST',
'/api/action/jingrow.core.pagetype.local_job.local_job.get_stats',
headers=headers
)
if result.get('success'):
return {
"success": True,
"stats": result.get('data', {})
}
else:
raise HTTPException(status_code=500, detail=result.get('error', 'Failed to get stats'))
count = get_local_job_count()
return {
"success": True,
"count": count
}
except Exception as e:
logger.error(f"Failed to get local job stats: {str(e)}")
raise HTTPException(status_code=500, detail=str(e))
error_msg = str(e) if str(e) else f"未知错误: {type(e).__name__}"
logger.error(f"Failed to get local job count: {error_msg}", exc_info=True)
raise HTTPException(status_code=500, detail=error_msg)

View File

@ -553,6 +553,37 @@ def get_record_count(pagetype: str, filters: list = None, debug: bool = False, c
log_error(f"获取记录总数异常: {str(e)}")
return 0
def get_local_job_count():
"""
获取 Local Job 总数
Returns: int 记录总数失败返回 0
"""
try:
api_url = f"{Config.jingrow_server_url}/api/action/jingrow.core.pagetype.local_job.local_job.get_local_job_count"
headers = get_jingrow_api_headers()
if not headers:
log_error("JINGROW_API_KEY 或 JINGROW_API_SECRET 未配置")
return 0
response = requests.get(api_url, headers=headers, timeout=10)
if response.status_code == 200:
data = response.json()
# 处理服务端 action 的包裹格式
if isinstance(data, dict) and 'message' in data:
count = data['message']
else:
count = data
# 确保返回的是整数
if isinstance(count, (int, float)):
return int(count)
return 0
else:
log_error(f"获取Local Job总数失败: HTTP {response.status_code}")
return 0
except Exception as e:
log_error(f"获取Local Job总数异常: {str(e)}")
return 0
def get_record_id(pagetype: str, filters: list = None, field: str = None, value: str = None, site: str = None):
"""
按条件获取单条记录的 name