governApi.ts 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. import { defHttp } from '@jeesite/core/utils/http/axios';
  2. import { useGlobSetting } from '@jeesite/core/hooks/setting';
  3. import type { Result } from '@jeesite/types/axios';
  4. import type { FileInfo } from '@jeesite/types/api';
  5. import { CalcTaskDTO, DataTableDTO, DoCleanDTO, GovernTree, PrepareProcessFileDTO } from './types/dto';
  6. import { Query } from '@jeesite/types';
  7. import { GovernTreeQuery } from './types/query';
  8. const { adminPath } = useGlobSetting();
  9. const DEFAULT_ELECTRON_API_URL = 'http://localhost:8980';
  10. const trimRightSlash = (value = '') => value.replace(/\/+$/, '');
  11. const ensureLeftSlash = (value = '') => (value.startsWith('/') ? value : `/${value}`);
  12. const joinUrl = (...parts: Array<string | undefined>) => {
  13. const filtered = parts.filter(Boolean) as string[];
  14. if (!filtered.length) return '';
  15. return filtered
  16. .map((part, index) => {
  17. if (index === 0) return trimRightSlash(part);
  18. return ensureLeftSlash(part).replace(/\/+$/, '');
  19. })
  20. .join('');
  21. };
  22. const getRuntimeOrigin = () => {
  23. if (typeof window === 'undefined') return '';
  24. const { origin, protocol } = window.location;
  25. if (protocol !== 'http:' && protocol !== 'https:') return '';
  26. return origin && origin !== 'null' ? origin : '';
  27. };
  28. const getPackagedFallbackOrigin = () => {
  29. if (typeof window === 'undefined') return '';
  30. return window.location.protocol === 'file:' ? DEFAULT_ELECTRON_API_URL : '';
  31. };
  32. export const getAdminBaseUrl = () => {
  33. const { apiUrl, urlPrefix, adminPath } = useGlobSetting();
  34. if (adminPath?.startsWith('http')) {
  35. return trimRightSlash(adminPath);
  36. }
  37. const prefix = urlPrefix || '';
  38. const normalizedAdminPath =
  39. prefix && adminPath?.startsWith(`${prefix}/`) ? adminPath : joinUrl(prefix, adminPath || '/a');
  40. const host = trimRightSlash(apiUrl || '') || getRuntimeOrigin() || getPackagedFallbackOrigin();
  41. return joinUrl(host, normalizedAdminPath);
  42. };
  43. export const getGovernTaskSseUrl = () => joinUrl(getAdminBaseUrl(), '/govern/sse');
  44. export const getGovernSseUrl = getGovernTaskSseUrl;
  45. export interface GovernConfItem {
  46. id?: ApiId | number;
  47. confStr?: 'Y' | 'N' | ApiText;
  48. confType?: 'useOpenInfo' | 'hasGovern' | 'duplicate' | 'other' | ApiText;
  49. }
  50. export interface CleanErrorLogItem {
  51. id?: ApiId | number;
  52. fileId?: ApiId | number;
  53. sheetId?: ApiId | number;
  54. fileName?: ApiText | null;
  55. sheetName?: ApiText | null;
  56. content?: ApiText | null;
  57. createDateTime?: ApiDateString;
  58. }
  59. export interface CleanErrorLogQuery extends Query {
  60. batchId?: ApiId | number;
  61. fileId?: ApiId | number;
  62. sheetId?: ApiId | number;
  63. }
  64. export interface CleanErrorLogPage {
  65. records?: ApiList<CleanErrorLogItem>;
  66. total?: ApiCount;
  67. size?: ApiCount;
  68. current?: ApiCount;
  69. pages?: ApiCount;
  70. }
  71. // ==================== 治理任务管理 ====================
  72. /**
  73. * SSE连接建立 - 创建Server-Sent Events连接
  74. */
  75. export const sse = (params?: Recordable) => defHttp.get<void>({ url: adminPath + '/govern/sse', params });
  76. /**
  77. * 测试 SSE 推送
  78. */
  79. export const testSse = () => defHttp.get<void>({ url: adminPath + '/govern/sse/put' });
  80. /**
  81. * 启动治理计算任务
  82. */
  83. export const calcTask = (params: CalcTaskDTO) => defHttp.get<void>({ url: adminPath + '/govern/calcTask', params });
  84. // ==================== 治理树结构管理 ====================
  85. /**
  86. * 获取治理树结构
  87. */
  88. export const getTree = () => defHttp.get<GovernTree[]>({ url: adminPath + '/gt/tree' });
  89. /**
  90. * 获取治理树表格分页数据
  91. */
  92. export const treeTablePage = (data: GovernTreeQuery) =>
  93. defHttp.postJson<DataTableDTO>({ url: adminPath + '/gt/treeTablePage', data });
  94. /**
  95. * 获取治理树关联的交易人员分页数据
  96. */
  97. export const getTreeTransPersonPage = (data: GovernTreeQuery) =>
  98. defHttp.postJson<DataTableDTO>({ url: adminPath + '/gt/getTreeTransPersonPage', data });
  99. /**
  100. * 获取治理树关联的交易银行卡分页数据
  101. */
  102. export const getTreeTransBankPage = (data: GovernTreeQuery) =>
  103. defHttp.postJson<DataTableDTO>({ url: adminPath + '/gt/getTreeTransBankPage', data });
  104. /**
  105. * 获取治理树关联的通话人员分页数据
  106. */
  107. export const getTreeCallPersonPage = (data: GovernTreeQuery) =>
  108. defHttp.postJson<DataTableDTO>({ url: adminPath + '/gt/getTreeCallPersonPage', data });
  109. /**
  110. * 获取治理树关联的通话对方号码分页数据
  111. */
  112. export const getTreeCallOperPage = (data: GovernTreeQuery) =>
  113. defHttp.postJson<DataTableDTO>({ url: adminPath + '/gt/getTreeCallOperPage', data });
  114. /**
  115. * 获取治理树关联的开户使用本人信息分页数据
  116. */
  117. export const getTreeCallPersonUseOpenInfoPage = (data: GovernTreeQuery) =>
  118. defHttp.postJson<Result>({ url: adminPath + '/gt/getTreeCallPersonUseOpenInfoPage', data });
  119. /**
  120. * 获取治理树关联的开户使用对方信息分页数据
  121. */
  122. export const getTreeCallOperUseOpenInfoPage = (data: GovernTreeQuery) =>
  123. defHttp.postJson<Result>({ url: adminPath + '/gt/getTreeCallOperUseOpenInfoPage', data });
  124. // ==================== 数据管理 ====================
  125. /**
  126. * 执行数据清洗
  127. */
  128. export const doClean = (data: DoCleanDTO) => defHttp.postJson<Recordable>({ url: adminPath + '/dm/doClean', data });
  129. /**
  130. * 文件预处理
  131. */
  132. export const preFile = (data: PrepareProcessFileDTO) =>
  133. defHttp.postJson<FileInfo[]>({ url: adminPath + '/dm/preFile', data });
  134. /**
  135. * 取消清洗任务
  136. */
  137. export const cancelClean = (params: { batchId?: ApiId | number }) =>
  138. defHttp.get<void>({ url: adminPath + '/dm/cancelClean', params });
  139. /**
  140. * 已导入文件列表
  141. * @param data
  142. * @returns
  143. */
  144. export const importFileList = (data: Query) => defHttp.postJson<FileInfo[]>({ url: adminPath + '/dm/getFiles', data });
  145. /**
  146. * 已删除文件列表
  147. * @param data
  148. * @returns
  149. */
  150. export const deletedFileList = (data: { ids: string[] }) =>
  151. defHttp.postJson<void>({ url: adminPath + '/dm/deletedFiles', data });
  152. /**
  153. * 获取治理配置
  154. */
  155. export const getGovernConfList = () => defHttp.get<GovernConfItem[]>({ url: adminPath + '/dm/getGovernConfList' });
  156. /**
  157. * 保存治理配置
  158. */
  159. export const saveGovernConf = (data: GovernConfItem[]) =>
  160. defHttp.postJson<void>({ url: adminPath + '/dm/saveGovernCon', data });
  161. /**
  162. * 获取清洗错误日志列表
  163. */
  164. export const cleanErrorLogList = (params: Partial<CleanErrorLogQuery>) =>
  165. defHttp.get<CleanErrorLogPage>({ url: adminPath + '/cleanLog/list', params });