增加get_local_job_count函数
This commit is contained in:
parent
43fc266277
commit
0371b7a8a4
@ -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 }> => {
|
export const getLocalJobCount = async (): Promise<{ success: boolean; count?: number; message?: string }> => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(
|
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(),
|
headers: get_session_api_headers(),
|
||||||
withCredentials: true
|
withCredentials: true
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
const count = response.data?.message || 0
|
const count = response.data?.count || 0
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
count: count,
|
count: count,
|
||||||
@ -217,7 +217,7 @@ export const getLocalJobCount = async (): Promise<{ success: boolean; count?: nu
|
|||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
count: 0,
|
count: 0,
|
||||||
message: error.response?.data?.message || error.message || '获取Local Job总数失败'
|
message: error.response?.data?.detail || error.response?.data?.message || error.message || '获取Local Job总数失败'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,11 +34,6 @@ export interface LocalJobDetailResponse {
|
|||||||
data: LocalJob
|
data: LocalJob
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LocalJobStatsResponse {
|
|
||||||
success: boolean
|
|
||||||
stats: Record<string, any>
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface BatchDeleteResponse {
|
export interface BatchDeleteResponse {
|
||||||
success: boolean
|
success: boolean
|
||||||
message: string
|
message: string
|
||||||
@ -103,10 +98,3 @@ export async function batchDeleteLocalJobs(jobIds: string[]): Promise<BatchDelet
|
|||||||
return response.data
|
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
|
|
||||||
}
|
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import requests
|
|||||||
|
|
||||||
from jingrow.utils.auth import get_jingrow_api_headers
|
from jingrow.utils.auth import get_jingrow_api_headers
|
||||||
from jingrow.config import Config
|
from jingrow.config import Config
|
||||||
|
from jingrow.utils.jingrow_api import get_local_job_count
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
router = APIRouter()
|
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)}")
|
logger.error(f"Failed to batch delete local jobs: {str(e)}")
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
|
||||||
@router.get("/jingrow/local-jobs/stats")
|
@router.get("/jingrow/local-job-count")
|
||||||
async def get_local_job_stats(request: Request):
|
async def get_local_job_count_route(request: Request):
|
||||||
"""
|
"""
|
||||||
获取Local Job统计信息
|
获取Local Job总数
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# 统一使用系统级认证
|
count = get_local_job_count()
|
||||||
headers = get_jingrow_api_headers()
|
return {
|
||||||
if not headers:
|
"success": True,
|
||||||
logger.error("JINGROW_API_KEY 或 JINGROW_API_SECRET 未配置")
|
"count": count
|
||||||
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'))
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Failed to get local job stats: {str(e)}")
|
error_msg = str(e) if str(e) else f"未知错误: {type(e).__name__}"
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
logger.error(f"Failed to get local job count: {error_msg}", exc_info=True)
|
||||||
|
raise HTTPException(status_code=500, detail=error_msg)
|
||||||
|
|||||||
@ -553,6 +553,37 @@ def get_record_count(pagetype: str, filters: list = None, debug: bool = False, c
|
|||||||
log_error(f"获取记录总数异常: {str(e)}")
|
log_error(f"获取记录总数异常: {str(e)}")
|
||||||
return 0
|
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):
|
def get_record_id(pagetype: str, filters: list = None, field: str = None, value: str = None, site: str = None):
|
||||||
"""
|
"""
|
||||||
按条件获取单条记录的 name 值。
|
按条件获取单条记录的 name 值。
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user