This commit is contained in:
2026-04-24 20:30:52 +08:00
commit 704bc34625
152 changed files with 45612 additions and 0 deletions

148
src/utils/dataCenter.ts Normal file
View File

@@ -0,0 +1,148 @@
import { getDataSourceList, getGroupList, getSymbolList } from '@/services/api';
import { transformToSymbolTree2 } from '@/utils/groupUtil';
// import { storage } from '@/utils/storage';
import {
transformToAssetsTree,
transformToSymbolTree,
} from '@/utils/symbolUtil';
// const aWeekTime = 3600 * 24 * 7;
// const aDay = 3600 * 24;
export const getSymbolTreeList = async (
_companyInfo: API.CompanyListItem | undefined,
dataSourceId?: number | string,
_forceRefresh = false,
) => {
if (!dataSourceId) {
return [];
}
// const dataSourceList = await getAllDataSourceList(_companyInfo);
// const dataSourceInfo = dataSourceList.find(
// (item) => item.id === dataSourceId,
// );
// if (!dataSourceInfo) {
// return [];
// }
// const sourceKey = btoa(
// encodeURIComponent(
// `${dataSourceInfo.id}_${dataSourceInfo.tradeIp}:${dataSourceInfo.tradePort}`,
// ),
// );
// const storageKey = `symbolTree_${sourceKey}`;
// if (!_forceRefresh) {
// const cachedTreeList = (await storage.get(storageKey)) as
// | API.SymbolTreeNode[]
// | null;
// if (cachedTreeList && cachedTreeList.length > 0) {
// return cachedTreeList;
// }
// }
const {
data: { data: symbolList },
} = await getSymbolList({ dataSourceId });
if (!symbolList || symbolList.length === 0) {
return [];
}
const treeList = transformToSymbolTree(symbolList);
// storage.set(storageKey, treeList, aDay);
return treeList;
};
export const getAllDataSourceList = async (
_companyInfo: API.CompanyListItem | undefined,
_forceRefresh = false,
): Promise<API.DataSourceListItem[]> => {
if (!_companyInfo) {
return [];
}
// const companyKey = btoa(
// encodeURIComponent(`${_companyInfo.id}_${_companyInfo.email}`),
// );
// const storageKey = `dataSourceList_${companyKey}`;
// if (!_forceRefresh) {
// const cachedList = (await storage.get(storageKey)) as
// | API.DataSourceListItem[]
// | null
// | undefined;
// if (cachedList && cachedList.length > 0) {
// return cachedList;
// }
// }
const {
data: { data: dataSourceList },
} = await getDataSourceList({
status: 1,
});
if (!dataSourceList || dataSourceList.length === 0) {
return [];
}
// storage.set(storageKey, dataSourceList, aDay);
return dataSourceList;
};
export const getGroupTreeList = async (
_companyInfo: API.CompanyListItem | undefined,
dataSourceId: number | string,
_forceRefresh = false,
) => {
if (!dataSourceId) {
return [];
}
// const dataSourceList = await getAllDataSourceList(_companyInfo);
// const dataSourceInfo = dataSourceList.find(
// (item) => item.id === dataSourceId,
// );
// if (!dataSourceInfo) {
// return [];
// }
// const sourceKey = btoa(
// encodeURIComponent(
// `${dataSourceInfo.id}_${dataSourceInfo.tradeIp}:${dataSourceInfo.tradePort}`,
// ),
// );
// const storageKey = `groupTree_${sourceKey}`;
// if (!_forceRefresh) {
// const cachedList = (await storage.get(storageKey)) as
// | API.GroupListItem[]
// | null
// | undefined;
// if (cachedList && cachedList.length > 0) {
// return cachedList;
// }
// }
const {
data: { data: groupList },
} = await getGroupList({ dataSourceId });
if (!groupList || groupList.length === 0) {
return [];
}
const treeList = transformToSymbolTree2(groupList);
// storage.set(storageKey, treeList, aDay);
return treeList;
};
export const getAssetsTreeList = async (
_companyInfo: API.CompanyListItem | undefined,
dataSourceId?: number | string,
_forceRefresh = false,
) => {
if (!dataSourceId) {
return [];
}
const {
data: { data: symbolList },
} = await getSymbolList({ dataSourceId });
if (!symbolList || symbolList.length === 0) {
return [];
}
const treeList = transformToAssetsTree(symbolList);
// storage.set(storageKey, treeList, aDay);
return treeList;
};