import { defHttp } from '@jeesite/core/utils/http/axios'; import { useGlobSetting } from '@jeesite/core/hooks/setting'; import type { Result } from '@jeesite/types/axios'; import type { FileInfo } from '@jeesite/types/api'; import { CalcTaskDTO, DataTableDTO, DoCleanDTO, GovernTree, PrepareProcessFileDTO } from './types/dto'; import { Query } from '@jeesite/types'; import { GovernTreeQuery } from './types/query'; const { adminPath } = useGlobSetting(); const DEFAULT_ELECTRON_API_URL = 'http://localhost:8980'; const trimRightSlash = (value = '') => value.replace(/\/+$/, ''); const ensureLeftSlash = (value = '') => (value.startsWith('/') ? value : `/${value}`); const joinUrl = (...parts: Array) => { const filtered = parts.filter(Boolean) as string[]; if (!filtered.length) return ''; return filtered .map((part, index) => { if (index === 0) return trimRightSlash(part); return ensureLeftSlash(part).replace(/\/+$/, ''); }) .join(''); }; const getRuntimeOrigin = () => { if (typeof window === 'undefined') return ''; const { origin, protocol } = window.location; if (protocol !== 'http:' && protocol !== 'https:') return ''; return origin && origin !== 'null' ? origin : ''; }; const getPackagedFallbackOrigin = () => { if (typeof window === 'undefined') return ''; return window.location.protocol === 'file:' ? DEFAULT_ELECTRON_API_URL : ''; }; export const getAdminBaseUrl = () => { const { apiUrl, urlPrefix, adminPath } = useGlobSetting(); if (adminPath?.startsWith('http')) { return trimRightSlash(adminPath); } const prefix = urlPrefix || ''; const normalizedAdminPath = prefix && adminPath?.startsWith(`${prefix}/`) ? adminPath : joinUrl(prefix, adminPath || '/a'); const host = trimRightSlash(apiUrl || '') || getRuntimeOrigin() || getPackagedFallbackOrigin(); return joinUrl(host, normalizedAdminPath); }; export const getGovernTaskSseUrl = () => joinUrl(getAdminBaseUrl(), '/govern/sse'); export const getGovernSseUrl = getGovernTaskSseUrl; export interface GovernConfItem { id?: ApiId | number; confStr?: 'Y' | 'N' | ApiText; confType?: 'useOpenInfo' | 'hasGovern' | 'duplicate' | 'other' | ApiText; } export interface CleanErrorLogItem { id?: ApiId | number; fileId?: ApiId | number; sheetId?: ApiId | number; fileName?: ApiText | null; sheetName?: ApiText | null; content?: ApiText | null; createDateTime?: ApiDateString; } export interface CleanErrorLogQuery extends Query { batchId?: ApiId | number; fileId?: ApiId | number; sheetId?: ApiId | number; } export interface CleanErrorLogPage { records?: ApiList; total?: ApiCount; size?: ApiCount; current?: ApiCount; pages?: ApiCount; } // ==================== 治理任务管理 ==================== /** * SSE连接建立 - 创建Server-Sent Events连接 */ export const sse = (params?: Recordable) => defHttp.get({ url: adminPath + '/govern/sse', params }); /** * 测试 SSE 推送 */ export const testSse = () => defHttp.get({ url: adminPath + '/govern/sse/put' }); /** * 启动治理计算任务 */ export const calcTask = (params: CalcTaskDTO) => defHttp.get({ url: adminPath + '/govern/calcTask', params }); // ==================== 治理树结构管理 ==================== /** * 获取治理树结构 */ export const getTree = () => defHttp.get({ url: adminPath + '/gt/tree' }); /** * 获取治理树表格分页数据 */ export const treeTablePage = (data: GovernTreeQuery) => defHttp.postJson({ url: adminPath + '/gt/treeTablePage', data }); /** * 获取治理树关联的交易人员分页数据 */ export const getTreeTransPersonPage = (data: GovernTreeQuery) => defHttp.postJson({ url: adminPath + '/gt/getTreeTransPersonPage', data }); /** * 获取治理树关联的交易银行卡分页数据 */ export const getTreeTransBankPage = (data: GovernTreeQuery) => defHttp.postJson({ url: adminPath + '/gt/getTreeTransBankPage', data }); /** * 获取治理树关联的通话人员分页数据 */ export const getTreeCallPersonPage = (data: GovernTreeQuery) => defHttp.postJson({ url: adminPath + '/gt/getTreeCallPersonPage', data }); /** * 获取治理树关联的通话对方号码分页数据 */ export const getTreeCallOperPage = (data: GovernTreeQuery) => defHttp.postJson({ url: adminPath + '/gt/getTreeCallOperPage', data }); /** * 获取治理树关联的开户使用本人信息分页数据 */ export const getTreeCallPersonUseOpenInfoPage = (data: GovernTreeQuery) => defHttp.postJson({ url: adminPath + '/gt/getTreeCallPersonUseOpenInfoPage', data }); /** * 获取治理树关联的开户使用对方信息分页数据 */ export const getTreeCallOperUseOpenInfoPage = (data: GovernTreeQuery) => defHttp.postJson({ url: adminPath + '/gt/getTreeCallOperUseOpenInfoPage', data }); // ==================== 数据管理 ==================== /** * 执行数据清洗 */ export const doClean = (data: DoCleanDTO) => defHttp.postJson({ url: adminPath + '/dm/doClean', data }); /** * 文件预处理 */ export const preFile = (data: PrepareProcessFileDTO) => defHttp.postJson({ url: adminPath + '/dm/preFile', data }); /** * 取消清洗任务 */ export const cancelClean = (params: { batchId?: ApiId | number }) => defHttp.get({ url: adminPath + '/dm/cancelClean', params }); /** * 已导入文件列表 * @param data * @returns */ export const importFileList = (data: Query) => defHttp.postJson({ url: adminPath + '/dm/getFiles', data }); /** * 已删除文件列表 * @param data * @returns */ export const deletedFileList = (data: { ids: string[] }) => defHttp.postJson({ url: adminPath + '/dm/deletedFiles', data }); /** * 获取治理配置 */ export const getGovernConfList = () => defHttp.get({ url: adminPath + '/dm/getGovernConfList' }); /** * 保存治理配置 */ export const saveGovernConf = (data: GovernConfItem[]) => defHttp.postJson({ url: adminPath + '/dm/saveGovernCon', data }); /** * 获取清洗错误日志列表 */ export const cleanErrorLogList = (params: Partial) => defHttp.get({ url: adminPath + '/cleanLog/list', params });