new
This commit is contained in:
148
src/utils/dataCenter.ts
Normal file
148
src/utils/dataCenter.ts
Normal 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;
|
||||
};
|
||||
Reference in New Issue
Block a user