563 lines
23 KiB
TypeScript
563 lines
23 KiB
TypeScript
/**
|
|
* features/admin/api/admin.api.ts
|
|
* 用途:管理后台用户、部门、Agent、货代客户、权限、报表等 HTTP API。
|
|
* 依赖:requestJson、getAuthHeaders、各管理域类型。
|
|
* 逻辑:JSON 接口统一走 requestJson;模板与对账二进制下载沿用认证 fetch 并抛 BusinessError。
|
|
*/
|
|
import { getAuthHeaders } from '@/shared/utils/auth';
|
|
import { BusinessError, requestJson, resolveLocalizedErrorMessage } from '@/shared/api/client';
|
|
import type { AdminUserRow } from '../types/admin.types';
|
|
import type { AdminDashboardBadges, AdminDashboardSummary } from '../types/dashboard.types';
|
|
import type { PaginatedResult } from '@/shared/types/pagination.types';
|
|
import type {
|
|
ApplicationReport,
|
|
ApplicationSortKey,
|
|
ApplicationStatusFilter,
|
|
ApplicationUsageFilter,
|
|
UsageReport,
|
|
UsageRangeKey,
|
|
} from '../types/report.types';
|
|
import type {
|
|
ShippingCustomerIdentifier,
|
|
ShippingCustomerImportBatch,
|
|
ShippingCustomerPage,
|
|
ShippingCustomerRow,
|
|
ShippingCustomerShadowItem,
|
|
ShippingCustomerShadowReport,
|
|
ShippingIdentifierFormState,
|
|
} from '../types/shipping-customer.types';
|
|
|
|
const auth = () => ({ headers: getAuthHeaders() });
|
|
const jsonAuth = () => ({ headers: { 'Content-Type': 'application/json', ...getAuthHeaders() } });
|
|
|
|
/** 下载管理端二进制文件,并将标准错误 envelope 保留为 BusinessError。 */
|
|
const downloadAdminFile = async (url: string, fallbackName: string): Promise<void> => {
|
|
const response = await fetch(url, { headers: getAuthHeaders() });
|
|
if (!response.ok) {
|
|
const payload = await response.json().catch(() => null);
|
|
const code = payload?.error?.code || 'SYSTEM.HTTP_ERROR';
|
|
throw new BusinessError({
|
|
message: resolveLocalizedErrorMessage(code, payload?.error?.message || `HTTP ${response.status}`),
|
|
code,
|
|
details: payload?.error?.details || {},
|
|
requestId: payload?.request_id,
|
|
status: response.status,
|
|
});
|
|
}
|
|
const blob = await response.blob();
|
|
const disposition = response.headers.get('Content-Disposition') || '';
|
|
const encodedName = disposition.match(/filename\*=UTF-8''([^;]+)/i)?.[1];
|
|
const plainName = disposition.match(/filename="?([^";]+)"?/i)?.[1];
|
|
const filename = encodedName ? decodeURIComponent(encodedName) : plainName || fallbackName;
|
|
const objectUrl = URL.createObjectURL(blob);
|
|
const anchor = document.createElement('a');
|
|
anchor.href = objectUrl;
|
|
anchor.download = filename;
|
|
anchor.click();
|
|
URL.revokeObjectURL(objectUrl);
|
|
};
|
|
|
|
// Shipping customers
|
|
export interface ListShippingCustomersParams {
|
|
q?: string;
|
|
status?: string;
|
|
page?: number;
|
|
pageSize?: number;
|
|
}
|
|
|
|
/** 分页查询货代标准客户。 */
|
|
export const listShippingCustomers = (params: ListShippingCustomersParams = {}) => {
|
|
const qs = new URLSearchParams();
|
|
if (params.q?.trim()) qs.set('q', params.q.trim());
|
|
if (params.status) qs.set('status', params.status);
|
|
qs.set('page', String(params.page || 1));
|
|
qs.set('page_size', String(params.pageSize || 20));
|
|
return requestJson<ShippingCustomerPage>(`/api/admin/shipping-customers?${qs.toString()}`, auth());
|
|
};
|
|
|
|
export const getShippingCustomer = (id: number) =>
|
|
requestJson<ShippingCustomerRow>(`/api/admin/shipping-customers/${id}`, auth());
|
|
|
|
export const createShippingCustomer = (payload: Record<string, unknown>) =>
|
|
requestJson<ShippingCustomerRow>('/api/admin/shipping-customers', {
|
|
method: 'POST', ...jsonAuth(), body: JSON.stringify(payload),
|
|
});
|
|
|
|
export const updateShippingCustomer = (id: number, payload: Record<string, unknown>) =>
|
|
requestJson<ShippingCustomerRow>(`/api/admin/shipping-customers/${id}`, {
|
|
method: 'PUT', ...jsonAuth(), body: JSON.stringify(payload),
|
|
});
|
|
|
|
export const deactivateShippingCustomer = (id: number) =>
|
|
requestJson<ShippingCustomerRow>(`/api/admin/shipping-customers/${id}/deactivate`, {
|
|
method: 'POST', ...auth(),
|
|
});
|
|
|
|
export const createShippingCustomerIdentifier = (customerId: number, payload: ShippingIdentifierFormState) =>
|
|
requestJson<ShippingCustomerIdentifier>(`/api/admin/shipping-customers/${customerId}/identifiers`, {
|
|
method: 'POST', ...jsonAuth(), body: JSON.stringify(payload),
|
|
});
|
|
|
|
export const updateShippingCustomerIdentifier = (identifierId: number, payload: Record<string, unknown>) =>
|
|
requestJson<ShippingCustomerIdentifier>(`/api/admin/shipping-customer-identifiers/${identifierId}`, {
|
|
method: 'PUT', ...jsonAuth(), body: JSON.stringify(payload),
|
|
});
|
|
|
|
export const uploadShippingCustomerImport = (file: File, sourceSystem: string) => {
|
|
const body = new FormData();
|
|
body.append('file', file);
|
|
body.append('source_system', sourceSystem);
|
|
return requestJson<ShippingCustomerImportBatch>('/api/admin/shipping-customer-imports', {
|
|
method: 'POST', headers: getAuthHeaders(), body,
|
|
});
|
|
};
|
|
|
|
export const decideShippingCustomerImportRow = (
|
|
rowId: number,
|
|
payload: { action: string; target_customer_id?: number; note?: string },
|
|
) => requestJson(`/api/admin/shipping-customer-import-rows/${rowId}/decision`, {
|
|
method: 'PUT', ...jsonAuth(), body: JSON.stringify(payload),
|
|
});
|
|
|
|
export const publishShippingCustomerImport = (batchId: number) =>
|
|
requestJson<ShippingCustomerImportBatch>(`/api/admin/shipping-customer-imports/${batchId}/publish`, {
|
|
method: 'POST', ...auth(),
|
|
});
|
|
|
|
export const downloadShippingCustomerImportTemplate = () =>
|
|
downloadAdminFile('/api/admin/shipping-customers/import-template', 'shipping_customer_import_template.xlsx');
|
|
|
|
export const downloadShippingCustomerReconciliation = (batchId: number, batchNo: string) =>
|
|
downloadAdminFile(
|
|
`/api/admin/shipping-customer-imports/${batchId}/reconciliation`,
|
|
`${batchNo}_reconciliation.csv`,
|
|
);
|
|
|
|
export const getShippingCustomerShadowReport = (limit = 100) =>
|
|
requestJson<ShippingCustomerShadowReport>(`/api/admin/shipping-customer-shadow-report?limit=${limit}`, auth());
|
|
|
|
export const labelShippingCustomerShadowResolution = (resolutionId: number, customerId: number) =>
|
|
requestJson<ShippingCustomerShadowItem>(
|
|
`/api/admin/shipping-customer-shadow-resolutions/${resolutionId}/label`,
|
|
{ method: 'PUT', ...jsonAuth(), body: JSON.stringify({ customer_id: customerId }) },
|
|
);
|
|
|
|
// Users
|
|
export const listAdminUsers = () => requestJson<AdminUserRow[]>('/api/admin/users', auth());
|
|
|
|
export interface ListAdminUsersPageParams {
|
|
page?: number;
|
|
pageSize?: number;
|
|
username?: string;
|
|
email?: string;
|
|
department?: string;
|
|
role?: string;
|
|
status?: string;
|
|
real_name?: string;
|
|
employee_id?: string;
|
|
phone_number?: string;
|
|
hideRejected?: boolean;
|
|
/** 排序列:username | department */
|
|
sortBy?: 'username' | 'department';
|
|
/** 排序方向 */
|
|
sortDir?: 'asc' | 'desc';
|
|
}
|
|
|
|
/**
|
|
* 分页拉取用户列表(服务端筛选 + 分页 + 排序,供用户管理页使用)。
|
|
* @param params - 页码、每页条数、字段模糊筛选与 sortBy/sortDir
|
|
*/
|
|
export const listAdminUsersPage = (params: ListAdminUsersPageParams) => {
|
|
const qs = new URLSearchParams();
|
|
qs.set('page', String(params.page ?? 1));
|
|
qs.set('page_size', String(params.pageSize ?? 20));
|
|
const textFilters: Array<{ paramKey: keyof ListAdminUsersPageParams; queryKey: string }> = [
|
|
{ paramKey: 'username', queryKey: 'username' },
|
|
{ paramKey: 'email', queryKey: 'email' },
|
|
{ paramKey: 'department', queryKey: 'department' },
|
|
{ paramKey: 'role', queryKey: 'role' },
|
|
{ paramKey: 'status', queryKey: 'status' },
|
|
{ paramKey: 'real_name', queryKey: 'real_name' },
|
|
{ paramKey: 'employee_id', queryKey: 'employee_id' },
|
|
{ paramKey: 'phone_number', queryKey: 'phone_number' },
|
|
];
|
|
for (const { paramKey, queryKey } of textFilters) {
|
|
const raw = params[paramKey];
|
|
const value = typeof raw === 'string' ? raw.trim() : '';
|
|
if (value) qs.set(queryKey, value);
|
|
}
|
|
if (params.hideRejected) qs.set('hide_rejected', 'true');
|
|
if (params.sortBy) qs.set('sort_by', params.sortBy);
|
|
if (params.sortDir) qs.set('sort_dir', params.sortDir);
|
|
return requestJson<PaginatedResult<AdminUserRow>>(`/api/admin/users?${qs.toString()}`, auth());
|
|
};
|
|
export const createAdminUser = (payload: Record<string, unknown>) =>
|
|
requestJson('/api/admin/users', { method: 'POST', ...jsonAuth(), body: JSON.stringify(payload) });
|
|
export const updateAdminUser = (id: number, payload: Record<string, unknown>) =>
|
|
requestJson(`/api/admin/users/${id}`, { method: 'PUT', ...jsonAuth(), body: JSON.stringify(payload) });
|
|
export const approveAdminUser = (id: number) =>
|
|
requestJson(`/api/admin/users/${id}/approve`, { method: 'POST', ...auth() });
|
|
export const rejectAdminUser = (id: number) =>
|
|
requestJson(`/api/admin/users/${id}/reject`, { method: 'POST', ...auth() });
|
|
export const cleanupRejectedAdminUsers = () =>
|
|
requestJson<{ deleted_count: number }>('/api/admin/users/cleanup-rejected', { method: 'POST', ...auth() });
|
|
export const batchDeleteAdminUsers = (userIds: number[]) =>
|
|
requestJson<{ deleted_count: number }>('/api/admin/users/batch-delete', {
|
|
method: 'POST',
|
|
...jsonAuth(),
|
|
body: JSON.stringify({ user_ids: userIds }),
|
|
});
|
|
export const batchUpdateAdminUsers = (userIds: number[], data: Record<string, unknown>) =>
|
|
requestJson('/api/admin/users/batch', {
|
|
method: 'PUT',
|
|
...jsonAuth(),
|
|
body: JSON.stringify({ user_ids: userIds, data }),
|
|
});
|
|
export const updateAdminUserPermissions = (userId: number, agentIds: number[]) =>
|
|
requestJson(`/api/admin/users/${userId}/permissions`, {
|
|
method: 'POST',
|
|
...jsonAuth(),
|
|
body: JSON.stringify({ agent_ids: agentIds }),
|
|
});
|
|
|
|
// Departments
|
|
export const listAdminDepartments = () => requestJson<any[]>('/api/admin/departments', auth());
|
|
export const createAdminDepartment = (payload: Record<string, unknown>) =>
|
|
requestJson('/api/admin/departments', { method: 'POST', ...jsonAuth(), body: JSON.stringify(payload) });
|
|
export const updateAdminDepartment = (id: number, payload: Record<string, unknown>) =>
|
|
requestJson(`/api/admin/departments/${id}`, { method: 'PUT', ...jsonAuth(), body: JSON.stringify(payload) });
|
|
export const deleteAdminDepartment = (id: number) =>
|
|
requestJson(`/api/admin/departments/${id}`, { method: 'DELETE', ...auth() });
|
|
|
|
// Agents
|
|
export interface AdminAgentRegistrySchema {
|
|
platform: {
|
|
runtime_providers: string[];
|
|
conversation_modes: string[];
|
|
dify_app_types: string[];
|
|
suggested_questions_styles: string[];
|
|
default_capabilities: Record<string, boolean>;
|
|
tool_run_progress_defaults: {
|
|
progress_type?: string;
|
|
poll_interval_seconds?: number;
|
|
lock_input_when_running?: boolean;
|
|
};
|
|
};
|
|
agent_types: Array<{
|
|
agent_code: string;
|
|
label: string;
|
|
conversation_mode_default: string;
|
|
runtime_provider_default: string;
|
|
runtime_handler?: string | null;
|
|
models?: string[];
|
|
required_fields?: string[];
|
|
forced_capabilities?: Record<string, boolean>;
|
|
default_capabilities?: Record<string, boolean>;
|
|
default_intent_routes?: string[];
|
|
progress_contract?: Record<string, unknown> | null;
|
|
handler_config_schema?: Record<string, unknown>;
|
|
}>;
|
|
handler_config_schemas: Record<string, unknown>;
|
|
content_profile_keys: string[];
|
|
}
|
|
|
|
export const getAdminAgentRegistrySchema = () =>
|
|
requestJson<AdminAgentRegistrySchema>('/api/admin/agents/schema', auth());
|
|
|
|
export const inferAdminContentProfile = (intentRoutes: string[]) =>
|
|
requestJson<{ content_profile: string | null }>('/api/admin/agents/infer-content-profile', {
|
|
method: 'POST',
|
|
...jsonAuth(),
|
|
body: JSON.stringify({ intent_routes: intentRoutes }),
|
|
});
|
|
|
|
export const listAdminAgentTypeCatalog = () =>
|
|
getAdminAgentRegistrySchema().then((schema) => schema.agent_types);
|
|
|
|
export interface AdminIntentRouteOption {
|
|
key: string;
|
|
label: string;
|
|
description?: string;
|
|
category?: string;
|
|
enabled?: boolean;
|
|
sort_order?: number;
|
|
}
|
|
|
|
export const listAdminIntentRoutes = () =>
|
|
requestJson<AdminIntentRouteOption[]>('/api/admin/agents/intent-routes', auth());
|
|
|
|
export interface AdminContentProfileOption {
|
|
key: string;
|
|
label: string;
|
|
description?: string;
|
|
welcome_message?: string;
|
|
suggested_questions_style?: 'plain' | 'styled';
|
|
suggested_questions?: Array<{ question: string; group?: string }>;
|
|
}
|
|
|
|
export const listAdminContentProfiles = () =>
|
|
requestJson<AdminContentProfileOption[]>('/api/admin/agents/content-profiles', auth());
|
|
|
|
export const listAdminAgents = () => requestJson<any[]>('/api/admin/agents', auth());
|
|
export const createAdminAgent = (payload: Record<string, unknown>) =>
|
|
requestJson('/api/admin/agents', { method: 'POST', ...jsonAuth(), body: JSON.stringify(payload) });
|
|
export const updateAdminAgent = (id: number, payload: Record<string, unknown>) =>
|
|
requestJson(`/api/admin/agents/${id}`, { method: 'PUT', ...jsonAuth(), body: JSON.stringify(payload) });
|
|
export const deleteAdminAgent = (id: number) =>
|
|
requestJson(`/api/admin/agents/${id}`, { method: 'DELETE', ...auth() });
|
|
|
|
// Agent Guides
|
|
export const listAdminAgentGuides = (agentId?: number) => {
|
|
const url = agentId ? `/api/admin/guides?agent_id=${agentId}` : '/api/admin/guides';
|
|
return requestJson<any[]>(url, auth());
|
|
};
|
|
|
|
export const createAdminAgentGuide = (payload: Record<string, unknown>) =>
|
|
requestJson('/api/admin/guides', { method: 'POST', ...jsonAuth(), body: JSON.stringify(payload) });
|
|
|
|
export const updateAdminAgentGuide = (id: number, payload: Record<string, unknown>) =>
|
|
requestJson(`/api/admin/guides/${id}`, { method: 'PUT', ...jsonAuth(), body: JSON.stringify(payload) });
|
|
|
|
export const deleteAdminAgentGuide = (id: number) =>
|
|
requestJson(`/api/admin/guides/${id}`, { method: 'DELETE', ...auth() });
|
|
|
|
export const uploadAdminAgentGuideFile = async (file: File) => {
|
|
const formData = new FormData();
|
|
formData.append('file', file);
|
|
const response = await fetch('/api/admin/guides/upload', {
|
|
method: 'POST',
|
|
headers: getAuthHeaders(),
|
|
body: formData,
|
|
});
|
|
if (!response.ok) {
|
|
const error = await response.json().catch(() => ({}));
|
|
throw new Error(error.message || 'Upload failed');
|
|
}
|
|
return response.json();
|
|
};
|
|
export const importAdminAgentTrainingQuestionBankFromPdf = (agentId: number, payload: { guide_id?: number | null }) =>
|
|
requestJson<{
|
|
guide_id: number;
|
|
guide_file_name: string;
|
|
parsed_count: number;
|
|
skipped_question_numbers: number[];
|
|
extraction_mode?: 'pdf_text' | 'ocr' | 'ocr_fallback';
|
|
extraction_warnings?: string[];
|
|
question_bank: Array<{
|
|
id: string;
|
|
type: 'single' | 'boolean';
|
|
prompt: string;
|
|
answer: string;
|
|
explanation: string;
|
|
options?: Array<{ id: string; label: string }>;
|
|
}>;
|
|
}>(`/api/admin/agents/${agentId}/training-question-bank/import-pdf`, {
|
|
method: 'POST',
|
|
...jsonAuth(),
|
|
body: JSON.stringify(payload),
|
|
});
|
|
export const testAdminAgent = (id: number) =>
|
|
requestJson<any>(`/api/admin/agents/${id}/test`, { method: 'POST', ...auth() });
|
|
export const saveAdminAgentPermissions = (agentId: number, userIds: number[]) =>
|
|
requestJson(`/api/admin/agents/${agentId}/permissions`, {
|
|
method: 'POST',
|
|
...jsonAuth(),
|
|
body: JSON.stringify({ user_ids: userIds }),
|
|
});
|
|
|
|
// Permission requests
|
|
export const listAdminPermissionRequests = () =>
|
|
requestJson<any[]>('/api/admin/permission-requests', auth());
|
|
export const approveAdminPermissionRequest = (id: number) =>
|
|
requestJson(`/api/admin/permission-requests/${id}/approve`, { method: 'POST', ...auth() });
|
|
export const rejectAdminPermissionRequest = (id: number) =>
|
|
requestJson(`/api/admin/permission-requests/${id}/reject`, { method: 'POST', ...auth() });
|
|
export const batchUpdateAdminPermissions = (payload: Record<string, unknown>) =>
|
|
requestJson('/api/admin/permissions/batch', { method: 'POST', ...jsonAuth(), body: JSON.stringify(payload) });
|
|
export const importAdminPermissions = (formData: FormData) =>
|
|
requestJson('/api/admin/permissions/import', { method: 'POST', ...auth(), body: formData });
|
|
|
|
// Dashboard
|
|
/** 仪表盘四张卡片:Agent 数、用户数、对话总数、平均评分 */
|
|
export const getAdminDashboardSummary = () =>
|
|
requestJson<AdminDashboardSummary>('/api/admin/dashboard/summary', auth());
|
|
|
|
/** 侧栏角标:待审批用户数、待处理权限申请数 */
|
|
export const getAdminDashboardBadges = () =>
|
|
requestJson<AdminDashboardBadges>('/api/admin/dashboard/badges', auth());
|
|
|
|
// Reports
|
|
export interface AdminUsageReportParams {
|
|
user_page?: number;
|
|
user_page_size?: number;
|
|
/** 时间范围:7d | 30d | 90d | 180d | 365d */
|
|
range?: UsageRangeKey;
|
|
}
|
|
|
|
export const getAdminUsageReport = (params: AdminUsageReportParams = {}) => {
|
|
const qs = new URLSearchParams();
|
|
if (params.user_page != null) qs.set('user_page', String(params.user_page));
|
|
if (params.user_page_size != null) qs.set('user_page_size', String(params.user_page_size));
|
|
if (params.range) qs.set('range', params.range);
|
|
const query = qs.toString();
|
|
return requestJson<UsageReport>(
|
|
`/api/admin/reports/usage${query ? `?${query}` : ''}`,
|
|
auth(),
|
|
);
|
|
};
|
|
|
|
export interface AdminApplicationReportParams {
|
|
range?: UsageRangeKey;
|
|
status?: ApplicationStatusFilter;
|
|
usage?: ApplicationUsageFilter;
|
|
q?: string;
|
|
sort?: ApplicationSortKey;
|
|
order?: 'asc' | 'desc';
|
|
page?: number;
|
|
page_size?: number;
|
|
}
|
|
|
|
/**
|
|
* 拉取应用运营报表(按应用聚合使用 / 权限 / 评分)。
|
|
* @param params - 时间范围、状态、使用筛选、搜索与排序分页
|
|
*/
|
|
export const getAdminApplicationReport = (params: AdminApplicationReportParams = {}) => {
|
|
const qs = new URLSearchParams();
|
|
if (params.range) qs.set('range', params.range);
|
|
if (params.status && params.status !== 'all') qs.set('status', params.status);
|
|
if (params.usage && params.usage !== 'all') qs.set('usage', params.usage);
|
|
if (params.q?.trim()) qs.set('q', params.q.trim());
|
|
if (params.sort) qs.set('sort', params.sort);
|
|
if (params.order) qs.set('order', params.order);
|
|
if (params.page != null) qs.set('page', String(params.page));
|
|
if (params.page_size != null) qs.set('page_size', String(params.page_size));
|
|
const query = qs.toString();
|
|
return requestJson<ApplicationReport>(
|
|
`/api/admin/reports/applications${query ? `?${query}` : ''}`,
|
|
auth(),
|
|
);
|
|
};
|
|
|
|
export const getAdminFeedbackReport = () => requestJson<any>('/api/admin/reports/feedback', auth());
|
|
export const getAdminReportTable = (url: string) => requestJson<any[]>(url, auth());
|
|
export const getAdminReportTableCount = (url: string) => requestJson<{ total: number }>(url, auth());
|
|
export const batchDeleteAdminChatLogs = (ids: number[]) =>
|
|
requestJson<{ deleted_count: number }>('/api/admin/database/chat_logs/batch-delete', {
|
|
method: 'POST',
|
|
...jsonAuth(),
|
|
body: JSON.stringify({ ids }),
|
|
});
|
|
|
|
// WeCom admin
|
|
export interface ListAdminWecomBindingsParams {
|
|
boundOnly?: boolean;
|
|
keyword?: string;
|
|
page?: number;
|
|
pageSize?: number;
|
|
}
|
|
|
|
export const listAdminWecomBindings = (params: ListAdminWecomBindingsParams = {}) => {
|
|
const qs = new URLSearchParams();
|
|
if (params.boundOnly) qs.set('bound_only', 'true');
|
|
const keyword = params.keyword?.trim();
|
|
if (keyword) qs.set('keyword', keyword);
|
|
if (params.page) qs.set('page', String(params.page));
|
|
if (params.pageSize) qs.set('page_size', String(params.pageSize));
|
|
const query = qs.toString();
|
|
const suffix = query ? `?${query}` : '';
|
|
return requestJson<import('@/shared/types/pagination.types').PaginatedResult<
|
|
import('@/features/admin/types/wecom.types').WecomBindingRow
|
|
>>(`/api/admin/wecom/bindings${suffix}`, auth());
|
|
};
|
|
export const listAdminWecomLoginAudits = (query: string) =>
|
|
requestJson<any[]>(`/api/admin/wecom/login-audits?${query}`, auth());
|
|
export const getAdminWecomSystemSettings = () =>
|
|
requestJson<any>('/api/admin/wecom/system-settings', auth());
|
|
export const getAdminWecomIntegrationManifest = () =>
|
|
requestJson<any>('/api/admin/wecom/integration-manifest', auth());
|
|
export const saveAdminWecomSystemSettings = (payload: Record<string, unknown>) =>
|
|
requestJson<any>('/api/admin/wecom/system-settings', {
|
|
method: 'PUT',
|
|
...jsonAuth(),
|
|
body: JSON.stringify(payload),
|
|
});
|
|
export const getAdminWecomNotifySettings = () =>
|
|
requestJson<any>('/api/admin/wecom/notify-settings', auth());
|
|
export const saveAdminWecomNotifySettings = (payload: Record<string, unknown>) =>
|
|
requestJson<any>('/api/admin/wecom/notify-settings', {
|
|
method: 'PUT',
|
|
...jsonAuth(),
|
|
body: JSON.stringify(payload),
|
|
});
|
|
export const getAdminWecomNotifyMetrics = () =>
|
|
requestJson<any>('/api/admin/wecom/notify-metrics', auth());
|
|
export const getAdminWecomBindingStats = () =>
|
|
requestJson<import('@/features/admin/types/wecom.types').WecomBindingStats>('/api/admin/wecom/binding-stats', auth());
|
|
export const syncAdminWecomUserids = (payload: { apply: boolean }) =>
|
|
requestJson<import('@/features/admin/types/wecom.types').WecomSyncSummary>('/api/admin/wecom/sync-userids', {
|
|
method: 'POST',
|
|
...jsonAuth(),
|
|
body: JSON.stringify(payload),
|
|
});
|
|
export const bindAdminWecomUser = (payload: Record<string, unknown>) =>
|
|
requestJson('/api/admin/wecom/bind', { method: 'POST', ...jsonAuth(), body: JSON.stringify(payload) });
|
|
export const unbindAdminWecomUser = (userId: number) =>
|
|
requestJson('/api/admin/wecom/unbind', {
|
|
method: 'POST',
|
|
...jsonAuth(),
|
|
body: JSON.stringify({ user_id: userId }),
|
|
});
|
|
|
|
// Announcements
|
|
export const listAnnouncements = () => requestJson<any[]>('/api/admin/announcements', auth());
|
|
export const createAnnouncement = (payload: Record<string, unknown>) =>
|
|
requestJson('/api/admin/announcements', { method: 'POST', ...jsonAuth(), body: JSON.stringify(payload) });
|
|
export const updateAnnouncement = (id: number, payload: Record<string, unknown>) =>
|
|
requestJson(`/api/admin/announcements/${id}`, { method: 'PUT', ...jsonAuth(), body: JSON.stringify(payload) });
|
|
export const deleteAnnouncement = (id: number) =>
|
|
requestJson(`/api/admin/announcements/${id}`, { method: 'DELETE', ...auth() });
|
|
|
|
// Quick questions
|
|
export const listAdminQuickQuestions = () => requestJson<any[]>('/api/admin/quick-questions', auth());
|
|
export const saveAdminQuickQuestion = (url: string, method: string, payload: Record<string, unknown>) =>
|
|
requestJson(url, { method, ...jsonAuth(), body: JSON.stringify(payload) });
|
|
export const deleteAdminQuickQuestion = (id: number) =>
|
|
requestJson(`/api/admin/quick-questions/${id}`, { method: 'DELETE', ...auth() });
|
|
|
|
// Hot FAQ candidates (offline aggregation)
|
|
export const listAdminFaqCandidates = (agentId?: number) => {
|
|
const query = agentId ? `?agent_id=${agentId}` : '';
|
|
return requestJson<any>(`/api/admin/faq-candidates${query}`, auth());
|
|
};
|
|
|
|
export const refreshAdminFaqCandidates = (payload?: { agent_id?: number; dry_run?: boolean }) =>
|
|
requestJson<{
|
|
promoted_count?: number;
|
|
scanned_logs?: number;
|
|
enabled?: boolean;
|
|
dry_run?: boolean;
|
|
}>('/api/admin/faq-candidates/refresh', {
|
|
method: 'POST',
|
|
...jsonAuth(),
|
|
body: JSON.stringify(payload || {}),
|
|
});
|
|
|
|
export const promoteAdminFaqCandidate = (payload: {
|
|
agent_id: number;
|
|
q_norm: string;
|
|
title?: string;
|
|
sort_order?: number;
|
|
}) =>
|
|
requestJson('/api/admin/faq-candidates/promote', {
|
|
method: 'POST',
|
|
...jsonAuth(),
|
|
body: JSON.stringify(payload),
|
|
});
|
|
|
|
export const dismissAdminFaqCandidate = (payload: { agent_id: number; q_norm: string }) =>
|
|
requestJson('/api/admin/faq-candidates/dismiss', {
|
|
method: 'POST',
|
|
...jsonAuth(),
|
|
body: JSON.stringify(payload),
|
|
});
|