diff --git a/leopard-server/src/main/java/com/lanyuanxiaoyao/leopard/server/controller/StockController.java b/leopard-server/src/main/java/com/lanyuanxiaoyao/leopard/server/controller/StockController.java index 783d29a..4af47bd 100644 --- a/leopard-server/src/main/java/com/lanyuanxiaoyao/leopard/server/controller/StockController.java +++ b/leopard-server/src/main/java/com/lanyuanxiaoyao/leopard/server/controller/StockController.java @@ -135,6 +135,36 @@ public class StockController extends SimpleControllerSupport> weeklyCharts(@PathVariable("id") Long id) { + var data = stockService.findWeeklyRecent(id, 50); + var xList = new ArrayList(); + var yList = new ArrayList>(); + for (var weekly : data) { + xList.add(weekly.tradeDate().toString()); + yList.add(List.of(weekly.open(), weekly.close(), weekly.low(), weekly.high())); + } + return GlobalResponse.responseMapData(Map.of( + "xList", xList, "yList", yList + )); + } + + @SuppressWarnings("DuplicatedCode") + @GetMapping("monthly/{id}") + public GlobalResponse> monthlyCharts(@PathVariable("id") Long id) { + var data = stockService.findMonthlyRecent(id, 24); + var xList = new ArrayList(); + var yList = new ArrayList>(); + for (var monthly : data) { + xList.add(monthly.tradeDate().toString()); + yList.add(List.of(monthly.open(), monthly.close(), monthly.low(), monthly.high())); + } + return GlobalResponse.responseMapData(Map.of( + "xList", xList, "yList", yList + )); + } + @Override protected Function saveItemMapper() { throw new UnsupportedOperationException(); diff --git a/leopard-web/src/util/amis.tsx b/leopard-web/src/util/amis.tsx index 52e7319..f67a33c 100644 --- a/leopard-web/src/util/amis.tsx +++ b/leopard-web/src/util/amis.tsx @@ -1,4 +1,4 @@ -import {AlertComponent, attachmentAdpator, makeTranslator, render, type Schema, ToastComponent} from 'amis' +import {AlertComponent, type Api, attachmentAdpator, makeTranslator, render, type Schema, ToastComponent} from 'amis' import 'amis/lib/themes/antd.css' import 'amis/lib/helper.css' import 'amis/sdk/iconfont.css' @@ -561,6 +561,139 @@ const financePropertyLabel = (idField: string, label: string, type: FinanceType, } } +const candleChart = (title: string, subtitle: string, api: Api): Schema => { + return { + type: 'chart', + height: 500, + api: api, + config: { + title: { + text: title, + subtext: subtitle, + }, + backgroundColor: '#fff', + animation: true, + animationDuration: 1000, + tooltip: { + trigger: 'axis', + axisPointer: { + type: 'cross', + }, + backgroundColor: 'rgba(0, 0, 0, 0.7)', + borderColor: '#333', + borderWidth: 1, + textStyle: { + color: '#fff', + fontSize: 12, + }, + padding: 12, + formatter: function (params: any) { + const param = params[0] + const open = toNumber(param.data[1]).toFixed(2) + const close = toNumber(param.data[2]).toFixed(2) + const lowest = toNumber(param.data[3]).toFixed(2) + const highest = toNumber(param.data[4]).toFixed(2) + + return `
${param.name}
+
+ 开盘: + ${open} +
+
+ 收盘: + ${close} +
+
+ 最低: + ${lowest} +
+
+ 最高: + ${highest} +
` + }, + }, + grid: { + left: '2%', + right: '2%', + top: '15%', + bottom: '15%', + containLabel: true, + }, + xAxis: { + data: '${xList || []}', + axisLine: { + lineStyle: { + color: '#e0e0e0', + }, + }, + axisLabel: { + color: '#666', + fontWeight: 'bold', + }, + splitLine: { + show: false, + }, + axisTick: { + show: false, + }, + }, + yAxis: { + scale: true, + axisLine: { + lineStyle: { + color: '#e0e0e0', + }, + }, + axisLabel: { + color: '#666', + fontWeight: 'bold', + formatter: function (value: number) { + return value.toFixed(2) + }, + }, + splitLine: { + lineStyle: { + type: 'dashed', + color: '#f0f0f0', + }, + }, + axisTick: { + show: false, + }, + }, + dataZoom: [ + { + type: 'inside', + start: 0, + end: 100, + }, + { + show: true, + type: 'slider', + top: '90%', + start: 0, + end: 100, + }, + ], + series: [ + { + type: 'candlestick', + data: '${yList || []}', + itemStyle: { + color: '#eb5454', + color0: '#4aaa93', + borderColor: '#eb5454', + borderColor0: '#4aaa93', + borderWidth: 1, + }, + + }, + ], + }, + } +} + export function stockListColumns(idField: string = 'id', extraColumns: Array = []) { return [ { @@ -803,137 +936,21 @@ export function stockListColumns(idField: string = 'id', extraColumns: Array${param.name} -
- 开盘: - ${open} -
-
- 收盘: - ${close} -
-
- 最低: - ${lowest} -
-
- 最高: - ${highest} -
` - }, - }, - grid: { - left: '2%', - right: '2%', - top: '15%', - bottom: '15%', - containLabel: true, - }, - xAxis: { - data: '${xList || []}', - axisLine: { - lineStyle: { - color: '#e0e0e0', - }, - }, - axisLabel: { - color: '#666', - fontWeight: 'bold', - }, - splitLine: { - show: false, - }, - axisTick: { - show: false, - }, - }, - yAxis: { - scale: true, - axisLine: { - lineStyle: { - color: '#e0e0e0', - }, - }, - axisLabel: { - color: '#666', - fontWeight: 'bold', - formatter: function (value: number) { - return value.toFixed(2) - }, - }, - splitLine: { - lineStyle: { - type: 'dashed', - color: '#f0f0f0', - }, - }, - axisTick: { - show: false, - }, - }, - dataZoom: [ - { - type: 'inside', - start: 0, - end: 100, - }, - { - show: true, - type: 'slider', - top: '90%', - start: 0, - end: 100, - }, - ], - series: [ - { - type: 'candlestick', - data: '${yList || []}', - itemStyle: { - color: '#eb5454', - color0: '#4aaa93', - borderColor: '#eb5454', - borderColor0: '#4aaa93', - borderWidth: 1, - }, - - }, - ], - }, - }, + candleChart( + '100日线数据', + '后复权数据', + `get:${commonInfo.baseUrl}/stock/daily/\${${idField}}`, + ), + candleChart( + '50周线数据', + '后复权数据', + `get:${commonInfo.baseUrl}/stock/weekly/\${${idField}}`, + ), + candleChart( + '24月线数据', + '后复权数据', + `get:${commonInfo.baseUrl}/stock/monthly/\${${idField}}`, + ), ], }, },