数据分析ui补充完善,接入数据库
This commit is contained in:
@@ -1,70 +1,58 @@
|
||||
import { rpcOrEmptyArray, rpcOrNull } from './rpc.uts'
|
||||
|
||||
export type DataDetailReportInfo = {
|
||||
period: string
|
||||
}
|
||||
|
||||
export type DataDetailRow = {
|
||||
export type ReportInfo = {
|
||||
id: string
|
||||
date: string
|
||||
gmv: number
|
||||
orders: number
|
||||
users: number
|
||||
title: string
|
||||
description: string
|
||||
definition: any
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export type DataDetailDrillItem = {
|
||||
id: string
|
||||
label: string
|
||||
value: string
|
||||
type: string
|
||||
function safeString(v: any): string {
|
||||
return v != null ? `${v}` : ''
|
||||
}
|
||||
|
||||
export async function fetchDataDetailReportInfo(reportId: string): Promise<DataDetailReportInfo | null> {
|
||||
const info = await rpcOrNull('rpc_data_detail_report_info', {
|
||||
// 改造:调用 rpc_data_detail_report_info
|
||||
export async function fetchReportInfo(reportId: string): Promise<ReportInfo | null> {
|
||||
const row = await rpcOrNull('rpc_data_detail_report_info', {
|
||||
p_report_id: reportId
|
||||
} as UTSJSONObject)
|
||||
if (info == null) return null
|
||||
return { period: info.getString('period') ?? '' }
|
||||
} as any)
|
||||
|
||||
if (row == null) return null
|
||||
|
||||
return {
|
||||
id: safeString(row.getAny?.('id')),
|
||||
title: safeString(row.getAny?.('title')),
|
||||
description: safeString(row.getAny?.('description')),
|
||||
definition: row.getAny?.('definition'),
|
||||
updated_at: safeString(row.getAny?.('updated_at'))
|
||||
}
|
||||
}
|
||||
|
||||
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', {
|
||||
// 改造:调用 rpc_data_detail_rows
|
||||
export async function fetchReportRows(reportId: string, params: any): Promise<Array<UTSJSONObject>> {
|
||||
const result = await rpcOrNull('rpc_data_detail_rows', {
|
||||
p_report_id: reportId,
|
||||
p_sort_by: sortBy,
|
||||
p_sort_dir: sortDir,
|
||||
p_limit: limit,
|
||||
p_offset: offset
|
||||
} as UTSJSONObject)
|
||||
p_params: params
|
||||
} as any)
|
||||
|
||||
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
|
||||
if (result == null) return []
|
||||
const anyData = result as any
|
||||
return Array.isArray(anyData) ? (anyData as Array<UTSJSONObject>) : ([] as Array<UTSJSONObject>)
|
||||
}
|
||||
|
||||
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
|
||||
// 保留调用,但 RPC 是模拟数据
|
||||
export async function fetchDrilldown(reportId: string, itemId: string): Promise<Array<UTSJSONObject>> {
|
||||
return await rpcOrEmptyArray('rpc_data_detail_drill_items', {
|
||||
p_report_id: reportId,
|
||||
p_item_id: itemId
|
||||
} as any)
|
||||
}
|
||||
|
||||
// 保留调用,但 RPC 是模拟数据
|
||||
export async function fetchComparison(itemId: string, period: string): Promise<Array<UTSJSONObject>> {
|
||||
return await rpcOrEmptyArray('rpc_data_detail_compare_gmv', {
|
||||
p_item_id: itemId,
|
||||
p_period: period
|
||||
} as any)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user