feat: 增加股票现价显示,日线改为后复权数据
This commit is contained in:
@@ -42,6 +42,20 @@ public class NumberHelper {
|
||||
return NumberUtil.decimalFormat("0.00%", value);
|
||||
}
|
||||
|
||||
public static String formatPriceDouble(Double value) {
|
||||
if (ObjectUtil.isNull(value)) {
|
||||
return null;
|
||||
}
|
||||
return NumberUtil.decimalFormat("0.00", value);
|
||||
}
|
||||
|
||||
public static String formatPriceDouble(Integer value) {
|
||||
if (ObjectUtil.isNull(value)) {
|
||||
return null;
|
||||
}
|
||||
return NumberUtil.decimalFormat("0.00", value);
|
||||
}
|
||||
|
||||
public static Double parseDouble(String value) {
|
||||
if (StrUtil.isBlank(value)) {
|
||||
return null;
|
||||
|
||||
@@ -23,6 +23,9 @@ public interface DailyRepository extends SimpleRepository<Daily> {
|
||||
@Query("select min(daily.tradeDate) from Daily daily")
|
||||
LocalDate findMinTradeDate();
|
||||
|
||||
@Query("from Daily daily where daily.stock.id = ?1 order by daily.tradeDate desc limit 1")
|
||||
Optional<Daily> findLatest(Long stockId);
|
||||
|
||||
@EntityGraph(attributePaths = {"stock"})
|
||||
@Override
|
||||
Optional<Daily> findOne(Predicate predicate);
|
||||
|
||||
@@ -58,4 +58,8 @@ public class StockService extends SimpleServiceSupport<Stock> {
|
||||
Sort.by(Sort.Direction.ASC, Daily_.TRADE_DATE)
|
||||
);
|
||||
}
|
||||
|
||||
public Optional<Daily> findDailyLatest(Long stockId) {
|
||||
return dailyRepository.findLatest(stockId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.lanyuanxiaoyao.leopard.server.controller;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.lanyuanxiaoyao.leopard.core.entity.Daily;
|
||||
import com.lanyuanxiaoyao.leopard.core.entity.Stock;
|
||||
import com.lanyuanxiaoyao.leopard.core.helper.NumberHelper;
|
||||
import com.lanyuanxiaoyao.leopard.core.service.StockService;
|
||||
@@ -108,6 +109,18 @@ public class StockController extends SimpleControllerSupport<Stock, Void, StockD
|
||||
));
|
||||
}
|
||||
|
||||
@GetMapping("daily/current/{id}")
|
||||
public GlobalResponse<Map<String, Object>> dailyCurrent(@PathVariable("id") Long id) {
|
||||
var daily = stockService.findDailyLatest(id);
|
||||
return GlobalResponse.responseMapData(Map.of(
|
||||
"date", daily.map(Daily::getTradeDate).map(LocalDate::toString).orElse("/"),
|
||||
"open", daily.map(Daily::getOpen).map(NumberHelper::formatPriceDouble).orElse(NumberHelper.FINANCE_NULL_DOUBLE),
|
||||
"close", daily.map(Daily::getClose).map(NumberHelper::formatPriceDouble).orElse(NumberHelper.FINANCE_NULL_DOUBLE),
|
||||
"low", daily.map(Daily::getLow).map(NumberHelper::formatPriceDouble).orElse(NumberHelper.FINANCE_NULL_DOUBLE),
|
||||
"high", daily.map(Daily::getHigh).map(NumberHelper::formatPriceDouble).orElse(NumberHelper.FINANCE_NULL_DOUBLE)
|
||||
));
|
||||
}
|
||||
|
||||
@GetMapping("daily/{id}")
|
||||
public GlobalResponse<Map<String, Object>> dailyCharts(@PathVariable("id") Long id) {
|
||||
var data = stockService.findDailyRecent(id, 100);
|
||||
@@ -115,7 +128,7 @@ public class StockController extends SimpleControllerSupport<Stock, Void, StockD
|
||||
var yList = new ArrayList<List<Double>>();
|
||||
for (var daily : data) {
|
||||
xList.add(daily.getTradeDate().toString());
|
||||
yList.add(List.of(daily.getOpen(), daily.getClose(), daily.getLow(), daily.getHigh()));
|
||||
yList.add(List.of(daily.getHfqOpen(), daily.getHfqClose(), daily.getHfqLow(), daily.getHfqHigh()));
|
||||
}
|
||||
return GlobalResponse.responseMapData(Map.of(
|
||||
"xList", xList, "yList", yList
|
||||
|
||||
@@ -6,7 +6,6 @@ import Overview from './pages/Overview.tsx'
|
||||
import Root from './pages/Root.tsx'
|
||||
import Test from './pages/Test.tsx'
|
||||
import StockList from './pages/stock/StockList.tsx'
|
||||
import StockDetail from './pages/stock/StockDetail.tsx'
|
||||
import TaskList from './pages/task/TaskList.tsx'
|
||||
import TaskTemplateList from './pages/task/TaskTemplateList.tsx'
|
||||
import TaskScheduleList from './pages/task/TaskScheduleList.tsx'
|
||||
@@ -35,10 +34,6 @@ const routes: RouteObject[] = [
|
||||
path: 'list',
|
||||
Component: StockList,
|
||||
},
|
||||
{
|
||||
path: 'detail/:id',
|
||||
Component: StockDetail,
|
||||
},
|
||||
{
|
||||
path: "collection",
|
||||
children: [
|
||||
|
||||
@@ -571,7 +571,7 @@ export function stockListColumns(idField: string = 'id', extraColumns: Array<Col
|
||||
{
|
||||
name: 'name',
|
||||
label: '简称',
|
||||
width: 150,
|
||||
width: 100,
|
||||
},
|
||||
{
|
||||
name: 'fullname',
|
||||
@@ -782,13 +782,37 @@ export function stockListColumns(idField: string = 'id', extraColumns: Array<Col
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{type: 'divider'},
|
||||
"100日线数据",
|
||||
{
|
||||
type: 'service',
|
||||
api: `get:${commonInfo.baseUrl}/stock/daily/current/\${${idField}}`,
|
||||
body: [
|
||||
"现价 (${date})",
|
||||
{
|
||||
className: 'my-2',
|
||||
type: 'property',
|
||||
column: 4,
|
||||
items: [
|
||||
{label: '开盘价', content: '${open}'},
|
||||
{label: '收盘价', content: '${close}'},
|
||||
{label: '最高价', content: '${high}'},
|
||||
{label: '最低价', content: '${low}'},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'chart',
|
||||
title: '100日线数据',
|
||||
height: 500,
|
||||
api: `get:${commonInfo.baseUrl}/stock/daily/\${${idField}}`,
|
||||
config: {
|
||||
title: {
|
||||
text: '100日线数据',
|
||||
subtext: '后复权数据',
|
||||
},
|
||||
backgroundColor: '#fff',
|
||||
animation: true,
|
||||
animationDuration: 1000,
|
||||
@@ -832,9 +856,9 @@ export function stockListColumns(idField: string = 'id', extraColumns: Array<Col
|
||||
},
|
||||
},
|
||||
grid: {
|
||||
left: '10%',
|
||||
right: '10%',
|
||||
top: '10%',
|
||||
left: '2%',
|
||||
right: '2%',
|
||||
top: '15%',
|
||||
bottom: '15%',
|
||||
containLabel: true,
|
||||
},
|
||||
@@ -910,9 +934,6 @@ export function stockListColumns(idField: string = 'id', extraColumns: Array<Col
|
||||
],
|
||||
},
|
||||
},
|
||||
"12月线数据",
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user