You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
123 lines
3.3 KiB
123 lines
3.3 KiB
{
|
|
"properties" : { },
|
|
"id" : "3c4d5e6f7a8490b1c2d3e4f5a678901",
|
|
"script" : null,
|
|
"groupId" : "f8e3d2c1b0a94e5f8a7b6c5d4e3f2a1",
|
|
"name" : "交易所牦牛成交数据",
|
|
"createTime" : 1780877000000,
|
|
"updateTime" : 1781369000000,
|
|
"lock" : null,
|
|
"createBy" : "admin",
|
|
"updateBy" : "admin",
|
|
"path" : "/yak-trading-data",
|
|
"method" : "GET",
|
|
"parameters" : [ {
|
|
"name" : "period",
|
|
"value" : null,
|
|
"description" : "时间维度:day(近6日)/week(近6周)/month(近6月),不传则返回全部",
|
|
"required" : false,
|
|
"dataType" : "String",
|
|
"type" : null,
|
|
"defaultValue" : null,
|
|
"validateType" : null,
|
|
"error" : null,
|
|
"expression" : null,
|
|
"children" : null
|
|
} ],
|
|
"options" : [ ],
|
|
"requestBody" : "",
|
|
"headers" : [ ],
|
|
"paths" : [ ],
|
|
"responseBody" : null,
|
|
"description" : "交易所牦牛成交数据:gov_count_order_total,一条记录一单,SUM(yak_number) 为成交头数,COUNT(*) 为订单数。",
|
|
"requestBodyDefinition" : null,
|
|
"responseBodyDefinition" : null
|
|
}
|
|
================================
|
|
// gov_count_order_total:一条记录 = 一笔订单
|
|
// 牦牛成交头数:SUM(yak_number)
|
|
// 成交订单数:COUNT(*)
|
|
// 时间维度按 update_time 分桶(count_date 多为空)
|
|
|
|
var buildSeries = (rows) => {
|
|
var labels = []
|
|
var yakNumber = []
|
|
var orderCount = []
|
|
|
|
for (row in rows) {
|
|
labels.push(row.label)
|
|
yakNumber.push(row.yakNumber != null ? row.yakNumber : 0)
|
|
orderCount.push(row.orderCount != null ? row.orderCount : 0)
|
|
}
|
|
|
|
return {
|
|
labels: labels,
|
|
yakNumber: yakNumber,
|
|
orderCount: orderCount
|
|
}
|
|
}
|
|
|
|
var daySql = """
|
|
SELECT
|
|
TO_CHAR(d.bucket_date, 'FMMM/FMDD') AS label,
|
|
COALESCE(SUM(o.yak_number), 0) AS yak_number,
|
|
COUNT(o.id) AS order_count
|
|
FROM (
|
|
SELECT (CURRENT_DATE - offs)::date AS bucket_date, offs
|
|
FROM generate_series(5, 0, -1) AS offs
|
|
) d
|
|
LEFT JOIN gov_count_order_total o
|
|
ON o.update_time >= d.bucket_date
|
|
AND o.update_time < d.bucket_date + INTERVAL '1 day'
|
|
GROUP BY d.bucket_date, d.offs
|
|
ORDER BY d.offs DESC
|
|
"""
|
|
|
|
var weekSql = """
|
|
SELECT
|
|
TO_CHAR(d.anchor_date, 'FMMM/FMDD') || '-' || TO_CHAR(d.anchor_date + 6, 'FMMM/FMDD') AS label,
|
|
COALESCE(SUM(o.yak_number), 0) AS yak_number,
|
|
COUNT(o.id) AS order_count
|
|
FROM (
|
|
SELECT (CURRENT_DATE - offs * 7)::date AS anchor_date, offs
|
|
FROM generate_series(5, 0, -1) AS offs
|
|
) d
|
|
LEFT JOIN gov_count_order_total o
|
|
ON o.update_time >= d.anchor_date
|
|
AND o.update_time < d.anchor_date + INTERVAL '7 days'
|
|
GROUP BY d.anchor_date, d.offs
|
|
ORDER BY d.offs DESC
|
|
"""
|
|
|
|
var monthSql = """
|
|
SELECT
|
|
TO_CHAR(d.month_start, 'YYYY/FMMM') AS label,
|
|
COALESCE(SUM(o.yak_number), 0) AS yak_number,
|
|
COUNT(o.id) AS order_count
|
|
FROM (
|
|
SELECT (date_trunc('month', CURRENT_DATE) - (offs || ' months')::interval)::date AS month_start, offs
|
|
FROM generate_series(5, 0, -1) AS offs
|
|
) d
|
|
LEFT JOIN gov_count_order_total o
|
|
ON o.update_time >= d.month_start
|
|
AND o.update_time < d.month_start + INTERVAL '1 month'
|
|
GROUP BY d.month_start, d.offs
|
|
ORDER BY d.offs DESC
|
|
"""
|
|
|
|
var dayRows = db.select(daySql)
|
|
var weekRows = db.select(weekSql)
|
|
var monthRows = db.select(monthSql)
|
|
|
|
var result = {
|
|
day: buildSeries(dayRows),
|
|
week: buildSeries(weekRows),
|
|
month: buildSeries(monthRows)
|
|
}
|
|
|
|
var p = period
|
|
if (p && result[p]) {
|
|
return result[p]
|
|
}
|
|
|
|
return result
|
|
|