{ "properties" : { }, "id" : "3c4d5e6f7a8490b1c2d3e4f5a678901", "script" : null, "groupId" : "f8e3d2c1b0a94e5f8a7b6c5d4e3f2a1", "name" : "交易所牦牛成交数据", "createTime" : 1780877000000, "updateTime" : 1780817847278, "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" : "{\n \"code\": -1,\n \"message\": \"系统内部出现错误\",\n \"data\": null,\n \"timestamp\": 1780817836665,\n \"executeTime\": 4\n}", "description" : "交易所牦牛成交数据:近6个时间段的牦牛交易数量(头)与成交订单数量(单)趋势,数据源 yak_sn_order 已完成订单(只读查询)", "requestBodyDefinition" : null, "responseBodyDefinition" : null } ================================ var buildSeries = (rows) => { var labels = [] var yakTradingVolume = [] var orderCount = [] for (row in rows) { labels.push(row.label) yakTradingVolume.push(row.yakVolume ? row.yakVolume : 0) orderCount.push(row.orderCount ? row.orderCount : 0) } return { labels: labels, yakTradingVolume: yakTradingVolume, orderCount: orderCount } } var daySql = """ SELECT TO_CHAR(d.bucket_date, 'FMMM/FMDD') AS label, COALESCE(SUM(o.quantity), 0) AS yak_volume, 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 yak_sn_order o ON o.del_flag = '0' AND o.status = 'COMPLETED' AND o.transaction_time >= d.bucket_date AND o.transaction_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.quantity), 0) AS yak_volume, 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 yak_sn_order o ON o.del_flag = '0' AND o.status = 'COMPLETED' AND o.transaction_time >= d.anchor_date AND o.transaction_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.quantity), 0) AS yak_volume, 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 yak_sn_order o ON o.del_flag = '0' AND o.status = 'COMPLETED' AND o.transaction_time >= d.month_start AND o.transaction_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