mall数据库文件
This commit is contained in:
70
services/analytics/dataDetailService.uts
Normal file
70
services/analytics/dataDetailService.uts
Normal file
@@ -0,0 +1,70 @@
|
||||
import { rpcOrEmptyArray, rpcOrNull } from './rpc.uts'
|
||||
|
||||
export type DataDetailReportInfo = {
|
||||
period: string
|
||||
}
|
||||
|
||||
export type DataDetailRow = {
|
||||
id: string
|
||||
date: string
|
||||
gmv: number
|
||||
orders: number
|
||||
users: number
|
||||
}
|
||||
|
||||
export type DataDetailDrillItem = {
|
||||
id: string
|
||||
label: string
|
||||
value: string
|
||||
type: string
|
||||
}
|
||||
|
||||
export async function fetchDataDetailReportInfo(reportId: string): Promise<DataDetailReportInfo | null> {
|
||||
const info = await rpcOrNull('rpc_data_detail_report_info', {
|
||||
p_report_id: reportId
|
||||
} as UTSJSONObject)
|
||||
if (info == null) return null
|
||||
return { period: info.getString('period') ?? '' }
|
||||
}
|
||||
|
||||
export async function fetchDataDetailRows(reportId: string, sortBy: string, sortDir: string, limit: number, offset: number): Promise<Array<DataDetailRow>> {
|
||||
const rows = await rpcOrEmptyArray('rpc_data_detail_rows', {
|
||||
p_report_id: reportId,
|
||||
p_sort_by: sortBy,
|
||||
p_sort_dir: sortDir,
|
||||
p_limit: limit,
|
||||
p_offset: offset
|
||||
} as UTSJSONObject)
|
||||
|
||||
const out: Array<DataDetailRow> = []
|
||||
for (let i = 0; i < rows.length; i++) {
|
||||
const r = rows[i]
|
||||
const dayStr = r.getString('row_date') ?? ''
|
||||
out.push({
|
||||
id: dayStr + '_' + i.toString(),
|
||||
date: dayStr,
|
||||
gmv: r.getNumber('gmv') ?? 0,
|
||||
orders: r.getNumber('orders') ?? 0,
|
||||
users: r.getNumber('users') ?? 0
|
||||
})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
export async function fetchDataDetailDrillItems(reportId: string): Promise<Array<DataDetailDrillItem>> {
|
||||
const rows = await rpcOrEmptyArray('rpc_data_detail_drill_items', {
|
||||
p_report_id: reportId
|
||||
} as UTSJSONObject)
|
||||
|
||||
const out: Array<DataDetailDrillItem> = []
|
||||
for (let i = 0; i < rows.length; i++) {
|
||||
const r = rows[i]
|
||||
out.push({
|
||||
id: `${r.getAny('id') ?? i}`,
|
||||
label: `${r.getString('label') ?? ''}`,
|
||||
value: `${r.getAny('value') ?? ''}`,
|
||||
type: `${r.getString('type') ?? ''}`
|
||||
})
|
||||
}
|
||||
return out
|
||||
}
|
||||
Reference in New Issue
Block a user